cline.c

changeset 21
91e0890464b0
parent 20
43725438ac50
child 22
4508da679ffb
equal deleted inserted replaced
20:43725438ac50 21:91e0890464b0
12 #include "stream.h" 12 #include "stream.h"
13 13
14 void printHelpText() { 14 void printHelpText() {
15 const char* helpText = 15 const char* helpText =
16 "\nUsage:" 16 "\nUsage:"
17 "\n cline [-hrm][-s suffix][<directory>]" 17 "\n cline [-hrmvV][-s suffix][-b level][<directory>]"
18 "\n cline [-hrm][-S suffix][<directory>]" 18 "\n cline [-hrmvV][-S suffix][-b level][<directory>]"
19 "\n\nCounts the line terminator characters (\\n) within all" 19 "\n\nCounts the line terminator characters (\\n) within all"
20 " files in the specified\ndirectory." 20 " files in the specified\ndirectory."
21 "\n\nOptions:" 21 "\n\nOptions:"
22 "\n -b <level> - binary file heuristics level (default medium)"
23 "\n One of: ignore low medium high"
22 "\n -h, --help - this help text" 24 "\n -h, --help - this help text"
23 "\n -m - print information about matching files only" 25 "\n -m - print information about matching files only"
24 "\n -s <suffixes> - only count files with these suffixes (separated" 26 "\n -s <suffixes> - only count files with these suffixes (separated"
25 "\n by commas)" 27 "\n by commas)"
26 "\n -S <suffixes> - count any file except those with these suffixes" 28 "\n -S <suffixes> - count any file except those with these suffixes"
64 char* suffix = " "; 66 char* suffix = " ";
65 int checked = 0; 67 int checked = 0;
66 68
67 for (int t = 1 ; t < argc ; t++) { 69 for (int t = 1 ; t < argc ; t++) {
68 70
69 int argflags = checkArgument(argv[t], "hsSrRmvV"); 71 int argflags = checkArgument(argv[t], "hsSrRmvVb");
70 72
71 // s, S 73 // s, S
72 if ((argflags & 6) > 0) { 74 if ((argflags & 6) > 0) {
73 if (registerArgument(&checked, 6)) { 75 if (registerArgument(&checked, 6)) {
74 return exit_with_help(settings, 1); 76 return exit_with_help(settings, 1);
107 if (registerArgument(&checked, 128)) { 109 if (registerArgument(&checked, 128)) {
108 return exit_with_help(settings, 1); 110 return exit_with_help(settings, 1);
109 } 111 }
110 settings->verbose = false; 112 settings->verbose = false;
111 } 113 }
114 // b
115 if ((argflags & 256) > 0) {
116 if (registerArgument(&checked, 256)) {
117 return exit_with_help(settings, 1);
118 }
119 t++;
120 if (t >= argc) {
121 return exit_with_help(settings, 1);
122 }
123 if (stricmp(argv[t], "ignore") == 0) {
124 settings->bfileHeuristics->level = BFILE_IGNORE;
125 } else if (stricmp(argv[t], "low") == 0) {
126 settings->bfileHeuristics->level = BFILE_LOW_ACCURACY;
127 } else if (stricmp(argv[t], "medium") == 0) {
128 settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY;
129 } else if (stricmp(argv[t], "high") == 0) {
130 settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
131 } else {
132 return exit_with_help(settings, 1);
133 }
134 }
112 // Path 135 // Path
113 if (argflags == 0) { 136 if (argflags == 0) {
114 if (registerArgument(&checked, 1024)) { 137 if (registerArgument(&checked, 1024)) {
115 return exit_with_help(settings, 1); 138 return exit_with_help(settings, 1);
116 } 139 }
135 if (dir == NULL) { 158 if (dir == NULL) {
136 perror("Operation failed"); 159 perror("Operation failed");
137 destroy_settings_t(settings); 160 destroy_settings_t(settings);
138 return 1; 161 return 1;
139 } 162 }
140 163
141 // Scan directory 164 // Scan directory
142 int lines = scanDirectory(dir, 0, directory, settings); 165 int lines = scanDirectory(dir, 0, directory, settings);
143 closedir(dir); 166 closedir(dir);
144 destroy_settings_t(settings); 167 destroy_settings_t(settings);
145 168
146 // Print double line and line count 169 // Print double line and line count
147 #ifdef _WIN32 170 for (int t = 0 ; t < 79 ; t++) {
148 const int columns = 79;
149 #else
150 const int columns = 80;
151 #endif /* _WIN32 */
152
153 for (int t = 0 ; t < columns ; t++) {
154 printf("="); 171 printf("=");
155 } 172 }
156 #ifdef _WIN32 173 printf("\n%73d lines\n", lines);
157 printf("\n%73d lines\n", lines);
158 #else
159 printf("\n%74d lines\n", lines);
160 #endif /* _WIN32 */
161 174
162 if (!settings->verbose) { 175 if (!settings->verbose) {
163 reopen_stdout(); 176 reopen_stdout();
164 printf("%d", lines); 177 printf("%d", lines);
165 } 178 }

mercurial