-//#include "toys.h"
+/* config2.help.c - config2hep Config.in .config > help.h
+
+ function parse() reads Config.in data into *sym list, then
+ we read .config and set sym->try on each enabled symbol.
+
+*/
#include <ctype.h>
#include <stdio.h>
#include <termios.h>
#include <poll.h>
#include <sys/socket.h>
+
struct statvfs {int i;};
#include "lib/portability.h"
#include "lib/lib.h"
} *sym;
// remove leading spaces
-char *trim(char *s)
+char *skip_spaces(char *s)
{
while (isspace(*s)) s++;
{
int len = strlen(name);
- line = trim(line);
+ line = skip_spaces(line);
if (strncmp(name, line, len)) return 0;
line += len;
if (*line && !isspace(*line)) return 0;
- line = trim(line);
+ line = skip_spaces(line);
return line;
}
while (*help) {
char *s;
- s = trim((*help)->data);
+ s = skip_spaces((*help)->data);
if (*s) break;
got++;
// Find start of dash block. Must be at start or after blank line.
for (;;) {
- s = trim((*from)->data);
+ s = skip_spaces((*from)->data);
if (*s == '-' && s[1] != '-' && !count) break;
if (!*s) count = 0;
// If there was whitespace before this, zap it. This can't take out *help
// because zap_blank_lines skipped blank lines, and we had to have at least
// one non-blank line (a dash line) to get this far.
- while (!*trim((*from)->prev->data)) {
+ while (!*skip_spaces((*from)->prev->data)) {
*from = (*from)->prev;
free(dlist_zap(from));
}
dd = *from;
if (*help == *from) *help = 0;
for (;;) {
- if (*trim(dd->data) != '-') break;
+ if (*skip_spaces(dd->data) != '-') break;
count++;
if (*from == (dd = dd->next)) break;
}
return list;
}
+// Read Config.in (and includes) to populate global struct symbol *sym list.
void parse(char *filename)
{
FILE *fp = xfopen(filename, "r");
return strcmp(*a, *b);
}
+// Three stages: read data, collate entries, output results.
+
int main(int argc, char *argv[])
{
FILE *fp;
exit(1);
}
+ // Stage 1: read data. Read Config.in to global 'struct symbol *sym' list,
+ // then read .config to set "enabled" member of each enabled symbol.
+
// Read Config.in
parse(argv[1]);
}
}
+ // Stage 2: process data.
+
// Collate help according to usage, depends, and .config
// Loop through each entry, finding duplicate enabled "usage:" names
catch->enabled++;
while (!isspace(*that) && *that) that++;
if (!throw) len = that-name;
- that = trim(that);
+ that = skip_spaces(that);
if (!throw) {
throw = catch;
this = that;
}
while (throw->help && throw->help != tfrom)
dlist_add(&cfrom, dlist_zap(&throw->help));
- if (cfrom && cfrom->prev->data && *trim(cfrom->prev->data))
+ if (cfrom && cfrom->prev->data && *skip_spaces(cfrom->prev->data))
dlist_add(&cfrom, strdup(""));
}
if (!anchor) {
if (!anchor->data) dlist_zap(&anchor);
// zap whitespace at end of catch help text
- while (!*trim(anchor->prev->data)) {
+ while (!*skip_spaces(anchor->prev->data)) {
anchor = anchor->prev;
free(dlist_zap(&anchor));
}
if (from[ff] == ']' && to[tt] == ']') {
try = xmprintf("[-%.*s%.*s] ", ff, from, tt, to);
qsort(try+2, ff+tt, 1, (void *)charsort);
- this = trim(this+ff+3);
- that = trim(that+tt+3);
+ this = skip_spaces(this+ff+3);
+ that = skip_spaces(that+tt+3);
}
}
if (!throw) break;
}
+ // Stage 3: output results to stdout.
+
// Print out help #defines
while (sym) {
struct double_list *dd;