diff --git a/bin/center/Makefile b/bin/center/Makefile index 8fcf2b2..cb01357 100644 --- a/bin/center/Makefile +++ b/bin/center/Makefile @@ -1,5 +1,11 @@ -center.a: center.c - compile center.c keep=center +# +# $Id: Makefile,v 1.2 1999/02/16 06:04:11 gdr-ftp Exp $ +# + +PROG = center +SRCS = center.c +STACK = 768 +# observed stack: 676 bytes + +.INCLUDE : /src/gno/prog.mk -center: center.a - link center 2/direct256 keep=center diff --git a/bin/center/center.1 b/bin/center/center.1 new file mode 100644 index 0000000..8bbe5c2 --- /dev/null +++ b/bin/center/center.1 @@ -0,0 +1,29 @@ +.\" +.\" $Id: center.1,v 1.1 1999/02/16 06:04:11 gdr-ftp Exp $ +.\" +.TH CENTER 1 "15 February 1999" GNO "Commands and Applications" +.SH NAME +.BR center +\- print centered text to stdout +.SH SYNOPSIS +.BR center +.I columns +.I file +.SH DESCRIPTION +.BR center +is a simple utility for centering text on a screen. +.I columns +is the number of columns that are considered to be the width of a full screen. +The default and maximum widths are both 80 columns. +Text is read from the input file +.I file +and printed to stdout. +.SH BUGS +.B center +should be able to read from stdin. +.LP +.B center +would be more useful if it took arbitrary screen widths into account, +including over 80 columns. Less than about 5 or 10 is probably unnecessary. +.SH AUTHOR +Marek Pawlowski. diff --git a/bin/center/center.c b/bin/center/center.c index 4441a68..56fa9f1 100644 --- a/bin/center/center.c +++ b/bin/center/center.c @@ -3,6 +3,8 @@ Takes input from stdin, center's it, and puts it to stdout. + v1.1 compiled for GNO Base Distribution. Devin Reade, 15 February 1999 + Usage: center [Columns] [File] Columns The number of columns are to be considered @@ -22,34 +24,45 @@ marekp@pnet91.cts.com marekp@cerf.net + $Id: center.c,v 1.2 1999/02/16 06:04:11 gdr-ftp Exp $ + */ -#pragma stacksize 1024 #include +#include #include -#define VERSION "1.00" +#include + +#define VERSION "1.1" + +static void center(FILE *stream, int t); char input[81]; char output[81]; -main(argc, argv) -int argc; -char **argv; +static void usage(const char *file); + +int +main(int argc, char **argv) { - int t, i, x, s, fflag; + int t, i, x, s, fflag, len, c; FILE *in; -/* _INITGNOSTDIO(); - setvbuf(stdin,NULL,_IOLBF,256l); */ - if (argc > 3) - usage(argv[0]); + __REPORT_STACK(); + if (argc > 3) { + usage(argv[0]); + } s = 1; if(argc > 1) { + len = strlen(argv[1]); for(x = 0 ; x <= (strlen(argv[1])-1) ; x++) { s = isdigit(argv[1][x]); t = atoi(argv[1]); + if (t>80) { + t = 80; + } } } @@ -60,7 +73,10 @@ char **argv; if (argc == 3) { in = fopen(argv[2], "r"); - if(!in) error(argv[1], argv[2]); + if (!in) { + fprintf(stderr, "%s: cannot open %s\n", argv[1], argv[2]); + exit(1); + } fflag = 1; } @@ -69,27 +85,28 @@ char **argv; center(in, t); else center(stdin, t); - } - - else + } else { usage(argv[0]); + } + return 0; } /* Function to call on other subroutines to result in a completely centered line! */ -center(stream, t) -FILE *stream; -int t; +static void +center(FILE *stream, int t) { - int x, i; + int x, i, j; while(feof(stream) == 0) { fgets(input, 80, stream); i = (t - strlen(input)) / 2; - fillit(i, 0); + for (j = 0; j