Home | History | Annotate | Line # | Download | only in xditview
      1 /*	$NetBSD: lex.c,v 1.1.1.1 2016/01/13 18:41:49 christos Exp $	*/
      2 
      3 #include <X11/Xos.h>
      4 #include <X11/IntrinsicP.h>
      5 #include <X11/StringDefs.h>
      6 #include <stdio.h>
      7 #include "DviP.h"
      8 
      9 int
     10 DviGetAndPut(DviWidget dw, int *cp)
     11 {
     12 	if (dw->dvi.ungot) {
     13 		dw->dvi.ungot =	0;
     14 		*cp = getc (dw->dvi.file);
     15 	}
     16 	else {
     17 		*cp = getc (dw->dvi.file);
     18 		if (*cp != EOF)
     19 			putc (*cp, dw->dvi.tmpFile);
     20 	}
     21 	return *cp;
     22 }
     23 
     24 char *
     25 GetLine(DviWidget dw, char *Buffer, int Length)
     26 {
     27 	int 	i = 0, c;
     28 
     29 	Length--;		     /* Save room for final '\0' */
     30 
     31 	while (DviGetC (dw, &c) != EOF) {
     32 		if (Buffer && i < Length)
     33 			Buffer[i++] = c;
     34 		if (c == '\n') {
     35 			DviUngetC(dw, c);
     36 			break;
     37 		}
     38 	}
     39 	if (Buffer)
     40 		Buffer[i] = '\0';
     41 	return Buffer;
     42 }
     43 
     44 char *
     45 GetWord(DviWidget dw, char *Buffer, int Length)
     46 {
     47 	int 	i = 0, c;
     48 
     49 	Length--;			    /* Save room for final '\0' */
     50 	while (DviGetC(dw, &c) == ' ' || c == '\n')
     51 		;
     52 	while (c != EOF) {
     53 		if (Buffer && i < Length)
     54 			Buffer[i++] = c;
     55 		if (DviGetC(dw, &c) == ' ' || c == '\n') {
     56 			DviUngetC(dw, c);
     57 			break;
     58 		}
     59 	}
     60 	if (Buffer)
     61 		Buffer[i] = '\0';
     62 	return Buffer;
     63 }
     64 
     65 int
     66 GetNumber(DviWidget dw)
     67 {
     68 	int	i = 0,  c;
     69 	int	negative = 0;
     70 
     71 	while (DviGetC(dw, &c) == ' ' || c == '\n')
     72 		;
     73 	if (c == '-') {
     74 		negative = 1;
     75 		DviGetC(dw, &c);
     76 	}
     77 
     78 	for (; c >= '0' && c <= '9'; DviGetC(dw, &c)) {
     79 		if (negative)
     80 			i = i*10 - (c - '0');
     81 		else
     82 			i = i*10 + c - '0';
     83 	}
     84 	if (c != EOF)
     85 		DviUngetC(dw, c);
     86 	return i;
     87 }
     88 
     89 /*
     90 Local Variables:
     91 c-indent-level: 8
     92 c-continued-statement-offset: 8
     93 c-brace-offset: -8
     94 c-argdecl-indent: 8
     95 c-label-offset: -8
     96 c-tab-always-indent: nil
     97 End:
     98 */
     99