]> granicus.if.org Git - graphviz/commitdiff
rephrase unnecessarily cryptic string comparisons in lefty
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 6 Mar 2021 22:09:53 +0000 (14:09 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Mar 2021 03:48:26 +0000 (20:48 -0700)
13 files changed:
cmd/lefty/aix_mods/exec.c
cmd/lefty/dot2l/dotlex.c
cmd/lefty/exec.c
cmd/lefty/g.c
cmd/lefty/internal.c
cmd/lefty/lex.c
cmd/lefty/os/unix/io.c
cmd/lefty/ws/gtk/gcanvas.c
cmd/lefty/ws/mswin32/gcanvas.c
cmd/lefty/ws/mswin32/gpcanvas.c
cmd/lefty/ws/x11/gbutton.c
cmd/lefty/ws/x11/gcanvas.c
cmd/lefty/ws/x11/gpcanvas.c

index cad42210d0c4e522f1cd3ccf461f2c515eee5979..7fb826b9fbeb97befbb02f58676f8a6187f3d0c5 100644 (file)
@@ -17,6 +17,7 @@
 #include "str.h"
 #include "exec.h"
 #include "internal.h"
+#include <string.h>
 
 static lvar_t *lvarp;
 static int lvarn, llvari, flvari;
@@ -985,7 +986,7 @@ static void printbody(char *s, int mode)
     }
     c = '\000';
     for (s1 = s; *s1; s1++)
-       if (*s1 == '>' && *(s1 + 1) && *(s1 + 1) == '>')
+       if (strncmp(s1, ">>", 2) == 0)
            break;
     if (!*s1)
        return;
index e75d36d70349693c4bbae411712be78a16c7344e..c404913adcaf2fdd86b3b508919df0285857c45f 100644 (file)
@@ -16,6 +16,7 @@ typedef void *Tobj;
 #include "dot2l.h"
 #include "leftyio.h"
 #include "triefa.c"
+#include <string.h>
 
 static int syntax_errors;
 static int lexer_fd;
@@ -67,7 +68,7 @@ int yylex (void) {
 
     /* get a nonempty lex buffer */
     do {
-        if ((lexptr == NULL) || (lexptr[0] == '\0'))
+        if ((lexptr == NULL) || strcmp(lexptr, "") == 0)
             if ((lexptr = lex_gets (0)) == NULL) {
                 if (in_comment)
                     fprintf (
@@ -78,7 +79,7 @@ int yylex (void) {
                 return EOF;
             }
         lexptr = skip_wscomments (lexptr);
-    } while (lexptr[0] == '\0');
+    } while (strcmp(lexptr, "") == 0);
 
     /* scan quoted strings */
     if (lexptr[0] == '\"') {
@@ -249,7 +250,7 @@ static char *scan_token (char *p) {
     char *q;
 
     q = lexbuf;
-    if (!p || *p == '\0')
+    if (!p || strcmp(p, "") == 0)
         return NULL;
     while (isalnum (*p) || (*p == '_') || (!isascii (*p)))
         *q++ = *p++;
@@ -307,7 +308,7 @@ static char *quoted_string (char *p) {
         }
         *q++ = *p++;
     }
-    if (*p == '\0')
+    if (strcmp(p, "") == 0)
         yyerror ("string ran past end of line", "");
     else
         p++;
index d838e605a8803e686033e685cd5f2e7c4a213720..9b33af78aebd66cc98342a447e1c9f3603002622 100644 (file)
@@ -17,6 +17,7 @@
 #include "str.h"
 #include "exec.h"
 #include "internal.h"
+#include <string.h>
 
 static lvar_t *lvarp;
 static int lvarn, llvari, flvari;
@@ -989,7 +990,7 @@ static void printbody (char *s, int mode) {
     }
     c = '\000';
     for (s1 = s; *s1; s1++)
-        if (*s1 == '>' && *(s1 + 1) && *(s1 + 1) == '>')
+        if (strncmp(s1, ">>", 2) == 0)
             break;
     if (!*s1)
         return;
index 6bf11c824cd67d1d095292b3a7126b701b3a0d57..a9c9ff51f847388d07ca361b0c34abb9e587adfa 100644 (file)
@@ -14,6 +14,7 @@
 #include "g.h"
 #include "gcommon.h"
 #include "mem.h"
+#include <string.h>
 
 Gwidget_t *Gwidgets;
 int Gwidgetn;
@@ -587,7 +588,7 @@ int Gtext (
         return -1;
     }
     widget = &Gwidgets[wi];
-    if (string[0] == '\000')
+    if (strcmp(string, "") == 0)
         return 0;
     n = unpackstring (string);
     if (!justs[0] || !justs[1])
@@ -622,7 +623,7 @@ int Ggettextsize (int wi, char *string, char *fn, double fs, Gsize_t *gsp) {
         Gerr (POS, G_ERRNOTACANVAS, wi);
         return -1;
     }
-    if (string[0] == '\000') {
+    if (strcmp(string, "") == 0) {
         gsp->x = gsp->y = 0.0;
         return 0;
     }
index 04c2010ef0d8e34e2a4921fb8b964a7ac5f49f1e..f084c9a0c5b08ffcd30f3efc8ed7c50deb9ea21b 100644 (file)
@@ -28,6 +28,7 @@
 #include "gmap2l.h"
 #endif
 #include "internal.h"
+#include <string.h>
 #ifndef FEATURE_MS
 #include <sys/time.h>
 #endif
@@ -404,7 +405,7 @@ int Isplit (int argc, lvar_t *argv) {
     qflag = (argc == 3) ? FALSE : TRUE;
     sp = Tgetstring (so);
     s = Tgetstring (fo);
-    if (s[0] == '\\' && s[1] == 'n')
+    if (strncmp(s, "\\n", 2) == 0)
         fc = '\n';
     else
         fc = s[0];
@@ -616,7 +617,7 @@ int Iload (int argc, lvar_t *argv) {
     Tobj co;
 
     if ((fn = Tgetstring (argv[0].o))) {
-        if (fn[0] == '-' && fn[1] == '\000')
+        if (strcmp(fn, "-") == 0)
             fp = stdin;
         else {
             fp = NULL;
index ab03138724b506f28702abcb5efad14bfbf8da04..793a49de0edec18da0cf5284fd7b5a2b9e64947d 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "common.h"
 #include "lex.h"
+#include <string.h>
 
 int Ltok;
 char Lstrtok[MAXTOKEN];
@@ -237,7 +238,7 @@ static int gtok (void) {
 static int sgetc (void) {
     if (seeneof)
         return EOF;
-    if (*ucp == '\000') {
+    if (strcmp(ucp, "") == 0) {
         if (lsrc == CHARSRC) {
             seeneof = TRUE;
             linenum++;
index 1cb17fefbb8ba6b2d1ac6d1ea674435b8e03102f..0e34ee8caec08cfbdec3d76f19c2d9a39f043b69 100644 (file)
@@ -18,6 +18,7 @@
 #include "mem.h"
 #include <fcntl.h>
 #include <signal.h>
+#include <string.h>
 #include <sys/wait.h>
 #ifndef HAVE_TERMIOS_H
 #include <termio.h>
@@ -418,7 +419,7 @@ static void pipeopen (char *cmd, FILE **ifp, FILE **ofp, int *pidp) {
     case 0:
         close (p1[0]), close (p2[1]);
         for (s = cmd; *s; s++)
-            if (*s == '%' && *(s + 1) && *(s + 1) == 'd') {
+            if (strncmp(s, "%d", 2) == 0) {
                 sprintf (cmd2, cmd, p2[0], p1[1]);
                 execl (shell, shbname, "-c", cmd2, NULL);
                 panic2 (POS, "pipeopen", "child cannot exec: %s\n", cmd2);
index 57f0b7516adba995f5904a56b1650bc193a1a7bd..4d07718182fe214103b5592be7d4311a9e43ab81 100644 (file)
@@ -12,6 +12,7 @@
 #include "common.h"
 #include "g.h"
 #include "gcommon.h"
+#include <string.h>
 
 #define WCU widget->u.c
 #define WINDOW widget->u.c->window
@@ -646,7 +647,7 @@ static GdkFont *findfont(char *name, int size)
     GdkFont *font;
     int fi, n, i;
 
-    if (name[0] == '\000')
+    if (strcmp(name, "") == 0)
        return Gfontp[0].font;
 
     sprintf(&Gbufp[0], name, size);
index f8621d54da73621fa204275b022092369500c885..47f839c7d8bb76d2dc0d40d41a1e5818e962c94c 100644 (file)
@@ -14,6 +14,7 @@
 #include "g.h"
 #include "gcommon.h"
 #include "mem.h"
+#include <string.h>
 
 #define WCU widget->u.c
 #define WINDOW widget->u.c->window
@@ -761,7 +762,7 @@ static HFONT findfont (char *name, int size) {
     HFONT font;
     int fi;
 
-    if (name[0] == '\000')
+    if (strcmp(name, "") == 0)
         return Gfontp[0].font;
 
     sprintf (&Gbufp[0], name, size);
index 8af2911da4e1af2cde00435b8208c1ffcdd5a8e7..d9bc1725ff0054fd006f987d60c3594f8067acf5 100644 (file)
@@ -14,6 +14,7 @@
 #include "g.h"
 #include "gcommon.h"
 #include "mem.h"
+#include <string.h>
 
 #define WPU widget->u.p
 #define WINDOW widget->u.p->window
@@ -674,7 +675,7 @@ static HFONT findfont (char *name, int size) {
     HFONT font;
     int fi;
 
-    if (name[0] == '\000')
+    if (strcmp(name, "") == 0)
         return Gfontp[0].font;
 
     sprintf (&Gbufp[0], name, size);
index 83a20bb6e0d42b8b4565ec830ed204010a11615c..93d1d3fe8071195358630caa3033694b3e5b9e7c 100644 (file)
@@ -13,6 +13,7 @@
 #include "common.h"
 #include "g.h"
 #include "gcommon.h"
+#include <string.h>
 
 #define WBU widget->u.b
 
@@ -80,7 +81,7 @@ int GBcreatewidget (
             return -1;
         }
     }
-    if (!s || s[0] == '\000') {
+    if (!s || strcmp(s, "") == 0) {
         ADD2ARGS (XtNwidth, ps.x);
         ADD2ARGS (XtNheight, ps.y);
     } else {
index e83bfcdd0238242e83b498310d74092c94d98340..0466f982f58c4a44918649d1cefabe0593b7ae81 100644 (file)
@@ -17,6 +17,7 @@
 #ifdef FEATURE_GMAP
 #include <gmap.h>
 #endif
+#include <string.h>
 
 #define WCU widget->u.c
 #define WINDOW widget->u.c->window
@@ -866,7 +867,7 @@ static XFontStruct *findfont (char *name, int size) {
     XFontStruct *font;
     int fi, n, i;
 
-    if (name[0] == '\000')
+    if (strcmp(name, "") == 0)
         return Gfontp[0].font;
 
     sprintf (&Gbufp[0], name, size);
index 32445760aed0dba756fa24e0a889de34a71ead1f..876ad430535bdf10e36bfaf64476a32d1b6b9c38 100644 (file)
@@ -14,6 +14,7 @@
 #include "g.h"
 #include "gcommon.h"
 #include "mem.h"
+#include <string.h>
 
 #define PSDPI 300.0
 #define PSMAXPIXW (8.0  * PSDPI)
@@ -515,7 +516,7 @@ int GPtext (
 static char *findfont (char *name) {
     char *font;
 
-    if (name[0] == '\000' || strcmp (name, "default") == 0)
+    if (strcmp(name, "") == 0 || strcmp (name, "default") == 0)
         font = "Times-Roman";
     else
         font = name;