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.1 by root, Mon Jun 11 19:48:55 2001 UTC vs.
Revision 1.9 by root, Thu Nov 6 13:33:40 2003 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include "uulib/fptools.h" 5#include "uulib/fptools.h"
6#include "uulib/uulib.h" 6#include "uulib/uudeview.h"
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 on this architecture", 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 case 'A': 21 case 'A':
22 if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING; 22 if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING;
41 if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE; 41 if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE;
42 if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE; 42 if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE;
43 if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC; 43 if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC;
44 if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING; 44 if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING;
45 case 'O': 45 case 'O':
46 if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION;
47 if (strEQ(name, "OPT_FAST")) return UUOPT_FAST;
48 if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
46 if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL; 49 if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL;
47 if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG; 50 if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE;
48 if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE; 51 if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE;
49 if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
50 if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
51 if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO;
52 if (strEQ(name, "OPT_FAST")) return UUOPT_FAST;
53 if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
54 if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY; 52 if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY;
55 if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE; 53 if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE;
54 if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
55 if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
56 if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG;
57 if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO;
58 if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
59 if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT;
56 if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB; 60 if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB;
57 if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
58 if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
59 if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64; 61 if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64;
60 if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT; 62 if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
61 if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE; 63 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE;
62 if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION; 64 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
65 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
63 case 'R': 66 case 'R':
64 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 67 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
65 if (strEQ(name, "RET_CONT")) return UURET_CONT; 68 if (strEQ(name, "RET_CONT")) return UURET_CONT;
66 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 69 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
67 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 70 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
70 if (strEQ(name, "RET_NOEND")) return UURET_NOEND; 73 if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
71 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM; 74 if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
72 if (strEQ(name, "RET_OK")) return UURET_OK; 75 if (strEQ(name, "RET_OK")) return UURET_OK;
73 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP; 76 if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
74 case 'B': 77 case 'B':
75 if (strEQ(name, "B64ENCODED")) return B64ENCODED; 78 if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
76 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED; 79 if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
77 case 'P': 80 case 'P':
78 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED; 81 if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
79 case 'Q': 82 case 'Q':
80 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED; 83 if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
81 case 'U': 84 case 'U':
82 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED; 85 if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
83 case 'X': 86 case 'X':
84 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED; 87 if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
88 case 'Y':
89 if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
85 } 90 }
86 errno = EINVAL; 91 errno = EINVAL;
87 return 0; 92 return 0;
88} 93}
89 94
95static void
90static void uu_msg_callback (void *cb, char *msg, int level) 96uu_msg_callback (void *cb, char *msg, int level)
91{ 97{
92 dSP; 98 dSP;
93 99
94 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,2); 100 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,2);
95 101
98 104
99 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN; 105 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
100 PUTBACK; FREETMPS; LEAVE; 106 PUTBACK; FREETMPS; LEAVE;
101} 107}
102 108
109static int
103static int uu_busy_callback (void *cb, uuprogress *uup) 110uu_busy_callback (void *cb, uuprogress *uup)
104{ 111{
105 dSP; 112 dSP;
106 int count; 113 int count;
107 int retval; 114 int retval;
108 115
125 PUTBACK; FREETMPS; LEAVE; 132 PUTBACK; FREETMPS; LEAVE;
126 133
127 return retval; 134 return retval;
128} 135}
129 136
137static char *
130static char *uu_fnamefilter_callback (void *cb, char *fname) 138uu_fnamefilter_callback (void *cb, char *fname)
131{ 139{
132 dSP; 140 dSP;
133 int count; 141 int count;
134 static char *str; 142 static char *str;
135 143
140 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 148 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
141 149
142 if (count != 1) 150 if (count != 1)
143 croak ("fnamefilter perl callback returned more than one argument"); 151 croak ("fnamefilter perl callback returned more than one argument");
144 152
145 FP_free(str); str = FP_strdup (POPp); 153 _FP_free(str); str = _FP_strdup (POPp);
146 154
147 PUTBACK; FREETMPS; LEAVE; 155 PUTBACK; FREETMPS; LEAVE;
148 156
149 return str; 157 return str;
150} 158}
151 159
160static int
152static int uu_file_callback (void *cb, char *id, char *fname, int retrieve) 161uu_file_callback (void *cb, char *id, char *fname, int retrieve)
153{ 162{
154 dSP; 163 dSP;
155 int count; 164 int count;
156 int retval; 165 int retval;
157 SV *xfname = newSVpv ("", 0); 166 SV *xfname = newSVpv ("", 0);
175 PUTBACK; FREETMPS; LEAVE; 184 PUTBACK; FREETMPS; LEAVE;
176 185
177 return retval; 186 return retval;
178} 187}
179 188
189static char *
190uu_filename_callback (void *cb, char *subject, char *filename)
191{
192 dSP;
193 int count;
194 SV *retval;
195 STRLEN dc;
196
197 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3);
198
199 PUSHs(sv_2mortal(newSVpv(subject, 0)));
200 PUSHs(filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
201
202 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
203
204 if (count > 1)
205 croak ("filenamecallback perl callback returned more than one argument");
206
207 if (count)
208 {
209 _FP_free (filename);
210
211 retval = POPs;
212
213 if (SvOK (retval))
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 }
229
230 PUTBACK; FREETMPS; LEAVE;
231
232 return filename;
233}
234
180static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv; 235static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv;
181 236
182#define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL 237#define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL
183 238
239static int
184static int uu_info_file(void *cb, char *info) 240uu_info_file (void *cb, char *info)
185{ 241{
186 dSP; 242 dSP;
187 int count; 243 int count;
188 int retval; 244 int retval;
189 245
222MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU 278MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU
223 279
224PROTOTYPES: ENABLE 280PROTOTYPES: ENABLE
225 281
226int 282int
227constant(name) 283constant (name)
228 char * name 284 char * name
229 285
230 286
231void 287void
232UUInitialize() 288UUInitialize ()
233 CODE: 289 CODE:
234 if (!uu_initialized) 290 if (!uu_initialized)
235 { 291 {
236 int retval; 292 int retval;
237 293
240 296
241 uu_initialized = 1; 297 uu_initialized = 1;
242 } 298 }
243 299
244void 300void
245UUCleanUp() 301UUCleanUp ()
246 CODE: 302 CODE:
247 if (uu_initialized) 303 if (uu_initialized)
248 UUCleanUp (); 304 UUCleanUp ();
249 305
250 uu_initialized = 0; 306 uu_initialized = 0;
251 307
252SV * 308SV *
253UUGetOption(opt) 309UUGetOption (opt)
254 int opt 310 int opt
255 CODE: 311 CODE:
256 { 312 {
257 if (opt == UUOPT_PROGRESS) 313 if (opt == UUOPT_PROGRESS)
258 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented"); 314 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
270 } 326 }
271 OUTPUT: 327 OUTPUT:
272 RETVAL 328 RETVAL
273 329
274int 330int
275UUSetOption(opt,val) 331UUSetOption (opt, val)
276 int opt 332 int opt
277 SV * val 333 SV * val
278 CODE: 334 CODE:
279 { 335 {
280 STRLEN dc; 336 STRLEN dc;
286 } 342 }
287 OUTPUT: 343 OUTPUT:
288 RETVAL 344 RETVAL
289 345
290char * 346char *
291UUstrerror(errcode) 347UUstrerror (errcode)
292 int errcode 348 int errcode
293 349
294void 350void
295UUSetMsgCallback(func=0) 351UUSetMsgCallback (func = 0)
296 SV * func 352 SV * func
297 CODE: 353 CODE:
298 UUSetMsgCallback (FUNC_CB(uu_msg)); 354 UUSetMsgCallback (FUNC_CB(uu_msg));
299 355
300void 356void
301UUSetBusyCallback(func=0,msecs=1000) 357UUSetBusyCallback (func = 0,msecs = 1000)
302 SV * func 358 SV * func
303 long msecs 359 long msecs
304 CODE: 360 CODE:
305 UUSetBusyCallback (FUNC_CB(uu_busy), msecs); 361 UUSetBusyCallback (FUNC_CB(uu_busy), msecs);
306 362
307void 363void
308UUSetFileCallback(func=0) 364UUSetFileCallback (func = 0)
309 SV * func 365 SV * func
310 CODE: 366 CODE:
311 UUSetFileCallback (FUNC_CB(uu_file)); 367 UUSetFileCallback (FUNC_CB(uu_file));
312 368
313void 369void
314UUSetFNameFilter(func=0) 370UUSetFNameFilter (func = 0)
315 SV * func 371 SV * func
316 CODE: 372 CODE:
317 UUSetFNameFilter (FUNC_CB(uu_fnamefilter)); 373 UUSetFNameFilter (FUNC_CB(uu_fnamefilter));
318 374
375void
376UUSetFileNameCallback (func = 0)
377 SV * func
378 CODE:
379 UUSetFileNameCallback (FUNC_CB(uu_filename));
380
319char * 381char *
320UUFNameFilter(fname) 382UUFNameFilter (fname)
321 char * fname 383 char * fname
322 384
323void 385void
324UULoadFile(fname,id=0,delflag=0) 386UULoadFile (fname, id = 0, delflag = 0, int partno = -1)
325 char * fname 387 char * fname
326 char * id 388 char * id
327 int delflag 389 int delflag
328 PPCODE: 390 PPCODE:
329 { 391 {
330 int count; 392 int count;
331 393
332 XPUSHs(sv_2mortal(newSViv(UULoadFile (fname, id, delflag, &count)))); 394 XPUSHs(sv_2mortal(newSViv(UULoadFile (fname, id, delflag, partno, &count))));
333 if (GIMME_V == G_ARRAY) 395 if (GIMME_V == G_ARRAY)
334 XPUSHs(sv_2mortal(newSViv(count))); 396 XPUSHs(sv_2mortal(newSViv(count)));
335 } 397 }
336 398
337int 399int
338UUSmerge(pass) 400UUSmerge (pass)
339 int pass 401 int pass
340 402
341int 403int
342UUQuickDecode(datain,dataout,boundary,maxpos) 404UUQuickDecode(datain,dataout,boundary,maxpos)
343 FILE * datain 405 FILE * datain
413 char * from 475 char * from
414 char * subject 476 char * subject
415 int isemail 477 int isemail
416 478
417uulist * 479uulist *
418UUGetFileListItem(num) 480UUGetFileListItem (num)
419 int num 481 int num
420 482
483MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item
484
421int 485int
422UURenameFile(item,newname) 486rename (item, newname)
423 uulist *item 487 uulist *item
424 char * newname 488 char * newname
425 ALIAS: 489 CODE:
426 Convert::UUlib::Item::rename = 1 490 RETVAL = UURenameFile (item, newname);
491 OUTPUT:
492 RETVAL
427 493
428int 494int
429UUDecodeToTemp(item) 495decode_temp (item)
430 uulist *item 496 uulist *item
431 ALIAS: 497 CODE:
432 Convert::UUlib::Item::decode_temp = 1 498 RETVAL = UUDecodeToTemp (item);
499 OUTPUT:
500 RETVAL
433 501
434int 502int
435UURemoveTemp(item) 503remove_temp (item)
436 uulist *item 504 uulist *item
437 ALIAS: 505 CODE:
438 Convert::UUlib::Item::remove_temp = 1 506 RETVAL = UURemoveTemp (item);
507 OUTPUT:
508 RETVAL
439 509
440int 510int
441UUDecodeFile(item,target=0) 511decode (item, target = 0)
442 uulist *item 512 uulist *item
443 char * target 513 char * target
444 ALIAS: 514 CODE:
445 Convert::UUlib::Item::decode = 1 515 RETVAL = UUDecodeFile (item, target);
516 OUTPUT:
517 RETVAL
446 518
447void 519void
448UUInfoFile(item,func) 520info (item, func)
449 uulist *item 521 uulist *item
450 SV * func 522 SV * func
451 CODE: 523 CODE:
452 UUInfoFile(item,(void *)func,uu_info_file); 524 UUInfoFile (item,(void *)func, uu_info_file);
453 ALIAS:
454 Convert::UUlib::Item::info = 1
455
456MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item
457 525
458short 526short
459state(li) 527state(li)
460 uulist *li 528 uulist *li
461 CODE: 529 CODE:
489 RETVAL = li->size; 557 RETVAL = li->size;
490 OUTPUT: 558 OUTPUT:
491 RETVAL 559 RETVAL
492 560
493char * 561char *
494filename(li,newfilename=0) 562filename (li, newfilename = 0)
495 uulist *li 563 uulist *li
496 char * newfilename 564 char * newfilename
497 CODE: 565 CODE:
498 if (newfilename) 566 if (newfilename)
499 { 567 {
500 FP_free (li->filename); 568 _FP_free (li->filename);
501 li->filename = FP_strdup (newfilename); 569 li->filename = _FP_strdup (newfilename);
502 } 570 }
503 RETVAL = li->filename; 571 RETVAL = li->filename;
504 OUTPUT: 572 OUTPUT:
505 RETVAL 573 RETVAL
506 574
507char * 575char *
508subfname(li) 576subfname (li)
509 uulist *li 577 uulist *li
510 CODE: 578 CODE:
511 RETVAL = li->subfname; 579 RETVAL = li->subfname;
512 OUTPUT: 580 OUTPUT:
513 RETVAL 581 RETVAL
514 582
515char * 583char *
516mimeid(li) 584mimeid (li)
517 uulist *li 585 uulist *li
518 CODE: 586 CODE:
519 RETVAL = li->mimeid; 587 RETVAL = li->mimeid;
520 OUTPUT: 588 OUTPUT:
521 RETVAL 589 RETVAL
522 590
523char * 591char *
524mimetype(li) 592mimetype (li)
525 uulist *li 593 uulist *li
526 CODE: 594 CODE:
527 RETVAL = li->mimetype; 595 RETVAL = li->mimetype;
528 OUTPUT: 596 OUTPUT:
529 RETVAL 597 RETVAL
530 598
531char * 599char *
532binfile(li) 600binfile (li)
533 uulist *li 601 uulist *li
534 CODE: 602 CODE:
535 RETVAL = li->binfile; 603 RETVAL = li->binfile;
536 OUTPUT: 604 OUTPUT:
537 RETVAL 605 RETVAL
538 606
539# functions accessing internal data(!) 607# methods accessing internal data(!)
540 608
541void 609void
542parts(li) 610parts (li)
543 uulist *li 611 uulist *li
544 PPCODE: 612 PPCODE:
545 { 613 {
546 struct _uufile *p = li->thisfile; 614 struct _uufile *p = li->thisfile;
547 615
571 p = p->NEXT; 639 p = p->NEXT;
572 } 640 }
573 } 641 }
574 642
575BOOT: 643BOOT:
576uu_msg_sv = newSVsv(&PL_sv_undef); 644 uu_msg_sv = newSVsv(&PL_sv_undef);
577uu_busy_sv = newSVsv(&PL_sv_undef); 645 uu_busy_sv = newSVsv(&PL_sv_undef);
578uu_file_sv = newSVsv(&PL_sv_undef); 646 uu_file_sv = newSVsv(&PL_sv_undef);
579uu_fnamefilter_sv = newSVsv(&PL_sv_undef); 647 uu_fnamefilter_sv = newSVsv(&PL_sv_undef);
648 uu_filename_sv = newSVsv(&PL_sv_undef);
580 649

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines