]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring to get rid of the utils.c file
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Apr 2018 01:01:05 +0000 (21:01 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 10 Apr 2018 01:01:05 +0000 (21:01 -0400)
Makefile
inc/edit.h
inc/stdc.h
lib/utils.c [deleted file]
lib/x11.c
tide.c

index a2703c4bda3dd5e35fec632703ca5c6f687d29a7..b01ff21cc842311774980f4aca120531312a0bac 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,6 @@ MAN1 = docs/tide.1
 LIBEDIT_OBJS =     \
        lib/buf.o      \
        lib/utf8.o     \
-       lib/utils.o    \
        lib/job.o      \
        lib/view.o     \
        lib/x11.o      \
index 3354d06c653a4e750e17858f2d520dc897c4a056..527c739a9f4d5fb6a13b3fa4fda6d7af3c68dddb 100644 (file)
@@ -1,8 +1,3 @@
-/* Utility Functions
- *****************************************************************************/
-char* stringdup(const char* str);
-char* strmcat(char* first, ...);
-
 /* Buffer management functions
  *****************************************************************************/
 /* undo/redo list item */
index 3d867aff8af8a0f97c468e78d9ddda3041112fc5..e70805c24a479b4d615b0ca458599497b3ca0227 100644 (file)
@@ -42,10 +42,6 @@ typedef int64_t int64;
 typedef uintptr_t uintptr;
 typedef intptr_t  intptr;
 
-/* Generic Death Function
- *****************************************************************************/
-void die(const char* msgfmt, ...) __attribute__((__noreturn__));
-
 /* Option Parsing
  *
  * This following macros implement a simple POSIX-style option parsing strategy.
diff --git a/lib/utils.c b/lib/utils.c
deleted file mode 100644 (file)
index b44127e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#define _XOPEN_SOURCE 700
-#include <stdc.h>
-#include <utf.h>
-#include <edit.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <time.h>
-#include <sys/time.h>
-
-void die(const char* msgfmt, ...) {
-    va_list args;
-    va_start(args, msgfmt);
-    fprintf(stderr, "error: ");
-    vfprintf(stderr, msgfmt, args);
-    va_end(args);
-    if (*msgfmt && msgfmt[strlen(msgfmt)-1] == ':')
-        fprintf(stderr, " %s", strerror(errno));
-    fprintf(stderr, "\n");
-    exit(EXIT_FAILURE);
-}
-
-char* strmcat(char* first, ...) {
-    va_list args;
-    /* calculate the length of the final string */
-    size_t len = strlen(first);
-    va_start(args, first);
-    for (char* s = NULL; (s = va_arg(args, char*));)
-        len += strlen(s);
-    va_end(args);
-    /* allocate the final string and copy the args into it */
-    char *str  = malloc(len+1), *curr = str;
-    while (first && *first) *(curr++) = *(first++);
-    va_start(args, first);
-    for (char* s = NULL; (s = va_arg(args, char*));)
-        while (s && *s) *(curr++) = *(s++);
-    va_end(args);
-    /* null terminate and return */
-    *curr = '\0';
-    return str;
-}
index c33d098fbea20eec4da4919be338b1e9cfa613ef..e640e0ed866b1a7cd312a2a8c3b4548664afad1a 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -19,6 +19,7 @@
 #undef Region
 
 /******************************************************************************/
+static void die(const char* msg);
 
 static uint32_t special_keys(uint32_t key);
 static uint32_t getkey(XEvent* e);
@@ -272,13 +273,13 @@ XFont x11_font_load(char* name) {
         die("Could not init fontconfig.\n");
     FcPattern* pattern = FcNameParse((FcChar8 *)name);
     if (!pattern)
-        die("can't open font %s\n", name);
+        die("could not parse font name\n");
 
     /* load the base font */
     FcResult result;
     FcPattern* match = XftFontMatch(X.display, X.screen, pattern, &result);
     if (!match || !(font->base.match = XftFontOpenPattern(X.display, match)))
-        die("could not load default font: %s", name);
+        die("could not load base font");
 
     /* get base font extents */
     XGlyphInfo extents;
@@ -783,3 +784,8 @@ static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t
         eol = false, rlen -= numspecs;
     }
 }
+
+static void die(const char* msg) {
+    perror(msg);
+    exit(EXIT_FAILURE);
+}
diff --git a/tide.c b/tide.c
index ee4469bbb3bce63ba360c8b7b721b08b708ea4c3..87f04ac03e29673ce526934651fc54e3c8f60c05 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -80,6 +80,26 @@ static void cmd_exec(char* cmd) {
         job_start(execcmd, input, len, (op != '<' ? curr : edit));
 }
 
+static char* strmcat(char* first, ...) {
+    va_list args;
+    /* calculate the length of the final string */
+    size_t len = strlen(first);
+    va_start(args, first);
+    for (char* s = NULL; (s = va_arg(args, char*));)
+        len += strlen(s);
+    va_end(args);
+    /* allocate the final string and copy the args into it */
+    char *str  = malloc(len+1), *curr = str;
+    while (first && *first) *(curr++) = *(first++);
+    va_start(args, first);
+    for (char* s = NULL; (s = va_arg(args, char*));)
+        while (s && *s) *(curr++) = *(s++);
+    va_end(args);
+    /* null terminate and return */
+    *curr = '\0';
+    return str;
+}
+
 static void cmd_execwitharg(char* cmd, char* arg) {
     cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
     cmd_exec(cmd);