cline.c

changeset 14
ee9333c91dda
parent 12
902cb8d2053c
child 16
bc9a0fefd892
equal deleted inserted replaced
13:51b1ba3776b1 14:ee9333c91dda
9 #include "scanner.h" 9 #include "scanner.h"
10 #include "settings.h" 10 #include "settings.h"
11 #include "arguments.h" 11 #include "arguments.h"
12 12
13 void printHelpText() { 13 void printHelpText() {
14 // Help text
15 const char* helpText = 14 const char* helpText =
16 "\nUsage:" 15 "\nUsage:"
17 "\n cline [-hrm][-s suffix][<directory>]" 16 "\n cline [-hrm][-s suffix][<directory>]"
18 "\n cline [-hrm][-S suffix][<directory>]" 17 "\n cline [-hrm][-S suffix][<directory>]"
19 "\n\nCounts the line terminator characters (\\n) within all" 18 "\n\nCounts the line terminator characters (\\n) within all"
24 "\n -s <suffixes> - only count files with these suffixes (separated" 23 "\n -s <suffixes> - only count files with these suffixes (separated"
25 "\n by commas)" 24 "\n by commas)"
26 "\n -S <suffixes> - count any file except those with these suffixes" 25 "\n -S <suffixes> - count any file except those with these suffixes"
27 "\n (separated by commas)" 26 "\n (separated by commas)"
28 "\n -r, -R - includes subdirectories" 27 "\n -r, -R - includes subdirectories"
28 "\n -v, --version - print out version information"
29 "\n\n" 29 "\n\n"
30 "The default call without any options is:" 30 "The default call without any options is:"
31 "\n cline ./\n" 31 "\n cline ./\n"
32 "So each file in the working directory is counted. If you want to count C" 32 "So each file in the working directory is counted. If you want to count C"
33 "\nsource code in your working directory and its subdirectories, type:" 33 "\nsource code in your working directory and its subdirectories, type:"
34 "\n cline -rs .c\n"; 34 "\n cline -rs .c\n";
35 35
36 printf(helpText); 36 printf(helpText);
37 }
38
39 int exit_with_version(settings_t* settings) {
40 printf("cline - Version: %s", VERSION);
41 destroy_settings_t(settings);
42 return 0;
37 } 43 }
38 44
39 int exit_with_help(settings_t* settings, int code) { 45 int exit_with_help(settings_t* settings, int code) {
40 printHelpText(); 46 printHelpText();
41 destroy_settings_t(settings); 47 destroy_settings_t(settings);
52 } 58 }
53 59
54 // Get arguments 60 // Get arguments
55 char* directory = "./"; 61 char* directory = "./";
56 char* suffix = " "; 62 char* suffix = " ";
57 bool showHelp = false;
58 int checked = 0; 63 int checked = 0;
59 64
60 for (int t = 1 ; t < argc ; t++) { 65 for (int t = 1 ; t < argc ; t++) {
61 66
62 int argflags = checkArgument(argv[t], "hsSrRm"); 67 int argflags = checkArgument(argv[t], "hsSrRmv");
63 68
64 // s 69 // s, S
65 if ((argflags & 2) > 0) { 70 if ((argflags & 6) > 0) {
66 if (registerArgument(&checked, 6)) { 71 if (registerArgument(&checked, 6)) {
67 return exit_with_help(settings, 1); 72 return exit_with_help(settings, 1);
68 } 73 }
69 settings->includeSuffixes = true; 74 settings->includeSuffixes = (argflags & 2) > 0;
70 t++; 75 t++;
71 if (t >= argc) { 76 if (t >= argc) {
72 return exit_with_help(settings, 1); 77 return exit_with_help(settings, 1);
73 } 78 }
74 suffix = argv[t]; 79 suffix = argv[t];
75 } 80 }
76 // S
77 if ((argflags & 4) > 0) {
78 if (registerArgument(&checked, 6)) {
79 return exit_with_help(settings, 1);
80 }
81 settings->includeSuffixes = false;
82 t++;
83 if (t >= argc) {
84 return exit_with_help(settings, 1);
85 }
86 suffix = argv[t];
87 }
88 // h 81 // h
89 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 82 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
90 return exit_with_help(settings, 1); 83 return exit_with_help(settings, 0);
91 } 84 }
92 // r, R 85 // r, R
93 if ((argflags & 24) > 0) { 86 if ((argflags & 24) > 0) {
94 if (registerArgument(&checked, 24)) { 87 if (registerArgument(&checked, 24)) {
95 return exit_with_help(settings, 1); 88 return exit_with_help(settings, 1);
100 if ((argflags & 32) > 0) { 93 if ((argflags & 32) > 0) {
101 if (registerArgument(&checked, 32)) { 94 if (registerArgument(&checked, 32)) {
102 return exit_with_help(settings, 1); 95 return exit_with_help(settings, 1);
103 } 96 }
104 settings->matchesOnly = true; 97 settings->matchesOnly = true;
98 }
99 // v
100 if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) {
101 return exit_with_version(settings);
105 } 102 }
106 // Path 103 // Path
107 if (argflags == 0) { 104 if (argflags == 0) {
108 if (registerArgument(&checked, 1024)) { 105 if (registerArgument(&checked, 1024)) {
109 return exit_with_help(settings, 1); 106 return exit_with_help(settings, 1);

mercurial