- stty's visible() function and catv's guts are identical. Merge them into
[oweals/busybox.git] / editors / ed.c
index 0414bfc9d25b75c54446200ecbafdac9e4ad5481..3aca7591224410289fc1479ddda78818f64c7022 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Copyright (c) 2002 by David I. Bell
  * Permission is granted to use, distribute, or modify this source,
@@ -6,16 +7,6 @@
  * The "ed" built-in command (much simplified)
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <memory.h>
-#include <time.h>
-#include <ctype.h>
-#include <sys/param.h>
-#include <malloc.h>
 #include "busybox.h"
 
 #define        USERSIZE        1024    /* max line length typed in by user */
@@ -58,7 +49,7 @@ int ed_main(int argc, char **argv)
                fileName = strdup(argv[1]);
 
                if (fileName == NULL) {
-                       bb_error_msg("No memory");
+                       bb_error_msg("no memory");
                        termEdit();
                        return EXIT_SUCCESS;
                }
@@ -89,8 +80,7 @@ static void doCommands(void)
        char *endbuf, *newname, buf[USERSIZE];
        int len, num1, num2, have1, have2;
 
-       while (TRUE)
-       {
+       while (TRUE) {
                printf(": ");
                fflush(stdout);
 
@@ -104,15 +94,12 @@ static void doCommands(void)
 
                endbuf = &buf[len - 1];
 
-               if (*endbuf != '\n')
-               {
-                       bb_error_msg("Command line too long");
+               if (*endbuf != '\n') {
+                       bb_error_msg("command line too long");
 
-                       do
-                       {
+                       do {
                                len = fgetc(stdin);
-                       }
-                       while ((len != EOF) && (len != '\n'));
+                       } while ((len != EOF) && (len != '\n'));
 
                        continue;
                }
@@ -130,8 +117,7 @@ static void doCommands(void)
                have1 = FALSE;
                have2 = FALSE;
 
-               if ((curNum == 0) && (lastNum > 0))
-               {
+               if ((curNum == 0) && (lastNum > 0)) {
                        curNum = 1;
                        curLine = lines.next;
                }
@@ -142,8 +128,7 @@ static void doCommands(void)
                while (isblank(*cp))
                        cp++;
 
-               if (*cp == ',')
-               {
+               if (*cp == ',') {
                        cp++;
 
                        if (!getNum(&cp, &have2, &num2))
@@ -165,8 +150,7 @@ static void doCommands(void)
                if (!have2)
                        num2 = num1;
 
-               switch (*cp++)
-               {
+               switch (*cp++) {
                        case 'a':
                                addLines(num1 + 1);
                                break;
@@ -181,30 +165,26 @@ static void doCommands(void)
                                break;
 
                        case 'f':
-                               if (*cp && !isblank(*cp))
-                               {
-                                       bb_error_msg("Bad file command");
+                               if (*cp && !isblank(*cp)) {
+                                       bb_error_msg("bad file command");
                                        break;
                                }
 
                                while (isblank(*cp))
                                        cp++;
 
-                               if (*cp == '\0')
-                               {
+                               if (*cp == '\0') {
                                        if (fileName)
                                                printf("\"%s\"\n", fileName);
                                        else
                                                printf("No file name\n");
-
                                        break;
                                }
 
                                newname = strdup(cp);
 
-                               if (newname == NULL)
-                               {
-                                       bb_error_msg("No memory for file name");
+                               if (newname == NULL) {
+                                       bb_error_msg("no memory for file name");
                                        break;
                                }
 
@@ -222,9 +202,8 @@ static void doCommands(void)
                                while (isblank(*cp))
                                        cp++;
 
-                               if ((*cp < 'a') || (*cp > 'a') || cp[1])
-                               {
-                                       bb_error_msg("Bad mark name");
+                               if ((*cp < 'a') || (*cp > 'a') || cp[1]) {
+                                       bb_error_msg("bad mark name");
                                        break;
                                }
 
@@ -243,9 +222,8 @@ static void doCommands(void)
                                while (isblank(*cp))
                                        cp++;
 
-                               if (have1 || *cp)
-                               {
-                                       bb_error_msg("Bad quit command");
+                               if (have1 || *cp) {
+                                       bb_error_msg("bad quit command");
                                        break;
                                }
 
@@ -268,18 +246,16 @@ static void doCommands(void)
                                break;
 
                        case 'r':
-                               if (*cp && !isblank(*cp))
-                               {
-                                       bb_error_msg("Bad read command");
+                               if (*cp && !isblank(*cp)) {
+                                       bb_error_msg("bad read command");
                                        break;
                                }
 
                                while (isblank(*cp))
                                        cp++;
 
-                               if (*cp == '\0')
-                               {
-                                       bb_error_msg("No file name");
+                               if (*cp == '\0') {
+                                       bb_error_msg("no file name");
                                        break;
                                }
 
@@ -299,9 +275,8 @@ static void doCommands(void)
                                break;
 
                        case 'w':
-                               if (*cp && !isblank(*cp))
-                               {
-                                       bb_error_msg("Bad write command");
+                               if (*cp && !isblank(*cp)) {
+                                       bb_error_msg("bad write command");
                                        break;
                                }
 
@@ -316,18 +291,16 @@ static void doCommands(void)
                                if (*cp == '\0')
                                        cp = fileName;
 
-                               if (cp == NULL)
-                               {
-                                       bb_error_msg("No file name specified");
+                               if (cp == NULL) {
+                                       bb_error_msg("no file name specified");
                                        break;
                                }
-       
+
                                writeLines(cp, num1, num2);
                                break;
 
                        case 'z':
-                               switch (*cp)
-                               {
+                               switch (*cp) {
                                case '-':
                                        printLines(curNum-21, curNum, FALSE);
                                        break;
@@ -341,15 +314,14 @@ static void doCommands(void)
                                break;
 
                        case '.':
-                               if (have1)
-                               {
-                                       bb_error_msg("No arguments allowed");
+                               if (have1) {
+                                       bb_error_msg("no arguments allowed");
                                        break;
                                }
 
                                printLines(curNum, curNum, FALSE);
                                break;
-       
+
                        case '-':
                                if (setCurNum(curNum - 1))
                                        printLines(curNum, curNum, FALSE);
@@ -361,8 +333,7 @@ static void doCommands(void)
                                break;
 
                        case '\0':
-                               if (have1)
-                               {
+                               if (have1) {
                                        printLines(num2, num2, FALSE);
                                        break;
                                }
@@ -373,7 +344,7 @@ static void doCommands(void)
                                break;
 
                        default:
-                               bb_error_msg("Unimplemented command");
+                               bb_error_msg("unimplemented command");
                                break;
                }
        }
@@ -387,14 +358,12 @@ static void doCommands(void)
 static void subCommand(const char * cmd, int num1, int num2)
 {
        char *cp, *oldStr, *newStr, buf[USERSIZE];
-       int     delim, oldLen, newLen, deltaLen, offset;
+       int delim, oldLen, newLen, deltaLen, offset;
        LINE *lp, *nlp;
        int globalFlag, printFlag, didSub, needPrint;
 
-       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
-       {
-               bb_error_msg("Bad line range for substitute");
-
+       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
+               bb_error_msg("bad line range for substitute");
                return;
        }
 
@@ -409,10 +378,8 @@ static void subCommand(const char * cmd, int num1, int num2)
        strcpy(buf, cmd);
        cp = buf;
 
-       if (isblank(*cp) || (*cp == '\0'))
-       {
-               bb_error_msg("Bad delimiter for substitute");
-
+       if (isblank(*cp) || (*cp == '\0')) {
+               bb_error_msg("bad delimiter for substitute");
                return;
        }
 
@@ -421,10 +388,8 @@ static void subCommand(const char * cmd, int num1, int num2)
 
        cp = strchr(cp, delim);
 
-       if (cp == NULL)
-       {
-               bb_error_msg("Missing 2nd delimiter for substitute");
-
+       if (cp == NULL) {
+               bb_error_msg("missing 2nd delimiter for substitute");
                return;
        }
 
@@ -438,8 +403,7 @@ static void subCommand(const char * cmd, int num1, int num2)
        else
                cp = "";
 
-       while (*cp) switch (*cp++)
-       {
+       while (*cp) switch (*cp++) {
                case 'g':
                        globalFlag = TRUE;
                        break;
@@ -449,17 +413,13 @@ static void subCommand(const char * cmd, int num1, int num2)
                        break;
 
                default:
-                       bb_error_msg("Unknown option for substitute");
-
+                       bb_error_msg("unknown option for substitute");
                        return;
        }
 
-       if (*oldStr == '\0')
-       {
-               if (searchString[0] == '\0')
-               {
-                       bb_error_msg("No previous search string");
-
+       if (*oldStr == '\0') {
+               if (searchString[0] == '\0') {
+                       bb_error_msg("no previous search string");
                        return;
                }
 
@@ -480,14 +440,11 @@ static void subCommand(const char * cmd, int num1, int num2)
        offset = 0;
        nlp = NULL;
 
-       while (num1 <= num2)
-       {
+       while (num1 <= num2) {
                offset = findString(lp, oldStr, oldLen, offset);
 
-               if (offset < 0)
-               {
-                       if (needPrint)
-                       {
+               if (offset < 0) {
+                       if (needPrint) {
                                printLines(num1, num1, FALSE);
                                needPrint = FALSE;
                        }
@@ -507,12 +464,10 @@ static void subCommand(const char * cmd, int num1, int num2)
                 * If the replacement string is the same size or shorter
                 * than the old string, then the substitution is easy.
                 */
-               if (deltaLen <= 0)
-               {
+               if (deltaLen <= 0) {
                        memcpy(&lp->data[offset], newStr, newLen);
 
-                       if (deltaLen)
-                       {
+                       if (deltaLen) {
                                memcpy(&lp->data[offset + newLen],
                                        &lp->data[offset + oldLen],
                                        lp->len - offset - oldLen);
@@ -525,8 +480,7 @@ static void subCommand(const char * cmd, int num1, int num2)
                        if (globalFlag)
                                continue;
 
-                       if (needPrint)
-                       {
+                       if (needPrint) {
                                printLines(num1, num1, FALSE);
                                needPrint = FALSE;
                        }
@@ -544,10 +498,8 @@ static void subCommand(const char * cmd, int num1, int num2)
                 */
                nlp = (LINE *) malloc(sizeof(LINE) + lp->len + deltaLen);
 
-               if (nlp == NULL)
-               {
-                       bb_error_msg("Cannot get memory for line");
-
+               if (nlp == NULL) {
+                       bb_error_msg("cannot get memory for line");
                        return;
                }
 
@@ -577,8 +529,7 @@ static void subCommand(const char * cmd, int num1, int num2)
                if (globalFlag)
                        continue;
 
-               if (needPrint)
-               {
+               if (needPrint) {
                        printLines(num1, num1, FALSE);
                        needPrint = FALSE;
                }
@@ -588,7 +539,7 @@ static void subCommand(const char * cmd, int num1, int num2)
        }
 
        if (!didSub)
-               bb_error_msg("No substitutions found for \"%s\"", oldStr);
+               bb_error_msg("no substitutions found for \"%s\"", oldStr);
 }
 
 
@@ -604,8 +555,7 @@ static int findString( const LINE * lp, const char * str, int len, int offset)
        cp = &lp->data[offset];
        left = lp->len - offset;
 
-       while (left >= len)
-       {
+       while (left >= len) {
                ncp = memchr(cp, *str, left);
 
                if (ncp == NULL)
@@ -637,11 +587,10 @@ static int findString( const LINE * lp, const char * str, int len, int offset)
  */
 static void addLines(int num)
 {
-       int     len;
-       char    buf[USERSIZE + 1];
+       int len;
+       char buf[USERSIZE + 1];
 
-       while (fgets(buf, sizeof(buf), stdin))
-       {
+       while (fgets(buf, sizeof(buf), stdin)) {
                if ((buf[0] == '.') && (buf[1] == '\n') && (buf[2] == '\0'))
                        return;
 
@@ -650,16 +599,11 @@ static void addLines(int num)
                if (len == 0)
                        return;
 
-               if (buf[len - 1] != '\n')
-               {
-                       bb_error_msg("Line too long");
-
-                       do
-                       {
+               if (buf[len - 1] != '\n') {
+                       bb_error_msg("line too long");
+                       do {
                                len = fgetc(stdin);
-                       }
-                       while ((len != EOF) && (len != '\n'));
-
+                       } while ((len != EOF) && (len != '\n'));
                        return;
                }
 
@@ -672,7 +616,7 @@ static void addLines(int num)
 /*
  * Parse a line number argument if it is present.  This is a sum
  * or difference of numbers, '.', '$', 'x, or a search string.
- * Returns TRUE if successful (whether or not there was a number). 
+ * Returns TRUE if successful (whether or not there was a number).
  * Returns FALSE if there was a parsing error, with a message output.
  * Whether there was a number is returned indirectly, as is the number.
  * The character pointer which stopped the scan is also returned.
@@ -688,13 +632,11 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
        value = 0;
        sign = 1;
 
-       while (TRUE)
-       {
+       while (TRUE) {
                while (isblank(*cp))
                        cp++;
 
-               switch (*cp)
-               {
+               switch (*cp) {
                        case '.':
                                haveNum = TRUE;
                                num = curNum;
@@ -710,10 +652,8 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
                        case '\'':
                                cp++;
 
-                               if ((*cp < 'a') || (*cp > 'z'))
-                               {
-                                       bb_error_msg("Bad mark name");
-
+                               if ((*cp < 'a') || (*cp > 'z')) {
+                                       bb_error_msg("bad mark name");
                                        return FALSE;
                                }
 
@@ -725,8 +665,7 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
                                strcpy(str, ++cp);
                                endStr = strchr(str, '/');
 
-                               if (endStr)
-                               {
+                               if (endStr) {
                                        *endStr++ = '\0';
                                        cp += (endStr - str);
                                }
@@ -742,12 +681,10 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
                                break;
 
                        default:
-                               if (!isdigit(*cp))
-                               {
+                               if (!isdigit(*cp)) {
                                        *retcp = cp;
                                        *retHaveNum = haveNum;
                                        *retNum = value;
-
                                        return TRUE;
                                }
 
@@ -765,8 +702,7 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
                while (isblank(*cp))
                        cp++;
 
-               switch (*cp)
-               {
+               switch (*cp) {
                        case '-':
                                sign = -1;
                                cp++;
@@ -781,7 +717,6 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
                                *retcp = cp;
                                *retHaveNum = haveNum;
                                *retNum = value;
-
                                return TRUE;
                }
        }
@@ -793,15 +728,13 @@ static int getNum(const char **retcp, int *retHaveNum, int *retNum)
  */
 static int initEdit(void)
 {
-       int     i;
+       int i;
 
        bufSize = INITBUF_SIZE;
        bufBase = malloc(bufSize);
 
-       if (bufBase == NULL)
-       {
-               bb_error_msg("No memory for buffer");
-
+       if (bufBase == NULL) {
+               bb_error_msg("no memory for buffer");
                return FALSE;
        }
 
@@ -860,23 +793,19 @@ static void termEdit(void)
  */
 static int readLines(const char * file, int num)
 {
-       int     fd, cc;
+       int fd, cc;
        int len, lineCount, charCount;
        char *cp;
 
-       if ((num < 1) || (num > lastNum + 1))
-       {
-               bb_error_msg("Bad line for read");
-
+       if ((num < 1) || (num > lastNum + 1)) {
+               bb_error_msg("bad line for read");
                return FALSE;
        }
 
        fd = open(file, 0);
 
-       if (fd < 0)
-       {
+       if (fd < 0) {
                perror(file);
-
                return FALSE;
        }
 
@@ -889,18 +818,14 @@ static int readLines(const char * file, int num)
        printf("\"%s\", ", file);
        fflush(stdout);
 
-       do
-       {
+       do {
                cp = memchr(bufPtr, '\n', bufUsed);
 
-               if (cp)
-               {
+               if (cp) {
                        len = (cp - bufPtr) + 1;
 
-                       if (!insertLine(num, bufPtr, len))
-                       {
+                       if (!insertLine(num, bufPtr, len)) {
                                close(fd);
-
                                return FALSE;
                        }
 
@@ -913,22 +838,18 @@ static int readLines(const char * file, int num)
                        continue;
                }
 
-               if (bufPtr != bufBase)
-               {
+               if (bufPtr != bufBase) {
                        memcpy(bufBase, bufPtr, bufUsed);
                        bufPtr = bufBase + bufUsed;
                }
 
-               if (bufUsed >= bufSize)
-               {
+               if (bufUsed >= bufSize) {
                        len = (bufSize * 3) / 2;
                        cp = realloc(bufBase, len);
 
-                       if (cp == NULL)
-                       {
-                               bb_error_msg("No memory for buffer");
+                       if (cp == NULL) {
+                               bb_error_msg("no memory for buffer");
                                close(fd);
-
                                return FALSE;
                        }
 
@@ -941,23 +862,17 @@ static int readLines(const char * file, int num)
                bufUsed += cc;
                bufPtr = bufBase;
 
-       }
-       while (cc > 0);
+       } while (cc > 0);
 
-       if (cc < 0)
-       {
+       if (cc < 0) {
                perror(file);
                close(fd);
-
                return FALSE;
        }
 
-       if (bufUsed)
-       {
-               if (!insertLine(num, bufPtr, bufUsed))
-               {
+       if (bufUsed) {
+               if (!insertLine(num, bufPtr, bufUsed)) {
                        close(fd);
-
                        return -1;
                }
 
@@ -981,12 +896,10 @@ static int readLines(const char * file, int num)
 static int writeLines(const char * file, int num1, int num2)
 {
        LINE *lp;
-       int     fd, lineCount, charCount;
-
-       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
-       {
-               bb_error_msg("Bad line range for write");
+       int fd, lineCount, charCount;
 
+       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
+               bb_error_msg("bad line range for write");
                return FALSE;
        }
 
@@ -997,7 +910,6 @@ static int writeLines(const char * file, int num1, int num2)
 
        if (fd < 0) {
                perror(file);
-
                return FALSE;
        }
 
@@ -1006,20 +918,15 @@ static int writeLines(const char * file, int num1, int num2)
 
        lp = findLine(num1);
 
-       if (lp == NULL)
-       {
+       if (lp == NULL) {
                close(fd);
-
                return FALSE;
        }
 
-       while (num1++ <= num2)
-       {
-               if (write(fd, lp->data, lp->len) != lp->len)
-               {
+       while (num1++ <= num2) {
+               if (write(fd, lp->data, lp->len) != lp->len) {
                        perror(file);
                        close(fd);
-
                        return FALSE;
                }
 
@@ -1028,15 +935,12 @@ static int writeLines(const char * file, int num1, int num2)
                lp = lp->next;
        }
 
-       if (close(fd) < 0)
-       {
+       if (close(fd) < 0) {
                perror(file);
-
                return FALSE;
        }
 
        printf("%d lines, %d chars\n", lineCount, charCount);
-
        return TRUE;
 }
 
@@ -1053,10 +957,8 @@ static int printLines(int num1, int num2, int expandFlag)
        const char *cp;
        int ch, count;
 
-       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
-       {
-               bb_error_msg("Bad line range for print");
-
+       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
+               bb_error_msg("bad line range for print");
                return FALSE;
        }
 
@@ -1065,10 +967,8 @@ static int printLines(int num1, int num2, int expandFlag)
        if (lp == NULL)
                return FALSE;
 
-       while (num1 <= num2)
-       {
-               if (!expandFlag)
-               {
+       while (num1 <= num2) {
+               if (!expandFlag) {
                        write(1, lp->data, lp->len);
                        setCurNum(num1++);
                        lp = lp->next;
@@ -1086,24 +986,20 @@ static int printLines(int num1, int num2, int expandFlag)
                if ((count > 0) && (cp[count - 1] == '\n'))
                        count--;
 
-               while (count-- > 0)
-               {
+               while (count-- > 0) {
                        ch = *cp++;
 
-                       if (ch & 0x80)
-                       {
+                       if (ch & 0x80) {
                                fputs("M-", stdout);
                                ch &= 0x7f;
                        }
 
-                       if (ch < ' ')
-                       {
+                       if (ch < ' ') {
                                fputc('^', stdout);
                                ch += '@';
                        }
 
-                       if (ch == 0x7f)
-                       {
+                       if (ch == 0x7f) {
                                fputc('^', stdout);
                                ch = '?';
                        }
@@ -1132,19 +1028,15 @@ static int insertLine(int num, const char * data, int len)
 {
        LINE *newLp, *lp;
 
-       if ((num < 1) || (num > lastNum + 1))
-       {
-               bb_error_msg("Inserting at bad line number");
-
+       if ((num < 1) || (num > lastNum + 1)) {
+               bb_error_msg("inserting at bad line number");
                return FALSE;
        }
 
-       newLp = (LINE *) malloc(sizeof(LINE) + len - 1);
-
-       if (newLp == NULL) 
-       {
-               bb_error_msg("Failed to allocate memory for line");
+       newLp = malloc(sizeof(LINE) + len - 1);
 
+       if (newLp == NULL) {
+               bb_error_msg("failed to allocate memory for line");
                return FALSE;
        }
 
@@ -1153,14 +1045,11 @@ static int insertLine(int num, const char * data, int len)
 
        if (num > lastNum)
                lp = &lines;
-       else
-       {
+       else {
                lp = findLine(num);
 
-               if (lp == NULL)
-               {
+               if (lp == NULL) {
                        free((char *) newLp);
-
                        return FALSE;
                }
        }
@@ -1172,7 +1061,6 @@ static int insertLine(int num, const char * data, int len)
 
        lastNum++;
        dirty = TRUE;
-
        return setCurNum(num);
 }
 
@@ -1185,10 +1073,8 @@ static int deleteLines(int num1, int num2)
        LINE *lp, *nlp, *plp;
        int count;
 
-       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
-       {
-               bb_error_msg("Bad line numbers for delete");
-
+       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
+               bb_error_msg("bad line numbers for delete");
                return FALSE;
        }
 
@@ -1197,8 +1083,7 @@ static int deleteLines(int num1, int num2)
        if (lp == NULL)
                return FALSE;
 
-       if ((curNum >= num1) && (curNum <= num2))
-       {
+       if ((curNum >= num1) && (curNum <= num2)) {
                if (num2 < lastNum)
                        setCurNum(num2 + 1);
                else if (num1 > 1)
@@ -1214,8 +1099,7 @@ static int deleteLines(int num1, int num2)
 
        lastNum -= count;
 
-       while (count-- > 0)
-       {
+       while (count-- > 0) {
                nlp = lp->next;
                plp = lp->prev;
                plp->next = nlp;
@@ -1245,19 +1129,14 @@ static int searchLines(const char *str, int num1, int num2)
        const LINE *lp;
        int len;
 
-       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
-       {
-               bb_error_msg("Bad line numbers for search");
-
+       if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
+               bb_error_msg("bad line numbers for search");
                return 0;
        }
 
-       if (*str == '\0')
-       {
-               if (searchString[0] == '\0')
-               {
-                       bb_error_msg("No previous search string");
-
+       if (*str == '\0') {
+               if (searchString[0] == '\0') {
+                       bb_error_msg("no previous search string");
                        return 0;
                }
 
@@ -1274,8 +1153,7 @@ static int searchLines(const char *str, int num1, int num2)
        if (lp == NULL)
                return 0;
 
-       while (num1 <= num2)
-       {
+       while (num1 <= num2) {
                if (findString(lp, str, len, 0) >= 0)
                        return num1;
 
@@ -1283,8 +1161,7 @@ static int searchLines(const char *str, int num1, int num2)
                lp = lp->next;
        }
 
-       bb_error_msg("Cannot find string \"%s\"", str);
-
+       bb_error_msg("cannot find string \"%s\"", str);
        return 0;
 }
 
@@ -1297,15 +1174,12 @@ static LINE *findLine(int num)
        LINE *lp;
        int lnum;
 
-       if ((num < 1) || (num > lastNum))
-       {
-               bb_error_msg("Line number %d does not exist", num);
-
+       if ((num < 1) || (num > lastNum)) {
+               bb_error_msg("line number %d does not exist", num);
                return NULL;
        }
 
-       if (curNum <= 0)
-       {
+       if (curNum <= 0) {
                curNum = 1;
                curLine = lines.next;
        }
@@ -1316,29 +1190,24 @@ static LINE *findLine(int num)
        lp = curLine;
        lnum = curNum;
 
-       if (num < (curNum / 2))
-       {
+       if (num < (curNum / 2)) {
                lp = lines.next;
                lnum = 1;
        }
-       else if (num > ((curNum + lastNum) / 2))
-       {
+       else if (num > ((curNum + lastNum) / 2)) {
                lp = lines.prev;
                lnum = lastNum;
        }
 
-       while (lnum < num)
-       {
+       while (lnum < num) {
                lp = lp->next;
                lnum++;
        }
 
-       while (lnum > num)
-       {
+       while (lnum > num) {
                lp = lp->prev;
                lnum--;
        }
-
        return lp;
 }
 
@@ -1358,6 +1227,5 @@ static int setCurNum(int num)
 
        curNum = num;
        curLine = lp;
-
        return TRUE;
 }