Merge from vendor branch BIND:
[dragonfly.git] / contrib / groff / src / 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 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
46 char *
47 GetWord(dw, Buffer, Length)
48         DviWidget       dw;
49         char    *Buffer;
50         int     Length;
51 {
52         int     i = 0, c;
53         
54         Length--;                           /* Save room for final '\0' */
55         while (DviGetC(dw, &c) == ' ' || c == '\n')
56                 ;
57         while (c != EOF) {
58                 if (Buffer && i < Length)
59                         Buffer[i++] = c;
60                 if (DviGetC(dw, &c) == ' ' || c == '\n') {
61                         DviUngetC(dw, c);
62                         break;
63                 }
64         }
65         if (Buffer)
66                 Buffer[i] = '\0';
67         return Buffer;
68
69
70 GetNumber(dw)
71         DviWidget       dw;
72 {
73         int     i = 0,  c;
74         int     negative = 0;
75
76         while (DviGetC(dw, &c) == ' ' || c == '\n')
77                 ;
78         if (c == '-') {
79                 negative = 1;
80                 DviGetC(dw, &c);
81         }
82
83         for (; c >= '0' && c <= '9'; DviGetC(dw, &c)) {
84                 if (negative)
85                         i = i*10 - (c - '0');
86                 else
87                         i = i*10 + c - '0';
88         }
89         if (c != EOF)
90                 DviUngetC(dw, c);
91         return i;
92 }
93         
94 /*
95 Local Variables:
96 c-indent-level: 8
97 c-continued-statement-offset: 8
98 c-brace-offset: -8
99 c-argdecl-indent: 8
100 c-label-offset: -8
101 c-tab-always-indent: nil
102 End:
103 */