summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2008-03-20 10:36:59 -0500
committerDan Nicholson <dbn.lists@gmail.com>2008-03-20 10:36:59 -0500
commita7f0e89d3d7bc2c6f028c9e272a4a4592e1f0285 (patch)
tree115ca8b2e69a91d710a2796657970e94007b1066 /test
parent7ea297eb548f0d6e6be8355245f9cb444df0406e (diff)
Set initd_t members from script parser
The parsing code is actually now useful in that it creates an initd_t structure and sets the members as it reads the supplied script. The initd_parse function has been changed to take a path and return an allocated initd_t. The path to the script must be valid. I.e., we no longer try to guess the directory. This functionality might be added back later at a higher level. To support setting the various members, a few functions have been added to the parsing code. initd_parse_line_tokens takes a line and loops over the tokens, adding the values found to the provided keys. This will have to validate input later. The tparse test has been changed to print the values from the allocated initd_t.
Diffstat (limited to 'test')
-rw-r--r--test/tparse.c58
1 files changed, 51 insertions, 7 deletions
diff --git a/test/tparse.c b/test/tparse.c
index 7f8a067..8c88066 100644
--- a/test/tparse.c
+++ b/test/tparse.c
@@ -6,16 +6,14 @@
#include "initd.h"
#include "str.h"
+static void print_initd(initd_t *ip);
+static void print_level(initd_rc_t rc);
+
int main(int argc, char *argv[])
{
initd_t *t;
char *tpath;
- if (setenv("INITD_DIR", ".", 0) < 0) {
- printf("Error setting the INITD_DIR envvar\n");
- exit(1);
- }
-
if (argc > 1) {
tpath = argv[1];
} else {
@@ -24,8 +22,54 @@ int main(int argc, char *argv[])
}
printf("Opening script %s\n", tpath);
- t = initd_new(tpath);
- initd_parse(t);
+ t = initd_parse(tpath);
+ print_initd(t);
return 0;
}
+
+static void print_initd(initd_t *ip)
+{
+ int n;
+
+ printf("%s: %s\n\n%s\n\n", ip->name, ip->sdesc, ip->desc);
+ printf("Provides:");
+ for (n = 0; n < ip->prov->nprov; n++)
+ printf(" %s", ip->prov->prov[n]);
+ putchar('\n');
+ printf("Default start levels:");
+ print_level(ip->dstart);
+ putchar('\n');
+ printf("Default stop levels:");
+ print_level(ip->dstop);
+ putchar('\n');
+
+ printf("Required start after:");
+ for (n = 0; n < ip->rstart->ndep; n++)
+ printf(" %s", ip->rstart->dep[n]);
+ putchar('\n');
+ printf("Required stop before:");
+ for (n = 0; n < ip->rstop->ndep; n++)
+ printf(" %s", ip->rstop->dep[n]);
+ putchar('\n');
+ printf("Should start after:");
+ for (n = 0; n < ip->sstart->ndep; n++)
+ printf(" %s", ip->sstart->dep[n]);
+ putchar('\n');
+ printf("Should stop before:");
+ for (n = 0; n < ip->sstop->ndep; n++)
+ printf(" %s", ip->sstop->dep[n]);
+ putchar('\n');
+}
+
+static void print_level(initd_rc_t rc)
+{
+ if (rc & RC_SI) printf(" sysinit");
+ if (rc & RC_0) printf(" 0");
+ if (rc & RC_1) printf(" 1");
+ if (rc & RC_2) printf(" 2");
+ if (rc & RC_3) printf(" 3");
+ if (rc & RC_4) printf(" 4");
+ if (rc & RC_5) printf(" 5");
+ if (rc & RC_6) printf(" 6");
+}