From ee1be504edab6f430cee618a1e243cea791beae2 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 22 Sep 2022 21:31:42 -0700 Subject: [PATCH] pack parsePackModeInfo: make some string prefix code more clear --- lib/pack/pack.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/pack/pack.c b/lib/pack/pack.c index 940ced613..079b4e32e 100644 --- a/lib/pack/pack.c +++ b/lib/pack/pack.c @@ -17,12 +17,11 @@ #include #include #include +#include #include #include #include -#define strneq(a,b,n) (!strncmp(a,b,n)) - #define C 100 /* Max. avg. polyomino size */ #define MOVEPT(p) ((p).x += dx, (p).y += dy) @@ -1182,10 +1181,6 @@ pack_graph(int ng, Agraph_t** gs, Agraph_t* root, bool *fixed) return ret; } -#define ARRAY "array" -#define ASPECT "aspect" -#define SLEN(s) (sizeof(s)/sizeof(char) - 1) - static const char*chkFlags(const char *p, pack_info *pinfo) { int c, more; @@ -1268,16 +1263,16 @@ parsePackModeInfo(const char* p, pack_mode dflt, pack_info* pinfo) if (p && *p) { switch (*p) { case 'a': - if (strneq(p, ARRAY, SLEN(ARRAY))) { + if (startswith(p, "array")) { pinfo->mode = l_array; - p += SLEN(ARRAY); + p += strlen("array"); p = chkFlags (p, pinfo); if ((sscanf (p, "%d", &i)>0) && (i > 0)) pinfo->sz = i; } - else if (strneq(p, ASPECT, SLEN(ASPECT))) { + else if (startswith(p, "aspect")) { pinfo->mode = l_aspect; - if (sscanf(p + SLEN(ASPECT), "%f", &v) > 0 && v > 0) + if (sscanf(p + strlen("aspect"), "%f", &v) > 0 && v > 0) pinfo->aspect = v; else pinfo->aspect = 1; -- 2.40.0