2016-07-20 12:15:59 +00:00
|
|
|
#include <string.h>
|
2016-07-16 16:45:39 +00:00
|
|
|
#include <stdio.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2016-07-16 16:45:39 +00:00
|
|
|
|
2016-07-17 19:51:41 +00:00
|
|
|
#include "blaze822.h"
|
2016-07-16 16:45:39 +00:00
|
|
|
|
2016-07-20 11:46:39 +00:00
|
|
|
static int nflag;
|
|
|
|
|
2016-07-16 16:45:39 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2016-07-20 11:46:39 +00:00
|
|
|
int c;
|
|
|
|
while ((c = getopt(argc, argv, "n")) != -1)
|
|
|
|
switch(c) {
|
|
|
|
case 'n': nflag = 1; break;
|
|
|
|
default:
|
|
|
|
// XXX usage
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-07-17 19:51:41 +00:00
|
|
|
char *map = blaze822_seq_open(0);
|
2016-07-16 16:45:39 +00:00
|
|
|
if (!map)
|
|
|
|
return 1;
|
|
|
|
|
2016-07-17 22:09:23 +00:00
|
|
|
int i;
|
|
|
|
char *f;
|
2016-07-20 13:38:24 +00:00
|
|
|
char *a;
|
2016-07-17 22:09:23 +00:00
|
|
|
struct blaze822_seq_iter iter = { 0 };
|
2016-07-20 13:38:24 +00:00
|
|
|
|
|
|
|
if (optind == argc && isatty(0)) {
|
|
|
|
a = ":";
|
|
|
|
i = argc;
|
|
|
|
goto hack;
|
|
|
|
}
|
2016-07-20 11:46:39 +00:00
|
|
|
for (i = optind; i < argc; i++) {
|
2016-07-20 13:38:24 +00:00
|
|
|
a = argv[i];
|
|
|
|
hack:
|
|
|
|
if (strchr(a, '/')) {
|
|
|
|
printf("%s\n", a);
|
2016-07-20 12:15:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-20 13:38:24 +00:00
|
|
|
while ((f = blaze822_seq_next(map, a, &iter))) {
|
2016-07-20 11:46:39 +00:00
|
|
|
if (nflag)
|
|
|
|
printf("%ld\n", iter.line-1);
|
|
|
|
else
|
|
|
|
printf("%s\n", f);
|
2016-07-17 22:09:23 +00:00
|
|
|
free(f);
|
2016-07-16 16:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|