root/trunk/freewrt/tools/nfotizer/nfotizer.h

Revision 2100, 2.3 kB (checked in by n0-1, 5 years ago)

added license information and (C)

Line 
1 /* nfotizer - split information given in info.nfo files into several places.
2  * Copyright (C) 2007  Phil Sutter <n0-1@freewrt.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 #define _GNU_SOURCE             /* asprintf */
19 #include <stdio.h>              /* FILE */
20
21 #define DIRSEP          '/'
22 #define MAXTHREADS      5
23
24 #ifdef DEBUG
25 #define DBG(x, ...)     fprintf(stderr, x "\n", ## __VA_ARGS__)
26 #else
27 #define DBG(x, ...)             /* empty */
28 #endif
29
30 #define PINFO(x, ...)   fprintf(stdout, x "\n", ## __VA_ARGS__)
31 #define PWARN(x, ...)   fprintf(stderr, "Warning: " x "\n", ## __VA_ARGS__)
32 #define PERR(x, ...)    fprintf(stderr, "Error: " x "\n", ## __VA_ARGS__)
33
34 /* conditional free */
35 #define zap(x)          if (x) { free(x); x = NULL; }
36
37 /* struct entry defines an htab item */
38 struct entry {
39         char *key;
40         char *val;
41 };
42
43 /* struct htab defines a hash table
44  * size: size of entry[]
45  * items: count of items in entry[] */
46 struct htab {
47         int size;
48         int items;
49         struct entry *data;
50 };
51
52 /* struct pline holding information about a parsed line
53  * type:     which sort of line was detected
54  * eof:      indicate end of file reached
55  * bs_end:   backslash at end present
56  * key, val: key and value (if given) */
57 struct pline {
58         enum {
59                 TYPE_COMMENT = 0,
60                 TYPE_KEY = 1,
61                 TYPE_SUBVAL = 2
62         } type;
63         int bs_end;
64         char *key, *val;
65 };
66
67 /* parse.c */
68 int parse(FILE *, struct htab *);
69
70 /* interpret.c */
71 char *my_strcat(char *, char *);
72 char *interpret(const char *, const char *, struct htab *);
73
74 /* hash.c */
75 struct htab *htab_create(int);
76 void htab_destroy(struct htab *);
77 int htab_indexof(char *, struct htab);
78 char *htab_get(char *, struct htab);
79 int htab_put(char *, char *, struct htab *);
80 void htab_print(struct htab);
81
82 /* filedefs.c */
83 extern const char **filedefs[];
Note: See TracBrowser for help on using the browser.