XINU
Macros | Functions
fscanf.c File Reference

Go to the source code of this file.

Macros

#define EMPTY   (-1)
 
#define EOF   (-2)
 

Functions

int _doscan (register char *, register int **, int(*getc)(int, int), int(*ungetc)(int, int), int, int)
 
int fscanf (int dev, char *fmt, int args)
 
int getc (int)
 デバイスから1Byte読み込むgetc()のextern宣言 More...
 
static int getch (int, int)
 
static int ungetch (int, int)
 

Macro Definition Documentation

◆ EMPTY

#define EMPTY   (-1)

Definition at line 4 of file fscanf.c.

Referenced by fscanf(), getch(), and ungetch().

◆ EOF

#define EOF   (-2)

Definition at line 7 of file fscanf.c.

Referenced by getch().

Function Documentation

◆ _doscan()

int _doscan ( register char *  ,
register int **  ,
int(*)(int, int)  getc,
int(*)(int, int)  ungetc,
int  ,
int   
)

Definition at line 38 of file doscan.c.

References _getccl(), _innum(), EOF, getch(), isdigit, isupper, LONG, REGULAR, SHORT, tolower, and ungetch().

Referenced by fscanf().

46 {
47  register int ch;
48  int nmatch, len, ch1;
49  int **ptr, fileended, size;
50 
51  nmatch = 0;
52  fileended = 0;
53  for (;;)
54  {
55  switch (ch = *fmt++)
56  {
57  case '\0':
58  return (nmatch);
59  case '%':
60  if ((ch = *fmt++) == '%')
61  {
62  goto def;
63  }
64  ptr = 0;
65  if (ch != '*')
66  {
67  ptr = argp++;
68  }
69  else
70  {
71  ch = *fmt++;
72  }
73  len = 0;
74  size = REGULAR;
75  while (isdigit(ch))
76  {
77  len = len * 10 + ch - '0';
78  ch = *fmt++;
79  }
80  if (len == 0)
81  {
82  len = 30000;
83  }
84  if (ch == 'l')
85  {
86  ch = *fmt++;
87  size = LONG;
88  }
89  else if (ch == 'h')
90  {
91  size = SHORT;
92  ch = *fmt++;
93  }
94  else if (ch == '[')
95  {
96  fmt = _getccl(fmt);
97  }
98  if (isupper(ch))
99  {
100  ch = tolower(ch);
101  size = LONG;
102  }
103  if (ch == '\0')
104  {
105  return (-1);
106  }
107  if (_innum
108  (ptr, ch, len, size,
109  getch, ungetch, arg1, arg2, &fileended) && ptr)
110  {
111  nmatch++;
112  }
113  if (fileended)
114  {
115  return (nmatch ? nmatch : -1);
116  }
117  break;
118 
119  case ' ':
120  case '\n':
121  case '\t':
122  while ((ch1 =
123  (*getch) (arg1,
124  arg2)) == ' ' || ch1 == '\t' || ch1 == '\n')
125  {;
126  }
127  if (ch1 != EOF)
128  {
129  (*ungetch) (arg1, arg2);
130  }
131  break;
132 
133  default:
134  def:
135  ch1 = (*getch) (arg1, arg2);
136  if (ch1 != ch)
137  {
138  if (ch1 == EOF)
139  {
140  return (-1);
141  }
142  (*ungetch) (arg1, arg2);
143  return nmatch;
144  }
145  }
146  }
147 }
static int ungetch(int, int)
Definition: fscanf.c:60
#define tolower(c)
アルファベットの大文字を小文字に変換するマクロ
#define isdigit(c)
文字が10進数の数字かどうかをチェックするマクロ
Definition: ctype.h:78
#define EOF
Definition: doscan.c:7
static int _innum(int **, int, int, int, int(*getc)(int, int), int(*ungetc)(int, int), int, int, int *)
Definition: doscan.c:153
#define isupper(c)
文字がアルファベットの大文字かどうかをチェックするマクロ
Definition: ctype.h:62
#define LONG
Definition: doscan.c:15
static int getch(int, int)
Definition: fscanf.c:40
#define SHORT
Definition: doscan.c:13
#define REGULAR
Definition: doscan.c:14
static char * _getccl(char *)
Definition: doscan.c:367
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fscanf()

int fscanf ( int  dev,
char *  fmt,
int  args 
)

Definition at line 23 of file fscanf.c.

References _doscan(), EMPTY, getch(), and ungetch().

28 {
29  int buf;
30 
31  buf = EMPTY;
32  return (_doscan
33  (fmt, (int **)&args, getch, ungetch, dev, (int)(int)&buf));
34 }
static int ungetch(int, int)
Definition: fscanf.c:60
#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
static int getch(int, int)
Definition: fscanf.c:40
Here is the call graph for this function:

◆ getc()

int getc ( int  )

デバイスから1Byte読み込むgetc()のextern宣言

Definition at line 9 of file getc.c.

References devtab, disable(), dentry::dvgetc, isbaddev, restore(), and SYSERR.

Referenced by getch().

12 {
13  intmask mask; /* Saved interrupt mask */
14  struct dentry *devptr; /* Entry in device switch table */
15  int32 retval; /* Value to return to caller */
16 
17  mask = disable();
18  if (isbaddev(descrp)) {
19  restore(mask);
20  return SYSERR;
21  }
22  devptr = (struct dentry *) &devtab[descrp];
23  retval = (*devptr->dvgetc) (devptr);
24  restore(mask);
25  return retval;
26 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
devcall(* dvgetc)(struct dentry *)
Definition: conf.h:16
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getch()

static int getch ( int  dev,
int  abuf 
)
static

Definition at line 40 of file fscanf.c.

References EMPTY, EOF, and getc().

Referenced by _doscan(), _innum(), _instr(), and fscanf().

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 }
#define EOF
Definition: fscanf.c:7
#define EMPTY
Definition: fscanf.c:4
int getc(int)
デバイスから1Byte読み込むgetc()のextern宣言
Definition: getc.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ungetch()

static int ungetch ( int  dev,
int  abuf 
)
static

Definition at line 60 of file fscanf.c.

References EMPTY.

Referenced by _doscan(), _innum(), and fscanf().

64 {
65  int *buf = (int *)abuf;
66 
67  *buf = EMPTY;
68  return (*buf);
69 }
#define EMPTY
Definition: fscanf.c:4
Here is the caller graph for this function: