cli: implement --nocase flag
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:16:33 +0000 (10:16 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:16:33 +0000 (10:16 +0100)
Introduce a new --nocase flag which causes all opkg pattern matching
operations to ignore the case.

This is useful to find packages with uppercase letters in their name.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_cmd.c
libopkg/opkg_conf.c
libopkg/opkg_conf.h
src/opkg-cl.c

index eba833bd7bdce4083f2070907c38c59da0eacf92..b98b86fb1ec116ed4ebd49dc245650e8ae832912 100644 (file)
@@ -436,7 +436,7 @@ opkg_configure_packages(char *pkg_name)
      for(i = 0; i < ordered->len; i++) {
          pkg = ordered->pkgs[i];
 
      for(i = 0; i < ordered->len; i++) {
          pkg = ordered->pkgs[i];
 
-         if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
+         if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase))
               continue;
 
          if (pkg->state_status == SS_UNPACKED) {
               continue;
 
          if (pkg->state_status == SS_UNPACKED) {
@@ -610,7 +610,7 @@ opkg_list_cmd(int argc, char **argv)
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
-         if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
+         if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase))
               continue;
           print_pkg(pkg);
      }
               continue;
           print_pkg(pkg);
      }
@@ -637,7 +637,7 @@ opkg_list_installed_cmd(int argc, char **argv)
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
-         if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
+         if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase))
               continue;
           print_pkg(pkg);
      }
               continue;
           print_pkg(pkg);
      }
@@ -666,7 +666,7 @@ opkg_list_changed_conffiles_cmd(int argc, char **argv)
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
          /* if we have package name or pattern and pkg does not match, then skip it */
-         if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
+         if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase))
            continue;
          if (nv_pair_list_empty(&pkg->conffiles))
            continue;
            continue;
          if (nv_pair_list_empty(&pkg->conffiles))
            continue;
@@ -722,7 +722,7 @@ opkg_info_status_cmd(int argc, char **argv, int installed_only)
 
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
 
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
-         if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
+         if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase)) {
               continue;
          }
 
               continue;
          }
 
@@ -792,7 +792,7 @@ opkg_remove_cmd(int argc, char **argv)
      for (i=0; i<argc; i++) {
         for (a=0; a<available->len; a++) {
             pkg = available->pkgs[a];
      for (i=0; i<argc; i++) {
         for (a=0; a<available->len; a++) {
             pkg = available->pkgs[a];
-           if (fnmatch(argv[i], pkg->name, 0)) {
+           if (fnmatch(argv[i], pkg->name, conf->nocase)) {
                continue;
             }
             if (conf->restrict_to_default_dest) {
                continue;
             }
             if (conf->restrict_to_default_dest) {
@@ -926,7 +926,7 @@ opkg_depends_cmd(int argc, char **argv)
                for (j=0; j<available_pkgs->len; j++) {
                        pkg = available_pkgs->pkgs[j];
 
                for (j=0; j<available_pkgs->len; j++) {
                        pkg = available_pkgs->pkgs[j];
 
-                       if (fnmatch(argv[i], pkg->name, 0) != 0)
+                       if (fnmatch(argv[i], pkg->name, conf->nocase) != 0)
                                continue;
 
                        depends_count = pkg->depends_count +
                                continue;
 
                        depends_count = pkg->depends_count +
@@ -1147,9 +1147,9 @@ opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc,
                              ((what_field_type == WHATPROVIDES)
                               ? pkg->provides[k]
                               : pkg->replaces[k]);
                              ((what_field_type == WHATPROVIDES)
                               ? pkg->provides[k]
                               : pkg->replaces[k]);
-                        if (fnmatch(target, apkg->name, 0) == 0) {
+                        if (fnmatch(target, apkg->name, conf->nocase) == 0) {
                              opkg_msg(NOTICE, "    %s", pkg->name);
                              opkg_msg(NOTICE, "    %s", pkg->name);
-                             if (strcmp(target, apkg->name) != 0)
+                             if ((conf->nocase ? strcasecmp(target, apkg->name) : strcmp(target, apkg->name)) != 0)
                                   opkg_msg(NOTICE, "\t%s %s\n",
                                                   rel_str, apkg->name);
                              opkg_message(NOTICE, "\n");
                                   opkg_msg(NOTICE, "\t%s %s\n",
                                                   rel_str, apkg->name);
                              opkg_message(NOTICE, "\n");
@@ -1200,7 +1200,7 @@ opkg_search_cmd(int argc, char **argv)
 
          for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
               installed_file = (char *)iter->data;
 
          for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
               installed_file = (char *)iter->data;
-              if (fnmatch(argv[0], installed_file, 0)==0)
+              if (fnmatch(argv[0], installed_file, conf->nocase)==0)
                    print_pkg(pkg);
          }
 
                    print_pkg(pkg);
          }
 
index 4711ce7e46b1f141d7bd9a2122f4c66000cfc502..bf7a56313ad4ada36611a4207fe1a50e8f2bd48f 100644 (file)
@@ -62,6 +62,7 @@ opkg_option_t options[] = {
          { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
          { "download_only", OPKG_OPT_TYPE_BOOL, &_conf.download_only },
          { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps },
          { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
          { "download_only", OPKG_OPT_TYPE_BOOL, &_conf.download_only },
          { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps },
+         { "nocase", OPKG_OPT_TYPE_BOOL, &_conf.nocase },
          { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root },
          { "overlay_root", OPKG_OPT_TYPE_STRING, &_conf.overlay_root },
          { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
          { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root },
          { "overlay_root", OPKG_OPT_TYPE_STRING, &_conf.overlay_root },
          { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
index 3a60bc597dfea03bd36a1f104340d15192cdb43d..10bfc607ad4b700574a3f1ce28effa0d8c995187 100644 (file)
@@ -24,6 +24,7 @@ extern opkg_conf_t *conf;
 #include "config.h"
 
 #include <stdarg.h>
 #include "config.h"
 
 #include <stdarg.h>
+#include <fnmatch.h> /* FNM_CASEFOLD */
 
 #include "hash_table.h"
 #include "pkg_src_list.h"
 
 #include "hash_table.h"
 #include "pkg_src_list.h"
@@ -79,6 +80,7 @@ struct opkg_conf
      int force_remove;
      int check_signature;
      int nodeps; /* do not follow dependencies */
      int force_remove;
      int check_signature;
      int nodeps; /* do not follow dependencies */
+     int nocase; /* perform case insensitive matching */
      char *offline_root;
      char *overlay_root;
      int query_all;
      char *offline_root;
      char *overlay_root;
      int query_all;
index 687bb9e84581cdf859c8a6bd537611f091af0303..1e7642f7024e913dbcf305e107812eb05430630a 100644 (file)
@@ -47,6 +47,7 @@ enum {
        ARGS_OPT_NOACTION,
        ARGS_OPT_DOWNLOAD_ONLY,
        ARGS_OPT_NODEPS,
        ARGS_OPT_NOACTION,
        ARGS_OPT_DOWNLOAD_ONLY,
        ARGS_OPT_NODEPS,
+       ARGS_OPT_NOCASE,
        ARGS_OPT_AUTOREMOVE,
        ARGS_OPT_CACHE,
 };
        ARGS_OPT_AUTOREMOVE,
        ARGS_OPT_CACHE,
 };
@@ -86,6 +87,7 @@ static struct option long_options[] = {
        {"noaction", 0, 0, ARGS_OPT_NOACTION},
        {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY},
        {"nodeps", 0, 0, ARGS_OPT_NODEPS},
        {"noaction", 0, 0, ARGS_OPT_NOACTION},
        {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY},
        {"nodeps", 0, 0, ARGS_OPT_NODEPS},
+       {"nocase", 0, 0, ARGS_OPT_NOCASE},
        {"offline", 1, 0, 'o'},
        {"offline-root", 1, 0, 'o'},
        {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
        {"offline", 1, 0, 'o'},
        {"offline-root", 1, 0, 'o'},
        {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
@@ -107,7 +109,7 @@ args_parse(int argc, char *argv[])
        char *tuple, *targ;
 
        while (1) {
        char *tuple, *targ;
 
        while (1) {
-               c = getopt_long_only(argc, argv, "Ad:f:no:p:t:vV::",
+               c = getopt_long_only(argc, argv, "Ad:f:ino:p:t:vV::",
                                long_options, &option_index);
                if (c == -1)
                        break;
                                long_options, &option_index);
                if (c == -1)
                        break;
@@ -122,6 +124,9 @@ args_parse(int argc, char *argv[])
                case 'f':
                        conf->conf_file = xstrdup(optarg);
                        break;
                case 'f':
                        conf->conf_file = xstrdup(optarg);
                        break;
+               case 'i':
+                       conf->nocase = FNM_CASEFOLD;
+                       break;
                case 'o':
                        conf->offline_root = xstrdup(optarg);
                        break;
                case 'o':
                        conf->offline_root = xstrdup(optarg);
                        break;
@@ -176,6 +181,9 @@ args_parse(int argc, char *argv[])
                case ARGS_OPT_NODEPS:
                        conf->nodeps = 1;
                        break;
                case ARGS_OPT_NODEPS:
                        conf->nodeps = 1;
                        break;
+               case ARGS_OPT_NOCASE:
+                       conf->nocase = FNM_CASEFOLD;
+                       break;
                case ARGS_OPT_ADD_ARCH:
                case ARGS_OPT_ADD_DEST:
                        tuple = xstrdup(optarg);
                case ARGS_OPT_ADD_ARCH:
                case ARGS_OPT_ADD_DEST:
                        tuple = xstrdup(optarg);
@@ -287,6 +295,7 @@ usage()
        printf("\t--noaction            No action -- test only\n");
        printf("\t--download-only       No action -- download only\n");
        printf("\t--nodeps              Do not follow dependencies\n");
        printf("\t--noaction            No action -- test only\n");
        printf("\t--download-only       No action -- download only\n");
        printf("\t--nodeps              Do not follow dependencies\n");
+       printf("\t--nocase              Perform case insensitive pattern matching\n");
        printf("\t--force-removal-of-dependent-packages\n");
        printf("\t                      Remove package and all dependencies\n");
        printf("\t--autoremove          Remove packages that were installed\n");
        printf("\t--force-removal-of-dependent-packages\n");
        printf("\t                      Remove package and all dependencies\n");
        printf("\t--autoremove          Remove packages that were installed\n");