SCCS-vsn: usr.bin/column/column.c 8.2
SCCS-vsn: usr.bin/comm/comm.c 8.2
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)column.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)column.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#include <sys/ioctl.h>
#endif /* not lint */
#include <sys/types.h>
#include <sys/ioctl.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void c_columnate __P((void));
void *emalloc __P((int));
void input __P((FILE *));
void maketbl __P((void));
void c_columnate __P((void));
void *emalloc __P((int));
void input __P((FILE *));
void maketbl __P((void));
void print __P((void));
void r_columnate __P((void));
void usage __P((void));
void print __P((void));
void r_columnate __P((void));
void usage __P((void));
input(fp);
(void)fclose(fp);
} else {
input(fp);
(void)fclose(fp);
} else {
- (void)fprintf(stderr, "column: %s: %s\n", *argv,
- strerror(errno));
- register int chcnt, col, cnt, numcols;
- int endcol;
+ int chcnt, col, cnt, endcol, numcols;
char **lp;
maxlength = (maxlength + TAB) & ~(TAB - 1);
char **lp;
maxlength = (maxlength + TAB) & ~(TAB - 1);
- register int base, chcnt, cnt, col;
- int endcol, numcols, numrows, row;
+ int base, chcnt, cnt, col, endcol, numcols, numrows, row;
maxlength = (maxlength + TAB) & ~(TAB - 1);
numcols = termwidth / maxlength;
maxlength = (maxlength + TAB) & ~(TAB - 1);
numcols = termwidth / maxlength;
- register int cnt;
- register char **lp;
for (cnt = entries, lp = list; cnt--; ++lp)
(void)printf("%s\n", *lp);
for (cnt = entries, lp = list; cnt--; ++lp)
(void)printf("%s\n", *lp);
- register TBL *t;
- register int coloff, cnt;
- register char *p, **lp;
+ TBL *t;
+ int coloff, cnt;
+ char *p, **lp;
int *lens, maxcols;
TBL *tbl;
char **cols;
int *lens, maxcols;
TBL *tbl;
char **cols;
DEFCOLS * sizeof(char *))) ||
!(lens = realloc(lens,
(u_int)maxcols + DEFCOLS * sizeof(int))))
DEFCOLS * sizeof(char *))) ||
!(lens = realloc(lens,
(u_int)maxcols + DEFCOLS * sizeof(int))))
- nomem();
- bzero((char *)lens + maxcols * sizeof(int),
- DEFCOLS * sizeof(int));
+ err(1, NULL);
+ memset((char *)lens + maxcols * sizeof(int),
+ 0, DEFCOLS * sizeof(int));
maxcols += DEFCOLS;
}
t->list = emalloc(coloff * sizeof(char *));
maxcols += DEFCOLS;
}
t->list = emalloc(coloff * sizeof(char *));
-#define MAXLINELEN (2048 + 1)
+#define MAXLINELEN (LINE_MAX + 1)
- register int len;
- register char *p;
- char buf[MAXLINELEN];
+ int len;
+ char *p, buf[MAXLINELEN];
if (!list)
list = emalloc((maxentry = DEFNUM) * sizeof(char *));
if (!list)
list = emalloc((maxentry = DEFNUM) * sizeof(char *));
for (p = buf; *p && isspace(*p); ++p);
if (!*p)
continue;
for (p = buf; *p && isspace(*p); ++p);
if (!*p)
continue;
- if (!(p = index(p, '\n'))) {
- (void)fprintf(stderr, "column: line too long.\n");
+ if (!(p = strchr(p, '\n'))) {
+ warnx("line too long");
maxentry += DEFNUM;
if (!(list = realloc(list,
(u_int)maxentry * sizeof(char *))))
maxentry += DEFNUM;
if (!(list = realloc(list,
(u_int)maxentry * sizeof(char *))))
}
list[entries++] = strdup(buf);
}
}
list[entries++] = strdup(buf);
}
char *p;
if (!(p = malloc(size)))
char *p;
if (!(p = malloc(size)))
- nomem();
- bzero(p, size);
- return(p);
-}
-
-void
-nomem()
-{
- (void)fprintf(stderr, "column: out of memory.\n");
- exit(1);
+ err(1, NULL);
+ memset(p, 0, size);
+ return (p);
(void)fprintf(stderr,
"usage: column [-tx] [-c columns] [file ...]\n");
exit(1);
(void)fprintf(stderr,
"usage: column [-tx] [-c columns] [file ...]\n");
exit(1);
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)comm.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)comm.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#include <fcntl.h>
#endif /* not lint */
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-#define MAXLINELEN (_POSIX2_LINE_MAX + 1)
+#define MAXLINELEN (LINE_MAX + 1)
char *tabs[] = { "", "\t", "\t\t" };
char *tabs[] = { "", "\t", "\t\t" };
+FILE *file __P((char *));
+void show __P((FILE *, char *, char *));
+void usage __P((void));
+
+int
+main(argc, argv)
int argc;
char *argv[];
{
int argc;
char *argv[];
{
- register int comp, file1done, file2done, read1, read2;
- register char *col1, *col2, *col3;
+ int comp, file1done, file2done, read1, read2;
int ch, flag1, flag2, flag3;
int ch, flag1, flag2, flag3;
- FILE *fp1, *fp2, *file();
+ FILE *fp1, *fp2;
+ char *col1, *col2, *col3;
char **p, line1[MAXLINELEN], line2[MAXLINELEN];
char **p, line1[MAXLINELEN], line2[MAXLINELEN];
flag1 = flag2 = flag3 = 1;
while ((ch = getopt(argc, argv, "-123")) != EOF)
flag1 = flag2 = flag3 = 1;
while ((ch = getopt(argc, argv, "-123")) != EOF)
show(fp, offset, buf)
FILE *fp;
char *offset, *buf;
{
show(fp, offset, buf)
FILE *fp;
char *offset, *buf;
{
do {
(void)printf("%s%s", offset, buf);
} while (fgets(buf, MAXLINELEN, fp));
do {
(void)printf("%s%s", offset, buf);
} while (fgets(buf, MAXLINELEN, fp));
FILE *fp;
if (!strcmp(name, "-"))
FILE *fp;
if (!strcmp(name, "-"))
if ((fp = fopen(name, "r")) == NULL) {
(void)fprintf(stderr, "comm: %s: %s\n", name, strerror(errno));
exit(1);
}
if ((fp = fopen(name, "r")) == NULL) {
(void)fprintf(stderr, "comm: %s: %s\n", name, strerror(errno));
exit(1);
}
(void)fprintf(stderr, "usage: comm [-123] file1 file2\n");
exit(1);
}
(void)fprintf(stderr, "usage: comm [-123] file1 file2\n");
exit(1);
}