From 10cdab28e983187a2c99c4bf66053954846f051d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 2 Aug 2009 00:14:45 -0700 Subject: Add a friendly comment at the top of auto-generated C files. --- tools/upbc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'tools/upbc.c') diff --git a/tools/upbc.c b/tools/upbc.c index 8eec85c..414d129 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -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); -- cgit v1.2.3