Replace name_locate test program with modify command name_locate.

Adapt test.

Add two flags, and document supported flags in modify usage.
diff --git a/.hgignore b/.hgignore
index 2809d29..f3ff322 100644
--- a/.hgignore
+++ b/.hgignore
@@ -45,7 +45,6 @@
 ^regress/hole$
 ^regress/manyfiles.zip$
 ^regress/modify$
-^regress/name_locate$
 ^regress/runtest$
 ^regress/set_comment_all$
 ^regress/tryopen$
diff --git a/regress/Makefile.am b/regress/Makefile.am
index 368784b..a45bde9 100644
--- a/regress/Makefile.am
+++ b/regress/Makefile.am
@@ -9,7 +9,6 @@
 	fread \
 	hole \
 	modify \
-	name_locate \
 	set_comment_all \
 	tryopen
 
diff --git a/regress/modify.c b/regress/modify.c
index 28e1ae1..6c4dd3d 100644
--- a/regress/modify.c
+++ b/regress/modify.c
@@ -363,6 +363,21 @@
 }
 
 static int
+name_locate(int argc, char *argv[]) {
+    zip_flags_t flags;
+    zip_int64_t idx;
+    flags = get_flags(argv[1]);
+
+    if ((idx=zip_name_locate(za, argv[0], flags)) < 0) {
+	fprintf(stderr, "can't find entry with name '%s' using flags '%s'\n", argv[0], argv[1]);
+    } else {
+	printf("name '%s' using flags '%s' found at index %" PRId64 "\n", argv[0], argv[1], idx);
+    }	
+
+    return 0;
+}
+
+static int
 zrename(int argc, char *argv[]) {
     zip_uint64_t idx;
     idx = strtoull(argv[0], NULL, 10);
@@ -518,8 +533,12 @@
 get_flags(const char *arg)
 {
     zip_flags_t flags = 0;
+    if (strchr(arg, 'C') != NULL)
+	flags |= ZIP_FL_NOCASE;
     if (strchr(arg, 'c') != NULL)
 	flags |= ZIP_FL_CENTRAL;
+    if (strchr(arg, 'd') != NULL)
+	flags |= ZIP_FL_NODIR;
     if (strchr(arg, 'l') != NULL)
 	flags |= ZIP_FL_LOCAL;
     if (strchr(arg, 'u') != NULL)
@@ -790,6 +809,7 @@
     { "get_extra", 3, "index extra_index flags", "show extra field", get_extra },
     { "get_extra_by_id", 4, "index extra_id extra_index flags", "show extra field of type extra_id", get_extra_by_id },
     { "get_file_comment", 1, "index", "get file comment", get_file_comment },
+    { "name_locate", 2, "name flags", "find entry in archive", name_locate },
     { "rename", 2, "index name", "rename entry", zrename },
     { "replace_file_contents", 2, "index data", "replace entry with data", replace_file_contents },
     { "set_archive_comment", 1, "comment", "set archive comment", set_archive_comment },
@@ -845,6 +865,12 @@
     for (i=0; i<sizeof(dispatch_table)/sizeof(dispatch_table_t); i++) {
 	fprintf(stderr, "\t%s %s -- %s\n", dispatch_table[i].cmdline_name, dispatch_table[i].arg_names, dispatch_table[i].description);
     }
+    fprintf(stderr, "\nSupported flags are:\n"
+	    "\tC\tZIP_FL_NOCASE\n"
+	    "\tc\tZIP_FL_CENTRAL\n"
+	    "\td\tZIP_FL_NODIR\n"
+	    "\tl\tZIP_FL_LOCAL\n"
+	    "\tu\tZIP_FL_UNCHANGED\n");
     fprintf(stderr, "\nThe index is zero-based.\n");
     exit(1);
 }
diff --git a/regress/name_locate.c b/regress/name_locate.c
deleted file mode 100644
index 6f05dfb..0000000
--- a/regress/name_locate.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
-  name_locate.c -- test cases for finding files in zip archives
-  Copyright (C) 2005-2014 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <libzip@nih.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "zip.h"
-
-#include "compat.h"
-
-static int find_fail(zip_t *z, const char *name, zip_flags_t flags, int zerr);
-static int find_success(zip_t *z, const char *name, zip_flags_t flags);
-
-const char *prg;
-
-
-int
-main(int argc, char *argv[])
-{
-    int fail, ze;
-    zip_t *z;
-    const char *archive;
-    zip_source_t *s;
-    const char buf[] = "teststring";
-
-    fail = 0;
-    prg = argv[0];
-
-    if (argc != 2) {
-        fprintf(stderr, "usage: %s archive\n", prg);
-        return 1;
-    }
-
-    archive = argv[1];
-
-    if ((z=zip_open(archive, 0, &ze)) == NULL) {
-	zip_error_t error;
-	zip_error_init_with_code(&error, ze);
-	fprintf(stderr, "%s: can't open zip archive '%s': %s\n", prg, archive, zip_error_strerror(&error));
-	zip_error_fini(&error);
-	return 1;
-    }
-
-    fail += find_fail(z, "nosuchfile", 0, ZIP_ER_NOENT);
-    fail += find_success(z, "test", 0);
-    fail += find_fail(z, "", 0, ZIP_ER_NOENT);
-    fail += find_fail(z, "TeSt", 0, ZIP_ER_NOENT);
-    fail += find_success(z, "TeSt", ZIP_FL_NOCASE);
-    fail += find_success(z, "testdir/test2", 0);
-    fail += find_success(z, "tesTdir/tESt2", ZIP_FL_NOCASE);
-    fail += find_fail(z, "testdir/test2", ZIP_FL_NODIR, ZIP_ER_NOENT);
-    fail += find_fail(z, "tesTdir/tESt2", ZIP_FL_NOCASE|ZIP_FL_NODIR,
-		      ZIP_ER_NOENT);
-    fail += find_fail(z, "test2", 0, ZIP_ER_NOENT);
-    fail += find_success(z, "test2", ZIP_FL_NODIR);
-    fail += find_success(z, "TeST2", ZIP_FL_NODIR|ZIP_FL_NOCASE);
-    zip_delete(z, 0);
-    fail += find_fail(z, "test", 0, ZIP_ER_NOENT);
-    fail += find_success(z, "test", ZIP_FL_UNCHANGED);
-    if ((s=zip_source_buffer(z, buf, sizeof(buf), 0)) == NULL || zip_file_add(z, "new", s, 0) < 0) {
-	zip_source_free(s);
-	printf("error adding file: %s\n", zip_strerror(z));
-    }
-    fail += find_success(z, "new", 0);
-    fail += find_fail(z, "new", ZIP_FL_UNCHANGED, ZIP_ER_NOENT);
-    if ((s=zip_source_buffer(z, buf, sizeof(buf), 0)) == NULL || zip_file_add(z, "", s, 0) < 0) {
-	zip_source_free(s);
-	printf("error adding file: %s\n", zip_strerror(z));
-    }
-    fail += find_success(z, "", 0);
-    zip_unchange_all(z);
-    fail += find_success(z, "test", 0);
-    fail += find_fail(z, "new", 0, ZIP_ER_NOENT);
-
-    if (zip_close(z) == -1) {
-	fprintf(stderr, "%s: can't close zip archive '%s': %s\n", prg,
-		archive, zip_strerror(z));
-	return 1;
-    }
-
-    exit(fail ? 1 : 0);
-}
-
-
-static int
-find_fail(zip_t *z, const char *name, zip_flags_t flags, int zerr)
-{
-    zip_int64_t idx;
-
-    if ((idx=zip_name_locate(z, name, flags)) < 0) {
-	if (zip_error_code_zip(zip_get_error(z)) != zerr) {
-	    zip_error_t error_ex;
-	    zip_error_init_with_code(&error_ex, zerr);
-	    printf("unexpected error while looking for '%s' with flags %x: got `%s', expected `%s'\n",
-		   name, flags, zip_strerror(z), zip_error_strerror(&error_ex));
-	    zip_error_fini(&error_ex);
-	    return 1;
-	}
-
-	return 0;
-    }
-
-    printf("unexpected success while looking for '%s' with flags %x: index %" PRId64 "\n", name, flags, idx);
-    return 1;
-}
-
-
-static int
-find_success(zip_t *z, const char *name, zip_flags_t flags)
-{
-
-    if (zip_name_locate(z, name, flags) < 0) {
-	printf("unexpected error while looking for '%s' with flags %x: %s\n",
-	       name, flags, zip_strerror(z));
-	return 1;
-    }
-
-    return 0;
-}
diff --git a/regress/name_locate.test b/regress/name_locate.test
index 5b5bde0..5d7fc26 100644
--- a/regress/name_locate.test
+++ b/regress/name_locate.test
@@ -1,5 +1,28 @@
 # various tests for zip_name_locate
-program name_locate
-args test.zip
+program modify
+args test.zip  name_locate nosuchfile 0  name_locate test 0  name_locate "" 0  name_locate TeSt 0  name_locate TeSt C  name_locate testdir/test2 0  name_locate tesTdir/tESt2 C  name_locate testdir/test2 d  name_locate tesTdir/tESt2 dC  name_locate test2 0  name_locate test2 d  name_locate TeST2 dC  delete 0  name_locate test 0  name_locate test u  add new teststring  name_locate new 0  name_locate new u  add "" teststring  name_locate "" 0  unchange_all  name_locate test 0  name_locate new 0
+stderr can't find entry with name 'nosuchfile' using flags '0'
+stdout name 'test' using flags '0' found at index 0
+stderr can't find entry with name '' using flags '0'
+stderr can't find entry with name 'TeSt' using flags '0'
+stdout name 'TeSt' using flags 'C' found at index 0
+stdout name 'testdir/test2' using flags '0' found at index 2
+stdout name 'tesTdir/tESt2' using flags 'C' found at index 2
+stderr can't find entry with name 'testdir/test2' using flags 'd'
+stderr can't find entry with name 'tesTdir/tESt2' using flags 'dC'
+stderr can't find entry with name 'test2' using flags '0'
+stdout name 'test2' using flags 'd' found at index 2
+stdout name 'TeST2' using flags 'dC' found at index 2
+# delete 0
+stderr can't find entry with name 'test' using flags '0'
+stdout name 'test' using flags 'u' found at index 0
+# add "new"
+stdout name 'new' using flags '0' found at index 3
+stderr can't find entry with name 'new' using flags 'u'
+# add ""
+stdout name '' using flags '0' found at index 4
+# unchange all
+stdout name 'test' using flags '0' found at index 0
+stderr can't find entry with name 'new' using flags '0'
 return 0
 file test.zip test.zip test.zip