mirror of
https://github.com/GnoConsortium/gno.git
synced 2025-02-06 10:30:50 +00:00
Makefile:
- modified for GNO base build center.c: - prototyped functions, general code cleanup center.1, center.desc, center.rez: - initial checkin
This commit is contained in:
parent
4d7cc8e5b6
commit
3f5e869b65
@ -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
|
||||
|
29
bin/center/center.1
Normal file
29
bin/center/center.1
Normal file
@ -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.
|
@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#define VERSION "1.00"
|
||||
#include <gno/gno.h>
|
||||
|
||||
#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<i; j++) {
|
||||
output[j] = ' ';
|
||||
}
|
||||
|
||||
for(x = 0 ; x <= strlen(input) ; x++)
|
||||
output[i+x] = input[x];
|
||||
@ -98,36 +115,10 @@ int t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Function to tell the person that the filename offered
|
||||
not be opened for reading */
|
||||
|
||||
error(name, file)
|
||||
char *name;
|
||||
char *file;
|
||||
{
|
||||
fprintf(stderr, "%s: cannot open %s\n", name, file);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Function to display the usage of the utility */
|
||||
|
||||
usage(file)
|
||||
char *file;
|
||||
static void
|
||||
usage(const char *file)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [columns] [file]\n", file);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Function to fill in the left side of text with the appropriate
|
||||
number of spaces */
|
||||
|
||||
fillit(ntf, start)
|
||||
int ntf; /* Number To Fill */
|
||||
int start; /* Start filling at.. */
|
||||
{
|
||||
int x;
|
||||
|
||||
for(x = start ; x <= ntf ; x++) {
|
||||
output[x] = ' ';
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
9
bin/center/center.desc
Normal file
9
bin/center/center.desc
Normal file
@ -0,0 +1,9 @@
|
||||
Name: center
|
||||
Version: 1.1
|
||||
Shell: GNO
|
||||
Author: Marek Pawlowski. Maintained by Devin Reade.
|
||||
Contact: gdr@trenco.gno.org
|
||||
Where: /bin
|
||||
FTP: ftp.gno.org
|
||||
|
||||
Take text from a file (or stdin), center it, and print it to stdout.
|
18
bin/center/center.rez
Normal file
18
bin/center/center.rez
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* $Id: center.rez,v 1.1 1999/02/16 06:04:12 gdr-ftp Exp $
|
||||
*/
|
||||
|
||||
#include "Types.Rez"
|
||||
#include "builddate.rez"
|
||||
|
||||
resource rVersion (0x1, purgeable3, nocrossbank) {
|
||||
|
||||
{ 1, 1, 0, /* version */
|
||||
release, /* development|alpha|beta|final|release */
|
||||
0 /* non-final release number */
|
||||
},
|
||||
verUS,
|
||||
"center",
|
||||
"Center text to stdout.\n"
|
||||
BUILD_DATE
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user