diff toys/posix/ln.c @ 694:786841fdb1e0

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.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 7e846e281e38
children 1e1abf1113f2
line wrap: on
line diff
--- a/toys/posix/ln.c	Tue Nov 13 16:13:45 2012 -0600
+++ b/toys/posix/ln.c	Tue Nov 13 17:14:08 2012 -0600
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * ln.c - Create filesystem links
+/* ln.c - Create filesystem links
  *
  * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
  *
@@ -9,17 +7,17 @@
 USE_LN(NEWTOY(ln, "<1nfs", TOYFLAG_BIN))
 
 config LN
-	bool "ln"
-	default y
-	help
-	  usage: ln [-sf] [FROM...] TO
+  bool "ln"
+  default y
+  help
+    usage: ln [-sf] [FROM...] TO
 
-	  Create a link between FROM and TO.
-	  With only one argument, create link in current directory.
+    Create a link between FROM and TO.
+    With only one argument, create link in current directory.
 
-	  -s	Create a symbolic link
-	  -f	Force the creation of the link, even if TO already exists
-          -n	Symlink at destination treated as file
+    -s	Create a symbolic link
+    -f	Force the creation of the link, even if TO already exists
+    -n	Symlink at destination treated as file
 */
 
 #define FOR_ln
@@ -27,41 +25,41 @@
 
 void ln_main(void)
 {
-    char *dest = toys.optargs[--toys.optc], *new;
-    struct stat buf;
-    int i;
+  char *dest = toys.optargs[--toys.optc], *new;
+  struct stat buf;
+  int i;
 
-    // With one argument, create link in current directory.
-    if (!toys.optc) {
-        toys.optc++;
-        dest=".";
-    }
+  // With one argument, create link in current directory.
+  if (!toys.optc) {
+    toys.optc++;
+    dest=".";
+  }
 
-    // Is destination a directory?
-    if (((toys.optflags&FLAG_n) ? lstat : stat)(dest, &buf)
-        || !S_ISDIR(buf.st_mode))
-    {
-        if (toys.optc>1) error_exit("'%s' not a directory");
-        buf.st_mode = 0;
-    }
+  // Is destination a directory?
+  if (((toys.optflags&FLAG_n) ? lstat : stat)(dest, &buf)
+    || !S_ISDIR(buf.st_mode))
+  {
+    if (toys.optc>1) error_exit("'%s' not a directory");
+    buf.st_mode = 0;
+  }
 
-    for (i=0; i<toys.optc; i++) {
-        int rc;
-        char *try = toys.optargs[i];
+  for (i=0; i<toys.optc; i++) {
+    int rc;
+    char *try = toys.optargs[i];
 
-        if (S_ISDIR(buf.st_mode)) {
-            new = strrchr(try, '/');
-            if (!new) new = try;
-            new = xmsprintf("%s/%s", dest, new);
-        } else new = dest;
-        /* Silently unlink the existing target. If it doesn't exist,
-         * then we just move on */
-        if (toys.optflags & FLAG_f) unlink(new);
+    if (S_ISDIR(buf.st_mode)) {
+      new = strrchr(try, '/');
+      if (!new) new = try;
+      new = xmsprintf("%s/%s", dest, new);
+    } else new = dest;
+    /* Silently unlink the existing target. If it doesn't exist,
+     * then we just move on */
+    if (toys.optflags & FLAG_f) unlink(new);
 
-        rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new);
-        if (rc)
-            perror_exit("cannot create %s link from '%s' to '%s'",
-                (toys.optflags & FLAG_s) ? "symbolic" : "hard", try, new);
-        if (new != dest) free(new);
-    }
+    rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new);
+    if (rc)
+      perror_exit("cannot create %s link from '%s' to '%s'",
+        (toys.optflags & FLAG_s) ? "symbolic" : "hard", try, new);
+    if (new != dest) free(new);
+  }
 }