cline.c

Thu, 26 May 2011 14:39:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 26 May 2011 14:39:52 +0200
changeset 3
510d6b198dde
parent 1
34a5e235d16e
child 4
c3acfb3b4957
permissions
-rw-r--r--

Moved some functions to functions.c
Replaced static variables by settings_t type

3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
1 #include "cline.h"
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
2 #include "functions.h"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
4 settings_t* new_settings_t() {
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
5 settings_t *settings = malloc(sizeof(settings_t*));
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
6 #ifdef _WIN32
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
7 settings->fileSeparator = '\\';
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
8 #else
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
9 settings->fileSeparator = '/';
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
10 #endif /* _WIN32 */
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
11 settings->suffixc = 1;
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
12 settings->recursive = false;
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
13 settings->includeSuffixes = false;
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
14 settings->matchesOnly = false;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
17 void printHelpText(const char* prgName) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 // Help text
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 const char* helpText =
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
20 "\nUsage:"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
21 "\n %s [-hrm][-s suffix][<directory>]"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
22 "\n %s [-hrm][-S suffix][<directory>]"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 "\n\nCounts the line terminator characters (\\n) within all"
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 " files in the specified\ndirectory."
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 "\n\nOptions:"
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 "\n -h, --help - this help text"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
27 "\n -m - print information about matching files only"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
28 "\n -s <suffixes> - only count files with these suffixes (separated"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 "\n by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
30 "\n -S <suffixes> - count any file except those with these suffixes"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 "\n (separated by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
32 "\n -r, -R - includes subdirectories"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 "\n\n"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
34 "The default call without any options is:"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
35 "\n %s ./\n"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 "That means each file in each subdirectory is counted. If you want to count"
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 "\nC source code in your working directory and its subdirectories, type:"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
38 "\n %s -rs .c\n";
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
39
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
40 printf(helpText, prgName, prgName, prgName, prgName);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
41 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
42
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
43 int main(int argc, char** argv) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
45 // Settings
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
46 settings_t *settings = new_settings_t();
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
47
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 // Program name
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
49 char* prgName = strrchr(argv[0], settings->fileSeparator);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
50
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
51 if (prgName == NULL) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 prgName = argv[0];
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
53 } else {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 prgName++;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 // Defaults
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
58 char* _suffix = " ";
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
59 char _directory[3];
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
60 _directory[0] = '.';
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
61 _directory[1] = settings->fileSeparator;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
62 _directory[2] = 0;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 // Get arguments
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 char* directory;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 char* suffix;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 bool showHelp = false;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 char checked = 0;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
70 for (int t = 1 ; t < argc ; t++) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
71
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
72 int argflags = checkArgument(argv[t], "hsSrRm");
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
73
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
74 // s
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
75 if ((argflags & 2) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
76 if ((checked & 1) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
77 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
80 settings->includeSuffixes = true;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
81 t++;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
82 if (t >= argc) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
83 printHelpText(prgName);
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
84 return -1;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
85 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
86 suffix = argv[t];
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 checked |= 1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
89 // S
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
90 if ((argflags & 4) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
91 if ((checked & 1) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
92 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
95 settings->includeSuffixes = false;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
96 t++;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
97 if (t >= argc) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
98 printHelpText(prgName);
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
99 return -1;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
100 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
101 suffix = argv[t];
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 checked |= 1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
104 // h
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
105 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
106 if ((checked & 2) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
107 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 checked |= 2;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 showHelp = true;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
113 // r, R
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
114 if ((argflags & 24) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
115 if ((checked & 4) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
116 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 checked |= 4;
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
120 settings->recursive = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
122 if ((argflags & 32) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
123 if ((checked & 32) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
124 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
127 checked |= 32;
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
128 settings->matchesOnly = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
130 // other
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
131 if (argflags == 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
132 if ((checked & 8) > 0) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
133 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 return -1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
136 checked |= 8;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 directory = argv[t];
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 // Show help and quit
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
142 if (showHelp) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
143 printHelpText(prgName);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 return 0;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 // Default values
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
148 if ((checked & 1) == 0) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 suffix = _suffix;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
152 if ((checked & 8) == 0) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 directory = _directory;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 // Find tokens
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 char* finder;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 finder = strchr(suffix, ',');
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
159 while (finder != NULL) {
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
160 settings->suffixc++;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 finder = strchr(finder+1, ',');
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
163 settings->suffixv = (char**) malloc(sizeof(char**)*settings->suffixc);
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
164 if (settings->suffixv == NULL) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 fprintf(stderr, "Memory allocation failed.\n");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 return 1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 finder = strtok(suffix, ",");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 int c = 0;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
170 while (finder != NULL) {
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
171 settings->suffixv[c] = finder;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 c++;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 finder = strtok(NULL, ",");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 // Open directory
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 DIR *dir = opendir(directory);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
178 if (dir == NULL) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 perror("Operation failed");
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
180 free(settings->suffixv);
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
181 free(settings);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 return 1;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 // Scan directory
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
186 int lines = scanDirectory(dir, 0, directory, settings);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 // Print double line and line count
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
189 #ifdef _WIN32
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
190 const int columns = 79;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
191 #else
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
192 const int columns = 80;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
193 #endif /* _WIN32 */
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
194
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
195 for (int t = 0 ; t < columns ; t++) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 printf("=");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
198 #ifdef _WIN32
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
199 printf("\n%73d lines\n", lines);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
200 #else
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
201 printf("\n%74d lines\n", lines);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
202 #endif /* _WIN32 */
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 closedir(dir);
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
205 free(settings->suffixv);
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
206 free(settings);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 return 0;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 }

mercurial