File Coverage

UUlib.xs
Criterion Covered Total %
statement 78 193 40.4
branch n/a
condition n/a
subroutine n/a
pod n/a
total 78 193 40.4


line stmt bran cond sub pod time code
1             #include "EXTERN.h"
2             #include "perl.h"
3             #include "XSUB.h"
4              
5             #include "uulib/fptools.h"
6             #include "uulib/uudeview.h"
7             #include "uulib/uuint.h"
8              
9             static int
10             not_here (char *s)
11             {
12                 croak("%s not implemented", s);
13             return -1;
14             }
15            
16             static int
17             constant (char *name)
18             {
19 59           errno = 0;
20 59           switch (*name) {
21                 case 'A':
22 5           if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING;
23 4           if (strEQ(name, "ACT_DECODING")) return UUACT_DECODING;
24 3           if (strEQ(name, "ACT_ENCODING")) return UUACT_ENCODING;
25 2           if (strEQ(name, "ACT_IDLE")) return UUACT_IDLE;
26 1           if (strEQ(name, "ACT_SCANNING")) return UUACT_SCANNING;
27                 case 'F':
28 9           if (strEQ(name, "FILE_DECODED")) return UUFILE_DECODED;
29 8           if (strEQ(name, "FILE_ERROR")) return UUFILE_ERROR;
30 7           if (strEQ(name, "FILE_MISPART")) return UUFILE_MISPART;
31 6           if (strEQ(name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN;
32 5           if (strEQ(name, "FILE_NODATA")) return UUFILE_NODATA;
33 4           if (strEQ(name, "FILE_NOEND")) return UUFILE_NOEND;
34 3           if (strEQ(name, "FILE_OK")) return UUFILE_OK;
35 2           if (strEQ(name, "FILE_READ")) return UUFILE_READ;
36 1           if (strEQ(name, "FILE_TMPFILE")) return UUFILE_TMPFILE;
37             break;
38                 case 'M':
39 6           if (strEQ(name, "MSG_ERROR")) return UUMSG_ERROR;
40 5           if (strEQ(name, "MSG_FATAL")) return UUMSG_FATAL;
41 4           if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE;
42 3           if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE;
43 2           if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC;
44 1           if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING;
45                 case 'O':
46 22           if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION;
47 21           if (strEQ(name, "OPT_FAST")) return UUOPT_FAST;
48 20           if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
49 19           if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL;
50 18           if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE;
51 17           if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE;
52 16           if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY;
53 15           if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE;
54 14           if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
55 13           if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
56 12           if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG;
57 11           if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO;
58 10           if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
59 9           if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT;
60 8           if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB;
61 7           if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64;
62 6           if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
63 5           if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE;
64 4           if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
65 3           if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
66 2           if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF;
67 1           if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF;
68                 case 'R':
69 10           if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
70 9           if (strEQ(name, "RET_CONT")) return UURET_CONT;
71 8           if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
72 7           if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
73 6           if (strEQ(name, "RET_IOERR")) return UURET_IOERR;
74 5           if (strEQ(name, "RET_NODATA")) return UURET_NODATA;
75 4           if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
76 3           if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
77 2           if (strEQ(name, "RET_OK")) return UURET_OK;
78 1           if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
79                 case 'B':
80 2           if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
81 1           if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
82                 case 'P':
83 1           if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
84                 case 'Q':
85 1           if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
86                 case 'U':
87 1           if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
88                 case 'X':
89 1           if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
90                 case 'Y':
91 1           if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
92                 }
93 0               errno = EINVAL;
94                 return 0;
95             }
96              
97             static void
98             uu_msg_callback (void *cb, char *msg, int level)
99 0           {
100 0             dSP;
101               
102 0             ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
103              
104 0             PUSHs (sv_2mortal (newSVpv (msg, 0)));
105 0             PUSHs (sv_2mortal (newSViv (level)));
106              
107 0             PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
108 0             PUTBACK; FREETMPS; LEAVE;
109             }
110              
111             static int
112             uu_busy_callback (void *cb, uuprogress *uup)
113 0           {
114 0             dSP;
115               int count;
116               int retval;
117               
118 0             ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
119              
120 0             PUSHs (sv_2mortal (newSViv (uup->action)));
121 0             PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
122 0             PUSHs (sv_2mortal (newSViv (uup->partno)));
123 0             PUSHs (sv_2mortal (newSViv (uup->numparts)));
124 0             PUSHs (sv_2mortal (newSViv (uup->fsize)));
125 0             PUSHs (sv_2mortal (newSViv (uup->percent)));
126              
127 0             PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
128              
129 0             if (count != 1)
130 0               croak ("busycallback perl callback returned more than one argument");
131              
132 0             retval = POPi;
133              
134 0             PUTBACK; FREETMPS; LEAVE;
135              
136               return retval;
137             }
138              
139             static char *
140             uu_fnamefilter_callback (void *cb, char *fname)
141 1           {
142 1             dSP;
143               int count;
144               static char *str;
145               
146 1             ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
147              
148 1             PUSHs (sv_2mortal (newSVpv (fname, 0)));
149              
150 1             PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
151              
152 1             if (count != 1)
153 0               croak ("fnamefilter perl callback returned more than one argument");
154              
155 1             _FP_free(str); str = _FP_strdup (POPp);
156              
157 1             PUTBACK; FREETMPS; LEAVE;
158              
159               return str;
160             }
161              
162             static int
163             uu_file_callback (void *cb, char *id, char *fname, int retrieve)
164 0           {
165 0             dSP;
166               int count;
167               int retval;
168 0             SV *xfname = newSVpv ("", 0);
169               STRLEN dc;
170               
171 0             ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
172              
173 0             PUSHs (sv_2mortal (newSVpv (id, 0)));
174 0             PUSHs (sv_2mortal (xfname));
175 0             PUSHs (sv_2mortal (newSViv (retrieve)));
176              
177 0             PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
178              
179 0             if (count != 1)
180 0               croak ("filecallback perl callback returned more than one argument");
181              
182 0             strcpy (fname, SvPV (xfname, dc));
183              
184 0             retval = POPi;
185              
186 0             PUTBACK; FREETMPS; LEAVE;
187              
188               return retval;
189             }
190              
191             static char *
192             uu_filename_callback (void *cb, char *subject, char *filename)
193 0           {
194 0             dSP;
195               int count;
196               SV *retval;
197               STRLEN dc;
198               
199 0             ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,3);
200              
201 0             PUSHs(sv_2mortal(newSVpv(subject, 0)));
202 0             PUSHs(filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
203              
204 0             PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
205              
206 0             if (count > 1)
207 0               croak ("filenamecallback perl callback returned more than one argument");
208              
209 0             if (count)
210                 {
211 0                 _FP_free (filename);
212              
213 0                 retval = POPs;
214              
215 0                 if (SvOK (retval))
216                     {
217                       STRLEN len;
218 0                     char *fn = SvPV (retval, len);
219              
220 0                     filename = malloc (len + 1);
221              
222 0                     if (filename)
223                         {
224 0                         memcpy (filename, fn, len);
225 0                         filename[len] = 0;
226                         }
227                     }
228                   else
229                     filename = 0;
230                 }
231              
232 0             PUTBACK; FREETMPS; LEAVE;
233              
234               return filename;
235             }
236              
237             static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv;
238              
239             #define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL
240              
241             static int
242             uu_info_file (void *cb, char *info)
243 0           {
244 0             dSP;
245               int count;
246               int retval;
247               
248 0             ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
249              
250 0             PUSHs(sv_2mortal(newSVpv(info,0)));
251              
252 0             PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
253              
254 0             if (count != 1)
255 0               croak ("info_file perl callback returned more than one argument");
256              
257 0             retval = POPi;
258              
259 0             PUTBACK; FREETMPS; LEAVE;
260              
261               return retval;
262             }
263              
264             static int
265             uu_opt_isstring (int opt)
266 0           {
267 0             switch (opt)
268                 {
269                   case UUOPT_VERSION:
270                   case UUOPT_SAVEPATH:
271                   case UUOPT_ENCEXT:
272                      return 1;
273                   default:
274                      return 0;
275                 }
276             }
277              
278             static int uu_initialized;
279              
280             MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU
281              
282             PROTOTYPES: ENABLE
283              
284             int
285             constant (name)
286             char * name
287              
288              
289             void
290             UUInitialize ()
291             CODE:
292 1                   if (!uu_initialized)
293                       {
294                         int retval;
295                         
296 1                       if ((retval = UUInitialize ()) != UURET_OK)
297 0                         croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
298              
299 1                       uu_initialized = 1;
300                       }
301              
302             void
303             UUCleanUp ()
304             CODE:
305 0                   if (uu_initialized)
306 0                     UUCleanUp ();
307              
308 0                   uu_initialized = 0;
309              
310             SV *
311             UUGetOption (opt)
312             int opt
313                     CODE:
314             {
315 0                           if (opt == UUOPT_PROGRESS)
316 0                             croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
317 0                           else if (uu_opt_isstring (opt))
318                               {
319                      char cval[8192];
320              
321 0                               UUGetOption (opt, 0, cval, sizeof cval);
322 0                               RETVAL = newSVpv (cval, 0);
323                               }
324                             else
325                               {
326 0                               RETVAL = newSViv (UUGetOption (opt, 0, 0, 0));
327                               }
328             }
329         &