forked from svarshavchik/vera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverac_parseinittab.c
63 lines (53 loc) · 988 Bytes
/
verac_parseinittab.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
#include "config.h"
#include "verac.h"
#include <string.h>
#include <stdio.h>
void parse_inittab(FILE *fp,
void (*cb)(const char *original_line,
const char *identifier,
const char *runlevels,
const char *action,
const char *command,
void *),
void *cbarg)
{
char buf[1024];
char orig_buf[1024];
while (fgets(buf, sizeof(buf), fp))
{
const char *identifier=NULL;
const char *runlevels="";
const char *action="";
const char *command="";
char *p, *q;
if ((p=strchr(buf, '#')) != 0)
*p=0;
for (p=q=buf; *p; ++p)
{
if (strchr(" \t\r\n", *p) == 0)
{
q=p+1;
}
}
*q=0;
strcpy(orig_buf, buf);
p=strchr(buf, ':');
if (p)
{
identifier=buf;
*p++=0;
runlevels=p;
if ((p=strchr(p, ':')) != 0)
{
*p++=0;
action=p;
if ((p=strchr(p, ':')) != 0)
{
*p++=0;
command=p;
}
}
}
(*cb)(orig_buf, identifier, runlevels, action, command, cbarg);
}
}