GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing jkorpela.fi — Using a C preprocessor as an HTML authoring tool Using a C preprocessor as an HTML authoring toolThe Web Authoring FAQ contains an answer to the question How do I include one file in another?, mentioning C preprocessor as one possible technique. This document gives some details about that approach, which lets you do some common tasks like file inclusion and simple macros easily, assuming just that you have a C compiler at your disposal. The definition of the
C programming language specifies, in addition to the
statements of the language, a set of
preprocessing directives. For example,
Options neededThe options (switches) you need to give in such a case depend on the C compiler. The following instructions apply to the Gnu C compiler (gcc). For other compilers, the options could be similar, but please check the applicable manuals.
When these options are used, gcc writes the preprocessed data
(e.g. with Do you find the use of the extension ExampleThe following simple document contains two
Processed the way described above, we get the following HTML document:
Error messages you may getYou might get error messages like the following from the preprocessor: foo.htm:8: unterminated character constant The reason is that the preprocessor parses its input
according to certain rules, recognizing things like quoted strings.
For example, if your document contains the word It is advisable to take a look at the lines reported in such
messages. They might contain real typos, even unclosed attribute
values in HTML. But in cases like the one mentioned as an example above,
you can just ignore the messages. However, if they bother you, you
can prevent them by
presenting the "homeless" apostrophes and quotation marks as
numeric character references, namely MacrosYou can also define and macros of your own. The simplest use
is for defining constants such as short names
for long words and phrases. Example:
Remember that in C, a newline terminates a macro definition.
Use backslash ( A macro can have arguments too. An example: #define TITLE(thetitle) <title>thetitle</title><h2>thetitle</h2>
You could put that definition into your generic #include "start.html" TITLE(Simple demo) Some extra spaces might be inserted by the preprocessor, but normally
they don't matter in HTML. The macro invocation
<title> Simple demo </title><h2> Simple demo </h2> Care must be taken when a macro invocation appears between quotation marks. You need to write a directive like #define Q(string) # string for such cases. The usage is probably best illustrated by an example which I used when generating a page for testing the effect of some CSS rules. I needed to write lots of things like <span style="font-size: xx-small ;font-family:sans-serif"> with different size specifiers appearing in place of #define Q(string) # string #define STY(siz) <span style=Q(font-size: SIZE ;font-family:sans-serif)> and use Having written this document, I found the document Using the C Preprocessor to Maintain HTML Code by Dr. George F. Corliss. It gives a nice overview of what else you might do with a C preprocessor, and a real-life illustration. And I found it via Micodocs, specifically via the nice, descriptive list HTML Preprocessors. Consider taking a look before deciding which preprocessor you'd like to use. It depends on the complexity of the desired preprocessing; the usefulness of a C preprocessor for HTML documents is relatively limited. In particular, note that the GTML preprocessor lets you use a syntax similar to the one discussed here, and is easy to use; you can start with simple features, then proceed to more advanced issues if needed. Date of last update: 2000-06-07 Jukka KorpelaBelorussian translation Выкарыстанне прэпрацэсара C у якасці прылады HTML аўтарская provided by fatcow. Ukrainian translation Використання препроцесора C як засіб розробки HTML provided by Jim Jerginson. | ||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |