<ulclass="crumbs"><li><ahref="../index.html">Home</a></li><li><ahref="../other.html">Other Tools</a></li><li><ahref="index.html">inblorb</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.
<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>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">error_count</span><spanclass="plain"> = </span><spanclass="constant">0</span><spanclass="plain">; </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"> = </span><spanclass="constant">0</span><spanclass="plain">; </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"> = </span><spanclass="constant">0</span><spanclass="plain">; </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"> = </span><spanclass="constant">0</span><spanclass="plain">; </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"> = </span><spanclass="constant">0</span><spanclass="plain">; </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"> = </span><spanclass="constant">0</span><spanclass="plain">; </span><spanclass="comment"> number of those holding source</span>
<spanclass="reserved">int</span><spanclass="plain"></span><spanclass="identifier">sound_resource_num</span><spanclass="plain"> = </span><spanclass="constant">3</span><spanclass="plain">; </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"> = </span><spanclass="constant">1</span><spanclass="plain">; </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>
<<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="functiontext"><ahref="3-cla.html#SP14">CommandLine::declare_heading</a></span><spanclass="plain">(</span><spanclass="identifier">L</span><spanclass="string">"inblorb: a releaser and packager for IF story files\n\n"</span>
<spanclass="reserved">if</span><spanclass="plain"> (</span><spanclass="identifier">bare_words</span><spanclass="plain">></span><spanclass="constant">0</span><spanclass="plain">) </span><spanclass="functiontext"><ahref="3-em.html#SP2">Errors::fatal</a></span><spanclass="plain">(</span><spanclass="string">"if -project is used, no other filenames should be given"</span><spanclass="plain">);</span>
<spanclass="identifier">default:</span><spanclass="plain"></span><spanclass="functiontext"><ahref="3-em.html#SP2">Errors::fatal</a></span><spanclass="plain">(</span><spanclass="string">"bad command line usage (see -help)"</span><spanclass="plain">);</span>
<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="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="reserved">void</span><spanclass="plain"></span><spanclass="functiontext">Main::print_banner<buttonclass="popup"onclick="togglePopup('usagePopup4')">...<spanclass="popuptext"id="usagePopup4">Usage of <b>Main::print_banner</b>:<br><ahref="#SP3">§3</a></span></button></span><spanclass="plain">(</span><spanclass="reserved">void</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="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="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"><ahref="4-sm.html#SP26">Str::literal</a></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">"the following reason:<p><ul>[CBLORBERRORS]</ul>"</span><spanclass="plain">), </span><spanclass="constant">0</span>
<spanclass="functiontext"><ahref="4-sm.html#SP26">Str::literal</a></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">), </span><spanclass="constant">0</span>
<spanclass="identifier">PRINT</span><spanclass="plain">(</span><spanclass="string">"! Completed: wrote blorb file with "</span><spanclass="plain">);</span>