]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/groff/src/devices/xditview/lex.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / groff / src / devices / xditview / lex.c
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 int
8 DviGetAndPut(DviWidget dw, int *cp)
9 {
10         if (dw->dvi.ungot) {
11                 dw->dvi.ungot = 0;
12                 *cp = getc (dw->dvi.file);
13         }
14         else {
15                 *cp = getc (dw->dvi.file);
16                 if (*cp != EOF)
17                         putc (*cp, dw->dvi.tmpFile);
18         }
19         return *cp;
20 }
21
22 char *
23 GetLine(DviWidget dw, char *Buffer, int Length)
24 {
25         int     i = 0, c;
26         
27         Length--;                    /* Save room for final '\0' */
28         
29         while (DviGetC (dw, &c) != EOF) {
30                 if (Buffer && i < Length)
31                         Buffer[i++] = c;
32                 if (c == '\n') {
33                         DviUngetC(dw, c);
34                         break;
35                 }
36         }
37         if (Buffer)
38                 Buffer[i] = '\0';
39         return Buffer;
40
41
42 char *
43 GetWord(DviWidget dw, char *Buffer, int Length)
44 {
45         int     i = 0, c;
46         
47         Length--;                           /* Save room for final '\0' */
48         while (DviGetC(dw, &c) == ' ' || c == '\n')
49                 ;
50         while (c != EOF) {
51                 if (Buffer && i < Length)
52                         Buffer[i++] = c;
53                 if (DviGetC(dw, &c) == ' ' || c == '\n') {
54                         DviUngetC(dw, c);
55                         break;
56                 }
57         }
58         if (Buffer)
59                 Buffer[i] = '\0';
60         return Buffer;
61
62
63 int
64 GetNumber(DviWidget dw)
65 {
66         int     i = 0,  c;
67         int     negative = 0;
68
69         while (DviGetC(dw, &c) == ' ' || c == '\n')
70                 ;
71         if (c == '-') {
72                 negative = 1;
73                 DviGetC(dw, &c);
74         }
75
76         for (; c >= '0' && c <= '9'; DviGetC(dw, &c)) {
77                 if (negative)
78                         i = i*10 - (c - '0');
79                 else
80                         i = i*10 + c - '0';
81         }
82         if (c != EOF)
83                 DviUngetC(dw, c);
84         return i;
85 }
86         
87 /*
88 Local Variables:
89 c-indent-level: 8
90 c-continued-statement-offset: 8
91 c-brace-offset: -8
92 c-argdecl-indent: 8
93 c-label-offset: -8
94 c-tab-always-indent: nil
95 End:
96 */