xiaoxiang781216 commented on a change in pull request #12: nxstyle improvements with No tooling URL: https://github.com/apache/incubator-nuttx/pull/12#discussion_r362011203
########## File path: tools/nxstyle.c ########## @@ -134,70 +211,80 @@ int main(int argc, char **argv, char **envp) int rbrace_lineno; /* Last line containing a right brace */ int externc_lineno; /* Last line where 'extern "C"' declared */ int linelen; /* Length of the line */ - int maxline; /* Lines longer that this generate warnings */ int n; int i; + int c; - maxline = 78; - filename = argv[1]; - - /* Usage: nxstyle [-m <maxline>] <filename> - * nxstyle -h - */ - - if (argc == 4) + while ((c = getopt(argc, argv, ":hv:gm:")) != -1) { - 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]; - } - else if (argc == 2) - { - if (strcmp(argv[1], "-h") == 0) - { - show_usage(argv[0], 0); - } - } - else + switch (c) + { + case 'm': + g_maxline = atoi(optarg); + if (g_maxline < 1) + { + show_usage(argv[0], 1, "Bad value for <maxline>."); + } + break; + + case 'v': + g_verbose = atoi(optarg); + if (g_verbose < 0 || g_verbose > 2) + { + show_usage(argv[0], 1, "Bad value for <level>."); + } + 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."); } - instream = fopen(filename, "r"); + g_file_name = argv[optind]; + instream = fopen(g_file_name, "r"); + if (!instream) { - fprintf(stderr, "Failed to open %s\n", argv[1]); + FATALFL("Failed to open", g_file_name); return 1; } /* Are we parsing a header file? */ - hdrfile = false; - ext = strrchr(filename, '.'); + hdrfile = false; + g_file_type = UNKNOWN; + ext = strrchr(g_file_name, '.'); if (ext == 0) { - printf("No file extension\n"); + WARN("No file extension", 0 , 0); } else if (strcmp(ext, ".h") == 0) { hdrfile = true; Review comment: should we remove hdrfile use g_file_type == C_HEADER instead? ---------------------------------------------------------------- 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