xiaoxiang781216 commented on a change in pull request #12: nxstyle improvements with No tooling URL: https://github.com/apache/incubator-nuttx/pull/12#discussion_r361990957
########## File path: tools/nxstyle.c ########## @@ -135,67 +211,98 @@ int main(int argc, char **argv, char **envp) int externc_lineno; /* Last line where 'extern "C"' declared */ int linelen; /* Length of the line */ int maxline; /* Lines longer that this generate warnings */ + bool silent; /* Used with go not go test option */ int n; int i; + int c; + extern char *optarg; + extern int optopt; + extern int optind; - maxline = 78; - filename = argv[1]; + g_gonogo = false; + maxline = 78; + filename = argv[1]; + silent = false; - /* Usage: nxstyle [-m <maxline>] <filename> - * nxstyle -h - */ - - if (argc == 4) + if (argc < 2) { - if (strcmp(argv[1], "-m") != 0) - { - fprintf(stderr, "Unrecognized argument\n"); - show_usage(argv[0], 1); - } - - maxline = atoi(argv[2]); - if (maxline < 1) - { - fprintf(stderr, "Bad value for <maxline>\n"); - show_usage(argv[0], 1); - } - - filename = argv[3]; + show_usage(argv[0], 1, "No file name given."); } - else if (argc == 2) + + while ((c = getopt(argc, argv, ":hsgm:")) != -1) { - if (strcmp(argv[1], "-h") == 0) - { - show_usage(argv[0], 0); - } - } - else + switch (c) + { + case 'm': + maxline = atoi(optarg); + if (maxline < 1) + { + show_usage(argv[0], 1, "Bad value for <maxline>."); + } + break; + + case 's': + silent = true; + break; + + case 'g': + g_gonogo = true; + break; + + case 'h': + show_usage(argv[0], 0, NULL); + break; + + case ':': + show_usage(argv[0], 1, "Missing argument."); + break; + + case '?': + show_usage(argv[0], 1, "Unrecognized option."); + break; + + default: + show_usage(argv[0], 0, NULL); + break; + } + } + + if (optind < argc - 1 || argv[optind] == NULL) { - fprintf(stderr, "Invalid number of arguments\n"); - show_usage(argv[0], 1); + show_usage(argv[0], 1, "No file name given."); } + filename = argv[optind]; + g_file_name = filename; instream = fopen(filename, "r"); + if (!instream) { - fprintf(stderr, "Failed to open %s\n", argv[1]); + g_gonogo = false; Review comment: why special handle this case? if user don't want to see anything, let's follow them. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services