summaryrefslogtreecommitdiffstats
path: root/text-utils/colcrt.c
diff options
context:
space:
mode:
authorSami Kerola2015-08-09 18:50:41 +0200
committerSami Kerola2015-08-09 19:59:52 +0200
commit3a41cdd7b5e1c8512553dfce27ca364f6a68a4f9 (patch)
tree277d242fc7c575ce6fc7922a370169f0beec2af8 /text-utils/colcrt.c
parentmisc: fix redundant assignment and reassignments before use [cppcheck] (diff)
downloadkernel-qcow2-util-linux-3a41cdd7b5e1c8512553dfce27ca364f6a68a4f9.tar.gz
kernel-qcow2-util-linux-3a41cdd7b5e1c8512553dfce27ca364f6a68a4f9.tar.xz
kernel-qcow2-util-linux-3a41cdd7b5e1c8512553dfce27ca364f6a68a4f9.zip
colcrt: use #define in place of magic constants
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/colcrt.c')
-rw-r--r--text-utils/colcrt.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c
index 567e7b5cf..cf630c404 100644
--- a/text-utils/colcrt.c
+++ b/text-utils/colcrt.c
@@ -68,7 +68,10 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out);
* Option -2 forces printing of all half lines.
*/
-wchar_t page[267][132];
+#define FLUSH_SIZE 62
+#define PAGE_ARRAY_ROWS 267
+#define PAGE_ARRAY_COLS 132
+wchar_t page[PAGE_ARRAY_ROWS][PAGE_ARRAY_COLS];
int outline = 1;
int outcol;
@@ -158,8 +161,8 @@ void colcrt(FILE *f) {
}
switch (c) {
case '\n':
- if (outline >= 265)
- pflush(62);
+ if (outline >= (PAGE_ARRAY_ROWS - 2))
+ pflush(FLUSH_SIZE);
outline += 2;
outcol = 0;
continue;
@@ -170,8 +173,8 @@ void colcrt(FILE *f) {
c = getwc(f);
switch (c) {
case '9':
- if (outline >= 266)
- pflush(62);
+ if (outline >= (PAGE_ARRAY_ROWS - 1))
+ pflush(FLUSH_SIZE);
outline++;
continue;
case '8':
@@ -198,7 +201,7 @@ void colcrt(FILE *f) {
/* fallthrough */
default:
w = wcwidth(c);
- if (outcol + w > 132) {
+ if (outcol + w > PAGE_ARRAY_COLS) {
outcol++;
continue;
}
@@ -207,7 +210,7 @@ void colcrt(FILE *f) {
if (c == '_') {
if (suppresul)
continue;
- cp += 132;
+ cp += PAGE_ARRAY_COLS;
c = '-';
}
if (*cp == 0) {
@@ -250,8 +253,8 @@ void pflush(int ol)
l = ol;
lastomit = 0;
- if (l > 266)
- l = 266;
+ if (l > (PAGE_ARRAY_ROWS - 1))
+ l = PAGE_ARRAY_ROWS - 1;
else
l |= 1;
for (i = first | 1; i < l; i++) {
@@ -274,8 +277,8 @@ void pflush(int ol)
}
putwchar('\n');
}
- memmove(page, page[ol], (267 - ol) * 132 * sizeof(wchar_t));
- memset(page[267 - ol], '\0', ol * 132 * sizeof(wchar_t));
+ memmove(page, page[ol], (PAGE_ARRAY_ROWS - ol) * PAGE_ARRAY_COLS * sizeof(wchar_t));
+ memset(page[PAGE_ARRAY_ROWS - ol], '\0', ol * PAGE_ARRAY_COLS * sizeof(wchar_t));
outline -= ol;
outcol = 0;
first = 1;