-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_tab.c
101 lines (92 loc) · 2.3 KB
/
read_tab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************/
/* */
/* $Header: server.c,v 1.23 93/03/30 16:19:12 tine Exp $ */
/* */
/******************************************************************************/
/*avoid duplicate definitions */
# include <stdio.h>
#include <unistd.h>
# include <string.h> /* fuer 'strlen()', 'memset()' */
# include <fcntl.h>
# include <server.h>
int
read_tab(char *line, GUITAB *guitab)
{
char *s = line;
char *u;
char tmp[256];
char *t = tmp;
int count = 0;
int j, k, ix;
while ((*s != '#') && (*s != '\n'))
*t++ = *s++;
*t = '\0';
s = tmp;
for (j = 1; j <= 8; j++)
{
if (*s == '\0')
return (count);
while ( (*s == ' ') || (*s =='\t') )
{
s++;
}
if (*s == '\0')
return (count);
switch (count)
{
case 0:
k = sscanf(s, "%s", &guitab->name[0]);
break;
case 1:
k = sscanf(s, "%d", &guitab->addr_port);
break;
case 2:
k = sscanf(s, "%d", &guitab->server_port);
break;
case 3:
k = sscanf(s, "%d", &guitab->ust_port);
break;
case 4:
k = sscanf(s, "%s", &guitab->host[0]);
break;
case 5:
k = sscanf(s, "%s", &guitab->display[0]);
break;
case 6:
if (*s != '"')
{
k = 0;
break;
}
s++;
u = guitab->title;
for (ix = 0; ix < 63; ix++)
{
if (*s == '"')
{
s++;
break;
}
*u++ = *s++;
}
*u = '\0';
k = strlen(guitab->title);
break;
case 7:
k = sscanf(s, "%s", &guitab->process[0]);
break;
}
if (k)
count++;
if (count < 8)
while ( (*s != ' ') && (*s != '\t') )
s++;
}
while ( (*s == ' ') && (*s =='\t') )
{
if (*s == '\0')
return (count);
s++;
}
return (count);
}