English Language flag
// Log In
// CVSweb
Project: FreeWRT
// Summary // Activity // Search // Tracker // Lists // News // SCM // Wiki

SCM Repository

ViewVC logotype

Contents of /branches/common-nfo/tools/nfotiser/pfile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3467 - (show annotations) (download)
Thu Aug 9 15:24:47 2007 UTC (6 years, 6 months ago) by tg
File MIME type: text/plain
File size: 5061 byte(s)
this is how it goes farther

1 /* $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $ */
2
3 /*-
4 * Copyright (c) 2007
5 * Thorsten Glaser <tg@mirbsd.de>
6 *
7 * Provided that these terms and disclaimer and all copyright notices
8 * are retained or reproduced in an accompanying document, permission
9 * is granted to deal in this work without restriction, including un-
10 * limited rights to use, publicly perform, distribute, sell, modify,
11 * merge, give away, or sublicence.
12 *
13 * Advertising materials mentioning features or use of this work must
14 * display the following acknowledgement:
15 * This product includes material provided by Thorsten Glaser.
16 * This acknowledgement does not need to be reprinted if this work is
17 * linked into a bigger work whose licence does not allow such clause
18 * and the author of this work is given due credit in the bigger work
19 * or its accompanying documents, where such information is generally
20 * kept, provided that said credits are retained.
21 *
22 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
23 * the utmost extent permitted by applicable law, neither express nor
24 * implied; without malicious intent or gross negligence. In no event
25 * may a licensor, author or contributor be held liable for indirect,
26 * direct, other damage, loss, or other issues arising in any way out
27 * of dealing in the work, even if advised of the possibility of such
28 * damage or existence of a defect, except proven that it results out
29 * of said person's immediate fault when using the work as intended.
30 */
31
32 #include <sys/param.h>
33
34 #include <err.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42
43 static void do_defaultvalues(struct parser_result *);
44 static void do_varexpand(struct parser_result *);
45
46 enum kwords {
47 KA_DISTFILE,
48 KA_HASH,
49 KA_RCCONF,
50 KN_DISTFILES,
51 K_BDEPS,
52 K_BROKEN,
53 K_CATEGORY,
54 K_CITEM,
55 K_CONFFILES,
56 K_CONFSYMS,
57 K_CSYM,
58 K_DASHVER,
59 K_DEFLT,
60 K_DESC,
61 K_FLAVOURS,
62 K_GROUPS,
63 K_HASHES,
64 K_HELP,
65 K_MDEPS,
66 K_MENUITEM,
67 K_MULTIPKGS,
68 K_NAME,
69 K_PERMIT_BIN,
70 K_PERMIT_SRC,
71 K_PKGDEPS,
72 K_PKGNAME,
73 K_RCCONF_SYMS,
74 K_SDEPS,
75 K_SITES,
76 K_URLS,
77 K_USERS,
78 K_VDEPS,
79 K_VERSION
80 };
81 #define parser_kwords enum kwords
82
83 #include "extern.h"
84
85 static const struct parser_keywords kwords[] = {
86 /* sorted but shortest-match aware */
87 { "BROKEN", K_BROKEN, KWT_NORMAL, ARGT_STRING },
88 { "BUILDDEPS", K_BDEPS, KWT_MULTI, ARGT_STRING },
89 { "CATEGORY", K_CATEGORY, KWT_MULTI, ARGT_STRING },
90 { "CITEM", K_CITEM, KWT_MULTI, ARGT_STRING },
91 { "CONFFILES", K_CONFFILES, KWT_MULTI, ARGT_STRING },
92 { "CONFSYMS", K_CONFSYMS, KWT_NORMAL, ARGT_STRING },
93 { "CSYMDEPS", K_SDEPS, KWT_MULTI, ARGT_STRING },
94 { "CSYM", K_CSYM, KWT_MULTI, ARGT_STRING },
95 { "CVALDEPS", K_VDEPS, KWT_MULTI, ARGT_STRING },
96 { "DASHVER", K_DASHVER, KWT_NORMAL, ARGT_INTEGER },
97 { "DEFAULT", K_DEFLT, KWT_MULTI, ARGT_STRING },
98 { "DESCRIPTION", K_DESC, KWT_MULTI, ARGT_STRING },
99 { "DISTFILES", KN_DISTFILES, KWT_NORMAL, ARGT_INTEGER },
100 { "DISTFILE", KA_DISTFILE, KWT_ITERATED, ARGT_STRING },
101 { "FLAVOURS", K_FLAVOURS, KWT_MULTI, ARGT_STRING },
102 { "GROUPS", K_GROUPS, KWT_NORMAL, ARGT_STRING },
103 { "HASHES", K_HASHES, KWT_NORMAL, ARGT_STRING },
104 { "HASH", KA_HASH, KWT_MULTITOP, ARGT_STRING },
105 { "HELPTEXT", K_HELP, KWT_MULTI, ARGT_STRING },
106 { "MASTER_SITES", K_SITES, KWT_ITERATED, ARGT_STRING },
107 { "MENUDEPS", K_MDEPS, KWT_MULTI, ARGT_STRING },
108 { "MENUITEM", K_MENUITEM, KWT_MULTI, ARGT_STRING },
109 { "MULTIPKGS", K_MULTIPKGS, KWT_NORMAL, ARGT_STRING },
110 { "NAME", K_NAME, KWT_NORMAL, ARGT_STRING },
111 { "PERMIT_BIN", K_PERMIT_BIN, KWT_MULTI, ARGT_STRING },
112 { "PERMIT_SRC", K_PERMIT_SRC, KWT_NORMAL, ARGT_STRING },
113 { "PKGDEPS", K_PKGDEPS, KWT_MULTI, ARGT_STRING },
114 { "PKGNAME", K_PKGNAME, KWT_NORMAL, ARGT_STRING },
115 { "RCCONF_SYMS", K_RCCONF_SYMS, KWT_NORMAL, ARGT_INTEGER },
116 { "RCCONF", KA_RCCONF, KWT_MULTITER, ARGT_STRING },
117 { "URLS", K_URLS, KWT_NORMAL, ARGT_STRING },
118 { "USERS", K_USERS, KWT_NORMAL, ARGT_STRING },
119 { "VERSION", K_VERSION, KWT_NORMAL, ARGT_STRING },
120 { NULL, 0, 0, 0 }
121 };
122
123 void
124 pfile(const char *fn)
125 {
126 struct parser_result *parsed;
127 struct parser_res *entry;
128 int fd;
129 size_t nument;
130
131 if ((fd = open(fn, O_RDONLY)) < 0)
132 err(255, "cannot open input file '%s'", fn);
133 printf("parsing %s…", fn);
134 if (parser_errpfx != NULL)
135 free(parser_errpfx);
136 parser_errpfx = strdup(fn);
137 parsed = nfo_parse(fd, kwords);
138 free(parser_errpfx);
139 parser_errpfx = NULL;
140 close(fd);
141 if (CIRCLEQ_EMPTY(parsed))
142 errx(1, "error, no entries in the file!");
143 nument = 0;
144 CIRCLEQ_FOREACH(entry, parsed, e)
145 ++nument;
146 printf("ok, %zu entries\n", nument);
147
148 do_defaultvalues(parsed);
149 do_varexpand(parsed);
150
151 /* do something with ‘parsed’ */
152 nument = 0;
153 CIRCLEQ_FOREACH(entry, parsed, e) {
154 printf("ent #%03zu: ", nument++);
155 parser_dump(entry, kwords);
156 }
157
158 parser_free(parsed);
159 }
160
161 static void
162 do_defaultvalues(struct parser_result *head)
163 {
164 /* ENOCOFFEE */;
165 }
166
167 static void
168 do_varexpand(struct parser_result *head)
169 {
170 /* ENOCOFFEE */;
171 }

root@freewrt.org:443
ViewVC Help
Powered by ViewVC 1.1.20