Rev 2 | Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | toby | 1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
||
3 | Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au |
||
4 | |||
5 | This program is free software; you can redistribute it and/or modify |
||
6 | it under the terms of the GNU General Public License as published by |
||
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 | |||
15 | You should have received a copy of the GNU General Public License |
||
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); |
||
33 | |||
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; |
||
47 | static char afs_sig[] = "%RGB-1.0\n"; |
||
48 | |||
15 | toby | 49 | if(!h) DBG("saveparams: Null handle!"); |
2 | toby | 50 | |
15 | toby | 51 | est = strlen(expr[0]) + strlen(expr[1]) + strlen(expr[2]) + strlen(expr[3]); |
52 | est += strlen(afs_sig) + est/CHOPLINES + 4 + 8*6 + 64 /*slop*/ ; |
||
53 | |||
54 | PIUNLOCKHANDLE(h); // should not be necessary |
||
2 | toby | 55 | if( !(e = PISETHANDLESIZE(h,est)) && (p = start = PILOCKHANDLE(h,false)) ){ |
56 | p = cat(p,afs_sig); |
||
57 | |||
58 | /* slider values */ |
||
59 | for( i=0 ; i<8 ; ++i ){ |
||
60 | p = int_str(p,slider[i],10); |
||
61 | *p++ = '\n'; |
||
62 | } |
||
63 | |||
64 | /* expressions */ |
||
15 | toby | 65 | for( i=0 ; i<4 ; ++i ){ |
66 | if(r = expr[i]) |
||
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; |
||
74 | }else |
||
75 | *q++ = *r++; |
||
76 | *q++ = '\n'; |
||
77 | *q = 0; |
||
78 | p = cat(p,outbuf); |
||
79 | } |
||
80 | else |
||
81 | p = cat(p,"(null expr)\n"); // this shouldn't happen |
||
82 | *p++ = '\n'; |
||
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 |
89 | }else{char s[100]; |
||
90 | //alertuser("saveparams","couldn't resize (or lock) parameters!"); |
||
91 | //sprintf(s,"est=%d e=%d ",est,e);dbg(s); |
||
2 | toby | 92 | } |
93 | err: |
||
94 | return e; |
||
95 | } |
||
96 | |||
97 | OSErr savehandleintofile(Handle h,FILEREF r){ |
||
98 | Ptr p = PILOCKHANDLE(h,false); |
||
99 | long n = PIGETHANDLESIZE(h); |
||
100 | OSErr e = FSWrite(r,&n,p); |
||
101 | PIUNLOCKHANDLE(h); |
||
102 | return e; |
||
103 | } |
||
104 | |||
105 | Boolean savefile(StandardFileReply *sfr){ |
||
106 | FILEREF r; |
||
107 | Handle h; |
||
108 | Boolean res = false; |
||
109 | char *reasonstr = ""; |
||
110 | |||
111 | FSpDelete(&sfr->sfFile); |
||
112 | if(!FSpCreate(&sfr->sfFile,SIG_SIMPLETEXT,TEXT_FILETYPE,sfr->sfScript)) |
||
113 | if(!FSpOpenDF(&sfr->sfFile,fsWrPerm,&r)){ |
||
114 | |||
115 | if(h = PINEWHANDLE(0)){ |
||
116 | res = !(saveparams(h) || savehandleintofile(h,r)) ; |
||
117 | PIDISPOSEHANDLE(h); |
||
118 | } |
||
119 | |||
120 | FSClose(r); |
||
121 | }else reasonstr = ("Could not open the file."); |
||
122 | else reasonstr = ("Could not create the file."); |
||
123 | |||
124 | if(!res) |
||
125 | alertuser("Could not save settings.",reasonstr); |
||
126 | |||
127 | return res; |
||
128 | } |