projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
prettyness police
[unix-history]
/
usr
/
src
/
usr.bin
/
banner
/
banner.c
diff --git
a/usr/src/usr.bin/banner/banner.c
b/usr/src/usr.bin/banner/banner.c
index
6d3cb8a
..
e4bb05b
100644
(file)
--- a/
usr/src/usr.bin/banner/banner.c
+++ b/
usr/src/usr.bin/banner/banner.c
@@
-1,16
+1,32
@@
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
-static char sccsid[] = " banner.c 4.1 82/10/24 ";
+#ifndef lint
+static char sccsid[] = "@(#)banner.c 8.2 (Berkeley) %G%";
+#endif /* not lint */
/*
* banner - prints large signs
* banner [-w#] [-d] [-t] message ...
*/
/*
* banner - prints large signs
* banner [-w#] [-d] [-t] message ...
*/
+#include <err.h>
#include <stdio.h>
#include <stdio.h>
-#define dir(f) "/e1/mrh/ucb/lib/f"
-#define INDTBL dir(ban.dat.indtbl)
-#define OBJECT dir(ban.dat.object)
-#define MAXMSG 100
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define MAXMSG 1024
#define DWIDTH 132
#define NCHARS 128
#define NBYTES 9271
#define DWIDTH 132
#define NCHARS 128
#define NBYTES 9271
@@
-975,92
+991,75
@@
char data_table[NBYTES] = {
/* 9270 */ 193
};
/* 9270 */ 193
};
-FILE *fd;
-int i,j,k;
-char c;
-int width = DWIDTH; /* -w option: scrunch letters to 80 columns */
-int debug;
-int trace;
-char line[DWIDTH];
-char print[DWIDTH];
-char message[MAXMSG];
-char *messp;
-int nchars;
-int linen;
-int x,y;
-int term,dup;
-int pc;
-int max;
+char line[DWIDTH];
+char message[MAXMSG];
+char print[DWIDTH];
+int debug, i, j, linen, max, nchars, pc, term, trace, x, y;
+int width = DWIDTH; /* -w option: scrunch letters to 80 columns */
-main(argc,argv)
-int argc;
-char **argv;
+int
+main(argc, argv)
+ int argc;
+ char **argv;
{
{
- if (argc > 1 && argv[1][0] == '-') {
- switch(argv[1][1]) {
+ int ch;
+
+ while ((ch = getopt(argc, argv, "w:td")) != EOF)
+ switch(ch) {
case 'w':
case 'w':
- width = atoi(
&argv[1][2]
);
- if (width
==
0)
+ width = atoi(
optarg
);
+ if (width
<=
0)
width = 80;
break;
case 'd':
width = 80;
break;
case 'd':
- debug
++
;
+ debug
= 1
;
break;
case 't':
break;
case 't':
- trace
++
;
+ trace
= 1
;
break;
break;
+ case '?':
default:
default:
-
printf("bad switch %s\n",argv[1]
);
-
break
;
+
fprintf(stderr, "usage: banner [-w width]\n"
);
+
exit(1)
;
}
}
- argc--;
- argv++;
- }
+ argc -= optind;
+ argv += optind;
- for (i
=0; i<
width; i++) {
+ for (i
= 0; i <
width; i++) {
j = i * 132 / width;
print[j] = 1;
}
j = i * 132 / width;
print[j] = 1;
}
-#ifdef notdef
- fd = fopen(INDTBL, "r");
- for (i=0; i<NCHARS; i++) {
- fscanf(fd, "%d", &asc_ptr[i]);
- }
- fclose(fd);
-
- fd = fopen(OBJECT, "r");
- fread(data_table, 1, NBYTES, fd);
- fclose(fd);
-#endif
/* Have now read in the data. Next get the message to be printed. */
/* Have now read in the data. Next get the message to be printed. */
- if (
argc > 1
) {
- strcpy(message,
argv[1]
);
-
for (i=2; i<argc; i++
) {
+ if (
*argv
) {
+ strcpy(message,
*argv
);
+
while (*++argv
) {
strcat(message, " ");
strcat(message, " ");
- strcat(message,
argv[i]
);
+ strcat(message,
*argv
);
}
}
+ nchars = strlen(message);
} else {
fprintf(stderr,"Message: ");
} else {
fprintf(stderr,"Message: ");
- gets(message);
+ (void)fgets(message, sizeof(message), stdin);
+ nchars = strlen(message);
+ message[nchars--] = '\0'; /* get rid of newline */
}
}
- nchars = strlen(message);
/* some debugging print statements */
if (debug) {
printf("int asc_ptr[128] = {\n");
/* some debugging print statements */
if (debug) {
printf("int asc_ptr[128] = {\n");
- for (i
=0; i<
128; i++) {
+ for (i
= 0; i <
128; i++) {
printf("%4d, ",asc_ptr[i]);
if ((i+1) % 8 == 0)
printf("\n");
}
printf("};\nchar data_table[NBYTES] = {\n");
printf(" /* ");
printf("%4d, ",asc_ptr[i]);
if ((i+1) % 8 == 0)
printf("\n");
}
printf("};\nchar data_table[NBYTES] = {\n");
printf(" /* ");
- for (i
=0; i<
10; i++) printf(" %3d ",i);
+ for (i
= 0; i <
10; i++) printf(" %3d ",i);
printf(" */\n");
printf(" */\n");
- for (i
=0; i<
NBYTES; i += 10) {
+ for (i
= 0; i <
NBYTES; i += 10) {
printf("/* %4d */ ",i);
printf("/* %4d */ ",i);
- for (j
=i; j<
i+10; j++) {
+ for (j
= i; j <
i+10; j++) {
x = data_table[j] & 0377;
printf(" %3d, ",x);
}
x = data_table[j] & 0377;
printf(" %3d, ",x);
}
@@
-1071,27
+1070,30
@@
char **argv;
/* check message to make sure it's legal */
j = 0;
/* check message to make sure it's legal */
j = 0;
- for (i=0; i<nchars; i++)
- if (asc_ptr[message[i]] == 0) {
- printf("The character '%c' is not in my character set.\n",message[i]);
+ for (i = 0; i < nchars; i++)
+ if ((u_char) message[i] >= NCHARS ||
+ asc_ptr[(u_char) message[i]] == 0) {
+ warnx("The character '%c' is not in my character set",
+ message[i]);
j++;
}
j++;
}
- if (j) exit(1);
+ if (j)
+ exit(1);
if (trace)
printf("Message '%s' is OK\n",message);
/* Now have message. Print it one character at a time. */
if (trace)
printf("Message '%s' is OK\n",message);
/* Now have message. Print it one character at a time. */
- for (i
=0; i<
nchars; i++) {
+ for (i
= 0; i <
nchars; i++) {
if (trace)
printf("Char #%d: %c\n", i, message[i]);
if (trace)
printf("Char #%d: %c\n", i, message[i]);
- for (j
=0; j<
DWIDTH; j++) line[j] = ' ';
- pc = asc_ptr[message[i]];
+ for (j
= 0; j <
DWIDTH; j++) line[j] = ' ';
+ pc = asc_ptr[
(u_char)
message[i]];
term = 0;
max = 0;
linen = 0;
term = 0;
max = 0;
linen = 0;
- while (
!term
) {
- if (pc
<
0 || pc > NBYTES) {
+ while (
!term
) {
+ if (pc
<
0 || pc > NBYTES) {
printf("bad pc: %d\n",pc);
exit(1);
}
printf("bad pc: %d\n",pc);
exit(1);
}
@@
-1103,13
+1105,13
@@
char **argv;
x = x & 63;
while (x--) {
if (print[linen++]) {
x = x & 63;
while (x--) {
if (print[linen++]) {
- for (j=0; j
<=
max; j++)
+ for (j=0; j
<=
max; j++)
if (print[j])
putchar(line[j]);
putchar('\n');
}
}
if (print[j])
putchar(line[j]);
putchar('\n');
}
}
- for (j
=0; j<
DWIDTH; j++) line[j] = ' ';
+ for (j
= 0; j <
DWIDTH; j++) line[j] = ' ';
pc++;
}
else {
pc++;
}
else {