Subversion Repositories filter_foundry

Rev

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

Rev 482 Rev 492
Line 36... Line 36...
36
enum{
36
enum{
37
        BUFSIZE = 4L<<10,
37
        BUFSIZE = 4L<<10,
38
        MAXLINE = 0x200,
38
        MAXLINE = 0x200,
39
};
39
};
40
 
40
 
41
Boolean readparams_afs_pff(Handle h,char **reason){
41
Boolean readparams_afs_pff(Handle h, TCHAR**reason){
42
        Boolean res = false;
42
        Boolean res = false;
43
        char linebuf[MAXLINE + 1] = { 0 };
43
        char linebuf[MAXLINE + 1] = { 0 };
44
        char curexpr[MAXEXPR + 1] = { 0 };
44
        char curexpr[MAXEXPR + 1] = { 0 };
45
        char *p, *dataend, *q;
45
        char *p, *dataend, *q;
46
        char c;
46
        char c;
Line 52... Line 52...
52
        dataend = p + PIGETHANDLESIZE(h);
52
        dataend = p + PIGETHANDLESIZE(h);
53
 
53
 
54
        q = curexpr;
54
        q = curexpr;
55
        linecnt = exprcnt = lineptr = 0;
55
        linecnt = exprcnt = lineptr = 0;
56
 
56
 
57
        //*reason = _strdup("File was too short.");
57
        //*reason = _strdup("File was too short."); // TODO (Not so important): TRANSLATE
58
        while(p < dataend){
58
        while(p < dataend){
59
 
59
 
60
                c = *p++;
60
                c = *p++;
61
 
61
 
62
                if(c==CR || c==LF){ /* detected end of line */
62
                if(c==CR || c==LF){ /* detected end of line */
Line 68... Line 68...
68
                        linebuf[lineptr] = 0; /* add terminating NUL to line buffer */
68
                        linebuf[lineptr] = 0; /* add terminating NUL to line buffer */
69
 
69
 
70
                        /* process complete line */
70
                        /* process complete line */
71
                        if(linecnt==0){
71
                        if(linecnt==0){
72
                                if(strcmp(linebuf,"%RGB-1.0")){
72
                                if(strcmp(linebuf,"%RGB-1.0")){
73
                                        // *reason = _strdup("This doesn't look like a Filter Factory file (first line is not \"%RGB-1.0\").");
73
                                        // *reason = _strdup("This doesn't look like a Filter Factory file (first line is not \"%RGB-1.0\")."); // TODO (Not so important): TRANSLATE
74
                                        break;
74
                                        break;
75
                                }
75
                                }
76
                        }else if(linecnt<=8){
76
                        }else if(linecnt<=8){
77
                                int v;
77
                                int v;
78
                                v = atoi(linebuf);
78
                                v = atoi(linebuf);
Line 81... Line 81...
81
                                slider[linecnt-1] = (uint8_t)v;
81
                                slider[linecnt-1] = (uint8_t)v;
82
                        }else{
82
                        }else{
83
                                if(lineptr){
83
                                if(lineptr){
84
                                        /* it's not an empty line; append it to current expr string */
84
                                        /* it's not an empty line; append it to current expr string */
85
                                        if( q+lineptr > curexpr+MAXEXPR ){
85
                                        if( q+lineptr > curexpr+MAXEXPR ){
-
 
86
                                                // TODO: isn't the limit 1024?! (because we need to have the NUL too?)
86
                                                *reason = _strdup("Found an expression longer than 1024 characters.");
87
                                                *reason = FF_GetMsg_Cpy(MSG_EXPRESSION1024_FOUND_ID);
87
                                                break;
88
                                                break;
88
                                        }
89
                                        }
89
                                        q = cat(q,linebuf);
90
                                        q = cat(q,linebuf);
90
                                }else{
91
                                }else{
91
                                        /* it's an empty line: we've completed the expr string */
92
                                        /* it's an empty line: we've completed the expr string */
92
                                        if(expr[exprcnt])
93
                                        if(expr[exprcnt])
93
                                                free(expr[exprcnt]);
94
                                                free(expr[exprcnt]);
94
                                        *q = 0;
95
                                        *q = 0;
95
                                        if(!(expr[exprcnt] = my_strdup(curexpr))){
96
                                        if(!(expr[exprcnt] = my_strdup(curexpr))){
96
                                                *reason = _strdup("Could not get memory for expression.");
97
                                                *reason = FF_GetMsg_Cpy(MSG_EXPRESSION_OOM_ID);
97
                                                break;
98
                                                break;
98
                                        }
99
                                        }
99
 
100
 
100
                                        if(++exprcnt == 4){
101
                                        if(++exprcnt == 4){
101
                                                res = true;
102
                                                res = true;
Line 124... Line 125...
124
                                                c = CR;
125
                                                c = CR;
125
                                                #endif
126
                                                #endif
126
                                                break;
127
                                                break;
127
                                        case '\\': break;
128
                                        case '\\': break;
128
                                        //default:
129
                                        //default:
129
                                        //      if(alerts) alertuser((TCHAR*)TEXT("Warning:"),TEXT("Unknown escape sequence in input."));
130
                                        //      if(alerts) alertuser((TCHAR*)TEXT("Warning:"),TEXT("Unknown escape sequence in input.")); // TODO (Not so important): TRANSLATE
130
                                        }
131
                                        }
131
                                }//else if(alerts) alertuser((TCHAR*)TEXT("Warning:"),TEXT("truncated escape sequence ends input"));
132
                                }//else if(alerts) alertuser((TCHAR*)TEXT("Warning:"),TEXT("truncated escape sequence ends input")); // TODO (Not so important): TRANSLATE
132
                        }
133
                        }
133
 
134
 
134
                        if(lineptr < MAXLINE)
135
                        if(lineptr < MAXLINE)
135
                                linebuf[lineptr++] = c;
136
                                linebuf[lineptr++] = c;
136
                }
137
                }
Line 192... Line 193...
192
        }
193
        }
193
        *q += len;
194
        *q += len;
194
        return val;
195
        return val;
195
}
196
}
196
 
197
 
197
Boolean readfile_ffx(StandardFileReply* sfr, char** reason) {
198
Boolean readfile_ffx(StandardFileReply* sfr, TCHAR** reason) {
198
        Handle h;
199
        Handle h;
199
        Boolean res = false;
200
        Boolean res = false;
200
        FILEREF refnum;
201
        FILEREF refnum;
201
        uint32_t len;
202
        uint32_t len;
202
        char* val;
203
        char* val;
Line 215... Line 216...
215
                                if (strcmp(val, "FFX1.0") == 0) format_version = 10;
216
                                if (strcmp(val, "FFX1.0") == 0) format_version = 10;
216
                                else if (strcmp(val, "FFX1.1") == 0) format_version = 11;
217
                                else if (strcmp(val, "FFX1.1") == 0) format_version = 11;
217
                                else if (strcmp(val, "FFX1.2") == 0) format_version = 12;
218
                                else if (strcmp(val, "FFX1.2") == 0) format_version = 12;
218
                                free(val);
219
                                free(val);
219
                                if (format_version > 0) {
220
                                if (format_version > 0) {
220
                                        simplewarning((TCHAR*)TEXT("Attention! You are loading a \"Filters Unlimited\" file. Please note that Filter Foundry only implements the basic Filter Factory functions. Therefore, most \"Filters Unlimited\" filters won't work with Filter Foundry."));
221
                                        simplewarning_id(MSG_FILTERS_UNLIMITED_WARNING_ID);
221
 
222
 
222
                                        val = _ffx_read_str(&q);
223
                                        val = _ffx_read_str(&q);
223
                                        strcpy(gdata->parm.szTitle, val);
224
                                        strcpy(gdata->parm.szTitle, val);
224
                                        free(val);
225
                                        free(val);
225
 
226
 
Line 257... Line 258...
257
                                                                val = val2;
258
                                                                val = val2;
258
                                                        }
259
                                                        }
259
                                                }
260
                                                }
260
                                                if (strlen(val) >= sizeof(gdata->parm.szFormula[i])) {
261
                                                if (strlen(val) >= sizeof(gdata->parm.szFormula[i])) {
261
                                                        if (i == 0) {
262
                                                        if (i == 0) {
262
                                                                simplealert((TCHAR*)TEXT("Attention! The formula for channel I/R was too long (longer than 1023 characters) and was truncated."));
263
                                                                simplealert_id(MSG_FORMULA_IR_1023_TRUNCATED_ID);
263
                                                        }
264
                                                        }
264
                                                        else if (i == 1) {
265
                                                        else if (i == 1) {
265
                                                                simplealert((TCHAR*)TEXT("Attention! The formula for channel G was too long (longer than 1023 characters) and was truncated."));
266
                                                                simplealert_id(MSG_FORMULA_G_1023_TRUNCATED_ID);
266
                                                        }
267
                                                        }
267
                                                        else if (i == 2) {
268
                                                        else if (i == 2) {
268
                                                                simplealert((TCHAR*)TEXT("Attention! The formula for channel B was too long (longer than 1023 characters) and was truncated."));
269
                                                                simplealert_id(MSG_FORMULA_B_1023_TRUNCATED_ID);
269
                                                        }
270
                                                        }
270
                                                        else if (i == 3) {
271
                                                        else if (i == 3) {
271
                                                                simplealert((TCHAR*)TEXT("Attention! The formula for channel A was too long (longer than 1023 characters) and was truncated."));
272
                                                                simplealert_id(MSG_FORMULA_A_1023_TRUNCATED_ID);
272
                                                        }
273
                                                        }
273
                                                        // C++ wrong warning: Buffer overflow (C6386)
274
                                                        // C++ wrong warning: Buffer overflow (C6386)
274
                                                        #pragma warning(suppress : 6386)
275
                                                        #pragma warning(suppress : 6386)
275
                                                        val[sizeof(gdata->parm.szFormula[i]) - 1] = '\0';
276
                                                        val[sizeof(gdata->parm.szFormula[i]) - 1] = '\0';
276
                                                }
277
                                                }
Line 319... Line 320...
319
 
320
 
320
        if (res) gdata->obfusc = false;
321
        if (res) gdata->obfusc = false;
321
        return res;
322
        return res;
322
}
323
}
323
 
324
 
324
Boolean readfile_8bf(StandardFileReply *sfr,char **reason){
325
Boolean readfile_8bf(StandardFileReply *sfr, TCHAR**reason){
325
        unsigned char magic[2];
326
        unsigned char magic[2];
326
        FILECOUNT count;
327
        FILECOUNT count;
327
        Handle h;
328
        Handle h;
328
        Boolean res = false;
329
        Boolean res = false;
329
        FILEREF refnum;
330
        FILEREF refnum;
Line 348... Line 349...
348
                                }
349
                                }
349
                        }
350
                        }
350
                } // else no point in proceeding
351
                } // else no point in proceeding
351
                FSClose(refnum);
352
                FSClose(refnum);
352
        }else
353
        }else
353
                *reason = _strdup("Could not open file.");
354
                *reason = FF_GetMsg_Cpy(MSG_CANNOT_OPEN_FILE_ID);
354
 
355
 
355
        if (res) gdata->obfusc = false;
356
        if (res) gdata->obfusc = false;
356
        return res;
357
        return res;
357
}
358
}
358
 
359
 
Line 699... Line 700...
699
        }
700
        }
700
        free(inputworkinitial);
701
        free(inputworkinitial);
701
        return true;
702
        return true;
702
}
703
}
703
 
704
 
704
Boolean readfile_picotxt(StandardFileReply* sfr, char** reason) {
705
Boolean readfile_picotxt(StandardFileReply* sfr, TCHAR** reason) {
705
        extern int ctls[], maps[];
706
        extern int ctls[], maps[];
706
 
707
 
707
        Handle h;
708
        Handle h;
708
        Boolean res = false;
709
        Boolean res = false;
709
        FILEREF refnum;
710
        FILEREF refnum;
Line 788... Line 789...
788
        }
789
        }
789
 
790
 
790
        return res;
791
        return res;
791
}
792
}
792
 
793
 
793
Boolean readfile_afs_pff(StandardFileReply *sfr,char **reason){
794
Boolean readfile_afs_pff(StandardFileReply *sfr, TCHAR**reason){
794
        FILEREF r;
795
        FILEREF r;
795
        Handle h;
796
        Handle h;
796
        Boolean res = false;
797
        Boolean res = false;
797
 
798
 
798
        if(FSpOpenDF(&sfr->sfFile,fsRdPerm,&r) == noErr){
799
        if(FSpOpenDF(&sfr->sfFile,fsRdPerm,&r) == noErr){
Line 811... Line 812...
811
                        }
812
                        }
812
 
813
 
813
                        PIDISPOSEHANDLE(h);
814
                        PIDISPOSEHANDLE(h);
814
                }
815
                }
815
                FSClose(r);
816
                FSClose(r);
-
 
817
        }
816
        }else
818
        else
817
                *reason = _strdup("Could not open the file.");
819
                *reason = FF_GetMsg_Cpy(MSG_CANNOT_OPEN_FILE_ID);
818
 
820
 
819
        return res;
821
        return res;
820
}
822
}