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.12 by root, Mon May 2 19:58:40 2005 UTC vs.
Revision 1.13 by root, Sat May 26 15:14:10 2007 UTC

7#include "uulib/uuint.h" 7#include "uulib/uuint.h"
8 8
9static int 9static int
10not_here (char *s) 10not_here (char *s)
11{ 11{
12 croak("%s not implemented", s); 12 croak("%s not implemented", s);
13 return -1; 13 return -1;
14} 14}
15 15
16static int 16static int
17constant (char *name) 17constant (char *name)
18{ 18{
19 errno = 0; 19 errno = 0;
20 switch (*name) { 20 switch (*name)
21 {
21 case 'A': 22 case 'A':
22 if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING; 23 if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING;
23 if (strEQ(name, "ACT_DECODING")) return UUACT_DECODING; 24 if (strEQ(name, "ACT_DECODING")) return UUACT_DECODING;
24 if (strEQ(name, "ACT_ENCODING")) return UUACT_ENCODING; 25 if (strEQ(name, "ACT_ENCODING")) return UUACT_ENCODING;
25 if (strEQ(name, "ACT_IDLE")) return UUACT_IDLE; 26 if (strEQ(name, "ACT_IDLE")) return UUACT_IDLE;
26 if (strEQ(name, "ACT_SCANNING")) return UUACT_SCANNING; 27 if (strEQ(name, "ACT_SCANNING")) return UUACT_SCANNING;
27 case 'F': 28 case 'F':
28 if (strEQ(name, "FILE_DECODED")) return UUFILE_DECODED; 29 if (strEQ(name, "FILE_DECODED")) return UUFILE_DECODED;
29 if (strEQ(name, "FILE_ERROR")) return UUFILE_ERROR; 30 if (strEQ(name, "FILE_ERROR")) return UUFILE_ERROR;
30 if (strEQ(name, "FILE_MISPART")) return UUFILE_MISPART; 31 if (strEQ(name, "FILE_MISPART")) return UUFILE_MISPART;
31 if (strEQ(name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN; 32 if (strEQ(name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN;
32 if (strEQ(name, "FILE_NODATA")) return UUFILE_NODATA; 33 if (strEQ(name, "FILE_NODATA")) return UUFILE_NODATA;
33 if (strEQ(name, "FILE_NOEND")) return UUFILE_NOEND; 34 if (strEQ(name, "FILE_NOEND")) return UUFILE_NOEND;
34 if (strEQ(name, "FILE_OK")) return UUFILE_OK; 35 if (strEQ(name, "FILE_OK")) return UUFILE_OK;
35 if (strEQ(name, "FILE_READ")) return UUFILE_READ; 36 if (strEQ(name, "FILE_READ")) return UUFILE_READ;
36 if (strEQ(name, "FILE_TMPFILE")) return UUFILE_TMPFILE; 37 if (strEQ(name, "FILE_TMPFILE")) return UUFILE_TMPFILE;
37 break; 38 break;
38 case 'M': 39 case 'M':
39 if (strEQ(name, "MSG_ERROR")) return UUMSG_ERROR; 40 if (strEQ(name, "MSG_ERROR")) return UUMSG_ERROR;
40 if (strEQ(name, "MSG_FATAL")) return UUMSG_FATAL; 41 if (strEQ(name, "MSG_FATAL")) return UUMSG_FATAL;
41 if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE; 42 if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE;
42 if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE; 43 if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE;
43 if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC; 44 if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC;
44 if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING; 45 if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING;
45 case 'O': 46 case 'O':
46 if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION; 47 if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION;
47 if (strEQ(name, "OPT_FAST")) return UUOPT_FAST; 48 if (strEQ(name, "OPT_FAST")) return UUOPT_FAST;
48 if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS; 49 if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
49 if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL; 50 if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL;
50 if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE; 51 if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE;
51 if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE; 52 if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE;
52 if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY; 53 if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY;
53 if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE; 54 if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE;
54 if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH; 55 if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
55 if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE; 56 if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
56 if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG; 57 if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG;
57 if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO; 58 if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO;
58 if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS; 59 if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
59 if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT; 60 if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT;
60 if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB; 61 if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB;
61 if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64; 62 if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64;
62 if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT; 63 if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
63 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE; 64 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE;
64 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME; 65 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
65 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT; 66 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
66 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF; 67 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF;
67 if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF; 68 if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF;
68 case 'R': 69 case 'R':
69 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 70 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
70 if (strEQ(name, "RET_CONT")) return UURET_CONT; 71 if (strEQ(name, "RET_CONT")) return UURET_CONT;
71 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 72 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
72 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 73 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
73 if (strEQ(name, "RET_IOERR")) return UURET_IOERR; 74 if (strEQ(name, "RET_IOERR")) return UURET_IOERR;
74 if (strEQ(name, "RET_NODATA")) return UURET_NODATA; 75 if (strEQ(name, "RET_NODATA")) return UURET_NODATA;
75 if (strEQ(name, "RET_NOEND")) return UURET_NOEND; 76 if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
76 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM; 77 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
77 if (strEQ(name, "RET_OK")) return UURET_OK; 78 if (strEQ(name, "RET_OK")) return UURET_OK;
78 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP; 79 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
79 case 'B': 80 case 'B':
80 if (strEQ(name, "B64_ENCODED")) return B64ENCODED; 81 if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
81 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED; 82 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
82 case 'P': 83 case 'P':
83 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED; 84 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
84 case 'Q': 85 case 'Q':
85 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED; 86 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
86 case 'U': 87 case 'U':
87 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED; 88 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
88 case 'X': 89 case 'X':
89 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED; 90 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
90 case 'Y': 91 case 'Y':
91 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED; 92 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
92 } 93 }
94
93 errno = EINVAL; 95 errno = EINVAL;
94 return 0; 96 return 0;
95} 97}
96 98
97static void 99static void
98uu_msg_callback (void *cb, char *msg, int level) 100uu_msg_callback (void *cb, char *msg, int level)
99{ 101{
148 PUSHs (sv_2mortal (newSVpv (fname, 0))); 150 PUSHs (sv_2mortal (newSVpv (fname, 0)));
149 151
150 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 152 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
151 153
152 if (count != 1) 154 if (count != 1)
153 croak ("fnamefilter perl callback returned more than one argument"); 155 croak ("fnamefilter perl callback MUST return a single filename exactly");
154 156
155 _FP_free(str); str = _FP_strdup (POPp); 157 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
156 158
157 PUTBACK; FREETMPS; LEAVE; 159 PUTBACK; FREETMPS; LEAVE;
158 160
159 return str; 161 return str;
160} 162}
164{ 166{
165 dSP; 167 dSP;
166 int count; 168 int count;
167 int retval; 169 int retval;
168 SV *xfname = newSVpv ("", 0); 170 SV *xfname = newSVpv ("", 0);
169 STRLEN dc;
170 171
171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3); 172 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
172 173
173 PUSHs (sv_2mortal (newSVpv (id, 0))); 174 PUSHs (sv_2mortal (newSVpv (id, 0)));
174 PUSHs (sv_2mortal (xfname)); 175 PUSHs (sv_2mortal (xfname));
175 PUSHs (sv_2mortal (newSViv (retrieve))); 176 PUSHs (sv_2mortal (newSViv (retrieve)));
176 177
177 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 178 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
178 179
179 if (count != 1) 180 if (count != 1)
180 croak ("filecallback perl callback returned more than one argument"); 181 croak ("filecallback perl callback must return a single return status");
181 182
182 strcpy (fname, SvPV (xfname, dc)); 183 strcpy (fname, SvPV_nolen (xfname));
183
184 retval = POPi; 184 retval = POPi;
185 185
186 PUTBACK; FREETMPS; LEAVE; 186 PUTBACK; FREETMPS; LEAVE;
187 187
188 return retval; 188 return retval;
191static char * 191static char *
192uu_filename_callback (void *cb, char *subject, char *filename) 192uu_filename_callback (void *cb, char *subject, char *filename)
193{ 193{
194 dSP; 194 dSP;
195 int count; 195 int count;
196 SV *retval;
197 STRLEN dc;
198 196
199 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3); 197 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
200 198
201 PUSHs(sv_2mortal(newSVpv(subject, 0))); 199 PUSHs (sv_2mortal(newSVpv(subject, 0)));
202 PUSHs(filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 200 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
203 201
204 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN; 202 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
205 203
206 if (count > 1) 204 if (count > 1)
207 croak ("filenamecallback perl callback returned more than one argument"); 205 croak ("filenamecallback perl callback must return nothing or a single filename");
208 206
209 if (count) 207 if (count)
210 { 208 {
211 _FP_free (filename); 209 _FP_free (filename);
212 210
213 retval = POPs; 211 filename = SvOK (TOPs)
214 212 ? _FP_strdup (SvPV_nolen (TOPs))
215 if (SvOK (retval)) 213 : 0;
216 {
217 STRLEN len;
218 char *fn = SvPV (retval, len);
219
220 filename = malloc (len + 1);
221
222 if (filename)
223 {
224 memcpy (filename, fn, len);
225 filename[len] = 0;
226 }
227 }
228 else
229 filename = 0;
230 } 214 }
231 215
232 PUTBACK; FREETMPS; LEAVE; 216 PUTBACK; FREETMPS; LEAVE;
233 217
234 return filename; 218 return filename;
351 335
352void 336void
353UUSetMsgCallback (func = 0) 337UUSetMsgCallback (func = 0)
354 SV * func 338 SV * func
355 CODE: 339 CODE:
356 UUSetMsgCallback (FUNC_CB(uu_msg)); 340 UUSetMsgCallback (FUNC_CB (uu_msg));
357 341
358void 342void
359UUSetBusyCallback (func = 0,msecs = 1000) 343UUSetBusyCallback (func = 0,msecs = 1000)
360 SV * func 344 SV * func
361 long msecs 345 long msecs
362 CODE: 346 CODE:
363 UUSetBusyCallback (FUNC_CB(uu_busy), msecs); 347 UUSetBusyCallback (FUNC_CB (uu_busy), msecs);
364 348
365void 349void
366UUSetFileCallback (func = 0) 350UUSetFileCallback (func = 0)
367 SV * func 351 SV * func
368 CODE: 352 CODE:
369 UUSetFileCallback (FUNC_CB(uu_file)); 353 UUSetFileCallback (FUNC_CB (uu_file));
370 354
371void 355void
372UUSetFNameFilter (func = 0) 356UUSetFNameFilter (func = 0)
373 SV * func 357 SV * func
374 CODE: 358 CODE:
375 UUSetFNameFilter (FUNC_CB(uu_fnamefilter)); 359 UUSetFNameFilter (FUNC_CB (uu_fnamefilter));
376 360
377void 361void
378UUSetFileNameCallback (func = 0) 362UUSetFileNameCallback (func = 0)
379 SV * func 363 SV * func
380 CODE: 364 CODE:
381 UUSetFileNameCallback (FUNC_CB(uu_filename)); 365 UUSetFileNameCallback (FUNC_CB (uu_filename));
382 366
383char * 367char *
384UUFNameFilter (fname) 368UUFNameFilter (fname)
385 char * fname 369 char * fname
386 370
642 p = p->NEXT; 626 p = p->NEXT;
643 } 627 }
644 } 628 }
645 629
646BOOT: 630BOOT:
647 uu_msg_sv = newSVsv(&PL_sv_undef); 631 uu_msg_sv = newSVsv (&PL_sv_undef);
648 uu_busy_sv = newSVsv(&PL_sv_undef); 632 uu_busy_sv = newSVsv (&PL_sv_undef);
649 uu_file_sv = newSVsv(&PL_sv_undef); 633 uu_file_sv = newSVsv (&PL_sv_undef);
650 uu_fnamefilter_sv = newSVsv(&PL_sv_undef); 634 uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
651 uu_filename_sv = newSVsv(&PL_sv_undef); 635 uu_filename_sv = newSVsv (&PL_sv_undef);
652 636

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines