Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/woip/c/searcher.c
blob: 5532313aa68e7b327bb3c7de4169182fb54324e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "search.h"

int returned;
int maxres = 10;
char needle[MAXLINE];

bool print_match(char *s, uint32_t block) {
  returned++;
  printf("%s %d\n", s, block);
  if(returned < maxres) return true;
  else return false;
}

void usage(char *name) {
  fprintf(stderr, "%s -f <indexFile> -s <search> [-m <maxres>] [-d]\n", name);
  exit(-1);
}

int main(int argc, char **argv) {
  char ch, indexFile[MAXLINE];
  bool printTree = false, printCmd = false;

  while ((ch = getopt(argc, argv, "cm:s:idf:hp")) != -1) {
    switch (ch) {
    case 'c':
      printCmd = true;
      break;  
    case 's':
      strcpy(needle, optarg);
      break;
    case 'd':
      debug = true;
      break;
    case 'f':
      strcpy(indexFile, optarg);
      break;
    case 'm':
      maxres = atoi(optarg);
      break;
    case 'i':
      csen_set(false);
      break;
    case 'p':
      printTree = true;
      break;
    case 'h':
    default:
      usage(argv[0]);
    }
  }

  load_root(indexFile);
  if(printTree) print_tree();
  else if(printCmd) print_cmd();
  else if(!needle[0] || !indexFile[0])
    usage(argv[0]);
  else {
    root_search(needle, print_match);
    printf("%d matches\n", returned);
  }

  return 0;
}