| 43 |
|
|
| 44 |
#include "nfotiser.h" |
#include "nfotiser.h" |
| 45 |
|
|
| 46 |
|
/* |
| 47 |
|
* Parsing works as follows: |
| 48 |
|
* |
| 49 |
|
* - strip completely empty line |
| 50 |
|
* - strip line beginning with hash mark |
| 51 |
|
* - if line ends with backslash, get next line that is not |
| 52 |
|
* + empty |
| 53 |
|
* + beginning with a hash mark |
| 54 |
|
* and look if it begins with a tab (if not: syntax error) |
| 55 |
|
* if so, strip backslash + newline + tab and repeat |
| 56 |
|
* - if line begins with a tab, strip it and append line to |
| 57 |
|
* the last line, including the newline separator |
| 58 |
|
* - match line with '([A-Za-z_][A-Za-z0-9_]*)\t(.*)$' and |
| 59 |
|
* call \1 the key and \2 the value (else: syntax error) |
| 60 |
|
* - uppercase the key |
| 61 |
|
* - enter the key/value pair in the system |
| 62 |
|
* |
| 63 |
|
* The following is also part of parsing, but left to the caller: |
| 64 |
|
* - replace ${foo} with the value of key "foo" |
| 65 |
|
* - undouble all backslashes |
| 66 |
|
* |
| 67 |
|
* We enter the key into the system up to three-fold: |
| 68 |
|
* - KWT_NORMAL => ([A-Za-z_][A-Za-z0-9_]*) |
| 69 |
|
* + \1 = keyword (toupper'd) |
| 70 |
|
* - KWT_MULTI => ([A-Za-z_][A-Za-z0-9_]*)_([A-Za-z0-9_]*) |
| 71 |
|
* + \1 = keyword (toupper'd) |
| 72 |
|
* + \2 = kw_multi (case preserving) |
| 73 |
|
* - KWT_ITERATED => ([A-Za-z_][A-Za-z0-9_]*)_([0-9]*) |
| 74 |
|
* + \1 = keyword (toupper'd) |
| 75 |
|
* + \2 = kw_iter (unsigned integer value) |
| 76 |
|
* - KWT_MULTITER => ([A-Za-z_][A-Za-z0-9_]*)_([0-9]*)_([A-Za-z0-9_]*) |
| 77 |
|
* + \1 = keyword (toupper'd) |
| 78 |
|
* + \2 = kw_iter (unsigned integer value) |
| 79 |
|
* + \3 = kw_multi (case preserving) |
| 80 |
|
* |
| 81 |
|
* Cf. https://www.freewrt.org/trac/wiki/Documentation/Specs/Freewrt_info_files |
| 82 |
|
* for more examples and a more human-readable version of this specification. |
| 83 |
|
*/ |
| 84 |
|
|
| 85 |
struct parser_result * |
struct parser_result * |
| 86 |
nfo_parse(int fd, const struct parser_keywords *kws) |
nfo_parse(int fd, const struct parser_keywords *kws) |
| 87 |
{ |
{ |