ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Urlader/Urlader.xs
Revision: 1.1
Committed: Mon Jan 2 09:23:03 2012 UTC (12 years, 4 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #define HLOG 18 /* up to 22, but gives diminishing improvements */
6 #define VERY_FAST 0
7 #define ULTRA_FAST 0
8
9 #include "liblzf/lzf_c_best.c"
10
11 #include "urlib.h"
12 #include "urlib.c"
13
14 MODULE = Urlader PACKAGE = Urlader PREFIX = u_
15
16 PROTOTYPES: ENABLE
17
18 BOOT:
19 {
20 HV *stash = gv_stashpv ("Urlader", 1);
21
22 static const struct {
23 const char *name;
24 IV iv;
25 } *civ, const_iv[] = {
26 # define const_iv(name) { # name, (IV) name },
27 const_iv (MAX_ARGC)
28 const_iv (MAX_ARGS)
29 const_iv (T_NULL)
30 const_iv (T_META)
31 const_iv (T_ENV)
32 const_iv (T_ARG)
33 const_iv (T_DIR)
34 const_iv (T_FILE)
35 const_iv (T_NUM)
36 const_iv (F_LZF)
37 const_iv (F_EXEC)
38 const_iv (F_NULL)
39 };
40
41 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
42 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
43
44 newCONSTSUB (stash, "URLADER" , newSVpv (URLADER , 0));
45 newCONSTSUB (stash, "URLADER_VERSION", newSVpv (URLADER_VERSION, 0));
46 newCONSTSUB (stash, "TAIL_MAGIC" , newSVpv (TAIL_MAGIC , 0));
47 }
48
49 const char *
50 getenv (const char *name)
51
52 SV *
53 lzf_compress (SV *in, int min_improve = 2)
54 CODE:
55 {
56 STRLEN in_len;
57 char *in_data = SvPVbyte (in, in_len);
58 STRLEN out_len = in_len - min_improve;
59 SV *out = sv_newmortal ();
60
61 RETVAL = &PL_sv_no;
62 if (in_len)
63 {
64 sv_grow (out, out_len);
65 out_len = lzf_compress_best (in_data, in_len, SvPVX (out), out_len);
66
67 if (out_len)
68 {
69 SvPOK_only (out);
70 SvCUR_set (out, out_len);
71 SvSetSV (in, out);
72 RETVAL = &PL_sv_yes;
73 }
74 }
75 }
76 OUTPUT:
77 RETVAL
78
79 void
80 _set_datadir ()
81 CODE:
82 u_set_datadir ();
83
84 void
85 _set_exe_info (const char *id, const char *ver)
86 CODE:
87 strcpy (exe_id , id);
88 strcpy (exe_ver, ver);
89 u_set_exe_info ();
90
91 SV *
92 lock (SV *path, SV *excl, SV *dowait)
93 CODE:
94 {
95 u_handle h = u_lock (SvPVbyte_nolen (path), SvTRUE (excl), SvTRUE (dowait));
96
97 RETVAL = &PL_sv_undef;
98 if (u_valid (h))
99 RETVAL = sv_setref_iv (sv_newmortal (), "Urlader::lock", (IV)h);
100 }
101 OUTPUT:
102 RETVAL
103
104 MODULE = Urlader PACKAGE = Urlader::lock
105
106 void
107 DESTROY (SV *self)
108 CODE:
109 u_close ((u_handle)SvIV (SvRV (self)));
110
111