Rev 387 | Rev 389 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 387 | Rev 388 | ||
---|---|---|---|
Line 444... | Line 444... | ||
444 | } |
444 | } |
445 | 445 | ||
446 | Boolean _picoLineContainsKey(char* line, char** content, const char* searchkey/*=NULL*/) { |
446 | Boolean _picoLineContainsKey(char* line, char** content, const char* searchkey/*=NULL*/) { |
447 | size_t i; |
447 | size_t i; |
448 | for (i = 0; i < strlen(line); i++) { |
448 | for (i = 0; i < strlen(line); i++) { |
- | 449 | if (line[i] == '?') break; // avoid that "a?b:c" is detected as key |
|
449 | if (line[i] == ':') { |
450 | if (line[i] == ':') { |
450 | // Note: We are ignoring whitespaces, i.e. " A :" != "A:" (TODO: should we change this?) |
451 | // Note: We are ignoring whitespaces, i.e. " A :" != "A:" (TODO: should we change this?) |
451 | if ((searchkey == NULL) || ((i == strlen(searchkey)) && (memcmp(line, searchkey, i) == 0))) { |
452 | if ((searchkey == NULL) || ((i == strlen(searchkey)) && (memcmp(line, searchkey, i) == 0))) { |
452 | i++; // jump over ':' char |
453 | i++; // jump over ':' char |
453 | //while ((line[i] == ' ') || (line[i] == TAB)) i++; // Trim value left |
454 | //while ((line[i] == ' ') || (line[i] == TAB)) i++; // Trim value left |
Line 458... | Line 459... | ||
458 | } |
459 | } |
459 | *content = line; |
460 | *content = line; |
460 | return false; |
461 | return false; |
461 | } |
462 | } |
462 | 463 | ||
- | 464 | void _ffdcomp_removebrackets(char* x, char* maxptr) { |
|
- | 465 | char* closingBracketPos = NULL; |
|
- | 466 | Boolean openingBracketFound = false; |
|
- | 467 | if (x[0] == '[') { |
|
- | 468 | openingBracketFound = true; |
|
- | 469 | } |
|
- | 470 | x[0] = ':'; |
|
- | 471 | x++; |
|
- | 472 | while (x < maxptr) { |
|
- | 473 | if ((!openingBracketFound) && (x[0] == '[')) { |
|
- | 474 | openingBracketFound = true; |
|
- | 475 | x[0] = ' '; |
|
- | 476 | } |
|
- | 477 | else if (openingBracketFound) { |
|
- | 478 | if (x[0] == ']') { |
|
- | 479 | closingBracketPos = x; |
|
- | 480 | } |
|
- | 481 | else if ((x[0] == CR) || (x[0] == LF)) { |
|
- | 482 | if (closingBracketPos) closingBracketPos[0] = ' '; // last closing pos before CR/LF |
|
- | 483 | break; |
|
- | 484 | } |
|
- | 485 | } |
|
- | 486 | x++; |
|
- | 487 | } |
|
- | 488 | } |
|
- | 489 | ||
463 | // isFormula=false => outputFile is Pascal string. TXT linebreaks become spaces. |
490 | // isFormula=false => outputFile is Pascal string. TXT linebreaks become spaces. |
464 | // isFormula=true => outputFile is C string. TXT line breaks become CRLF line breaks |
491 | // isFormula=true => outputFile is C string. TXT line breaks become CRLF line breaks |
465 | Boolean _picoReadProperty(char* inputFile, int maxInput, const char* property, char* outputFile, size_t maxOutput, Boolean isFormula) { |
492 | Boolean _picoReadProperty(char* inputFile, int maxInput, const char* property, char* outputFile, size_t maxOutput, Boolean isFormula) { |
466 | int i; |
493 | int i; |
467 | char* outputwork; |
494 | char* outputwork; |
Line 479... | Line 506... | ||
479 | //char* inputwork = inputFile; |
506 | //char* inputwork = inputFile; |
480 | inputwork = (char*)malloc(maxInput + 1); |
507 | inputwork = (char*)malloc(maxInput + 1); |
481 | inputworkinitial = inputwork; |
508 | inputworkinitial = inputwork; |
482 | if (inputwork == 0) return false; |
509 | if (inputwork == 0) return false; |
483 | memcpy(inputwork, inputFile, maxInput); |
510 | memcpy(inputwork, inputFile, maxInput); |
- | 511 | inputwork[maxInput] = 0; // otherwise strstr() will crash |
|
- | 512 | ||
- | 513 | // Transform "FFDecomp" TXT file into the similar "PluginCommander" TXT file |
|
- | 514 | if (strstr(inputwork, "Filter Factory Plugin Information:")) { |
|
- | 515 | char* x; |
|
- | 516 | char* k1; |
|
- | 517 | char* k2; |
|
- | 518 | // Metadata: |
|
- | 519 | x = strstr(inputwork, "CATEGORY:"); |
|
- | 520 | if (x) strncpy(x, "Category:", strlen("Category:")); |
|
- | 521 | x = strstr(inputwork, "TITLE:"); |
|
- | 522 | if (x) strncpy(x, "Title:", strlen("Title:")); |
|
- | 523 | x = strstr(inputwork, "COPYRIGHT:"); |
|
- | 524 | if (x) strncpy(x, "Copyright:", strlen("Copyright:")); |
|
- | 525 | x = strstr(inputwork, "AUTHOR:"); |
|
- | 526 | if (x) strncpy(x, "Author:", strlen("Author:")); |
|
- | 527 | // Controls: |
|
- | 528 | for (i = 0; i < 8; i++) { |
|
- | 529 | k1 = (char*)malloc(strlen("Control X:") + 1); |
|
- | 530 | sprintf(k1, "Control %d:", i); |
|
- | 531 | x = strstr(inputwork, k1); |
|
- | 532 | if (x) { |
|
- | 533 | k2 = (char*)malloc(strlen("ctl[X]: ") + 1); |
|
- | 534 | sprintf(k2, "ctl[%d]: ", i); |
|
- | 535 | strncpy(x, k2, strlen(k2)); |
|
- | 536 | x += strlen("ctl[X]"); |
|
- | 537 | _ffdcomp_removebrackets(x, inputwork + maxInput - 1); |
|
- | 538 | free(k2); |
|
- | 539 | } |
|
- | 540 | free(k1); |
|
- | 541 | } |
|
- | 542 | // Maps: |
|
- | 543 | for (i = 0; i < 4; i++) { |
|
- | 544 | k1 = (char*)malloc(strlen("Map X:") + 1); |
|
- | 545 | sprintf(k1, "Map %d:", i); |
|
- | 546 | x = strstr(inputwork, k1); |
|
- | 547 | if (x) { |
|
- | 548 | k2 = (char*)malloc(strlen("map[X]:") + 1); |
|
- | 549 | sprintf(k2, "map[%d]:", i); |
|
- | 550 | strncpy(x, k2, strlen(k2)); |
|
- | 551 | x += strlen("map[X]"); |
|
- | 552 | _ffdcomp_removebrackets(x, inputwork + maxInput - 1); |
|
- | 553 | free(k2); |
|
- | 554 | } |
|
- | 555 | free(k1); |
|
- | 556 | } |
|
- | 557 | // Convert all '\r' to '\n' for the next step to be easier |
|
- | 558 | for (i = 0; i < maxInput; i++) { |
|
- | 559 | if (inputworkinitial[i] == CR) inputworkinitial[i] = LF; |
|
- | 560 | } |
|
- | 561 | x = strstr(inputwork, "\nR=\n"); |
|
- | 562 | if (x) strncpy(x, "\nR:\n", strlen("\nR:\n")); |
|
- | 563 | x = strstr(inputwork, "\nG=\n"); |
|
- | 564 | if (x) strncpy(x, "\nG:\n", strlen("\nG:\n")); |
|
- | 565 | x = strstr(inputwork, "\nB=\n"); |
|
- | 566 | if (x) strncpy(x, "\nB:\n", strlen("\nB:\n")); |
|
- | 567 | x = strstr(inputwork, "\nA=\n"); |
|
- | 568 | if (x) strncpy(x, "\nA:\n", strlen("\nA:\n")); |
|
- | 569 | } |
|
484 | // Replace all \r and \n with \0, so that we can parse easier |
570 | // Replace all \r and \n with \0, so that we can parse easier |
485 | for (i = 0; i < maxInput; i++) { |
571 | for (i = 0; i < maxInput; i++) { |
486 | if (inputwork[i] == 0) break; |
572 | if (inputworkinitial[i] == 0) break; |
487 | if (inputwork[i] == CR) inputwork[i] = 0; |
573 | if (inputworkinitial[i] == CR) inputworkinitial[i] = 0; |
488 | if (inputwork[i] == LF) inputwork[i] = 0; |
574 | if (inputworkinitial[i] == LF) inputworkinitial[i] = 0; |
489 | } |
575 | } |
490 | // C++ wrong warning: Buffer overflow (C6386) |
- | |
491 | // 'The writeable size is "maxInput+1" Byte, but "maxInput" byte can be written'. WTF? |
- | |
492 | #pragma warning(suppress : 6386) |
- | |
493 | inputwork[maxInput] = 0; |
- | |
- | 576 | ||
494 | // Find line that contains out key |
577 | // Find line that contains out key |
- | 578 | inputwork = inputworkinitial; |
|
495 | do { |
579 | do { |
496 | if (inputwork > inputworkinitial + maxInput) { |
580 | if (inputwork > inputworkinitial + maxInput) { |
497 | // Key not found. Set output to empty string |
581 | // Key not found. Set output to empty string |
498 | outputwork[0] = 0; |
582 | outputwork[0] = 0; |
499 | free(inputworkinitial); |
583 | free(inputworkinitial); |
Line 509... | Line 593... | ||
509 | free(inputworkinitial); |
593 | free(inputworkinitial); |
510 | if (!isFormula) myc2pstr(outputFile); |
594 | if (!isFormula) myc2pstr(outputFile); |
511 | return false; |
595 | return false; |
512 | } |
596 | } |
513 | } while (!_picoLineContainsKey(sline, &svalue, property)); |
597 | } while (!_picoLineContainsKey(sline, &svalue, property)); |
- | 598 | ||
514 | // Read line(s) until we find a line with another key, or the line end |
599 | // Read line(s) until we find a line with another key, or the line end |
515 | do { |
600 | do { |
516 | while ((svalue[0] == ' ') || (svalue[0] == TAB)) svalue++; // Trim left |
601 | while ((svalue[0] == ' ') || (svalue[0] == TAB)) svalue++; // Trim left |
517 | while ((svalue[strlen(svalue) - 1] == ' ') || (svalue[strlen(svalue) - 1] == TAB)) svalue[strlen(svalue) - 1] = 0; // Trim right |
602 | while ((svalue[strlen(svalue) - 1] == ' ') || (svalue[strlen(svalue) - 1] == TAB)) svalue[strlen(svalue) - 1] = 0; // Trim right |
518 | 603 | ||
Line 530... | Line 615... | ||
530 | else { |
615 | else { |
531 | memcpy(outputwork, svalue, strlen(svalue)); |
616 | memcpy(outputwork, svalue, strlen(svalue)); |
532 | outputwork += strlen(svalue); |
617 | outputwork += strlen(svalue); |
533 | if (isFormula) { |
618 | if (isFormula) { |
534 | // Formulas: TXT line break stays line break (important if you have comments!) |
619 | // Formulas: TXT line break stays line break (important if you have comments!) |
535 | outputwork[1] = CR; |
620 | outputwork[0] = CR; |
536 | outputwork[2] = LF; |
621 | outputwork[1] = LF; |
537 | outputwork += 2; |
622 | outputwork += 2; |
538 | } |
623 | } |
539 | else { |
624 | else { |
540 | // Everything else: TXT line breaks becomes single whitespace |
625 | // Everything else: TXT line breaks becomes single whitespace |
541 | outputwork[0] = ' '; |
626 | outputwork[0] = ' '; |
Line 549... | Line 634... | ||
549 | if (inputwork > inputworkinitial + maxInput) break; |
634 | if (inputwork > inputworkinitial + maxInput) break; |
550 | sline = inputwork; |
635 | sline = inputwork; |
551 | inputwork += strlen(sline) + 1; |
636 | inputwork += strlen(sline) + 1; |
552 | if (inputwork - 1 > inputworkinitial + maxInput) break; // TODO: will that be ever called? |
637 | if (inputwork - 1 > inputworkinitial + maxInput) break; // TODO: will that be ever called? |
553 | } while (!_picoLineContainsKey(sline, &svalue, NULL)); |
638 | } while (!_picoLineContainsKey(sline, &svalue, NULL)); |
- | 639 | ||
554 | // Remove trailing whitespace |
640 | // Remove trailing whitespace |
555 | if (outputwork > outputFile) { |
641 | if (outputwork > outputFile) { |
556 | outputwork -= 1; |
642 | outputwork -= 1; |
557 | outputwork[0] = 0; |
643 | outputwork[0] = 0; |
558 | } |
644 | } |
Line 571... | Line 657... | ||
571 | if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
657 | if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
572 | if ((h = readfileintohandle(refnum))) { |
658 | if ((h = readfileintohandle(refnum))) { |
573 | FILECOUNT count = PIGETHANDLESIZE(h); |
659 | FILECOUNT count = PIGETHANDLESIZE(h); |
574 | char* q = PILOCKHANDLE(h, false); |
660 | char* q = PILOCKHANDLE(h, false); |
575 | 661 | ||
576 | // TODO: Test if ffdecomp TXT file also works |
- | |
577 | char out[256]; |
662 | char out[256]; |
578 | if (_picoReadProperty(q, count, "Title", out, sizeof(out), false)) { |
663 | if (_picoReadProperty(q, count, "Title", out, sizeof(out), false)) { |
579 | int i; |
664 | int i; |
580 | 665 | ||
581 | // Plugin infos |
666 | // Plugin infos |