about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-08-31 15:37:36 -0400
committerJune McEnroe <june@causal.agency>2017-08-31 15:37:36 -0400
commit2aa5fe545bdba997bdb728a2dfb2e3bca93766ae (patch)
treea7c529bf45c3a713538fcc4d7dbdeb88e8e7f322
parentChoose B for tiles with equal modify times (diff)
downloadtorus-2aa5fe545bdba997bdb728a2dfb2e3bca93766ae.tar.gz
torus-2aa5fe545bdba997bdb728a2dfb2e3bca93766ae.zip
Clean up merge tool
Choose the version with the most recent access if the modify times are
the same.
-rw-r--r--merge.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/merge.c b/merge.c
index e5a5f64..3390c59 100644
--- a/merge.c
+++ b/merge.c
@@ -56,62 +56,59 @@ static void drawTile(int offsetY, const struct Tile *tile) {
 int main(int argc, char *argv[]) {
     if (argc != 4) return EX_USAGE;
 
-    int a = open(argv[1], O_RDONLY);
-    if (a < 0) err(EX_IOERR, "%s", argv[1]);
+    int fileA = open(argv[1], O_RDONLY);
+    if (fileA < 0) err(EX_IOERR, "%s", argv[1]);
 
-    int b = open(argv[2], O_RDONLY);
-    if (b < 0) err(EX_IOERR, "%s", argv[2]);
+    int fileB = open(argv[2], O_RDONLY);
+    if (fileB < 0) err(EX_IOERR, "%s", argv[2]);
 
-    int c = open(argv[3], O_WRONLY | O_CREAT, 0644);
-    if (c < 0) err(EX_IOERR, "%s", argv[3]);
+    int fileC = open(argv[3], O_WRONLY | O_CREAT, 0644);
+    if (fileC < 0) err(EX_IOERR, "%s", argv[3]);
 
     initscr();
     cbreak();
     noecho();
     keypad(stdscr, true);
     set_escdelay(100);
+
     start_color();
     for (int bg = COLOR_BLACK; bg < COLOR_BRIGHT; ++bg) {
         for (int fg = COLOR_BLACK; fg < COLOR_BRIGHT; ++fg) {
             init_pair(bg << 4 | fg, fg, bg);
         }
     }
+
     mvhline(CELL_ROWS, 0, 0, CELL_COLS);
+    mvhline(CELL_ROWS * 2 + 1, 0, 0, CELL_COLS);
+    mvvline(0, CELL_COLS, 0, CELL_ROWS * 2 + 1);
+    mvaddch(CELL_ROWS, CELL_COLS, ACS_RTEE);
+    mvaddch(CELL_ROWS * 2 + 1, CELL_COLS, ACS_LRCORNER);
 
     struct Tile tileA, tileB;
     for (;;) {
-        ssize_t lenA = read(a, &tileA, sizeof(tileA));
+        ssize_t lenA = read(fileA, &tileA, sizeof(tileA));
         if (lenA < 0) err(EX_IOERR, "%s", argv[1]);
 
-        ssize_t lenB = read(b, &tileB, sizeof(tileB));
+        ssize_t lenB = read(fileB, &tileB, sizeof(tileB));
         if (lenB < 0) err(EX_IOERR, "%s", argv[2]);
 
         if (!lenA && !lenB) break;
         if (!lenA || !lenB) errx(EX_IOERR, "different size inputs");
 
-        if (tileA.modify == tileB.modify) {
-            ssize_t lenC = writeAll(c, (char *)&tileB, sizeof(tileB));
-            if (lenC < 0) err(EX_IOERR, "%s", argv[3]);
-            continue;
-        }
+        const struct Tile *tileC = (tileA.access > tileB.access) ? &tileA : &tileB;
+
+        if (tileA.modify != tileB.modify) {
+            drawTile(0, &tileA);
+            drawTile(CELL_ROWS + 1, &tileB);
+            move(CELL_ROWS * 2 + 2, 0);
+            refresh();
 
-        drawTile(0, &tileA);
-        drawTile(CELL_ROWS + 1, &tileB);
-        refresh();
-
-        const struct Tile *choice;
-        int ch;
-retry:
-        ch = getch();
-        if (ch == 'a') {
-            choice = &tileA;
-        } else if (ch == 'b') {
-            choice = &tileB;
-        } else {
-            goto retry;
+            int c;
+            do { c = getch(); } while (c != 'a' && c != 'b');
+            tileC = (c == 'a') ? &tileA : &tileB;
         }
 
-        ssize_t lenC = writeAll(c, (char *)choice, sizeof(*choice));
+        ssize_t lenC = writeAll(fileC, (char *)tileC, sizeof(*tileC));
         if (lenC < 0) err(EX_IOERR, "%s", argv[3]);
     }
 
lass='logmsg'> Installing mandoc from pkgsrc also installs a man executable which is horribly broken. Keep using the system man. 2019-02-20Set man_hard_wrap in nvimJune McEnroe Vendoring man.vim until <https://github.com/neovim/neovim/pull/9633> is merged and appears in a release. 2019-02-18Use hi -o anchor in upJune McEnroe 2019-02-18Don't match nested parentheses in Tag for CJune McEnroe Fixes mistaken highlight of: pngWrite(file, (uint8_t []) { 0, 0, 0 }, 3); 2019-02-18Match whitespace between * [] {}June McEnroe 2019-02-18Fix function-like #define regexJune McEnroe A define like #define FOO (1) is not function-like. 2019-02-18Match Tag in RustJune McEnroe 2019-02-18Match sh functions as TagJune McEnroe 2019-02-18Match Sh and Ss as Tag in mdocJune McEnroe 2019-02-18Match statics and typedefs as TagJune McEnroe 2019-02-18Clean up htmlHeaderJune McEnroe 2019-02-18Remove hi line numberingJune McEnroe Tags are much better for referring to specific parts of a file and line numbering is better done by a post-processing tool such as cat -n or producing a two-column HTML <table>. 2019-02-18Add Tag class to hiJune McEnroe 2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe Running hi twice to insert stuff between the head and the content is a bit of a hack but oh well. 2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe 2019-02-17Simplify temp trap in upJune McEnroe 2019-02-17Add line numbers to hiJune McEnroe Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow. 2019-02-17Always split spans after newlinesJune McEnroe Simplifies ANSI and IRC output code, and prepares for line numbered output. 2019-02-15Color format specifiers light cyan in vimJune McEnroe 2019-02-15Highlight Interp as yellowJune McEnroe 2019-02-15Highlight strings in sh command substitutionsJune McEnroe 2019-02-15Add nmap gpJune McEnroe 2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe 2019-02-13Add forgotten "sixth" book of H2G2June McEnroe