]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wall: replace magic number by named value
authorSami Kerola <kerolasa@iki.fi>
Sun, 11 May 2014 19:26:45 +0000 (20:26 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 12 May 2014 11:38:25 +0000 (13:38 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/wall.c

index 1bae9d652a3f1b781f0ac8e0ded05f8dfd334759..80b8678d9a266820eb777a5df644bf6c3c1245ea 100644 (file)
@@ -69,7 +69,8 @@
 #include "fileutils.h"
 #include "closestream.h"
 
-#define WRITE_TIME_OUT 300             /* in seconds */
+#define        TERM_WIDTH      79
+#define        WRITE_TIME_OUT  300             /* in seconds */
 
 /* Function prototypes */
 static char *makemsg(char *fname, char **mvec, int mvecsz,
@@ -225,14 +226,14 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
                 */
                /* snprintf is not always available, but the sprintf's here
                   will not overflow as long as %d takes at most 100 chars */
-               fprintf(fp, "\r%79s\r\n", " ");
+               fprintf(fp, "\r%*s\r\n", TERM_WIDTH, " ");
                sprintf(lbuf, _("Broadcast message from %s@%s (%s) (%s):"),
                              whom, hostname, where, date);
-               fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
+               fprintf(fp, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf);
                free(hostname);
                free(date);
        }
-       fprintf(fp, "%79s\r\n", " ");
+       fprintf(fp, "%*s\r\n", TERM_WIDTH, " ");
 
         if (mvec) {
                /*
@@ -274,8 +275,8 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
                 */
                while (fgets(lbuf, line_max, stdin)) {
                        for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
-                               if (cnt == 79 || ch == '\n') {
-                                       for (; cnt < 79; ++cnt)
+                               if (cnt == TERM_WIDTH || ch == '\n') {
+                                       for (; cnt < TERM_WIDTH; ++cnt)
                                                putc(' ', fp);
                                        putc('\r', fp);
                                        putc('\n', fp);
@@ -288,7 +289,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
                        }
                }
        }
-       fprintf(fp, "%79s\r\n", " ");
+       fprintf(fp, "%*s\r\n", TERM_WIDTH, " ");
 
        free(lbuf);
        rewind(fp);