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.15 by root, Mon Aug 24 06:15:00 2009 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;
69 if (strEQ(name, "OPT_AUTOCHECK")) return UUOPT_AUTOCHECK;
68 case 'R': 70 case 'R':
69 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 71 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
70 if (strEQ(name, "RET_CONT")) return UURET_CONT; 72 if (strEQ(name, "RET_CONT")) return UURET_CONT;
71 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 73 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
72 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 74 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
73 if (strEQ(name, "RET_IOERR")) return UURET_IOERR; 75 if (strEQ(name, "RET_IOERR")) return UURET_IOERR;
74 if (strEQ(name, "RET_NODATA")) return UURET_NODATA; 76 if (strEQ(name, "RET_NODATA")) return UURET_NODATA;
75 if (strEQ(name, "RET_NOEND")) return UURET_NOEND; 77 if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
76 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM; 78 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
77 if (strEQ(name, "RET_OK")) return UURET_OK; 79 if (strEQ(name, "RET_OK")) return UURET_OK;
78 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP; 80 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
79 case 'B': 81 case 'B':
80 if (strEQ(name, "B64_ENCODED")) return B64ENCODED; 82 if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
81 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED; 83 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
82 case 'P': 84 case 'P':
83 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED; 85 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
84 case 'Q': 86 case 'Q':
85 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED; 87 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
86 case 'U': 88 case 'U':
87 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED; 89 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
88 case 'X': 90 case 'X':
89 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED; 91 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
90 case 'Y': 92 case 'Y':
91 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED; 93 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
92 } 94 }
95
93 errno = EINVAL; 96 errno = EINVAL;
94 return 0; 97 return 0;
95} 98}
96 99
97static void 100static void
98uu_msg_callback (void *cb, char *msg, int level) 101uu_msg_callback (void *cb, char *msg, int level)
99{ 102{
148 PUSHs (sv_2mortal (newSVpv (fname, 0))); 151 PUSHs (sv_2mortal (newSVpv (fname, 0)));
149 152
150 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 153 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
151 154
152 if (count != 1) 155 if (count != 1)
153 croak ("fnamefilter perl callback returned more than one argument"); 156 croak ("fnamefilter perl callback MUST return a single filename exactly");
154 157
155 _FP_free(str); str = _FP_strdup (POPp); 158 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
156 159
157 PUTBACK; FREETMPS; LEAVE; 160 PUTBACK; FREETMPS; LEAVE;
158 161
159 return str; 162 return str;
160} 163}
164{ 167{
165 dSP; 168 dSP;
166 int count; 169 int count;
167 int retval; 170 int retval;
168 SV *xfname = newSVpv ("", 0); 171 SV *xfname = newSVpv ("", 0);
169 STRLEN dc;
170 172
171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3); 173 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
172 174
173 PUSHs (sv_2mortal (newSVpv (id, 0))); 175 PUSHs (sv_2mortal (newSVpv (id, 0)));
174 PUSHs (sv_2mortal (xfname)); 176 PUSHs (sv_2mortal (xfname));
175 PUSHs (sv_2mortal (newSViv (retrieve))); 177 PUSHs (sv_2mortal (newSViv (retrieve)));
176 178
177 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 179 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
178 180
179 if (count != 1) 181 if (count != 1)
180 croak ("filecallback perl callback returned more than one argument"); 182 croak ("filecallback perl callback must return a single return status");
181 183
182 strcpy (fname, SvPV (xfname, dc)); 184 strcpy (fname, SvPV_nolen (xfname));
183
184 retval = POPi; 185 retval = POPi;
185 186
186 PUTBACK; FREETMPS; LEAVE; 187 PUTBACK; FREETMPS; LEAVE;
187 188
188 return retval; 189 return retval;
191static char * 192static char *
192uu_filename_callback (void *cb, char *subject, char *filename) 193uu_filename_callback (void *cb, char *subject, char *filename)
193{ 194{
194 dSP; 195 dSP;
195 int count; 196 int count;
196 SV *retval;
197 STRLEN dc;
198 197
199 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3); 198 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
200 199
201 PUSHs(sv_2mortal(newSVpv(subject, 0))); 200 PUSHs (sv_2mortal(newSVpv(subject, 0)));
202 PUSHs(filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 201 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
203 202
204 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN; 203 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
205 204
206 if (count > 1) 205 if (count > 1)
207 croak ("filenamecallback perl callback returned more than one argument"); 206 croak ("filenamecallback perl callback must return nothing or a single filename");
208 207
209 if (count) 208 if (count)
210 { 209 {
211 _FP_free (filename); 210 _FP_free (filename);
212 211
213 retval = POPs; 212 filename = SvOK (TOPs)
214 213 ? _FP_strdup (SvPV_nolen (TOPs))
215 if (SvOK (retval)) 214 : 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 } 215 }
231 216
232 PUTBACK; FREETMPS; LEAVE; 217 PUTBACK; FREETMPS; LEAVE;
233 218
234 return filename; 219 return filename;
351 336
352void 337void
353UUSetMsgCallback (func = 0) 338UUSetMsgCallback (func = 0)
354 SV * func 339 SV * func
355 CODE: 340 CODE:
356 UUSetMsgCallback (FUNC_CB(uu_msg)); 341 UUSetMsgCallback (FUNC_CB (uu_msg));
357 342
358void 343void
359UUSetBusyCallback (func = 0,msecs = 1000) 344UUSetBusyCallback (func = 0,msecs = 1000)
360 SV * func 345 SV * func
361 long msecs 346 long msecs
362 CODE: 347 CODE:
363 UUSetBusyCallback (FUNC_CB(uu_busy), msecs); 348 UUSetBusyCallback (FUNC_CB (uu_busy), msecs);
364 349
365void 350void
366UUSetFileCallback (func = 0) 351UUSetFileCallback (func = 0)
367 SV * func 352 SV * func
368 CODE: 353 CODE:
369 UUSetFileCallback (FUNC_CB(uu_file)); 354 UUSetFileCallback (FUNC_CB (uu_file));
370 355
371void 356void
372UUSetFNameFilter (func = 0) 357UUSetFNameFilter (func = 0)
373 SV * func 358 SV * func
374 CODE: 359 CODE:
375 UUSetFNameFilter (FUNC_CB(uu_fnamefilter)); 360 UUSetFNameFilter (FUNC_CB (uu_fnamefilter));
376 361
377void 362void
378UUSetFileNameCallback (func = 0) 363UUSetFileNameCallback (func = 0)
379 SV * func 364 SV * func
380 CODE: 365 CODE:
381 UUSetFileNameCallback (FUNC_CB(uu_filename)); 366 UUSetFileNameCallback (FUNC_CB (uu_filename));
382 367
383char * 368char *
384UUFNameFilter (fname) 369UUFNameFilter (fname)
385 char * fname 370 char * fname
386 371
642 p = p->NEXT; 627 p = p->NEXT;
643 } 628 }
644 } 629 }
645 630
646BOOT: 631BOOT:
647 uu_msg_sv = newSVsv(&PL_sv_undef); 632 uu_msg_sv = newSVsv (&PL_sv_undef);
648 uu_busy_sv = newSVsv(&PL_sv_undef); 633 uu_busy_sv = newSVsv (&PL_sv_undef);
649 uu_file_sv = newSVsv(&PL_sv_undef); 634 uu_file_sv = newSVsv (&PL_sv_undef);
650 uu_fnamefilter_sv = newSVsv(&PL_sv_undef); 635 uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
651 uu_filename_sv = newSVsv(&PL_sv_undef); 636 uu_filename_sv = newSVsv (&PL_sv_undef);
652 637

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines