XINU
fscanf.c
Go to the documentation of this file.
1 /* fscanf.c - fscanf, getch, ungetch */
2 
3 #ifndef EMPTY
4 #define EMPTY (-1)
5 #endif
6 #ifndef EOF
7 #define EOF (-2)
8 #endif
9 
10 extern int getc(int);
11 
12 static int getch(int, int);
13 static int ungetch(int, int);
14 extern int _doscan(register char *, register int **,
15  int (*getc) (int, int), int (*ungetc) (int, int), int,
16  int);
17 
18 /*------------------------------------------------------------------------
19  * fscanf - Read from a device (file) according to a format.
20  * Return result of _doscan.
21  *------------------------------------------------------------------------
22  */
23 int fscanf(
24  int dev, /* device to use */
25  char *fmt, /* format string */
26  int args /* num of args in format */
27  )
28 {
29  int buf;
30 
31  buf = EMPTY;
32  return (_doscan
33  (fmt, (int **)&args, getch, ungetch, dev, (int)(int)&buf));
34 }
35 
36 /*------------------------------------------------------------------------
37  * getch - Get a character from a device with pushback.
38  *------------------------------------------------------------------------
39  */
40 static int getch(
41  int dev, /* device to use */
42  int abuf /* buffer to use */
43  )
44 {
45  int *buf = (int *)abuf;
46 
47  if (*buf != EOF && *buf != EMPTY)
48  {
49  *buf = getc(dev);
50  }
51 /* if( *buf != EOF ) */
52 /* { *buf = control(dev, TTY_IOC_NEXTC, 0, 0); } */
53  return (*buf);
54 }
55 
56 /*------------------------------------------------------------------------
57  * ungetch - Pushback a character for getch.
58  *------------------------------------------------------------------------
59  */
60 static int ungetch(
61  int dev, /* device to use */
62  int abuf /* buffer to use */
63  )
64 {
65  int *buf = (int *)abuf;
66 
67  *buf = EMPTY;
68  return (*buf);
69 }
static int ungetch(int, int)
Definition: fscanf.c:60
#define EOF
Definition: fscanf.c:7
#define EMPTY
Definition: fscanf.c:4
int _doscan(register char *, register int **, int(*getc)(int, int), int(*ungetc)(int, int), int, int)
Definition: doscan.c:38
int fscanf(int dev, char *fmt, int args)
Definition: fscanf.c:23
int getc(int)
デバイスから1Byte読み込むgetc()のextern宣言
Definition: getc.c:9
static int getch(int, int)
Definition: fscanf.c:40