comparison main.c @ 137:0816803b22d1

Improve usage reporting. Since imake is a principal application for tradcpp and imake carefully hides what it's doing when you run it, when rejecting an invalid option be sure to report *what* that option is.
author David A. Holland
date Tue, 09 Jul 2013 13:43:27 -0400
parents 59680a727e9d
children 904f7a9827e3
comparison
equal deleted inserted replaced
136:59680a727e9d 137:0816803b22d1
907 return false; 907 return false;
908 } 908 }
909 909
910 DEAD static 910 DEAD static
911 void 911 void
912 usage(const char *argv0) 912 usage(const char *argv0, const char *fmt, ...)
913 { 913 {
914 const char *progname; 914 const char *progname;
915 va_list ap;
915 916
916 progname = strrchr(argv0, '/'); 917 progname = strrchr(argv0, '/');
917 progname = progname == NULL ? argv0 : progname + 1; 918 progname = progname == NULL ? argv0 : progname + 1;
919
920 fprintf(stderr, "%s: ", progname);
921 va_start(ap, fmt);
922 vfprintf(stderr, fmt, ap);
923 va_end(ap);
924 fprintf(stderr, "\n");
918 925
919 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname); 926 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname);
920 fprintf(stderr, "Common options:\n"); 927 fprintf(stderr, "Common options:\n");
921 fprintf(stderr, " -C Retain comments\n"); 928 fprintf(stderr, " -C Retain comments\n");
922 fprintf(stderr, " -Dmacro[=def] Predefine macro\n"); 929 fprintf(stderr, " -Dmacro[=def] Predefine macro\n");
1021 place_setcommandline(&cmdplace, i+1, 1); 1028 place_setcommandline(&cmdplace, i+1, 1);
1022 if (check_arg_option(argv[i]+1, &cmdplace, argv[i+1])) { 1029 if (check_arg_option(argv[i]+1, &cmdplace, argv[i+1])) {
1023 i++; 1030 i++;
1024 continue; 1031 continue;
1025 } 1032 }
1026 usage(argv[0]); 1033 usage(argv[0], "Invalid option %s", argv[i]);
1027 } 1034 }
1028 if (i < argc) { 1035 if (i < argc) {
1029 inputfile = argv[i++]; 1036 inputfile = argv[i++];
1030 } 1037 }
1031 if (i < argc) { 1038 if (i < argc) {
1032 outputfile = argv[i++]; 1039 outputfile = argv[i++];
1033 } 1040 }
1034 if (i < argc) { 1041 if (i < argc) {
1035 usage(argv[0]); 1042 usage(argv[0], "Extra non-option argument %s", argv[i]);
1036 } 1043 }
1037 1044
1038 mode.output_file = outputfile; 1045 mode.output_file = outputfile;
1039 1046
1040 loadincludepath(); 1047 loadincludepath();