<ulclass="crumbs"><li><ahref="../webs.html">★</a></li><li><ahref="index.html">inblorb 4</a></li><li><ahref="index.html#1">Chapter 1: Blurbs</a></li><li><b>Main</b></li></ul><pclass="purpose">To parse command-line arguments, then start the Blurb interpreter, then report back to the user.</p>
<ulclass="toc"><li><ahref="#SP1">§1. Some globals</a></li><li><ahref="#SP3">§3. Main</a></li><li><ahref="#SP5">§5. Opening and closing banners</a></li></ul><hrclass="tocbar">
<pclass="inwebparagraph"><aid="SP1"></a><b>§1. Some globals. </b>The following variables record HTML and Javascript-related points where
Inblorb needs to behave differently on the different platforms. The default
values here aren't actually correct for any platform as they stand: in the
<codeclass="display"><spanclass="extract">main</span></code> routine below, we set them as needed.
</p>
<preclass="display">
<spanclass="identifier">wchar_t</span><spanclass="plain"> *</span><spanclass="identifier">FONT_TAG</span><spanclass="plain"> = </span><spanclass="identifier">L</span><spanclass="string">"size=2"</span><spanclass="plain">; </span><spanclass="comment">contents of a <codeclass="display"><spanclass="extract"><font></span></code> tag</span>
<pclass="inwebparagraph"><aid="SP2"></a><b>§2. </b>Some global variables:
</p>
<preclass="display">
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">error_count</span><spanclass="plain"> = 0; </span><spanclass="comment">number of error messages produced so far</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">verbose_mode</span><spanclass="plain"> = </span><spanclass="constant">FALSE</span><spanclass="plain">; </span><spanclass="comment">print diagnostics to <codeclass="display"><spanclass="extract">stdout</span></code> while running?</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">blorb_file_size</span><spanclass="plain"> = 0; </span><spanclass="comment">size in bytes of the blorb file written</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">no_pictures_included</span><spanclass="plain"> = 0; </span><spanclass="comment">number of picture resources included in the blorb</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">no_sounds_included</span><spanclass="plain"> = 0; </span><spanclass="comment">number of sound resources included in the blorb</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">HTML_pages_created</span><spanclass="plain"> = 0; </span><spanclass="comment">number of pages created in the website, if any</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">source_HTML_pages_created</span><spanclass="plain"> = 0; </span><spanclass="comment">number of those holding source</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">sound_resource_num</span><spanclass="plain"> = 3; </span><spanclass="comment">current sound resource number we're working on</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">picture_resource_num</span><spanclass="plain"> = 1; </span><spanclass="comment">current picture resource number we're working on</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">use_css_code_styles</span><spanclass="plain"> = </span><spanclass="constant">FALSE</span><spanclass="plain">; </span><spanclass="comment">use <codeclass="display"><spanclass="extract"><span class="X"></span></code> markings when setting code</span>
<spanclass="reserved">pathname</span><spanclass="plain"> *</span><spanclass="identifier">project_folder</span><spanclass="plain"> = </span><spanclass="identifier">NULL</span><spanclass="plain">; </span><spanclass="comment">pathname of I7 project folder, if any</span>
<spanclass="reserved">pathname</span><spanclass="plain"> *</span><spanclass="identifier">release_folder</span><spanclass="plain"> = </span><spanclass="identifier">NULL</span><spanclass="plain">; </span><spanclass="comment">pathname of folder for website to write, if any</span>
<spanclass="reserved">filename</span><spanclass="plain"> *</span><spanclass="identifier">status_template</span><spanclass="plain"> = </span><spanclass="identifier">NULL</span><spanclass="plain">; </span><spanclass="comment">filename of report HTML page template, if any</span>
<spanclass="reserved">filename</span><spanclass="plain"> *</span><spanclass="identifier">status_file</span><spanclass="plain"> = </span><spanclass="identifier">NULL</span><spanclass="plain">; </span><spanclass="comment">filename of report HTML page to write, if any</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">cover_exists</span><spanclass="plain"> = </span><spanclass="constant">FALSE</span><spanclass="plain">; </span><spanclass="comment">an image is specified as cover art</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">default_cover_used</span><spanclass="plain"> = </span><spanclass="constant">FALSE</span><spanclass="plain">; </span><spanclass="comment">but it's only the default supplied by Inform</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">cover_is_in_JPEG_format</span><spanclass="plain"> = </span><spanclass="constant">TRUE</span><spanclass="plain">; </span><spanclass="comment">as opposed to <codeclass="display"><spanclass="extract">PNG</span></code> format</span>
</pre>
<pclass="inwebparagraph"></p>
<pclass="inwebparagraph"><aid="SP3"></a><b>§3. Main. </b>Like most programs, this one parses command-line arguments, sets things up,
reads the input and then writes the output.
</p>
<pclass="inwebparagraph">That's a little over-simplified, though, because it also produces auxiliary
outputs along the way, in the course of parsing the blurb file. The blorb
file is only the main output — there might also be a web page and a solution
<<spanclass="cwebmacro">Read the command-line switches</span><spanclass="cwebmacronumber">3.3.1</span>><spanclass="plain">;</span>
<<spanclass="cwebmacro">Set platform-dependent HTML and Javascript variables</span><spanclass="cwebmacronumber">3.3.3</span>><spanclass="plain">;</span>
<<spanclass="cwebmacrodefn">Read the command-line switches</span><spanclass="cwebmacronumber">3.3.1</span>> =
</code></p>
<preclass="displaydefn">
<spanclass="functiontext">CommandLine::declare_heading</span><spanclass="plain">(</span><spanclass="identifier">L</span><spanclass="string">"inblorb: a releaser and packager for IF story files\</span><spanclass="plain">n</span><spanclass="string">\</span><spanclass="plain">n</span><spanclass="string">"</span>
<spanclass="reserved">if</span><spanclass="plain"> (</span><spanclass="identifier">bare_words</span><spanclass="plain">> 0) </span><spanclass="functiontext">Errors::fatal</span><spanclass="plain">(</span><spanclass="string">"if -project is used, no other filenames should be given"</span><spanclass="plain">);</span>
<spanclass="reserved">default</span><spanclass="plain">: </span><spanclass="functiontext">Errors::fatal</span><spanclass="plain">(</span><spanclass="string">"bad command line usage (see -help)"</span><spanclass="plain">);</span>
<spanclass="plain">}</span>
<spanclass="plain">}</span>
</pre>
<pclass="inwebparagraph"></p>
<pclass="endnote">The function Main::switch is used in <ahref="#SP3_3_1">§3.3.1</a>.</p>
<pclass="endnote">The function Main::bareword is used in <ahref="#SP3_3_1">§3.3.1</a>.</p>
<pclass="inwebparagraph"><aid="SP3_3_3"></a><b>§3.3.3. </b>Now let's set the platform-dependent variables.
</p>
<pclass="inwebparagraph">Inblorb generates quite a variety of HTML, for instance to create websites,
but the tricky points below affect only one special page not browsed by
the general public: the results page usually called <codeclass="display"><spanclass="extract">StatusCblorb.html</span></code>
(though this depends on how the <codeclass="display"><spanclass="extract">status</span></code> command is used in the blurb).
The results page is intended only for viewing within the Inform user
interface, and it expects to have two Javascript functions available,
<codeclass="display"><spanclass="extract">openUrl</span></code> and <codeclass="display"><spanclass="extract">fileUrl</span></code>. Because the object structure has needed to be
different for the Windows and OS X user interface implementations of
Javascript, we abstract the prefix for these function calls into the
<pclass="inwebparagraph">causes a link, when clicked, to call the <codeclass="display"><spanclass="extract">openUrl</span></code> function, where <codeclass="display"><spanclass="extract">***</span></code>
is the prelude; similarly for <codeclass="display"><spanclass="extract">fileUrl</span></code>. The first opens a URL in the local
operating system's default web browser, the second opens a file (identified
by a <codeclass="display"><spanclass="extract">file:...</span></code> URL) in the local operating system. These two URLs may
need treatment to handle special characters:
</p>
<pclass="inwebparagraph"></p>
<ulclass="items"><li>(a) "escaping", where spaces in the URL are escaped to <codeclass="display"><spanclass="extract">%2520</span></code>, which
within a Javascript string literal produces <codeclass="display"><spanclass="extract">%20</span></code>, the standard way to
represent a space in a web URL;
</li></ul>
<ulclass="items"><li>(b) "reversing slashes", where backslashes are converted to forward
slashes — useful if the separation character is a backslash, as on Windows,
since backslashes are escape characters in Javascript literals.
</li></ul>
<pclass="macrodefinition"><codeclass="display">
<<spanclass="cwebmacrodefn">Set platform-dependent HTML and Javascript variables</span><spanclass="cwebmacronumber">3.3.3</span>> =
<spanclass="identifier">escape_openUrl</span><spanclass="plain"> = </span><spanclass="constant">TRUE</span><spanclass="plain">; </span><spanclass="comment">we want <codeclass="display"><spanclass="extract">openUrl</span></code> to escape, and <codeclass="display"><spanclass="extract">fileUrl</span></code> not to</span>
<pclass="endnote">The function Main::initialise_time_variables is used in 3/plc (<ahref="3-plc.html#SP2">§2</a>).</p>
<pclass="inwebparagraph"><aid="SP5"></a><b>§5. Opening and closing banners. </b>Note that Inblorb customarily prints informational messages with an initial
<codeclass="display"><spanclass="extract">!</span></code>, so that the piped output from Inblorb could be used as an <codeclass="display"><spanclass="extract">Include</span></code>
file in I6 code, where <codeclass="display"><spanclass="extract">!</span></code> is the comment character; that isn't in fact how
I7 uses Inblorb, but it's traditional for blorbing programs to do this.
<spanclass="identifier">PRINT</span><spanclass="plain">(</span><spanclass="string">"! %S [executing on %S at %S]\</span><spanclass="plain">n</span><spanclass="string">"</span><spanclass="plain">,</span>
<spanclass="identifier">PRINT</span><spanclass="plain">(</span><spanclass="string">"! The blorb spell (safely protect a small object "</span><spanclass="plain">);</span>
<spanclass="identifier">PRINT</span><spanclass="plain">(</span><spanclass="string">"as though in a strong box).\</span><spanclass="plain">n</span><spanclass="string">"</span><spanclass="plain">);</span>
<spanclass="plain">}</span>
</pre>
<pclass="inwebparagraph"></p>
<pclass="endnote">The function Main::print_banner is used in <ahref="#SP3">§3</a>.</p>
<pclass="inwebparagraph"><aid="SP6"></a><b>§6. </b>The concluding banner is much smaller — empty if all went well, a single
comment line if not. But we also generate the status report page (if that has
been requested) — a single HTML file generated from a template by expanding
placeholders in the template. All of the meat of the report is in those
placeholders, of course; the template contains only some fancy formatting.
<<spanclass="cwebmacro">Set a whole pile of placeholders which will be needed to generate the status page</span><spanclass="cwebmacronumber">6.1</span>><spanclass="plain">;</span>
<pclass="endnote">The function Main::print_report is used in <ahref="#SP3">§3</a>, 1/be (<ahref="1-be.html#SP2">§2</a>).</p>
<pclass="inwebparagraph"><aid="SP6_1"></a><b>§6.1. </b>If it isn't apparent what these placeholders do, take a look at
the template file called <codeclass="display"><spanclass="extract">CblorbModel.html</span></code> in the Inform application —
that's where they're used.
</p>
<pclass="macrodefinition"><codeclass="display">
<<spanclass="cwebmacrodefn">Set a whole pile of placeholders which will be needed to generate the status page</span><spanclass="cwebmacronumber">6.1</span>> =
<spanclass="functiontext">Str::literal</span><spanclass="plain">(</span><spanclass="identifier">L</span><spanclass="string">"Inform translated your source text as usual, to manufacture a 'story "</span>
<spanclass="identifier">L</span><spanclass="string">"file': all of that worked fine. But the Release then went wrong, for "</span>
<spanclass="identifier">L</span><spanclass="string">"the following reason:<p><ul>[CBLORBERRORS]</ul>"</span><spanclass="plain">), 0</span>
<spanclass="functiontext">Str::literal</span><spanclass="plain">(</span><spanclass="identifier">L</span><spanclass="string">"All went well. I've put the released material into the 'Release' subfolder "</span>
<spanclass="identifier">L</span><spanclass="string">"of the Materials folder for the project: you can take a look with "</span>
<spanclass="identifier">L</span><spanclass="string">"the menu option <b>Release &gt; Open Materials Folder</b> or by clicking "</span>
<spanclass="identifier">L</span><spanclass="string">"the blue folders above.<p>"</span>
<spanclass="identifier">L</span><spanclass="string">"Releases can range in size from a single blorb file to a medium-sized website. "</span>
<spanclass="identifier">L</span><spanclass="string">"Here's what we currently have:<p>"</span><spanclass="plain">), 0</span>
<spanclass="identifier">PRINT</span><spanclass="plain">(</span><spanclass="string">"! Completed: wrote blorb file with "</span><spanclass="plain">);</span>