clean-up and simplification

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5162 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1998-09-26 23:28:19 +00:00
parent 3538cf2fa9
commit aa8360ff2b

View File

@@ -65,6 +65,9 @@ add_command(char *function,
unsigned flags) unsigned flags)
{ {
struct command_list *cl = malloc(sizeof(*cl)); struct command_list *cl = malloc(sizeof(*cl));
if (cl == NULL)
err (1, "malloc");
cl->function = function; cl->function = function;
cl->help = help; cl->help = help;
cl->aliases = aliases; cl->aliases = aliases;
@@ -111,21 +114,31 @@ quote(const char *str)
static void static void
generate_commands(void) generate_commands(void)
{ {
char base[128]; char *base;
char cfn[128]; char *cfn;
const char *p; char *p;
p = strrchr(table_name, '/'); p = strrchr(table_name, '/');
if(p == NULL) if(p == NULL)
p = table_name; p = table_name;
else else
p++; p++;
strcpy(base, p);
base = strdup (p);
if (base == NULL)
err (1, "strdup");
p = strrchr(base, '.'); p = strrchr(base, '.');
if(p) if(p)
*p == '\0'; *p = '\0';
asprintf(&cfn, "%s.c", base);
if (cfn == NULL)
err (1, "asprintf");
snprintf(cfn, sizeof(cfn), "%s.c", base);
c_file = fopen(cfn, "w"); c_file = fopen(cfn, "w");
if (c_file == NULL)
err (1, "cannot fopen %s", cfn);
fprintf(c_file, "/* Generated from %s */\n", filename); fprintf(c_file, "/* Generated from %s */\n", filename);
fprintf(c_file, "\n"); fprintf(c_file, "\n");
@@ -146,8 +159,7 @@ generate_commands(void)
/* XXX hack for ss_quit */ /* XXX hack for ss_quit */
if(strcmp(cl->function, "ss_quit") == 0) { if(strcmp(cl->function, "ss_quit") == 0) {
fprintf(c_file, "int %s (int, char**);\n", cl->function); fprintf(c_file, "int %s (int, char**);\n", cl->function);
fprintf(c_file, "#define _ss_quit_wrap ss_quit\n\n", fprintf(c_file, "#define _ss_quit_wrap ss_quit\n\n");
cl->function, cl->function);
continue; continue;
} }
fprintf(c_file, "void %s (int, char**);\n", cl->function); fprintf(c_file, "void %s (int, char**);\n", cl->function);
@@ -180,6 +192,8 @@ generate_commands(void)
fprintf(c_file, "\n"); fprintf(c_file, "\n");
} }
fclose(c_file); fclose(c_file);
free(base);
free(cfn);
} }
int int