ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/UUlib.xs
Revision: 1.24
Committed: Sat Sep 24 07:35:02 2022 UTC (19 months, 3 weeks ago) by root
Branch: MAIN
Changes since 1.23: +0 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.17 #include "perlmulticore.h"
6    
7 root 1.1 #include "uulib/fptools.h"
8 root 1.2 #include "uulib/uudeview.h"
9 root 1.1
10 root 1.19 static int perlinterp_released;
11 root 1.17
12 root 1.19 #define RELEASE do { perlinterp_released = 1; perlinterp_release (); } while (0)
13     #define ACQUIRE do { perlinterp_acquire (); perlinterp_released = 0; } while (0)
14 root 1.17
15 root 1.19 #define TEMP_ACQUIRE if (perlinterp_released) perlinterp_acquire ();
16     #define TEMP_RELEASE if (perlinterp_released) perlinterp_release ();
17 root 1.17
18 root 1.8 static void
19     uu_msg_callback (void *cb, char *msg, int level)
20 root 1.1 {
21 root 1.17 TEMP_ACQUIRE {
22    
23 root 1.19 dSP;
24    
25     ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
26 root 1.1
27 root 1.19 PUSHs (sv_2mortal (newSVpv (msg, 0)));
28     PUSHs (sv_2mortal (newSViv (level)));
29 root 1.1
30 root 1.19 PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
31     PUTBACK; FREETMPS; LEAVE;
32 root 1.17
33     } TEMP_RELEASE;
34 root 1.1 }
35    
36 root 1.8 static int
37     uu_busy_callback (void *cb, uuprogress *uup)
38 root 1.1 {
39 root 1.17 int retval;
40    
41     TEMP_ACQUIRE {
42    
43 root 1.19 dSP;
44     int count;
45    
46     ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
47    
48     PUSHs (sv_2mortal (newSViv (uup->action)));
49     PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
50     PUSHs (sv_2mortal (newSViv (uup->partno)));
51     PUSHs (sv_2mortal (newSViv (uup->numparts)));
52     PUSHs (sv_2mortal (newSViv (uup->fsize)));
53     PUSHs (sv_2mortal (newSViv (uup->percent)));
54 root 1.1
55 root 1.19 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
56 root 1.1
57 root 1.19 if (count != 1)
58     croak ("busycallback perl callback returned more than one argument");
59 root 1.1
60 root 1.19 retval = POPi;
61 root 1.1
62 root 1.19 PUTBACK; FREETMPS; LEAVE;
63 root 1.1
64 root 1.17 } TEMP_RELEASE;
65    
66 root 1.1 return retval;
67     }
68    
69 root 1.8 static char *
70     uu_fnamefilter_callback (void *cb, char *fname)
71 root 1.1 {
72 root 1.17 static char *str;
73    
74     TEMP_ACQUIRE {
75    
76 root 1.19 dSP;
77     int count;
78    
79     ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
80 root 1.1
81 root 1.19 PUSHs (sv_2mortal (newSVpv (fname, 0)));
82 root 1.1
83 root 1.19 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
84 root 1.1
85 root 1.19 if (count != 1)
86     croak ("fnamefilter perl callback MUST return a single filename exactly");
87 root 1.1
88 root 1.22 FP_free (str); str = FP_strdup (SvPV_nolen (TOPs));
89 root 1.1
90 root 1.19 PUTBACK; FREETMPS; LEAVE;
91 root 1.1
92 root 1.17 } TEMP_RELEASE;
93    
94 root 1.1 return str;
95     }
96    
97 root 1.8 static int
98     uu_file_callback (void *cb, char *id, char *fname, int retrieve)
99 root 1.1 {
100 root 1.17 int retval;
101    
102     TEMP_ACQUIRE {
103    
104 root 1.19 dSP;
105     int count;
106     SV *xfname = newSVpv ("", 0);
107    
108     ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
109 root 1.1
110 root 1.19 PUSHs (sv_2mortal (newSVpv (id, 0)));
111     PUSHs (sv_2mortal (xfname));
112     PUSHs (sv_2mortal (newSViv (retrieve)));
113 root 1.1
114 root 1.19 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
115 root 1.1
116 root 1.19 if (count != 1)
117     croak ("filecallback perl callback must return a single return status");
118 root 1.1
119 root 1.19 strcpy (fname, SvPV_nolen (xfname));
120     retval = POPi;
121 root 1.1
122 root 1.19 PUTBACK; FREETMPS; LEAVE;
123 root 1.1
124 root 1.17 } TEMP_RELEASE;
125    
126 root 1.1 return retval;
127     }
128    
129 root 1.8 static char *
130     uu_filename_callback (void *cb, char *subject, char *filename)
131 root 1.5 {
132 root 1.17 TEMP_ACQUIRE {
133    
134 root 1.19 dSP;
135     int count;
136    
137     ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
138 root 1.5
139 root 1.23 PUSHs (sv_2mortal (newSVpv (subject, 0)));
140     PUSHs (filename ? sv_2mortal (newSVpv (filename, 0)) : &PL_sv_undef);
141 root 1.5
142 root 1.19 PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
143 root 1.5
144 root 1.19 if (count > 1)
145     croak ("filenamecallback perl callback must return nothing or a single filename");
146 root 1.5
147 root 1.19 if (count)
148     {
149 root 1.22 FP_free (filename);
150 root 1.5
151 root 1.19 filename = SvOK (TOPs)
152 root 1.22 ? FP_strdup (SvPV_nolen (TOPs))
153 root 1.19 : 0;
154     }
155 root 1.5
156 root 1.19 PUTBACK; FREETMPS; LEAVE;
157 root 1.5
158 root 1.17 } TEMP_RELEASE;
159    
160 root 1.5 return filename;
161     }
162    
163     static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv;
164 root 1.1
165     #define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL
166    
167 root 1.8 static int
168     uu_info_file (void *cb, char *info)
169 root 1.1 {
170 root 1.17 int retval;
171    
172     TEMP_ACQUIRE {
173    
174 root 1.19 dSP;
175     int count;
176    
177     ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
178 root 1.1
179 root 1.19 PUSHs(sv_2mortal(newSVpv(info,0)));
180 root 1.1
181 root 1.19 PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
182 root 1.1
183 root 1.19 if (count != 1)
184     croak ("info_file perl callback returned more than one argument");
185 root 1.1
186 root 1.19 retval = POPi;
187 root 1.1
188 root 1.19 PUTBACK; FREETMPS; LEAVE;
189 root 1.1
190 root 1.17 } TEMP_RELEASE;
191    
192 root 1.1 return retval;
193     }
194    
195     static int
196     uu_opt_isstring (int opt)
197     {
198     switch (opt)
199     {
200     case UUOPT_VERSION:
201     case UUOPT_SAVEPATH:
202     case UUOPT_ENCEXT:
203     return 1;
204     default:
205     return 0;
206     }
207     }
208    
209 root 1.19 static void
210     initialise (void)
211     {
212     int retval = UUInitialize ();
213    
214     if (retval != UURET_OK)
215     croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
216     }
217 root 1.1
218     MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU
219    
220     PROTOTYPES: ENABLE
221    
222     void
223 root 1.8 UUCleanUp ()
224 root 1.1 CODE:
225 root 1.19 UUCleanUp ();
226     initialise ();
227 root 1.1
228     SV *
229 root 1.8 UUGetOption (opt)
230 root 1.1 int opt
231     CODE:
232 root 1.16 {
233     if (opt == UUOPT_PROGRESS)
234     croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
235     else if (uu_opt_isstring (opt))
236     {
237     char cval[8192];
238    
239     UUGetOption (opt, 0, cval, sizeof cval);
240     RETVAL = newSVpv (cval, 0);
241     }
242     else
243     {
244     RETVAL = newSViv (UUGetOption (opt, 0, 0, 0));
245     }
246     }
247 root 1.1 OUTPUT:
248     RETVAL
249    
250     int
251 root 1.8 UUSetOption (opt, val)
252 root 1.1 int opt
253     SV * val
254     CODE:
255 root 1.16 {
256     STRLEN dc;
257 root 1.1
258 root 1.16 if (uu_opt_isstring (opt))
259     RETVAL = UUSetOption (opt, 0, SvPV (val, dc));
260     else
261     RETVAL = UUSetOption (opt, SvIV (val), (void *)0);
262     }
263 root 1.1 OUTPUT:
264     RETVAL
265    
266     char *
267 root 1.8 UUstrerror (errcode)
268 root 1.1 int errcode
269    
270     void
271 root 1.8 UUSetMsgCallback (func = 0)
272 root 1.1 SV * func
273     CODE:
274 root 1.13 UUSetMsgCallback (FUNC_CB (uu_msg));
275 root 1.1
276     void
277 root 1.8 UUSetBusyCallback (func = 0,msecs = 1000)
278 root 1.1 SV * func
279     long msecs
280     CODE:
281 root 1.13 UUSetBusyCallback (FUNC_CB (uu_busy), msecs);
282 root 1.1
283     void
284 root 1.8 UUSetFileCallback (func = 0)
285 root 1.1 SV * func
286     CODE:
287 root 1.13 UUSetFileCallback (FUNC_CB (uu_file));
288 root 1.1
289     void
290 root 1.8 UUSetFNameFilter (func = 0)
291 root 1.1 SV * func
292     CODE:
293 root 1.13 UUSetFNameFilter (FUNC_CB (uu_fnamefilter));
294 root 1.1
295 root 1.5 void
296 root 1.8 UUSetFileNameCallback (func = 0)
297 root 1.5 SV * func
298     CODE:
299 root 1.13 UUSetFileNameCallback (FUNC_CB (uu_filename));
300 root 1.5
301 root 1.1 char *
302 root 1.8 UUFNameFilter (fname)
303 root 1.1 char * fname
304    
305     void
306 root 1.11 UULoadFile (fname, id = 0, delflag = 0, partno = -1)
307 root 1.1 char * fname
308     char * id
309     int delflag
310 root 1.11 int partno
311 root 1.1 PPCODE:
312 root 1.16 {
313     int count;
314 root 1.17 IV ret;
315    
316     RELEASE;
317     ret = UULoadFileWithPartNo (fname, id, delflag, partno, &count);
318     ACQUIRE;
319 root 1.16
320 root 1.17 XPUSHs (sv_2mortal (newSViv (ret)));
321 root 1.16 if (GIMME_V == G_ARRAY)
322     XPUSHs (sv_2mortal (newSViv (count)));
323     }
324 root 1.1
325     int
326 root 1.8 UUSmerge (pass)
327 root 1.1 int pass
328    
329     int
330     UUQuickDecode(datain,dataout,boundary,maxpos)
331     FILE * datain
332     FILE * dataout
333     char * boundary
334     long maxpos
335    
336     int
337     UUEncodeMulti(outfile,infile,infname,encoding,outfname,mimetype,filemode)
338     FILE * outfile
339     FILE * infile
340     char * infname
341     int encoding
342     char * outfname
343     char * mimetype
344     int filemode
345    
346     int
347     UUEncodePartial(outfile,infile,infname,encoding,outfname,mimetype,filemode,partno,linperfile)
348     FILE * outfile
349     FILE * infile
350     char * infname
351     int encoding
352     char * outfname
353     char * mimetype
354     int filemode
355     int partno
356     long linperfile
357    
358     int
359     UUEncodeToStream(outfile,infile,infname,encoding,outfname,filemode)
360     FILE * outfile
361     FILE * infile
362     char * infname
363     int encoding
364     char * outfname
365     int filemode
366    
367     int
368     UUEncodeToFile(infile,infname,encoding,outfname,diskname,linperfile)
369     FILE * infile
370     char * infname
371     int encoding
372     char * outfname
373     char * diskname
374     long linperfile
375    
376     int
377     UUE_PrepSingle(outfile,infile,infname,encoding,outfname,filemode,destination,from,subject,isemail)
378     FILE * outfile
379     FILE * infile
380     char * infname
381     int encoding
382     char * outfname
383     int filemode
384     char * destination
385     char * from
386     char * subject
387     int isemail
388    
389     int
390     UUE_PrepPartial(outfile,infile,infname,encoding,outfname,filemode,partno,linperfile,filesize,destination,from,subject,isemail)
391     FILE * outfile
392     FILE * infile
393     char * infname
394     int encoding
395     char * outfname
396     int filemode
397     int partno
398     long linperfile
399     long filesize
400     char * destination
401     char * from
402     char * subject
403     int isemail
404    
405     uulist *
406 root 1.8 UUGetFileListItem (num)
407 root 1.1 int num
408    
409 root 1.18 void
410     GetFileList ()
411     PPCODE:
412 root 1.21 {
413     uulist *iter;
414    
415     for (iter = UUGlobalFileList; iter; iter = iter->NEXT)
416 root 1.18 XPUSHs (sv_setref_pv (sv_newmortal (), "Convert::UUlib::Item", iter));
417 root 1.21 }
418 root 1.18
419 root 1.8 MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item
420    
421 root 1.1 int
422 root 1.8 rename (item, newname)
423 root 1.1 uulist *item
424     char * newname
425 root 1.8 CODE:
426     RETVAL = UURenameFile (item, newname);
427     OUTPUT:
428     RETVAL
429 root 1.1
430     int
431 root 1.8 decode_temp (item)
432 root 1.1 uulist *item
433 root 1.8 CODE:
434 root 1.17 RELEASE;
435 root 1.8 RETVAL = UUDecodeToTemp (item);
436 root 1.17 ACQUIRE;
437 root 1.8 OUTPUT:
438     RETVAL
439 root 1.1
440     int
441 root 1.8 remove_temp (item)
442 root 1.1 uulist *item
443 root 1.8 CODE:
444 root 1.17 RELEASE;
445 root 1.8 RETVAL = UURemoveTemp (item);
446 root 1.17 ACQUIRE;
447 root 1.8 OUTPUT:
448     RETVAL
449 root 1.1
450     int
451 root 1.8 decode (item, target = 0)
452 root 1.1 uulist *item
453     char * target
454 root 1.8 CODE:
455 root 1.17 RELEASE;
456 root 1.8 RETVAL = UUDecodeFile (item, target);
457 root 1.17 ACQUIRE;
458 root 1.8 OUTPUT:
459     RETVAL
460 root 1.1
461     void
462 root 1.8 info (item, func)
463 root 1.1 uulist *item
464     SV * func
465     CODE:
466 root 1.17 RELEASE;
467     UUInfoFile (item, (void *)func, uu_info_file);
468     ACQUIRE;
469 root 1.1
470     short
471     state(li)
472     uulist *li
473     CODE:
474     RETVAL = li->state;
475     OUTPUT:
476     RETVAL
477    
478     short
479     mode(li,newmode=0)
480     uulist *li
481     short newmode
482     CODE:
483     if (newmode)
484     li->mode = newmode;
485     RETVAL = li->mode;
486     OUTPUT:
487     RETVAL
488    
489     short
490     uudet(li)
491     uulist *li
492     CODE:
493     RETVAL = li->uudet;
494     OUTPUT:
495     RETVAL
496    
497     long
498     size(li)
499     uulist *li
500     CODE:
501     RETVAL = li->size;
502     OUTPUT:
503     RETVAL
504    
505     char *
506 root 1.8 filename (li, newfilename = 0)
507 root 1.1 uulist *li
508     char * newfilename
509     CODE:
510     if (newfilename)
511     {
512 root 1.22 FP_free (li->filename);
513     li->filename = FP_strdup (newfilename);
514 root 1.1 }
515     RETVAL = li->filename;
516     OUTPUT:
517     RETVAL
518    
519     char *
520 root 1.8 subfname (li)
521 root 1.1 uulist *li
522     CODE:
523     RETVAL = li->subfname;
524     OUTPUT:
525     RETVAL
526    
527     char *
528 root 1.8 mimeid (li)
529 root 1.1 uulist *li
530     CODE:
531     RETVAL = li->mimeid;
532     OUTPUT:
533     RETVAL
534    
535     char *
536 root 1.8 mimetype (li)
537 root 1.1 uulist *li
538     CODE:
539     RETVAL = li->mimetype;
540     OUTPUT:
541     RETVAL
542    
543     char *
544 root 1.8 binfile (li)
545 root 1.1 uulist *li
546     CODE:
547     RETVAL = li->binfile;
548     OUTPUT:
549     RETVAL
550    
551 root 1.8 # methods accessing internal data(!)
552 root 1.1
553     void
554 root 1.8 parts (li)
555 root 1.1 uulist *li
556     PPCODE:
557 root 1.16 {
558     struct _uufile *p = li->thisfile;
559 root 1.1
560 root 1.16 while (p)
561     {
562     HV *pi = newHV ();
563    
564 root 1.20 hv_store (pi, "partno" , 6, newSViv (p->partno) , 0);
565     if (p->filename ) hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0);
566     if (p->subfname ) hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0);
567     if (p->mimeid ) hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0);
568     if (p->mimetype ) hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0);
569     if (p->data->subject) hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0);
570     if (p->data->origin ) hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0);
571     if (p->data->sfname ) hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0);
572 root 1.16
573     XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi)));
574    
575     p = p->NEXT;
576     }
577     }
578 root 1.1
579     BOOT:
580 root 1.20 {
581     HV *stash = GvSTASH (CvGV (cv));
582    
583     static const struct {
584     const char *name;
585     IV iv;
586     } *civ, const_iv[] = {
587     # define const_iv(name, value) { # name, (IV) value },
588     const_iv (ACT_COPYING , UUACT_COPYING)
589     const_iv (ACT_DECODING , UUACT_DECODING)
590     const_iv (ACT_ENCODING , UUACT_ENCODING)
591     const_iv (ACT_IDLE , UUACT_IDLE)
592     const_iv (ACT_SCANNING , UUACT_SCANNING)
593     const_iv (FILE_DECODED , UUFILE_DECODED)
594     const_iv (FILE_ERROR , UUFILE_ERROR)
595     const_iv (FILE_MISPART , UUFILE_MISPART)
596     const_iv (FILE_NOBEGIN , UUFILE_NOBEGIN)
597     const_iv (FILE_NODATA , UUFILE_NODATA)
598     const_iv (FILE_NOEND , UUFILE_NOEND)
599     const_iv (FILE_OK , UUFILE_OK)
600     const_iv (FILE_READ , UUFILE_READ)
601     const_iv (FILE_TMPFILE , UUFILE_TMPFILE)
602     const_iv (MSG_ERROR , UUMSG_ERROR)
603     const_iv (MSG_FATAL , UUMSG_FATAL)
604     const_iv (MSG_MESSAGE , UUMSG_MESSAGE)
605     const_iv (MSG_NOTE , UUMSG_NOTE)
606     const_iv (MSG_PANIC , UUMSG_PANIC)
607     const_iv (MSG_WARNING , UUMSG_WARNING)
608     const_iv (OPT_VERSION , UUOPT_VERSION)
609     const_iv (OPT_FAST , UUOPT_FAST)
610     const_iv (OPT_DUMBNESS , UUOPT_DUMBNESS)
611     const_iv (OPT_BRACKPOL , UUOPT_BRACKPOL)
612     const_iv (OPT_VERBOSE , UUOPT_VERBOSE)
613     const_iv (OPT_DESPERATE, UUOPT_DESPERATE)
614     const_iv (OPT_IGNREPLY , UUOPT_IGNREPLY)
615     const_iv (OPT_OVERWRITE, UUOPT_OVERWRITE)
616     const_iv (OPT_SAVEPATH , UUOPT_SAVEPATH)
617     const_iv (OPT_IGNMODE , UUOPT_IGNMODE)
618     const_iv (OPT_DEBUG , UUOPT_DEBUG)
619     const_iv (OPT_ERRNO , UUOPT_ERRNO)
620     const_iv (OPT_PROGRESS , UUOPT_PROGRESS)
621     const_iv (OPT_USETEXT , UUOPT_USETEXT)
622     const_iv (OPT_PREAMB , UUOPT_PREAMB)
623     const_iv (OPT_TINYB64 , UUOPT_TINYB64)
624     const_iv (OPT_ENCEXT , UUOPT_ENCEXT)
625     const_iv (OPT_REMOVE , UUOPT_REMOVE)
626     const_iv (OPT_MOREMIME , UUOPT_MOREMIME)
627     const_iv (OPT_DOTDOT , UUOPT_DOTDOT)
628     const_iv (OPT_RBUF , UUOPT_RBUF)
629     const_iv (OPT_WBUF , UUOPT_WBUF)
630     const_iv (OPT_AUTOCHECK, UUOPT_AUTOCHECK)
631     const_iv (RET_CANCEL , UURET_CANCEL)
632     const_iv (RET_CONT , UURET_CONT)
633     const_iv (RET_EXISTS , UURET_EXISTS)
634     const_iv (RET_ILLVAL , UURET_ILLVAL)
635     const_iv (RET_IOERR , UURET_IOERR)
636     const_iv (RET_NODATA , UURET_NODATA)
637     const_iv (RET_NOEND , UURET_NOEND)
638     const_iv (RET_NOMEM , UURET_NOMEM)
639     const_iv (RET_OK , UURET_OK)
640     const_iv (RET_UNSUP , UURET_UNSUP)
641     const_iv (B64_ENCODED , B64ENCODED)
642     const_iv (BH_ENCODED , BH_ENCODED)
643     const_iv (PT_ENCODED , PT_ENCODED)
644     const_iv (QP_ENCODED , QP_ENCODED)
645     const_iv (UU_ENCODED , UU_ENCODED)
646     const_iv (XX_ENCODED , XX_ENCODED)
647     const_iv (YENC_ENCODED , YENC_ENCODED)
648     };
649    
650     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
651     newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
652    
653 root 1.13 uu_msg_sv = newSVsv (&PL_sv_undef);
654     uu_busy_sv = newSVsv (&PL_sv_undef);
655     uu_file_sv = newSVsv (&PL_sv_undef);
656     uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
657     uu_filename_sv = newSVsv (&PL_sv_undef);
658 root 1.20
659 root 1.19 initialise ();
660 root 1.20 }
661 root 1.1