]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added utility function to chomp off newlines
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Nov 2016 01:42:31 +0000 (20:42 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Nov 2016 01:42:31 +0000 (20:42 -0500)
inc/edit.h
libedit/utils.c
xedit.c

index 4c94f258f7f490b911432a3c3f6f1137e2f145c3..2eefce0f27d899c8b0ddd5df55d17d18b710286f 100644 (file)
@@ -12,6 +12,7 @@ bool risword(Rune r);
 bool risblank(Rune r);
 char* stringdup(const char* str);
 char* fdgets(int fd);
+char* chomp(char* in);
 
 /* Buffer management functions
  *****************************************************************************/
index 674c704e60dda7143bcf562d8faeb96f9e3c0925..70e52c929654a55936d18664eccc1aa92c50d728 100644 (file)
@@ -74,3 +74,7 @@ char* fdgets(int fd) {
     if (str) str[len] = '\0';
     return str;
 }
+
+char* chomp(char* in) {
+    return strtok(in, "\r\n");
+}
diff --git a/xedit.c b/xedit.c
index 6820019862afb67e54562a2051bf76bde3cfaaf1..3db2bdfb359fbae6f608dd3c2663f5bcfafd2fa9 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -481,7 +481,7 @@ static void find(char* arg) {
 static void open_file(void) {
     char* file = cmdread(PickFileCmd, NULL);
     if (file) {
-        file[strlen(file)-1] = '\0';
+        file = chomp(file);
         if (!getbuf(EDIT)->path && !getbuf(EDIT)->modified) {
             buf_load(getbuf(EDIT), file);
         } else {
@@ -528,9 +528,6 @@ static void tag_exec(Tag* tag, char* arg) {
     free(arg);
 }
 
-static char* chomp(char* in) {
-    return (in[strlen(in)-1] = '\0', in);
-}
 static void cmd_exec(char* cmd) {
     char op = '\0';
     if (*cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>')