ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/UUlib.xs
(Generate patch)

Comparing Convert-UUlib/UUlib.xs (file contents):
Revision 1.18 by root, Fri Feb 28 16:57:25 2020 UTC vs.
Revision 1.19 by root, Fri Feb 28 17:19:02 2020 UTC

6 6
7#include "uulib/fptools.h" 7#include "uulib/fptools.h"
8#include "uulib/uudeview.h" 8#include "uulib/uudeview.h"
9#include "uulib/uuint.h" 9#include "uulib/uuint.h"
10 10
11static int released; 11static int perlinterp_released;
12 12
13#define RELEASE do { released = 1; perlinterp_release (); } while (0) 13#define RELEASE do { perlinterp_released = 1; perlinterp_release (); } while (0)
14#define ACQUIRE do { perlinterp_acquire (); released = 0; } while (0) 14#define ACQUIRE do { perlinterp_acquire (); perlinterp_released = 0; } while (0)
15 15
16#define TEMP_ACQUIRE if (released) perlinterp_acquire (); 16#define TEMP_ACQUIRE if (perlinterp_released) perlinterp_acquire ();
17#define TEMP_RELEASE if (released) perlinterp_release (); 17#define TEMP_RELEASE if (perlinterp_released) perlinterp_release ();
18 18
19static int 19static int
20not_here (char *s) 20not_here (char *s)
21{ 21{
22 croak("%s not implemented", s); 22 croak("%s not implemented", s);
28{ 28{
29 errno = 0; 29 errno = 0;
30 switch (*name) 30 switch (*name)
31 { 31 {
32 case 'A': 32 case 'A':
33 if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING; 33 if (strEQ (name, "ACT_COPYING")) return UUACT_COPYING;
34 if (strEQ(name, "ACT_DECODING")) return UUACT_DECODING; 34 if (strEQ (name, "ACT_DECODING")) return UUACT_DECODING;
35 if (strEQ(name, "ACT_ENCODING")) return UUACT_ENCODING; 35 if (strEQ (name, "ACT_ENCODING")) return UUACT_ENCODING;
36 if (strEQ(name, "ACT_IDLE")) return UUACT_IDLE; 36 if (strEQ (name, "ACT_IDLE")) return UUACT_IDLE;
37 if (strEQ(name, "ACT_SCANNING")) return UUACT_SCANNING; 37 if (strEQ (name, "ACT_SCANNING")) return UUACT_SCANNING;
38 case 'F': 38 case 'F':
39 if (strEQ(name, "FILE_DECODED")) return UUFILE_DECODED; 39 if (strEQ (name, "FILE_DECODED")) return UUFILE_DECODED;
40 if (strEQ(name, "FILE_ERROR")) return UUFILE_ERROR; 40 if (strEQ (name, "FILE_ERROR")) return UUFILE_ERROR;
41 if (strEQ(name, "FILE_MISPART")) return UUFILE_MISPART; 41 if (strEQ (name, "FILE_MISPART")) return UUFILE_MISPART;
42 if (strEQ(name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN; 42 if (strEQ (name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN;
43 if (strEQ(name, "FILE_NODATA")) return UUFILE_NODATA; 43 if (strEQ (name, "FILE_NODATA")) return UUFILE_NODATA;
44 if (strEQ(name, "FILE_NOEND")) return UUFILE_NOEND; 44 if (strEQ (name, "FILE_NOEND")) return UUFILE_NOEND;
45 if (strEQ(name, "FILE_OK")) return UUFILE_OK; 45 if (strEQ (name, "FILE_OK")) return UUFILE_OK;
46 if (strEQ(name, "FILE_READ")) return UUFILE_READ; 46 if (strEQ (name, "FILE_READ")) return UUFILE_READ;
47 if (strEQ(name, "FILE_TMPFILE")) return UUFILE_TMPFILE; 47 if (strEQ (name, "FILE_TMPFILE")) return UUFILE_TMPFILE;
48 break; 48 break;
49 case 'M': 49 case 'M':
50 if (strEQ(name, "MSG_ERROR")) return UUMSG_ERROR; 50 if (strEQ (name, "MSG_ERROR")) return UUMSG_ERROR;
51 if (strEQ(name, "MSG_FATAL")) return UUMSG_FATAL; 51 if (strEQ (name, "MSG_FATAL")) return UUMSG_FATAL;
52 if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE; 52 if (strEQ (name, "MSG_MESSAGE")) return UUMSG_MESSAGE;
53 if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE; 53 if (strEQ (name, "MSG_NOTE")) return UUMSG_NOTE;
54 if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC; 54 if (strEQ (name, "MSG_PANIC")) return UUMSG_PANIC;
55 if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING; 55 if (strEQ (name, "MSG_WARNING")) return UUMSG_WARNING;
56 case 'O': 56 case 'O':
57 if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION; 57 if (strEQ (name, "OPT_VERSION")) return UUOPT_VERSION;
58 if (strEQ(name, "OPT_FAST")) return UUOPT_FAST; 58 if (strEQ (name, "OPT_FAST")) return UUOPT_FAST;
59 if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS; 59 if (strEQ (name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
60 if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL; 60 if (strEQ (name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL;
61 if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE; 61 if (strEQ (name, "OPT_VERBOSE")) return UUOPT_VERBOSE;
62 if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE; 62 if (strEQ (name, "OPT_DESPERATE")) return UUOPT_DESPERATE;
63 if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY; 63 if (strEQ (name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY;
64 if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE; 64 if (strEQ (name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE;
65 if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH; 65 if (strEQ (name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
66 if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE; 66 if (strEQ (name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
67 if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG; 67 if (strEQ (name, "OPT_DEBUG")) return UUOPT_DEBUG;
68 if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO; 68 if (strEQ (name, "OPT_ERRNO")) return UUOPT_ERRNO;
69 if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS; 69 if (strEQ (name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
70 if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT; 70 if (strEQ (name, "OPT_USETEXT")) return UUOPT_USETEXT;
71 if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB; 71 if (strEQ (name, "OPT_PREAMB")) return UUOPT_PREAMB;
72 if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64; 72 if (strEQ (name, "OPT_TINYB64")) return UUOPT_TINYB64;
73 if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT; 73 if (strEQ (name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
74 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE; 74 if (strEQ (name, "OPT_REMOVE")) return UUOPT_REMOVE;
75 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME; 75 if (strEQ (name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
76 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT; 76 if (strEQ (name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
77 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF; 77 if (strEQ (name, "OPT_RBUF")) return UUOPT_RBUF;
78 if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF; 78 if (strEQ (name, "OPT_WBUF")) return UUOPT_WBUF;
79 if (strEQ(name, "OPT_AUTOCHECK")) return UUOPT_AUTOCHECK; 79 if (strEQ (name, "OPT_AUTOCHECK")) return UUOPT_AUTOCHECK;
80 case 'R': 80 case 'R':
81 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 81 if (strEQ (name, "RET_CANCEL")) return UURET_CANCEL;
82 if (strEQ(name, "RET_CONT")) return UURET_CONT; 82 if (strEQ (name, "RET_CONT")) return UURET_CONT;
83 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 83 if (strEQ (name, "RET_EXISTS")) return UURET_EXISTS;
84 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 84 if (strEQ (name, "RET_ILLVAL")) return UURET_ILLVAL;
85 if (strEQ(name, "RET_IOERR")) return UURET_IOERR; 85 if (strEQ (name, "RET_IOERR")) return UURET_IOERR;
86 if (strEQ(name, "RET_NODATA")) return UURET_NODATA; 86 if (strEQ (name, "RET_NODATA")) return UURET_NODATA;
87 if (strEQ(name, "RET_NOEND")) return UURET_NOEND; 87 if (strEQ (name, "RET_NOEND")) return UURET_NOEND;
88 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM; 88 if (strEQ (name, "RET_NOMEM")) return UURET_NOMEM;
89 if (strEQ(name, "RET_OK")) return UURET_OK; 89 if (strEQ (name, "RET_OK")) return UURET_OK;
90 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP; 90 if (strEQ (name, "RET_UNSUP")) return UURET_UNSUP;
91 case 'B': 91 case 'B':
92 if (strEQ(name, "B64_ENCODED")) return B64ENCODED; 92 if (strEQ (name, "B64_ENCODED")) return B64ENCODED;
93 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED; 93 if (strEQ (name, "BH_ENCODED")) return BH_ENCODED;
94 case 'P': 94 case 'P':
95 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED; 95 if (strEQ (name, "PT_ENCODED")) return PT_ENCODED;
96 case 'Q': 96 case 'Q':
97 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED; 97 if (strEQ (name, "QP_ENCODED")) return QP_ENCODED;
98 case 'U': 98 case 'U':
99 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED; 99 if (strEQ (name, "UU_ENCODED")) return UU_ENCODED;
100 case 'X': 100 case 'X':
101 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED; 101 if (strEQ (name, "XX_ENCODED")) return XX_ENCODED;
102 case 'Y': 102 case 'Y':
103 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED; 103 if (strEQ (name, "YENC_ENCODED")) return YENC_ENCODED;
104 } 104 }
105 105
106 errno = EINVAL; 106 errno = EINVAL;
107 return 0; 107 return 0;
108} 108}
110static void 110static void
111uu_msg_callback (void *cb, char *msg, int level) 111uu_msg_callback (void *cb, char *msg, int level)
112{ 112{
113 TEMP_ACQUIRE { 113 TEMP_ACQUIRE {
114 114
115 dSP; 115 dSP;
116 116
117 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 117 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
118 118
119 PUSHs (sv_2mortal (newSVpv (msg, 0))); 119 PUSHs (sv_2mortal (newSVpv (msg, 0)));
120 PUSHs (sv_2mortal (newSViv (level))); 120 PUSHs (sv_2mortal (newSViv (level)));
121 121
122 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN; 122 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
123 PUTBACK; FREETMPS; LEAVE; 123 PUTBACK; FREETMPS; LEAVE;
124 124
125 } TEMP_RELEASE; 125 } TEMP_RELEASE;
126} 126}
127 127
128static int 128static int
130{ 130{
131 int retval; 131 int retval;
132 132
133 TEMP_ACQUIRE { 133 TEMP_ACQUIRE {
134 134
135 dSP; 135 dSP;
136 int count; 136 int count;
137 137
138 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6); 138 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
139 139
140 PUSHs (sv_2mortal (newSViv (uup->action))); 140 PUSHs (sv_2mortal (newSViv (uup->action)));
141 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0))); 141 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
142 PUSHs (sv_2mortal (newSViv (uup->partno))); 142 PUSHs (sv_2mortal (newSViv (uup->partno)));
143 PUSHs (sv_2mortal (newSViv (uup->numparts))); 143 PUSHs (sv_2mortal (newSViv (uup->numparts)));
144 PUSHs (sv_2mortal (newSViv (uup->fsize))); 144 PUSHs (sv_2mortal (newSViv (uup->fsize)));
145 PUSHs (sv_2mortal (newSViv (uup->percent))); 145 PUSHs (sv_2mortal (newSViv (uup->percent)));
146 146
147 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 147 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
148 148
149 if (count != 1) 149 if (count != 1)
150 croak ("busycallback perl callback returned more than one argument"); 150 croak ("busycallback perl callback returned more than one argument");
151 151
152 retval = POPi; 152 retval = POPi;
153 153
154 PUTBACK; FREETMPS; LEAVE; 154 PUTBACK; FREETMPS; LEAVE;
155 155
156 } TEMP_RELEASE; 156 } TEMP_RELEASE;
157 157
158 return retval; 158 return retval;
159} 159}
163{ 163{
164 static char *str; 164 static char *str;
165 165
166 TEMP_ACQUIRE { 166 TEMP_ACQUIRE {
167 167
168 dSP; 168 dSP;
169 int count; 169 int count;
170 170
171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1); 171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
172 172
173 PUSHs (sv_2mortal (newSVpv (fname, 0))); 173 PUSHs (sv_2mortal (newSVpv (fname, 0)));
174 174
175 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 175 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
176 176
177 if (count != 1) 177 if (count != 1)
178 croak ("fnamefilter perl callback MUST return a single filename exactly"); 178 croak ("fnamefilter perl callback MUST return a single filename exactly");
179 179
180 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs)); 180 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
181 181
182 PUTBACK; FREETMPS; LEAVE; 182 PUTBACK; FREETMPS; LEAVE;
183 183
184 } TEMP_RELEASE; 184 } TEMP_RELEASE;
185 185
186 return str; 186 return str;
187} 187}
191{ 191{
192 int retval; 192 int retval;
193 193
194 TEMP_ACQUIRE { 194 TEMP_ACQUIRE {
195 195
196 dSP; 196 dSP;
197 int count; 197 int count;
198 SV *xfname = newSVpv ("", 0); 198 SV *xfname = newSVpv ("", 0);
199 199
200 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3); 200 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
201 201
202 PUSHs (sv_2mortal (newSVpv (id, 0))); 202 PUSHs (sv_2mortal (newSVpv (id, 0)));
203 PUSHs (sv_2mortal (xfname)); 203 PUSHs (sv_2mortal (xfname));
204 PUSHs (sv_2mortal (newSViv (retrieve))); 204 PUSHs (sv_2mortal (newSViv (retrieve)));
205 205
206 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 206 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
207 207
208 if (count != 1) 208 if (count != 1)
209 croak ("filecallback perl callback must return a single return status"); 209 croak ("filecallback perl callback must return a single return status");
210 210
211 strcpy (fname, SvPV_nolen (xfname)); 211 strcpy (fname, SvPV_nolen (xfname));
212 retval = POPi; 212 retval = POPi;
213 213
214 PUTBACK; FREETMPS; LEAVE; 214 PUTBACK; FREETMPS; LEAVE;
215 215
216 } TEMP_RELEASE; 216 } TEMP_RELEASE;
217 217
218 return retval; 218 return retval;
219} 219}
221static char * 221static char *
222uu_filename_callback (void *cb, char *subject, char *filename) 222uu_filename_callback (void *cb, char *subject, char *filename)
223{ 223{
224 TEMP_ACQUIRE { 224 TEMP_ACQUIRE {
225 225
226 dSP; 226 dSP;
227 int count; 227 int count;
228 228
229 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 229 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
230 230
231 PUSHs (sv_2mortal(newSVpv(subject, 0))); 231 PUSHs (sv_2mortal(newSVpv(subject, 0)));
232 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 232 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
233 233
234 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN; 234 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
235 235
236 if (count > 1) 236 if (count > 1)
237 croak ("filenamecallback perl callback must return nothing or a single filename"); 237 croak ("filenamecallback perl callback must return nothing or a single filename");
238 238
239 if (count) 239 if (count)
240 { 240 {
241 _FP_free (filename); 241 _FP_free (filename);
242 242
243 filename = SvOK (TOPs) 243 filename = SvOK (TOPs)
244 ? _FP_strdup (SvPV_nolen (TOPs)) 244 ? _FP_strdup (SvPV_nolen (TOPs))
245 : 0; 245 : 0;
246 } 246 }
247 247
248 PUTBACK; FREETMPS; LEAVE; 248 PUTBACK; FREETMPS; LEAVE;
249 249
250 } TEMP_RELEASE; 250 } TEMP_RELEASE;
251 251
252 return filename; 252 return filename;
253} 253}
261{ 261{
262 int retval; 262 int retval;
263 263
264 TEMP_ACQUIRE { 264 TEMP_ACQUIRE {
265 265
266 dSP; 266 dSP;
267 int count; 267 int count;
268 268
269 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1); 269 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
270 270
271 PUSHs(sv_2mortal(newSVpv(info,0))); 271 PUSHs(sv_2mortal(newSVpv(info,0)));
272 272
273 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 273 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
274 274
275 if (count != 1) 275 if (count != 1)
276 croak ("info_file perl callback returned more than one argument"); 276 croak ("info_file perl callback returned more than one argument");
277 277
278 retval = POPi; 278 retval = POPi;
279 279
280 PUTBACK; FREETMPS; LEAVE; 280 PUTBACK; FREETMPS; LEAVE;
281 281
282 } TEMP_RELEASE; 282 } TEMP_RELEASE;
283 283
284 return retval; 284 return retval;
285} 285}
296 default: 296 default:
297 return 0; 297 return 0;
298 } 298 }
299} 299}
300 300
301static int uu_initialized; 301static void
302initialise (void)
303{
304 int retval = UUInitialize ();
305
306 if (retval != UURET_OK)
307 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
308}
302 309
303MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU 310MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU
304 311
305PROTOTYPES: ENABLE 312PROTOTYPES: ENABLE
306 313
307int 314int
308constant (name) 315constant (name)
309 char * name 316 char * name
310 317
311
312void
313UUInitialize ()
314 CODE:
315 if (!uu_initialized)
316 {
317 int retval;
318
319 if ((retval = UUInitialize ()) != UURET_OK)
320 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
321
322 uu_initialized = 1;
323 }
324
325void 318void
326UUCleanUp () 319UUCleanUp ()
327 CODE: 320 CODE:
328 if (uu_initialized)
329 UUCleanUp (); 321 UUCleanUp ();
330 322 initialise ();
331 uu_initialized = 0;
332 323
333SV * 324SV *
334UUGetOption (opt) 325UUGetOption (opt)
335 int opt 326 int opt
336 CODE: 327 CODE:
689 uu_msg_sv = newSVsv (&PL_sv_undef); 680 uu_msg_sv = newSVsv (&PL_sv_undef);
690 uu_busy_sv = newSVsv (&PL_sv_undef); 681 uu_busy_sv = newSVsv (&PL_sv_undef);
691 uu_file_sv = newSVsv (&PL_sv_undef); 682 uu_file_sv = newSVsv (&PL_sv_undef);
692 uu_fnamefilter_sv = newSVsv (&PL_sv_undef); 683 uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
693 uu_filename_sv = newSVsv (&PL_sv_undef); 684 uu_filename_sv = newSVsv (&PL_sv_undef);
685 initialise ();
694 686

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines