home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / groff / libXdvi / lex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-30  |  1.7 KB  |  104 lines

  1. #include <X11/Xos.h>
  2. #include <X11/IntrinsicP.h>
  3. #include <X11/StringDefs.h>
  4. #include <stdio.h>
  5. #include "DviP.h"
  6.  
  7. DviGetAndPut(dw, cp)
  8.     DviWidget    dw;
  9.     int        *cp;
  10. {
  11.     if (dw->dvi.ungot)
  12.     {
  13.     dw->dvi.ungot = 0;
  14.     *cp = getc (dw->dvi.file);
  15.     }
  16.     else
  17.     {
  18.     *cp = getc (dw->dvi.file);
  19.     putc (*cp, dw->dvi.tmpFile);
  20.     }
  21.     return *cp;
  22. }
  23.  
  24. char *
  25. GetLine(dw, Buffer, Length)
  26.     DviWidget    dw;
  27.     char    *Buffer;
  28.     int    Length;
  29. {
  30.     int     i = 0, c;
  31.     char    *p = Buffer;
  32.     
  33.     Length--;                /* Save room for final NULL */
  34.     
  35.     while (i < Length && DviGetC (dw, &c) != EOF && c != '\n')
  36.         if (p)
  37.             *p++ = c;
  38.     if (c == '\n' && p)            /* Retain the newline like fgets */
  39.         *p++ = c;
  40.     if (c == '\n')
  41.         DviUngetC(dw, c);
  42.     if (p)    
  43.         *p = NULL;
  44.     return (Buffer);
  45.  
  46. char *
  47. GetWord(dw, Buffer, Length)
  48.     DviWidget    dw;
  49.     char    *Buffer;
  50.     int    Length;
  51. {
  52.     int     i = 0, c;
  53.     char    *p = Buffer;
  54.     
  55.     Length--;                /* Save room for final NULL */
  56.     while (DviGetC(dw, &c) != EOF && (c == ' ' || c == '\n'))
  57.         ;
  58.     if (c != EOF)
  59.         DviUngetC(dw, c);
  60.     while (i < Length && DviGetC(dw, &c) != EOF && c != ' ' && c != '\n')
  61.         if (p)
  62.             *p++ = c;
  63.     if (c != EOF)
  64.         DviUngetC(dw, c);
  65.     if (p)
  66.         *p = NULL;
  67.     return (Buffer);
  68.  
  69. GetNumber(dw)
  70.     DviWidget    dw;
  71. {
  72.     int    i = 0,  c;
  73.     int    negative = 0;
  74.  
  75.     while (DviGetC(dw, &c) != EOF && (c == ' ' || c == '\n'))
  76.         ;
  77.     if (c != EOF)
  78.         DviUngetC(dw, c);
  79.     
  80.     while (DviGetC(dw, &c) != EOF && c >= '0' && c <= '9') {
  81.         if (negative)
  82.             i = i*10 - (c - '0');
  83.         else
  84.             i = i*10 + c - '0';
  85.     }
  86.  
  87.     if (c != EOF)
  88.         DviUngetC(dw, c);
  89.     return (i);
  90. }
  91.     
  92. /*
  93. Local Variables:
  94. c-indent-level: 8
  95. c-continued-statement-offset: 8
  96. c-brace-offset: -8
  97. c-argdecl-indent: 8
  98. c-label-offset: -8
  99. c-tab-always-indent: nil
  100. End:
  101. */
  102.