about summary refs log tree commit diff
path: root/mseq.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-18 00:09:23 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-18 00:09:35 +0200
commit08032f89babab3b5ec792f6aa394a28f95112e11 (patch)
tree5a91d63a1c9e3c5f8f0db0aa3a83b667426079e4 /mseq.c
parent7e17d9d631f9d47e9a03901c97a54649cd3542eb (diff)
downloadmblaze-08032f89babab3b5ec792f6aa394a28f95112e11.tar.gz
mblaze-08032f89babab3b5ec792f6aa394a28f95112e11.tar.xz
mblaze-08032f89babab3b5ec792f6aa394a28f95112e11.zip
seq: import most parts of mseq, make blaze822_loop resolve ranges
Diffstat (limited to 'mseq.c')
-rw-r--r--mseq.c130
1 files changed, 6 insertions, 124 deletions
diff --git a/mseq.c b/mseq.c
index 776966d..a700b72 100644
--- a/mseq.c
+++ b/mseq.c
@@ -12,54 +12,6 @@
 
 #include "blaze822.h"
 
-static const char *
-readlin(const char *p)
-{
-        static char b[PATH_MAX];
-        int r = readlink(p, b, sizeof b - 1);
-        if (r < 0)
-		r = 0;
-        b[r] = 0;
-        return b;
-}
-
-char *
-parse_relnum(char *a, long cur, long last, long *out)
-{
-	long base;
-	char *b;
-
-	if (strcmp(a, "+") == 0)
-		a = ".+1";
-	else if (strcmp(a, "-") == 0)
-		a = ".-1";
-	else if (strcmp(a, "$") == 0)
-		a = "-1";
-	
-	if (*a == '.') {
-		a++;
-		base = cur;
-	} else if (*a == '-') {
-		base = last + 1;
-	} else {
-		base = 0;
-	}
-	errno = 0;
-	long d = strtol(a, &b, 10);
-	if (errno != 0) {
-		perror("strtol");
-		exit(1);
-	}
-
-	*out = base + d;
-	if (*out <= 0)
-		*out = 1;
-	if (*out > last)
-		*out = last;
-	
-	return b;
-}
-
 int
 main(int argc, char *argv[])
 {
@@ -67,85 +19,15 @@ main(int argc, char *argv[])
 	if (!map)
 		return 1;
 
-	long lines;
-	long cur = 0;
-
-	const char *curfile = readlin("map.cur");
-	char *curpath;
-
-	char *s, *t;
-	for (s = map, lines = 0; s; s = t) {
-		t = strchr(s+1, '\n');
-		if (!t)
-			break;
-		s++;
-//		printf("{%.*s}\n", t-s, s);
-		lines++;
-		// XXX compare modulo whitespace
-		if (!cur &&
-		    strncmp(s, curfile, strlen(curfile)) == 0 &&
-		    s[strlen(curfile)] == '\n')
-			cur = lines;
-	}
-	lines--;
-
-	long i, start, stop;
+	int i;
+	char *f;
+	struct blaze822_seq_iter iter = { 0 };
 	for (i = 1; i < argc; i++) {
-		char *a = argv[i];
-		start = stop = 0;
-
-		while (*a && *a != ':') {
-			char *b = parse_relnum(a, cur, lines, &start);
-			if (a == b) {
-				printf("huh\n");
-				exit(1);
-			}
-			a = b;
-		}
-		if (*a == ':') {
-			a++;
-			if (!*a) {
-				stop = lines;
-			} else {
-				char *b = parse_relnum(a, cur, lines, &stop);
-				if (a == b) {
-					printf("huh\n");
-					exit(1);
-				}
-				a = b;
-			}
-		} else if (!*a) {
-			stop = start;
-		} else {
-			printf("huh\n");
-			exit(1);
-		}
-
-		long line;
-		for (s = map, line = 0; s; s = t) {
-			t = strchr(s+1, '\n');
-			if (!t)
-				break;
-			s++;
-			line++;
-
-			if (line >= start && line <= stop) {
-				fwrite(s, 1, t-s, stdout);
-				putchar('\n');
-				cur = line;
-				curpath = s;
-				while (*curpath == ' ')
-					curpath++;
-			}
+		while ((f = blaze822_seq_next(map, argv[i], &iter))) {
+			printf("%s\n", f);
+			free(f);
 		}
 	}
 
-/*
-	char *e = strchr(curpath, '\n');
-	unlink("map.cur-");
-	symlink(strndup(curpath, e-curpath), "map.cur-");
-	rename("map.cur-", "map.cur");
-*/
-
 	return 0;
 }