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.13 by root, Sat May 26 15:14:10 2007 UTC vs.
Revision 1.17 by root, Fri Feb 28 06:57:25 2020 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 "perlmulticore.h"
6
5#include "uulib/fptools.h" 7#include "uulib/fptools.h"
6#include "uulib/uudeview.h" 8#include "uulib/uudeview.h"
7#include "uulib/uuint.h" 9#include "uulib/uuint.h"
10
11static int released;
12
13#define RELEASE do { released = 1; perlinterp_release (); } while (0)
14#define ACQUIRE do { perlinterp_acquire (); released = 0; } while (0)
15
16#define TEMP_ACQUIRE if (released) perlinterp_acquire ();
17#define TEMP_RELEASE if (released) perlinterp_release ();
8 18
9static int 19static int
10not_here (char *s) 20not_here (char *s)
11{ 21{
12 croak("%s not implemented", s); 22 croak("%s not implemented", s);
64 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE; 74 if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE;
65 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME; 75 if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
66 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT; 76 if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
67 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF; 77 if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF;
68 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;
69 case 'R': 80 case 'R':
70 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL; 81 if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
71 if (strEQ(name, "RET_CONT")) return UURET_CONT; 82 if (strEQ(name, "RET_CONT")) return UURET_CONT;
72 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS; 83 if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
73 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL; 84 if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
97} 108}
98 109
99static void 110static void
100uu_msg_callback (void *cb, char *msg, int level) 111uu_msg_callback (void *cb, char *msg, int level)
101{ 112{
113 TEMP_ACQUIRE {
114
102 dSP; 115 dSP;
103 116
104 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 117 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
105 118
106 PUSHs (sv_2mortal (newSVpv (msg, 0))); 119 PUSHs (sv_2mortal (newSVpv (msg, 0)));
107 PUSHs (sv_2mortal (newSViv (level))); 120 PUSHs (sv_2mortal (newSViv (level)));
108 121
109 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;
110 PUTBACK; FREETMPS; LEAVE; 123 PUTBACK; FREETMPS; LEAVE;
124
125 } TEMP_RELEASE;
111} 126}
112 127
113static int 128static int
114uu_busy_callback (void *cb, uuprogress *uup) 129uu_busy_callback (void *cb, uuprogress *uup)
115{ 130{
131 int retval;
132
133 TEMP_ACQUIRE {
134
116 dSP; 135 dSP;
117 int count; 136 int count;
118 int retval; 137
119
120 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6); 138 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
121 139
122 PUSHs (sv_2mortal (newSViv (uup->action))); 140 PUSHs (sv_2mortal (newSViv (uup->action)));
123 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0))); 141 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
124 PUSHs (sv_2mortal (newSViv (uup->partno))); 142 PUSHs (sv_2mortal (newSViv (uup->partno)));
133 151
134 retval = POPi; 152 retval = POPi;
135 153
136 PUTBACK; FREETMPS; LEAVE; 154 PUTBACK; FREETMPS; LEAVE;
137 155
156 } TEMP_RELEASE;
157
138 return retval; 158 return retval;
139} 159}
140 160
141static char * 161static char *
142uu_fnamefilter_callback (void *cb, char *fname) 162uu_fnamefilter_callback (void *cb, char *fname)
143{ 163{
164 static char *str;
165
166 TEMP_ACQUIRE {
167
144 dSP; 168 dSP;
145 int count; 169 int count;
146 static char *str; 170
147
148 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1); 171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
149 172
150 PUSHs (sv_2mortal (newSVpv (fname, 0))); 173 PUSHs (sv_2mortal (newSVpv (fname, 0)));
151 174
152 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 175 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
156 179
157 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs)); 180 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
158 181
159 PUTBACK; FREETMPS; LEAVE; 182 PUTBACK; FREETMPS; LEAVE;
160 183
184 } TEMP_RELEASE;
185
161 return str; 186 return str;
162} 187}
163 188
164static int 189static int
165uu_file_callback (void *cb, char *id, char *fname, int retrieve) 190uu_file_callback (void *cb, char *id, char *fname, int retrieve)
166{ 191{
192 int retval;
193
194 TEMP_ACQUIRE {
195
167 dSP; 196 dSP;
168 int count; 197 int count;
169 int retval;
170 SV *xfname = newSVpv ("", 0); 198 SV *xfname = newSVpv ("", 0);
171 199
172 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3); 200 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
173 201
174 PUSHs (sv_2mortal (newSVpv (id, 0))); 202 PUSHs (sv_2mortal (newSVpv (id, 0)));
175 PUSHs (sv_2mortal (xfname)); 203 PUSHs (sv_2mortal (xfname));
176 PUSHs (sv_2mortal (newSViv (retrieve))); 204 PUSHs (sv_2mortal (newSViv (retrieve)));
183 strcpy (fname, SvPV_nolen (xfname)); 211 strcpy (fname, SvPV_nolen (xfname));
184 retval = POPi; 212 retval = POPi;
185 213
186 PUTBACK; FREETMPS; LEAVE; 214 PUTBACK; FREETMPS; LEAVE;
187 215
216 } TEMP_RELEASE;
217
188 return retval; 218 return retval;
189} 219}
190 220
191static char * 221static char *
192uu_filename_callback (void *cb, char *subject, char *filename) 222uu_filename_callback (void *cb, char *subject, char *filename)
193{ 223{
224 TEMP_ACQUIRE {
225
194 dSP; 226 dSP;
195 int count; 227 int count;
196 228
197 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 229 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
198 230
199 PUSHs (sv_2mortal(newSVpv(subject, 0))); 231 PUSHs (sv_2mortal(newSVpv(subject, 0)));
200 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 232 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
201 233
213 : 0; 245 : 0;
214 } 246 }
215 247
216 PUTBACK; FREETMPS; LEAVE; 248 PUTBACK; FREETMPS; LEAVE;
217 249
250 } TEMP_RELEASE;
251
218 return filename; 252 return filename;
219} 253}
220 254
221static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv; 255static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv;
222 256
223#define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL 257#define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL
224 258
225static int 259static int
226uu_info_file (void *cb, char *info) 260uu_info_file (void *cb, char *info)
227{ 261{
262 int retval;
263
264 TEMP_ACQUIRE {
265
228 dSP; 266 dSP;
229 int count; 267 int count;
230 int retval; 268
231
232 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1); 269 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
233 270
234 PUSHs(sv_2mortal(newSVpv(info,0))); 271 PUSHs(sv_2mortal(newSVpv(info,0)));
235 272
236 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 273 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
239 croak ("info_file perl callback returned more than one argument"); 276 croak ("info_file perl callback returned more than one argument");
240 277
241 retval = POPi; 278 retval = POPi;
242 279
243 PUTBACK; FREETMPS; LEAVE; 280 PUTBACK; FREETMPS; LEAVE;
281
282 } TEMP_RELEASE;
244 283
245 return retval; 284 return retval;
246} 285}
247 286
248static int 287static int
274UUInitialize () 313UUInitialize ()
275 CODE: 314 CODE:
276 if (!uu_initialized) 315 if (!uu_initialized)
277 { 316 {
278 int retval; 317 int retval;
279 318
280 if ((retval = UUInitialize ()) != UURET_OK) 319 if ((retval = UUInitialize ()) != UURET_OK)
281 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval)); 320 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
282 321
283 uu_initialized = 1; 322 uu_initialized = 1;
284 } 323 }
285 324
286void 325void
287UUCleanUp () 326UUCleanUp ()
288 CODE: 327 CODE:
289 if (uu_initialized) 328 if (uu_initialized)
290 UUCleanUp (); 329 UUCleanUp ();
291 330
292 uu_initialized = 0; 331 uu_initialized = 0;
293 332
294SV * 333SV *
295UUGetOption (opt) 334UUGetOption (opt)
296 int opt 335 int opt
297 CODE: 336 CODE:
298 { 337{
299 if (opt == UUOPT_PROGRESS) 338 if (opt == UUOPT_PROGRESS)
300 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented"); 339 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
301 else if (uu_opt_isstring (opt)) 340 else if (uu_opt_isstring (opt))
302 { 341 {
303 char cval[8192]; 342 char cval[8192];
304 343
305 UUGetOption (opt, 0, cval, sizeof cval); 344 UUGetOption (opt, 0, cval, sizeof cval);
306 RETVAL = newSVpv (cval, 0); 345 RETVAL = newSVpv (cval, 0);
307 } 346 }
308 else 347 else
309 { 348 {
310 RETVAL = newSViv (UUGetOption (opt, 0, 0, 0)); 349 RETVAL = newSViv (UUGetOption (opt, 0, 0, 0));
311 } 350 }
312 } 351}
313 OUTPUT: 352 OUTPUT:
314 RETVAL 353 RETVAL
315 354
316int 355int
317UUSetOption (opt, val) 356UUSetOption (opt, val)
318 int opt 357 int opt
319 SV * val 358 SV * val
320 CODE: 359 CODE:
321 { 360{
322 STRLEN dc; 361 STRLEN dc;
323 362
324 if (uu_opt_isstring (opt)) 363 if (uu_opt_isstring (opt))
325 RETVAL = UUSetOption (opt, 0, SvPV (val, dc)); 364 RETVAL = UUSetOption (opt, 0, SvPV (val, dc));
326 else 365 else
327 RETVAL = UUSetOption (opt, SvIV (val), (void *)0); 366 RETVAL = UUSetOption (opt, SvIV (val), (void *)0);
328 } 367}
329 OUTPUT: 368 OUTPUT:
330 RETVAL 369 RETVAL
331 370
332char * 371char *
333UUstrerror (errcode) 372UUstrerror (errcode)
373 char * fname 412 char * fname
374 char * id 413 char * id
375 int delflag 414 int delflag
376 int partno 415 int partno
377 PPCODE: 416 PPCODE:
378 { 417{
379 int count; 418 int count;
380 419 IV ret;
381 XPUSHs (sv_2mortal (newSViv (UULoadFileWithPartNo (fname, id, delflag, partno, &count)))); 420
421 RELEASE;
422 ret = UULoadFileWithPartNo (fname, id, delflag, partno, &count);
423 ACQUIRE;
424
425 XPUSHs (sv_2mortal (newSViv (ret)));
382 if (GIMME_V == G_ARRAY) 426 if (GIMME_V == G_ARRAY)
383 XPUSHs (sv_2mortal (newSViv (count))); 427 XPUSHs (sv_2mortal (newSViv (count)));
384 } 428}
385 429
386int 430int
387UUSmerge (pass) 431UUSmerge (pass)
388 int pass 432 int pass
389 433
480 524
481int 525int
482decode_temp (item) 526decode_temp (item)
483 uulist *item 527 uulist *item
484 CODE: 528 CODE:
529 RELEASE;
485 RETVAL = UUDecodeToTemp (item); 530 RETVAL = UUDecodeToTemp (item);
531 ACQUIRE;
486 OUTPUT: 532 OUTPUT:
487 RETVAL 533 RETVAL
488 534
489int 535int
490remove_temp (item) 536remove_temp (item)
491 uulist *item 537 uulist *item
492 CODE: 538 CODE:
539 RELEASE;
493 RETVAL = UURemoveTemp (item); 540 RETVAL = UURemoveTemp (item);
541 ACQUIRE;
494 OUTPUT: 542 OUTPUT:
495 RETVAL 543 RETVAL
496 544
497int 545int
498decode (item, target = 0) 546decode (item, target = 0)
499 uulist *item 547 uulist *item
500 char * target 548 char * target
501 CODE: 549 CODE:
550 RELEASE;
502 RETVAL = UUDecodeFile (item, target); 551 RETVAL = UUDecodeFile (item, target);
552 ACQUIRE;
503 OUTPUT: 553 OUTPUT:
504 RETVAL 554 RETVAL
505 555
506void 556void
507info (item, func) 557info (item, func)
508 uulist *item 558 uulist *item
509 SV * func 559 SV * func
510 CODE: 560 CODE:
561 RELEASE;
511 UUInfoFile (item,(void *)func, uu_info_file); 562 UUInfoFile (item, (void *)func, uu_info_file);
563 ACQUIRE;
512 564
513short 565short
514state(li) 566state(li)
515 uulist *li 567 uulist *li
516 CODE: 568 CODE:
595 647
596void 648void
597parts (li) 649parts (li)
598 uulist *li 650 uulist *li
599 PPCODE: 651 PPCODE:
600 { 652{
601 struct _uufile *p = li->thisfile; 653 struct _uufile *p = li->thisfile;
602 654
603 while (p) 655 while (p)
604 { 656 {
605 HV *pi = newHV (); 657 HV *pi = newHV ();
606 658
607 hv_store (pi, "partno" , 6, newSViv (p->partno) , 0); 659 hv_store (pi, "partno" , 6, newSViv (p->partno) , 0);
608 660
609 if (p->filename) 661 if (p->filename)
610 hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0); 662 hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0);
611 if(p->subfname) 663 if(p->subfname)
612 hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0); 664 hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0);
613 if(p->mimeid) 665 if(p->mimeid)
614 hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0); 666 hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0);
615 if(p->mimetype) 667 if(p->mimetype)
616 hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0); 668 hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0);
617 if (p->data->subject) 669 if (p->data->subject)
618 hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0); 670 hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0);
619 if (p->data->origin) 671 if (p->data->origin)
620 hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0); 672 hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0);
621 if (p->data->sfname) 673 if (p->data->sfname)
622 hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0); 674 hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0);
623 675
624 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi))); 676 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi)));
625 677
626 p = p->NEXT; 678 p = p->NEXT;
627 }
628 } 679 }
680}
629 681
630BOOT: 682BOOT:
631 uu_msg_sv = newSVsv (&PL_sv_undef); 683 uu_msg_sv = newSVsv (&PL_sv_undef);
632 uu_busy_sv = newSVsv (&PL_sv_undef); 684 uu_busy_sv = newSVsv (&PL_sv_undef);
633 uu_file_sv = newSVsv (&PL_sv_undef); 685 uu_file_sv = newSVsv (&PL_sv_undef);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines