~tokyocabinet/tokyocabinet/c99-posix-trunk

« back to all changes in this revision

Viewing changes to tcucodec.c

  • Committer: Baptiste Lepilleur
  • Date: 2009-07-30 19:32:28 UTC
  • Revision ID: blep@users.sourceforge.net-20090730193228-68fdik1yihz6li9s
Tags: tokyocabinet-1.4.28
releaseĀ 1.4.28

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
static int procbzip(const char *ibuf, int isiz, bool dec);
55
55
static int procxml(const char *ibuf, int isiz, bool dec, bool br);
56
56
static int proccstr(const char *ibuf, int isiz, bool dec, bool js);
57
 
static int procucs(const char *ibuf, int isiz, bool dec, bool un);
 
57
static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw);
58
58
static int prochash(const char *ibuf, int isiz, bool crc, int ch);
59
59
static int procdate(const char *str, int jl, bool wf, bool rf);
60
60
static int proctmpl(const char *ibuf, int isiz, TCMAP *vars);
584
584
  char *path = NULL;
585
585
  bool dec = false;
586
586
  bool un = false;
 
587
  char *kw = NULL;
587
588
  for(int i = 2; i < argc; i++){
588
589
    if(!path && argv[i][0] == '-'){
589
590
      if(!strcmp(argv[i], "-d")){
590
591
        dec = true;
591
592
      } else if(!strcmp(argv[i], "-un")){
592
593
        un = true;
 
594
      } else if(!strcmp(argv[i], "-kw")){
 
595
        if(++i >= argc) usage();
 
596
        kw = argv[i];
593
597
      } else {
594
598
        usage();
595
599
      }
611
615
    eprintf("%s: cannot open", path ? path : "(stdin)");
612
616
    return 1;
613
617
  }
614
 
  int rv = procucs(ibuf, isiz, dec, un);
 
618
  int rv = procucs(ibuf, isiz, dec, un, kw);
615
619
  if(path && path[0] == '@') printf("\n");
616
620
  tcfree(ibuf);
617
621
  return rv;
1087
1091
 
1088
1092
 
1089
1093
/* perform ucs command */
1090
 
static int procucs(const char *ibuf, int isiz, bool dec, bool un){
 
1094
static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw){
1091
1095
  if(un){
1092
1096
    uint16_t *ary = tcmalloc(isiz * sizeof(uint16_t) + 1);
1093
1097
    int anum;
1094
1098
    tcstrutftoucs(ibuf, ary, &anum);
1095
 
    anum = tcstrucsnorm(ary, anum, TCUNLOWER | TCUNNOACC | TCUNSPACE);
 
1099
    anum = tcstrucsnorm(ary, anum, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
1096
1100
    char *str = tcmalloc(anum * 3 + 1);
1097
1101
    tcstrucstoutf(ary, anum, str);
1098
1102
    printf("%s", str);
1099
1103
    tcfree(str);
1100
1104
    tcfree(ary);
 
1105
  } else if(kw){
 
1106
    TCLIST *words = tcstrtokenize(kw);
 
1107
    TCLIST *texts = tcstrkwic(ibuf, words, 10, TCKWMUTAB);
 
1108
    for(int i = 0; i < tclistnum(texts); i++){
 
1109
      printf("%s\n", tclistval2(texts, i));
 
1110
    }
 
1111
    tclistdel(texts);
 
1112
    tclistdel(words);
1101
1113
  } else if(dec){
1102
1114
    uint16_t *ary = tcmalloc(isiz + 1);
1103
1115
    int anum = 0;
1231
1243
    printf("sysconf(_SC_CLK_TCK): %ld\n", sysconf(_SC_CLK_TCK));
1232
1244
    printf("sysconf(_SC_OPEN_MAX): %ld\n", sysconf(_SC_OPEN_MAX));
1233
1245
    printf("sysconf(_SC_PAGESIZE): %ld\n", sysconf(_SC_PAGESIZE));
 
1246
    TCMAP *info = tcsysinfo();
 
1247
    if(info){
 
1248
      const char *val = tcmapget2(info, "size");
 
1249
      if(val) printf("sysinfo(size): %s\n", val);
 
1250
      val = tcmapget2(info, "rss");
 
1251
      if(val) printf("sysinfo(rss): %s\n", val);
 
1252
      val = tcmapget2(info, "total");
 
1253
      if(val) printf("sysinfo(total): %s\n", val);
 
1254
      val = tcmapget2(info, "free");
 
1255
      if(val) printf("sysinfo(free): %s\n", val);
 
1256
      val = tcmapget2(info, "cached");
 
1257
      if(val) printf("sysinfo(cached): %s\n", val);
 
1258
      tcmapdel(info);
 
1259
    }
1234
1260
    struct stat sbuf;
1235
1261
    if(stat(MYCDIRSTR, &sbuf) == 0){
1236
1262
      printf("stat(st_uid): %d\n", (int)sbuf.st_uid);