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.8 by root, Tue Oct 15 23:20:30 2002 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;
67 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF;
68 if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF;
69 if (strEQ(name, "OPT_AUTOCHECK")) return UUOPT_AUTOCHECK;
66 case 'R': 70 case 'R':
67 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 71 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
68 if (strEQ(name, "RET_CONT")) return UURET_CONT; 72 if (strEQ(name, "RET_CONT")) return UURET_CONT;
69 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 73 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
70 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 74 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
71 if (strEQ(name, "RET_IOERR")) return UURET_IOERR; 75 if (strEQ(name, "RET_IOERR")) return UURET_IOERR;
72 if (strEQ(name, "RET_NODATA")) return UURET_NODATA; 76 if (strEQ(name, "RET_NODATA")) return UURET_NODATA;
73 if (strEQ(name, "RET_NOEND")) return UURET_NOEND; 77 if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
74 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM; 78 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
75 if (strEQ(name, "RET_OK")) return UURET_OK; 79 if (strEQ(name, "RET_OK")) return UURET_OK;
76 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP; 80 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
77 case 'B': 81 case 'B':
78 if (strEQ(name, "B64_ENCODED")) return B64ENCODED; 82 if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
79 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED; 83 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
80 case 'P': 84 case 'P':
81 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED; 85 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
82 case 'Q': 86 case 'Q':
83 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED; 87 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
84 case 'U': 88 case 'U':
85 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED; 89 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
86 case 'X': 90 case 'X':
87 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED; 91 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
88 case 'Y': 92 case 'Y':
89 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED; 93 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
90 } 94 }
95
91 errno = EINVAL; 96 errno = EINVAL;
92 return 0; 97 return 0;
93} 98}
94 99
95static void 100static void
96uu_msg_callback (void *cb, char *msg, int level) 101uu_msg_callback (void *cb, char *msg, int level)
97{ 102{
98 dSP; 103 dSP;
99 104
100 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,2); 105 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
101 106
102 PUSHs(sv_2mortal(newSVpv(msg,0))); 107 PUSHs (sv_2mortal (newSVpv (msg, 0)));
103 PUSHs(sv_2mortal(newSViv(level))); 108 PUSHs (sv_2mortal (newSViv (level)));
104 109
105 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN; 110 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
106 PUTBACK; FREETMPS; LEAVE; 111 PUTBACK; FREETMPS; LEAVE;
107} 112}
108 113
111{ 116{
112 dSP; 117 dSP;
113 int count; 118 int count;
114 int retval; 119 int retval;
115 120
116 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,6); 121 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
117 122
118 PUSHs(sv_2mortal(newSViv(uup->action))); 123 PUSHs (sv_2mortal (newSViv (uup->action)));
119 PUSHs(sv_2mortal(newSVpv(uup->curfile,0))); 124 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
120 PUSHs(sv_2mortal(newSViv(uup->partno))); 125 PUSHs (sv_2mortal (newSViv (uup->partno)));
121 PUSHs(sv_2mortal(newSViv(uup->numparts))); 126 PUSHs (sv_2mortal (newSViv (uup->numparts)));
122 PUSHs(sv_2mortal(newSViv(uup->fsize))); 127 PUSHs (sv_2mortal (newSViv (uup->fsize)));
123 PUSHs(sv_2mortal(newSViv(uup->percent))); 128 PUSHs (sv_2mortal (newSViv (uup->percent)));
124 129
125 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 130 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
126 131
127 if (count != 1) 132 if (count != 1)
128 croak ("busycallback perl callback returned more than one argument"); 133 croak ("busycallback perl callback returned more than one argument");
139{ 144{
140 dSP; 145 dSP;
141 int count; 146 int count;
142 static char *str; 147 static char *str;
143 148
144 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1); 149 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
145 150
146 PUSHs(sv_2mortal(newSVpv(fname,0))); 151 PUSHs (sv_2mortal (newSVpv (fname, 0)));
147 152
148 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 153 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
149 154
150 if (count != 1) 155 if (count != 1)
151 croak ("fnamefilter perl callback returned more than one argument"); 156 croak ("fnamefilter perl callback MUST return a single filename exactly");
152 157
153 _FP_free(str); str = _FP_strdup (POPp); 158 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
154 159
155 PUTBACK; FREETMPS; LEAVE; 160 PUTBACK; FREETMPS; LEAVE;
156 161
157 return str; 162 return str;
158} 163}
162{ 167{
163 dSP; 168 dSP;
164 int count; 169 int count;
165 int retval; 170 int retval;
166 SV *xfname = newSVpv ("", 0); 171 SV *xfname = newSVpv ("", 0);
167 STRLEN dc;
168 172
169 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3); 173 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
170 174
171 PUSHs(sv_2mortal(newSVpv(id,0))); 175 PUSHs (sv_2mortal (newSVpv (id, 0)));
172 PUSHs(sv_2mortal(xfname)); 176 PUSHs (sv_2mortal (xfname));
173 PUSHs(sv_2mortal(newSViv(retrieve))); 177 PUSHs (sv_2mortal (newSViv (retrieve)));
174 178
175 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 179 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
176 180
177 if (count != 1) 181 if (count != 1)
178 croak ("filecallback perl callback returned more than one argument"); 182 croak ("filecallback perl callback must return a single return status");
179 183
180 strcpy (fname, SvPV (xfname, dc)); 184 strcpy (fname, SvPV_nolen (xfname));
181
182 retval = POPi; 185 retval = POPi;
183 186
184 PUTBACK; FREETMPS; LEAVE; 187 PUTBACK; FREETMPS; LEAVE;
185 188
186 return retval; 189 return retval;
189static char * 192static char *
190uu_filename_callback (void *cb, char *subject, char *filename) 193uu_filename_callback (void *cb, char *subject, char *filename)
191{ 194{
192 dSP; 195 dSP;
193 int count; 196 int count;
194 SV *retval;
195 STRLEN dc;
196 197
197 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3); 198 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
198 199
199 PUSHs(sv_2mortal(newSVpv(subject, 0))); 200 PUSHs (sv_2mortal(newSVpv(subject, 0)));
200 PUSHs(filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 201 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
201 202
202 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN; 203 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
203 204
204 if (count > 1) 205 if (count > 1)
205 croak ("filenamecallback perl callback returned more than one argument"); 206 croak ("filenamecallback perl callback must return nothing or a single filename");
206 207
207 if (count) 208 if (count)
208 { 209 {
209 _FP_free (filename); 210 _FP_free (filename);
210 211
211 retval = POPs; 212 filename = SvOK (TOPs)
212 213 ? _FP_strdup (SvPV_nolen (TOPs))
213 if (SvOK (retval)) 214 : 0;
214 {
215 STRLEN len;
216 char *fn = SvPV (retval, len);
217
218 filename = malloc (len + 1);
219
220 if (filename)
221 {
222 memcpy (filename, fn, len);
223 filename[len] = 0;
224 }
225 }
226 else
227 filename = 0;
228 } 215 }
229 216
230 PUTBACK; FREETMPS; LEAVE; 217 PUTBACK; FREETMPS; LEAVE;
231 218
232 return filename; 219 return filename;
349 336
350void 337void
351UUSetMsgCallback (func = 0) 338UUSetMsgCallback (func = 0)
352 SV * func 339 SV * func
353 CODE: 340 CODE:
354 UUSetMsgCallback (FUNC_CB(uu_msg)); 341 UUSetMsgCallback (FUNC_CB (uu_msg));
355 342
356void 343void
357UUSetBusyCallback (func = 0,msecs = 1000) 344UUSetBusyCallback (func = 0,msecs = 1000)
358 SV * func 345 SV * func
359 long msecs 346 long msecs
360 CODE: 347 CODE:
361 UUSetBusyCallback (FUNC_CB(uu_busy), msecs); 348 UUSetBusyCallback (FUNC_CB (uu_busy), msecs);
362 349
363void 350void
364UUSetFileCallback (func = 0) 351UUSetFileCallback (func = 0)
365 SV * func 352 SV * func
366 CODE: 353 CODE:
367 UUSetFileCallback (FUNC_CB(uu_file)); 354 UUSetFileCallback (FUNC_CB (uu_file));
368 355
369void 356void
370UUSetFNameFilter (func = 0) 357UUSetFNameFilter (func = 0)
371 SV * func 358 SV * func
372 CODE: 359 CODE:
373 UUSetFNameFilter (FUNC_CB(uu_fnamefilter)); 360 UUSetFNameFilter (FUNC_CB (uu_fnamefilter));
374 361
375void 362void
376UUSetFileNameCallback (func = 0) 363UUSetFileNameCallback (func = 0)
377 SV * func 364 SV * func
378 CODE: 365 CODE:
379 UUSetFileNameCallback (FUNC_CB(uu_filename)); 366 UUSetFileNameCallback (FUNC_CB (uu_filename));
380 367
381char * 368char *
382UUFNameFilter (fname) 369UUFNameFilter (fname)
383 char * fname 370 char * fname
384 371
385void 372void
386UULoadFile (fname, id = 0, delflag = 0) 373UULoadFile (fname, id = 0, delflag = 0, partno = -1)
387 char * fname 374 char * fname
388 char * id 375 char * id
389 int delflag 376 int delflag
377 int partno
390 PPCODE: 378 PPCODE:
391 { 379 {
392 int count; 380 int count;
393 381
394 XPUSHs(sv_2mortal(newSViv(UULoadFile (fname, id, delflag, &count)))); 382 XPUSHs (sv_2mortal (newSViv (UULoadFileWithPartNo (fname, id, delflag, partno, &count))));
395 if (GIMME_V == G_ARRAY) 383 if (GIMME_V == G_ARRAY)
396 XPUSHs(sv_2mortal(newSViv(count))); 384 XPUSHs (sv_2mortal (newSViv (count)));
397 } 385 }
398 386
399int 387int
400UUSmerge (pass) 388UUSmerge (pass)
401 int pass 389 int pass
639 p = p->NEXT; 627 p = p->NEXT;
640 } 628 }
641 } 629 }
642 630
643BOOT: 631BOOT:
644 uu_msg_sv = newSVsv(&PL_sv_undef); 632 uu_msg_sv = newSVsv (&PL_sv_undef);
645 uu_busy_sv = newSVsv(&PL_sv_undef); 633 uu_busy_sv = newSVsv (&PL_sv_undef);
646 uu_file_sv = newSVsv(&PL_sv_undef); 634 uu_file_sv = newSVsv (&PL_sv_undef);
647 uu_fnamefilter_sv = newSVsv(&PL_sv_undef); 635 uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
648 uu_filename_sv = newSVsv(&PL_sv_undef); 636 uu_filename_sv = newSVsv (&PL_sv_undef);
649 637

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines