From cc44c7655fe2dd0cfb46e841156634fe622df397 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 Feb 2007 01:53:29 -0800 Subject: Mechanical conversion to use prefixcmp() This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano --- peek-remote.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'peek-remote.c') diff --git a/peek-remote.c b/peek-remote.c index ef3c76ce52..7b66228a22 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -35,11 +35,11 @@ int main(int argc, char **argv) char *arg = argv[i]; if (*arg == '-') { - if (!strncmp("--upload-pack=", arg, 14)) { + if (!(-prefixcmp(arg, "--upload-pack="))) { uploadpack = arg + 14; continue; } - if (!strncmp("--exec=", arg, 7)) { + if (!(-prefixcmp(arg, "--exec="))) { uploadpack = arg + 7; continue; } -- cgit v1.2.3 From 599065a3bb94ae9f48e3808b8fafc8443017af28 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 Feb 2007 01:54:00 -0800 Subject: prefixcmp(): fix-up mechanical conversion. Previous step converted use of strncmp() with literal string mechanically even when the result is only used as a boolean: if (!strncmp("foo", arg, 3)) ==> if (!(-prefixcmp(arg, "foo"))) This step manually cleans them up to read: if (!prefixcmp(arg, "foo")) Signed-off-by: Junio C Hamano --- peek-remote.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'peek-remote.c') diff --git a/peek-remote.c b/peek-remote.c index 7b66228a22..96bfac498b 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -35,11 +35,11 @@ int main(int argc, char **argv) char *arg = argv[i]; if (*arg == '-') { - if (!(-prefixcmp(arg, "--upload-pack="))) { + if (!prefixcmp(arg, "--upload-pack=")) { uploadpack = arg + 14; continue; } - if (!(-prefixcmp(arg, "--exec="))) { + if (!prefixcmp(arg, "--exec=")) { uploadpack = arg + 7; continue; } -- cgit v1.2.3