PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/groff/src/devices/xditview/lex.c

https://bitbucket.org/freebsd/freebsd-head/
C | 96 lines | 76 code | 10 blank | 10 comment | 35 complexity | eeb98e420bf842816139e7894ab09211 MD5 | raw file
 1#include <X11/Xos.h>
 2#include <X11/IntrinsicP.h>
 3#include <X11/StringDefs.h>
 4#include <stdio.h>
 5#include "DviP.h"
 6
 7int
 8DviGetAndPut(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
22char *
23GetLine(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
42char *
43GetWord(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
63int
64GetNumber(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/*
88Local Variables:
89c-indent-level: 8
90c-continued-statement-offset: 8
91c-brace-offset: -8
92c-argdecl-indent: 8
93c-label-offset: -8
94c-tab-always-indent: nil
95End:
96*/