summaryrefslogtreecommitdiff
path: root/pikul.i
blob: d21798220ebd7b06f5d221b0393f0ef3ea758ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%module Pikul
%{
#include "pikul.h"
%}

%typemap(in) char *[] {
        AV *tempav = (AV *)SvRV($input);
        I32 len = av_len(tempav);
        $1 = (char **)malloc((len + 2) * sizeof(char *));
        int i;
        for (i = 0; i <= len; i++) {
                SV **tv = av_fetch(tempav, i, 0);
                $1[i] = (char *)SvPV(*tv, PL_na);
        }
        $1[i] = NULL;
};
%typemap(freearg) char *[] {
        free($1);
}
%typemap(out) char ** {
        int len = 0;
        while ($1[len])
                len++;
        SV **svs = malloc(len * sizeof(SV *));
        for (int i = 0; i < len; i++) {
                svs[i] = sv_newmortal();
                sv_setpv((SV *)svs[i], $1[i]);
        };
        AV *myav = av_make(len, svs);
        free(svs);
        $result = newRV_noinc((SV *)myav);
        sv_2mortal($result);
        argvi++;
}

%typemap(in) char **[] {
        AV *items = (AV *)SvRV($input);
        I32 nitems_min1 = av_len(items);
        $1 = (char ***)malloc((nitems_min1 + 2) * sizeof(char **));
        int i;
        for (i = 0; i <= nitems_min1; i++) {
                SV **refptr = av_fetch(items, i, 0);
                AV *flat = (AV *)SvRV(*refptr);
                I32 nattrs_min1 = av_len(flat);
                $1[i] = (char **)malloc((nattrs_min1 + 2) * sizeof(char *));
                int j;
                for (j = 0; j <= nattrs_min1; j++) {
                        SV **tv = av_fetch(flat, j, 0);
                        $1[i][j] = (char *)SvPV(*tv, PL_na);
                }
                $1[i][j] = NULL;
        }
        $1[i] = NULL;
};
%typemap(freearg) char **[] {
        free($1);
}

%rename("%(strip:[pikul_])s") "";
void pikul_init(enum pikul_company, char *[]);
char *pikul_html(const char *, const char *, double, const char *, const char *, const char *, const char *,
                char *[], char *[]);
char **pikul_codes(const char *, const char *, double);
double pikul_cost(const char *, const char *, double, const char *);
char *pikul_order(const char *, const char *, const char *, const char *, const char *, const char *,
                const char *, const char *, const char *, const char *, const char *, const char *, int,
                char **[], double);
void pikul_cleanup();