about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichal Mazurek <akfaew@jasminek.net>2012-03-04 13:29:00 +0100
committerMichal Mazurek <akfaew@jasminek.net>2012-03-04 13:29:00 +0100
commitc303971def63e3810937ddb683bbddfa38595ed7 (patch)
treeeba5a5c889cf1659f74a08ed214c95be6964c5bd
parent076f60a9df019caaf6401369a11b4b8fd223c536 (diff)
downloadxombrero-c303971def63e3810937ddb683bbddfa38595ed7.tar.gz
* simplify marks code, no more magic loops
* separate quickmarks from marks
-rw-r--r--xxxterm.c53
-rw-r--r--xxxterm.h5
2 files changed, 31 insertions, 27 deletions
diff --git a/xxxterm.c b/xxxterm.c
index c9650ad..c5705a6 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -358,43 +358,44 @@ history_read(struct command_list *list, char *file, int *counter)
 	return (0);
 }
 
-/* marks and quickmarks array storage.
- * first a-z, then A-Z, then 0-9 */
+/* marks array storage. */
 char
 indextomark(int i)
 {
-	if (i < 0)
+	if (i < 0 || i >= XT_NOMARKS)
 		return (0);
 
-	if (i >= 0 && i <= 'z' - 'a')
-		return 'a' + i;
+	return XT_MARKS[i];
+}
 
-	i -= 'z' - 'a' + 1;
-	if (i >= 0 && i <= 'Z' - 'A')
-		return 'A' + i;
+int
+marktoindex(char m)
+{
+	char *ret;
 
-	i -= 'Z' - 'A' + 1;
-	if (i >= 10)
-		return (0);
+	if ((ret = strchr(XT_MARKS, m)) != NULL)
+		return ret - XT_MARKS;
 
-	return i + '0';
+	return (-1);
 }
 
-int
-marktoindex(char m)
+/* quickmarks array storage. */
+char
+indextoqmark(int i)
 {
-	int ret = 0;
+	if (i < 0 || i >= XT_NOQMARKS)
+		return (0);
 
-	if (m >= 'a' && m <= 'z')
-		return ret + m - 'a';
+	return XT_QMARKS[i];
+}
 
-	ret += 'z' - 'a' + 1;
-	if (m >= 'A' && m <= 'Z')
-		return ret + m - 'A';
+int
+qmarktoindex(char m)
+{
+	char *ret;
 
-	ret += 'Z' - 'A' + 1;
-	if (m >= '0' && m <= '9')
-		return ret + m - '0';
+	if ((ret = strchr(XT_QMARKS, m)) != NULL)
+		return ret - XT_QMARKS;
 
 	return (-1);
 }
@@ -4944,7 +4945,7 @@ qmarks_load(void)
 		p = strtok(line, " \t");
 
 		if (p == NULL || strlen(p) != 1 ||
-		    (index = marktoindex(*p)) == -1) {
+		    (index = qmarktoindex(*p)) == -1) {
 			warnx("corrupt quickmarks file, line %d", i);
 			break;
 		}
@@ -4975,7 +4976,7 @@ qmarks_save(void)
 
 	for (i = 0; i < XT_NOMARKS; i++)
 		if (qmarks[i] != NULL)
-			fprintf(f, "%c %s\n", indextomark(i), qmarks[i]);
+			fprintf(f, "%c %s\n", indextoqmark(i), qmarks[i]);
 
 	fclose(f);
 
@@ -4989,7 +4990,7 @@ qmark(struct tab *t, struct karg *arg)
 	int		index;
 
 	mark = arg->s[strlen(arg->s)-1];
-	index = marktoindex(mark);
+	index = qmarktoindex(mark);
 	if (index == -1)
 		return (-1);
 
diff --git a/xxxterm.h b/xxxterm.h
index 38d9cfc..51c0bd5 100644
--- a/xxxterm.h
+++ b/xxxterm.h
@@ -159,7 +159,10 @@ extern uint32_t	swm_debug;
 				    ~(GDK_BUTTON4_MASK) &	\
 				    ~(GDK_BUTTON5_MASK))
 
-#define XT_NOMARKS		(('z' - 'a' + 1) * 2 + 10)
+#define XT_MARKS		"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+#define XT_NOMARKS		(sizeof(XT_MARKS) - 1)
+#define XT_QMARKS		"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+#define XT_NOQMARKS		(sizeof(XT_QMARKS) - 1)
 
 /* Path Separator */
 #ifndef	PS