home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / util / gnu / groff_src.lha / groff-1.10src / xditview / lex.c < prev    next >
C/C++ Source or Header  |  1992-03-08  |  2KB  |  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.         dw->dvi.ungot =    0;
  13.         *cp = getc (dw->dvi.file);
  14.     }
  15.     else {
  16.         *cp = getc (dw->dvi.file);
  17.         if (*cp != EOF)
  18.             putc (*cp, dw->dvi.tmpFile);
  19.     }
  20.     return *cp;
  21. }
  22.  
  23. char *
  24. GetLine(dw, Buffer, Length)
  25.     DviWidget    dw;
  26.     char    *Buffer;
  27.     int    Length;
  28. {
  29.     int     i = 0, c;
  30.     
  31.     Length--;             /* Save room for final '\0' */
  32.     
  33.     while (DviGetC (dw, &c) != EOF) {
  34.         if (Buffer && i < Length)
  35.             Buffer[i++] = c;
  36.         if (c == '\n') {
  37.             DviUngetC(dw, c);
  38.             break;
  39.         }
  40.     }
  41.     if (Buffer)
  42.         Buffer[i] = '\0';
  43.     return Buffer;
  44.  
  45. char *
  46. GetWord(dw, Buffer, Length)
  47.     DviWidget    dw;
  48.     char    *Buffer;
  49.     int    Length;
  50. {
  51.     int     i = 0, c;
  52.     
  53.     Length--;                /* Save room for final '\0' */
  54.     while (DviGetC(dw, &c) == ' ' || c == '\n')
  55.         ;
  56.     while (c != EOF) {
  57.         if (Buffer && i < Length)
  58.             Buffer[i++] = c;
  59.         if (DviGetC(dw, &c) == ' ' || c == '\n') {
  60.             DviUngetC(dw, c);
  61.             break;
  62.         }
  63.     }
  64.     if (Buffer)
  65.         Buffer[i] = '\0';
  66.     return Buffer;
  67.  
  68. GetNumber(dw)
  69.     DviWidget    dw;
  70. {
  71.     int    i = 0,  c;
  72.     int    negative = 0;
  73.  
  74.     while (DviGetC(dw, &c) == ' ' || c == '\n')
  75.         ;
  76.     if (c == '-') {
  77.         negative = 1;
  78.         DviGetC(dw, &c);
  79.     }
  80.  
  81.     for (; c >= '0' && c <= '9'; DviGetC(dw, &c)) {
  82.         if (negative)
  83.             i = i*10 - (c - '0');
  84.         else
  85.             i = i*10 + c - '0';
  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.