1 /*********************************************************************
2 *
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * ===================================================================
15 * Revision History ::
16 * YYYY.MM.DD Change ID Developer
17 * Description
18 * -------------------------------------------------------------------
19 * 2002.04.25 Vlad Skarzhevskyy
20 * Initial implementation.
21 *
22 * ===================================================================
23 *
24 ********************************************************************/
25
26 #include "pure-sfv.h"
27
set_rc(int * rc,int new_rc)28 void set_rc(int *rc, int new_rc)
29 {
30 if ((*rc == EXIT_NO_PROBLEMS) ||
31 (*rc > new_rc)) {
32 *rc = new_rc;
33 }
34 }
35
sfvPrintLogo(char * msg)36 void sfvPrintLogo(char* msg)
37 {
38 printf("pure-sfv v%s http://pure-sfv.sourceforge.net, %s\n",
39 PURE_SFV_VERSION, msg);
40 }
41
reportTotal(int functions_rc,pure_sfv_params * params)42 int reportTotal(int functions_rc, pure_sfv_params* params)
43 {
44 int pure_sfv_return = 0;
45 int atr;
46 int i;
47 debugParams(params);
48 set_rc(&pure_sfv_return, functions_rc);
49 switch (params->mode)
50 {
51 case MODE_COUNT:
52 case MODE_TEST:
53 if (params->recurse_subdirectories) {
54 if (params->cnt.sfv_tested == 0) {
55 printf("SFV file for tests not found anywhere down this path ...\n");
56 }
57 } else {
58 if ((params->cnt.sfv_tested == 0) && (params->sfv_files.names_cnt == 0)) {
59 printf("SFV file for tests not found in this directory ...\n");
60 } else {
61 /* Report untested SFV */
62 if (params->sfv_files.names_cnt != 0) {
63 for(i = 0 ; i < params->sfv_files.len; i++) {
64 atr = params->sfv_files.attr[i];
65 DBUG_PRINT("report", ("[%i] atr [%i]", i, atr));
66 if ((attr_base(atr) == PARAM_NAME) &&
67 (!attr_is_set(atr, PARAM_NAME_FOUND))) {
68 printf("SFV file [%s] not found \n", params->sfv_files.strs[i]);
69 set_rc(&pure_sfv_return, EXIT_SFV_NOT_FOUND);
70 }
71 }
72 }
73 }
74 }
75 /* Report untested Files */
76 if (params->files.names_cnt != 0) {
77 for(i = 0 ; i < params->files.len; i++) {
78 atr = params->files.attr[i];
79 DBUG_PRINT("report", ("[%i] atr [%i]", i, atr));
80 if ((attr_base(atr) == PARAM_NAME) &&
81 (!attr_is_set(atr, PARAM_NAME_FOUND))) {
82 printf("SFV file has not been found to verify [%s]\n", params->files.strs[i]);
83 set_rc(&pure_sfv_return, EXIT_FILE_NOT_FOUND);
84 }
85 }
86 }
87 if (params->cnt.files_not_found) {
88 set_rc(&pure_sfv_return, EXIT_TESTED_OK_MISSING);
89 }
90 if (params->cnt.files_broken) {
91 set_rc(&pure_sfv_return, EXIT_TESTED_DIFFERENT);
92 }
93 if ((params->cnt.files_broken) && (params->cnt.files_not_found)) {
94 set_rc(&pure_sfv_return, EXIT_TESTED_DIFFERENT_MISSING);
95 }
96 break;
97 case MODE_CREATE:
98 if (params->files.names_cnt != 0) {
99 for(i = 0 ; i < params->files.len; i++) {
100 atr = params->files.attr[i];
101 DBUG_PRINT("report", ("[%i] atr [%i]", i, atr));
102 if ((attr_base(atr) == PARAM_NAME) &&
103 (!attr_is_set(atr, PARAM_NAME_FOUND))) {
104 printf("File not found [%s]\n", params->files.strs[i]);
105 set_rc(&pure_sfv_return, EXIT_FILE_NOT_FOUND);
106 }
107 }
108 }
109 break;
110 default:
111 break;
112 }
113
114 if (params->cnt.directories_scaned > 1) {
115 if (!params->quiet) { printf("Scaned %i directories\n", params->cnt.directories_scaned); }
116 }
117
118 if ((params->cnt.sfv_tested > 1) || (params->cnt.sfv_created > 1)) {
119 if (!params->quiet) { printf("--Totals--\n"); }
120 }
121
122 if ((params->cnt.sfv_tested > 1) && (params->list_files == 0)) {
123 printf("Tested %i SFV files\n", params->cnt.sfv_tested);
124 printf(" Tested %4i files\n", params->cnt.files_tested);
125 printf(" Ignored %4i files\n", params->cnt.files_ignored);
126 printf(" Successful %4i files\n", params->cnt.files_ok);
127 printf(" Different %4i files\n", params->cnt.files_broken);
128 printf(" Read error %4i files\n", params->cnt.files_error);
129 printf(" Missing %4i files\n", params->cnt.files_not_found);
130 }
131 if (params->cnt.sfv_created > 1) {
132 printf("Created %i SFV files\n", params->cnt.sfv_created);
133 printf(" Added %i files\n", params->cnt.files_added);
134 }
135
136 if (functions_rc) {
137 /* Some fatel error happened */
138 pure_sfv_return = functions_rc;
139 }
140
141 return pure_sfv_return;
142 }
143
sfvProcess(pure_sfv_params * params)144 int sfvProcess(pure_sfv_params* params)
145 {
146 int rc = 0;
147 if (params->mode == MODE_DEFAULT) {
148 params->mode = MODE_TEST;
149 }
150 debugParams(params);
151 switch (params->mode)
152 {
153 case MODE_COUNT:
154 case MODE_TEST:
155 sfvPrintLogo("Testing");
156 if (params->recurse_subdirectories) {
157 rc = sfvTestInDirRecursive(params, params->sfv_dir);
158 } else {
159 rc = sfvTestInDir(params, params->sfv_dir);
160 }
161 break;
162 case MODE_CREATE:
163 sfvPrintLogo("Creating");
164 rc = sfvCreateRecursive(params, params->sfv_dir);
165 if (params->cnt.sfv_created == 0) {
166 printf("Nothing has been created ...\n");
167 }
168 break;
169 default:
170 fprintf(stderr, "Mode not implemented ...\n");
171 rc = 1;
172 }
173 rc = reportTotal(rc, params);
174 #ifndef __unix
175 if (params->windows_pause) {
176 printf( "Press any key to continue\n" );
177 getchar();
178 }
179 #endif
180 return rc;
181 }
182
183 /* EOF */
184