home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
m2latex
/
part03
< prev
next >
Wrap
Text File
|
1991-08-29
|
32KB
|
1,298 lines
Newsgroups: comp.sources.misc
From: Joerg Heitkoetter <heitkoet@gorbi.informatik.uni-dortmund.de>
Subject: v22i081: m2latex - Generate LaTex source from Pascal or Modula-2, Part03/03
Message-ID: <1991Aug30.024540.1258@sparky.IMD.Sterling.COM>
X-Md4-Signature: 2a46b471263679a179184c77f04a343f
Date: Fri, 30 Aug 1991 02:45:40 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Joerg Heitkoetter <heitkoet@gorbi.informatik.uni-dortmund.de>
Posting-number: Volume 22, Issue 81
Archive-name: m2latex/part03
Environment: UNIX, LaTex, Flex
---- Cut Here and feed the following to sh ----
# this is Part.03 (part 3 of a multipart archive)
# do not concatenate these parts, unpack them in order with /bin/sh
# file m2latex.c continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 3; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping m2latex.c'
else
echo 'x - continuing file m2latex.c'
sed 's/^X//' << 'SHAR_EOF' >> 'm2latex.c' &&
X * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
X * EOB_ACT_END_OF_FILE - end of file
X */
X
static int yy_get_next_buffer()
X
X {
X register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
X register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
X register int number_to_move, i;
X int ret_val;
X
X if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
X YY_FATAL_ERROR(
X "fatal flex scanner internal error--end of buffer missed" );
X
X /* try to read more data */
X
X /* first move last chars to start of buffer */
X number_to_move = yy_c_buf_p - yytext;
X
X for ( i = 0; i < number_to_move; ++i )
X *(dest++) = *(source++);
X
X if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
X /* don't do the read, it's not guaranteed to return an EOF,
X * just force an EOF
X */
X yy_n_chars = 0;
X
X else
X {
X int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
X
X if ( num_to_read > YY_READ_BUF_SIZE )
X num_to_read = YY_READ_BUF_SIZE;
X
X else if ( num_to_read <= 0 )
X YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
X
X /* read in more data */
X YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
X yy_n_chars, num_to_read );
X }
X
X if ( yy_n_chars == 0 )
X {
X if ( number_to_move == 1 )
X {
X ret_val = EOB_ACT_END_OF_FILE;
X yy_current_buffer->yy_eof_status = EOF_DONE;
X }
X
X else
X {
X ret_val = EOB_ACT_LAST_MATCH;
X yy_current_buffer->yy_eof_status = EOF_PENDING;
X }
X }
X
X else
X ret_val = EOB_ACT_CONTINUE_SCAN;
X
X yy_n_chars += number_to_move;
X yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
X yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
X
X /* yytext begins at the second character in yy_ch_buf; the first
X * character is the one which preceded it before reading in the latest
X * buffer; it needs to be kept around in case it's a newline, so
X * yy_get_previous_state() will have with '^' rules active
X */
X
X yytext = &yy_current_buffer->yy_ch_buf[1];
X
X return ( ret_val );
X }
X
X
/* yy_get_previous_state - get the state just before the EOB char was reached
X *
X * synopsis
X * yy_state_type yy_get_previous_state();
X */
X
static yy_state_type yy_get_previous_state()
X
X {
X register yy_state_type yy_current_state;
X register YY_CHAR *yy_cp;
X
X register YY_CHAR *yy_bp = yytext;
X
X yy_current_state = yy_start;
X if ( yy_bp[-1] == '\n' )
X ++yy_current_state;
X
X for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
X {
X register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1);
X if ( yy_accept[yy_current_state] )
X {
X yy_last_accepting_state = yy_current_state;
X yy_last_accepting_cpos = yy_cp;
X }
X while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
X {
X yy_current_state = yy_def[yy_current_state];
X if ( yy_current_state >= 591 )
X yy_c = yy_meta[yy_c];
X }
X yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
X }
X
X return ( yy_current_state );
X }
X
X
/* yy_try_NUL_trans - try to make a transition on the NUL character
X *
X * synopsis
X * next_state = yy_try_NUL_trans( current_state );
X */
X
#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
register yy_state_type yy_current_state;
#endif
X
X {
X register int yy_is_jam;
X register YY_CHAR *yy_cp = yy_c_buf_p;
X
X register YY_CHAR yy_c = 1;
X if ( yy_accept[yy_current_state] )
X {
X yy_last_accepting_state = yy_current_state;
X yy_last_accepting_cpos = yy_cp;
X }
X while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
X {
X yy_current_state = yy_def[yy_current_state];
X if ( yy_current_state >= 591 )
X yy_c = yy_meta[yy_c];
X }
X yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
X yy_is_jam = (yy_current_state == 590);
X
X return ( yy_is_jam ? 0 : yy_current_state );
X }
X
X
#ifdef YY_USE_PROTOS
static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
#else
static void yyunput( c, yy_bp )
YY_CHAR c;
register YY_CHAR *yy_bp;
#endif
X
X {
X register YY_CHAR *yy_cp = yy_c_buf_p;
X
X /* undo effects of setting up yytext */
X *yy_cp = yy_hold_char;
X
X if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X { /* need to shift things up to make room */
X register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
X register YY_CHAR *dest =
X &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
X register YY_CHAR *source =
X &yy_current_buffer->yy_ch_buf[number_to_move];
X
X while ( source > yy_current_buffer->yy_ch_buf )
X *--dest = *--source;
X
X yy_cp += dest - source;
X yy_bp += dest - source;
X yy_n_chars = yy_current_buffer->yy_buf_size;
X
X if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X YY_FATAL_ERROR( "flex scanner push-back overflow" );
X }
X
X if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
X yy_cp[-2] = '\n';
X
X *--yy_cp = c;
X
X /* note: the formal parameter *must* be called "yy_bp" for this
X * macro to now work correctly
X */
X YY_DO_BEFORE_ACTION; /* set up yytext again */
X }
X
X
#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
X
X {
X int c;
X YY_CHAR *yy_cp = yy_c_buf_p;
X
X *yy_cp = yy_hold_char;
X
X if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
X {
X /* yy_c_buf_p now points to the character we want to return.
X * If this occurs *before* the EOB characters, then it's a
X * valid NUL; if not, then we've hit the end of the buffer.
X */
X if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
X /* this was really a NUL */
X *yy_c_buf_p = '\0';
X
X else
X { /* need more input */
X yytext = yy_c_buf_p;
X ++yy_c_buf_p;
X
X switch ( yy_get_next_buffer() )
X {
X case EOB_ACT_END_OF_FILE:
X {
X if ( yywrap() )
X {
X yy_c_buf_p = yytext + YY_MORE_ADJ;
X return ( EOF );
X }
X
X YY_NEW_FILE;
X
#ifdef __cplusplus
X return ( yyinput() );
#else
X return ( input() );
#endif
X }
X break;
X
X case EOB_ACT_CONTINUE_SCAN:
X yy_c_buf_p = yytext + YY_MORE_ADJ;
X break;
X
X case EOB_ACT_LAST_MATCH:
#ifdef __cplusplus
X YY_FATAL_ERROR( "unexpected last match in yyinput()" );
#else
X YY_FATAL_ERROR( "unexpected last match in input()" );
#endif
X }
X }
X }
X
X c = *yy_c_buf_p;
X yy_hold_char = *++yy_c_buf_p;
X
X return ( c );
X }
X
X
#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
X
X {
X yy_init_buffer( yy_current_buffer, input_file );
X yy_load_buffer_state();
X }
X
X
#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
X
X {
X if ( yy_current_buffer == new_buffer )
X return;
X
X if ( yy_current_buffer )
X {
X /* flush out information for old buffer */
X *yy_c_buf_p = yy_hold_char;
X yy_current_buffer->yy_buf_pos = yy_c_buf_p;
X yy_current_buffer->yy_n_chars = yy_n_chars;
X }
X
X yy_current_buffer = new_buffer;
X yy_load_buffer_state();
X
X /* we don't actually know whether we did this switch during
X * EOF (yywrap()) processing, but the only time this flag
X * is looked at is after yywrap() is called, so it's safe
X * to go ahead and always set it.
X */
X yy_did_buffer_switch_on_eof = 1;
X }
X
X
#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
X
X {
X yy_n_chars = yy_current_buffer->yy_n_chars;
X yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
X yyin = yy_current_buffer->yy_input_file;
X yy_hold_char = *yy_c_buf_p;
X }
X
X
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
X
X {
X YY_BUFFER_STATE b;
X
X b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
X
X if ( ! b )
X YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X b->yy_buf_size = size;
X
X /* yy_ch_buf has to be 2 characters longer than the size given because
X * we need to put in 2 end-of-buffer characters.
X */
X b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
X
X if ( ! b->yy_ch_buf )
X YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X yy_init_buffer( b, file );
X
X return ( b );
X }
X
X
#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
X
X {
X if ( b == yy_current_buffer )
X yy_current_buffer = (YY_BUFFER_STATE) 0;
X
X free( (char *) b->yy_ch_buf );
X free( (char *) b );
X }
X
X
#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif
X
X {
X b->yy_input_file = file;
X
X /* we put in the '\n' and start reading from [1] so that an
X * initial match-at-newline will be true.
X */
X
X b->yy_ch_buf[0] = '\n';
X b->yy_n_chars = 1;
X
X /* we always need two end-of-buffer characters. The first causes
X * a transition to the end-of-buffer state. The second causes
X * a jam in that state.
X */
X b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
X b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
X
X b->yy_buf_pos = &b->yy_ch_buf[1];
X
X b->yy_eof_status = EOF_NOT_SEEN;
X }
# line 243 "m2latex.l"
X
X
#include "main.c"
SHAR_EOF
echo 'File m2latex.c is complete' &&
chmod 0640 m2latex.c ||
echo 'restore of m2latex.c failed'
Wc_c="`wc -c < 'm2latex.c'`"
test 59511 -eq "$Wc_c" ||
echo 'm2latex.c: original size 59511, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= m2latex.l ==============
if test -f 'm2latex.l' -a X"$1" != X"-c"; then
echo 'x - skipping m2latex.l (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting m2latex.l (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'm2latex.l' &&
/*
X * This is a flex input file but should be edited in -*-C-*- mode
X *
X * Modula2LaTeX 1.0:
X * Produce prettyprinted LaTeX files from Modula-2 or Pascal sources.
X *
X * Copyright (C) 1991 Joerg Heitkoetter
X * Systems Analysis Group, University of Dortmund
X * (heitkoet@gorbi.informatik.uni-dortmund.de).
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X */
X
%x STRING COMMENT
%s MODULA2
X
%{
#define KEY printf ("{\\%s %s}", keyword_font, yytext)
#define STDFUN unput("("); printf ("{\\%s %s} (", stdfun_font, yytext)
#define SYM(x) printf ("$\\%s$", x)
#define OUT(x) printf ("%s", x)
#define CTAB printf ("\\hspace*{%d\\indentation}", tabtocomment)
#define FONT(x) printf ("{\\%s ",x);
#define SUB(x) substitute(x)
#define IND indent(yytext)
#define INIT BEGIN (modula_mode ? MODULA2 : INITIAL);
#define REPARSE yyless (0)
X
#include <stdio.h>
X
#define ON (1)
#define OFF (0)
X
int modula_mode = ON;
X
int complete_file = OFF;
int header = OFF;
int tabtotab = 8;
int piped = OFF;
X
int aligntoright = ON; /* align comments to the right -joke */
int tabtocomment = 4; /* distance between statement and corresponding comment -joke */
X
char *indentation = "0.5em";
X
char* font_size = "10";
char* comment_font = "it";
char* keyword_font = "bf";
char* header_font = "sl";
char* stdfun_font = "bf";
char* string_font = "tt";
X
#ifdef __STDC__
void substitute(const char*);
void indent(const char*);
void newpage(int);
void usage(const char*);
#else
void substitute();
void indent();
void newpage();
void usage();
#endif
%}
X
%%
X
X INIT;
X
"CHR"[ \t]*"(" |
"DIV"[ \t]*"(" |
"DISPOSE"[ \t]*"(" |
"MOD"[ \t]*"(" |
"NEW"[ \t]*"(" |
"SUCC"[ \t]*"(" |
"ORD"[ \t]*"(" |
"ODD"[ \t]*"(" |
"PRED"[ \t]*"(" |
"ROUND"[ \t]*"(" |
"TRUNC"[ \t]*"(" |
<MODULA2>"ABS"[ \t]*"(" |
<MODULA2>"CAP"[ \t]*"(" |
<MODULA2>"EXCL"[ \t]*"(" |
<MODULA2>"FLOAT"[ \t]*"(" |
<MODULA2>"HIGH"[ \t]*"(" |
<MODULA2>"INCL"[ \t]*"(" |
<MODULA2>"MIN"[ \t]*"(" |
<MODULA2>"MAX"[ \t]*"(" |
<MODULA2>"REAL"[ \t]*"(" |
<MODULA2>"VAL"[ \t]*"(" |
<MODULA2>"DEC"[ \t]*"(" |
<MODULA2>"INC"[ \t]*"(" STDFUN;
X
"AND" |
"ARRAY" |
"BEGIN" |
"CASE" |
"CONST" |
"DO" |
"DOWNTO" |
"ELSE" |
"END" |
"EXIT" |
"FOR" |
"FUNCTION" |
"FROM" |
"IF" |
"HALT" |
"IN" |
"NOT" |
"OF" |
"OR" |
"PACKED" |
"PROCEDURE" |
"RECORD" |
"REPEAT" |
"SET" |
"STRING" |
"THEN" |
"TO" |
"TYPE" |
"UNTIL" |
"VAR" |
"WHILE" |
"WITH" |
"INTEGER" |
"CHAR" |
"REAL" |
"BOOLEAN" |
"NIL" |
<MODULA2>"SHORTINT" |
<MODULA2>"CARDINAL" |
<MODULA2>"SHORTCARD" |
<MODULA2>"BITSET" |
<MODULA2>"PROC" |
<MODULA2>"BY" |
<MODULA2>"DEFINITION" |
<MODULA2>"ELSIF" |
<MODULA2>"EXPORT" |
<MODULA2>"FOREIGN" | /* Mocka special -joke */
<MODULA2>"IMPLEMENTATION" |
<MODULA2>"IMPORT" |
<MODULA2>"LOOP" |
<MODULA2>"MODULE" |
<MODULA2>"POINTER" |
<MODULA2>"RETURN" |
<MODULA2>"QUALIFIED" KEY;
X
"<=" SYM ("leq");
">=" SYM ("geq");
"<>" SYM ("neq");
"*" SYM ("ast");
"^" SYM ("wedge");
"|" SYM ("mid");
<MODULA2>"#" SYM ("neq");
<MODULA2>"~" SYM ("sim");
"<" OUT ("$<$");
">" OUT ("$>$");
"{" OUT ("\\{");
"}" OUT ("\\}");
<MODULA2>"&" OUT ("\\&");
":" |
"=" |
"," |
"." |
";" |
"-" |
"+" |
"/" |
":=" |
"(" |
")" |
"[" |
"]" ECHO;
X
<MODULA2>[a-zA-Z_$][a-zA-Z_$0-9]* |
[a-zA-Z_][a-zA-Z_0-9]* SUB (yytext);
X
^[ \t]*"(*" { BEGIN (COMMENT);
X FONT (comment_font);
X REPARSE; }
X
"(*" { BEGIN (COMMENT);
X if (aligntoright) {
X OUT ("\\hfill");
X } else {
X CTAB;
X }
X FONT (comment_font);
X OUT ("($\\ast$"); }
X
<COMMENT>"*)" { INIT; OUT ("$\\ast$)}"); }
<COMMENT>"\n" OUT ("\\mbox{}\\\\\n");
<COMMENT>[ \t]+ IND;
<COMMENT>. SUB (yytext);
X
L?\" { BEGIN (STRING);
X FONT (string_font); OUT ("\""); }
<STRING>"\"" { INIT; OUT ("\"}"); }
X
L?' { BEGIN (STRING);
X FONT (string_font); OUT ("'"); }
<STRING>"'" { INIT; OUT ("'}"); }
<STRING>"\n" OUT ("\\mbox{}\\\\\n");
<STRING>^[ \t]+ IND;
<STRING>. SUB (yytext);
X
([0-9]*\.[0-9]+[fFlL]?) |
([0-9]+\.[0-9]*[fFlL]?) |
([0-9]*\.?[0-9]+[eE][+-]?[0-9]+) |
([0-9]+\.?[0-9]*[eE][+-]?[0-9]+) ECHO;
X
[0-9]+[uUlL]? ECHO;
X
L?'[ -~]' |
L?'\\[ntvbrfa\\?'"]' |
L?'\\[0-7]{1,3}' |
L?'\\x[0-9a-fA-F]{1,2}' SUB (yytext);
X
0[0-7]+[uUlL]? ECHO;
X
0x[0-9a-fA-F]+[uUlL]? ECHO;
X
"\\\n" OUT ("$\\backslash$\\\\\n");
^[ \t]+ IND;
[ \t]+ ECHO;
"\f"[\n]? OUT ("\\newpage\n");
"\n" OUT ("\\mbox{}\\\\\n");
X
%%
X
#include "main.c"
SHAR_EOF
chmod 0640 m2latex.l ||
echo 'restore of m2latex.l failed'
Wc_c="`wc -c < 'm2latex.l'`"
test 5245 -eq "$Wc_c" ||
echo 'm2latex.l: original size 5245, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= m2latex.man ==============
if test -f 'm2latex.man' -a X"$1" != X"-c"; then
echo 'x - skipping m2latex.man (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting m2latex.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'm2latex.man' &&
X
X
X
M2LATEX(1) USER COMMANDS M2LATEX(1)
X
X
X
NAME
X m2latex - a Modula-2 to LaTeX converter
X
X
SYNOPSIS
X _m_2_l_a_t_e_x [-c] [-h] [-i length] [-n] [-o file] [-p] [-s
X fontsize] [-H font] [-K font] [-P] [-S [+complete-file]
X [+header] [+indentation length] [+output file] [+font-size
X size] [+pipe] [+comment-font font] [+function-font font]
X [+keyword-font font] [+pascal] [+header-font font]
X [+string-font font] [+tabstop width] [+version] _f_i_l_e
X
X
DESCRIPTION
X _m_2_l_a_t_e_x is a tool for generating _L_a_T_e_X sources from Pascal
X or Modula-2 It recogizes all keywords, strings, and com-
X ments. These recognized parts can be typeset in different
X fonts. _m_2_l_a_t_e_x can generate complete _L_a_T_e_X files which can
X pass directly through latex(1) or parts of _L_a_T_e_X files which
X can be included in other files (either direct or by the
X \input or \include commands).
X
X The output filename is searched in various steps. First, if
X the {-o,+output} flag is given, the output is written to the
X file pointed to by the value of this flag. If the {-p,+pipe}
X option is given, the output is written to _s_t_d_o_u_t. (It is an
X error to specify both options together.) If none of these
X options but an input filename is given, the output is writ-
X ten to a file who's name is the last component of the input
X filename with the added suffix '.tex'.
X
X
OPTIONS
X _m_2_l_a_t_e_x recognizes the following options:
X
X {-c,+complete-file}
X The output is enveloped in commands which produce a
X complete _L_a_T_e_X source.
X
X {-h,+header}
X Each page of output has a header giving the input file
X name. This option implies the {-c,+complete-file}
X option.
X
X {-i,+indentation} length
X Gives the amount of indentation for each leading blank
X (tabs are converted to blanks). Default is `0.5em'.
X
X {-n,+no-alignment}
X Comments belonging to statements are aligned to the
X right paper side by default. You can turn off this
X behaviour using this switch.
X
X
X
MAGPIE Release 1.0 Last change: 29 August 1991 1
X
X
X
X
X
X
M2LATEX(1) USER COMMANDS M2LATEX(1)
X
X
X
X {-o,+output} _f_i_l_e
X The output is written in the file pointed to by _f_i_l_e.
X
X {-s,+font-size} _s_i_z_e
X The LaTeX source is set in _s_i_z_ept. Default is `10'.
X
X {-p,+pipe}
X The output is written to stdout.
X
X {-C,+comment-font} _f_o_n_t
X The comments are set in the given font. Default is
X `it'.
X
X {-F,+function-font} _f_o_n_t
X The standard functions are set in the given font.
X Default is `bf'.
X
X {-H,+header-font} _f_o_n_t
X The headers are set in the given font. Default is `sl'.
X
X {-K,+keyword-font} _f_o_n_t
X The keywords are set in the given font. Default is
X `bf'.
X
X {-P,+pascal} _f_o_n_t
X recognize Pascal keywords, only. Keywords must be writ-
X ten in uppercase letters!
X
X {-S,+string-font} _f_o_n_t
X The string and character constants are set in the given
X font. Default is `tt'.
X
X {-T,+tabstop} _w_i_d_t_h
X The width of tabs is _w_i_d_t_h. Default is `8'.
X
X {-V,+version}
X Prints the version number on _s_t_d_e_r_r.
X
X
OPTION SUMMARY
X To give no option at all is the same as to give the options
X -i 0.5em -s 10 -C it -F bf -H sl -K bf -S tt -T 8
X
X
SEE ALSO
X c++2latex(1), latex(1).
X
X
DIAGNOSTICS
X _C_a_n'_t _u_s_e {-_p,+_p_i_p_e} _a_n_d {-_o,+_o_u_t_p_u_t} _t_o_g_e_t_h_e_r.
X At most one of this options may be given.
X
X
X
X
MAGPIE Release 1.0 Last change: 29 August 1991 2
X
X
X
X
X
X
M2LATEX(1) USER COMMANDS M2LATEX(1)
X
X
X
X _C_a_n'_t _o_p_e_n `<_f_i_l_e>' _f_o_r _r_e_a_d_i_n_g
X The program failed to open <file> for reading.
X
X _C_a_n'_t _o_p_e_n `<_f_i_l_e>' _f_o_r _w_r_i_t_i_n_g
X The program failed to open <file> for writing. All out-
X put is written in the current directory if not expli-
X citly changed by {-o,+output}.
X
X _V_i_r_t_u_a_l _m_e_m_o_r_y _e_x_h_a_u_s_t_e_d
X The program failed to allocate storage. As this is only
X done for the construction of filenames, this error will
X normally indicate a program error.
X
X
AUTHOR
X Copyright (C) 1991 by Joerg Heitkoetter, Systems Analysis
X Group, University of Dortmund, Germany.
X Send bugs, comments, etc., to (heitkoet@gorbi.informatik.uni-dortmund.de).
X
X
CREDITS
X Thanks to Norbert Kiesel for his C++2LaTeX converter, show-
X ing me how to flex(1) something like this.
X
X
AVAILABILITY
X This program is under GNU General Public License. Refer to
X the LICENSE file accompanying this software for a lengthy,
X boring, but absolutely complete description.
X
X
FINAL NOTE
X If you want to use _m_2_l_a_t_e_x as a Pascal pretty printer only,
X simply install it as a (soft) link to ``p2latex''. The
X Modula-2 mode is switched on, when _m_2_l_a_t_e_x finds the letter
X ``m'' in it's name during execution.
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
MAGPIE Release 1.0 Last change: 29 August 1991 3
X
X
X
SHAR_EOF
chmod 0640 m2latex.man ||
echo 'restore of m2latex.man failed'
Wc_c="`wc -c < 'm2latex.man'`"
test 5672 -eq "$Wc_c" ||
echo 'm2latex.man: original size 5672, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= main.c ==============
if test -f 'main.c' -a X"$1" != X"-c"; then
echo 'x - skipping main.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting main.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
/*
X * Modula2LaTeX 1.0:
X * Produce pretty printed LaTeX files from Modula-2 and Pascal sources.
X *
X * Copyright (C) 1991 Joerg Heitkoetter
X * Systems Analysis Group, University of Dortmund (UNIDO)
X * (heitkoet@gorbi.informatik.uni-dortmund.de).
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X */
X
void
substitute (input)
char *input;
{
X while (*input) {
X switch (*input) {
X case '_':
X case '&':
X case '#':
X case '$':
X case '%':
X case '{':
X case '}':
X printf ("\\%c", *input);
X break;
X case '+':
X case '=':
X case '<':
X case '>':
X printf ("$%c$", *input);
X break;
X case '*':
X printf ("$\\ast$");
X break;
X case '|':
X printf ("$\\mid$");
X break;
X case '\\':
X printf ("$\\backslash$");
X break;
X case '^':
X printf ("$\\wedge$");
X break;
X case '~':
X printf ("$\\sim$");
X break;
X default:
X printf ("%c", *input);
X break;
X }
X input++;
X }
}
X
void
indent (blanks)
char *blanks;
{
X int i;
X
X i = 0;
X while (*blanks) {
X if (*blanks == ' ') {
X i++;
X } else { /* *blanks == '\t' */
X while (++i % tabtotab);
X }
X blanks++;
X }
X printf ("\\hspace*{%d\\indentation}", i);
}
X
#include "getopt.h"
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <time.h>
X
extern char *version_string;
X
static struct option opts[] =
{
X {"complete-file", 0, 0, 'c'},
X {"font-size", 1, 0, 's'},
X {"indentation", 1, 0, 'i'},
X {"header", 0, 0, 'h'},
X {"piped", 0, 0, 'p'},
X {"alignment", 0, 0, 'n'}, /* turn off comment alignment -joke */
X {"output", 1, 0, 'o'},
X {"tabstop", 1, 0, 'T'},
X {"comment-font", 1, 0, 'C'},
X {"function-font", 1, 0, 'F'},
X {"string-font", 1, 0, 'S'},
X {"keyword-font", 1, 0, 'K'},
X {"header-font", 1, 0, 'H'},
X {"pascal", 0, 0, 'P'},
X {"version", 0, 0, 'V'},
X {0, 0, 0, 0}
};
X
X
main (argc, argv)
int argc;
char **argv;
{
X int c;
X int index;
X int i;
X int has_filename;
X char *input_name;
X char *output_name;
X char *program_name;
X long now;
X char *today;
X char *malloc ();
X
X input_name = "Standard Input";
X output_name = 0;
X
X now = time (0);
X today = ctime (&now);
X
X program_name = strrchr (argv[0], '/');
X if (program_name == NULL) { /* no pathname */
X program_name = argv[0];
X } else {
X program_name++;
X }
X
X /* simple heuristic: 'm' in name means Modula-2 */
X modula_mode = (strchr (program_name, 'm') != 0);
X
X if (argc == 1)
X usage (program_name); /* added exit with usage -joke */
X
X while ((c = getopt_long (argc, argv,
X "cpno:s:i:b:hT:C:F:H:S:K:P:V", opts, &index))
X != EOF) {
X if (c == 0) { /* Long option */
X c = opts[index].val;
X }
X switch (c) {
X case 'c':
X complete_file = 1;
X break;
X case 'o':
X if (piped) {
X fprintf (stderr,
X "%s: Can't use {-p,+pipe} and {-o,+output} together\n",
X program_name);
X exit (5);
X }
X output_name = optarg;
X break;
X case 'n':
X aligntoright = 0;
X break;
X case 's':
X font_size = optarg;
X break;
X case 'i':
X indentation = optarg;
X break;
X case 'T':
X tabtotab = atoi (optarg);
X break;
X case 'p':
X if (output_name != 0) {
X fprintf (stderr,
X "%s: Can't use {-p,+pipe} and {-o,+output} together\n",
X program_name);
X exit (5);
X }
X piped = 1;
X break;
X case 'h':
X header = 1;
X complete_file = 1; /* header implies
X * complete-file */
X break;
X case 'C':
X comment_font = optarg;
X break;
X case 'F':
X stdfun_font = optarg;
X break;
X case 'H':
X header_font = optarg;
X break;
X case 'S':
X string_font = optarg;
X break;
X case 'K':
X keyword_font = optarg;
X break;
X case 'P':
X modula_mode = 0;
X break;
X case 'V':
X fprintf (stderr, "%s\n", version_string);
X break;
X default:
X usage (program_name);
X }
X }
X has_filename = (argc - optind == 1);
X if (has_filename) { /* last argument is input file name */
X input_name = argv[optind];
X if (freopen (input_name, "r", stdin) == NULL) {
X fprintf (stderr, "%s: Can't open `%s' for reading\n",
X program_name, input_name);
X exit (2);
X }
X }
X if ((output_name == 0) && !piped) {
X char *tmp;
X if (has_filename) {
X tmp = strrchr (input_name, '/');
X if (tmp == 0) { /* plain filename */
X tmp = input_name;
X } else {
X tmp++;
X }
X } else {
X tmp = program_name;
X }
X output_name = malloc (strlen (tmp) + 4);
X if (output_name == 0) {
X fprintf (stderr, "%s: Virtual memory exhausted\n", program_name);
X exit (3);
X }
X strcpy (output_name, tmp);
X strcat (output_name, ".tex");
X }
X if (!piped) {
X if (freopen (output_name, "w", stdout) == NULL) {
X fprintf (stderr, "%s: Can't open `%s' for writing\n",
X program_name, output_name);
X exit (3);
X }
X }
X printf ("\
%%\n\
%% This file was automatically produced at %.24s by\n\
%% %s", today, program_name);
X for (i = 1; i < argc; i++) {
X printf (" %s", argv[i]);
X }
X if (!has_filename) {
X printf (" (from Standard Input)");
X }
X printf ("\n%%\n");
X if (complete_file) {
X if (header) {
X if (strcmp (font_size, "10") == 0) {
X printf ("\\documentstyle[fancyheadings]{article}\n");
X } else {
X printf ("\\documentstyle[%spt,fancyheadings]{article}\n",
X font_size);
X }
X } else {
X if (strcmp (font_size, "10") == 0) {
X printf ("\\documentstyle{article}\n");
X } else {
X printf ("\\documentstyle[%spt]{article}\n", font_size);
X }
X }
X printf ("\\setlength{\\textwidth}{16cm}\n");
X printf ("\\setlength{\\textheight}{23cm}\n");
X printf ("\\setlength{\\hoffset}{-2cm}\n");
X printf ("\\setlength{\\voffset}{-2cm}\n");
X if (header) {
X printf ("\\lhead{\\%s ", header_font);
X substitute (input_name);
X printf ("}");
X printf ("\\rhead{\\rm\\thepage}\n");
X printf ("\\cfoot{}\n");
X printf ("\\addtolength{\\headheight}{14pt}\n");
X printf ("\\pagestyle{fancy}\n");
X }
X printf ("\\begin{document}\n");
X }
X printf ("\\expandafter\\ifx\\csname indentation\\endcsname\\relax%\n");
X printf ("\\newlength{\\indentation}\\fi\n");
X printf ("\\setlength{\\indentation}{%s}\n", indentation);
X printf ("\\begin{flushleft}\n");
X yylex ();
X printf ("\\end{flushleft}\n");
X if (complete_file) {
X printf ("\\end{document}\n");
X }
X exit (0);
}
X
void
usage (name)
char *name;
{
X fprintf (stderr, "%s\n", version_string);
X fprintf (stderr, "\
Usage: %s [options] file\n\n\
Options:\n\
X [-c] [-h]\n\
X [-i length] [-n]\n\
X [-o file] [-p]\n\
X [-s fontsize] [-C font]\n\
X [-F font [-H font]\n\
X [-K font] [-P]\n\
X [-S font] [-T tabulatorwidth]\n\
X [-V]\n\
X \n\
X [+complete-file] [+header]\n\
X [+indentation length] [+no-alignment]\n\
X [+output file] [+pipe]\n\
X [+font-size size] [+comment-font font]\n\
X {+function-font font [+keyword-font font]\n\
X [+pascal] [+header-font font]\n\
X [+string-font font] [+tabstop width]\n\
X [+version]\n", name);
X exit (1);
}
SHAR_EOF
chmod 0640 main.c ||
echo 'restore of main.c failed'
Wc_c="`wc -c < 'main.c'`"
test 7449 -eq "$Wc_c" ||
echo 'main.c: original size 7449, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= version.c ==============
if test -f 'version.c' -a X"$1" != X"-c"; then
echo 'x - skipping version.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting version.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'version.c' &&
char* version_string = "m2latex Version 1.0, Patchlevel 1";
SHAR_EOF
chmod 0640 version.c ||
echo 'restore of version.c failed'
Wc_c="`wc -c < 'version.c'`"
test 60 -eq "$Wc_c" ||
echo 'version.c: original size 60, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
rm -f _shar_seq_.tmp
echo You have unpacked the last part
exit 0
exit 0 # Just in case...