home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume41 / p2latex / part03 < prev    next >
Encoding:
Text File  |  1994-01-09  |  48.4 KB  |  1,649 lines

  1. Newsgroups: comp.sources.misc
  2. From: torsten@diku.dk (Torsten Poulin Nielsen)
  3. Subject: v41i085:  p2latex - Pascal to LaTeX v1.0, Part03/03
  4. Message-ID: <1994Jan10.035631.13918@sparky.sterling.com>
  5. X-Md4-Signature: 95fd2f203dc2de43c37278652d4a6a25
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 10 Jan 1994 03:56:31 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: torsten@diku.dk (Torsten Poulin Nielsen)
  12. Posting-number: Volume 41, Issue 85
  13. Archive-name: p2latex/part03
  14. Environment: UNIX, AmigaDOS
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  Makefile.unix alloca.c fancyheadings.doc fancyheadings.sty
  21. #   getopt.h getopt1.c main.c p2latex.l
  22. # Wrapped by kent@sparky on Sun Jan  9 21:45:40 1994
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 3 (of 3)."'
  26. if test -f 'Makefile.unix' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Makefile.unix'\"
  28. else
  29.   echo shar: Extracting \"'Makefile.unix'\" \(730 characters\)
  30.   sed "s/^X//" >'Makefile.unix' <<'END_OF_FILE'
  31. X#
  32. X#    Simple Unix Makefile for p2latex
  33. X#    Torsten Poulin <torsten@diku.dk>
  34. X#
  35. X
  36. XSHELL        = /bin/sh
  37. XPRG        = p2latex
  38. X
  39. XLEX        = flex
  40. XLEXOPTS     = -i -8
  41. X#              ^ so we can handle 8-bit char sets
  42. X
  43. XROFF        = groff
  44. XROFFOPTS    = -Tlatin1
  45. X
  46. XCC        = gcc
  47. XCCFLAGS        = -O2
  48. X
  49. XOBJ        = alloca.o p2latex.o main.o getopt.o getopt1.o \
  50. X          version.o allocate.o 
  51. X
  52. X
  53. X$(PRG): $(OBJ)
  54. X    $(CC) -o $(PRG) $(OBJ)
  55. X
  56. X.c.o:
  57. X    $(CC) $(CCFLAGS) -c $<
  58. X
  59. X.l.c:
  60. X    $(LEX) $(LEXOPTS) $<
  61. X    mv lex.yy.c $*.c
  62. X
  63. Xmanual: p2latex.1
  64. X    $(ROFF) $(ROFFOPTS) -man p2latex.1 > p2latex.0
  65. X
  66. Xclean:
  67. X    -rm -f $(OBJ)
  68. X    
  69. Xalloca.o: alloca.c 
  70. Xp2latex.c: p2latex.l
  71. Xp2latex.o: p2latex.c
  72. Xmain.o: main.c getopt.h 
  73. Xgetopt.o: getopt.c getopt.h 
  74. Xgetopt1.o: getopt1.c getopt.h 
  75. Xversion.o: version.c 
  76. Xallocate.o: allocate.c 
  77. END_OF_FILE
  78.   if test 730 -ne `wc -c <'Makefile.unix'`; then
  79.     echo shar: \"'Makefile.unix'\" unpacked with wrong size!
  80.   fi
  81.   # end of 'Makefile.unix'
  82. fi
  83. if test -f 'alloca.c' -a "${1}" != "-c" ; then 
  84.   echo shar: Will not clobber existing file \"'alloca.c'\"
  85. else
  86.   echo shar: Extracting \"'alloca.c'\" \(5233 characters\)
  87.   sed "s/^X//" >'alloca.c' <<'END_OF_FILE'
  88. X/*
  89. X    alloca -- (mostly) portable public-domain implementation -- D A Gwyn
  90. X
  91. X    last edit:    86/05/30    rms
  92. X       include config.h, since on VMS it renames some symbols.
  93. X       Use xmalloc instead of malloc.
  94. X
  95. X    This implementation of the PWB library alloca() function,
  96. X    which is used to allocate space off the run-time stack so
  97. X    that it is automatically reclaimed upon procedure exit, 
  98. X    was inspired by discussions with J. Q. Johnson of Cornell.
  99. X
  100. X    It should work under any C implementation that uses an
  101. X    actual procedure stack (as opposed to a linked list of
  102. X    frames).  There are some preprocessor constants that can
  103. X    be defined when compiling for your specific system, for
  104. X    improved efficiency; however, the defaults should be okay.
  105. X
  106. X    The general concept of this implementation is to keep
  107. X    track of all alloca()-allocated blocks, and reclaim any
  108. X    that are found to be deeper in the stack than the current
  109. X    invocation.  This heuristic does not reclaim storage as
  110. X    soon as it becomes invalid, but it will do so eventually.
  111. X
  112. X    As a special case, alloca(0) reclaims storage without
  113. X    allocating any.  It is a good idea to use alloca(0) in
  114. X    your main control loop, etc. to force garbage collection.
  115. X*/
  116. X#ifndef lint
  117. Xstatic char    SCCSid[] = "@(#)alloca.c    1.1";    /* for the "what" utility */
  118. X#endif
  119. X
  120. X#ifdef emacs
  121. X#include "config.h"
  122. X#ifdef static
  123. X/* actually, only want this if static is defined as ""
  124. X   -- this is for usg, in which emacs must undefine static
  125. X   in order to make unexec workable
  126. X   */
  127. X#ifndef STACK_DIRECTION
  128. Xyou
  129. Xlose
  130. X-- must know STACK_DIRECTION at compile-time
  131. X#endif /* STACK_DIRECTION undefined */
  132. X#endif /* static */
  133. X#endif /* emacs */
  134. X
  135. X#ifdef __STDC__
  136. Xtypedef void    *pointer;        /* generic pointer type */
  137. X#else
  138. Xtypedef char    *pointer;        /* generic pointer type */
  139. X#endif
  140. X
  141. X#define    NULL    0            /* null pointer constant */
  142. X
  143. Xextern void    free();
  144. Xextern pointer    xmalloc();
  145. X
  146. X/*
  147. X    Define STACK_DIRECTION if you know the direction of stack
  148. X    growth for your system; otherwise it will be automatically
  149. X    deduced at run-time.
  150. X
  151. X    STACK_DIRECTION > 0 => grows toward higher addresses
  152. X    STACK_DIRECTION < 0 => grows toward lower addresses
  153. X    STACK_DIRECTION = 0 => direction of growth unknown
  154. X*/
  155. X
  156. X#ifndef STACK_DIRECTION
  157. X#define    STACK_DIRECTION    0        /* direction unknown */
  158. X#endif
  159. X
  160. X#if STACK_DIRECTION != 0
  161. X
  162. X#define    STACK_DIR    STACK_DIRECTION    /* known at compile-time */
  163. X
  164. X#else    /* STACK_DIRECTION == 0; need run-time code */
  165. X
  166. Xstatic int    stack_dir;        /* 1 or -1 once known */
  167. X#define    STACK_DIR    stack_dir
  168. X
  169. Xstatic void
  170. Xfind_stack_direction (/* void */)
  171. X{
  172. X  static char    *addr = NULL;    /* address of first
  173. X                   `dummy', once known */
  174. X  auto char    dummy;        /* to get stack address */
  175. X
  176. X  if (addr == NULL)
  177. X    {                /* initial entry */
  178. X      addr = &dummy;
  179. X
  180. X      find_stack_direction ();    /* recurse once */
  181. X    }
  182. X  else                /* second entry */
  183. X    if (&dummy > addr)
  184. X      stack_dir = 1;        /* stack grew upward */
  185. X    else
  186. X      stack_dir = -1;        /* stack grew downward */
  187. X}
  188. X
  189. X#endif    /* STACK_DIRECTION == 0 */
  190. X
  191. X/*
  192. X    An "alloca header" is used to:
  193. X    (a) chain together all alloca()ed blocks;
  194. X    (b) keep track of stack depth.
  195. X
  196. X    It is very important that sizeof(header) agree with malloc()
  197. X    alignment chunk size.  The following default should work okay.
  198. X*/
  199. X
  200. X#ifndef    ALIGN_SIZE
  201. X#define    ALIGN_SIZE    sizeof(double)
  202. X#endif
  203. X
  204. Xtypedef union hdr
  205. X{
  206. X  char    align[ALIGN_SIZE];    /* to force sizeof(header) */
  207. X  struct
  208. X    {
  209. X      union hdr *next;        /* for chaining headers */
  210. X      char *deep;        /* for stack depth measure */
  211. X    } h;
  212. X} header;
  213. X
  214. X/*
  215. X    alloca( size ) returns a pointer to at least `size' bytes of
  216. X    storage which will be automatically reclaimed upon exit from
  217. X    the procedure that called alloca().  Originally, this space
  218. X    was supposed to be taken from the current stack frame of the
  219. X    caller, but that method cannot be made to work for some
  220. X    implementations of C, for example under Gould's UTX/32.
  221. X*/
  222. X
  223. Xstatic header *last_alloca_header = NULL; /* -> last alloca header */
  224. X
  225. Xpointer
  226. Xalloca (size)            /* returns pointer to storage */
  227. X     unsigned    size;        /* # bytes to allocate */
  228. X{
  229. X  auto char    probe;        /* probes stack depth: */
  230. X  register char    *depth = &probe;
  231. X
  232. X#if STACK_DIRECTION == 0
  233. X  if (STACK_DIR == 0)        /* unknown growth direction */
  234. X    find_stack_direction ();
  235. X#endif
  236. X
  237. X                /* Reclaim garbage, defined as all alloca()ed storage that
  238. X                   was allocated from deeper in the stack than currently. */
  239. X
  240. X  {
  241. X    register header    *hp;    /* traverses linked list */
  242. X
  243. X    for (hp = last_alloca_header; hp != NULL;)
  244. X      if ((STACK_DIR > 0 && hp->h.deep > depth)
  245. X      || (STACK_DIR < 0 && hp->h.deep < depth))
  246. X    {
  247. X      register header    *np = hp->h.next;
  248. X
  249. X      free ((pointer) hp);    /* collect garbage */
  250. X
  251. X      hp = np;        /* -> next header */
  252. X    }
  253. X      else
  254. X    break;            /* rest are not deeper */
  255. X
  256. X    last_alloca_header = hp;    /* -> last valid storage */
  257. X  }
  258. X
  259. X  if (size == 0)
  260. X    return NULL;        /* no allocation required */
  261. X
  262. X  /* Allocate combined header + user data storage. */
  263. X
  264. X  {
  265. X    register pointer    new = xmalloc (sizeof (header) + size);
  266. X    /* address of header */
  267. X
  268. X    ((header *)new)->h.next = last_alloca_header;
  269. X    ((header *)new)->h.deep = depth;
  270. X
  271. X    last_alloca_header = (header *)new;
  272. X
  273. X    /* User storage begins just after header. */
  274. X
  275. X    return (pointer)((char *)new + sizeof(header));
  276. X  }
  277. X}
  278. X
  279. END_OF_FILE
  280.   if test 5233 -ne `wc -c <'alloca.c'`; then
  281.     echo shar: \"'alloca.c'\" unpacked with wrong size!
  282.   fi
  283.   # end of 'alloca.c'
  284. fi
  285. if test -f 'fancyheadings.doc' -a "${1}" != "-c" ; then 
  286.   echo shar: Will not clobber existing file \"'fancyheadings.doc'\"
  287. else
  288.   echo shar: Extracting \"'fancyheadings.doc'\" \(9284 characters\)
  289.   sed "s/^X//" >'fancyheadings.doc' <<'END_OF_FILE'
  290. XReturn-Path: piet@cs.ruu.nl
  291. XReceived: from unido.informatik.uni-dortmund.de
  292. X    by gorbi.informatik.uni-dortmund.de id AA04891; Mon, 7 Oct 91 11:35:20 +0100
  293. XReceived: from ruuinf.cs.ruu.nl 
  294. X    by unido.informatik.uni-dortmund.de with SMTP (5.65+/UNIDO-2.0.4.d)
  295. X    via EUnet for gorbi.informatik.uni-dortmund.de
  296. X    id AA12353; Mon, 7 Oct 91 11:31:05 +0100
  297. XReceived: from gnu.cs.ruu.nl by ruuinf.cs.ruu.nl with SMTP
  298. X    (5.61+/IDA-1.2.8) id AA25657; Mon, 7 Oct 91 12:15:53 +0100
  299. XReceived: by alchemy.cs.ruu.nl
  300. X    (15.11/15.6) id AA20318; Mon, 7 Oct 91 11:34:15 -0100
  301. XDate: Mon, 7 Oct 91 11:34:15 -0100
  302. XFrom: Piet van Oostrum <piet@cs.ruu.nl>
  303. XMessage-Id: <9110071034.AA20318@alchemy.cs.ruu.nl>
  304. XTo: heitkoet (Joerg Heitkoetter)
  305. XSubject: Re: Fancy Latex Headers - Please Help
  306. XNewsgroups: comp.text.tex
  307. XIn-Reply-To: <3853@laura.UUCP>
  308. XOrganization: Dept of Computer Science, Utrecht University, The Netherlands
  309. XCc: 
  310. X
  311. XHere is the (new) doc file for fancyheadings.sty:
  312. X
  313. XHere is a documentstylestyle option that allows you to customize your
  314. Xpage headers and footers in an easy way. It combines features that were
  315. Xseparately available in other pagestyles, without introducing much
  316. Xcomplexity. You can define:
  317. X    - three-part headers and footers
  318. X    - rules in header and footer
  319. X    - headers and footers wider than \textwidth
  320. X    - multiline headers and footers
  321. X    - separate headers and footers for even and odd pages
  322. X    - separate headers and footers for chapter pages
  323. X
  324. XTo use this pagestyle, you must include the ``fancyheadings'' style
  325. Xoption in your \documentstyle, and issue the \pagestyle{fancy} command.
  326. XThe \pagestyle{fancy} command should be issued after any changes made to
  327. X\textwidth.
  328. X
  329. XThe page layout will be as follows:
  330. X
  331. X        LHEAD          CHEAD          RHEAD
  332. X        ----------------------------------- (rule)
  333. X
  334. X                 page body
  335. X
  336. X
  337. X        ----------------------------------- (rule)
  338. X        LFOOT           CFOOT          RFOOT
  339. X
  340. XThe L-fields will be leftadjusted, the C-fields centered and the
  341. XR-fields rightadjusted.
  342. XEach of the six fields and the two rules can be defined separately.
  343. X
  344. XSimple use:
  345. X
  346. XThe header and footer fields can be defined by commands \lhead{LHEAD}
  347. Xand so on for the other fields. If the field depends on something in the
  348. Xdocument (e.g. section titles) you must in general use the \markboth and
  349. X\markright commands, otherwise a title may end on the wrong page. You
  350. Xcan do this e.g. by redefining the commands \chaptermark, \sectionmark
  351. Xand so on (see example below). The defaults for these marks are as in
  352. Xthe standard pagestyles. The marks can be put into a header or footer
  353. Xfield by referencing \leftmark and \rightmark.
  354. X
  355. XRules in header and footer
  356. X
  357. XThe thickness of the rules below the header and above the footer can be
  358. Xchanged by redefining the length parameters \headrulewidth (default
  359. X0.4pt) and \footrulewidth (default 0). These may be redefined by the
  360. X\setlength command. A thickness of 0pt makes the rule invisible.
  361. XIf you want to make more complicated changes, you have to redefine the
  362. Xcommands \headrule and/or \footrule.
  363. X
  364. XHeaders and footers wider than \textwidth
  365. X
  366. XThe headers and footers are set in a box of width \headwidth. The
  367. Xdefault for this is the value of \textwidth. You can make it wider (or
  368. Xsmaller) by redefining \headwidth with the \setlength or \addtolength
  369. Xcommand. The headers and footers will stick out the page on the same
  370. Xside as the marginal notes. For example to include the marginal notes,
  371. Xadd both \marginparsep and \marginparwidth to \headwidth (see also the
  372. Xexample below).
  373. X
  374. XMultiline headers and footers
  375. X
  376. XEach of the six fields is set in an appropriate parbox, so you can put a
  377. Xmultiline part in it with the \\ command. It is also possible to put
  378. Xextra space in it with the \vspace command. Note that if you do this you
  379. Xwill probably have to increase the \headheight or \footskip lengths.
  380. X
  381. XSeparate headers and footers for even and odd pages
  382. X
  383. XIf you want the headers and footers to be different on even- and
  384. Xodd-numbered pages in the ``twoside'' style, the field-defining macros
  385. Xcan be given an optional argument, to be used on the even-numbered
  386. Xpages, like \lhead[EVEN-LHEAD]{ODD-LHEAD}.
  387. X
  388. XSeparate headers and footers for chapter pages
  389. X
  390. XLaTeX gives a \thispagestyle{plain} command for the first page of the
  391. Xdocument, the first page of each chapter and a couple of other pages. It
  392. Xmight be incompatible with your pagestyle. In this case you can use a
  393. Xslightly different version of the pagestyle, called \pagestyle{fancyplain}. 
  394. XThis pagestyle redefines the pagestyle ``plain'' to also use pagestyle
  395. X``fancy'' with the following modifications:
  396. X    - the thicknesses of the rules is defined by \plainheadrulewidth and
  397. X      \plainfootrulewidth (both default 0).
  398. X    - the 6 fields may be defined separately for the plain pages by
  399. X      giving them the value \fancyplain{PLAIN-VALUE}{NORMAL-VALUE}. This
  400. X      construct may be used in both the optional argument and the normal
  401. X      argument. Thus \lhead[\fancyplain{F1}{F2}]{\fancyplain{F3}{F4}}
  402. X      specifies the LHEAD value in a two-sided document:
  403. X    F1 on an even-numbered ``plain'' page
  404. X    F2 on an even-numbered normal page
  405. X    F3 on an odd-numbered ``plain'' page
  406. X    F4 on an odd-numbered normal page.
  407. X
  408. XDefaults:
  409. X
  410. X\headrulewidth           0.4pt
  411. X\footrulewidth        0pt
  412. X\plainheadrulewidth    0pt
  413. X\plainfootrulewidth    0pt
  414. X
  415. X\lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}}
  416. X%  i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages
  417. X\chead{}
  418. X\rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}}
  419. X%  i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages
  420. X\lfoot{}
  421. X\cfoot{\rm\thepage} % page number
  422. X\rfoot{}
  423. X
  424. XExamples:
  425. X
  426. XTo put two lines containing the section title and the subsection title
  427. Xin the righthandside corner, use:
  428. X
  429. X\documentstyle[fancyheadings]{article}
  430. X\pagestyle{fancy}
  431. X\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
  432. X\renewcommand{\subsectionmark}[1]{\markright{#1}}
  433. X\rfoot{\leftmark\\\rightmark}
  434. X
  435. XThe following definitions give an approximation of the style used in the
  436. XLaTeX book:
  437. X
  438. X\documentstyle[fancyheadings]{book}
  439. X\pagestyle{fancyplain}
  440. X\addtolength{\headwidth}{\marginparsep}
  441. X\addtolength{\headwidth}{\marginparwidth}
  442. X\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}} % remember chapter title
  443. X\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
  444. X                                                % section number and title
  445. X\lhead[\fancyplain{}{\bf\thepage}]{\fancyplain{}{\bf\rightmark}}
  446. X\rhead[\fancyplain{}{\bf\leftmark}]{\fancyplain{}{\bf\thepage}}
  447. X\cfoot{}
  448. X
  449. XUsing section titles etc. in the headers and/or footers:
  450. X
  451. XYou can't just change the header and/or footer fields in the middle of some
  452. Xtext (e.g. after a section header). This is because TeX may have processed
  453. Xa bit more text before deciding to make up the page. It may have passed a
  454. Xsection beginning, causing the wrong title on the page.  TeX has a
  455. Xmechanism called 'marks' to solve this problem.  There is in LaTeX a
  456. X\leftmark and a \rightmark. Usually \leftmark is a chapter title and
  457. X\rightmark is a section title. To set the marks there are two commands:
  458. X\markboth{L}{R} sets the \leftmark to L and the rightmark to R, and
  459. X\rightmark{R} sets only the rightmark to R.
  460. XThe default definitions of \section etc. do this already for you.
  461. X
  462. XAn example follows:
  463. X
  464. X    left page                        right page
  465. X    ---------                        ----------
  466. X
  467. X2         CHAPTER 1. Introduction | 1.2 Some section                        3
  468. X------------------------------------ | -----------------------------------------
  469. X                                     |
  470. XText                                 | more text
  471. XText                                 | more text
  472. XText                                 | more text
  473. X                                     |
  474. X                                     |
  475. X                                     |
  476. X
  477. XThis can be easily done with fancyheadings as follows:
  478. X
  479. X\pagestyle{fancy}
  480. X\setlength{\headrulewidth}{1pt}
  481. X\lhead[\rm\thepage]{\sl\rightmark}
  482. X\rhead[\sl\leftmark]{\rm\thepage}
  483. X
  484. XThis specifies that on even pages (the [] parts) the leftheadpart is page
  485. Xnumber and rightheadpart is \leftmark, which is the chapter title (because that
  486. Xis given as the left argument of \markboth (see page 162 of the LaTeX book)
  487. X
  488. XOn odd pages (the parts between {}) the leftheadpart is \rightmark (which
  489. Xis the last section title because that is given as argument to \markright
  490. X(see the same page), and the rightheadpart is the page no.
  491. X
  492. XNow suppose you don't want the section number and you want the section
  493. Xtitle in upper case:
  494. XYou add the following to your preamble:
  495. X
  496. X\renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}}
  497. X
  498. XOr if you don't want the chapter number but only the chapter title (not in
  499. Xuppercase):
  500. X
  501. X\renewcommand{\chaptermark}[1]{\markboth{#1}{ }}
  502. X
  503. XNote: the parameter in both cases is the (section|chapter) title.
  504. X
  505. XKNOWN PROBLEMS:
  506. X
  507. XSometimes you will get a warning message from LaTeX concerning ``overfull
  508. Xvbox during output''. In this case you have to increase the \headheight or
  509. X\footskip lengths or both (with \addtolength or \setlength).
  510. X-- 
  511. XPiet* van Oostrum, Dept of Computer Science, Utrecht University,
  512. XPadualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
  513. XTelephone: +31 30 531806   Uucp:   uunet!mcsun!ruuinf!piet
  514. XTelefax:   +31 30 513791   Internet:  piet@cs.ruu.nl   (*`Pete')
  515. END_OF_FILE
  516.   if test 9284 -ne `wc -c <'fancyheadings.doc'`; then
  517.     echo shar: \"'fancyheadings.doc'\" unpacked with wrong size!
  518.   fi
  519.   # end of 'fancyheadings.doc'
  520. fi
  521. if test -f 'fancyheadings.sty' -a "${1}" != "-c" ; then 
  522.   echo shar: Will not clobber existing file \"'fancyheadings.sty'\"
  523. else
  524.   echo shar: Extracting \"'fancyheadings.sty'\" \(3778 characters\)
  525.   sed "s/^X//" >'fancyheadings.sty' <<'END_OF_FILE'
  526. X% fancyheadings.sty version 1.0
  527. X% Fancy headers and footers.
  528. X% Piet van Oostrum, Dept of Computer Science, University of Utrecht
  529. X% Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
  530. X% Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)
  531. X% March, 1989.
  532. X
  533. X\def\lhead{\@ifnextchar[{\@xlhead}{\@ylhead}}
  534. X\def\@xlhead[#1]#2{\gdef\@elhead{#1}\gdef\@olhead{#2}}
  535. X\def\@ylhead#1{\gdef\@elhead{#1}\gdef\@olhead{#1}}
  536. X
  537. X\def\chead{\@ifnextchar[{\@xchead}{\@ychead}}
  538. X\def\@xchead[#1]#2{\gdef\@echead{#1}\gdef\@ochead{#2}}
  539. X\def\@ychead#1{\gdef\@echead{#1}\gdef\@ochead{#1}}
  540. X
  541. X\def\rhead{\@ifnextchar[{\@xrhead}{\@yrhead}}
  542. X\def\@xrhead[#1]#2{\gdef\@erhead{#1}\gdef\@orhead{#2}}
  543. X\def\@yrhead#1{\gdef\@erhead{#1}\gdef\@orhead{#1}}
  544. X
  545. X\def\lfoot{\@ifnextchar[{\@xlfoot}{\@ylfoot}}
  546. X\def\@xlfoot[#1]#2{\gdef\@elfoot{#1}\gdef\@olfoot{#2}}
  547. X\def\@ylfoot#1{\gdef\@elfoot{#1}\gdef\@olfoot{#1}}
  548. X
  549. X\def\cfoot{\@ifnextchar[{\@xcfoot}{\@ycfoot}}
  550. X\def\@xcfoot[#1]#2{\gdef\@ecfoot{#1}\gdef\@ocfoot{#2}}
  551. X\def\@ycfoot#1{\gdef\@ecfoot{#1}\gdef\@ocfoot{#1}}
  552. X
  553. X\def\rfoot{\@ifnextchar[{\@xrfoot}{\@yrfoot}}
  554. X\def\@xrfoot[#1]#2{\gdef\@erfoot{#1}\gdef\@orfoot{#2}}
  555. X\def\@yrfoot#1{\gdef\@erfoot{#1}\gdef\@orfoot{#1}}
  556. X
  557. X\newdimen\headrulewidth
  558. X\newdimen\footrulewidth
  559. X\newdimen\plainheadrulewidth
  560. X\newdimen\plainfootrulewidth
  561. X\newdimen\headwidth
  562. X\newif\if@fancyplain \@fancyplainfalse
  563. X\def\fancyplain#1#2{\if@fancyplain#1\else#2\fi}
  564. X
  565. X% Initialization of the head and foot text.
  566. X
  567. X\headrulewidth 0.4pt
  568. X\footrulewidth\z@
  569. X\plainheadrulewidth\z@
  570. X\plainfootrulewidth\z@
  571. X
  572. X\lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}}
  573. X%  i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages
  574. X\chead{}
  575. X\rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}}
  576. X%  i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages
  577. X\lfoot{}
  578. X\cfoot{\rm\thepage} % page number
  579. X\rfoot{}
  580. X
  581. X% Put together a header or footer given the left, center and
  582. X% right text, fillers at left and right and a rule.
  583. X% The \lap commands put the text into an hbox of zero size,
  584. X% so overlapping text does not generate an errormessage.
  585. X
  586. X\def\@fancyhead#1#2#3#4#5{#1\hbox to\headwidth{\vbox{\hbox
  587. X{\rlap{\parbox[b]{\headwidth}{\raggedright#2\strut}}\hfill
  588. X\parbox[b]{\headwidth}{\centering#3\strut}\hfill
  589. X\llap{\parbox[b]{\headwidth}{\raggedleft#4\strut}}}\headrule}}#5}
  590. X
  591. X
  592. X\def\@fancyfoot#1#2#3#4#5{#1\hbox to\headwidth{\vbox{\footrule
  593. X\hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2\strut}}\hfill
  594. X\parbox[t]{\headwidth}{\centering#3\strut}\hfill
  595. X\llap{\parbox[t]{\headwidth}{\raggedleft#4\strut}}}}}#5}
  596. X
  597. X\def\headrule{{\if@fancyplain\headrulewidth\plainheadrulewidth\fi
  598. X\hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}
  599. X
  600. X\def\footrule{{\if@fancyplain\footrulewidth\plainfootrulewidth\fi
  601. X\vskip-0.3\normalbaselineskip\vskip-\footrulewidth
  602. X\hrule\@width\headwidth\@height\footrulewidth\vskip0.3\normalbaselineskip}}
  603. X
  604. X\def\ps@fancy{
  605. X\let\@mkboth\markboth
  606. X\@ifundefined{chapter}{\def\sectionmark##1{\markboth
  607. X{\uppercase{\ifnum \c@secnumdepth>\z@
  608. X \thesection\hskip 1em\relax \fi ##1}}{}}
  609. X\def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne
  610. X \thesubsection\hskip 1em\relax \fi ##1}}}
  611. X{\def\chaptermark##1{\markboth {\uppercase{\ifnum \c@secnumdepth>\m@ne
  612. X \@chapapp\ \thechapter. \ \fi ##1}}{}}
  613. X\def\sectionmark##1{\markright{\uppercase{\ifnum \c@secnumdepth >\z@
  614. X \thesection. \ \fi ##1}}}}
  615. X\def\@oddhead{\@fancyhead\relax\@olhead\@ochead\@orhead\hss}
  616. X\def\@oddfoot{\@fancyfoot\relax\@olfoot\@ocfoot\@orfoot\hss}
  617. X\def\@evenhead{\@fancyhead\hss\@elhead\@echead\@erhead\relax}
  618. X\def\@evenfoot{\@fancyfoot\hss\@elfoot\@ecfoot\@erfoot\relax}
  619. X\headwidth\textwidth}
  620. X\def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy}
  621. X\def\ps@plain@fancy{\@fancyplaintrue\ps@fancy}
  622. END_OF_FILE
  623.   if test 3778 -ne `wc -c <'fancyheadings.sty'`; then
  624.     echo shar: \"'fancyheadings.sty'\" unpacked with wrong size!
  625.   fi
  626.   # end of 'fancyheadings.sty'
  627. fi
  628. if test -f 'getopt.h' -a "${1}" != "-c" ; then 
  629.   echo shar: Will not clobber existing file \"'getopt.h'\"
  630. else
  631.   echo shar: Extracting \"'getopt.h'\" \(3754 characters\)
  632.   sed "s/^X//" >'getopt.h' <<'END_OF_FILE'
  633. X/* Declarations for getopt.
  634. X   Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  635. X
  636. X   This program is free software; you can redistribute it and/or modify
  637. X   it under the terms of the GNU General Public License as published by
  638. X   the Free Software Foundation; either version 2, or (at your option)
  639. X   any later version.
  640. X
  641. X   This program is distributed in the hope that it will be useful,
  642. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  643. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  644. X   GNU General Public License for more details.
  645. X
  646. X   You should have received a copy of the GNU General Public License
  647. X   along with this program; if not, write to the Free Software
  648. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  649. X
  650. X#ifndef _GETOPT_H_
  651. X#define _GETOPT_H_
  652. X
  653. X/* For communication from `getopt' to the caller.
  654. X   When `getopt' finds an option that takes an argument,
  655. X   the argument value is returned here.
  656. X   Also, when `ordering' is RETURN_IN_ORDER,
  657. X   each non-option ARGV-element is returned here.  */
  658. X
  659. Xextern char *optarg;
  660. X
  661. X/* Index in ARGV of the next element to be scanned.
  662. X   This is used for communication to and from the caller
  663. X   and for communication between successive calls to `getopt'.
  664. X
  665. X   On entry to `getopt', zero means this is the first call; initialize.
  666. X
  667. X   When `getopt' returns EOF, this is the index of the first of the
  668. X   non-option elements that the caller should itself scan.
  669. X
  670. X   Otherwise, `optind' communicates from one call to the next
  671. X   how much of ARGV has been scanned so far.  */
  672. X
  673. Xextern int optind;
  674. X
  675. X/* Callers store zero here to inhibit the error message `getopt' prints
  676. X   for unrecognized options.  */
  677. X
  678. Xextern int opterr;
  679. X
  680. X/* Describe the long-named options requested by the application.
  681. X   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  682. X   of `struct option' terminated by an element containing a name which is
  683. X   zero.
  684. X
  685. X   The field `has_arg' is:
  686. X   no_argument        (or 0) if the option does not take an argument,
  687. X   required_argument    (or 1) if the option requires an argument,
  688. X   optional_argument     (or 2) if the option takes an optional argument.
  689. X
  690. X   If the field `flag' is not NULL, it points to a variable that is set
  691. X   to the value given in the field `val' when the option is found, but
  692. X   left unchanged if the option is not found.
  693. X
  694. X   To have a long-named option do something other than set an `int' to
  695. X   a compiled-in constant, such as set a value from `optarg', set the
  696. X   option's `flag' field to zero and its `val' field to a nonzero
  697. X   value (the equivalent single-letter option character, if there is
  698. X   one).  For long options that have a zero `flag' field, `getopt'
  699. X   returns the contents of the `val' field.  */
  700. X
  701. Xstruct option
  702. X{
  703. X#ifdef    __STDC__
  704. X  const char *name;
  705. X#else
  706. X  char *name;
  707. X#endif
  708. X  enum
  709. X    {
  710. X      no_argument,
  711. X      required_argument,
  712. X      optional_argument
  713. X    } has_arg;
  714. X  int *flag;
  715. X  int val;
  716. X};
  717. X
  718. X#ifdef __STDC__
  719. Xextern int getopt (int argc, char *const *argv, const char *shortopts);
  720. Xextern int getopt_long (int argc, char *const *argv, const char *shortopts,
  721. X                const struct option *longopts, int *longind);
  722. Xextern int getopt_long_only (int argc, char *const *argv,
  723. X                 const char *shortopts,
  724. X                     const struct option *longopts, int *longind);
  725. X
  726. X/* Internal only.  Users should not call this directly.  */
  727. Xextern int _getopt_internal (int argc, char *const *argv,
  728. X                 const char *shortopts,
  729. X                     const struct option *longopts, int *longind,
  730. X                 int long_only);
  731. X#else /* not __STDC__ */
  732. Xextern int getopt ();
  733. Xextern int getopt_long ();
  734. Xextern int getopt_long_only ();
  735. X
  736. Xextern int _getopt_internal ();
  737. X#endif /* not __STDC__ */
  738. X
  739. X#endif /* _GETOPT_H_ */
  740. END_OF_FILE
  741.   if test 3754 -ne `wc -c <'getopt.h'`; then
  742.     echo shar: \"'getopt.h'\" unpacked with wrong size!
  743.   fi
  744.   # end of 'getopt.h'
  745. fi
  746. if test -f 'getopt1.c' -a "${1}" != "-c" ; then 
  747.   echo shar: Will not clobber existing file \"'getopt1.c'\"
  748. else
  749.   echo shar: Extracting \"'getopt1.c'\" \(3530 characters\)
  750.   sed "s/^X//" >'getopt1.c' <<'END_OF_FILE'
  751. X/* Getopt for GNU.
  752. X   Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
  753. X
  754. X   This program is free software; you can redistribute it and/or modify
  755. X   it under the terms of the GNU General Public License as published by
  756. X   the Free Software Foundation; either version 2, or (at your option)
  757. X   any later version.
  758. X
  759. X   This program is distributed in the hope that it will be useful,
  760. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  761. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  762. X   GNU General Public License for more details.
  763. X
  764. X   You should have received a copy of the GNU General Public License
  765. X   along with this program; if not, write to the Free Software
  766. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  767. X
  768. X#ifdef    LIBC
  769. X/* For when compiled as part of the GNU C library.  */
  770. X#include <ansidecl.h>
  771. X#endif
  772. X
  773. X#include "getopt.h"
  774. X
  775. X#ifndef __STDC__
  776. X#define const
  777. X#endif
  778. X
  779. X#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC)
  780. X#include <stdlib.h>
  781. X#else /* STDC_HEADERS or __GNU_LIBRARY__ */
  782. Xchar *getenv ();
  783. X#endif /* STDC_HEADERS or __GNU_LIBRARY__ */
  784. X
  785. X#if !defined (NULL)
  786. X#define NULL 0
  787. X#endif
  788. X
  789. Xint
  790. Xgetopt_long (argc, argv, options, long_options, opt_index)
  791. X     int argc;
  792. X     char *const *argv;
  793. X     const char *options;
  794. X     const struct option *long_options;
  795. X     int *opt_index;
  796. X{
  797. X  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  798. X}
  799. X
  800. X/* Like getopt_long, but '-' as well as '--' can indicate a long option.
  801. X   If an option that starts with '-' (not '--') doesn't match a long option,
  802. X   but does match a short option, it is parsed as a short option
  803. X   instead. */
  804. X
  805. Xint 
  806. Xgetopt_long_only (argc, argv, options, long_options, opt_index)
  807. X     int argc;
  808. X     char *const *argv;
  809. X     const char *options;
  810. X     const struct option *long_options;
  811. X     int *opt_index;
  812. X{
  813. X  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  814. X}
  815. X
  816. X#ifdef TEST
  817. X
  818. X#include <stdio.h>
  819. X
  820. Xint
  821. Xmain (argc, argv)
  822. X     int argc;
  823. X     char **argv;
  824. X{
  825. X  int c;
  826. X  int digit_optind = 0;
  827. X
  828. X  while (1)
  829. X    {
  830. X      int this_option_optind = optind ? optind : 1;
  831. X      int option_index = 0;
  832. X      static struct option long_options[] =
  833. X      {
  834. X    {"add", 1, 0, 0},
  835. X    {"append", 0, 0, 0},
  836. X    {"delete", 1, 0, 0},
  837. X    {"verbose", 0, 0, 0},
  838. X    {"create", 0, 0, 0},
  839. X    {"file", 1, 0, 0},
  840. X    {0, 0, 0, 0}
  841. X      };
  842. X
  843. X      c = getopt_long (argc, argv, "abc:d:0123456789",
  844. X               long_options, &option_index);
  845. X      if (c == EOF)
  846. X    break;
  847. X
  848. X      switch (c)
  849. X    {
  850. X    case 0:
  851. X      printf ("option %s", long_options[option_index].name);
  852. X      if (optarg)
  853. X        printf (" with arg %s", optarg);
  854. X      printf ("\n");
  855. X      break;
  856. X
  857. X    case '0':
  858. X    case '1':
  859. X    case '2':
  860. X    case '3':
  861. X    case '4':
  862. X    case '5':
  863. X    case '6':
  864. X    case '7':
  865. X    case '8':
  866. X    case '9':
  867. X      if (digit_optind != 0 && digit_optind != this_option_optind)
  868. X        printf ("digits occur in two different argv-elements.\n");
  869. X      digit_optind = this_option_optind;
  870. X      printf ("option %c\n", c);
  871. X      break;
  872. X
  873. X    case 'a':
  874. X      printf ("option a\n");
  875. X      break;
  876. X
  877. X    case 'b':
  878. X      printf ("option b\n");
  879. X      break;
  880. X
  881. X    case 'c':
  882. X      printf ("option c with value `%s'\n", optarg);
  883. X      break;
  884. X
  885. X    case 'd':
  886. X      printf ("option d with value `%s'\n", optarg);
  887. X      break;
  888. X
  889. X    case '?':
  890. X      break;
  891. X
  892. X    default:
  893. X      printf ("?? getopt returned character code 0%o ??\n", c);
  894. X    }
  895. X    }
  896. X
  897. X  if (optind < argc)
  898. X    {
  899. X      printf ("non-option ARGV-elements: ");
  900. X      while (optind < argc)
  901. X    printf ("%s ", argv[optind++]);
  902. X      printf ("\n");
  903. X    }
  904. X
  905. X  exit (0);
  906. X}
  907. X
  908. X#endif /* TEST */
  909. END_OF_FILE
  910.   if test 3530 -ne `wc -c <'getopt1.c'`; then
  911.     echo shar: \"'getopt1.c'\" unpacked with wrong size!
  912.   fi
  913.   # end of 'getopt1.c'
  914. fi
  915. if test -f 'main.c' -a "${1}" != "-c" ; then 
  916.   echo shar: Will not clobber existing file \"'main.c'\"
  917. else
  918.   echo shar: Extracting \"'main.c'\" \(9897 characters\)
  919.   sed "s/^X//" >'main.c' <<'END_OF_FILE'
  920. X/*
  921. X *  p2LaTeX: Produce prettyprinted LaTeX files from Pascal sources.
  922. X *  Copyright (C) 1993 Torsten Poulin
  923. X *    Note: This program is derived from work done by others.
  924. X *
  925. X *  This program is free software; you can redistribute it and/or modify
  926. X *  it under the terms of the GNU General Public License as published by
  927. X *  the Free Software Foundation; either version 2, or (at your option)
  928. X *  any later version.
  929. X *
  930. X *  This program is distributed in the hope that it will be useful,
  931. X *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  932. X *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  933. X *  GNU General Public License for more details.
  934. X *
  935. X *  You should have received a copy of the GNU General Public License
  936. X *  along with this program; if not, write to the Free Software
  937. X *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  938. X *
  939. X *  Torsten Poulin 
  940. X *  Banebrinken 99, 2, 77
  941. X *  DK-2400 Copenhagen NV
  942. X *  DENMARK
  943. X *
  944. X *  e-mail: torsten@diku.dk
  945. X *  --------------------------------------------------------------------
  946. X *  p2latex is derived from the code for the program C++2LaTeX 2.0 which
  947. X *  produces prettyprinted LaTeX files from C++ or C sources.
  948. X *
  949. X *  C++2LaTeX 2.0 is copyright (C) 1991 Joerg Heitkoetter
  950. X *
  951. X *     Systems Analysis Research Group
  952. X *     University of Dortmund
  953. X *     (heitkoet@gorbi.informatik.uni-dortmund.de).
  954. X *
  955. X *  The original C++2LaTeX is copyright (C) 1990 Norbert Kiesel
  956. X *
  957. X *      Norbert Kiesel
  958. X *      RWTH Aachen / Institut f. Informatik III
  959. X *      Ahornstr. 55
  960. X *      D-5100 Aachen
  961. X *      West Germany
  962. X *
  963. X *      Phone:  +49 241 80-7266
  964. X *      EUNET:  norbert@rwthi3.uucp
  965. X *      USENET: ...!mcvax!unido!rwthi3!norbert
  966. X *      X.400:  norbert@rwthi3.informatik.rwth-aachen.de
  967. X *  --------------------------------------------------------------------
  968. X * p2latex main.c revision history.
  969. X * $Log:    main.c,v $
  970. X * Revision 1.5  93/12/20  14:25:10  Torsten
  971. X * Changed the error messages to comply with the manual page.
  972. X * 
  973. X * Revision 1.4  93/12/09  12:14:50  Torsten
  974. X * Moved the #include lines to get rid of a warning when using gcc.
  975. X * Blanks are now printed with \verb*+ + inside strings.
  976. X * The copyleft comment now refers to version 2 of the GPL.
  977. X * The usage() function changed a bit to display more POSIX.2
  978. X * compliant options ('--' instead of '+').
  979. X * 
  980. X * Revision 1.3  93/11/06  14:41:41  Torsten
  981. X * Added a few lines to the comment at the top of the program
  982. X * giving credit to the authors of C++2LaTeX.
  983. X * Program name isn't hard-wired anymore.
  984. X * ANSIfied the code a bit.
  985. X * 
  986. X * Revision 1.2  93/10/30  11:59:51  Torsten
  987. X * Corrected the usage "page".
  988. X * Changed "+piped" to "+pipe".
  989. X * 
  990. X * Revision 1.1  93/10/15  23:42:27  Torsten
  991. X * Initial revision
  992. X * 
  993. X */
  994. X
  995. X#include <stdio.h>
  996. X#include "getopt.h"
  997. X#include <string.h>
  998. X#include <fcntl.h>
  999. X#include <ctype.h>
  1000. X#include <time.h>
  1001. X
  1002. Xstatic char RCSid[] = "$Id: main.c,v 1.5 93/12/20 14:25:10 Torsten Rel $";
  1003. X
  1004. Xextern insidestring;
  1005. Xextern int tabtoend, tabtotab, complete_file, piped;
  1006. Xextern int aligntoright, header, fancysymbols;
  1007. Xextern char *font_size, *indentation, *comment_font, *header_font;
  1008. Xextern char *string_font, *keyword_font, *ident_font;
  1009. X
  1010. X/* Prototypes for functions defined in main.c */
  1011. Xvoid substitute(char *input);
  1012. Xvoid indent(char *blanks);
  1013. Xint main(int argc, char **argv);
  1014. Xvoid usage(char *name);
  1015. X
  1016. Xvoid substitute(char *input)
  1017. X{
  1018. X  while (*input) {
  1019. X    switch (*input) {
  1020. X    case '_':
  1021. X    case '&':
  1022. X    case '#':
  1023. X    case '$':
  1024. X    case '%':
  1025. X    case '{':
  1026. X    case '}':
  1027. X      printf("\\%c", *input);
  1028. X      break;
  1029. X    case '+':
  1030. X    case '=':
  1031. X    case '<':
  1032. X    case '>':
  1033. X      printf("$%c$", *input);
  1034. X      break;
  1035. X    case '*':
  1036. X      printf("$\\ast$");
  1037. X      break;
  1038. X    case '|':
  1039. X      printf("$\\mid$");
  1040. X      break;
  1041. X    case '\\':
  1042. X      printf("$\\backslash$");
  1043. X      break;
  1044. X    case '^':
  1045. X      printf("$\\wedge$");
  1046. X      break;
  1047. X    case '~':
  1048. X      printf("$\\sim$");
  1049. X      break;
  1050. X    case ' ':
  1051. X      if (insidestring)
  1052. X    printf("\\verb*+ +");
  1053. X      else
  1054. X    printf(" ");
  1055. X      break;
  1056. X    default:
  1057. X      printf("%c", *input);
  1058. X      break;
  1059. X    }
  1060. X    input++;
  1061. X  }
  1062. X}
  1063. X
  1064. Xvoid indent(char *blanks)
  1065. X{
  1066. X  int i;
  1067. X
  1068. X  i = 0;
  1069. X  while (*blanks) {
  1070. X    if (*blanks == ' ') {
  1071. X      i++;
  1072. X    }
  1073. X    else {            /* *blanks == '\t' */
  1074. X      while (++i % tabtotab) ;
  1075. X    }
  1076. X    blanks++;
  1077. X  }
  1078. X  printf("\\hspace*{%d\\indentation}", i);
  1079. X}
  1080. X
  1081. Xextern char *version_string;
  1082. X
  1083. Xstatic struct option opts[] =
  1084. X{
  1085. X  {"complete-file", 0, 0, 'c'},
  1086. X  {"fancy", 0, 0, 'f'},
  1087. X  {"font-size", 1, 0, 's'},
  1088. X  {"indentation", 1, 0, 'i'},
  1089. X  {"header", 0, 0, 'h'},
  1090. X  {"pipe", 0, 0, 'p'},
  1091. X  {"no-alignment", 0, 0, 'n'},
  1092. X  {"output", 1, 0, 'o'},
  1093. X  {"tabstop", 1, 0, 'T'},
  1094. X  {"end-comment", 1, 0, 'e'},
  1095. X  {"comment-font", 1, 0, 'C'},
  1096. X  {"string-font", 1, 0, 'S'},
  1097. X  {"identifier-font", 1, 0, 'I'},
  1098. X  {"keyword-font", 1, 0, 'K'},
  1099. X  {"header-font", 1, 0, 'H'},
  1100. X  {"version", 0, 0, 'V'},
  1101. X  {0, 0, 0, 0}
  1102. X};
  1103. X
  1104. Xchar *program_name;
  1105. X
  1106. Xmain(int argc, char **argv)
  1107. X{
  1108. X  int c;
  1109. X  int index;
  1110. X  int i;
  1111. X  int has_filename;
  1112. X  char *input_name;
  1113. X  char *output_name;
  1114. X  long now;
  1115. X  char *today;
  1116. X  char *malloc();
  1117. X
  1118. X  input_name = "Standard Input";
  1119. X  output_name = 0;
  1120. X
  1121. X  now = time(0);
  1122. X  today = ctime(&now);
  1123. X
  1124. X  program_name = argv[0];
  1125. X
  1126. X  if (argc == 1)
  1127. X    usage(program_name);
  1128. X
  1129. X  while ((c = getopt_long(argc, argv,
  1130. X              "cfpno:s:i:e:hT:C:H:S:I:K:V", opts, &index))
  1131. X     != EOF) {
  1132. X    if (c == 0) {
  1133. X      /* Long option */
  1134. X      c = opts[index].val;
  1135. X    }
  1136. X    switch (c) {
  1137. X    case 'c':
  1138. X      complete_file = 1;
  1139. X      break;
  1140. X    case 'f':
  1141. X      fancysymbols = 1;
  1142. X      break;
  1143. X    case 'o':
  1144. X      if (piped) {
  1145. X    fprintf(stderr,
  1146. X        "%s: Can't use {-p,--pipe} and {-o,--output} together\n",
  1147. X        program_name);
  1148. X    exit(5);
  1149. X      }
  1150. X      output_name = optarg;
  1151. X      break;
  1152. X    case 'n':
  1153. X      aligntoright = 0;
  1154. X      break;
  1155. X    case 's':
  1156. X      font_size = optarg;
  1157. X      break;
  1158. X    case 'i':
  1159. X      indentation = optarg;
  1160. X      break;
  1161. X    case 'e':
  1162. X      tabtoend = atoi(optarg);
  1163. X      break;
  1164. X    case 'T':
  1165. X      tabtotab = atoi(optarg);
  1166. X      break;
  1167. X    case 'p':
  1168. X      if (output_name != 0) {
  1169. X    fprintf(stderr,
  1170. X        "%s: Can't use {-p,--pipe} and {-o,--output} together\n",
  1171. X        program_name);
  1172. X    exit(5);
  1173. X      }
  1174. X      piped = 1;
  1175. X      break;
  1176. X    case 'h':
  1177. X      header = 1;
  1178. X      complete_file = 1;    /* header implies complete-file */
  1179. X      break;
  1180. X    case 'C':
  1181. X      comment_font = optarg;
  1182. X      break;
  1183. X    case 'H':
  1184. X      header_font = optarg;
  1185. X      break;
  1186. X    case 'S':
  1187. X      string_font = optarg;
  1188. X      break;
  1189. X    case 'I':
  1190. X      ident_font = optarg;
  1191. X      break;
  1192. X    case 'K':
  1193. X      keyword_font = optarg;
  1194. X      break;
  1195. X    case 'V':
  1196. X      fprintf(stderr, "%s\n", version_string);
  1197. X      break;
  1198. X    default:
  1199. X      usage(program_name);
  1200. X    }
  1201. X  }
  1202. X  has_filename = (argc - optind == 1);
  1203. X  if (has_filename) {
  1204. X    /* last argument is input file name */
  1205. X    input_name = argv[optind];
  1206. X    if (freopen(input_name, "r", stdin) == NULL) {
  1207. X      fprintf(stderr, "%s: Can't open `%s' for reading\n",
  1208. X          program_name, input_name);
  1209. X      exit(2);
  1210. X    }
  1211. X  }
  1212. X  if ((output_name == 0) && !piped) {
  1213. X    char *tmp;
  1214. X
  1215. X    if (has_filename) {
  1216. X      tmp = strrchr(input_name, '/');
  1217. X      if (tmp == 0) {
  1218. X    /* plain filename */
  1219. X    tmp = input_name;
  1220. X      }
  1221. X      else {
  1222. X    tmp++;
  1223. X      }
  1224. X    }
  1225. X    else {
  1226. X      tmp = program_name;
  1227. X    }
  1228. X
  1229. X    output_name = malloc(strlen(tmp) + 4);
  1230. X
  1231. X    if (output_name == 0) {
  1232. X      fprintf(stderr, "%s: Virtual memory exhausted\n", program_name);
  1233. X      exit(3);
  1234. X    }
  1235. X    strcpy(output_name, tmp);
  1236. X    strcat(output_name, ".tex");
  1237. X  }
  1238. X  if (!piped) {
  1239. X    if (freopen(output_name, "w", stdout) == NULL) {
  1240. X      fprintf(stderr, "%s: Can't open `%s' for writing\n",
  1241. X          program_name, output_name);
  1242. X      exit(3);
  1243. X    }
  1244. X  }
  1245. X  printf("\
  1246. X%%\n\
  1247. X%% This file was automatically produced at %.24s by\n\
  1248. X%% %s", today, program_name);
  1249. X  for (i = 1; i < argc; i++) {
  1250. X    printf(" %s", argv[i]);
  1251. X  }
  1252. X  if (!has_filename) {
  1253. X    printf(" (from Standard Input)");
  1254. X  }
  1255. X  printf("\n%%\n");
  1256. X  if (complete_file) {
  1257. X    if (header) {
  1258. X      if (strcmp(font_size, "10") == 0) {
  1259. X    printf("\\documentstyle[fancyheadings]{article}\n");
  1260. X      } else {
  1261. X    printf("\\documentstyle[%spt,fancyheadings]{article}\n",
  1262. X           font_size);
  1263. X      }
  1264. X    }
  1265. X    else {
  1266. X      if (strcmp(font_size, "10") == 0) {
  1267. X    printf("\\documentstyle{article}\n");
  1268. X      }
  1269. X      else {
  1270. X    printf("\\documentstyle[%spt]{article}\n", font_size);
  1271. X      }
  1272. X    }
  1273. X
  1274. X    printf("\\setlength{\\textwidth}{16cm}\n");
  1275. X    printf("\\setlength{\\textheight}{23cm}\n");
  1276. X    printf("\\setlength{\\hoffset}{-2cm}\n");
  1277. X    printf("\\setlength{\\voffset}{-2cm}\n");
  1278. X
  1279. X    if (header) {
  1280. X      printf("\\lhead{\\%s ", header_font);
  1281. X      substitute(input_name);
  1282. X      printf("}");
  1283. X      printf("\\rhead{\\rm\\thepage}\n");
  1284. X      printf("\\cfoot{}\n");
  1285. X      printf("\\addtolength{\\headheight}{14pt}\n");
  1286. X      printf("\\pagestyle{fancy}\n");
  1287. X    }
  1288. X    printf("\\begin{document}\n");
  1289. X  }
  1290. X
  1291. X  printf("\\expandafter\\ifx\\csname indentation\\endcsname\\relax%\n");
  1292. X  printf("\\newlength{\\indentation}\\fi\n");
  1293. X  printf("\\setlength{\\indentation}{%s}\n", indentation);
  1294. X
  1295. X  printf("\\begin{flushleft}\n");
  1296. X  yylex();
  1297. X  printf("\\end{flushleft}\n");
  1298. X
  1299. X  if (complete_file) {
  1300. X    printf("\\end{document}\n");
  1301. X  }
  1302. X  exit(0);
  1303. X}
  1304. X
  1305. Xvoid usage(char *name)
  1306. X{
  1307. X  fprintf(stderr, "%s\n", version_string);
  1308. X  fprintf(stderr, "\
  1309. XUsage: %s [options] [file]\n\n\
  1310. XShort options:\n\
  1311. X    [-c]            [-e distance]\n\
  1312. X    [-f]            [-h]\n\
  1313. X    [-i length]        [-n]\n\
  1314. X    [-o file]        [-p]\n\
  1315. X    [-s fontsize]        [-C font]\n\
  1316. X    [-H font]        [-I font]\n\
  1317. X    [-K font]        [-S font]\n\
  1318. X    [-T tabulatorwidth]    [-V]\n\
  1319. X\n\
  1320. XLong options:\n\
  1321. X    [--complete-file]    [--end-comment distance]\n\
  1322. X    [--fancy]        [--header]\n\
  1323. X    [--indentation length]    [--no-alignment]\n\
  1324. X    [--output file]        [--pipe]\n\
  1325. X    [--font-size size]    [--comment-font font]\n\
  1326. X    [--header-font font]    [--identifier-font font]\n\
  1327. X    [--keyword-font font]    [--string-font font]\n\
  1328. X    [--tabstop width]    [--version]\n", name);
  1329. X  exit(1);
  1330. X}
  1331. END_OF_FILE
  1332.   if test 9897 -ne `wc -c <'main.c'`; then
  1333.     echo shar: \"'main.c'\" unpacked with wrong size!
  1334.   fi
  1335.   # end of 'main.c'
  1336. fi
  1337. if test -f 'p2latex.l' -a "${1}" != "-c" ; then 
  1338.   echo shar: Will not clobber existing file \"'p2latex.l'\"
  1339. else
  1340.   echo shar: Extracting \"'p2latex.l'\" \(7390 characters\)
  1341.   sed "s/^X//" >'p2latex.l' <<'END_OF_FILE'
  1342. X/*
  1343. X *  p2LaTeX: Produce prettyprinted LaTeX files from Pascal sources.
  1344. X *  Copyright (C) 1993 Torsten Poulin
  1345. X *    Note: This program is derived from work done by others (see below).
  1346. X *
  1347. X *  This program is free software; you can redistribute it and/or modify
  1348. X *  it under the terms of the GNU General Public License as published by
  1349. X *  the Free Software Foundation; either version 2, or (at your option)
  1350. X *  any later version.
  1351. X *
  1352. X *  This program is distributed in the hope that it will be useful,
  1353. X *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  1354. X *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1355. X *  GNU General Public License for more details.
  1356. X *
  1357. X *  You should have received a copy of the GNU General Public License
  1358. X *  along with this program; if not, write to the Free Software
  1359. X *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1360. X *
  1361. X *  Torsten Poulin 
  1362. X *  Banebrinken 99, 2, 77
  1363. X *  DK-2400 Copenhagen NV
  1364. X *  DENMARK
  1365. X *
  1366. X *  e-mail: torsten@diku.dk
  1367. X *  --------------------------------------------------------------------
  1368. X *  p2latex is derived from the code for the program C++2LaTeX 2.0 which
  1369. X *  produces prettyprinted LaTeX files from C++ or C sources.
  1370. X *
  1371. X *  C++2LaTeX 2.0 is copyright (C) 1991 Joerg Heitkoetter
  1372. X *
  1373. X *     Systems Analysis Research Group
  1374. X *     University of Dortmund
  1375. X *     (heitkoet@gorbi.informatik.uni-dortmund.de).
  1376. X *
  1377. X *  The original C++2LaTeX is copyright (C) 1990 Norbert Kiesel
  1378. X *
  1379. X *      Norbert Kiesel
  1380. X *      RWTH Aachen / Institut f. Informatik III
  1381. X *      Ahornstr. 55
  1382. X *      D-5100 Aachen
  1383. X *      West Germany
  1384. X *
  1385. X *      Phone:  +49 241 80-7266
  1386. X *      EUNET:  norbert@rwthi3.uucp
  1387. X *      USENET: ...!mcvax!unido!rwthi3!norbert
  1388. X *      X.400:  norbert@rwthi3.informatik.rwth-aachen.de
  1389. X *  --------------------------------------------------------------------
  1390. X * p2latex p2main.l revision history.
  1391. X * $Log:    p2latex.l,v $
  1392. X * Revision 1.3  93/12/09  01:20:12  Torsten
  1393. X * Now sets the insidestring flag when inside a string.
  1394. X * Corrected the indentation of comments preceded only by white-space.
  1395. X * The copyleft comment now refers to version 2 of the GPL.
  1396. X * 
  1397. X * Revision 1.2  93/11/06  14:43:51  Torsten
  1398. X * Added a few lines to the comment at the top of the program
  1399. X * giving credit to the authors of C++2LaTeX.
  1400. X * Minus now emits -- (a TeX number-range dash) when not in
  1401. X * a comment or a string.
  1402. X * Strings are now printed using \frenchspacing to suppress
  1403. X * extra space after punctuation. 
  1404. X * 
  1405. X * Revision 1.1  93/10/15  23:41:49  Torsten
  1406. X * Initial revision
  1407. X *
  1408. X */
  1409. X
  1410. X%x STRING BCOMMENT
  1411. X
  1412. X%{
  1413. X#define KEY        printf ("{\\%s %s}", keyword_font, yytext)
  1414. X#define FANCYKEY(x)    fancysymbols ? printf(x) : KEY
  1415. X#define SYM(x)        printf ("$\\%s$", x)
  1416. X#define FANCY(x,y)    printf ("%s", fancysymbols ? x : y)
  1417. X#define OUT(x)        printf ("%s", x)
  1418. X#define ETAB        printf ("\\hspace*{%d\\indentation}", tabtoend)
  1419. X#define CTAB        printf ("\\hspace*{%d\\indentation}", tabtocomment)
  1420. X#define FONT(x)        printf ("{\\%s ",x)
  1421. X#define SUB(x)        substitute(x)
  1422. X#define IDENTIFIER    printf ("{\\%s %s\\/}", ident_font, yytext)
  1423. X#define IND        indent(yytext)
  1424. X#define INIT        BEGIN (INITIAL);
  1425. X
  1426. X#include <stdio.h>
  1427. X
  1428. Xstatic char RCSid[] = "$Id: p2latex.l,v 1.3 93/12/09 01:20:12 Torsten Rel $";
  1429. X
  1430. Xstatic void nindent(char *, int);
  1431. Xint insidestring    = 0;
  1432. X
  1433. Xint complete_file    = 0;
  1434. Xint header        = 0;
  1435. Xint tabtotab        = 8;
  1436. Xint piped        = 0;
  1437. Xint fancysymbols    = 0;
  1438. X
  1439. Xint aligntoright    = 1;        /* align comments to the right */
  1440. Xint tabtoend        = 2;        /* distance between end and comment */
  1441. Xint tabtocomment    = 4;        /* distance between statement and comment*/
  1442. X
  1443. Xchar *font_size        = "10";
  1444. Xchar *indentation    = "0.5em";
  1445. Xchar *comment_font    = "it";
  1446. Xchar *ident_font    = "it";
  1447. Xchar *keyword_font    = "bf";
  1448. Xchar *header_font    = "sl";
  1449. Xchar *string_font    = "tt";
  1450. X
  1451. X#ifdef __STDC__
  1452. Xvoid substitute(const char *);
  1453. Xvoid indent(const char *);
  1454. Xvoid newpage(int);
  1455. Xvoid usage(const char *);
  1456. X#else
  1457. Xvoid substitute();
  1458. Xvoid indent();
  1459. Xvoid newpage();
  1460. Xvoid usage();
  1461. X#endif
  1462. X%}
  1463. X
  1464. X%%
  1465. X
  1466. X            INIT;
  1467. X
  1468. X"array"            |
  1469. X"begin"            |
  1470. X"case"            |
  1471. X"const"            |
  1472. X"div"            |
  1473. X"do"            |
  1474. X"downto"        |
  1475. X"else"            |
  1476. X"end"            |
  1477. X"file"            |
  1478. X"for"            |
  1479. X"function"        |
  1480. X"goto"            |
  1481. X"if"            |
  1482. X"in"            |
  1483. X"label"            |
  1484. X"mod"            |
  1485. X"nil"            |
  1486. X"of"            |
  1487. X"packed"        |
  1488. X"procedure"        |
  1489. X"program"        |
  1490. X"record"        |
  1491. X"repeat"        |
  1492. X"set"            |
  1493. X"then"            |
  1494. X"to"            |
  1495. X"type"            |
  1496. X"until"            |
  1497. X"var"            |
  1498. X"while"            |
  1499. X"with"            KEY;
  1500. X"and"            FANCYKEY("$\\wedge$");
  1501. X"not"            FANCYKEY("$\\neg$");
  1502. X"or"            FANCYKEY("$\\vee");
  1503. X"<="            FANCY ("$\\leq$", "$<$=");
  1504. X">="            FANCY ("$\\geq$", "$>$=");
  1505. X"<>"            FANCY ("$\\neq$", "$<>$");
  1506. X"*"            SYM ("ast");
  1507. X"^"            SYM ("uparrow");
  1508. X"/"            OUT ("$/$");
  1509. X"<"            OUT ("$<$");
  1510. X">"            OUT ("$>$");
  1511. X"-"            OUT ("--");
  1512. X"("            |
  1513. X")"            |
  1514. X":"            |
  1515. X"="            |
  1516. X","            |
  1517. X"."            |
  1518. X";"            |
  1519. X"+"            |
  1520. X"["            |
  1521. X"]"            ECHO;
  1522. X
  1523. X[a-z_][a-z_0-9]*        IDENTIFIER;
  1524. X
  1525. X /* Comments mini scanner */
  1526. X /* 1. Comment after 'end;', 'end.', or 'end'  */
  1527. X"end"[;\.]?[ \t]*"(*"        { BEGIN (BCOMMENT);
  1528. X                { int i;
  1529. X                  printf("{\\%s ", keyword_font);
  1530. X                  for (i = 0; i < 3; i++)
  1531. X                    printf("%c", yytext[i]);
  1532. X                  printf("}");
  1533. X                  if (yytext[i] == ';' || yytext[i] == '.')
  1534. X                    printf("%c", yytext[i]); }
  1535. X                                ETAB;
  1536. X                                OUT ("($\\ast$");
  1537. X                                FONT (comment_font); }
  1538. X"end"[;\.]?[ \t]*"{"        { BEGIN (BCOMMENT);
  1539. X                { int i;
  1540. X                  printf("{\\%s ", keyword_font);
  1541. X                  for (i = 0; i < 3; i++)
  1542. X                    printf("%c", yytext[i]);
  1543. X                  printf("}");
  1544. X                  if (yytext[i] == ';' || yytext[i] == '.')
  1545. X                    printf("%c", yytext[i]); }
  1546. X                                ETAB;
  1547. X                                OUT ("\\{");
  1548. X                                FONT (comment_font); }
  1549. X
  1550. X /* 2. Comments at the beginning of a line */
  1551. X^[ \t]*"(*"              { BEGIN (BCOMMENT);
  1552. X                nindent(yytext, yyleng - 2);
  1553. X                                OUT ("($\\ast$");
  1554. X                FONT (comment_font); }
  1555. X^[ \t]*"{"              { BEGIN (BCOMMENT);
  1556. X                nindent(yytext, yyleng - 1);
  1557. X                OUT ("\\{");
  1558. X                FONT (comment_font); }
  1559. X
  1560. X /* 3. Other comments, aligned to right side of paper */
  1561. X"(*"                  { BEGIN (BCOMMENT);
  1562. X                                if (aligntoright) {
  1563. X                    OUT ("\\hfill");
  1564. X                } else {
  1565. X                    CTAB;
  1566. X                }
  1567. X                                OUT ("($\\ast$");
  1568. X                FONT (comment_font); }
  1569. X"{"                  { BEGIN (BCOMMENT);
  1570. X                                if (aligntoright) {
  1571. X                    OUT ("\\hfill");
  1572. X                } else {
  1573. X                    CTAB;
  1574. X                }
  1575. X                                OUT ("\\{");
  1576. X                FONT (comment_font); }
  1577. X
  1578. X
  1579. X<BCOMMENT>"*)"              { INIT; OUT ("}$\\ast$)"); }
  1580. X<BCOMMENT>"}"              { INIT; OUT ("}\\}"); }
  1581. X<BCOMMENT>"\n"            OUT ("\\mbox{}\\\\\n");
  1582. X<BCOMMENT>[ \t]+        IND;
  1583. X<BCOMMENT>.            SUB (yytext);
  1584. X
  1585. XL?\'                       { BEGIN (STRING);
  1586. X                FONT (string_font);
  1587. X                OUT ("\\frenchspacing{");
  1588. X                OUT ("\'");
  1589. X                insidestring = 1; }
  1590. X<STRING>\'              { INIT;
  1591. X                OUT ("\'}}");
  1592. X                insidestring = 0; }
  1593. X<STRING>"\n"            OUT ("\\mbox{}\\\\\n");
  1594. X<STRING>^[ \t]+            IND;
  1595. X<STRING>.            SUB (yytext);
  1596. X
  1597. X([0-9]*\.[0-9]+)        |
  1598. X([0-9]+\.[0-9]*)        |
  1599. X([0-9]*\.?[0-9]+e[+-]?[0-9]+)    |
  1600. X([0-9]+\.?[0-9]*e[+-]?[0-9]+)    ECHO;
  1601. X
  1602. X[0-9]+                ECHO;
  1603. X
  1604. X^[ \t]+                IND;
  1605. X[ \t]+                ECHO;
  1606. X"\f"[\n]?            OUT ("\\newpage\n");
  1607. X"\n"                OUT ("\\mbox{}\\\\\n");
  1608. X
  1609. X%%
  1610. X
  1611. Xstatic void nindent(char *blanks, int n)
  1612. X{
  1613. X  int i, bl;
  1614. X
  1615. X  for (i = bl = 0; i < n; i++) {
  1616. X    if (*blanks == ' ') {
  1617. X      bl++;
  1618. X    }
  1619. X    else {            /* *blanks == '\t' */
  1620. X      while (++bl % tabtotab) ;
  1621. X    }
  1622. X    blanks++;
  1623. X  }
  1624. X  printf("\\hspace*{%d\\indentation}", bl);
  1625. X}
  1626. END_OF_FILE
  1627.   if test 7390 -ne `wc -c <'p2latex.l'`; then
  1628.     echo shar: \"'p2latex.l'\" unpacked with wrong size!
  1629.   fi
  1630.   # end of 'p2latex.l'
  1631. fi
  1632. echo shar: End of archive 3 \(of 3\).
  1633. cp /dev/null ark3isdone
  1634. MISSING=""
  1635. for I in 1 2 3 ; do
  1636.     if test ! -f ark${I}isdone ; then
  1637.     MISSING="${MISSING} ${I}"
  1638.     fi
  1639. done
  1640. if test "${MISSING}" = "" ; then
  1641.     echo You have unpacked all 3 archives.
  1642.     rm -f ark[1-9]isdone
  1643. else
  1644.     echo You still must unpack the following archives:
  1645.     echo "        " ${MISSING}
  1646. fi
  1647. exit 0
  1648. exit 0 # Just in case...
  1649.