|
|
|
@ -372,10 +372,30 @@ static void add_submsgs(void *data, struct upb_msg *m, struct upb_strtable *t) |
|
|
|
|
/* write_messages_c emits a .c file that contains the data of a protobuf,
|
|
|
|
|
* serialized as C structures. */ |
|
|
|
|
static void write_message_c(void *data, struct upb_msg *m, |
|
|
|
|
char *cident, char *hfile_name, FILE *stream) |
|
|
|
|
char *cident, char *hfile_name, |
|
|
|
|
int argc, char *argv[], char *infile_name, |
|
|
|
|
FILE *stream) |
|
|
|
|
{ |
|
|
|
|
fputs("/* This file was generated by upbc (the upb compiler). " |
|
|
|
|
"Do not edit. */\n\n", stream), |
|
|
|
|
fputs( |
|
|
|
|
"/*\n" |
|
|
|
|
" * This file is a data dump of a protocol buffer into a C structure.\n" |
|
|
|
|
" * It was created by the upb compiler (upbc) with the following\n" |
|
|
|
|
" * command-line:\n" |
|
|
|
|
" *\n", stream); |
|
|
|
|
fputs(" * ", stream); |
|
|
|
|
for(int i = 0; i < argc; i++) { |
|
|
|
|
fputs(argv[i], stream); |
|
|
|
|
if(i < argc-1) fputs(" ", stream); |
|
|
|
|
} |
|
|
|
|
fputs("\n *\n", stream); |
|
|
|
|
fprintf(stream, " * This file is a dump of '%s'.\n", infile_name); |
|
|
|
|
fputs( |
|
|
|
|
" * It contains exactly the same data, but in a C structure form\n" |
|
|
|
|
" * instead of a serialized protobuf. This file contains no code,\n" |
|
|
|
|
" * only data.\n" |
|
|
|
|
" *\n" |
|
|
|
|
" * This file was auto-generated. Do not edit. */\n\n", stream); |
|
|
|
|
|
|
|
|
|
fprintf(stream, "#include \"%s\"\n\n", hfile_name); |
|
|
|
|
|
|
|
|
|
/* Gather all strings into a giant string. Use a hash to prevent adding the
|
|
|
|
@ -652,7 +672,7 @@ int main(int argc, char *argv[]) |
|
|
|
|
if(cident) { |
|
|
|
|
FILE *c_file = fopen(c_filename, "w"); |
|
|
|
|
if(!c_file) error("Failed to open .h output file"); |
|
|
|
|
write_message_c(fds, c.fds_msg, cident, h_filename, c_file); |
|
|
|
|
write_message_c(fds, c.fds_msg, cident, h_filename, argc, argv, input_file, c_file); |
|
|
|
|
fclose(c_file); |
|
|
|
|
} |
|
|
|
|
upb_context_free(&c); |
|
|
|
|