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.15 by root, Mon Aug 24 06:15:00 2009 UTC vs.
Revision 1.18 by root, Fri Feb 28 16: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);
98} 108}
99 109
100static void 110static void
101uu_msg_callback (void *cb, char *msg, int level) 111uu_msg_callback (void *cb, char *msg, int level)
102{ 112{
113 TEMP_ACQUIRE {
114
103 dSP; 115 dSP;
104 116
105 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 117 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
106 118
107 PUSHs (sv_2mortal (newSVpv (msg, 0))); 119 PUSHs (sv_2mortal (newSVpv (msg, 0)));
108 PUSHs (sv_2mortal (newSViv (level))); 120 PUSHs (sv_2mortal (newSViv (level)));
109 121
110 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;
111 PUTBACK; FREETMPS; LEAVE; 123 PUTBACK; FREETMPS; LEAVE;
124
125 } TEMP_RELEASE;
112} 126}
113 127
114static int 128static int
115uu_busy_callback (void *cb, uuprogress *uup) 129uu_busy_callback (void *cb, uuprogress *uup)
116{ 130{
131 int retval;
132
133 TEMP_ACQUIRE {
134
117 dSP; 135 dSP;
118 int count; 136 int count;
119 int retval; 137
120
121 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6); 138 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
122 139
123 PUSHs (sv_2mortal (newSViv (uup->action))); 140 PUSHs (sv_2mortal (newSViv (uup->action)));
124 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0))); 141 PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
125 PUSHs (sv_2mortal (newSViv (uup->partno))); 142 PUSHs (sv_2mortal (newSViv (uup->partno)));
134 151
135 retval = POPi; 152 retval = POPi;
136 153
137 PUTBACK; FREETMPS; LEAVE; 154 PUTBACK; FREETMPS; LEAVE;
138 155
156 } TEMP_RELEASE;
157
139 return retval; 158 return retval;
140} 159}
141 160
142static char * 161static char *
143uu_fnamefilter_callback (void *cb, char *fname) 162uu_fnamefilter_callback (void *cb, char *fname)
144{ 163{
164 static char *str;
165
166 TEMP_ACQUIRE {
167
145 dSP; 168 dSP;
146 int count; 169 int count;
147 static char *str; 170
148
149 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1); 171 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
150 172
151 PUSHs (sv_2mortal (newSVpv (fname, 0))); 173 PUSHs (sv_2mortal (newSVpv (fname, 0)));
152 174
153 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 175 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
157 179
158 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs)); 180 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
159 181
160 PUTBACK; FREETMPS; LEAVE; 182 PUTBACK; FREETMPS; LEAVE;
161 183
184 } TEMP_RELEASE;
185
162 return str; 186 return str;
163} 187}
164 188
165static int 189static int
166uu_file_callback (void *cb, char *id, char *fname, int retrieve) 190uu_file_callback (void *cb, char *id, char *fname, int retrieve)
167{ 191{
192 int retval;
193
194 TEMP_ACQUIRE {
195
168 dSP; 196 dSP;
169 int count; 197 int count;
170 int retval;
171 SV *xfname = newSVpv ("", 0); 198 SV *xfname = newSVpv ("", 0);
172 199
173 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3); 200 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
174 201
175 PUSHs (sv_2mortal (newSVpv (id, 0))); 202 PUSHs (sv_2mortal (newSVpv (id, 0)));
176 PUSHs (sv_2mortal (xfname)); 203 PUSHs (sv_2mortal (xfname));
177 PUSHs (sv_2mortal (newSViv (retrieve))); 204 PUSHs (sv_2mortal (newSViv (retrieve)));
184 strcpy (fname, SvPV_nolen (xfname)); 211 strcpy (fname, SvPV_nolen (xfname));
185 retval = POPi; 212 retval = POPi;
186 213
187 PUTBACK; FREETMPS; LEAVE; 214 PUTBACK; FREETMPS; LEAVE;
188 215
216 } TEMP_RELEASE;
217
189 return retval; 218 return retval;
190} 219}
191 220
192static char * 221static char *
193uu_filename_callback (void *cb, char *subject, char *filename) 222uu_filename_callback (void *cb, char *subject, char *filename)
194{ 223{
224 TEMP_ACQUIRE {
225
195 dSP; 226 dSP;
196 int count; 227 int count;
197 228
198 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); 229 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
199 230
200 PUSHs (sv_2mortal(newSVpv(subject, 0))); 231 PUSHs (sv_2mortal(newSVpv(subject, 0)));
201 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef); 232 PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
202 233
214 : 0; 245 : 0;
215 } 246 }
216 247
217 PUTBACK; FREETMPS; LEAVE; 248 PUTBACK; FREETMPS; LEAVE;
218 249
250 } TEMP_RELEASE;
251
219 return filename; 252 return filename;
220} 253}
221 254
222static 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;
223 256
224#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
225 258
226static int 259static int
227uu_info_file (void *cb, char *info) 260uu_info_file (void *cb, char *info)
228{ 261{
262 int retval;
263
264 TEMP_ACQUIRE {
265
229 dSP; 266 dSP;
230 int count; 267 int count;
231 int retval; 268
232
233 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1); 269 ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
234 270
235 PUSHs(sv_2mortal(newSVpv(info,0))); 271 PUSHs(sv_2mortal(newSVpv(info,0)));
236 272
237 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN; 273 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
240 croak ("info_file perl callback returned more than one argument"); 276 croak ("info_file perl callback returned more than one argument");
241 277
242 retval = POPi; 278 retval = POPi;
243 279
244 PUTBACK; FREETMPS; LEAVE; 280 PUTBACK; FREETMPS; LEAVE;
281
282 } TEMP_RELEASE;
245 283
246 return retval; 284 return retval;
247} 285}
248 286
249static int 287static int
275UUInitialize () 313UUInitialize ()
276 CODE: 314 CODE:
277 if (!uu_initialized) 315 if (!uu_initialized)
278 { 316 {
279 int retval; 317 int retval;
280 318
281 if ((retval = UUInitialize ()) != UURET_OK) 319 if ((retval = UUInitialize ()) != UURET_OK)
282 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval)); 320 croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
283 321
284 uu_initialized = 1; 322 uu_initialized = 1;
285 } 323 }
286 324
287void 325void
288UUCleanUp () 326UUCleanUp ()
289 CODE: 327 CODE:
290 if (uu_initialized) 328 if (uu_initialized)
291 UUCleanUp (); 329 UUCleanUp ();
292 330
293 uu_initialized = 0; 331 uu_initialized = 0;
294 332
295SV * 333SV *
296UUGetOption (opt) 334UUGetOption (opt)
297 int opt 335 int opt
298 CODE: 336 CODE:
299 { 337{
300 if (opt == UUOPT_PROGRESS) 338 if (opt == UUOPT_PROGRESS)
301 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented"); 339 croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
302 else if (uu_opt_isstring (opt)) 340 else if (uu_opt_isstring (opt))
303 { 341 {
304 char cval[8192]; 342 char cval[8192];
305 343
306 UUGetOption (opt, 0, cval, sizeof cval); 344 UUGetOption (opt, 0, cval, sizeof cval);
307 RETVAL = newSVpv (cval, 0); 345 RETVAL = newSVpv (cval, 0);
308 } 346 }
309 else 347 else
310 { 348 {
311 RETVAL = newSViv (UUGetOption (opt, 0, 0, 0)); 349 RETVAL = newSViv (UUGetOption (opt, 0, 0, 0));
312 } 350 }
313 } 351}
314 OUTPUT: 352 OUTPUT:
315 RETVAL 353 RETVAL
316 354
317int 355int
318UUSetOption (opt, val) 356UUSetOption (opt, val)
319 int opt 357 int opt
320 SV * val 358 SV * val
321 CODE: 359 CODE:
322 { 360{
323 STRLEN dc; 361 STRLEN dc;
324 362
325 if (uu_opt_isstring (opt)) 363 if (uu_opt_isstring (opt))
326 RETVAL = UUSetOption (opt, 0, SvPV (val, dc)); 364 RETVAL = UUSetOption (opt, 0, SvPV (val, dc));
327 else 365 else
328 RETVAL = UUSetOption (opt, SvIV (val), (void *)0); 366 RETVAL = UUSetOption (opt, SvIV (val), (void *)0);
329 } 367}
330 OUTPUT: 368 OUTPUT:
331 RETVAL 369 RETVAL
332 370
333char * 371char *
334UUstrerror (errcode) 372UUstrerror (errcode)
374 char * fname 412 char * fname
375 char * id 413 char * id
376 int delflag 414 int delflag
377 int partno 415 int partno
378 PPCODE: 416 PPCODE:
379 { 417{
380 int count; 418 int count;
381 419 IV ret;
382 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)));
383 if (GIMME_V == G_ARRAY) 426 if (GIMME_V == G_ARRAY)
384 XPUSHs (sv_2mortal (newSViv (count))); 427 XPUSHs (sv_2mortal (newSViv (count)));
385 } 428}
386 429
387int 430int
388UUSmerge (pass) 431UUSmerge (pass)
389 int pass 432 int pass
390 433
466 509
467uulist * 510uulist *
468UUGetFileListItem (num) 511UUGetFileListItem (num)
469 int num 512 int num
470 513
514void
515GetFileList ()
516 PPCODE:
517 for (uulist *iter = UUGlobalFileList; iter; iter = iter->NEXT)
518 XPUSHs (sv_setref_pv (sv_newmortal (), "Convert::UUlib::Item", iter));
519
471MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item 520MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item
472 521
473int 522int
474rename (item, newname) 523rename (item, newname)
475 uulist *item 524 uulist *item
481 530
482int 531int
483decode_temp (item) 532decode_temp (item)
484 uulist *item 533 uulist *item
485 CODE: 534 CODE:
535 RELEASE;
486 RETVAL = UUDecodeToTemp (item); 536 RETVAL = UUDecodeToTemp (item);
537 ACQUIRE;
487 OUTPUT: 538 OUTPUT:
488 RETVAL 539 RETVAL
489 540
490int 541int
491remove_temp (item) 542remove_temp (item)
492 uulist *item 543 uulist *item
493 CODE: 544 CODE:
545 RELEASE;
494 RETVAL = UURemoveTemp (item); 546 RETVAL = UURemoveTemp (item);
547 ACQUIRE;
495 OUTPUT: 548 OUTPUT:
496 RETVAL 549 RETVAL
497 550
498int 551int
499decode (item, target = 0) 552decode (item, target = 0)
500 uulist *item 553 uulist *item
501 char * target 554 char * target
502 CODE: 555 CODE:
556 RELEASE;
503 RETVAL = UUDecodeFile (item, target); 557 RETVAL = UUDecodeFile (item, target);
558 ACQUIRE;
504 OUTPUT: 559 OUTPUT:
505 RETVAL 560 RETVAL
506 561
507void 562void
508info (item, func) 563info (item, func)
509 uulist *item 564 uulist *item
510 SV * func 565 SV * func
511 CODE: 566 CODE:
567 RELEASE;
512 UUInfoFile (item,(void *)func, uu_info_file); 568 UUInfoFile (item, (void *)func, uu_info_file);
569 ACQUIRE;
513 570
514short 571short
515state(li) 572state(li)
516 uulist *li 573 uulist *li
517 CODE: 574 CODE:
596 653
597void 654void
598parts (li) 655parts (li)
599 uulist *li 656 uulist *li
600 PPCODE: 657 PPCODE:
601 { 658{
602 struct _uufile *p = li->thisfile; 659 struct _uufile *p = li->thisfile;
603 660
604 while (p) 661 while (p)
605 { 662 {
606 HV *pi = newHV (); 663 HV *pi = newHV ();
607 664
608 hv_store (pi, "partno" , 6, newSViv (p->partno) , 0); 665 hv_store (pi, "partno" , 6, newSViv (p->partno) , 0);
609 666
610 if (p->filename) 667 if (p->filename)
611 hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0); 668 hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0);
612 if(p->subfname) 669 if(p->subfname)
613 hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0); 670 hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0);
614 if(p->mimeid) 671 if(p->mimeid)
615 hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0); 672 hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0);
616 if(p->mimetype) 673 if(p->mimetype)
617 hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0); 674 hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0);
618 if (p->data->subject) 675 if (p->data->subject)
619 hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0); 676 hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0);
620 if (p->data->origin) 677 if (p->data->origin)
621 hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0); 678 hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0);
622 if (p->data->sfname) 679 if (p->data->sfname)
623 hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0); 680 hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0);
624 681
625 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi))); 682 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi)));
626 683
627 p = p->NEXT; 684 p = p->NEXT;
628 }
629 } 685 }
686}
630 687
631BOOT: 688BOOT:
632 uu_msg_sv = newSVsv (&PL_sv_undef); 689 uu_msg_sv = newSVsv (&PL_sv_undef);
633 uu_busy_sv = newSVsv (&PL_sv_undef); 690 uu_busy_sv = newSVsv (&PL_sv_undef);
634 uu_file_sv = newSVsv (&PL_sv_undef); 691 uu_file_sv = newSVsv (&PL_sv_undef);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines