comparison sidinfo.c @ 398:9f9cf5c4b474

Rename functions for consistency.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 11 Dec 2022 02:10:17 +0200
parents db64a58314a9
children b095a35a0848
comparison
equal deleted inserted replaced
397:8958acd67028 398:9f9cf5c4b474
142 }; 142 };
143 143
144 static const int optListN = sizeof(optList) / sizeof(optList[0]); 144 static const int optListN = sizeof(optList) / sizeof(optList[0]);
145 145
146 146
147 void argShowHelp(void) 147 void siArgShowHelp(void)
148 { 148 {
149 int index, width; 149 int index, width;
150 150
151 th_print_banner(stdout, th_prog_name, "[options] <sid file|path> [file|path #2 ..]"); 151 th_print_banner(stdout, th_prog_name, "[options] <sid file|path> [file|path #2 ..]");
152 th_args_help(stdout, optList, optListN, 0, 80 - 2); 152 th_args_help(stdout, optList, optListN, 0, 80 - 2);
198 setSTILDBPath != NULL ? setSTILDBPath : "[not set]" 198 setSTILDBPath != NULL ? setSTILDBPath : "[not set]"
199 ); 199 );
200 } 200 }
201 201
202 202
203 int argMatchPSField(const char *field) 203 int siArgMatchPSField(const char *field)
204 { 204 {
205 int index, found = -1; 205 int index, found = -1;
206 for (index = 0; index < noptPSOptions; index++) 206 for (index = 0; index < noptPSOptions; index++)
207 { 207 {
208 const PSFOption *opt = &optPSOptions[index]; 208 const PSFOption *opt = &optPSOptions[index];
216 216
217 return found; 217 return found;
218 } 218 }
219 219
220 220
221 int argMatchPSFieldError(const char *field) 221 int siArgMatchPSFieldError(const char *field)
222 { 222 {
223 int found = argMatchPSField(field); 223 int found = siArgMatchPSField(field);
224 switch (found) 224 switch (found)
225 { 225 {
226 case -1: 226 case -1:
227 THERR("No such field '%s'.\n", field); 227 THERR("No such field '%s'.\n", field);
228 break; 228 break;
272 memset(stack, 0, sizeof(PSFStack)); 272 memset(stack, 0, sizeof(PSFStack));
273 } 273 }
274 } 274 }
275 275
276 276
277 bool argParsePSFields(PSFStack *stack, const char *fmt) 277 bool siArgParsePSFields(PSFStack *stack, const char *fmt)
278 { 278 {
279 const char *start = fmt; 279 const char *start = fmt;
280 siClearStack(stack); 280 siClearStack(stack);
281 281
282 while (*start) 282 while (*start)
287 th_strdup_trim(start, TH_TRIM_BOTH); 287 th_strdup_trim(start, TH_TRIM_BOTH);
288 288
289 if (field != NULL) 289 if (field != NULL)
290 { 290 {
291 PSFStackItem item; 291 PSFStackItem item;
292 int found = argMatchPSFieldError(field); 292 int found = siArgMatchPSFieldError(field);
293 th_free(field); 293 th_free(field);
294 294
295 if (found < 0) 295 if (found < 0)
296 return false; 296 return false;
297 297
528 528
529 529
530 // 530 //
531 // Parse a format string into a PSFStack structure 531 // Parse a format string into a PSFStack structure
532 // 532 //
533 static bool argParsePSFormatStr(PSFStack *stack, const char *fmt) 533 static bool siArgParsePSFormatStr(PSFStack *stack, const char *fmt)
534 { 534 {
535 const char *start = NULL; 535 const char *start = NULL;
536 int mode = 0; 536 int mode = 0;
537 bool rval = true; 537 bool rval = true;
538 538
582 { 582 {
583 *pfield = 0; 583 *pfield = 0;
584 fopt = th_strdup_trim(pfield + 1, TH_TRIM_BOTH); 584 fopt = th_strdup_trim(pfield + 1, TH_TRIM_BOTH);
585 } 585 }
586 586
587 int ret = argMatchPSFieldError(field); 587 int ret = siArgMatchPSFieldError(field);
588 if (ret >= 0) 588 if (ret >= 0)
589 { 589 {
590 PSFStackItem item; 590 PSFStackItem item;
591 memset(&item, 0, sizeof(item)); 591 memset(&item, 0, sizeof(item));
592 item.cmd = ret; 592 item.cmd = ret;
639 639
640 return rval; 640 return rval;
641 } 641 }
642 642
643 643
644 static bool argHandleOpt(const int optN, char *optArg, char *currArg) 644 static bool siArgHandleOpt(const int optN, char *optArg, char *currArg)
645 { 645 {
646 switch (optN) 646 switch (optN)
647 { 647 {
648 case 0: 648 case 0:
649 optShowHelp = true; 649 optShowHelp = true;
677 case 18: 677 case 18:
678 optEscapeChars = optArg; 678 optEscapeChars = optArg;
679 break; 679 break;
680 680
681 case 20: 681 case 20:
682 if (!argParsePSFields(&optFormat, optArg)) 682 if (!siArgParsePSFields(&optFormat, optArg))
683 return false; 683 return false;
684 break; 684 break;
685 685
686 case 22: 686 case 22:
687 optFieldOutput = false; 687 optFieldOutput = false;
688 if (!argParsePSFormatStr(&optFormat, optArg)) 688 if (!siArgParsePSFormatStr(&optFormat, optArg))
689 return false; 689 return false;
690 break; 690 break;
691 691
692 case 24: 692 case 24:
693 optRecurseDirs = true; 693 optRecurseDirs = true;
1064 1064
1065 return true; 1065 return true;
1066 } 1066 }
1067 1067
1068 1068
1069 bool argHandleFileDir(const char *path, const char *filename, const char *pattern) 1069 bool siArgHandleFileDir(const char *path, const char *filename, const char *pattern)
1070 { 1070 {
1071 th_stat_data sdata; 1071 th_stat_data sdata;
1072 char *npath; 1072 char *npath;
1073 bool ret = true; 1073 bool ret = true;
1074 1074
1105 } 1105 }
1106 1106
1107 while ((entry = readdir(dirh)) != NULL) 1107 while ((entry = readdir(dirh)) != NULL)
1108 if (entry->d_name[0] != '.') 1108 if (entry->d_name[0] != '.')
1109 { 1109 {
1110 if (!argHandleFileDir(npath, entry->d_name, pattern)) 1110 if (!siArgHandleFileDir(npath, entry->d_name, pattern))
1111 { 1111 {
1112 ret = false; 1112 ret = false;
1113 goto out; 1113 goto out;
1114 } 1114 }
1115 } 1115 }
1126 th_free(npath); 1126 th_free(npath);
1127 return ret; 1127 return ret;
1128 } 1128 }
1129 1129
1130 1130
1131 bool argHandleFile(char *path) 1131 bool siArgHandleOther(char *path)
1132 { 1132 {
1133 char *pattern, *filename, *pt, *npath; 1133 char *pattern, *filename, *pt, *npath;
1134 bool ret; 1134 bool ret;
1135 1135
1136 if ((npath = th_strdup(path)) == NULL) 1136 if ((npath = th_strdup(path)) == NULL)
1157 pattern = th_strdup(pt); 1157 pattern = th_strdup(pt);
1158 else 1158 else
1159 filename = th_strdup(pt); 1159 filename = th_strdup(pt);
1160 } 1160 }
1161 1161
1162 ret = argHandleFileDir(npath, filename, pattern); 1162 ret = siArgHandleFileDir(npath, filename, pattern);
1163 1163
1164 th_free(pattern); 1164 th_free(pattern);
1165 th_free(npath); 1165 th_free(npath);
1166 th_free(filename); 1166 th_free(filename);
1167 return ret; 1167 return ret;
1186 memset(&optFormat, 0, sizeof(optFormat)); 1186 memset(&optFormat, 0, sizeof(optFormat));
1187 memset(&setChConv, 0, sizeof(setChConv)); 1187 memset(&setChConv, 0, sizeof(setChConv));
1188 1188
1189 // Parse command line arguments 1189 // Parse command line arguments
1190 if (!th_args_process(argc, argv, optList, optListN, 1190 if (!th_args_process(argc, argv, optList, optListN,
1191 argHandleOpt, NULL, OPTH_ONLY_OPTS)) 1191 siArgHandleOpt, NULL, OPTH_ONLY_OPTS))
1192 goto exit; 1192 goto exit;
1193 1193
1194 // Check if HVSC path is set 1194 // Check if HVSC path is set
1195 if (setHVSCPath != NULL) 1195 if (setHVSCPath != NULL)
1196 { 1196 {
1210 } 1210 }
1211 1211
1212 // Check if help is requested 1212 // Check if help is requested
1213 if (optShowHelp || argc < 2) 1213 if (optShowHelp || argc < 2)
1214 { 1214 {
1215 argShowHelp(); 1215 siArgShowHelp();
1216 goto exit; 1216 goto exit;
1217 } 1217 }
1218 1218
1219 // Initialize character set conversion 1219 // Initialize character set conversion
1220 if ((res = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK) 1220 if ((res = sidutil_chconv_init(&setChConv, setLang)) != THERR_OK)
1277 goto exit; 1277 goto exit;
1278 } 1278 }
1279 1279
1280 // Process files 1280 // Process files
1281 if (!th_args_process(argc, argv, optList, optListN, 1281 if (!th_args_process(argc, argv, optList, optListN,
1282 NULL, argHandleFile, OPTH_ONLY_OTHER)) 1282 NULL, siArgHandleOther, OPTH_ONLY_OTHER))
1283 goto exit; 1283 goto exit;
1284 1284
1285 if (optNFiles == 0) 1285 if (optNFiles == 0)
1286 { 1286 {
1287 THERR("No filename(s) specified. Try --help.\n"); 1287 THERR("No filename(s) specified. Try --help.\n");