diff options
author | Steve Bennett <steveb@workware.net.au> | 2014-01-05 17:18:16 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-01-15 07:46:33 +1000 |
commit | 65820c9d0e90fb082e8399ad13bc654ac7c1a547 (patch) | |
tree | 580a56edd79b65346214822129e942976cd36796 | |
parent | bc451e3f792dc06662b40250f9dcbbd600ac2baf (diff) | |
download | jimtcl-65820c9d0e90fb082e8399ad13bc654ac7c1a547.zip jimtcl-65820c9d0e90fb082e8399ad13bc654ac7c1a547.tar.gz jimtcl-65820c9d0e90fb082e8399ad13bc654ac7c1a547.tar.bz2 |
exec: remove duplicate code
Two versions of the "trim trailing space" function
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim-exec.c | 23 |
1 files changed, 5 insertions, 18 deletions
@@ -166,6 +166,10 @@ static const char *JimStrError(void) return strerror(JimErrno()); } +/* + * If the last character of 'objPtr' is a newline, then remove + * the newline character. + */ static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr) { int len; @@ -203,23 +207,6 @@ static int JimAppendStreamToString(Jim_Interp *interp, fdtype fd, Jim_Obj *strOb return JIM_OK; } -/* - * If the last character of the result is a newline, then remove - * the newline character (the newline would just confuse things). - * - * Note: Ideally we could do this by just reducing the length of stringrep - * by 1, but there is no API for this :-( - */ -static void JimTrimTrailingNewline(Jim_Interp *interp) -{ - int len; - const char *p = Jim_GetString(Jim_GetResult(interp), &len); - - if (len > 0 && p[len - 1] == '\n') { - Jim_SetResultString(interp, p, len - 1); - } -} - /** * Builds the environment array from $::env * @@ -1133,7 +1120,7 @@ static int JimCleanupChildren(Jim_Interp *interp, int numPids, pidtype *pidPtr, } } - JimTrimTrailingNewline(interp); + Jim_RemoveTrailingNewline(Jim_GetResult(interp)); return result; } |