diff options
author | Rob Landley <rob@landley.net> | 2012-11-13 17:14:08 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-11-13 17:14:08 -0600 |
commit | 7aa651a6a4496d848f86de9b1e6b3a003256a01f (patch) | |
tree | 6995fb4b7cc2e90a6706b0239ebaf95d9dbab530 /toys/other/which.c | |
parent | 571b0706cce45716126776d0ad0f6ac65f4586e3 (diff) | |
download | toybox-7aa651a6a4496d848f86de9b1e6b3a003256a01f.tar.gz |
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
Diffstat (limited to 'toys/other/which.c')
-rw-r--r-- | toys/other/which.c | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/toys/other/which.c b/toys/other/which.c index 44b1f568..fc65fe8a 100644 --- a/toys/other/which.c +++ b/toys/other/which.c @@ -1,20 +1,18 @@ -/* vi: set sw=4 ts=4: - * - * which.c - Find executable files in $PATH. +/* which.c - Find executable files in $PATH. * * Copyright 2006 Rob landley <rob@landley.net> USE_WHICH(NEWTOY(which, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) config WHICH - bool "which" - default y - help - usage: which [-a] filename ... + bool "which" + default y + help + usage: which [-a] filename ... - Search $PATH for executable files matching filename(s). + Search $PATH for executable files matching filename(s). - -a Show all matches + -a Show all matches */ #include "toys.h" @@ -24,46 +22,47 @@ config WHICH static int which_in_path(char *filename) { - struct string_list *list; + struct string_list *list; - // If they gave us a path, don't worry about $PATH or -a + // If they gave us a path, don't worry about $PATH or -a - if (strchr(filename, '/')) { - // Confirm it has the executable bit set, and it's not a directory. - if (!access(filename, X_OK)) { - struct stat st; + if (strchr(filename, '/')) { + // Confirm it has the executable bit set, and it's not a directory. + if (!access(filename, X_OK)) { + struct stat st; - if (!stat(filename, &st) && S_ISREG(st.st_mode)) { - puts(filename); - return 0; - } - return 1; - } - } + if (!stat(filename, &st) && S_ISREG(st.st_mode)) { + puts(filename); + return 0; + } + return 1; + } + } - // Search $PATH for matches. - list = find_in_path(getenv("PATH"), filename); - if (!list) return 1; + // Search $PATH for matches. + list = find_in_path(getenv("PATH"), filename); + if (!list) return 1; - // Print out matches - while (list) { - if (!access(list->str, X_OK)) { - puts(list->str); - // If we should stop at one match, do so - if (!toys.optflags) { - llist_traverse(list, free); - break; - } - } - free(llist_pop(&list)); - } + // Print out matches + while (list) { + if (!access(list->str, X_OK)) { + puts(list->str); + // If we should stop at one match, do so + if (!toys.optflags) { + llist_traverse(list, free); + break; + } + } + free(llist_pop(&list)); + } - return 0; + return 0; } void which_main(void) { - int i; - for (i=0; toys.optargs[i]; i++) - toys.exitval |= which_in_path(toys.optargs[i]); + int i; + + for (i=0; toys.optargs[i]; i++) + toys.exitval |= which_in_path(toys.optargs[i]); } |