Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
/* "center", (c) 1992 Marek Pawlowski. v1.0
|
|
|
|
Takes input from stdin, center's it, and puts it to
|
|
|
|
stdout.
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
v1.1 compiled for GNO Base Distribution. Devin Reade, 15 February 1999
|
|
|
|
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
Usage: center [Columns] [File]
|
|
|
|
|
|
|
|
Columns The number of columns are to be considered
|
|
|
|
"full-screen" for centering. Default 80.
|
|
|
|
File Stream to read input from. Default stdin.
|
|
|
|
|
|
|
|
This utility is in the public domain, along with
|
|
|
|
source code. Munge at will. Contact author for
|
|
|
|
redistribution rights, or inclusion in package.
|
|
|
|
Credit to Marek Pawlowski must be retained in
|
|
|
|
modified source code.
|
|
|
|
|
|
|
|
I'd like to see what you did to my source code, when
|
|
|
|
you change it. Correspond with the author (Marek
|
|
|
|
Pawlowski) at the following Email addresses:
|
|
|
|
|
|
|
|
marekp@pnet91.cts.com
|
|
|
|
marekp@cerf.net
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
$Id: center.c,v 1.2 1999/02/16 06:04:11 gdr-ftp Exp $
|
|
|
|
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-02-16 06:04:12 +00:00
|
|
|
#include <string.h>
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
#include <ctype.h>
|
1999-02-16 06:04:12 +00:00
|
|
|
#include <gno/gno.h>
|
|
|
|
|
|
|
|
#define VERSION "1.1"
|
|
|
|
|
|
|
|
static void center(FILE *stream, int t);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
char input[81];
|
|
|
|
char output[81];
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
static void usage(const char *file);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
{
|
1999-02-16 06:04:12 +00:00
|
|
|
int t, i, x, s, fflag, len, c;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
FILE *in;
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
__REPORT_STACK();
|
|
|
|
if (argc > 3) {
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
s = 1;
|
|
|
|
|
|
|
|
if(argc > 1) {
|
1999-02-16 06:04:12 +00:00
|
|
|
len = strlen(argv[1]);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
for(x = 0 ; x <= (strlen(argv[1])-1) ; x++) {
|
|
|
|
s = isdigit(argv[1][x]);
|
|
|
|
t = atoi(argv[1]);
|
1999-02-16 06:04:12 +00:00
|
|
|
if (t>80) {
|
|
|
|
t = 80;
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (argc == 1)
|
|
|
|
t = 80;
|
|
|
|
|
|
|
|
fflag = 0;
|
|
|
|
|
|
|
|
if (argc == 3) {
|
|
|
|
in = fopen(argv[2], "r");
|
1999-02-16 06:04:12 +00:00
|
|
|
if (!in) {
|
|
|
|
fprintf(stderr, "%s: cannot open %s\n", argv[1], argv[2]);
|
|
|
|
exit(1);
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
fflag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s != 0) {
|
|
|
|
if(fflag == 1)
|
|
|
|
center(in, t);
|
|
|
|
else
|
|
|
|
center(stdin, t);
|
1999-02-16 06:04:12 +00:00
|
|
|
} else {
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
usage(argv[0]);
|
1999-02-16 06:04:12 +00:00
|
|
|
}
|
|
|
|
return 0;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Function to call on other subroutines to result in a completely
|
|
|
|
centered line! */
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
static void
|
|
|
|
center(FILE *stream, int t)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
{
|
1999-02-16 06:04:12 +00:00
|
|
|
int x, i, j;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
while(feof(stream) == 0) {
|
|
|
|
fgets(input, 80, stream);
|
|
|
|
|
|
|
|
i = (t - strlen(input)) / 2;
|
|
|
|
|
1999-02-16 06:04:12 +00:00
|
|
|
for (j = 0; j<i; j++) {
|
|
|
|
output[j] = ' ';
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
for(x = 0 ; x <= strlen(input) ; x++)
|
|
|
|
output[i+x] = input[x];
|
|
|
|
if(feof(stream) == 0)
|
|
|
|
fputs(output, stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function to display the usage of the utility */
|
1999-02-16 06:04:12 +00:00
|
|
|
static void
|
|
|
|
usage(const char *file)
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [columns] [file]\n", file);
|
1999-02-16 06:04:12 +00:00
|
|
|
exit(1);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|