Skip to content

Commit

Permalink
Don't include toys.h from config2help.c (so cross-compiling from syst…
Browse files Browse the repository at this point in the history
…ems we

don't run on is easier), and use HELP_ instead of help_ for macro prefixes
to avoid name collisions (such as help_exit() the function).
  • Loading branch information
landley committed Feb 11, 2016
1 parent 28711d3 commit 187649d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void show_help(FILE *out) {;}

#undef NEWTOY
#undef OLDTOY
#define NEWTOY(name,opt,flags) help_##name "\0"
#define NEWTOY(name,opt,flags) HELP_##name "\0"
#define OLDTOY(name,oldname,flags) "\xff" #oldname "\0"
static char *help_data =
#include "generated/newtoys.h"
Expand Down
30 changes: 23 additions & 7 deletions scripts/config2help.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include "toys.h"

// Humor toys.h
struct toy_context toys;
char libbuf[4096], toybuf[4096];
//#include "toys.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <regex.h>
#include <inttypes.h>
#include <termios.h>
#include <poll.h>
struct statvfs {int i;};
#include "lib/portability.h"
#include "lib/lib.h"

// Humor toys.h (lie through our teeth, C's linker doesn't care).
char toys[4096], libbuf[4096], toybuf[4096];
void show_help(FILE *out) {;}
void toy_exec(char *argv[]) {;}
void toy_init(struct toy_list *which, char *argv[]) {;}
void toy_init(void *which, char *argv[]) {;}

// Parse config files into data structures.

Expand All @@ -16,13 +29,15 @@ struct symbol {
struct double_list *help;
} *sym;

// remove leading spaces
char *trim(char *s)
{
while (isspace(*s)) s++;

return s;
}

// if line starts with name (as whole word) return pointer after it, else NULL
char *keyword(char *name, char *line)
{
int len = strlen(name);
Expand All @@ -36,6 +51,7 @@ char *keyword(char *name, char *line)
return line;
}

// dlist_pop() freeing wrapper structure for you.
char *dlist_zap(struct double_list **help)
{
struct double_list *dd = dlist_pop(help);
Expand Down Expand Up @@ -366,7 +382,7 @@ int main(int argc, char *argv[])
char *s = xstrdup(sym->name);

for (i = 0; s[i]; i++) s[i] = tolower(s[i]);
printf("#define help_%s \"", s);
printf("#define HELP_%s \"", s);
free(s);

dd = sym->help;
Expand Down

0 comments on commit 187649d

Please sign in to comment.