diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-09-26 11:46:38 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-09-26 11:46:38 -0700 |
commit | 33a68acb14759cb6fcf796b41ad001c93de4b8e4 (patch) | |
tree | f03543b04c0e5b7ce7f2650ff1330919d4d6e055 /tools/upbc.c | |
parent | 4b47002198f2c0404e16d2f02786845d6d3a0d3b (diff) |
Use a status object for errors so a message can be returned.
Also delay deletion of subfields until the entire message is
deleted.
Diffstat (limited to 'tools/upbc.c')
-rw-r--r-- | tools/upbc.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/tools/upbc.c b/tools/upbc.c index 36d36d0..fa9c015 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -10,6 +10,7 @@ #include <ctype.h> #include <inttypes.h> +#include <stdarg.h> #include "descriptor.h" #include "upb_context.h" #include "upb_enum.h" @@ -632,9 +633,13 @@ void usage_err(char *err) exit(1); } -void error(char *err) +void error(char *err, ...) { - fprintf(stderr, "upbc: %s\n\n", err); + va_list args; + va_start(args, err); + fprintf(stderr, "upbc: "); + vfprintf(stderr, err, args); + va_end(args); exit(1); } @@ -680,12 +685,15 @@ int main(int argc, char *argv[]) /* Parse input file. */ struct upb_context *c = upb_context_new(); struct upb_msg *fds_msg = upb_msg_new(c->fds_msg); - if(upb_msg_parsestr(fds_msg, descriptor->ptr, descriptor->byte_len) != UPB_STATUS_OK) - error("Failed to parse input file descriptor."); + struct upb_status status = UPB_STATUS_INIT; + upb_msg_parsestr(fds_msg, descriptor->ptr, descriptor->byte_len, &status); + if(!upb_ok(&status)) + error("Failed to parse input file descriptor: %s", status.msg); //upb_msg_print(fds_msg, false, stderr); google_protobuf_FileDescriptorSet *fds = (void*)fds_msg; - if(!upb_context_addfds(c, fds)) - error("Failed to resolve symbols in descriptor.\n"); + upb_context_addfds(c, fds, &status); + if(!upb_ok(&status)) + error("Failed to resolve symbols in descriptor: %s", status.msg); /* We need to sort the fields of all the descriptors. They will already be * sorted in the upb_msgs that we base our header file output on, so we must |