[Toybox] [PATCH 2/2] Whitespace cleanup on cut.

Daniel K. Levy alliedenvy at gmail.com
Sat Aug 29 18:12:04 PDT 2015


Whitespace cleanup on cut.

---
 toys/posix/cut.c | 110 +++++++++++++++++++++++++++--------------------
--------
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/toys/posix/cut.c b/toys/posix/cut.c
index 934e27f..139ea24 100644
--- a/toys/posix/cut.c
+++ b/toys/posix/cut.c
@@ -51,16 +51,16 @@ static void add_to_list(int start, int end)
   temp1_node->start = start;
   temp1_node->end = end;
 
-  /* Special case for the head end */
+  // Special case for the head end
   if (!TT.slist_head || ((struct slist*)TT.slist_head)->start >=
start) {
     temp1_node->next = TT.slist_head;
     TT.slist_head = temp1_node;
-  } else { 
-    /* Locate the node before the point of insertion */   
+  } else {
+    // Locate the node before the point of insertion
     current = TT.slist_head;
     while (current->next && current->next->start < temp1_node->start)
-        current = current->next;
-    temp1_node->next = current->next;   
+      current = current->next;
+    temp1_node->next = current->next;
     current->next = temp1_node;
   }
 }
@@ -75,22 +75,22 @@ static void parse_list(char *list)
     if (!ctoken) break;
     if (!*ctoken) error_exit("empty position specifier");
 
-    //Get start position.
+    // Get start position.
     if (*(dtoken = strsep(&ctoken, "-")))
       start = atolx_range(dtoken, 1, INT_MAX)-1;
 
-    //Get end position.
-    if (!ctoken) end = -1; //case e.g. 1,2,3
-    else if (*ctoken) {//case e.g. N-M
+    // Get end position.
+    if (!ctoken) end = -1; // case e.g. 1,2,3
+    else if (*ctoken) { // case e.g. N-M
       end = atolx_range(ctoken, start+1, INT_MAX)-1;
-      if(end == start) end = -1;
+      if (end == start) end = -1;
     } else if (!*dtoken)
       error_exit("empty position specifier");
 
     add_to_list(start, end);
     TT.nelem++;
   }
-  //if list is missing in command line.
+  // if list is missing in command line.
   if (!TT.nelem) error_exit("missing positions list");
 }
 
@@ -104,39 +104,39 @@ static void do_fcut(int fd, char *name)
     int start, ndelimiters = -1, nprinted_fields = 0;
     struct slist *temp_node = TT.slist_head;
 
-    //does line have any delimiter?.
+    // does line have any delimiter?
     if (!strchr(buff, *TT.delim)) {
-      //if not then print whole line and move to next line.
+      // if not then print whole line and move to next line.
       if (!(toys.optflags & FLAG_s)) xputs(buff);
       continue;
     }
 
     pfield = xzalloc(strlen(buff) + 1);
 
-      //process list on each line.
-      for (cpos = 0; temp_node && cpos < TT.nelem && buff; cpos++) {
-        start = temp_node->start;
-        do {
-          char *field = 0;
+    // process list on each line.
+    for (cpos = 0; temp_node && cpos < TT.nelem && buff; cpos++) {
+      start = temp_node->start;
+      do {
+        char *field = 0;
 
-          //count number of delimeters per line.
-          while (buff && ndelimiters < start) {
-              ndelimiters++;
-              field = strsep(&buff, TT.delim);
-          }
-          //print field (if not yet printed).
-          if (!pfield[ndelimiters] && ndelimiters == start) {
-              //put delimiter.
-              if (nprinted_fields++ > 0) xputc(*TT.delim);
-              if (field) fputs(field, stdout);
-              //make sure this field won't print again.
-              pfield[ndelimiters] = (char) 0x23; //put some char at
this position.
-          }
-          start++;
-          if ((temp_node->end < 0) || !buff) break;          
-        } while(start <= temp_node->end);
-        temp_node = temp_node->next;
-      }
+        // count number of delimeters per line.
+        while (buff && ndelimiters < start) {
+          ndelimiters++;
+          field = strsep(&buff, TT.delim);
+        }
+        // print field (if not yet printed).
+        if (!pfield[ndelimiters] && ndelimiters == start) {
+          // put delimiter.
+          if (nprinted_fields++ > 0) xputc(*TT.delim);
+          if (field) fputs(field, stdout);
+          // make sure this field won't print again.
+          pfield[ndelimiters] = (char) 0x23; // put some char at this
position.
+        }
+        start++;
+        if ((temp_node->end < 0) || !buff) break;
+      } while (start <= temp_node->end);
+      temp_node = temp_node->next;
+    }
     xputc('\n');
     free(pfield);
   }
@@ -153,28 +153,28 @@ static void do_bccut(int fd, char *name)
     char *pfield = xzalloc(buffln + 1);
     struct slist *temp_node = TT.slist_head;
 
-      for (cpos = 0; temp_node && cpos < TT.nelem; cpos++) {
-        int start;
+    for (cpos = 0; temp_node && cpos < TT.nelem; cpos++) {
+      int start;
 
-        start = temp_node->start;
-        while (start < buffln) {
-          //to avoid duplicate field printing.
-          if (pfield[start]) {
-              if (++start <= temp_node->end) continue;
-              temp_node = temp_node->next;
-              break;
-          } else {
-            //make sure this field won't print again.
-            pfield[start] = (char) 0x23; //put some char at this
position.
-            xputc(buff[start]);
-          }
-          if (++start > temp_node->end) {
-            temp_node = temp_node->next;
-            break;
-          }
+      start = temp_node->start;
+      while (start < buffln) {
+        // to avoid duplicate field printing.
+        if (pfield[start]) {
+          if (++start <= temp_node->end) continue;
+          temp_node = temp_node->next;
+          break;
+        } else {
+          // make sure this field won't print again.
+          pfield[start] = (char) 0x23; // put some char at this
position.
+          xputc(buff[start]);
+        }
+        if (++start > temp_node->end) {
+          temp_node = temp_node->next;
+          break;
         }
       }
-      xputc('\n');
+    }
+    xputc('\n');
     free(pfield);
   }
 }
--


 1440897124.0


More information about the Toybox mailing list