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