enscript: Output Languages
1
1 8.3 Output Languages
1 ====================
1
1 -- Function: map_color (r, g, b)
1
1 -- Function: language_print (string)
1
1 -- Function: language_symbol (symbol)
1
1 -- Function: header ()
1
1 -- Function: trailer ()
1
1 -- Function: face_on (face)
1
1 -- Function: face_off (face)
1
1 -- Variable: LANGUAGE_SPECIALS
1
1 The following example creates a new output language `simple_html'
1 that creates simple HTML outputs. The output language is defined in a
1 file called `lang_simple_html.st'. The file must define a state called
1 `lang_simple_html'. The file can be located in any directory that is
1 in the load path of the states program.
1
1 The output language definitions are defined in the `BEGIN' block of
1 the `lang_simple_html' state. Please, note that the `BEGIN' block is
1 ended with a `return'-statement. This statement will return the
1 control to the calling state that is the start state of the enscript
1 highlight program. If the `return'-statement was omitted, the states
1 would start processing the input with the `lang_simple_html' state
1 which is obviously a wrong choice.
1
1 state lang_simple_html
1 {
1 BEGIN {
1 sub map_color (r, g, b)
1 {
1 return sprintf ("#%02X%02X%02X", r, g, b);
1 }
1
1 sub language_print (str)
1 {
1 str = regsuball (str, /\&/, "&");
1 str = regsuball (str, /</, "<");
1 str = regsuball (str, />/, ">");
1 str = regsuball (str, /\"/, """);
1 print (str);
1 }
1
1 sub language_symbol (symbol)
1 {
1 return false;
1 }
1
1 sub header ()
1 {
1 print ("<html>\n<head>\n<title>Simple HTML Output</title>\n");
1 print ("</head>\n<body>\n");
1 }
1
1 sub trailer ()
1 {
1 print ("</body>\n</html>\n");
1 }
1
1 sub fase_on (face)
1 {
1 if (face(boldp])
1 print ("<B>");
1 if (face(italicp])
1 print ("<I>");
1 if (face[fg_color])
1 print ("<FONT COLOR=\", face[fg_color], "\">");
1 }
1
1 sub face_off (face)
1 {
1 if (face[fg_color])
1 print ("</FONT>");
1 if (face[italicp])
1 print ("</I>");
1 if (face[boldp])
1 print ("</B>");
1 }
1
1 LANGUAGE_SPECIALS = /[<>\&\"]/;
1
1 return;
1 }
1 }
1