Rev 167 | Rev 185 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | toby | 1 | /* |
18 | toby | 2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
171 | dmarschall | 3 | Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au |
2 | toby | 4 | |
5 | This program is free software; you can redistribute it and/or modify |
||
103 | toby | 6 | it under the terms of the GNU General Public License as published by |
2 | toby | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
103 | toby | 15 | You should have received a copy of the GNU General Public License |
2 | toby | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | #include "ff.h" |
||
21 | |||
22 | #include "file_compat.h" |
||
23 | #include "sprintf_tiny.h" |
||
24 | |||
25 | enum{ CHOPLINES = 63 }; |
||
26 | |||
27 | OSErr putstr(Handle h,char *s); |
||
28 | |||
29 | OSErr putstr(Handle h,char *s){ |
||
30 | Ptr p; |
||
31 | OSErr e; |
||
32 | long size = PIGETHANDLESIZE(h),n = strlen(s); |
||
103 | toby | 33 | |
2 | toby | 34 | if(!(e = PISETHANDLESIZE(h,size+n))){ |
35 | p = PILOCKHANDLE(h,false); |
||
36 | memcpy(p+size,s,n); |
||
37 | PIUNLOCKHANDLE(h); |
||
38 | } |
||
39 | return e; |
||
40 | } |
||
41 | |||
42 | OSErr saveparams(Handle h){ |
||
43 | char outbuf[CHOPLINES*2+2],*q,*p,*r,*start; |
||
44 | int i,j,chunk,n; |
||
45 | OSErr e; |
||
46 | long est; |
||
124 | dmarschall | 47 | static char afs_sig[] = "%RGB-1.0\r"; |
103 | toby | 48 | |
15 | toby | 49 | if(!h) DBG("saveparams: Null handle!"); |
103 | toby | 50 | |
52 | toby | 51 | est = strlen(expr[0]) + strlen(expr[1]) + strlen(expr[2]) + strlen(expr[3]); |
52 | // do not be tempted to combine into one expression: 'est' is referenced below |
||
53 | est += strlen(afs_sig) + est/CHOPLINES + 4 + 8*6 + 64 /*slop*/ ; |
||
103 | toby | 54 | |
15 | toby | 55 | PIUNLOCKHANDLE(h); // should not be necessary |
2 | toby | 56 | if( !(e = PISETHANDLESIZE(h,est)) && (p = start = PILOCKHANDLE(h,false)) ){ |
52 | toby | 57 | // build one long string in AFS format |
58 | p = cat(p,afs_sig); // first the header signature |
||
103 | toby | 59 | |
52 | toby | 60 | /* then slider values, one per line */ |
102 | toby | 61 | for( i=0 ; i<8 ; ++i ) |
124 | dmarschall | 62 | p += sprintf(p, "%ld\r", slider[i]); |
103 | toby | 63 | |
52 | toby | 64 | /* expressions, broken into lines no longer than CHOPLINES characters */ |
15 | toby | 65 | for( i=0 ; i<4 ; ++i ){ |
23 | toby | 66 | if( (r = expr[i]) ) |
15 | toby | 67 | for( n = strlen(r) ; n ; n -= chunk ){ |
68 | chunk = n>CHOPLINES ? CHOPLINES : n; |
||
69 | for( j = chunk,q = outbuf ; j-- ; ) |
||
70 | if(*r == CR){ |
||
71 | *q++ = '\\'; |
||
72 | *q++ = 'r'; |
||
73 | ++r; |
||
103 | toby | 74 | }else |
15 | toby | 75 | *q++ = *r++; |
124 | dmarschall | 76 | *q++ = '\r'; |
15 | toby | 77 | *q = 0; |
78 | p = cat(p,outbuf); |
||
79 | } |
||
80 | else |
||
124 | dmarschall | 81 | p = cat(p,"(null expr)\r"); // this shouldn't happen |
82 | *p++ = '\r'; |
||
15 | toby | 83 | } |
84 | |||
85 | // *p = 0; dbg(start); |
||
86 | |||
2 | toby | 87 | PIUNLOCKHANDLE(h); |
15 | toby | 88 | e = PISETHANDLESIZE(h,p - start); // could ignore this error, maybe |
2 | toby | 89 | } |
23 | toby | 90 | |
2 | toby | 91 | return e; |
92 | } |
||
93 | |||
94 | OSErr savehandleintofile(Handle h,FILEREF r){ |
||
95 | Ptr p = PILOCKHANDLE(h,false); |
||
96 | long n = PIGETHANDLESIZE(h); |
||
97 | OSErr e = FSWrite(r,&n,p); |
||
98 | PIUNLOCKHANDLE(h); |
||
99 | return e; |
||
100 | } |
||
101 | |||
102 | Boolean savefile(StandardFileReply *sfr){ |
||
103 | FILEREF r; |
||
104 | Handle h; |
||
105 | Boolean res = false; |
||
106 | char *reasonstr = ""; |
||
107 | |||
108 | FSpDelete(&sfr->sfFile); |
||
109 | if(!FSpCreate(&sfr->sfFile,SIG_SIMPLETEXT,TEXT_FILETYPE,sfr->sfScript)) |
||
110 | if(!FSpOpenDF(&sfr->sfFile,fsWrPerm,&r)){ |
||
111 | |||
167 | dmarschall | 112 | if( (h = PINEWHANDLE(1)) ){ // don't set initial size to 0, since some hosts (e.g. GIMP/PSPI) are incompatible with that. res = !(saveparams(h) || savehandleintofile(h,r)) ; |
2 | toby | 113 | res = !(saveparams(h) || savehandleintofile(h,r)) ; |
114 | PIDISPOSEHANDLE(h); |
||
115 | } |
||
116 | |||
117 | FSClose(r); |
||
118 | }else reasonstr = ("Could not open the file."); |
||
119 | else reasonstr = ("Could not create the file."); |
||
120 | |||
121 | if(!res) |
||
122 | alertuser("Could not save settings.",reasonstr); |
||
123 | |||
124 | return res; |
||
125 | } |