xiaoxiang781216 commented on a change in pull request #12: nxstyle improvements with No tooling URL: https://github.com/apache/incubator-nuttx/pull/12#discussion_r361991442
########## 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; + FATALFL("Failed to open", filename); return 1; } /* Are we parsing a header file? */ - hdrfile = false; - ext = strrchr(filename, '.'); + hdrfile = false; + g_file_type = UNKNOWN; + ext = strrchr(filename, '.'); if (ext == 0) { - printf("No file extension\n"); + WARN("No file extension", 0 , 0); } else if (strcmp(ext, ".h") == 0) { hdrfile = true; + g_file_type = C_HEADER; } - else if (strcmp(ext, ".c") != 0) + else if (strcmp(ext, ".c") == 0) + { + g_file_type = C_SOURCE; + } + else { printf("Unrecognized file extension: \"%s\"\n", ext + 1); Review comment: How about we silient the unknow file? so we can integrate with the workflow more easier? ---------------------------------------------------------------- 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