Subversion Repositories filter_foundry

Rev

Rev 537 | Rev 541 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 537 Rev 539
Line 60... Line 60...
60
 
60
 
61
                        /* look ahead to see if we need to skip a line feed (DOS CRLF EOL convention) */
61
                        /* look ahead to see if we need to skip a line feed (DOS CRLF EOL convention) */
62
                        if(p < dataend && c == CR && *p == LF)
62
                        if(p < dataend && c == CR && *p == LF)
63
                                ++p;
63
                                ++p;
64
 
64
 
65
                        linebuf[lineptr] = 0; /* add terminating NUL to line buffer */
65
                        linebuf[lineptr] = '\0'; /* add terminating NUL to line buffer */
66
 
66
 
67
                        /* process complete line */
67
                        /* process complete line */
68
                        if(linecnt==0){
68
                        if(linecnt==0){
69
                                if(strcmp(linebuf,"%RGB-1.0")){
69
                                if(strcmp(linebuf,"%RGB-1.0") != 0){
70
                                        // Note: We don't set *reason, because we cannot be sure if it is a valid file in regards to a different data type
70
                                        // Note: We don't set *reason, because we cannot be sure if it is a valid file in regards to a different data type
71
                                        // We only set *Reason, if we are sure that it is an AFS file which is indeed wrong.
71
                                        // We only set *Reason, if we are sure that it is an AFS file which is indeed wrong.
72
                                        break;
72
                                        break;
73
                                }
73
                                }
74
                        }else if(linecnt<=8){
74
                        }else if(linecnt<=8){
Line 88... Line 88...
88
                                        q = cat(q,linebuf);
88
                                        q = cat(q,linebuf);
89
                                }else{
89
                                }else{
90
                                        /* it's an empty line: we've completed the expr string */
90
                                        /* it's an empty line: we've completed the expr string */
91
                                        if(expr[exprcnt])
91
                                        if(expr[exprcnt])
92
                                                free(expr[exprcnt]);
92
                                                free(expr[exprcnt]);
93
                                        *q = 0;
93
                                        *q = '\0';
94
                                        if(!(expr[exprcnt] = my_strdup(curexpr))){
94
                                        if(!(expr[exprcnt] = my_strdup(curexpr))){
95
                                                if (reason) *reason = FF_GetMsg_Cpy(MSG_EXPRESSION_OOM_ID);
95
                                                if (reason) *reason = FF_GetMsg_Cpy(MSG_EXPRESSION_OOM_ID);
96
                                                break;
96
                                                break;
97
                                        }
97
                                        }
98
 
98
 
Line 185... Line 185...
185
        len = *((uint32_t*)*q);
185
        len = *((uint32_t*)*q);
186
        *q += sizeof(uint32_t);
186
        *q += sizeof(uint32_t);
187
        val = (char*)malloc((size_t)len + 1);
187
        val = (char*)malloc((size_t)len + 1);
188
        if (val != NULL) {
188
        if (val != NULL) {
189
                memcpy(val, (char*)*q, len);
189
                memcpy(val, (char*)*q, len);
190
                val[len] = 0;
190
                val[len] = '\0';
191
        }
191
        }
192
        *q += len;
192
        *q += len;
193
        return val;
193
        return val;
194
}
194
}
195
 
195
 
Line 557... Line 557...
557
        outputwork = outputFile;
557
        outputwork = outputFile;
558
        sline = NULL;
558
        sline = NULL;
559
        svalue = NULL;
559
        svalue = NULL;
560
        // Check parameters
560
        // Check parameters
561
        if (maxOutput == 0) return false;
561
        if (maxOutput == 0) return false;
562
        if (inputFile == 0) return false;
562
        if (inputFile == NULL) return false;
563
        // Let input memory be read-only, +1 for terminal zero
563
        // Let input memory be read-only, +1 for terminal zero
564
        //char* inputwork = inputFile;
564
        //char* inputwork = inputFile;
565
        inputwork = (char*)malloc((size_t)maxInput + 1);
565
        inputwork = (char*)malloc((size_t)maxInput + 1);
566
        inputworkinitial = inputwork;
566
        inputworkinitial = inputwork;
567
        if (inputwork == 0) return false;
567
        if (inputwork == NULL) return false;
568
        memcpy(inputwork, inputFile, maxInput);
568
        memcpy(inputwork, inputFile, maxInput);
569
        inputwork[maxInput] = 0; // otherwise strstr() will crash
569
        inputwork[maxInput] = '\0'; // otherwise strstr() will crash
570
 
570
 
571
        // Transform "FFDecomp" TXT file into the similar "PluginCommander" TXT file
571
        // Transform "FFDecomp" TXT file into the similar "PluginCommander" TXT file
572
        if (strstr(inputwork, "Filter Factory Plugin Information:")) {
572
        if (strstr(inputwork, "Filter Factory Plugin Information:")) {
573
                char* x;
573
                char* x;
574
                char* k1;
574
                char* k1;
Line 625... Line 625...
625
                x = strstr(inputwork, "\nA=\n");
625
                x = strstr(inputwork, "\nA=\n");
626
                if (x) memcpy(x, "\nA:\n", strlen("\nA:\n"));
626
                if (x) memcpy(x, "\nA:\n", strlen("\nA:\n"));
627
        }
627
        }
628
        // Replace all \r and \n with \0, so that we can parse easier
628
        // Replace all \r and \n with \0, so that we can parse easier
629
        for (i = 0; i < maxInput; i++) {
629
        for (i = 0; i < maxInput; i++) {
630
                if (inputworkinitial[i] == CR) inputworkinitial[i] = 0;
630
                if (inputworkinitial[i] == CR) inputworkinitial[i] = '\0';
631
                else if (inputworkinitial[i] == LF) inputworkinitial[i] = 0;
631
                else if (inputworkinitial[i] == LF) inputworkinitial[i] = '\0';
632
        }
632
        }
633
 
633
 
634
        // Find line that contains out key
634
        // Find line that contains out key
635
        inputwork = inputworkinitial;
635
        inputwork = inputworkinitial;
636
        do {
636
        do {
637
                if (inputwork > inputworkinitial + maxInput) {
637
                if (inputwork > inputworkinitial + maxInput) {
638
                        // Key not found. Set output to empty string
638
                        // Key not found. Set output to empty string
639
                        outputwork[0] = 0;
639
                        outputwork[0] = '\0';
640
                        free(inputworkinitial);
640
                        free(inputworkinitial);
641
                        return false;
641
                        return false;
642
                }
642
                }
643
                sline = inputwork;
643
                sline = inputwork;
644
                inputwork += strlen(sline) + 1;
644
                inputwork += strlen(sline) + 1;
645
                if (inputwork - 1 > inputworkinitial + maxInput) {
645
                if (inputwork - 1 > inputworkinitial + maxInput) {
646
                        // Key not found. Set output to empty string
646
                        // Key not found. Set output to empty string
647
                        // TODO: will that be ever called?
647
                        // TODO: will that be ever called?
648
                        outputwork[0] = 0;
648
                        outputwork[0] = '\0';
649
                        free(inputworkinitial);
649
                        free(inputworkinitial);
650
                        return false;
650
                        return false;
651
                }
651
                }
652
        } while (!_picoLineContainsKey(sline, &svalue, property));
652
        } while (!_picoLineContainsKey(sline, &svalue, property));
653
 
653
 
654
        // Read line(s) until we find a line with another key, or the line end
654
        // Read line(s) until we find a line with another key, or the line end
655
        do {
655
        do {
656
                while ((svalue[0] == ' ') || (svalue[0] == TAB)) svalue++; // Trim left
656
                while ((svalue[0] == ' ') || (svalue[0] == TAB)) svalue++; // Trim left
657
                while ((svalue[strlen(svalue) - 1] == ' ') || (svalue[strlen(svalue) - 1] == TAB)) svalue[strlen(svalue) - 1] = 0; // Trim right
657
                while ((svalue[strlen(svalue) - 1] == ' ') || (svalue[strlen(svalue) - 1] == TAB)) svalue[strlen(svalue) - 1] = '\0'; // Trim right
658
 
658
 
659
                if (strlen(svalue) > 0) {
659
                if (strlen(svalue) > 0) {
660
                        if (outputwork + strlen(svalue) + (isFormula ? 3/*CRLF+NUL*/ : 2/*space+NUL*/) > outputFile + maxOutput) {
660
                        if (outputwork + strlen(svalue) + (isFormula ? 3/*CRLF+NUL*/ : 2/*space+NUL*/) > outputFile + maxOutput) {
661
                                size_t remaining = maxOutput - (outputwork - outputFile) - 1;
661
                                size_t remaining = maxOutput - (outputwork - outputFile) - 1;
662
                                //printf("BUFFER FULL (remaining = %d)\n", remaining);
662
                                //printf("BUFFER FULL (remaining = %d)\n", remaining);
663
                                memcpy(outputwork, svalue, remaining);
663
                                memcpy(outputwork, svalue, remaining);
664
                                outputwork += remaining;
664
                                outputwork += remaining;
665
                                outputwork[0] = 0;
665
                                outputwork[0] = '\0';
666
                                free(inputworkinitial);
666
                                free(inputworkinitial);
667
                                return true;
667
                                return true;
668
                        }
668
                        }
669
                        else {
669
                        else {
670
                                memcpy(outputwork, svalue, strlen(svalue));
670
                                memcpy(outputwork, svalue, strlen(svalue));
Line 680... Line 680...
680
                                        outputwork[0] = ' ';
680
                                        outputwork[0] = ' ';
681
                                        outputwork++;
681
                                        outputwork++;
682
                                }
682
                                }
683
                        }
683
                        }
684
                }
684
                }
685
                outputwork[0] = 0;
685
                outputwork[0] = '\0';
686
 
686
 
687
                // Process next line
687
                // Process next line
688
                if (inputwork > inputworkinitial + maxInput) break;
688
                if (inputwork > inputworkinitial + maxInput) break;
689
                sline = inputwork;
689
                sline = inputwork;
690
                inputwork += strlen(sline) + 1;
690
                inputwork += strlen(sline) + 1;
Line 692... Line 692...
692
        } while (!_picoLineContainsKey(sline, &svalue, NULL));
692
        } while (!_picoLineContainsKey(sline, &svalue, NULL));
693
 
693
 
694
        // Remove trailing whitespace
694
        // Remove trailing whitespace
695
        if (outputwork > outputFile) {
695
        if (outputwork > outputFile) {
696
                outputwork -= 1;
696
                outputwork -= 1;
697
                outputwork[0] = 0;
697
                outputwork[0] = '\0';
698
        }
698
        }
699
        free(inputworkinitial);
699
        free(inputworkinitial);
700
        return true;
700
        return true;
701
}
701
}
702
 
702
 
Line 785... Line 785...
785
        }
785
        }
786
 
786
 
787
        return res;
787
        return res;
788
}
788
}
789
 
789
 
790
Boolean _gufReadProperty(char* inputFile, size_t maxInput, const char* section, const char* property, char* outputFile, size_t maxOutput) {
790
Boolean _gufReadProperty(char* fileContents, size_t argMaxInputLength, const char* section, const char* keyname, char* argOutput, size_t argMaxOutLength) {
-
 
791
        size_t iTmp;
-
 
792
        char* tmpFileContents, * tmpSection, * tmpStart, * tmpStart2, * tmpEnd, * tmpKeyname, * tmpStart3, * tmpStart4, * inputwork;
-
 
793
 
791
        // TODO: Implement
794
        // Check parameters
-
 
795
        if (argMaxOutLength == 0) return false;
-
 
796
        if (fileContents == NULL) return false;
-
 
797
 
-
 
798
        // Handle argMaxInputLength
-
 
799
        //char* inputwork = fileContents;
-
 
800
        inputwork = (char*)malloc((size_t)argMaxInputLength + 1);
-
 
801
        if (inputwork == NULL) return false;
-
 
802
        memcpy(inputwork, fileContents, argMaxInputLength);
-
 
803
        inputwork[argMaxInputLength] = '\0';
-
 
804
 
-
 
805
        // Prepare the input file contents to make it easier parse-able
-
 
806
        iTmp = strlen(inputwork) + strlen("\n\n[");
-
 
807
        tmpFileContents = (char*)malloc(iTmp + 1);
-
 
808
        if (tmpFileContents == NULL) return false;
-
 
809
        sprintf(tmpFileContents, "\n%s\n[", inputwork);
-
 
810
        for (iTmp = 0; iTmp < strlen(tmpFileContents); iTmp++) {
-
 
811
                if (tmpFileContents[iTmp] == '\r') tmpFileContents[iTmp] = '\n';
-
 
812
        }
-
 
813
 
-
 
814
        // Find the section begin
-
 
815
        iTmp = strlen(section) + strlen("\n[]\n");
-
 
816
        tmpSection = (char*)malloc(iTmp + 1);
-
 
817
        if (tmpSection == NULL) return false;
-
 
818
        sprintf(tmpSection, "\n[%s]\n", section);
-
 
819
        tmpStart = strstr(tmpFileContents, tmpSection);
-
 
820
        if (tmpStart == NULL) return false;
-
 
821
        tmpStart += iTmp;
-
 
822
 
-
 
823
        // Find the end of the section and set a NULL terminator to it
-
 
824
        iTmp = strlen(tmpStart) + strlen("\n");
-
 
825
        tmpStart2 = (char*)malloc(iTmp + 1/*NUL byte*/);
-
 
826
        if (tmpStart2 == NULL) return false;
-
 
827
        sprintf(tmpStart2, "\n%s", tmpStart);
-
 
828
        tmpEnd = strstr(tmpStart2, "\n[");
-
 
829
        if (tmpEnd == NULL) return false;
-
 
830
        tmpEnd[0] = '\0';
-
 
831
 
-
 
832
        // Find the start of the value
-
 
833
        iTmp = strlen(keyname) + strlen("\n=");
-
 
834
        tmpKeyname = (char*)malloc(iTmp + 1/*NUL byte*/);
-
 
835
        if (tmpKeyname == NULL) return false;
-
 
836
        sprintf(tmpKeyname, "\n%s=", keyname);
-
 
837
        tmpStart3 = strstr(tmpStart2, tmpKeyname);
-
 
838
        if (tmpStart3 == NULL) return false;
-
 
839
        tmpStart3 += strlen("\n");
-
 
840
        tmpStart4 = strstr(tmpStart3, "=");
-
 
841
        if (tmpStart4 == NULL) return false;
-
 
842
        tmpStart4 += strlen("=");
-
 
843
 
-
 
844
        // Find the end of the value
-
 
845
        tmpEnd = strstr(tmpStart4, "\n");
-
 
846
        if (tmpEnd == NULL) return false;
-
 
847
        tmpEnd[0] = '\0';
-
 
848
 
-
 
849
        // Copy to output
-
 
850
        if (strlen(tmpStart4) < argMaxOutLength + 1) argMaxOutLength = strlen(tmpStart4) + 1;
-
 
851
        memcpy(argOutput, tmpStart4, argMaxOutLength);
-
 
852
        argOutput[argMaxOutLength - 1] = '\0';
-
 
853
 
-
 
854
        // Free all temporary stuff
-
 
855
        //for (iTmp = 0; iTmp < strlen(tmpFileContents); iTmp++) tmpFileContents[iTmp] = '\0';
-
 
856
        free(tmpFileContents);
-
 
857
        //for (iTmp = 0; iTmp < strlen(tmpSection); iTmp++) tmpSection[iTmp] = '\0';
-
 
858
        free(tmpSection);
-
 
859
        //for (iTmp = 0; iTmp < strlen(tmpKeyname); iTmp++) tmpKeyname[iTmp] = '\0';
-
 
860
        free(tmpKeyname);
-
 
861
        //for (iTmp = 0; iTmp < strlen(tmpStart2); iTmp++) tmpStart2[iTmp] = '\0';
-
 
862
        free(tmpStart2);
-
 
863
 
-
 
864
        // Return success
792
        return false;
865
        return true;
793
}
866
}
794
 
867
 
795
Boolean readfile_guf(StandardFileReply* sfr, TCHAR** reason) {
868
Boolean readfile_guf(StandardFileReply* sfr, TCHAR** reason) {
796
        extern int ctls[], maps[];
869
        extern int ctls[], maps[];
797
 
870
 
Line 806... Line 879...
806
                        FILECOUNT count = (FILECOUNT)PIGETHANDLESIZE(h);
879
                        FILECOUNT count = (FILECOUNT)PIGETHANDLESIZE(h);
807
                        char* q = PILOCKHANDLE(h, false);
880
                        char* q = PILOCKHANDLE(h, false);
808
 
881
 
809
                        char out[256];
882
                        char out[256];
810
                        if (_gufReadProperty(q, count, "GUF", "Protocol", out, sizeof(out))) {
883
                        if (_gufReadProperty(q, count, "GUF", "Protocol", out, sizeof(out))) {
811
                                if (!strcmp(out, "1")) {
884
                                if (strcmp(out, "1") != 0) {
812
                                        if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID);
885
                                        if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID);
-
 
886
                                        PIUNLOCKHANDLE(h);
-
 
887
                                        PIDISPOSEHANDLE(h);
-
 
888
                                        FSClose(refnum);
813
                                        return false;
889
                                        return false;
814
                                }
890
                                }
815
                        }
891
                        }
816
                        else {
892
                        else {
817
                                if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID);
893
                                if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID);
-
 
894
                                PIUNLOCKHANDLE(h);
-
 
895
                                PIDISPOSEHANDLE(h);
-
 
896
                                FSClose(refnum);
818
                                return false;
897
                                return false;
819
                        }
898
                        }
820
                        if (_gufReadProperty(q, count, "Info", "Title", out, sizeof(out))) {
899
                        if (_gufReadProperty(q, count, "Info", "Title", out, sizeof(out))) {
821
                                int i;
900
                                int i;
822
 
901