change strncasecmp() == 0 to STRCASEEQLEN()
[libguestfs.git] / src / generator.ml
old mode 100755 (executable)
new mode 100644 (file)
index 8b83496..4fba15f
@@ -4688,7 +4688,7 @@ and generate_xdr () =
            List.iter (
              function
              | Pathname n | Device n | Dev_or_Path n | String n ->
-                pr "  string %s<>;\n" n
+                 pr "  string %s<>;\n" n
              | OptString n -> pr "  str *%s;\n" n
              | StringList n | DeviceList n -> pr "  str %s<>;\n" n
              | Bool n -> pr "  bool %s;\n" n
@@ -5878,9 +5878,9 @@ static int %s_skip (void)
   if (str)
     return strstr (str, \"%s\") == NULL;
   str = getenv (\"SKIP_%s\");
-  if (str && strcmp (str, \"1\") == 0) return 1;
+  if (str && STREQ (str, \"1\")) return 1;
   str = getenv (\"SKIP_TEST_%s\");
-  if (str && strcmp (str, \"1\") == 0) return 1;
+  if (str && STREQ (str, \"1\")) return 1;
   return 0;
 }
 
@@ -6001,7 +6001,7 @@ and generate_one_test_body name i test_name init test =
       pr "  const char *expected = \"%s\";\n" (c_quote expected);
       let seq, last = get_seq_last seq in
       let test () =
-        pr "    if (strcmp (r, expected) != 0) {\n";
+        pr "    if (STRNEQ (r, expected)) {\n";
         pr "      fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r);\n" test_name;
         pr "      return -1;\n";
         pr "    }\n"
@@ -6021,7 +6021,7 @@ and generate_one_test_body name i test_name init test =
             pr "    }\n";
             pr "    {\n";
             pr "      const char *expected = \"%s\";\n" (c_quote str);
-            pr "      if (strcmp (r[%d], expected) != 0) {\n" i;
+            pr "      if (STRNEQ (r[%d], expected)) {\n" i;
             pr "        fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r[%d]);\n" test_name i;
             pr "        return -1;\n";
             pr "      }\n";
@@ -6050,7 +6050,7 @@ and generate_one_test_body name i test_name init test =
             pr "    {\n";
             pr "      const char *expected = \"%s\";\n" (c_quote str);
             pr "      r[%d][5] = 's';\n" i;
-            pr "      if (strcmp (r[%d], expected) != 0) {\n" i;
+            pr "      if (STRNEQ (r[%d], expected)) {\n" i;
             pr "        fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r[%d]);\n" test_name i;
             pr "        return -1;\n";
             pr "      }\n";
@@ -6146,7 +6146,7 @@ and generate_one_test_body name i test_name init test =
         pr "      fprintf (stderr, \"%s: returned size of buffer wrong, expected %d but got %%zu\\n\", size);\n" test_name len;
         pr "      return -1;\n";
         pr "    }\n";
-        pr "    if (strncmp (r, expected, size) != 0) {\n";
+        pr "    if (STRNEQLEN (r, expected, size)) {\n";
         pr "      fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r);\n" test_name;
         pr "      return -1;\n";
         pr "    }\n"
@@ -6174,7 +6174,7 @@ and generate_one_test_body name i test_name init test =
               pr "      return -1;\n";
               pr "    }\n"
           | CompareWithString (field, expected) ->
-              pr "    if (strcmp (r->%s, \"%s\") != 0) {\n" field expected;
+              pr "    if (STRNEQ (r->%s, \"%s\")) {\n" field expected;
               pr "      fprintf (stderr, \"%s: %s was \"%%s\", expected \"%s\"\\n\",\n"
                 test_name field expected;
               pr "               r->%s);\n" field;
@@ -6188,7 +6188,7 @@ and generate_one_test_body name i test_name init test =
               pr "      return -1;\n";
               pr "    }\n"
           | CompareFieldsStrEq (field1, field2) ->
-              pr "    if (strcmp (r->%s, r->%s) != 0) {\n" field1 field2;
+              pr "    if (STRNEQ (r->%s, r->%s)) {\n" field1 field2;
               pr "      fprintf (stderr, \"%s: %s (\"%%s\") <> %s (\"%%s\")\\n\",\n"
                 test_name field1 field2;
               pr "               r->%s, r->%s);\n" field1 field2;
@@ -6430,11 +6430,11 @@ and generate_fish_cmds () =
         else "" in
 
       pr "  if (";
-      pr "strcasecmp (cmd, \"%s\") == 0" name;
+      pr "STRCASEEQ (cmd, \"%s\")" name;
       if name <> name2 then
-        pr " || strcasecmp (cmd, \"%s\") == 0" name2;
+        pr " || STRCASEEQ (cmd, \"%s\")" name2;
       if name <> alias then
-        pr " || strcasecmp (cmd, \"%s\") == 0" alias;
+        pr " || STRCASEEQ (cmd, \"%s\")" alias;
       pr ")\n";
       pr "    pod2text (\"%s\", _(\"%s\"), %S);\n"
         name2 shortdesc
@@ -6581,19 +6581,19 @@ and generate_fish_cmds () =
           function
           | Device name
           | String name ->
-             pr "  %s = argv[%d];\n" name i
+              pr "  %s = argv[%d];\n" name i
           | Pathname name
           | Dev_or_Path name ->
-             pr "  %s = resolve_win_path (argv[%d]);\n" name i;
-             pr "  if (%s == NULL) return -1;\n" name
+              pr "  %s = resolve_win_path (argv[%d]);\n" name i;
+              pr "  if (%s == NULL) return -1;\n" name
           | OptString name ->
-              pr "  %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] : NULL;\n"
+              pr "  %s = STRNEQ (argv[%d], \"\") ? argv[%d] : NULL;\n"
                 name i i
           | FileIn name ->
-              pr "  %s = strcmp (argv[%d], \"-\") != 0 ? argv[%d] : \"/dev/stdin\";\n"
+              pr "  %s = STRNEQ (argv[%d], \"-\") ? argv[%d] : \"/dev/stdin\";\n"
                 name i i
           | FileOut name ->
-              pr "  %s = strcmp (argv[%d], \"-\") != 0 ? argv[%d] : \"/dev/stdout\";\n"
+              pr "  %s = STRNEQ (argv[%d], \"-\") ? argv[%d] : \"/dev/stdout\";\n"
                 name i i
           | StringList name | DeviceList name ->
               pr "  %s = parse_string_list (argv[%d]);\n" name i;
@@ -6692,11 +6692,11 @@ and generate_fish_cmds () =
         try find_map (function FishAlias n -> Some n | _ -> None) flags
         with Not_found -> name in
       pr "  if (";
-      pr "strcasecmp (cmd, \"%s\") == 0" name;
+      pr "STRCASEEQ (cmd, \"%s\")" name;
       if name <> name2 then
-        pr " || strcasecmp (cmd, \"%s\") == 0" name2;
+        pr " || STRCASEEQ (cmd, \"%s\")" name2;
       if name <> alias then
-        pr " || strcasecmp (cmd, \"%s\") == 0" alias;
+        pr " || STRCASEEQ (cmd, \"%s\")" alias;
       pr ")\n";
       pr "    return run_%s (cmd, argc, argv);\n" name;
       pr "  else\n";
@@ -6772,7 +6772,7 @@ generator (const char *text, int state)
 
   while ((name = commands[index]) != NULL) {
     index++;
-    if (strncasecmp (name, text, len) == 0)
+    if (STRCASEEQLEN (name, text, len))
       return strdup (name);
   }
 
@@ -7255,7 +7255,7 @@ copy_table (char * const * argv)
         | StringList n | DeviceList n ->
             pr "  ocaml_guestfs_free_strings (%s);\n" n;
         | Pathname _ | Device _ | Dev_or_Path _ | String _ | OptString _
-       | Bool _ | Int _ | Int64 _
+        | Bool _ | Int _ | Int64 _
         | FileIn _ | FileOut _ -> ()
       ) (snd style);
 
@@ -7506,7 +7506,7 @@ DESTROY (g)
         List.iter (
           function
           | Pathname _ | Device _ | Dev_or_Path _ | String _ | OptString _
-         | Bool _ | Int _ | Int64 _
+          | Bool _ | Int _ | Int64 _
           | FileIn _ | FileOut _ -> ()
           | StringList n | DeviceList n -> pr "      free (%s);\n" n
         ) (snd style)
@@ -8160,8 +8160,8 @@ py_guestfs_close (PyObject *self, PyObject *args)
         | Bool _ -> pr "i" (* XXX Python has booleans? *)
         | Int _ -> pr "i"
         | Int64 _ -> pr "L" (* XXX Whoever thought it was a good idea to
-                            * emulate C's int/long/long long in Python?
-                            *)
+                             * emulate C's int/long/long long in Python?
+                             *)
       ) (snd style);
       pr ":guestfs_%s\",\n" name;
       pr "                         &py_g";
@@ -9129,7 +9129,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close
             pr "  free (%s);\n" n
         | Bool n
         | Int n
-       | Int64 n -> ()
+        | Int64 n -> ()
       ) (snd style);
 
       (* Check for errors. *)
@@ -9317,6 +9317,12 @@ module Guestfs (
 
   pr "
   ) where
+
+-- Unfortunately some symbols duplicate ones already present
+-- in Prelude.  We don't know which, so we hard-code a list
+-- here.
+import Prelude hiding (truncate)
+
 import Foreign
 import Foreign.C
 import Foreign.C.Types
@@ -9564,7 +9570,7 @@ print_strings (char *const *argv)
              pr "  sscanf (val, \"%%\" SCNi64, &r);\n";
              pr "  return r;\n"
          | RBool _ ->
-             pr "  return strcmp (val, \"true\") == 0;\n"
+             pr "  return STREQ (val, \"true\");\n"
          | RConstString _
          | RConstOptString _ ->
              (* Can't return the input string here.  Return a static