Esempio n. 1
0
extern int
tcvp_close_skin(skin_t *s)
{
    widget_data_t *wd;

    xtk_widget_t *win = s->window;

    wd = xtk_widget_get_data(win);

    unregister_textwidget(win, wd->value);
    if(wd->action) free(wd->action);
    if(wd->value) free(wd->value);
    tcfree(wd);

    xtk_window_destroy(win);

    ui_count--;
    if(ui_count == 0) {
        tcvp_quit();
    }

    tcfree(s);

    return 0;
}
Esempio n. 2
0
File: conf.c Progetto: rvs/libtc
static void
tcconf_free(void *p)
{
    tcconf_section_t *s = p;
    tcfree(s->sec);
    if(s->parent)
	tcfree(s->parent);
}
Esempio n. 3
0
/* Delete a word database object. */
void tcwdbdel(TCWDB *wdb){
  assert(wdb);
  if(wdb->open) tcwdbclose(wdb);
  tcbdbdel(wdb->idx);
  pthread_rwlock_destroy(wdb->mmtx);
  tcfree(wdb->mmtx);
  tcfree(wdb);
}
Esempio n. 4
0
/* perform list command */
static int proclist(const char *path, int omode, int max, bool pv, bool px,
                    const char *rlstr, const char *rustr, const char *ristr){
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
    printerr(fdb);
    tcfdbdel(fdb);
    return 1;
  }
  bool err = false;
  if(rlstr || ristr){
    TCLIST *keys = ristr ? tcfdbrange5(fdb, ristr, max) : tcfdbrange3(fdb, rlstr, rustr, max);
    for(int i = 0; i < tclistnum(keys); i++){
      int ksiz;
      const char *kbuf = tclistval(keys, i, &ksiz);
      printf("%s", kbuf);
      if(pv){
        int vsiz;
        char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px);
          tcfree(vbuf);
        }
      }
      putchar('\n');
    }
    tclistdel(keys);
  } else {
    if(!tcfdbiterinit(fdb)){
      printerr(fdb);
      err = true;
    }
    int cnt = 0;
    uint64_t id;
    while((id = tcfdbiternext(fdb)) > 0){
      printf("%llu", (unsigned long long)id);
      if(pv){
        int vsiz;
        char *vbuf = tcfdbget(fdb, id, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px);
          tcfree(vbuf);
        }
      }
      putchar('\n');
      if(max >= 0 && ++cnt >= max) break;
    }
  }
  if(!tcfdbclose(fdb)){
    if(!err) printerr(fdb);
    err = true;
  }
  tcfdbdel(fdb);
  return err ? 1 : 0;
}
Esempio n. 5
0
/* parse arguments of put command */
static int runput(int argc, char **argv){
  char *name = NULL;
  char *key = NULL;
  char *value = NULL;
  int dmode = 0;
  bool sx = false;
  int sep = -1;
  for(int i = 2; i < argc; i++){
    if(!name && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-dk")){
        dmode = -1;
      } else if(!strcmp(argv[i], "-dc")){
        dmode = 1;
      } else if(!strcmp(argv[i], "-dai")){
        dmode = 10;
      } else if(!strcmp(argv[i], "-dad")){
        dmode = 11;
      } else if(!strcmp(argv[i], "-sx")){
        sx = true;
      } else if(!strcmp(argv[i], "-sep")){
        if(++i >= argc) usage();
        sep = sepstrtochr(argv[i]);
      } else {
        usage();
      }
    } else if(!name){
      name = argv[i];
    } else if(!key){
      key = argv[i];
    } else if(!value){
      value = argv[i];
    } else {
      usage();
    }
  }
  if(!name || !key || !value) usage();
  char *kbuf, *vbuf;
  int ksiz, vsiz;
  if(sx){
    kbuf = tchexdecode(key, &ksiz);
    vbuf = tchexdecode(value, &vsiz);
  } else if(sep > 0){
    kbuf = strtozsv(key, sep, &ksiz);
    vbuf = strtozsv(value, sep, &vsiz);
  } else {
    ksiz = strlen(key);
    kbuf = tcmemdup(key, ksiz);
    vsiz = strlen(value);
    vbuf = tcmemdup(value, vsiz);
  }
  int rv = procput(name, kbuf, ksiz, vbuf, vsiz, dmode);
  tcfree(vbuf);
  tcfree(kbuf);
  return rv;
}
Esempio n. 6
0
/* parse arguments of put command */
static int runput(int argc, char **argv){
  char *path = NULL;
  char *key = NULL;
  char *value = NULL;
  int omode = 0;
  int dmode = 0;
  bool sx = false;
  for(int i = 2; i < argc; i++){
    if(!path && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-nl")){
        omode |= FDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= FDBOLCKNB;
      } else if(!strcmp(argv[i], "-dk")){
        dmode = -1;
      } else if(!strcmp(argv[i], "-dc")){
        dmode = 1;
      } else if(!strcmp(argv[i], "-dai")){
        dmode = 10;
      } else if(!strcmp(argv[i], "-dad")){
        dmode = 11;
      } else if(!strcmp(argv[i], "-sx")){
        sx = true;
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else if(!key){
      key = argv[i];
    } else if(!value){
      value = argv[i];
    } else {
      usage();
    }
  }
  if(!path || !key || !value) usage();
  char *kbuf, *vbuf;
  int ksiz, vsiz;
  if(sx){
    kbuf = tchexdecode(key, &ksiz);
    vbuf = tchexdecode(value, &vsiz);
  } else {
    ksiz = strlen(key);
    kbuf = tcmemdup(key, ksiz);
    vsiz = strlen(value);
    vbuf = tcmemdup(value, vsiz);
  }
  int rv = procput(path, kbuf, ksiz, vbuf, vsiz, omode, dmode);
  tcfree(vbuf);
  tcfree(kbuf);
  return rv;
}
Esempio n. 7
0
static VALUE cDB_values(VALUE vself){
  VALUE vary;
  TCRDB *db;
  char *kxstr, *vxstr;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
  vary = rb_ary_new2(tcrdbrnum(db));
  tcrdbiterinit(db);
  while((kxstr = tcrdbiternext2(db)) != NULL){
    vxstr = tcrdbget2(db, kxstr);
    rb_ary_push(vary, rb_str_new2(vxstr));
    tcfree(vxstr);
    tcfree(kxstr);
  }
  return vary;
}
Esempio n. 8
0
File: conf.c Progetto: rvs/libtc
extern int
tcconf_clearvalue(tcconf_section_t *ts, char *name)
{
    conf_section *sec = NULL;
    char *n = strdup(name);
    char *p = strrchr(n, '/');
    tcconf_section_t *s = NULL;
    int c = 0;

    if(p){
	*p++ = 0;
	if((s = tcconf_getsection(ts, n)))
	sec = s->sec;
    } else {
	p = n;
	sec = ts->sec;
    }

    if(sec)
	c = tclist_delete_matched(sec->entries, p, cmp_str_sec, tcfree);
    if(s)
	tcfree(s);

    free(n);
    return c;
}
Esempio n. 9
0
/* get */
JNIEXPORT jbyteArray JNICALL Java_tokyocabinet_BDB_get
(JNIEnv *env, jobject self, jbyteArray key){
  if(!key){
    throwillarg(env);
    return NULL;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return NULL;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  int vsiz;
  char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
  jbyteArray val;
  if(vbuf){
    val = (*env)->NewByteArray(env, vsiz);
    if(!val){
      throwoutmem(env);
      return NULL;
    }
    (*env)->SetByteArrayRegion(env, val, 0, vsiz, (jbyte *)vbuf);
    tcfree(vbuf);
  } else {
    val = NULL;
  }
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return val;
}
Esempio n. 10
0
static VALUE cDB_each_value(VALUE vself){
  VALUE vrv;
  TCRDB *db;
  char *kxstr, *vxstr;
  if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given");
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
  vrv = Qnil;
  tcrdbiterinit(db);
  while((kxstr = tcrdbiternext2(db)) != NULL){
    vxstr = tcrdbget2(db, kxstr);
    vrv = rb_yield_values(1, rb_str_new2(vxstr));
    tcfree(vxstr);
    tcfree(kxstr);
  }
  return vrv;
}
Esempio n. 11
0
static xtk_widget_t*
create_skinned_background(xtk_widget_t *c, skin_t *skin,
                          tcconf_section_t *sec, tchash_table_t *parameters)
{
    char *file = NULL;
    int i = 0;
    image_t *img = NULL;
    xtk_widget_t *w;

    i += tcconf_getvalue(sec, "background", "%s", &file);
    img = load_image(skin->path, file);

    if(img)
        i++;

    if(i != 2)
        return NULL;

    w = xtk_widget_image_create(c, 0, 0, c->width, c->height);
    xtk_widget_image_set_image(w, img);
    xtk_widget_show(w);

    xtk_widget_container_set_shape(c, img);

    free(file);
    tcfree(img);

    return (xtk_widget_t*)c;
}
Esempio n. 12
0
/* RTDBIterItemsType.tp_iternext */
static PyObject *
RTDBIterItems_tp_iternext(DBIter *self)
{
    RDBBase *rdbbase = (RDBBase *)self->db;
    void *key;
    int key_size;
    TCMAP *value;
    PyObject *pykey, *pyvalue, *pyresult = NULL;

    if (rdbbase->changed) {
        return set_error(Error, "DB changed during iteration");
    }
    Py_BEGIN_ALLOW_THREADS
    key = tcrdbiternext(rdbbase->rdb, &key_size);
    if (key) {
        value = tcrdbtblget(rdbbase->rdb, key, key_size);
    }
    Py_END_ALLOW_THREADS
    if (!key) {
        if (tcrdbecode(rdbbase->rdb) == TTENOREC) {
            return set_stopiteration_error();
        }
        return set_rdb_error(rdbbase->rdb, NULL);
    }
    pykey = void_to_bytes(key, key_size);
    pyvalue = tcmap_to_dict(value);
    if (pykey && pyvalue) {
        pyresult = PyTuple_Pack(2, pykey, pyvalue);
    }
    Py_XDECREF(pykey);
    Py_XDECREF(pyvalue);
    tcfree(key);
    tcmapdel(value);
    return pyresult;
}
Esempio n. 13
0
File: conf.c Progetto: rvs/libtc
static void
vsfree(v_state *vs)
{
    free(vs->n);
    tcfree(vs->ts);
    free(vs);
}
Esempio n. 14
0
extern void
widgetdata_free(void *p)
{
    widget_data_t *wd = p;

    tcfree(wd->skin);
}
Esempio n. 15
0
/* RTDBIterValuesKeysType.tp_iternext */
static PyObject *
RTDBIterValuesKeys_tp_iternext(DBIter *self)
{
    RDBBase *rdbbase = (RDBBase *)self->db;
    void *key;
    int key_size;
    TCMAP *value;
    TCLIST *valuekeys;
    PyObject *pyvaluekeys;

    if (rdbbase->changed) {
        return set_error(Error, "DB changed during iteration");
    }
    Py_BEGIN_ALLOW_THREADS
    key = tcrdbiternext(rdbbase->rdb, &key_size);
    if (key) {
        value = tcrdbtblget(rdbbase->rdb, key, key_size);
    }
    Py_END_ALLOW_THREADS
    if (!key) {
        if (tcrdbecode(rdbbase->rdb) == TTENOREC) {
            return set_stopiteration_error();
        }
        return set_rdb_error(rdbbase->rdb, NULL);
    }
    valuekeys = tcmapkeys(value);
    pyvaluekeys = tclist_to_tuple(valuekeys);
    tcfree(key);
    tcmapdel(value);
    tclistdel(valuekeys);
    return pyvaluekeys;
}
Esempio n. 16
0
/* FDBIterValuesType.tp_iternext */
static PyObject *
FDBIterValues_tp_iternext(DBIter *self)
{
    FDB *fdb = (FDB *)self->db;
    long long key;
    void *value;
    int value_size;
    PyObject *pyvalue;

    if (fdb->changed) {
        return set_error(Error, "FDB changed during iteration");
    }
    key = uint64_to_int64(tcfdbiternext(fdb->fdb));
    if (key == -1) {
        return NULL;
    }
    else if (!key) {
        if (tcfdbecode(fdb->fdb) == TCENOREC) {
            return set_stopiteration_error();
        }
        return set_fdb_error(fdb->fdb, 0);
    }
    value = tcfdbget(fdb->fdb, key, &value_size);
    pyvalue = void_to_bytes(value, value_size);
    tcfree(value);
    return pyvalue;
}
Esempio n. 17
0
/* thread the read function */
static void *threadread(void *targ){
  TCFDB *fdb = ((TARGREAD *)targ)->fdb;
  int rnum = ((TARGREAD *)targ)->rnum;
  bool wb = ((TARGREAD *)targ)->wb;
  bool rnd = ((TARGREAD *)targ)->rnd;
  int id = ((TARGREAD *)targ)->id;
  bool err = false;
  int base = id * rnum;
  for(int i = 1; i <= rnum && !err; i++){
    uint64_t kid = base + (rnd ? myrandnd(i) + 1 : i);
    int vsiz;
    if(wb){
      char vbuf[RECBUFSIZ];
      int vsiz = tcfdbget4(fdb, kid, vbuf, RECBUFSIZ);
      if(vsiz < 0 && (!rnd || tcfdbecode(fdb) != TCENOREC)){
        eprint(fdb, __LINE__, "tcfdbget4");
        err = true;
      }
    } else {
      char *vbuf = tcfdbget(fdb, kid, &vsiz);
      if(!vbuf && (!rnd || tcfdbecode(fdb) != TCENOREC)){
        eprint(fdb, __LINE__, "tcfdbget");
        err = true;
      }
      tcfree(vbuf);
    }
    if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
    }
  }
  return err ? "error" : NULL;
}
Esempio n. 18
0
/* parse arguments of map command */
static int runmap(int argc, char **argv){
  char *name = NULL;
  char *dest = NULL;
  char *fmstr = NULL;
  for(int i = 2; i < argc; i++){
    if(!name && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-fm")){
        if(++i >= argc) usage();
        fmstr = argv[i];
      } else {
        usage();
      }
    } else if(!name){
      name = argv[i];
    } else if(!dest){
      dest = argv[i];
    } else {
      usage();
    }
  }
  if(!name || !dest) usage();
  name = tcsprintf("%s#mode=r", name);
  int rv = procmap(name, dest, fmstr);
  tcfree(name);
  return rv;
}
Esempio n. 19
0
/* parse arguments of update command */
static int runupdate(int argc, char **argv){
  char *dbpath = NULL;
  char *idstr = NULL;
  char *file = NULL;
  for(int i = 2; i < argc; i++){
    if(!dbpath && argv[i][0] == '-'){
      usage();
    } else if(!dbpath){
      dbpath = argv[i];
    } else if(!idstr){
      idstr = argv[i];
    } else if(!file){
      file = argv[i];
    } else {
      usage();
    }
  }
  if(!dbpath || !idstr) usage();
  int64_t id = tcatoi(idstr);
  char *ibuf;
  int isiz;
  if(file && file[0] == '@'){
    isiz = strlen(file) - 1;
    ibuf = tcmemdup(file + 1, isiz);
  } else {
    ibuf = tcreadfile(file, -1, &isiz);
  }
  if(!ibuf){
    eprintf("%s: cannot open", file ? file : "(stdin)");
    return 1;
  }
  int rv = procupdate(dbpath, id, ibuf);
  tcfree(ibuf);
  return rv;
}
Esempio n. 20
0
/* perform get command */
static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz){
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
    printerr(fdb);
    tcfdbdel(fdb);
    return 1;
  }
  bool err = false;
  int vsiz;
  char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
  if(vbuf){
    printdata(vbuf, vsiz, px);
    if(!pz) putchar('\n');
    tcfree(vbuf);
  } else {
    printerr(fdb);
    err = true;
  }
  if(!tcfdbclose(fdb)){
    if(!err) printerr(fdb);
    err = true;
  }
  tcfdbdel(fdb);
  return err ? 1 : 0;
}
Esempio n. 21
0
/* perform get command */
static int procget(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode,
        bool px, bool pz) {
    TCBDB *bdb = tcbdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
    if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
    if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
    if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
        printerr(bdb);
        tcbdbdel(bdb);
        return 1;
    }
    bool err = false;
    int vsiz;
    char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
    if (vbuf) {
        printdata(vbuf, vsiz, px);
        if (!pz) putchar('\n');
        tcfree(vbuf);
    } else {
        printerr(bdb);
        err = true;
    }
    if (!tcbdbclose(bdb)) {
        if (!err) printerr(bdb);
        err = true;
    }
    tcbdbdel(bdb);
    return err ? 1 : 0;
}
Esempio n. 22
0
/* perform get command */
static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  int vsiz;
  char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
  if(vbuf){
    printdata(vbuf, vsiz, px);
    if(!pz) putchar('\n');
    tcfree(vbuf);
  } else {
    printerr(hdb);
    err = true;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
Esempio n. 23
0
static void *
event_loop(void *p)
{
    event_handler_t *eh = p;
    tcvp_event_type_handler_t *handlers = eh->handlers;
    void *data = eh->data;
    eventq_t q = eh->q;
    int run = 1;

    eh->running = 1;
    eh = NULL;

    while(run) {
        tcvp_event_t *te = eventq_recv(q);
        tcvp_event_type_handler_t *h = handlers;
        while(h->handler) {
            if(h->type == te->type) {
                h->handler(data, te);
                break;
            }
            h++;
        }

        if(te->type == -1)
            run = 0;

        tcfree(te);
    }

    return NULL;
}
Esempio n. 24
0
extern int
send_eventv(eventq_t q, int type, va_list args)
{
    tcvp_event_t *te = NULL;
    int ret = -1;

    if(type == -1) {
        te = tcalloc(sizeof(*te));
        te->type = -1;
    } else if(type <= event_num && event_tab[type] && event_tab[type]->alloc) {
        te = event_tab[type]->alloc(type, args);
    } else {
        tc2_print("EVENT", TC2_PRINT_WARNING, "unknown event #%i\n", type);
    }

    if(te) {
        if(type >= 0)
            tc2_print("EVENT", TC2_PRINT_DEBUG,
                      "sending %s\n", event_tab[type]->name);
        ret = eventq_send(q, te);
        tcfree(te);
    }

    return ret;
}
Esempio n. 25
0
/* FDBIterItemsType.tp_iternext */
static PyObject *
FDBIterItems_tp_iternext(DBIter *self)
{
    FDB *fdb = (FDB *)self->db;
    long long key;
    void *value;
    int value_size;
    PyObject *pykey, *pyvalue, *pyresult = NULL;

    if (fdb->changed) {
        return set_error(Error, "FDB changed during iteration");
    }
    key = uint64_to_int64(tcfdbiternext(fdb->fdb));
    if (key == -1) {
        return NULL;
    }
    else if (!key) {
        if (tcfdbecode(fdb->fdb) == TCENOREC) {
            return set_stopiteration_error();
        }
        return set_fdb_error(fdb->fdb, 0);
    }
    value = tcfdbget(fdb->fdb, key, &value_size);
    pykey = PyLong_FromLongLong(key);
    pyvalue = void_to_bytes(value, value_size);
    if (pykey && pyvalue) {
        pyresult = PyTuple_Pack(2, pykey, pyvalue);
    }
    Py_XDECREF(pykey);
    Py_XDECREF(pyvalue);
    tcfree(value);
    return pyresult;
}
Esempio n. 26
0
/* perform importtsv command */
static int procimporttsv(const char *path, const char *file, int omode, bool sc){
  FILE *ifp = file ? fopen(file, "rb") : stdin;
  if(!ifp){
    fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
    return 1;
  }
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    if(ifp != stdin) fclose(ifp);
    return 1;
  }
  bool err = false;
  char *line;
  int cnt = 0;
  while(!err && (line = mygetline(ifp)) != NULL){
    char *pv = strchr(line, '\t');
    if(!pv){
      tcfree(line);
      continue;
    }
    *pv = '\0';
    if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
    if(!tchdbput2(hdb, line, pv + 1)){
      printerr(hdb);
      err = true;
    }
    tcfree(line);
    if(cnt > 0 && cnt % 100 == 0){
      putchar('.');
      fflush(stdout);
      if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
    }
    cnt++;
  }
  printf(" (%08d)\n", cnt);
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  if(ifp != stdin) fclose(ifp);
  return err ? 1 : 0;
}
Esempio n. 27
0
static void *tcddbget(TCDDB *ddb, const void *kbuf, int ksiz, int *sp){
  if(!ddb->name) return false;
  void *vbuf;
  char *path = makepath(ddb, kbuf, ksiz);
  vbuf = tcreadfile(path, -1, sp);
  tcfree(path);
  return vbuf;
}
Esempio n. 28
0
static bool tcddbput(TCDDB *ddb, const void *kbuf, int ksiz, const void *vbuf, int vsiz){
  if(!ddb->name) return false;
  bool err = false;
  char *path = makepath(ddb, kbuf, ksiz);
  if(!tcwritefile(path, vbuf, vsiz)) err = true;
  tcfree(path);
  return !err;
}
Esempio n. 29
0
/* parse arguments of get command */
static int runget(int argc, char **argv){
  char *name = NULL;
  char *key = NULL;
  bool sx = false;
  int sep = -1;
  bool px = false;
  bool pz = false;
  for(int i = 2; i < argc; i++){
    if(!name && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-sx")){
        sx = true;
      } else if(!strcmp(argv[i], "-sep")){
        if(++i >= argc) usage();
        sep = sepstrtochr(argv[i]);
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-pz")){
        pz = true;
      } else {
        usage();
      }
    } else if(!name){
      name = argv[i];
    } else if(!key){
      key = argv[i];
    } else {
      usage();
    }
  }
  if(!name || !key) usage();
  int ksiz;
  char *kbuf;
  if(sx){
    kbuf = tchexdecode(key, &ksiz);
  } else if(sep > 0){
    kbuf = strtozsv(key, sep, &ksiz);
  } else {
    ksiz = strlen(key);
    kbuf = tcmemdup(key, ksiz);
  }
  name = tcsprintf("%s#mode=r", name);
  int rv = procget(name, kbuf, ksiz, sep, px, pz);
  tcfree(name);
  tcfree(kbuf);
  return rv;
}
Esempio n. 30
0
static bool tcddbout(TCDDB *ddb, const void *kbuf, int ksiz){
  if(!ddb->name) return false;
  bool err = false;
  char *path = makepath(ddb, kbuf, ksiz);
  if(unlink(path) != 0) err = true;
  tcfree(path);
  return !err;
}