Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/* duplication callback function */
static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op){
  if(op){
    char *buf = NULL;
    int len = 0;
    switch((int)(intptr_t)op){
      case 1:
        len = vsiz + 1;
        buf = tcmalloc(len + 1);
        memset(buf, '*', len);
        break;
      case 2:
        buf = (void *)-1;
        break;
    }
    *sp = len;
    return buf;
  }
  if(myrand(4) == 0) return (void *)-1;
  if(myrand(2) == 0) return NULL;
  int len = myrand(RECBUFSIZ);
  char buf[RECBUFSIZ];
  memset(buf, '*', len);
  *sp = len;
  return tcmemdup(buf, len);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
/* encode a string as a zero separaterd string */
static char *strtozsv(const char *str, int sep, int *sp){
 int size = strlen(str);
 char *buf = tcmemdup(str, size);
 for(int i = 0; i < size; i++){
   if(buf[i] == sep) buf[i] = '\0';
 }
 *sp = size;
 return buf;
}
Ejemplo n.º 6
0
/* parse arguments of get command */
static int runget(int argc, char **argv) {
    char *path = NULL;
    char *key = NULL;
    TCCMP cmp = NULL;
    int omode = 0;
    bool sx = false;
    bool px = false;
    bool pz = false;
    for (int i = 2; i < argc; i++) {
        if (!path && argv[i][0] == '-') {
            if (!strcmp(argv[i], "-cd")) {
                cmp = tccmpdecimal;
            } else if (!strcmp(argv[i], "-ci")) {
                cmp = tccmpint32;
            } else if (!strcmp(argv[i], "-cj")) {
                cmp = tccmpint64;
            } else if (!strcmp(argv[i], "-nl")) {
                omode |= BDBONOLCK;
            } else if (!strcmp(argv[i], "-nb")) {
                omode |= BDBOLCKNB;
            } else if (!strcmp(argv[i], "-sx")) {
                sx = true;
            } else if (!strcmp(argv[i], "-px")) {
                px = true;
            } else if (!strcmp(argv[i], "-pz")) {
                pz = true;
            } else {
                usage();
            }
        } else if (!path) {
            path = argv[i];
        } else if (!key) {
            key = argv[i];
        } else {
            usage();
        }
    }
    if (!path || !key) usage();
    int ksiz;
    char *kbuf;
    if (sx) {
        kbuf = tchexdecode(key, &ksiz);
    } else {
        ksiz = strlen(key);
        kbuf = tcmemdup(key, ksiz);
    }
    int rv = procget(path, kbuf, ksiz, cmp, omode, px, pz);
    tcfree(kbuf);
    return rv;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
/* parse arguments of convert command */
static int runconvert(int argc, char **argv){
  char *path = NULL;
  int fmt = FMTHTML;
  char *buri = "promenade.cgi";
  char *duri = NULL;
  bool page = false;
  for(int i = 2; i < argc; i++){
    if(!path && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-fw")){
        fmt = FMTWIKI;
      } else if(!strcmp(argv[i], "-ft")){
        fmt = FMTTEXT;
      } else if(!strcmp(argv[i], "-buri")){
        if(++i >= argc) usage();
        buri = argv[i];
      } else if(!strcmp(argv[i], "-duri")){
        if(++i >= argc) usage();
        duri = argv[i];
      } else if(!strcmp(argv[i], "-page")){
        page = true;
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else {
      usage();
    }
  }
  char *ibuf;
  int isiz;
  if(path && path[0] == '@'){
    isiz = strlen(path) - 1;
    ibuf = tcmemdup(path + 1, isiz);
  } else {
    ibuf = tcreadfile(path, IOMAXSIZ, &isiz);
  }
  if(!ibuf){
    eprintf("%s: cannot open", path ? path : "(stdin)");
    return 1;
  }
  int rv = procconvert(ibuf, isiz, fmt, buri, duri, page);
  if(path && path[0] == '@') printf("\n");
  tcfree(ibuf);
  return rv;
}
Ejemplo n.º 9
0
Archivo: tchmgr.c Proyecto: kadoma/fms
/* parse arguments of get command */
static int runget(int argc, char **argv){
  char *path = NULL;
  char *key = NULL;
  int omode = 0;
  bool sx = false;
  bool px = false;
  bool pz = false;
  for(int i = 2; i < argc; i++){
    if(argv[i][0] == '-'){
      if(!strcmp(argv[i], "-nl")){
        omode |= HDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= HDBOLCKNB;
      } else if(!strcmp(argv[i], "-sx")){
        sx = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-pz")){
        pz = true;
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else if(!key){
      key = argv[i];
    } else {
      usage();
    }
  }
  if(!path || !key) usage();
  int ksiz;
  char *kbuf;
  if(sx){
    kbuf = hextoobj(key, &ksiz);
  } else {
    ksiz = strlen(key);
    kbuf = tcmemdup(key, ksiz);
  }
  int rv = procget(path, kbuf, ksiz, omode, px, pz);
  free(kbuf);
  return rv;
}
Ejemplo n.º 10
0
/* parse arguments of get command */
static int runget(int argc, char **argv){
  char *path = NULL;
  char *pkey = NULL;
  int omode = 0;
  bool sx = false;
  bool px = false;
  bool pz = false;
  for(int i = 2; i < argc; i++){
    if(!path && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-nl")){
        omode |= TDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= TDBOLCKNB;
      } else if(!strcmp(argv[i], "-sx")){
        sx = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-pz")){
        pz = true;
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else if(!pkey){
      pkey = argv[i];
    } else {
      usage();
    }
  }
  if(!path || !pkey) usage();
  int pksiz;
  char *pkbuf;
  if(sx){
    pkbuf = tchexdecode(pkey, &pksiz);
  } else {
    pksiz = strlen(pkey);
    pkbuf = tcmemdup(pkey, pksiz);
  }
  int rv = procget(path, pkbuf, pksiz, omode, px, pz);
  tcfree(pkbuf);
  return rv;
}
Ejemplo n.º 11
0
/* parse arguments of put command */
static int runput(int argc, char **argv){
  char *path = NULL;
  char *pkey = NULL;
  TCLIST *vals = tcmpoollistnew(tcmpoolglobal());
  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 |= TDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= TDBOLCKNB;
      } 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(!pkey){
      pkey = argv[i];
    } else {
      tclistpush2(vals, argv[i]);
    }
  }
  if(!path || !pkey) usage();
  TCMAP *cols = tcmapnew();
  char *pkbuf;
  int pksiz;
  if(sx){
    pkbuf = tchexdecode(pkey, &pksiz);
    for(int i = 0; i < tclistnum(vals) - 1; i += 2){
      const char *name = tclistval2(vals, i);
      const char *value = tclistval2(vals, i + 1);
      int nsiz;
      char *nbuf = tchexdecode(name, &nsiz);
      int vsiz;
      char *vbuf = tchexdecode(value, &vsiz);
      tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
      tcfree(vbuf);
      tcfree(nbuf);
    }
  } else {
    pksiz = strlen(pkey);
    pkbuf = tcmemdup(pkey, pksiz);
    for(int i = 0; i < tclistnum(vals) - 1; i += 2){
      const char *name = tclistval2(vals, i);
      const char *value = tclistval2(vals, i + 1);
      tcmapput2(cols, name, value);
    }
  }
  int rv = procput(path, pkbuf, pksiz, cols, omode, dmode);
  tcmapdel(cols);
  tcfree(pkbuf);
  return rv;
}