coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: relpath


From: Jim Meyering
Subject: Re: PATCH: relpath
Date: Sat, 31 Dec 2011 15:03:24 +0100

Pádraig Brady wrote:
> On 12/12/2011 12:24 AM, Pádraig Brady wrote:
>> FYI I'm not forgetting about this.
>> This week I'll be travelling with work,
>> but I intend to tackle this early the following week.
>
> Sorry for the delay.
> Attached is the realpath implementation, which I think
> turned into a good cohesive set of functionality.
> It has this interface:
>
> Usage: src/realpath [OPTION] FILE...
> Print the resolved absolute file name;
> all but the last component must exist

Here are some indentation fixes:

src/realpath.c
--- /tmp/realpath.c.orig        2011-12-31 14:56:55.765991046 +0100
+++ /tmp/realpath.c     2011-12-31 14:56:55.768991122 +0100
@@ -117,3 +116,3 @@
       if (*prefix != *path)
-          break;
+        break;
       prefix++;
@@ -136,5 +135,5 @@
       if (*path1 != *path2)
-          break;
+        break;
       if (*path1 == '/')
-          ret = i;
+        ret = i;
       path1++;
@@ -145,7 +144,7 @@
   if (!*path1 && !*path2)
-      ret = i;
+    ret = i;
   if (!*path1 && *path2 == '/')
-      ret = i;
+    ret = i;
   if (!*path2 && *path1 == '/')
-      ret = i;
+    ret = i;

@@ -182,3 +181,3 @@
               if (*relto_suffix == '/')
-                  printf ("%s", "/..");
+                printf ("%s", "/..");
             }
@@ -190,5 +189,5 @@
           if (*fname_suffix)
-              printf ("%s", ++fname_suffix);
+            printf ("%s", ++fname_suffix);
           else
-              printf ("%c", '.');
+            printf ("%c", '.');
         }
@@ -224,3 +223,3 @@
   if (!relpath (can_fname))
-      printf ("%s%c", can_fname, (use_nuls ? '\0' : '\n'));
+    printf ("%s%c", can_fname, (use_nuls ? '\0' : '\n'));

@@ -286,4 +285,4 @@
           break;
-        case_GETOPT_HELP_CHAR;
-        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
+          case_GETOPT_HELP_CHAR;
+          case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
         default:

Also, while looking through those, I saw a few unnecessary uses of printf.
I think of printf as a big gun (complexity and code size), and try to avoid
using it when the much simpler fputs or putchar will do.  I would use the
latter for all of these:

          printf ("%s", "..");
                  printf ("%s", "/..");
          printf ("%s", fname_suffix);
              printf ("%s", ++fname_suffix);
              printf ("%c", '.');
      printf ("%s%c", can_fname, (use_nuls ? '\0' : '\n'));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]