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
|
template:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#define MAX_SZ 100
int map[MAX_SZ];
#define MPL_SUCCESS 0
#define MPL_ERR_FAIL 1
#define MPL_malloc(sz,t) malloc(sz)
#define MPL_realloc(p,sz,t) realloc(p,sz)
#define MPL_free free
[src/mpl/src/mpl_rankmap.c:MPL_rankmap_array_to_str]
int main(int argc, char **argv)
{
int sz = argc - 1;
if (sz > MAX_SZ) {
printf("sz exceeds limit (%d > %d)\n", sz, MAX_SZ);
return 1;
}
for (int i = 0; i < sz; i++) {
map[i] = atoi(argv[1 + i]);
}
char *str;
int err = MPL_rankmap_array_to_str(map, sz, &str);
if (err) {
printf("err = 0x%x\n", err);
return 1;
}
if (str == NULL) {
printf("str is NULL\n");
return 1;
}
printf("%s\n", str);
return 0;
}
TESTS:
cmd: ./t 3 2 1 0
expect: (vector,3,2,1,0)
cmd: ./t 1 2 3 0
expect: (vector,(1,3,1),0)
cmd: ./t 0 0 0 0 1 1 1 1 2 2 2 2
expect: (vector,(0,3,4))
cmd: ./t 0 1 2 0 1 2 0 1 2 0 1 2
expect: (vector,[(0,3,1)]x4)
cmd: ./t 1 2 3 0 1 2 3 0 1 2 3 0
expect: (vector,[(1,3,1),0]x3)
|