diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-20 00:11:56 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-20 00:11:56 +0800 |
commit | 1264915af1cd1f47a34873360c4e88ae73a1bd33 (patch) | |
tree | c98c331871a559fe47df921e5ffd515257e53b39 | |
parent | 0f4b2281ee59811e72a9975dd019891eb334683e (diff) |
Function to get list of just the service codes
-rw-r--r-- | pikul.c | 15 | ||||
-rw-r--r-- | pikul.h | 1 | ||||
-rw-r--r-- | pikul.i | 16 |
3 files changed, 32 insertions, 0 deletions
@@ -174,6 +174,21 @@ static int servicecmp(const void *service1, const void *service2) (*(struct pikul_service * const *)service2)->code); } +char **pikul_codes(const char *origin, const char *destination, double weight) +{ + char **codes = malloc(sizeof(char *)); + codes[0] = NULL; + struct pikul_services *services = pikul_services(origin, destination, weight); + if (!services || !services->length) + return codes; + codes = realloc(codes, (services->length + 1) * sizeof(char *)); + size_t i = 0; + for (i = 0; i < services->length; i++) + codes[i] = services->list[i]->code; + codes[i] = NULL; + return codes; +} + double pikul_cost(const char *origin, const char *destination, double weight, const char *code) { struct pikul_services *services = pikul_services(origin, destination, weight); @@ -24,6 +24,7 @@ extern "C" { void pikul_init(enum pikul_company company, char *provisions[]); struct pikul_services *pikul_services(const char *origin, const char *destination, double weight); void pikul_free_services(struct pikul_services *services); +char **pikul_codes(const char *origin, const char *destination, double weight); double pikul_cost(const char *origin, const char *destination, double weight, const char *service); char *pikul_order(const char *order_number, const char *service, const char *sender_name, const char *sender_phone, const char *origin, const char *sender_address, @@ -17,6 +17,21 @@ %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); @@ -43,6 +58,7 @@ %rename("%(strip:[pikul_])s") ""; void pikul_init(enum pikul_company, 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, |