poldek: poldek/cli/shell.c - fixed capabilities completion (#154, applied p...

mis mis at pld-linux.org
Sat May 24 09:58:57 CEST 2008


Author: mis                          Date: Sat May 24 07:58:57 2008 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- fixed capabilities completion (#154, applied patch by megabajt)
- code cleanups

---- Files affected:
poldek/poldek/cli:
   shell.c (1.36 -> 1.37) 

---- Diffs:

================================================================
Index: poldek/poldek/cli/shell.c
diff -u poldek/poldek/cli/shell.c:1.36 poldek/poldek/cli/shell.c:1.37
--- poldek/poldek/cli/shell.c:1.36	Mon May 12 22:53:30 2008
+++ poldek/poldek/cli/shell.c	Sat May 24 09:58:52 2008
@@ -67,6 +67,7 @@
 #define COMPLETITION_CTX_INSTALLED       3
 #define COMPLETITION_CTX_WHAT_PROVIDES   4
 #define COMPLETITION_CTX_WHAT_REQUIRES   5
+#define COMPLETITION_CTX_DIRNAME         6
 
 struct sh_ctx {
     int completion_ctx;
@@ -263,35 +264,28 @@
 		for (i = 0; i < n_array_size(ents); i++) {
 			struct pkg_dent *ent = n_array_nth(ents, i);
 			struct pkg *pkg = ent->pkg_dent_pkg;
-
+            tn_array *caps = NULL;
+            
 			if (pkg_dent_isdir(ent))
 				continue;
 
-			if (sh_ctx.completion_ctx == COMPLETITION_CTX_WHAT_PROVIDES) {
-				/* provides */
-				if (pkg->caps == NULL)
-                    continue;
-                
-                for (j = 0; j < n_array_size(pkg->caps); j++) {
-                    struct capreq *cr = n_array_nth(pkg->caps, j);
-                    const char *name = capreq_name(cr);
+            switch (sh_ctx.completion_ctx) {
+                case COMPLETITION_CTX_WHAT_PROVIDES:
+                    caps = pkg->caps;
+                    break;
                     
-                    if (len == 0 || strncmp(name, text, len) == 0)
-                        n_array_push(deps_table, name);
-                }
-			}
-
-			if (sh_ctx.completion_ctx == COMPLETITION_CTX_WHAT_REQUIRES) {
-				/* requires */
-				if (pkg->reqs == NULL)
-                    continue;
-                
-                for (j = 0; j < n_array_size(pkg->reqs); j++) {
-                    struct capreq *cr = n_array_nth(pkg->reqs, j);
+                case COMPLETITION_CTX_WHAT_REQUIRES:
+                    caps = pkg->reqs;
+                    break;
+            }
+            
+            if (caps) {
+                for (j = 0; j < n_array_size(caps); j++) {
+                    struct capreq *cr = n_array_nth(caps, j);
                     const char *name = capreq_name(cr);
                     
                     if (len == 0 || strncmp(name, text, len) == 0)
-                        n_array_push(deps_table, name);
+                        n_array_push(deps_table, (void*)name);
                 }
 			}
 		}
@@ -324,7 +318,6 @@
     char **matches = NULL;
     char *p;
     
-    
     start = start;
     end = end;
     matches = NULL;
@@ -349,7 +342,10 @@
 
         else if (strncmp(p, "what-req", 8) == 0) /* what-requires cmd */
             sh_ctx.completion_ctx = COMPLETITION_CTX_WHAT_REQUIRES;
-        
+
+        else if (strncmp(p, "cd ", 3) == 0)
+            sh_ctx.completion_ctx = COMPLETITION_CTX_DIRNAME;
+
         else 
             sh_ctx.completion_ctx = COMPLETITION_CTX_NONE;
     }
@@ -358,15 +354,22 @@
         matches = rl_completion_matches(text, command_generator);
         
     } else {
-        if (strncmp(p, "cd ", 3) == 0)
-            matches = rl_completion_matches(text, dirname_generator);
-        
-        else if (sh_ctx.completion_ctx == COMPLETITION_CTX_WHAT_PROVIDES ||
-                 sh_ctx.completion_ctx == COMPLETITION_CTX_WHAT_REQUIRES)
-            matches = rl_completion_matches(text, deps_generator);
+        rl_completer_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
         
-        else
-            matches = rl_completion_matches(text, pkgname_generator);
+        switch (sh_ctx.completion_ctx) {
+            case COMPLETITION_CTX_DIRNAME:
+                matches = rl_completion_matches(text, dirname_generator);
+                break;
+                
+            case COMPLETITION_CTX_WHAT_PROVIDES:
+            case COMPLETITION_CTX_WHAT_REQUIRES:
+                rl_completer_word_break_characters = " \t\n\"\\'`@$><=;|&{";
+                matches = rl_completion_matches(text, deps_generator);
+                break;
+                
+            default:
+                matches = rl_completion_matches(text, pkgname_generator);
+        }
     }
     
     return matches;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/cli/shell.c?r1=1.36&r2=1.37&f=u



More information about the pld-cvs-commit mailing list