Skip to contentSkip to conversation

libbb: remove vi tabwidth setting

PATCH Applied Alexander Aring 3 participants 6 messages Sep 11, 2012 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libbb: remove vi tabwidth setting

Remove vi tabwidth and tabstop setting.

---
 lib/libbb.c | 1 -
 1 file changed, 1 deletion(-)
lib/libbb.c +0 -1
index 9a0a60b..e0d7481 100644
@@ -1,4 +1,3 @@
-/* vi: set sw=8 ts=8: */
 /*
  * Utility routines.
  *
Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/2 complete: abstract path complete

Rewritten path complete, to use it maybe
in another functions.

---
 common/complete.c | 73 +++++++++++++------------------------------------------
 include/libbb.h   |  2 ++
 lib/libbb.c       | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 82 insertions(+), 57 deletions(-)
common/complete.c +17 -56
index 6a871ef..a06c070 100644
@@ -25,6 +25,8 @@
 #include <libgen.h>
 #include <command.h>
 #include <environment.h>
+#include <errno.h>
+#include <libbb.h>
 
 static int file_complete(struct string_list *sl, char *instr, int exec)
 {
@@ -70,65 +72,24 @@ out:
 	return 0;
 }
 
-static int path_command_complete(struct string_list *sl, char *instr)
+static int path_command_complete(char *name, void *priv)
 {
-	struct stat s;
-	DIR *dir;
-	struct dirent *d;
-	char tmp[PATH_MAX];
-	char *path, *p, *n;
-
-	p = path = strdup(getenv("PATH"));
-
-	if (!path)
-		return -1;
-
-	while (p) {
-		n = strchr(p, ':');
-		if (n)
-			*n++ = '\0';
-		if (*p == '\0') {
-			p = n;
-			continue;
-		}
-		dir = opendir(p);
+	struct string_list *sl = priv;
+	char *filename;
 
-		/* We need to check all PATH dirs, so if one failed,
-		 * try next */
-		if (!dir) {
-			p = n;
-			continue;
-		}
+	filename = strrchr(name, '/') + 1;
+	if (!filename)
+		return -EINVAL;
 
-		while ((d = readdir(dir))) {
-			if (!strcmp(d->d_name, ".") ||
-					!strcmp(d->d_name, ".."))
-				continue;
+	strcat(filename, " ");
 
-			if (!strncmp(instr, d->d_name, strlen(instr))) {
-				strcpy(tmp, d->d_name);
-				if (!stat(tmp, &s) &&
-						S_ISDIR(s.st_mode))
-					continue;
-				else
-					strcat(tmp, " ");
-
-				/* This function is called
-				 * after command_complete,
-				 * so we check if a double
-				 * entry exist */
-				if (string_list_contains
-						(sl, tmp) == 0) {
-					string_list_add_sorted(sl, tmp);
-				}
-			}
-		}
-
-		closedir(dir);
-		p = n;
-	}
-
-	free(path);
+	/* This function is called
+	 * after command_complete,
+	 * so we check if a double
+	 * entry exist */
+	if (!string_list_contains
+		(sl, filename))
+		string_list_add_sorted(sl, filename);
 
 	return 0;
 }
@@ -334,7 +295,7 @@ int complete(char *instr, char **outstr)
 			instr = t;
 		} else {
 			command_complete(&sl, instr);
-			path_command_complete(&sl, instr);
+			find_execable_like(path_command_complete, instr, &sl);
 			env_param_complete(&sl, instr, 0);
 		}
 		if (*instr == '$')
include/libbb.h +2 -0
index 47b2e08..0ef702b 100644
@@ -11,6 +11,8 @@ char *concat_subpath_file(const char *path, const char *f);
 int execable_file(const char *name);
 char *find_execable(const char *filename);
 char* last_char_is(const char *s, int c);
+int find_execable_like(int found(char *name, void *priv),
+		const char *likelyname, void *priv);
 
 enum {
 	ACTION_RECURSE     = (1 << 0),
lib/libbb.c +63 -1

82 lines not on this page · raw message

Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#5 lore raw
In reply to Alexander Aring
Quoted 3 lines · Alexander Aring

Remove vi tabwidth and tabstop setting.

Applied, thanks

Sascha

Quoted 22 lines
---
 lib/libbb.c | 1 -
 1 file changed, 1 deletion(-)
lib/libbb.c +0 -1
index 9a0a60b..e0d7481 100644
@@ -1,4 +1,3 @@
-/* vi: set sw=8 ts=8: */
 /*
  * Utility routines.
  *
Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH 2/2] complete: abstract path complete

In reply to Alexander Aring
Quoted 2 lines · Alexander Aring

Rewritten path complete, to use it maybe
in another functions.

Do you have a usecase for this?

Quoted 146 lines
---
 common/complete.c | 73 +++++++++++++------------------------------------------
 include/libbb.h   |  2 ++
 lib/libbb.c       | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 82 insertions(+), 57 deletions(-)
common/complete.c +17 -56
index 6a871ef..a06c070 100644
@@ -25,6 +25,8 @@
 #include <libgen.h>
 #include <command.h>
 #include <environment.h>
+#include <errno.h>
+#include <libbb.h>
 
 static int file_complete(struct string_list *sl, char *instr, int exec)
 {
@@ -70,65 +72,24 @@ out:
 	return 0;
 }
 
-static int path_command_complete(struct string_list *sl, char *instr)
+static int path_command_complete(char *name, void *priv)
 {
-	struct stat s;
-	DIR *dir;
-	struct dirent *d;
-	char tmp[PATH_MAX];
-	char *path, *p, *n;
-
-	p = path = strdup(getenv("PATH"));
-
-	if (!path)
-		return -1;
-
-	while (p) {
-		n = strchr(p, ':');
-		if (n)
-			*n++ = '\0';
-		if (*p == '\0') {
-			p = n;
-			continue;
-		}
-		dir = opendir(p);
+	struct string_list *sl = priv;
+	char *filename;
 
-		/* We need to check all PATH dirs, so if one failed,
-		 * try next */
-		if (!dir) {
-			p = n;
-			continue;
-		}
+	filename = strrchr(name, '/') + 1;
+	if (!filename)
+		return -EINVAL;
 
-		while ((d = readdir(dir))) {
-			if (!strcmp(d->d_name, ".") ||
-					!strcmp(d->d_name, ".."))
-				continue;
+	strcat(filename, " ");
 
-			if (!strncmp(instr, d->d_name, strlen(instr))) {
-				strcpy(tmp, d->d_name);
-				if (!stat(tmp, &s) &&
-						S_ISDIR(s.st_mode))
-					continue;
-				else
-					strcat(tmp, " ");
-
-				/* This function is called
-				 * after command_complete,
-				 * so we check if a double
-				 * entry exist */
-				if (string_list_contains
-						(sl, tmp) == 0) {
-					string_list_add_sorted(sl, tmp);
-				}
-			}
-		}
-
-		closedir(dir);
-		p = n;
-	}
-
-	free(path);
+	/* This function is called
+	 * after command_complete,
+	 * so we check if a double
+	 * entry exist */
+	if (!string_list_contains
+		(sl, filename))
+		string_list_add_sorted(sl, filename);
 
 	return 0;
 }
@@ -334,7 +295,7 @@ int complete(char *instr, char **outstr)
 			instr = t;
 		} else {
 			command_complete(&sl, instr);
-			path_command_complete(&sl, instr);
+			find_execable_like(path_command_complete, instr, &sl);
 			env_param_complete(&sl, instr, 0);
 		}
 		if (*instr == '$')
include/libbb.h +2 -0
index 47b2e08..0ef702b 100644
@@ -11,6 +11,8 @@ char *concat_subpath_file(const char *path, const char *f);
 int execable_file(const char *name);
 char *find_execable(const char *filename);
 char* last_char_is(const char *s, int c);
+int find_execable_like(int found(char *name, void *priv),
+		const char *likelyname, void *priv);
 
 enum {
 	ACTION_RECURSE     = (1 << 0),
lib/libbb.c +1 -1
index e0d7481..daf77c7 100644
@@ -14,6 +14,7 @@
 #include <xfuncs.h>
 #include <malloc.h>
 #include <environment.h>
+#include <errno.h>
 
 /* concatenate path and file name to new allocation buffer,
  * not adding '/' if path name already has '/'
@@ -60,7 +61,6 @@ int execable_file(const char *name)
 }
 EXPORT_SYMBOL(execable_file);
 
-
 /* search $PATH for an executable file;
  * return allocated string containing full path if found;
  * return NULL otherwise;
@@ -89,6 +89,68 @@ char *find_execable(const char *filename)
 }
 EXPORT_SYMBOL(find_execable);

lib/libbb.c char *find_execable(const char *filename) · line 100

Quoted 10 lines
lib/libbb.c +9 -0
 
+/* search $PATH for an executable file which is
+ * like the filename specified in likelyname;
+ * A likelyname on match will call the found function;
+ * Caller need to duplicate the name string in
+ * found functionpointer, if he want to save it;
+ * return 0 on success and <0 on error;
+ */
+int find_execable_like(int found(char *name, void *priv),
+		const char *likelyname, void *priv)

I don't like the name very much. Can we name it execable_complete? Also I would use the likelyname argument as first argument, because then it would read "on 'name' do call 'found'"

(I always stumble over 'execable', it should rather be 'executable', but we have the former everywhere, so either change them all keep it here aswell)

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/2] complete: abstract path complete

Hi,

I prefer this implementation than the older one, because it check on executable(Maybe we add a attribute for that or check on shebang) file and call found with the full path.
I was thinking about to put this as RFC..., because I don't have really a usecase for this.
Some commands can do a autocompletion for files that are in $PATH, when this is needed.

The naming things, I don't like the name, too. I was doing the naming like the others functions.
I will send a v2 with a better name and functionheader

Regards
Alexander Aring

2012/9/11 Sascha Hauer <[email protected]>

Quoted 174 lines · Alexander Aring
Quoted 2 lines

Rewritten path complete, to use it maybe
in another functions.

Do you have a usecase for this?

Quoted 4 lines
---
 common/complete.c | 73

+++++++++++++------------------------------------------

Quoted 98 lines
 include/libbb.h   |  2 ++
 lib/libbb.c       | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 82 insertions(+), 57 deletions(-)
common/complete.c +16 -55
index 6a871ef..a06c070 100644
@@ -25,6 +25,8 @@
 #include <libgen.h>
 #include <command.h>
 #include <environment.h>
+#include <errno.h>
+#include <libbb.h>
 
 static int file_complete(struct string_list *sl, char *instr, int exec)
 {
@@ -70,65 +72,24 @@ out:
      return 0;
 }
 
-static int path_command_complete(struct string_list *sl, char *instr)
+static int path_command_complete(char *name, void *priv)
 {
-     struct stat s;
-     DIR *dir;
-     struct dirent *d;
-     char tmp[PATH_MAX];
-     char *path, *p, *n;
-
-     p = path = strdup(getenv("PATH"));
-
-     if (!path)
-             return -1;
-
-     while (p) {
-             n = strchr(p, ':');
-             if (n)
-                     *n++ = '\0';
-             if (*p == '\0') {
-                     p = n;
-                     continue;
-             }
-             dir = opendir(p);
+     struct string_list *sl = priv;
+     char *filename;
 
-             /* We need to check all PATH dirs, so if one failed,
-              * try next */
-             if (!dir) {
-                     p = n;
-                     continue;
-             }
+     filename = strrchr(name, '/') + 1;
+     if (!filename)
+             return -EINVAL;
 
-             while ((d = readdir(dir))) {
-                     if (!strcmp(d->d_name, ".") ||
-                                     !strcmp(d->d_name, ".."))
-                             continue;
+     strcat(filename, " ");
 
-                     if (!strncmp(instr, d->d_name, strlen(instr))) {
-                             strcpy(tmp, d->d_name);
-                             if (!stat(tmp, &s) &&
-                                             S_ISDIR(s.st_mode))
-                                     continue;
-                             else
-                                     strcat(tmp, " ");
-
-                             /* This function is called
-                              * after command_complete,
-                              * so we check if a double
-                              * entry exist */
-                             if (string_list_contains
-                                             (sl, tmp) == 0) {
-                                     string_list_add_sorted(sl, tmp);
-                             }
-                     }
-             }
-
-             closedir(dir);
-             p = n;
-     }
-
-     free(path);
+     /* This function is called
+      * after command_complete,
+      * so we check if a double
+      * entry exist */
+     if (!string_list_contains
+             (sl, filename))
+             string_list_add_sorted(sl, filename);
 
      return 0;
 }

common/complete.c int complete(char *instr, char **outstr) · line 298

Quoted 5 lines
common/complete.c +1 -1
@@ -334,7 +295,7 @@ int complete(char *instr, char **outstr)
                      instr = t;
              } else {
                      command_complete(&sl, instr);
-                     path_command_complete(&sl, instr);
+                     find_execable_like(path_command_complete, instr,

&sl);

include/libbb.h char *concat_subpath_file(const char *path, const char

Quoted 8 lines
common/complete.c +0 -0
                      env_param_complete(&sl, instr, 0);
              }
              if (*instr == '$')
include/libbb.h +0 -0
index 47b2e08..0ef702b 100644
@@ -11,6 +11,8 @@ char *concat_subpath_file(const char *path, const char

*f);

Quoted 31 lines
include/libbb.h +2 -0
 int execable_file(const char *name);
 char *find_execable(const char *filename);
 char* last_char_is(const char *s, int c);
+int find_execable_like(int found(char *name, void *priv),
+             const char *likelyname, void *priv);
 
 enum {
      ACTION_RECURSE     = (1 << 0),
lib/libbb.c +1 -1
index e0d7481..daf77c7 100644
@@ -14,6 +14,7 @@
 #include <xfuncs.h>
 #include <malloc.h>
 #include <environment.h>
+#include <errno.h>
 
 /* concatenate path and file name to new allocation buffer,
  * not adding '/' if path name already has '/'
@@ -60,7 +61,6 @@ int execable_file(const char *name)
 }
 EXPORT_SYMBOL(execable_file);
 
-
 /* search $PATH for an executable file;
  * return allocated string containing full path if found;
  * return NULL otherwise;
@@ -89,6 +89,68 @@ char *find_execable(const char *filename)
 }
 EXPORT_SYMBOL(find_execable);

lib/libbb.c char *find_execable(const char *filename) · line 100

Quoted 10 lines
lib/libbb.c +9 -0
 
+/* search $PATH for an executable file which is
+ * like the filename specified in likelyname;
+ * A likelyname on match will call the found function;
+ * Caller need to duplicate the name string in
+ * found functionpointer, if he want to save it;
+ * return 0 on success and <0 on error;
+ */
+int find_execable_like(int found(char *name, void *priv),
+             const char *likelyname, void *priv)

I don't like the name very much. Can we name it execable_complete? Also I would use the likelyname argument as first argument, because then it would read "on 'name' do call 'found'"

(I always stumble over 'execable', it should rather be 'executable', but we have the former everywhere, so either change them all keep it here aswell)

Quoted 8 lines

Sascha

--

Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 2/2] complete: abstract path complete

Quoted 10 lines · Alexander Aring

Hi,

I prefer this implementation than the older one, because it check on executable(Maybe we add a attribute for that or check on shebang) file and call found with the full path.
I was thinking about to put this as RFC..., because I don't have really a usecase for this.
Some commands can do a autocompletion for files that are in $PATH, when this is needed.

Quoted 3 lines

The naming things, I don't like the name, too. I was doing the naming like the others functions.
I will send a v2 with a better name and functionheader

do not like it is not a justification to move or rename it

IT remember the shit that did TI guys on the kernel rename and move stuff because x or y do notlinke the naming

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox