Ejemplo n.º 1
0
/* parse arguments of import command */
static int runimport(int argc, char **argv){
  char *dbpath = NULL;
  TCLIST *files = tcmpoollistnew(tcmpoolglobal());
  TCLIST *sufs = tcmpoollistnew(tcmpoolglobal());
  for(int i = 2; i < argc; i++){
    if(!dbpath && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-suf")){
        if(++i >= argc) usage();
        tclistpush2(sufs, argv[i]);
      } else {
        usage();
      }
    } else if(!dbpath){
      dbpath = argv[i];
    } else {
      tclistpush2(files, argv[i]);
    }
  }
  if(!dbpath || tclistnum(files) < 1) usage();
  tclistpush2(sufs, ".tpw");
  int rv = procimport(dbpath, files, sufs);
  return rv;
}
Ejemplo n.º 2
0
/* parse arguments of misc command */
static int runmisc(int argc, char **argv){
  char *name = NULL;
  char *func = NULL;
  TCLIST *args = tcmpoollistnew(tcmpoolglobal());
  bool sx = false;
  int sep = -1;
  bool px = 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 {
        usage();
      }
    } else if(!name){
      name = argv[i];
    } else if(!func){
      func = argv[i];
    } else {
      if(sx){
        int size;
        char *buf = tchexdecode(argv[i], &size);
        tclistpush(args, buf, size);
        tcfree(buf);
      } else if(sep > 0){
        int size;
        char *buf = strtozsv(argv[i], sep, &size);
        tclistpush(args, buf, size);
        tcfree(buf);
      } else {
        tclistpush2(args, argv[i]);
      }
    }
  }
  if(!name || !func) usage();
  int rv = procmisc(name, func, args, sep, px);
  return rv;
}
Ejemplo n.º 3
0
/* parse arguments of search command */
static int runsearch(int argc, char **argv){
  char *path = NULL;
  TCLIST *conds = tcmpoollistnew(tcmpoolglobal());
  char *oname = NULL;
  char *otype = NULL;
  int omode = 0;
  int max = -1;
  int skip = -1;
  bool pv = false;
  bool px = false;
  bool kw = false;
  bool ph = false;
  int bt = 0;
  bool rm = false;
  char *mtype = NULL;
  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], "-ord")){
        if(++i >= argc) usage();
        oname = argv[i];
        if(++i >= argc) usage();
        otype = argv[i];
      } else if(!strcmp(argv[i], "-m")){
        if(++i >= argc) usage();
        max = tcatoix(argv[i]);
      } else if(!strcmp(argv[i], "-sk")){
        if(++i >= argc) usage();
        skip = tcatoix(argv[i]);
      } else if(!strcmp(argv[i], "-kw")){
        kw = true;
      } else if(!strcmp(argv[i], "-pv")){
        pv = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-ph")){
        ph = true;
      } else if(!strcmp(argv[i], "-bt")){
        if(++i >= argc) usage();
        bt = tcatoix(argv[i]);
      } else if(!strcmp(argv[i], "-rm")){
        rm = true;
      } else if(!strcmp(argv[i], "-ms")){
        if(++i >= argc) usage();
        mtype = argv[i];
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else {
      tclistpush2(conds, argv[i]);
    }
  }
  if(!path || tclistnum(conds) % 3 != 0) usage();
  int rv = procsearch(path, conds, oname, otype, omode, max, skip,
                      pv, px, kw, ph, bt, rm, mtype);
  return rv;
}
Ejemplo n.º 4
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;
}