mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-31 21:21:08 +00:00
make includes work right; support `-\' as stdin for input file
This commit is contained in:
parent
90ade6856e
commit
c70caa7ec2
@ -86,6 +86,11 @@ main(int argc, char *argv[])
|
|||||||
if (argv[i][0] != '-')
|
if (argv[i][0] != '-')
|
||||||
break;
|
break;
|
||||||
switch (argv[i][1]) {
|
switch (argv[i][1]) {
|
||||||
|
case '-':
|
||||||
|
argc++;
|
||||||
|
/* fall through */
|
||||||
|
case 0: /* - is a legal input filename (stdin) */
|
||||||
|
goto done_options;
|
||||||
case 'w':
|
case 'w':
|
||||||
enable_warnings = TRUE;
|
enable_warnings = TRUE;
|
||||||
break;
|
break;
|
||||||
@ -153,7 +158,7 @@ main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done_options:
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
fprintf(stderr, "ERROR: must specify output mode\n");
|
fprintf(stderr, "ERROR: must specify output mode\n");
|
||||||
xpidl_usage(argc, argv);
|
xpidl_usage(argc, argv);
|
||||||
@ -161,7 +166,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (idlfiles = 0; i < argc; i++) {
|
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);
|
idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,18 +66,19 @@ typedef struct ModeData {
|
|||||||
} ModeData;
|
} ModeData;
|
||||||
|
|
||||||
typedef struct IncludePathEntry {
|
typedef struct IncludePathEntry {
|
||||||
char *directory;
|
char *directory;
|
||||||
struct IncludePathEntry *next;
|
struct IncludePathEntry *next;
|
||||||
} IncludePathEntry;
|
} IncludePathEntry;
|
||||||
|
|
||||||
struct TreeState {
|
struct TreeState {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *basename;
|
char *basename;
|
||||||
IDL_ns ns;
|
IDL_ns ns;
|
||||||
IDL_tree tree;
|
IDL_tree tree;
|
||||||
GHashTable *includes;
|
GHashTable *includes;
|
||||||
IncludePathEntry *include_path;
|
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.
|
* in case of fatal error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void XPIDL_add_output_file(char *fn);
|
void
|
||||||
void XPIDL_cleanup_on_error();
|
XPIDL_add_output_file(char *fn);
|
||||||
|
|
||||||
gboolean process_node(TreeState *state);
|
void
|
||||||
|
XPIDL_cleanup_on_error();
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
process_node(TreeState *state);
|
||||||
|
|
||||||
#endif /* __xpidl_h */
|
#endif /* __xpidl_h */
|
||||||
|
@ -59,7 +59,6 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
|
|||||||
gboolean
|
gboolean
|
||||||
process_node(TreeState *state)
|
process_node(TreeState *state)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
|
||||||
nodeHandler *handlerp = state->dispatch, handler;
|
nodeHandler *handlerp = state->dispatch, handler;
|
||||||
gint type;
|
gint type;
|
||||||
assert(state->tree);
|
assert(state->tree);
|
||||||
@ -140,6 +139,9 @@ fopen_from_includes(const char *filename, const char *mode,
|
|||||||
{
|
{
|
||||||
char *filebuf = NULL;
|
char *filebuf = NULL;
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
|
if (!strcmp(filename, "-"))
|
||||||
|
return stdin;
|
||||||
|
|
||||||
for (; include_path && !file; include_path = include_path->next) {
|
for (; include_path && !file; include_path = include_path->next) {
|
||||||
filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
||||||
include_path->directory, filename);
|
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_stack *stack = user_data;
|
||||||
struct input_callback_data *data = stack->top, *new_data = NULL;
|
struct input_callback_data *data = stack->top, *new_data = NULL;
|
||||||
int rv, avail, copy;
|
int avail, copy;
|
||||||
char *search, *check_point, *ptr, *end_copy, *raw_start, *comment_start,
|
char *check_point, *ptr, *end_copy, *raw_start, *comment_start,
|
||||||
*include_start;
|
*include_start;
|
||||||
|
|
||||||
switch(reason) {
|
switch(reason) {
|
||||||
@ -214,7 +216,6 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
|
|||||||
data->point = data->buf;
|
data->point = data->buf;
|
||||||
|
|
||||||
/* fill the buffer */
|
/* fill the buffer */
|
||||||
fill_buffer:
|
|
||||||
data->len = fread(data->buf, 1, data->max, data->input);
|
data->len = fread(data->buf, 1, data->max, data->input);
|
||||||
if (!data->len) {
|
if (!data->len) {
|
||||||
if (ferror(data->input))
|
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_ABORT:
|
||||||
case IDL_INPUT_REASON_FINISH:
|
case IDL_INPUT_REASON_FINISH:
|
||||||
fclose(data->input);
|
if (data->input != stdin)
|
||||||
|
fclose(data->input);
|
||||||
data->input = NULL;
|
data->input = NULL;
|
||||||
free(data->buf);
|
free(data->buf);
|
||||||
data->buf = data->point = NULL;
|
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");
|
fprintf(stderr, "failed to create hashtable (EOM?)\n");
|
||||||
return 0;
|
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;
|
stack.include_path = include_path;
|
||||||
|
|
||||||
rv = IDL_parse_filename_with_input(filename, input_callback, &stack,
|
rv = IDL_parse_filename_with_input(filename, input_callback, &stack,
|
||||||
@ -459,15 +475,8 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.basename = strdup(filename);
|
/* so we don't make a #include for it */
|
||||||
tmp = strrchr(state.basename, '.');
|
g_hash_table_remove(stack.includes, filename);
|
||||||
if (tmp)
|
|
||||||
*tmp = '\0';
|
|
||||||
|
|
||||||
if (!basename)
|
|
||||||
outname = strdup(state.basename);
|
|
||||||
else
|
|
||||||
outname = strdup(basename);
|
|
||||||
|
|
||||||
state.includes = stack.includes;
|
state.includes = stack.includes;
|
||||||
state.include_path = include_path;
|
state.include_path = include_path;
|
||||||
|
@ -86,6 +86,11 @@ main(int argc, char *argv[])
|
|||||||
if (argv[i][0] != '-')
|
if (argv[i][0] != '-')
|
||||||
break;
|
break;
|
||||||
switch (argv[i][1]) {
|
switch (argv[i][1]) {
|
||||||
|
case '-':
|
||||||
|
argc++;
|
||||||
|
/* fall through */
|
||||||
|
case 0: /* - is a legal input filename (stdin) */
|
||||||
|
goto done_options;
|
||||||
case 'w':
|
case 'w':
|
||||||
enable_warnings = TRUE;
|
enable_warnings = TRUE;
|
||||||
break;
|
break;
|
||||||
@ -153,7 +158,7 @@ main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done_options:
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
fprintf(stderr, "ERROR: must specify output mode\n");
|
fprintf(stderr, "ERROR: must specify output mode\n");
|
||||||
xpidl_usage(argc, argv);
|
xpidl_usage(argc, argv);
|
||||||
@ -161,7 +166,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (idlfiles = 0; i < argc; i++) {
|
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);
|
idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,18 +66,19 @@ typedef struct ModeData {
|
|||||||
} ModeData;
|
} ModeData;
|
||||||
|
|
||||||
typedef struct IncludePathEntry {
|
typedef struct IncludePathEntry {
|
||||||
char *directory;
|
char *directory;
|
||||||
struct IncludePathEntry *next;
|
struct IncludePathEntry *next;
|
||||||
} IncludePathEntry;
|
} IncludePathEntry;
|
||||||
|
|
||||||
struct TreeState {
|
struct TreeState {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *basename;
|
char *basename;
|
||||||
IDL_ns ns;
|
IDL_ns ns;
|
||||||
IDL_tree tree;
|
IDL_tree tree;
|
||||||
GHashTable *includes;
|
GHashTable *includes;
|
||||||
IncludePathEntry *include_path;
|
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.
|
* in case of fatal error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void XPIDL_add_output_file(char *fn);
|
void
|
||||||
void XPIDL_cleanup_on_error();
|
XPIDL_add_output_file(char *fn);
|
||||||
|
|
||||||
gboolean process_node(TreeState *state);
|
void
|
||||||
|
XPIDL_cleanup_on_error();
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
process_node(TreeState *state);
|
||||||
|
|
||||||
#endif /* __xpidl_h */
|
#endif /* __xpidl_h */
|
||||||
|
@ -59,7 +59,6 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
|
|||||||
gboolean
|
gboolean
|
||||||
process_node(TreeState *state)
|
process_node(TreeState *state)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
|
||||||
nodeHandler *handlerp = state->dispatch, handler;
|
nodeHandler *handlerp = state->dispatch, handler;
|
||||||
gint type;
|
gint type;
|
||||||
assert(state->tree);
|
assert(state->tree);
|
||||||
@ -140,6 +139,9 @@ fopen_from_includes(const char *filename, const char *mode,
|
|||||||
{
|
{
|
||||||
char *filebuf = NULL;
|
char *filebuf = NULL;
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
|
if (!strcmp(filename, "-"))
|
||||||
|
return stdin;
|
||||||
|
|
||||||
for (; include_path && !file; include_path = include_path->next) {
|
for (; include_path && !file; include_path = include_path->next) {
|
||||||
filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
||||||
include_path->directory, filename);
|
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_stack *stack = user_data;
|
||||||
struct input_callback_data *data = stack->top, *new_data = NULL;
|
struct input_callback_data *data = stack->top, *new_data = NULL;
|
||||||
int rv, avail, copy;
|
int avail, copy;
|
||||||
char *search, *check_point, *ptr, *end_copy, *raw_start, *comment_start,
|
char *check_point, *ptr, *end_copy, *raw_start, *comment_start,
|
||||||
*include_start;
|
*include_start;
|
||||||
|
|
||||||
switch(reason) {
|
switch(reason) {
|
||||||
@ -214,7 +216,6 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
|
|||||||
data->point = data->buf;
|
data->point = data->buf;
|
||||||
|
|
||||||
/* fill the buffer */
|
/* fill the buffer */
|
||||||
fill_buffer:
|
|
||||||
data->len = fread(data->buf, 1, data->max, data->input);
|
data->len = fread(data->buf, 1, data->max, data->input);
|
||||||
if (!data->len) {
|
if (!data->len) {
|
||||||
if (ferror(data->input))
|
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_ABORT:
|
||||||
case IDL_INPUT_REASON_FINISH:
|
case IDL_INPUT_REASON_FINISH:
|
||||||
fclose(data->input);
|
if (data->input != stdin)
|
||||||
|
fclose(data->input);
|
||||||
data->input = NULL;
|
data->input = NULL;
|
||||||
free(data->buf);
|
free(data->buf);
|
||||||
data->buf = data->point = NULL;
|
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");
|
fprintf(stderr, "failed to create hashtable (EOM?)\n");
|
||||||
return 0;
|
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;
|
stack.include_path = include_path;
|
||||||
|
|
||||||
rv = IDL_parse_filename_with_input(filename, input_callback, &stack,
|
rv = IDL_parse_filename_with_input(filename, input_callback, &stack,
|
||||||
@ -459,15 +475,8 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.basename = strdup(filename);
|
/* so we don't make a #include for it */
|
||||||
tmp = strrchr(state.basename, '.');
|
g_hash_table_remove(stack.includes, filename);
|
||||||
if (tmp)
|
|
||||||
*tmp = '\0';
|
|
||||||
|
|
||||||
if (!basename)
|
|
||||||
outname = strdup(state.basename);
|
|
||||||
else
|
|
||||||
outname = strdup(basename);
|
|
||||||
|
|
||||||
state.includes = stack.includes;
|
state.includes = stack.includes;
|
||||||
state.include_path = include_path;
|
state.include_path = include_path;
|
||||||
|
Loading…
Reference in New Issue
Block a user