Mercurial > hg > sidinfo
comparison sidinfo.c @ 393:db64a58314a9
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:19:12 +0200 |
parents | e89e5d956a63 |
children | 9f9cf5c4b474 |
comparison
equal
deleted
inserted
replaced
392:ad0fe49a211a | 393:db64a58314a9 |
---|---|
99 | 99 |
100 // Option variables | 100 // Option variables |
101 char *setHVSCPath = NULL, | 101 char *setHVSCPath = NULL, |
102 *setSLDBPath = NULL, | 102 *setSLDBPath = NULL, |
103 *setSTILDBPath = NULL; | 103 *setSTILDBPath = NULL; |
104 BOOL optParsable = FALSE, | 104 bool optParsable = false, |
105 optFieldNamePrefix = TRUE, | 105 optFieldNamePrefix = true, |
106 optHexadecimal = FALSE, | 106 optHexadecimal = false, |
107 optFieldOutput = TRUE, | 107 optFieldOutput = true, |
108 optRecurseDirs = FALSE, | 108 optRecurseDirs = false, |
109 optShowHelp = FALSE; | 109 optShowHelp = false; |
110 char *optOneLineFieldSep = NULL, | 110 char *optOneLineFieldSep = NULL, |
111 *optEscapeChars = NULL; | 111 *optEscapeChars = NULL; |
112 int optNFiles = 0, | 112 int optNFiles = 0, |
113 setSIDLibFlags = 0; | 113 setSIDLibFlags = 0; |
114 | 114 |
233 } | 233 } |
234 return found; | 234 return found; |
235 } | 235 } |
236 | 236 |
237 | 237 |
238 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item) | 238 bool siStackAddItem(PSFStack *stack, const PSFStackItem *item) |
239 { | 239 { |
240 if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated) | 240 if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated) |
241 { | 241 { |
242 stack->nallocated += 16; | 242 stack->nallocated += 16; |
243 if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL) | 243 if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL) |
244 { | 244 { |
245 THERR("Could not allocate memory for format item stack.\n"); | 245 THERR("Could not allocate memory for format item stack.\n"); |
246 return FALSE; | 246 return false; |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem)); | 250 memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem)); |
251 stack->nitems++; | 251 stack->nitems++; |
252 return TRUE; | 252 return true; |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 void siClearStack(PSFStack *stack) | 256 void siClearStack(PSFStack *stack) |
257 { | 257 { |
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 argParsePSFields(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) |
291 PSFStackItem item; | 291 PSFStackItem item; |
292 int found = argMatchPSFieldError(field); | 292 int found = argMatchPSFieldError(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 |
298 memset(&item, 0, sizeof(item)); | 298 memset(&item, 0, sizeof(item)); |
299 item.cmd = found; | 299 item.cmd = found; |
300 item.fmt = th_strdup(optPSOptions[found].dfmt); | 300 item.fmt = th_strdup(optPSOptions[found].dfmt); |
301 | 301 |
302 if (!siStackAddItem(stack, &item)) | 302 if (!siStackAddItem(stack, &item)) |
303 return FALSE; | 303 return false; |
304 } | 304 } |
305 | 305 |
306 if (!end) | 306 if (!end) |
307 break; | 307 break; |
308 | 308 |
309 start = end + 1; | 309 start = end + 1; |
310 } | 310 } |
311 | 311 |
312 return TRUE; | 312 return true; |
313 } | 313 } |
314 | 314 |
315 | 315 |
316 static int siItemFormatStrPutInt(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 316 static int siItemFormatStrPutInt(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
317 const int value, const int f_radix, int f_flags, int f_width, int f_prec, | 317 const int value, const int f_radix, int f_flags, int f_width, int f_prec, |
318 const BOOL f_unsig, th_vprintf_altfmt_func f_alt) | 318 const bool f_unsig, th_vprintf_altfmt_func f_alt) |
319 { | 319 { |
320 char buf[64]; | 320 char buf[64]; |
321 int f_len = 0, vret; | 321 int f_len = 0, vret; |
322 BOOL f_neg = FALSE; | 322 bool f_neg = false; |
323 | 323 |
324 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, value, | 324 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, value, |
325 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | 325 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
326 | 326 |
327 if (vret == EOF) | 327 if (vret == EOF) |
345 goto out; | 345 goto out; |
346 } | 346 } |
347 else | 347 else |
348 { | 348 { |
349 int f_width = -1, f_prec = -1, f_flags = 0; | 349 int f_width = -1, f_prec = -1, f_flags = 0; |
350 BOOL end = FALSE; | 350 bool end = false; |
351 | 351 |
352 fmt++; | 352 fmt++; |
353 | 353 |
354 // Check for flags | 354 // Check for flags |
355 while (!end) | 355 while (!end) |
379 case '\'': | 379 case '\'': |
380 f_flags |= TH_PF_GROUP; | 380 f_flags |= TH_PF_GROUP; |
381 break; | 381 break; |
382 | 382 |
383 default: | 383 default: |
384 end = TRUE; | 384 end = true; |
385 break; | 385 break; |
386 } | 386 } |
387 if (!end) fmt++; | 387 if (!end) fmt++; |
388 } | 388 } |
389 | 389 |
423 case 0: | 423 case 0: |
424 return -104; | 424 return -104; |
425 | 425 |
426 case 'o': | 426 case 'o': |
427 if (otype != OTYPE_INT) return -120; | 427 if (otype != OTYPE_INT) return -120; |
428 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF) | 428 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct)) == EOF) |
429 goto out; | 429 goto out; |
430 break; | 430 break; |
431 | 431 |
432 case 'u': | 432 case 'u': |
433 case 'i': | 433 case 'i': |
440 case 'x': | 440 case 'x': |
441 case 'X': | 441 case 'X': |
442 if (otype != OTYPE_INT) return -120; | 442 if (otype != OTYPE_INT) return -120; |
443 if (*fmt == 'X') | 443 if (*fmt == 'X') |
444 f_flags |= TH_PF_UPCASE; | 444 f_flags |= TH_PF_UPCASE; |
445 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) | 445 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) |
446 goto out; | 446 goto out; |
447 break; | 447 break; |
448 | 448 |
449 case 's': | 449 case 's': |
450 if (otype != OTYPE_STR) return -121; | 450 if (otype != OTYPE_STR) return -121; |
515 ctx->ipos++; | 515 ctx->ipos++; |
516 return ch; | 516 return ch; |
517 } | 517 } |
518 | 518 |
519 | 519 |
520 static BOOL siItemFormatStrCheck(const char *fmt, const PSFOption *opt) | 520 static bool siItemFormatStrCheck(const char *fmt, const PSFOption *opt) |
521 { | 521 { |
522 th_vprintf_ctx ctx; | 522 th_vprintf_ctx ctx; |
523 | 523 |
524 memset(&ctx, 0, sizeof(ctx)); | 524 memset(&ctx, 0, sizeof(ctx)); |
525 | 525 |
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 argParsePSFormatStr(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 |
539 siClearStack(stack); | 539 siClearStack(stack); |
540 | 540 |
541 while (mode != -1) | 541 while (mode != -1) |
542 switch (mode) | 542 switch (mode) |
571 memset(&item, 0, sizeof(item)); | 571 memset(&item, 0, sizeof(item)); |
572 item.cmd = -2; | 572 item.cmd = -2; |
573 item.chr = '@'; | 573 item.chr = '@'; |
574 | 574 |
575 if (!siStackAddItem(stack, &item)) | 575 if (!siStackAddItem(stack, &item)) |
576 return FALSE; | 576 return false; |
577 } | 577 } |
578 else | 578 else |
579 { | 579 { |
580 char *fopt = NULL, *pfield, *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH); | 580 char *fopt = NULL, *pfield, *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH); |
581 if ((pfield = strchr(field, ':')) != NULL) | 581 if ((pfield = strchr(field, ':')) != NULL) |
599 item.fmt = th_strdup(fopt); | 599 item.fmt = th_strdup(fopt); |
600 } | 600 } |
601 else | 601 else |
602 { | 602 { |
603 THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field); | 603 THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field); |
604 rval = FALSE; | 604 rval = false; |
605 } | 605 } |
606 } | 606 } |
607 | 607 |
608 if (!siStackAddItem(stack, &item)) | 608 if (!siStackAddItem(stack, &item)) |
609 rval = FALSE; | 609 rval = false; |
610 } | 610 } |
611 else | 611 else |
612 rval = FALSE; | 612 rval = false; |
613 | 613 |
614 th_free(fopt); | 614 th_free(fopt); |
615 th_free(field); | 615 th_free(field); |
616 } | 616 } |
617 | 617 |
626 memset(&item, 0, sizeof(item)); | 626 memset(&item, 0, sizeof(item)); |
627 item.cmd = -1; | 627 item.cmd = -1; |
628 item.str = th_strndup(start, fmt - start); | 628 item.str = th_strndup(start, fmt - start); |
629 | 629 |
630 if (!siStackAddItem(stack, &item)) | 630 if (!siStackAddItem(stack, &item)) |
631 return FALSE; | 631 return false; |
632 | 632 |
633 mode = (*fmt == 0) ? -1 : 0; | 633 mode = (*fmt == 0) ? -1 : 0; |
634 } | 634 } |
635 else | 635 else |
636 fmt++; | 636 fmt++; |
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 argHandleOpt(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; |
650 break; | 650 break; |
651 | 651 |
652 case 1: | 652 case 1: |
653 sidutil_print_license(); | 653 sidutil_print_license(); |
654 exit(0); | 654 exit(0); |
657 case 2: | 657 case 2: |
658 th_verbosity++; | 658 th_verbosity++; |
659 break; | 659 break; |
660 | 660 |
661 case 10: | 661 case 10: |
662 optParsable = TRUE; | 662 optParsable = true; |
663 break; | 663 break; |
664 | 664 |
665 case 12: | 665 case 12: |
666 optHexadecimal = TRUE; | 666 optHexadecimal = true; |
667 break; | 667 break; |
668 | 668 |
669 case 14: | 669 case 14: |
670 optFieldNamePrefix = FALSE; | 670 optFieldNamePrefix = false; |
671 break; | 671 break; |
672 | 672 |
673 case 16: | 673 case 16: |
674 optOneLineFieldSep = optArg; | 674 optOneLineFieldSep = optArg; |
675 break; | 675 break; |
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 (!argParsePSFields(&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 (!argParsePSFormatStr(&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; |
694 break; | 694 break; |
695 | 695 |
696 case 30: | 696 case 30: |
697 th_pstr_cpy(&setHVSCPath, optArg); | 697 th_pstr_cpy(&setHVSCPath, optArg); |
698 break; | 698 break; |
705 th_pstr_cpy(&setSTILDBPath, optArg); | 705 th_pstr_cpy(&setSTILDBPath, optArg); |
706 break; | 706 break; |
707 | 707 |
708 default: | 708 default: |
709 THERR("Unknown option '%s'.\n", currArg); | 709 THERR("Unknown option '%s'.\n", currArg); |
710 return FALSE; | 710 return false; |
711 } | 711 } |
712 | 712 |
713 return TRUE; | 713 return true; |
714 } | 714 } |
715 | 715 |
716 | 716 |
717 static void siPrintFieldPrefixName(FILE *outfh, const char *name, const BOOL multifield) | 717 static void siPrintFieldPrefixName(FILE *outfh, const char *name, const bool multifield) |
718 { | 718 { |
719 if (optFieldNamePrefix) | 719 if (optFieldNamePrefix) |
720 { | 720 { |
721 if (optFieldOutput && optOneLineFieldSep == NULL) | 721 if (optFieldOutput && optOneLineFieldSep == NULL) |
722 fprintf(outfh, optParsable ? "%s=" : "%-20s : ", name); | 722 fprintf(outfh, optParsable ? "%s=" : "%-20s : ", name); |
729 | 729 |
730 static void siPrintFieldPrefix(FILE *outfh, const PSFOption *opt) | 730 static void siPrintFieldPrefix(FILE *outfh, const PSFOption *opt) |
731 { | 731 { |
732 siPrintFieldPrefixName(outfh, | 732 siPrintFieldPrefixName(outfh, |
733 (optParsable || opt->lname == NULL) ? opt->name : opt->lname, | 733 (optParsable || opt->lname == NULL) ? opt->name : opt->lname, |
734 FALSE); | 734 false); |
735 } | 735 } |
736 | 736 |
737 | 737 |
738 static void siPrintFieldSeparator(FILE *outfh, const BOOL multifield, const BOOL last) | 738 static void siPrintFieldSeparator(FILE *outfh, const bool multifield, const bool last) |
739 { | 739 { |
740 if (optFieldOutput) | 740 if (optFieldOutput) |
741 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outfh); | 741 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outfh); |
742 else | 742 else |
743 if (multifield && !last) | 743 if (multifield && !last) |
765 return NULL; | 765 return NULL; |
766 } | 766 } |
767 } | 767 } |
768 | 768 |
769 | 769 |
770 static void siPrintPSIDInfoLine(FILE *outfh, BOOL *shown, | 770 static void siPrintPSIDInfoLine(FILE *outfh, bool *shown, |
771 const char *fmt, const int otype, | 771 const char *fmt, const int otype, |
772 const char *d_str, const int d_int, | 772 const char *d_str, const int d_int, |
773 const BOOL convert) | 773 const bool convert) |
774 { | 774 { |
775 char *formatted, *escaped; | 775 char *formatted, *escaped; |
776 | 776 |
777 escaped = sidutil_escape_string(d_str, optEscapeChars); | 777 escaped = sidutil_escape_string(d_str, optEscapeChars); |
778 | 778 |
790 } | 790 } |
791 | 791 |
792 th_free(formatted); | 792 th_free(formatted); |
793 th_free(escaped); | 793 th_free(escaped); |
794 | 794 |
795 *shown = TRUE; | 795 *shown = true; |
796 } | 796 } |
797 | 797 |
798 | 798 |
799 #define PRS(d_str, d_conv) do { \ | 799 #define PRS(d_str, d_conv) do { \ |
800 siPrintFieldPrefix(outfh, opt); \ | 800 siPrintFieldPrefix(outfh, opt); \ |
801 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ | 801 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ |
802 siPrintFieldSeparator(outfh, FALSE, TRUE); \ | 802 siPrintFieldSeparator(outfh, false, true); \ |
803 } while (0) | 803 } while (0) |
804 | 804 |
805 #define PRI(d_int) do { \ | 805 #define PRI(d_int) do { \ |
806 siPrintFieldPrefix(outfh, opt); \ | 806 siPrintFieldPrefix(outfh, opt); \ |
807 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, FALSE); \ | 807 siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, false); \ |
808 siPrintFieldSeparator(outfh, FALSE, TRUE); \ | 808 siPrintFieldSeparator(outfh, false, true); \ |
809 } while (0) | 809 } while (0) |
810 | 810 |
811 | 811 |
812 static void siPrintPSIDInformationField(FILE *outfh, const char *filename, | 812 static void siPrintPSIDInformationField(FILE *outfh, const char *filename, |
813 const SIDLibPSIDHeader *psid, BOOL *shown, const PSFStackItem *item) | 813 const SIDLibPSIDHeader *psid, bool *shown, const PSFStackItem *item) |
814 { | 814 { |
815 const PSFOption *opt = &optPSOptions[item->cmd]; | 815 const PSFOption *opt = &optPSOptions[item->cmd]; |
816 char tmp[128]; | 816 char tmp[128]; |
817 | 817 |
818 switch (item->cmd) | 818 switch (item->cmd) |
819 { | 819 { |
820 case 0: PRS(filename, FALSE); break; | 820 case 0: PRS(filename, false); break; |
821 case 1: | 821 case 1: |
822 snprintf(tmp, sizeof(tmp), "%s%s", | 822 snprintf(tmp, sizeof(tmp), "%s%s", |
823 psid->magic, | 823 psid->magic, |
824 psid->isInvalidRSID ? " (INVALID RSID!)" : ""); | 824 psid->isInvalidRSID ? " (INVALID RSID!)" : ""); |
825 PRS(tmp, FALSE); | 825 PRS(tmp, false); |
826 break; | 826 break; |
827 case 2: | 827 case 2: |
828 snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8)); | 828 snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8)); |
829 PRS(tmp, FALSE); | 829 PRS(tmp, false); |
830 break; | 830 break; |
831 case 3: | 831 case 3: |
832 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", FALSE); | 832 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", false); |
833 break; | 833 break; |
834 case 4: | 834 case 4: |
835 if (psid->version >= 2) | 835 if (psid->version >= 2) |
836 PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", FALSE); | 836 PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", false); |
837 break; | 837 break; |
838 case 5: | 838 case 5: |
839 if (psid->version >= 2) | 839 if (psid->version >= 2) |
840 PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), FALSE); | 840 PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), false); |
841 break; | 841 break; |
842 case 6: | 842 case 6: |
843 if (psid->version >= 2) | 843 if (psid->version >= 2) |
844 PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), FALSE); | 844 PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), false); |
845 break; | 845 break; |
846 | 846 |
847 case 7: PRI(psid->dataOffset); break; | 847 case 7: PRI(psid->dataOffset); break; |
848 case 8: PRI(psid->dataSize); break; | 848 case 8: PRI(psid->dataSize); break; |
849 case 9: PRI(psid->loadAddress); break; | 849 case 9: PRI(psid->loadAddress); break; |
865 { | 865 { |
866 int flags = (psid->flags >> 6) & PSF_MODEL_MASK; | 866 int flags = (psid->flags >> 6) & PSF_MODEL_MASK; |
867 if (flags == PSF_MODEL_UNKNOWN) | 867 if (flags == PSF_MODEL_UNKNOWN) |
868 flags = (psid->flags >> 4) & PSF_MODEL_MASK; | 868 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
869 | 869 |
870 PRS(sidlib_get_sid_model_str(flags), FALSE); | 870 PRS(sidlib_get_sid_model_str(flags), false); |
871 } | 871 } |
872 break; | 872 break; |
873 case 17: | 873 case 17: |
874 if (psid->version >= 4) | 874 if (psid->version >= 4) |
875 { | 875 { |
876 int flags = (psid->flags >> 8) & PSF_MODEL_MASK; | 876 int flags = (psid->flags >> 8) & PSF_MODEL_MASK; |
877 if (flags == PSF_MODEL_UNKNOWN) | 877 if (flags == PSF_MODEL_UNKNOWN) |
878 flags = (psid->flags >> 4) & PSF_MODEL_MASK; | 878 flags = (psid->flags >> 4) & PSF_MODEL_MASK; |
879 | 879 |
880 PRS(sidlib_get_sid_model_str(flags), FALSE); | 880 PRS(sidlib_get_sid_model_str(flags), false); |
881 } | 881 } |
882 break; | 882 break; |
883 case 18: | 883 case 18: |
884 if (psid->version >= 3) | 884 if (psid->version >= 3) |
885 PRI(0xD000 | (psid->sid2Addr << 4)); | 885 PRI(0xD000 | (psid->sid2Addr << 4)); |
887 case 19: | 887 case 19: |
888 if (psid->version >= 4) | 888 if (psid->version >= 4) |
889 PRI(0xD000 | (psid->sid3Addr << 4)); | 889 PRI(0xD000 | (psid->sid3Addr << 4)); |
890 break; | 890 break; |
891 | 891 |
892 case 20: PRS(psid->sidName, TRUE); break; | 892 case 20: PRS(psid->sidName, true); break; |
893 case 21: PRS(psid->sidAuthor, TRUE); break; | 893 case 21: PRS(psid->sidAuthor, true); break; |
894 case 22: PRS(psid->sidReleased, TRUE); break; | 894 case 22: PRS(psid->sidReleased, true); break; |
895 | 895 |
896 case 23: | 896 case 23: |
897 { | 897 { |
898 size_t i, k; | 898 size_t i, k; |
899 for (i = k = 0; i < TH_MD5HASH_LENGTH && k < sizeof(tmp) - 1; i++, k += 2) | 899 for (i = k = 0; i < TH_MD5HASH_LENGTH && k < sizeof(tmp) - 1; i++, k += 2) |
900 sprintf(&tmp[k], "%02x", psid->hash[i]); | 900 sprintf(&tmp[k], "%02x", psid->hash[i]); |
901 | 901 |
902 PRS(tmp, FALSE); | 902 PRS(tmp, false); |
903 } | 903 } |
904 break; | 904 break; |
905 | 905 |
906 case 24: | 906 case 24: |
907 if (psid->lengths != NULL && psid->lengths->nlengths > 0) | 907 if (psid->lengths != NULL && psid->lengths->nlengths > 0) |
917 | 917 |
918 siPrintPSIDInfoLine(outfh, shown, | 918 siPrintPSIDInfoLine(outfh, shown, |
919 siGetInfoFormat(item, OTYPE_STR), | 919 siGetInfoFormat(item, OTYPE_STR), |
920 OTYPE_STR, | 920 OTYPE_STR, |
921 tmp, | 921 tmp, |
922 -1, FALSE); | 922 -1, false); |
923 } | 923 } |
924 siPrintFieldSeparator(outfh, FALSE, TRUE); | 924 siPrintFieldSeparator(outfh, false, true); |
925 } | 925 } |
926 break; | 926 break; |
927 | 927 |
928 case 25: | 928 case 25: |
929 if (psid->stil != NULL) | 929 if (psid->stil != NULL) |
968 { | 968 { |
969 snprintf(tmp, sizeof(tmp), "STIL/%s", | 969 snprintf(tmp, sizeof(tmp), "STIL/%s", |
970 sidlib_stil_fields_uc[nfield]); | 970 sidlib_stil_fields_uc[nfield]); |
971 } | 971 } |
972 | 972 |
973 siPrintFieldPrefixName(outfh, tmp, TRUE); | 973 siPrintFieldPrefixName(outfh, tmp, true); |
974 siPrintPSIDInfoLine(outfh, shown, | 974 siPrintPSIDInfoLine(outfh, shown, |
975 siGetInfoFormat(item, OTYPE_STR), | 975 siGetInfoFormat(item, OTYPE_STR), |
976 OTYPE_STR, | 976 OTYPE_STR, |
977 fld->data[nitem], | 977 fld->data[nitem], |
978 -1, TRUE); | 978 -1, true); |
979 | 979 |
980 siPrintFieldSeparator(outfh, TRUE, | 980 siPrintFieldSeparator(outfh, true, |
981 ++nfieldn >= nfieldcount); | 981 ++nfieldn >= nfieldcount); |
982 } | 982 } |
983 } | 983 } |
984 } | 984 } |
985 } | 985 } |
993 (void) err; | 993 (void) err; |
994 THERR("%s - %s\n", msg, fh->filename); | 994 THERR("%s - %s\n", msg, fh->filename); |
995 } | 995 } |
996 | 996 |
997 | 997 |
998 BOOL siHandleSIDFile(const char *filename) | 998 bool siHandleSIDFile(const char *filename) |
999 { | 999 { |
1000 SIDLibPSIDHeader *psid = NULL; | 1000 SIDLibPSIDHeader *psid = NULL; |
1001 th_ioctx *infh = NULL; | 1001 th_ioctx *infh = NULL; |
1002 FILE *outfh; | 1002 FILE *outfh; |
1003 BOOL shown = FALSE; | 1003 bool shown = false; |
1004 int res; | 1004 int res; |
1005 | 1005 |
1006 outfh = stdout; | 1006 outfh = stdout; |
1007 | 1007 |
1008 if ((res = th_io_fopen(&infh, &th_stdio_io_ops, filename, "rb")) != THERR_OK) | 1008 if ((res = th_io_fopen(&infh, &th_stdio_io_ops, filename, "rb")) != THERR_OK) |
1060 // Shutdown | 1060 // Shutdown |
1061 error: | 1061 error: |
1062 sidlib_free_sid_file(psid); | 1062 sidlib_free_sid_file(psid); |
1063 th_io_close(infh); | 1063 th_io_close(infh); |
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 argHandleFileDir(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 |
1075 if (filename != NULL) | 1075 if (filename != NULL) |
1076 npath = th_strdup_printf("%s%c%s", path, TH_DIR_SEPARATOR_CHR, filename); | 1076 npath = th_strdup_printf("%s%c%s", path, TH_DIR_SEPARATOR_CHR, filename); |
1077 else | 1077 else |
1078 npath = th_strdup(path); | 1078 npath = th_strdup(path); |
1079 | 1079 |
1080 if (!th_stat_path(npath, &sdata)) | 1080 if (!th_stat_path(npath, &sdata)) |
1081 { | 1081 { |
1082 THERR("File or path '%s' does not exist.\n", npath); | 1082 THERR("File or path '%s' does not exist.\n", npath); |
1083 ret = FALSE; | 1083 ret = false; |
1084 goto out; | 1084 goto out; |
1085 } | 1085 } |
1086 | 1086 |
1087 optNFiles++; | 1087 optNFiles++; |
1088 | 1088 |
1098 if ((dirh = opendir(npath)) == NULL) | 1098 if ((dirh = opendir(npath)) == NULL) |
1099 { | 1099 { |
1100 int err = th_get_error(); | 1100 int err = th_get_error(); |
1101 THERR("Could not open directory '%s': %s\n", | 1101 THERR("Could not open directory '%s': %s\n", |
1102 path, th_error_str(err)); | 1102 path, th_error_str(err)); |
1103 ret = FALSE; | 1103 ret = false; |
1104 goto out; | 1104 goto out; |
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 (!argHandleFileDir(npath, entry->d_name, pattern)) |
1111 { | 1111 { |
1112 ret = FALSE; | 1112 ret = false; |
1113 goto out; | 1113 goto out; |
1114 } | 1114 } |
1115 } | 1115 } |
1116 | 1116 |
1117 closedir(dirh); | 1117 closedir(dirh); |
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 argHandleFile(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) |
1137 return FALSE; | 1137 return false; |
1138 | 1138 |
1139 // Check if we have path separators | 1139 // Check if we have path separators |
1140 if ((pt = strrchr(npath, '/')) != NULL || | 1140 if ((pt = strrchr(npath, '/')) != NULL || |
1141 (pt = strrchr(npath, '\\')) != NULL) | 1141 (pt = strrchr(npath, '\\')) != NULL) |
1142 { | 1142 { |
1175 | 1175 |
1176 // Get HVSC_BASE env variable if it is set | 1176 // Get HVSC_BASE env variable if it is set |
1177 th_pstr_cpy(&setHVSCPath, getenv("HVSC_BASE")); | 1177 th_pstr_cpy(&setHVSCPath, getenv("HVSC_BASE")); |
1178 | 1178 |
1179 // Initialize | 1179 // Initialize |
1180 th_init("SIDInfo", "PSID/RSID information displayer", "0.9.5", | 1180 th_init("SIDInfo", "PSID/RSID information displayer", "1.0.0", |
1181 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2022 TNSP", | 1181 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2022 TNSP", |
1182 "This program is distributed under a 3-clause BSD -style license."); | 1182 "This program is distributed under a 3-clause BSD -style license."); |
1183 | 1183 |
1184 th_verbosity = 0; | 1184 th_verbosity = 0; |
1185 | 1185 |
1229 // Check operation mode | 1229 // Check operation mode |
1230 if (optOneLineFieldSep != NULL || | 1230 if (optOneLineFieldSep != NULL || |
1231 (!optFieldOutput && optFormat.nitems > 0)) | 1231 (!optFieldOutput && optFormat.nitems > 0)) |
1232 { | 1232 { |
1233 // For one-line format and formatted output (-F), disable parsable | 1233 // For one-line format and formatted output (-F), disable parsable |
1234 optParsable = FALSE; | 1234 optParsable = false; |
1235 | 1235 |
1236 // If no escape chars have been set, use the field separator(s) | 1236 // If no escape chars have been set, use the field separator(s) |
1237 if (optEscapeChars == NULL) | 1237 if (optEscapeChars == NULL) |
1238 optEscapeChars = optOneLineFieldSep; | 1238 optEscapeChars = optOneLineFieldSep; |
1239 } | 1239 } |