mblaze/mseq.c

54 lines
783 B
C
Raw Normal View History

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;
int i;
char *f;
char *a;
struct blaze822_seq_iter iter = { 0 };
if (optind == argc && isatty(0)) {
a = ":";
i = argc;
goto hack;
}
2016-07-20 11:46:39 +00:00
for (i = optind; i < argc; i++) {
a = argv[i];
hack:
if (strchr(a, '/')) {
printf("%s\n", a);
2016-07-20 12:15:59 +00:00
continue;
}
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);
free(f);
2016-07-16 16:45:39 +00:00
}
}
return 0;
}