From c70caa7ec2d0ccfefb9263e8adff42797c5d07e7 Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Tue, 16 Feb 1999 03:47:24 +0000 Subject: [PATCH] make includes work right; support `-\' as stdin for input file --- xpcom/tools/xpidl/xpidl.c | 9 ++++++-- xpcom/tools/xpidl/xpidl.h | 25 +++++++++++++--------- xpcom/tools/xpidl/xpidl_idl.c | 37 ++++++++++++++++++++------------- xpcom/typelib/xpidl/xpidl.c | 9 ++++++-- xpcom/typelib/xpidl/xpidl.h | 25 +++++++++++++--------- xpcom/typelib/xpidl/xpidl_idl.c | 37 ++++++++++++++++++++------------- 6 files changed, 90 insertions(+), 52 deletions(-) diff --git a/xpcom/tools/xpidl/xpidl.c b/xpcom/tools/xpidl/xpidl.c index c23ce39ba1e1..4f5c36bdb7cd 100644 --- a/xpcom/tools/xpidl/xpidl.c +++ b/xpcom/tools/xpidl/xpidl.c @@ -86,6 +86,11 @@ main(int argc, char *argv[]) if (argv[i][0] != '-') break; switch (argv[i][1]) { + case '-': + argc++; + /* fall through */ + case 0: /* - is a legal input filename (stdin) */ + goto done_options; case 'w': enable_warnings = TRUE; break; @@ -153,7 +158,7 @@ main(int argc, char *argv[]) return 1; } } - + done_options: if (!mode) { fprintf(stderr, "ERROR: must specify output mode\n"); xpidl_usage(argc, argv); @@ -161,7 +166,7 @@ main(int argc, char *argv[]) } for (idlfiles = 0; i < argc; i++) { - if (argv[i][0] && argv[i][0] != '-') + if (argv[i][0]) idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode); } diff --git a/xpcom/tools/xpidl/xpidl.h b/xpcom/tools/xpidl/xpidl.h index 817f4bf4bff6..17c87d6ef342 100644 --- a/xpcom/tools/xpidl/xpidl.h +++ b/xpcom/tools/xpidl/xpidl.h @@ -66,18 +66,19 @@ typedef struct ModeData { } ModeData; typedef struct IncludePathEntry { - char *directory; + char *directory; struct IncludePathEntry *next; } IncludePathEntry; struct TreeState { - FILE *file; - char *basename; - IDL_ns ns; - IDL_tree tree; - GHashTable *includes; + FILE *file; + char *basename; + IDL_ns ns; + IDL_tree tree; + GHashTable *includes; IncludePathEntry *include_path; - nodeHandler *dispatch; + nodeHandler *dispatch; + void *priv; /* mode-private data */ }; /* @@ -99,9 +100,13 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data); * in case of fatal error. */ -void XPIDL_add_output_file(char *fn); -void XPIDL_cleanup_on_error(); +void +XPIDL_add_output_file(char *fn); -gboolean process_node(TreeState *state); +void +XPIDL_cleanup_on_error(); + +gboolean +process_node(TreeState *state); #endif /* __xpidl_h */ diff --git a/xpcom/tools/xpidl/xpidl_idl.c b/xpcom/tools/xpidl/xpidl_idl.c index 11169741fd12..fc6a51363fd8 100644 --- a/xpcom/tools/xpidl/xpidl_idl.c +++ b/xpcom/tools/xpidl/xpidl_idl.c @@ -59,7 +59,6 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data) gboolean process_node(TreeState *state) { - char *name = NULL; nodeHandler *handlerp = state->dispatch, handler; gint type; assert(state->tree); @@ -140,6 +139,9 @@ fopen_from_includes(const char *filename, const char *mode, { char *filebuf = NULL; FILE *file = NULL; + if (!strcmp(filename, "-")) + return stdin; + for (; include_path && !file; include_path = include_path->next) { filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", include_path->directory, filename); @@ -190,8 +192,8 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, { struct input_callback_stack *stack = user_data; struct input_callback_data *data = stack->top, *new_data = NULL; - int rv, avail, copy; - char *search, *check_point, *ptr, *end_copy, *raw_start, *comment_start, + int avail, copy; + char *check_point, *ptr, *end_copy, *raw_start, *comment_start, *include_start; switch(reason) { @@ -214,7 +216,6 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, data->point = data->buf; /* fill the buffer */ - fill_buffer: data->len = fread(data->buf, 1, data->max, data->input); if (!data->len) { if (ferror(data->input)) @@ -415,7 +416,8 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, case IDL_INPUT_REASON_ABORT: case IDL_INPUT_REASON_FINISH: - fclose(data->input); + if (data->input != stdin) + fclose(data->input); data->input = NULL; free(data->buf); data->buf = data->point = NULL; @@ -444,6 +446,20 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path, fprintf(stderr, "failed to create hashtable (EOM?)\n"); return 0; } + + state.basename = strdup(filename); + tmp = strrchr(state.basename, '.'); + if (tmp) + *tmp = '\0'; + + if (!basename) + outname = strdup(state.basename); + else + outname = strdup(basename); + + /* so we don't include it again! */ + g_hash_table_insert(stack.includes, filename, state.basename); + stack.include_path = include_path; rv = IDL_parse_filename_with_input(filename, input_callback, &stack, @@ -459,15 +475,8 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path, return 0; } - state.basename = strdup(filename); - tmp = strrchr(state.basename, '.'); - if (tmp) - *tmp = '\0'; - - if (!basename) - outname = strdup(state.basename); - else - outname = strdup(basename); + /* so we don't make a #include for it */ + g_hash_table_remove(stack.includes, filename); state.includes = stack.includes; state.include_path = include_path; diff --git a/xpcom/typelib/xpidl/xpidl.c b/xpcom/typelib/xpidl/xpidl.c index c23ce39ba1e1..4f5c36bdb7cd 100644 --- a/xpcom/typelib/xpidl/xpidl.c +++ b/xpcom/typelib/xpidl/xpidl.c @@ -86,6 +86,11 @@ main(int argc, char *argv[]) if (argv[i][0] != '-') break; switch (argv[i][1]) { + case '-': + argc++; + /* fall through */ + case 0: /* - is a legal input filename (stdin) */ + goto done_options; case 'w': enable_warnings = TRUE; break; @@ -153,7 +158,7 @@ main(int argc, char *argv[]) return 1; } } - + done_options: if (!mode) { fprintf(stderr, "ERROR: must specify output mode\n"); xpidl_usage(argc, argv); @@ -161,7 +166,7 @@ main(int argc, char *argv[]) } for (idlfiles = 0; i < argc; i++) { - if (argv[i][0] && argv[i][0] != '-') + if (argv[i][0]) idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode); } diff --git a/xpcom/typelib/xpidl/xpidl.h b/xpcom/typelib/xpidl/xpidl.h index 817f4bf4bff6..17c87d6ef342 100644 --- a/xpcom/typelib/xpidl/xpidl.h +++ b/xpcom/typelib/xpidl/xpidl.h @@ -66,18 +66,19 @@ typedef struct ModeData { } ModeData; typedef struct IncludePathEntry { - char *directory; + char *directory; struct IncludePathEntry *next; } IncludePathEntry; struct TreeState { - FILE *file; - char *basename; - IDL_ns ns; - IDL_tree tree; - GHashTable *includes; + FILE *file; + char *basename; + IDL_ns ns; + IDL_tree tree; + GHashTable *includes; IncludePathEntry *include_path; - nodeHandler *dispatch; + nodeHandler *dispatch; + void *priv; /* mode-private data */ }; /* @@ -99,9 +100,13 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data); * in case of fatal error. */ -void XPIDL_add_output_file(char *fn); -void XPIDL_cleanup_on_error(); +void +XPIDL_add_output_file(char *fn); -gboolean process_node(TreeState *state); +void +XPIDL_cleanup_on_error(); + +gboolean +process_node(TreeState *state); #endif /* __xpidl_h */ diff --git a/xpcom/typelib/xpidl/xpidl_idl.c b/xpcom/typelib/xpidl/xpidl_idl.c index 11169741fd12..fc6a51363fd8 100644 --- a/xpcom/typelib/xpidl/xpidl_idl.c +++ b/xpcom/typelib/xpidl/xpidl_idl.c @@ -59,7 +59,6 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data) gboolean process_node(TreeState *state) { - char *name = NULL; nodeHandler *handlerp = state->dispatch, handler; gint type; assert(state->tree); @@ -140,6 +139,9 @@ fopen_from_includes(const char *filename, const char *mode, { char *filebuf = NULL; FILE *file = NULL; + if (!strcmp(filename, "-")) + return stdin; + for (; include_path && !file; include_path = include_path->next) { filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", include_path->directory, filename); @@ -190,8 +192,8 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, { struct input_callback_stack *stack = user_data; struct input_callback_data *data = stack->top, *new_data = NULL; - int rv, avail, copy; - char *search, *check_point, *ptr, *end_copy, *raw_start, *comment_start, + int avail, copy; + char *check_point, *ptr, *end_copy, *raw_start, *comment_start, *include_start; switch(reason) { @@ -214,7 +216,6 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, data->point = data->buf; /* fill the buffer */ - fill_buffer: data->len = fread(data->buf, 1, data->max, data->input); if (!data->len) { if (ferror(data->input)) @@ -415,7 +416,8 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data, case IDL_INPUT_REASON_ABORT: case IDL_INPUT_REASON_FINISH: - fclose(data->input); + if (data->input != stdin) + fclose(data->input); data->input = NULL; free(data->buf); data->buf = data->point = NULL; @@ -444,6 +446,20 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path, fprintf(stderr, "failed to create hashtable (EOM?)\n"); return 0; } + + state.basename = strdup(filename); + tmp = strrchr(state.basename, '.'); + if (tmp) + *tmp = '\0'; + + if (!basename) + outname = strdup(state.basename); + else + outname = strdup(basename); + + /* so we don't include it again! */ + g_hash_table_insert(stack.includes, filename, state.basename); + stack.include_path = include_path; rv = IDL_parse_filename_with_input(filename, input_callback, &stack, @@ -459,15 +475,8 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path, return 0; } - state.basename = strdup(filename); - tmp = strrchr(state.basename, '.'); - if (tmp) - *tmp = '\0'; - - if (!basename) - outname = strdup(state.basename); - else - outname = strdup(basename); + /* so we don't make a #include for it */ + g_hash_table_remove(stack.includes, filename); state.includes = stack.includes; state.include_path = include_path;