100994698Smrg#ifdef HAVE_CONFIG_H 200994698Smrg# include "config.h" 300994698Smrg#endif 4f80a6dcdSmrg 5f80a6dcdSmrg#include <X11/Xos.h> 6f80a6dcdSmrg#include <X11/IntrinsicP.h> 7f80a6dcdSmrg#include <X11/StringDefs.h> 8f80a6dcdSmrg#include <stdio.h> 9f80a6dcdSmrg#include <ctype.h> 10f80a6dcdSmrg#include "DviP.h" 11f80a6dcdSmrg 12f80a6dcdSmrgint 1365912f00SmrgDviGetAndPut(DviWidget dw, int *cp) 14f80a6dcdSmrg{ 1500994698Smrg if (dw->dvi.ungot) { 1600994698Smrg dw->dvi.ungot = 0; 1700994698Smrg *cp = getc(dw->dvi.file); 18f80a6dcdSmrg } 1900994698Smrg else { 2000994698Smrg *cp = getc(dw->dvi.file); 2100994698Smrg putc(*cp, dw->dvi.tmpFile); 22f80a6dcdSmrg } 23f80a6dcdSmrg return *cp; 24f80a6dcdSmrg} 25f80a6dcdSmrg 26f80a6dcdSmrgchar * 2765912f00SmrgGetLine(DviWidget dw, char *Buffer, int Length) 28f80a6dcdSmrg{ 2900994698Smrg int i = 0, c = 0; 3000994698Smrg char *p = Buffer; 31f80a6dcdSmrg 3200994698Smrg Length--; /* Save room for final NULL */ 33f80a6dcdSmrg 3400994698Smrg while ((!p || i++ < Length) && DviGetC(dw, &c) != EOF && c != '\n') { 3500994698Smrg if (p) 3600994698Smrg *p++ = c; 3700994698Smrg } 3800994698Smrg if (c == '\n') 3900994698Smrg DviUngetC(dw, c); 4000994698Smrg if (p) 4100994698Smrg *p = '\0'; 4200994698Smrg return (Buffer); 43f80a6dcdSmrg} 44f80a6dcdSmrg 45f80a6dcdSmrgchar * 4665912f00SmrgGetWord(DviWidget dw, char *Buffer, int Length) 47f80a6dcdSmrg{ 4800994698Smrg int i = 0, c; 4900994698Smrg char *p = Buffer; 50f80a6dcdSmrg 5100994698Smrg Length--; /* Save room for final NULL */ 5200994698Smrg while (DviGetC(dw, &c) != EOF && isspace(c)) 5300994698Smrg ; 5400994698Smrg if (c != EOF) 5500994698Smrg DviUngetC(dw, c); 5600994698Smrg while (i++ < Length && DviGetC(dw, &c) != EOF && !isspace(c)) { 5700994698Smrg if (p) 5800994698Smrg *p++ = c; 5900994698Smrg } 6000994698Smrg if (c != EOF) 6100994698Smrg DviUngetC(dw, c); 6200994698Smrg if (p) 6300994698Smrg *p = '\0'; 6400994698Smrg return (Buffer); 65f80a6dcdSmrg} 66f80a6dcdSmrg 67f80a6dcdSmrgint 6865912f00SmrgGetNumber(DviWidget dw) 69f80a6dcdSmrg{ 7000994698Smrg int i = 0, c; 71f80a6dcdSmrg 7200994698Smrg while (DviGetC(dw, &c) != EOF && isspace(c)) 7300994698Smrg ; 7400994698Smrg if (c != EOF) 7500994698Smrg DviUngetC(dw, c); 7600994698Smrg while (DviGetC(dw, &c) != EOF && isdigit(c)) 7700994698Smrg i = i * 10 + c - '0'; 7800994698Smrg if (c != EOF) 7900994698Smrg DviUngetC(dw, c); 8000994698Smrg return (i); 81f80a6dcdSmrg} 82