lex.c revision f80a6dcd
1/* $XFree86: xc/programs/xditview/lex.c,v 1.3 2000/12/04 21:01:01 dawes Exp $ */ 2 3#include <X11/Xos.h> 4#include <X11/IntrinsicP.h> 5#include <X11/StringDefs.h> 6#include <stdio.h> 7#include <ctype.h> 8#include "DviP.h" 9 10int 11DviGetAndPut(dw, cp) 12 DviWidget dw; 13 int *cp; 14{ 15 if (dw->dvi.ungot) 16 { 17 dw->dvi.ungot = 0; 18 *cp = getc (dw->dvi.file); 19 } 20 else 21 { 22 *cp = getc (dw->dvi.file); 23 putc (*cp, dw->dvi.tmpFile); 24 } 25 return *cp; 26} 27 28char * 29GetLine(dw, Buffer, Length) 30 DviWidget dw; 31 char *Buffer; 32 int Length; 33{ 34 int i = 0, c; 35 char *p = Buffer; 36 37 Length--; /* Save room for final NULL */ 38 39 while ((!p || i < Length) && DviGetC (dw, &c) != EOF && c != '\n') 40 if (p) 41 *p++ = c; 42#if 0 43 if (c == '\n' && p) /* Retain the newline like fgets */ 44 *p++ = c; 45#endif 46 if (c == '\n') 47 DviUngetC(dw, c); 48 if (p) 49 *p = '\0'; 50 return (Buffer); 51} 52 53char * 54GetWord(dw, Buffer, Length) 55 DviWidget dw; 56 char *Buffer; 57 int Length; 58{ 59 int i = 0, c; 60 char *p = Buffer; 61 62 Length--; /* Save room for final NULL */ 63 while (DviGetC(dw, &c) != EOF && isspace(c)) 64 ; 65 if (c != EOF) 66 DviUngetC(dw, c); 67 while (i < Length && DviGetC(dw, &c) != EOF && !isspace(c)) 68 if (p) 69 *p++ = c; 70 if (c != EOF) 71 DviUngetC(dw, c); 72 if (p) 73 *p = '\0'; 74 return (Buffer); 75} 76 77int 78GetNumber(dw) 79 DviWidget dw; 80{ 81 int i = 0, c; 82 83 while (DviGetC(dw, &c) != EOF && isspace(c)) 84 ; 85 if (c != EOF) 86 DviUngetC(dw, c); 87 while (DviGetC(dw, &c) != EOF && isdigit(c)) 88 i = i*10 + c - '0'; 89 if (c != EOF) 90 DviUngetC(dw, c); 91 return (i); 92} 93