Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 2004:161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
pointer. Also improve error handling in it.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Jul 2018 01:11:22 +0300 |
parents | 8896d5676f1b |
children | 2ff214f811b4 |
comparison
equal
deleted
inserted
replaced
2003:2ae47dcaaf10 | 2004:161e731eb152 |
---|---|
379 value->color.b = colB; | 379 value->color.b = colB; |
380 value->triplet = TRUE; | 380 value->triplet = TRUE; |
381 } | 381 } |
382 else | 382 else |
383 { | 383 { |
384 if (!dmGetIntVal(opt, &value->from)) | 384 if (!dmGetIntVal(opt, &value->from, NULL)) |
385 { | 385 { |
386 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); | 386 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); |
387 goto error; | 387 goto error; |
388 } | 388 } |
389 value->triplet = FALSE; | 389 value->triplet = FALSE; |
392 // Trim whitespace | 392 // Trim whitespace |
393 split++; | 393 split++; |
394 while (*split && isspace(*split)) split++; | 394 while (*split && isspace(*split)) split++; |
395 | 395 |
396 // Parse destination value | 396 // Parse destination value |
397 if (!dmGetIntVal(split, &value->to)) | 397 if (!dmGetIntVal(split, &value->to, NULL)) |
398 { | 398 { |
399 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); | 399 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); |
400 goto error; | 400 goto error; |
401 } | 401 } |
402 | 402 |
447 { | 447 { |
448 dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt); | 448 dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt); |
449 return FALSE; | 449 return FALSE; |
450 } | 450 } |
451 | 451 |
452 if (!dmGetIntVal(opt, &value[index])) | 452 if (!dmGetIntVal(opt, &value[index], NULL)) |
453 { | 453 { |
454 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); | 454 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); |
455 return FALSE; | 455 return FALSE; |
456 } | 456 } |
457 } | 457 } |
604 if (*last != 0) | 604 if (*last != 0) |
605 ptr++; | 605 ptr++; |
606 | 606 |
607 *arg = ptr; | 607 *arg = ptr; |
608 | 608 |
609 return dmGetIntVal(start, value); | 609 return dmGetIntVal(start, value, NULL); |
610 } | 610 } |
611 | 611 |
612 | 612 |
613 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | 613 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
614 { | 614 { |
651 case 3: | 651 case 3: |
652 optOutFilename = optArg; | 652 optOutFilename = optArg; |
653 break; | 653 break; |
654 | 654 |
655 case 4: | 655 case 4: |
656 if (!dmGetIntVal(optArg, &optInSkip)) | 656 if (!dmGetIntVal(optArg, &optInSkip, NULL)) |
657 { | 657 { |
658 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); | 658 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); |
659 return FALSE; | 659 return FALSE; |
660 } | 660 } |
661 break; | 661 break; |
694 dmPrint(1, "\n"); | 694 dmPrint(1, "\n"); |
695 } | 695 } |
696 break; | 696 break; |
697 | 697 |
698 case 7: | 698 case 7: |
699 if (!dmGetIntVal(optArg, &tmpUInt) || | 699 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
700 tmpUInt < 1) | 700 tmpUInt < 1) |
701 { | 701 { |
702 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n", | 702 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n", |
703 optArg); | 703 optArg); |
704 return FALSE; | 704 return FALSE; |
766 } | 766 } |
767 } | 767 } |
768 break; | 768 break; |
769 | 769 |
770 case 11: | 770 case 11: |
771 if (!dmGetIntVal(optArg, &tmpUInt) || | 771 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
772 tmpUInt < 1 || tmpUInt > 512) | 772 tmpUInt < 1 || tmpUInt > 512) |
773 { | 773 { |
774 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n", | 774 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n", |
775 optArg); | 775 optArg); |
776 return FALSE; | 776 return FALSE; |
781 case 12: | 781 case 12: |
782 optSpec.paletted = TRUE; | 782 optSpec.paletted = TRUE; |
783 break; | 783 break; |
784 | 784 |
785 case 13: | 785 case 13: |
786 if (!dmGetIntVal(optArg, &tmpUInt) || | 786 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
787 tmpUInt < 1 || tmpUInt > 8) | 787 tmpUInt < 1 || tmpUInt > 8) |
788 { | 788 { |
789 dmErrorMsg("Invalid number of bitplanes value '%s' [1 .. 8]\n", | 789 dmErrorMsg("Invalid number of bitplanes value '%s' [1 .. 8]\n", |
790 optArg); | 790 optArg); |
791 return FALSE; | 791 return FALSE; |
792 } | 792 } |
793 optSpec.nplanes = tmpUInt; | 793 optSpec.nplanes = tmpUInt; |
794 break; | 794 break; |
795 | 795 |
796 case 18: | 796 case 18: |
797 if (!dmGetIntVal(optArg, &tmpUInt) || | 797 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
798 tmpUInt < 1 || tmpUInt > 32) | 798 tmpUInt < 1 || tmpUInt > 32) |
799 { | 799 { |
800 dmErrorMsg("Invalid number of bits per pixel value '%s' [1 .. 32]\n", | 800 dmErrorMsg("Invalid number of bits per pixel value '%s' [1 .. 32]\n", |
801 optArg); | 801 optArg); |
802 return FALSE; | 802 return FALSE; |