]> git.mdlowis.com Git - projs/tide.git/commitdiff
removed old tools and moved scripts to bin folder
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 10 Oct 2018 01:20:06 +0000 (21:20 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 10 Oct 2018 01:20:06 +0000 (21:20 -0400)
13 files changed:
Makefile
bin/tfetch [moved from tfetch with 100% similarity]
bin/topen [moved from topen with 100% similarity]
reader.c [deleted file]
src/tide.c [moved from tide.c with 100% similarity]
tests/lib/win.c
tools/c+ [deleted file]
tools/c- [deleted file]
tools/i+ [deleted file]
tools/i- [deleted file]
tools/lang [deleted file]
tools/trim [deleted file]
xcpd.c [deleted file]

index 13310ff7b4e1ffd5c9c50476a4f3c685101dc324..f2a4d827fce59434863067d14ea837a50dfd3163 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,6 @@ clean:
 install:
        mkdir -p $(PREFIX)/bin
        cp -f tide $(PREFIX)/bin
-       cp -f xcpd $(PREFIX)/bin
 
 uninstall:
        rm -f $(PREFIX)/bin/tide
@@ -51,12 +50,11 @@ gcov:
 libedit.a: $(LIBEDIT_OBJS)
        $(AR) $(ARFLAGS) $@ $^
 
-tide: tide.o libedit.a
-xcpd: xcpd.o libedit.a
+tide: src/tide.o libedit.a
 tests/libedit: tests/libedit.o tests/lib/buf.o tests/lib/utf8.o tests/lib/win.o libedit.a
 
 # define implicit rule for building binaries
-%: %.o
+%: src/%.o
        $(LD) -o $@ $^ $(LDFLAGS)
 
 # load generate dependencies
similarity index 100%
rename from tfetch
rename to bin/tfetch
diff --git a/topen b/bin/topen
similarity index 100%
rename from topen
rename to bin/topen
diff --git a/reader.c b/reader.c
deleted file mode 100644 (file)
index 2d16962..0000000
--- a/reader.c
+++ /dev/null
@@ -1,258 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <regex.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#include <stdbool.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#define nelem(x) (sizeof(x)/sizeof((x)[0]))
-
-#ifdef __MACH__
-    #define OPENCMD "open"
-#else
-    #define OPENCMD "xdg-open"
-#endif
-
-typedef struct {
-    enum {
-        COMPLETE=0, MATCHES, IS, ISSET, ISDIR, ISFILE,
-        SET, UNSET, FINDFILE, EXEC, LAUNCH
-    } type;
-    char* arg1;
-    char* arg2;
-} Rule;
-
-char* Matches[10];
-
-Rule* BuiltinRules[] = {
-    (Rule[]){ // Look up .c or .h files in Code/
-        { ISSET, "EDITOR", NULL },
-        { MATCHES, "data", "\\.[ch]$" },
-        { ISDIR, "Code", NULL },
-        { EXEC, "[[ $(find Code -type f -name '*$data') ]]", NULL },
-        { LAUNCH, "find Code -type f -name '*$data' | xargs -r $EDITOR", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-    (Rule[]){ // Match URLS and open them with the browser
-        { ISSET, "BROWSER", NULL },
-        { MATCHES, "data", "^(https?|ftp)://.*" },
-        { LAUNCH, "$BROWSER $0", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-    (Rule[]){ // Open files with addresses in the editor
-        { ISSET, "EDITOR", NULL },
-        { MATCHES, "data", "^([^:]+):([0-9]+)" },
-        { ISFILE, "$1", NULL },
-        { LAUNCH, "tctl $0", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-    (Rule[]){ // If it's an existing text file, open it with editor
-        { ISSET, "EDITOR", NULL },
-        { ISFILE, "$data", NULL },
-        { EXEC, "file --mime '$file' | grep -q 'text/'", NULL },
-        { LAUNCH, "$EDITOR '$file'", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-    (Rule[]){ // Look it up in ctags database
-        { ISSET, "EDITOR", NULL },
-        { ISFILE, "tags", NULL },
-        { EXEC, "grep -q '^$data\\s\\+' tags", NULL },
-        { LAUNCH, "picktag fetch tags '$data' | xargs -r tide", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-    (Rule[]){ // If it's an existing directory, open it with system default
-        { ISDIR, "$data", NULL },
-        { LAUNCH, OPENCMD " $data", NULL },
-        { COMPLETE, NULL, NULL }
-    },
-};
-
-/******************************************************************************/
-
-char* getvar(char* val) {
-    if (strlen(val) == 1 && isdigit(*val))
-        val = Matches[*val - '0'];
-    else
-        val = getenv(val);
-    return (val ? val : "");
-}
-
-char* eval(char* str) {
-    static bool inited = false;
-    static char* patt = "\\$([a-zA-Z0-9_]+)";
-    static regex_t regex;
-
-    if (!inited && (regcomp(&regex, patt, REG_EXTENDED) < 0)) {
-        perror("regcomp() :");
-        exit(1);
-    }
-
-    regmatch_t matches[2] = {0};
-    if (regexec(&regex, str, nelem(matches), matches, 0) < 0) {
-        return str;
-    } else if (matches[1].rm_so > 0) {
-        char* var = strndup(str+matches[1].rm_so, matches[1].rm_eo-matches[1].rm_so);
-        char* val = getvar(var);
-        size_t sz = strlen(str) + strlen(val);
-        char* exp = calloc(1, sz);
-        strncat(exp, str, matches[0].rm_so);
-        strcat(exp, val);
-        strcat(exp, str + matches[0].rm_eo);
-        return eval(exp);
-    } else {
-        return str;
-    }
-}
-
-/******************************************************************************/
-
-bool matches(char* var, char* patt) {
-    regex_t regex = {0};
-    regmatch_t matches[10] = {0};
-    if (regcomp(&regex, patt, REG_EXTENDED) == 0) {
-        var = getvar(var);
-        memset(Matches, 0, sizeof(Matches));
-        int err = regexec(&regex, var, nelem(matches), matches, 0);
-        for (int i = 0; i < 10 && matches[i].rm_so >= 0; i++) {
-            Matches[i] = strndup(var+matches[i].rm_so, matches[i].rm_eo-matches[i].rm_so);
-        }
-        return (err == 0);
-    }
-    return false;
-}
-
-bool var_is(char* var, char* val) {
-    return (strcmp(getvar(var), eval(val)) == 0);
-}
-
-bool var_isset(char* var) {
-    return (getenv(var) != NULL);
-}
-
-bool var_isdir(char* var) {
-    struct stat st = {0};
-    char* path = eval(var);
-    if ((stat(path, &st) < 0) && (errno == ENOENT)) {
-        return false;
-    } else if (S_ISDIR(st.st_mode)) {
-        setenv("dir", var, 1);
-        return true;
-    } else {
-        return false;
-    }
-}
-
-bool var_isfile(char* var) {
-    struct stat st = {0};
-    char* path = eval(var);
-    if ((stat(eval(var), &st) < 0) && (errno == ENOENT)) {
-        return false;
-    } else if (!S_ISDIR(st.st_mode)) {
-        setenv("file", path, 1);
-        return true;
-    } else {
-        return false;
-    }
-}
-
-bool var_set(char* var, char* val) {
-    return (setenv(var, eval(val), 1) == 0);
-}
-
-bool var_unset(char* var) {
-    return (unsetenv(var) == 0);
-}
-
-bool find_file(char* file) {
-    return false;
-}
-
-void runcmd(char* cmd) {
-    char* shellcmd[] = { getvar("SHELL"), "-c", NULL, NULL };
-    if (!shellcmd[0]) shellcmd[0] = "/bin/sh";
-    shellcmd[2] = eval(cmd);
-    _exit(execvp(shellcmd[0], shellcmd));
-}
-
-bool exec(char* cmd) {
-    int pid, status, outpipe[2];
-    if ((pid = fork()) < 0) return false;
-    if (pid == 0) {
-        runcmd(cmd);
-    } else {
-        waitpid(pid, &status, 0);
-        return (status == 0);
-    }
-    return false;
-}
-
-bool launch(char* cmd) {
-    int pid = fork();
-    if (pid > 0)
-        return true;
-    else if (pid == 0)
-        runcmd(cmd);
-    return false;
-}
-
-bool apply_rule(Rule* rule) {
-    switch (rule->type) {
-        case COMPLETE: exit(0);
-        case MATCHES:  return matches(rule->arg1, rule->arg2);
-        case IS:       return var_is(rule->arg1, rule->arg2);
-        case ISSET:    return var_isset(rule->arg1);
-        case ISDIR:    return var_isdir(rule->arg1);
-        case ISFILE:   return var_isfile(rule->arg1);
-        case SET:      return var_set(rule->arg1, rule->arg2);
-        case UNSET:    return var_unset(rule->arg1);
-        case FINDFILE: return find_file(rule->arg1);
-        case EXEC:     return exec(rule->arg1);
-        case LAUNCH:   return launch(rule->arg1);
-    }
-    return false;
-}
-
-void apply_ruleset(char* text) {
-    setenv("data", text, 1);
-    for (int i = 0; i < nelem(BuiltinRules); i++) {
-        Rule* rule = BuiltinRules[i];
-        for (; rule->type != COMPLETE; rule++)
-            if (!apply_rule(rule))
-                break;
-        if (rule->type == COMPLETE)
-            exit(0);
-    }
-}
-
-/******************************************************************************/
-
-int fifo_open(char* path, mode_t mode) {
-    mkfifo(path, mode);
-    int fd = open(path, O_WRONLY|O_NONBLOCK);
-    if (fd >= 0) { close(fd); return -1; }
-    return open(path, O_RDONLY);
-}
-
-int main(int argc, char** argv) {
-    int ret = 0, nread, fd = fifo_open("./myfifo", 0655);
-    if (fd >= 0) {
-        char buf[1024];
-        while ((nread = read(fd, buf, sizeof(buf)-1)) >= 0) {
-            if (nread == 0) continue;
-            buf[nread] = '\0';
-            printf("fetch: '%s'\n", buf);
-            if (fork() == 0) apply_ruleset(buf);
-        }
-    } else {
-        perror("open()");
-        ret = 1;
-    }
-    return ret;
-}
similarity index 100%
rename from tide.c
rename to src/tide.c
index e4b8e55bb0c507cdd8cdb9eb5e003dddf168b84c..257adda6322b4833c4f2b82439c04365878a4474 100644 (file)
@@ -1,6 +1,6 @@
 #define _XOPEN_SOURCE 700
 #include <atf.h>
-#include "tide.c"
+#include "src/tide.c"
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
diff --git a/tools/c+ b/tools/c+
deleted file mode 100755 (executable)
index fa23571..0000000
--- a/tools/c+
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-case "$(lang "$file")" in
-    C) sed 's/^/\/\//g' "$@" ;;
-    *) sed 's/^/#/g' "$@" ;;
-esac
diff --git a/tools/c- b/tools/c-
deleted file mode 100644 (file)
index 93107ad..0000000
--- a/tools/c-
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-case "$(lang "$file")" in
-    C) sed 's/^\/\///g' "$@" ;;
-    *) sed 's/^#//g' "$@" ;;
-esac
diff --git a/tools/i+ b/tools/i+
deleted file mode 100755 (executable)
index 13a0f95..0000000
--- a/tools/i+
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-case "$(lang "$file")" in
-    ML|Python|Ruby)
-        sed 's/^/  /g' "$@" ;;
-    *)  sed 's/^/    /g' "$@" ;;
-esac
diff --git a/tools/i- b/tools/i-
deleted file mode 100755 (executable)
index a9ec504..0000000
--- a/tools/i-
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-case "$(lang "$file")" in
-    ML|Python|Ruby)
-        sed 's/^  //g' "$@" ;;
-    *)  sed 's/^    //g' "$@" ;;
-esac
diff --git a/tools/lang b/tools/lang
deleted file mode 100755 (executable)
index 8c1806f..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-case "$1" in
-    *.c|*.cpp|*.cc|*.h|*.hpp)
-        echo "C" ;;
-    *.ml) echo "ML" ;;
-    *.py) echo "Python" ;;
-    *.rb) echo "Ruby" ;;
-    *)    echo "Text" ;;
-esac
diff --git a/tools/trim b/tools/trim
deleted file mode 100755 (executable)
index e50e722..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-sed 's/ *$//g' "$@"
diff --git a/xcpd.c b/xcpd.c
deleted file mode 100644 (file)
index b1a2782..0000000
--- a/xcpd.c
+++ /dev/null
@@ -1,68 +0,0 @@
-#include <stdc.h>
-#include <utf.h>
-#include <edit.h>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/Xft/Xft.h>
-#include <unistd.h>
-
-char* SelText;     // The text of the clipboard selection
-Atom SelType;      // The X11 selection name. Always CLIPBOARD
-Atom SelTarget;    // The conversion target for the selection (always string or utf8)
-Display* XDisplay; // Handle for the X connection
-Window XRoot;      // The root X window
-Window XWindow;    // Our window used to serve the selection up
-
-void serve_selection(void) {
-    if (!(XDisplay = XOpenDisplay(0)))
-        die("could not open display");
-    XRoot = DefaultRootWindow(XDisplay);
-    XWindow = XCreateSimpleWindow(XDisplay, XRoot, 0, 0, 1, 1, 0, 0, 0);
-    SelType   = XInternAtom(XDisplay, "CLIPBOARD", 0);
-    SelTarget = XInternAtom(XDisplay, "UTF8_STRING", 0);
-    if (SelTarget == None)
-        SelTarget = XInternAtom(XDisplay, "STRING", 0);
-    XSetSelectionOwner(XDisplay, SelType, XWindow, CurrentTime);
-
-    for (XEvent e;;) {
-        XNextEvent(XDisplay, &e);
-        if (e.type == SelectionRequest) {
-            XEvent s;
-            s.xselection.type      = SelectionNotify;
-            s.xselection.property  = e.xselectionrequest.property;
-            s.xselection.requestor = e.xselectionrequest.requestor;
-            s.xselection.selection = e.xselectionrequest.selection;
-            s.xselection.target    = e.xselectionrequest.target;
-            s.xselection.time      = e.xselectionrequest.time;
-            Atom target    = e.xselectionrequest.target;
-            Atom xatargets = XInternAtom(XDisplay, "TARGETS", 0);
-            Atom xastring  = XInternAtom(XDisplay, "STRING", 0);
-            if (target == xatargets) {
-                /* respond with the supported type */
-                XChangeProperty(
-                    XDisplay, s.xselection.requestor, s.xselection.property,
-                    XA_ATOM, 32, PropModeReplace,
-                    (unsigned char*)&SelTarget, 1);
-            } else if (target == SelTarget || target == xastring) {
-                XChangeProperty(
-                    XDisplay, s.xselection.requestor, s.xselection.property,
-                    SelTarget, 8, PropModeReplace,
-                    (unsigned char*)SelText, strlen(SelText));
-            }
-            XSendEvent(XDisplay, s.xselection.requestor, True, 0, &s);
-        } else if (e.type == SelectionClear) {
-            break; // Someone else took over. We're done here.
-        }
-    }
-}
-
-int main(int argc, char** argv) {
-    SelText = fdgets(STDIN_FILENO);
-    if (SelText) {
-        if (daemonize() == 0)
-            serve_selection();
-        else
-            die("daemonize() failed");
-    }
-    return 0;
-}