summaryrefslogtreecommitdiff
path: root/buff.c
diff options
context:
space:
mode:
Diffstat (limited to 'buff.c')
-rw-r--r--buff.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/buff.c b/buff.c
index 89ca82f..aa66a67 100644
--- a/buff.c
+++ b/buff.c
@@ -1,4 +1,5 @@
#include "buff.h"
+#include <regex.h>
line_t* __search_pos(int addr){
@@ -108,6 +109,8 @@ void print_lines(char lineno){
int move_to_line(int addr, char print){
+ fprintf(stderr, " >>>> move_to_line: addr: %d pos: %d\n", addr, pos);
+
if (addr > num)
return -1;
else if (addr >= 0){
@@ -307,3 +310,59 @@ int write_lines(){
printf("%d\n", tot);
return 0;
}
+
+/* match either forward (bw=0) or backward (bw=1)*/
+int match(char **c, char bw){
+
+ char sep = **c, *tmp;
+ line_t *ptr;
+ regex_t re;
+ int l;
+
+ if (bw)
+ tmp = strtok(*c, "?\n");
+ else
+ tmp = strtok(*c, "/\n");
+ fprintf(stderr, " >>>> string to match: \"%s\" bw: %d\n", tmp, bw);
+ if (!tmp)
+ return -1;
+
+ if (regcomp(&re, tmp, REG_EXTENDED)){
+ return -1;
+ }
+ *c += strlen(tmp);
+ l = pos;
+ ptr = cur;
+ do {
+ fprintf(stderr, ".");
+ if (bw){
+ ptr = ptr->prev;
+ l = (l-1 + num) % num;
+ if (!ptr){
+ /* FIXME: if we keep b_end updated we can avoid this search */
+ ptr = __search_pos(num);
+ l = num;
+ }
+ }
+ else{
+ ptr = ptr->next;
+ l = (l+1) % num;
+ if (! ptr){
+ ptr = b_start;
+ l = 1;
+ }
+ }
+ if (!l) l = num;
+ if (!regexec(&re, (char *) ptr->c , (size_t) 0, NULL, 0)){
+ regfree(&re);
+ return l;
+ }
+ fprintf(stderr, " %d\n", l);
+ } while(l != pos);
+ fprintf(stderr, " >>>> match: returning\n");
+ regfree(&re);
+ return -1;
+}
+
+
+