// gcc -o pdp_set_get_path pdp_set_get_path.c -lpdp
#include <stdio.h>
#include <parsec/pdp.h>
int pdpl_file_set(char *label, char *path)
{
PDPL_T* l;
int r;
if (!path || !label) return 1;
l = pdpl_get_from_text(label);
if (!l) return 1;
r = pdp_set_path(path, l);
pdpl_put(l);
return r;
}
int pdpl_file_get(char *path)
{
PDPL_T* l;
char *pdpl_txt;
if (!path) return 1;
l = pdp_get_lpath(path);
if (!l) return 1;
pdpl_txt = pdpl_get_text(l, 0);
pdpl_put(l);
if (!pdpl_txt) return 1;
printf("%s\n", pdpl_txt);
free(pdpl_txt);
return 0;
}
int main(int argc, char **argv)
{
int r;
if (argc != 2 && argc != 3)
{
fprintf(stderr, "usage: %s [<label>] <file>\n", argv[0]);
return 1;
}
if (argc == 3)
{
r = pdpl_file_set(argv[1], argv[2]);
if (r)
fprintf(stderr, "label set error %d\n", r);
else
fprintf(stderr, "label set success\n");
} else
{
r = pdpl_file_get(argv[1]);
if (r)
fprintf(stderr, "label get error %d\n", r);
else
fprintf(stderr, "label get success\n");
}
return r;
}