mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-11 18:49:16 +00:00
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.
This commit is contained in:
parent
d00f2dadaa
commit
784e3de7cd
13
bin/aroff/Makefile
Normal file
13
bin/aroff/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
#
|
||||
# Makefile for aroff
|
||||
# AWGS WordProc -> Text formatter
|
||||
#
|
||||
|
||||
awgs.root: awgs.c awgs.h
|
||||
compile awgs.c keep=awgs
|
||||
|
||||
print.root: print.c awgs.h
|
||||
compile print.c keep=print
|
||||
|
||||
awgs: awgs.root
|
||||
link awgs print 2/direct256 keep=aroff
|
160
bin/aroff/aroff.c
Normal file
160
bin/aroff/aroff.c
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
|
||||
awgs.c
|
||||
|
||||
Main loop driver code and awgs wordproc file read routines
|
||||
|
||||
*/
|
||||
|
||||
#pragma stacksize 2048
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <gsos.h>
|
||||
#include <shell.h>
|
||||
|
||||
#include "awgs.h"
|
||||
|
||||
void fileError(char *s)
|
||||
{
|
||||
int err;
|
||||
int cl[2];
|
||||
|
||||
if (err = toolerror()) {
|
||||
fprintf(stderr,"%s\n",s);
|
||||
ERROR(&err);
|
||||
cl[0] = 1; cl[1] = 0; CloseGS(cl);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int noboldflag = 0;
|
||||
saveArray *docSaveArray;
|
||||
Ruler *docRulers;
|
||||
textBlock **docTextBlocks; /* an array of textBlockPtrs */
|
||||
word docSACount, numRulers, numBlocks;
|
||||
|
||||
void readAWGS(char *file)
|
||||
{
|
||||
int ref,err,z; /* refnum, err temp, and loop variable */
|
||||
long recBlockSize; /* size of the upcoming text block */
|
||||
int cl[2]; /* pBlock for GS/OS CloseGS call */
|
||||
GSString255 f; /* converted cstring(file) -> GSString */
|
||||
OpenRecGS o; /* pBlock for GS/OS Open call */
|
||||
SetPositionRecGS p;
|
||||
IORecGS i;
|
||||
|
||||
f.length = strlen(file);
|
||||
strcpy(f.text,file);
|
||||
o.pCount = 7;
|
||||
o.pathname = &f;
|
||||
o.requestAccess = readEnable;
|
||||
o.resourceNumber = 0;
|
||||
OpenGS(&o);
|
||||
if (err = toolerror()) {
|
||||
fprintf(stderr,"aroff: could not open AWGS file %s\n",file);
|
||||
ERROR(&err);
|
||||
exit(1);
|
||||
}
|
||||
ref = o.refNum;
|
||||
if ((o.fileType != 0x50) || (o.auxType != 0x8010l)) {
|
||||
cl[0] = 1; cl[1] = ref; CloseGS(cl);
|
||||
fprintf(stderr,"aroff: file (%s) is not an AWGS file\n",file);
|
||||
exit(1);
|
||||
}
|
||||
p.pCount = 3; p.refNum = ref; p.base = startPlus; p.displacement = 668l;
|
||||
SetMarkGS(&p); fileError("SetMarkGS");
|
||||
|
||||
i.pCount = 4;
|
||||
i.refNum = ref;
|
||||
i.dataBuffer = (void *) &docSACount;
|
||||
i.requestCount = 2l;
|
||||
ReadGS(&i); fileError("ReadGS (docSACount)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Number of SaveArray entries: %d\n",docSACount);
|
||||
#endif
|
||||
|
||||
docSaveArray = calloc((size_t) docSACount, sizeof(saveArray));
|
||||
i.dataBuffer = (void *) docSaveArray;
|
||||
i.requestCount = sizeof(saveArray) * docSACount;
|
||||
ReadGS(&i); fileError("ReadGS (docSaveArray)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr," saNum textBlock rulerNum\n");
|
||||
fprintf(stderr," ----- --------- --------\n");
|
||||
for (z = 0; z < docSACount; z++) {
|
||||
fprintf(stderr," [%3d] %5d %5d\n",
|
||||
z+1, docSaveArray[z].textBlock,docSaveArray[z].rulerNum);
|
||||
}
|
||||
#endif
|
||||
|
||||
numRulers = numBlocks = 0;
|
||||
for (z = 0; z < docSACount; z++) {
|
||||
if (docSaveArray[z].rulerNum+1 > numRulers)
|
||||
numRulers = docSaveArray[z].rulerNum+1;
|
||||
if (docSaveArray[z].textBlock+1 > numBlocks)
|
||||
numBlocks = docSaveArray[z].textBlock+1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Number of Rulers: %d\n",numRulers);
|
||||
fprintf(stderr,"Number of Blocks: %d\n",numBlocks);
|
||||
#endif
|
||||
|
||||
docRulers = calloc((size_t) numRulers, sizeof(Ruler));
|
||||
i.dataBuffer = (void *) docRulers;
|
||||
i.requestCount = sizeof(Ruler) * numRulers;
|
||||
ReadGS(&i); fileError("ReadGS (docRulers)");
|
||||
|
||||
docTextBlocks = calloc((size_t) numBlocks, sizeof(textBlockPtr));
|
||||
for (z = 0; z < numBlocks; z++) {
|
||||
i.requestCount = 4l;
|
||||
i.dataBuffer = (void *) &recBlockSize;
|
||||
ReadGS(&i); fileError("ReadGS (recBlockSize)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"block %d size %8ld : ",z,recBlockSize);
|
||||
#endif
|
||||
docTextBlocks[z] = malloc(recBlockSize);
|
||||
i.requestCount = recBlockSize;
|
||||
i.dataBuffer = (void *) docTextBlocks[z];
|
||||
ReadGS(&i); fileError("ReadGS (textBlock)");
|
||||
}
|
||||
|
||||
cl[0] = 1;
|
||||
cl[1] = ref;
|
||||
CloseGS(cl);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr,"aroff [-b] file1 [file ...]\n"
|
||||
"-b don't do any boldfacing (useful for GNO Ref. Manuals)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,z;
|
||||
extern void printAWGS(void);
|
||||
extern int _INITGNOSTDIO();
|
||||
|
||||
_INITGNOSTDIO();
|
||||
|
||||
if (argc == 1) usage();
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (*argv[i] == '-') {
|
||||
if (argv[i][1] == 'b')
|
||||
{ noboldflag = 1; continue; }
|
||||
else usage();
|
||||
}
|
||||
readAWGS(argv[i]);
|
||||
printAWGS();
|
||||
free(docSaveArray);
|
||||
free(docRulers);
|
||||
for (z = 0; z < numBlocks; z++)
|
||||
free(docTextBlocks[z]);
|
||||
free(docTextBlocks);
|
||||
}
|
||||
}
|
57
bin/aroff/aroff.h
Normal file
57
bin/aroff/aroff.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
This file contains the data structures that are
|
||||
used in AWGS Word Processor files.
|
||||
|
||||
Data structures gleaned from DTS File Type Note TN.50.8010
|
||||
*/
|
||||
|
||||
/* #define DEBUG */
|
||||
|
||||
typedef struct pgraph {
|
||||
word firstFont;
|
||||
byte firstStyle;
|
||||
byte firstSize;
|
||||
byte firstColor;
|
||||
word reserved;
|
||||
} pgraph, *pgraphPtr;
|
||||
|
||||
typedef struct textBlock {
|
||||
word blockSize;
|
||||
word blockUsed;
|
||||
pgraphPtr pgraphs;
|
||||
} textBlock, *textBlockPtr;
|
||||
|
||||
typedef struct tabRec {
|
||||
word tabLocation;
|
||||
word tabType;
|
||||
} tabRec, *tabRecPtr;
|
||||
|
||||
#define rsFULL 0x80
|
||||
#define rsRIGHT 0x40
|
||||
#define rsCENTER 0x20
|
||||
#define rsLEFT 0x10
|
||||
#define rsNOBREAK 0x08
|
||||
#define rsTRIPLE 0x04
|
||||
#define rsDOUBLE 0x02
|
||||
#define rsSINGLE 0x01
|
||||
|
||||
typedef struct Ruler {
|
||||
word numParagraphs;
|
||||
word statusBits;
|
||||
word leftMargin;
|
||||
word indentMargin;
|
||||
word rightMargin;
|
||||
word numTabs;
|
||||
tabRec tabRecs[10];
|
||||
} Ruler, *RulerPtr;
|
||||
|
||||
typedef struct SaveArrEntry {
|
||||
word textBlock; /* Text block number */
|
||||
word offset; /* offset + text block = paragraph */
|
||||
word attributes; /* 0 = normal text, 1 = page break paragrf */
|
||||
word rulerNum; /* #of ruler associated with this paragrf */
|
||||
word pixelHeight; /* height of paragraph in pixels */
|
||||
word numLines; /* # of lines in this paragraph */
|
||||
} saveArray, *saveArrayPtr;
|
||||
|
||||
extern int noboldflag;
|
160
bin/aroff/awgs.c
Normal file
160
bin/aroff/awgs.c
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
|
||||
awgs.c
|
||||
|
||||
Main loop driver code and awgs wordproc file read routines
|
||||
|
||||
*/
|
||||
|
||||
#pragma stacksize 2048
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <gsos.h>
|
||||
#include <shell.h>
|
||||
|
||||
#include "awgs.h"
|
||||
|
||||
void fileError(char *s)
|
||||
{
|
||||
int err;
|
||||
int cl[2];
|
||||
|
||||
if (err = toolerror()) {
|
||||
fprintf(stderr,"%s\n",s);
|
||||
ERROR(&err);
|
||||
cl[0] = 1; cl[1] = 0; CloseGS(cl);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int noboldflag = 0;
|
||||
saveArray *docSaveArray;
|
||||
Ruler *docRulers;
|
||||
textBlock **docTextBlocks; /* an array of textBlockPtrs */
|
||||
word docSACount, numRulers, numBlocks;
|
||||
|
||||
void readAWGS(char *file)
|
||||
{
|
||||
int ref,err,z; /* refnum, err temp, and loop variable */
|
||||
long recBlockSize; /* size of the upcoming text block */
|
||||
int cl[2]; /* pBlock for GS/OS CloseGS call */
|
||||
GSString255 f; /* converted cstring(file) -> GSString */
|
||||
OpenRecGS o; /* pBlock for GS/OS Open call */
|
||||
SetPositionRecGS p;
|
||||
IORecGS i;
|
||||
|
||||
f.length = strlen(file);
|
||||
strcpy(f.text,file);
|
||||
o.pCount = 7;
|
||||
o.pathname = &f;
|
||||
o.requestAccess = readEnable;
|
||||
o.resourceNumber = 0;
|
||||
OpenGS(&o);
|
||||
if (err = toolerror()) {
|
||||
fprintf(stderr,"aroff: could not open AWGS file %s\n",file);
|
||||
ERROR(&err);
|
||||
exit(1);
|
||||
}
|
||||
ref = o.refNum;
|
||||
if ((o.fileType != 0x50) || (o.auxType != 0x8010l)) {
|
||||
cl[0] = 1; cl[1] = ref; CloseGS(cl);
|
||||
fprintf(stderr,"aroff: file (%s) is not an AWGS file\n",file);
|
||||
exit(1);
|
||||
}
|
||||
p.pCount = 3; p.refNum = ref; p.base = startPlus; p.displacement = 668l;
|
||||
SetMarkGS(&p); fileError("SetMarkGS");
|
||||
|
||||
i.pCount = 4;
|
||||
i.refNum = ref;
|
||||
i.dataBuffer = (void *) &docSACount;
|
||||
i.requestCount = 2l;
|
||||
ReadGS(&i); fileError("ReadGS (docSACount)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Number of SaveArray entries: %d\n",docSACount);
|
||||
#endif
|
||||
|
||||
docSaveArray = calloc((size_t) docSACount, sizeof(saveArray));
|
||||
i.dataBuffer = (void *) docSaveArray;
|
||||
i.requestCount = sizeof(saveArray) * docSACount;
|
||||
ReadGS(&i); fileError("ReadGS (docSaveArray)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr," saNum textBlock rulerNum\n");
|
||||
fprintf(stderr," ----- --------- --------\n");
|
||||
for (z = 0; z < docSACount; z++) {
|
||||
fprintf(stderr," [%3d] %5d %5d\n",
|
||||
z+1, docSaveArray[z].textBlock,docSaveArray[z].rulerNum);
|
||||
}
|
||||
#endif
|
||||
|
||||
numRulers = numBlocks = 0;
|
||||
for (z = 0; z < docSACount; z++) {
|
||||
if (docSaveArray[z].rulerNum+1 > numRulers)
|
||||
numRulers = docSaveArray[z].rulerNum+1;
|
||||
if (docSaveArray[z].textBlock+1 > numBlocks)
|
||||
numBlocks = docSaveArray[z].textBlock+1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Number of Rulers: %d\n",numRulers);
|
||||
fprintf(stderr,"Number of Blocks: %d\n",numBlocks);
|
||||
#endif
|
||||
|
||||
docRulers = calloc((size_t) numRulers, sizeof(Ruler));
|
||||
i.dataBuffer = (void *) docRulers;
|
||||
i.requestCount = sizeof(Ruler) * numRulers;
|
||||
ReadGS(&i); fileError("ReadGS (docRulers)");
|
||||
|
||||
docTextBlocks = calloc((size_t) numBlocks, sizeof(textBlockPtr));
|
||||
for (z = 0; z < numBlocks; z++) {
|
||||
i.requestCount = 4l;
|
||||
i.dataBuffer = (void *) &recBlockSize;
|
||||
ReadGS(&i); fileError("ReadGS (recBlockSize)");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"block %d size %8ld : ",z,recBlockSize);
|
||||
#endif
|
||||
docTextBlocks[z] = malloc(recBlockSize);
|
||||
i.requestCount = recBlockSize;
|
||||
i.dataBuffer = (void *) docTextBlocks[z];
|
||||
ReadGS(&i); fileError("ReadGS (textBlock)");
|
||||
}
|
||||
|
||||
cl[0] = 1;
|
||||
cl[1] = ref;
|
||||
CloseGS(cl);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr,"aroff [-b] file1 [file ...]\n"
|
||||
"-b don't do any boldfacing (useful for GNO Ref. Manuals)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,z;
|
||||
extern void printAWGS(void);
|
||||
extern int _INITGNOSTDIO();
|
||||
|
||||
_INITGNOSTDIO();
|
||||
|
||||
if (argc == 1) usage();
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (*argv[i] == '-') {
|
||||
if (argv[i][1] == 'b')
|
||||
{ noboldflag = 1; continue; }
|
||||
else usage();
|
||||
}
|
||||
readAWGS(argv[i]);
|
||||
printAWGS();
|
||||
free(docSaveArray);
|
||||
free(docRulers);
|
||||
for (z = 0; z < numBlocks; z++)
|
||||
free(docTextBlocks[z]);
|
||||
free(docTextBlocks);
|
||||
}
|
||||
}
|
57
bin/aroff/awgs.h
Normal file
57
bin/aroff/awgs.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
This file contains the data structures that are
|
||||
used in AWGS Word Processor files.
|
||||
|
||||
Data structures gleaned from DTS File Type Note TN.50.8010
|
||||
*/
|
||||
|
||||
/* #define DEBUG */
|
||||
|
||||
typedef struct pgraph {
|
||||
word firstFont;
|
||||
byte firstStyle;
|
||||
byte firstSize;
|
||||
byte firstColor;
|
||||
word reserved;
|
||||
} pgraph, *pgraphPtr;
|
||||
|
||||
typedef struct textBlock {
|
||||
word blockSize;
|
||||
word blockUsed;
|
||||
pgraphPtr pgraphs;
|
||||
} textBlock, *textBlockPtr;
|
||||
|
||||
typedef struct tabRec {
|
||||
word tabLocation;
|
||||
word tabType;
|
||||
} tabRec, *tabRecPtr;
|
||||
|
||||
#define rsFULL 0x80
|
||||
#define rsRIGHT 0x40
|
||||
#define rsCENTER 0x20
|
||||
#define rsLEFT 0x10
|
||||
#define rsNOBREAK 0x08
|
||||
#define rsTRIPLE 0x04
|
||||
#define rsDOUBLE 0x02
|
||||
#define rsSINGLE 0x01
|
||||
|
||||
typedef struct Ruler {
|
||||
word numParagraphs;
|
||||
word statusBits;
|
||||
word leftMargin;
|
||||
word indentMargin;
|
||||
word rightMargin;
|
||||
word numTabs;
|
||||
tabRec tabRecs[10];
|
||||
} Ruler, *RulerPtr;
|
||||
|
||||
typedef struct SaveArrEntry {
|
||||
word textBlock; /* Text block number */
|
||||
word offset; /* offset + text block = paragraph */
|
||||
word attributes; /* 0 = normal text, 1 = page break paragrf */
|
||||
word rulerNum; /* #of ruler associated with this paragrf */
|
||||
word pixelHeight; /* height of paragraph in pixels */
|
||||
word numLines; /* # of lines in this paragraph */
|
||||
} saveArray, *saveArrayPtr;
|
||||
|
||||
extern int noboldflag;
|
157
bin/aroff/print.c
Normal file
157
bin/aroff/print.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
print.c
|
||||
|
||||
the code that formats each individual paragraph is here.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <types.h>
|
||||
#include <texttool.h>
|
||||
|
||||
#include "awgs.h"
|
||||
|
||||
extern saveArray *docSaveArray;
|
||||
extern Ruler *docRulers;
|
||||
extern textBlock **docTextBlocks; /* an array of textBlockPtrs */
|
||||
extern word docSACount, numRulers, numBlocks;
|
||||
|
||||
/*
|
||||
1 2
|
||||
01234567890123456 7890
|
||||
This is a bloody ^car
|
||||
z = 16;
|
||||
|
||||
This is a bloody
|
||||
^car
|
||||
|
||||
col=4 (width - z - 1)
|
||||
printcol=3
|
||||
*/
|
||||
|
||||
/* 100 lines should be more than enough */
|
||||
char paraBuf[100][80];
|
||||
|
||||
|
||||
/* given a paragraph, and a pointer to it's ruler, format the
|
||||
paragraph according to the ruler. */
|
||||
void printPara(RulerPtr ruler, pgraphPtr pptr)
|
||||
{
|
||||
char *txt;
|
||||
int width,z;
|
||||
int curLine, col, printcol, numctrl;
|
||||
int i,left,style;
|
||||
|
||||
curLine = col = printcol = 0;
|
||||
txt = ((char *)pptr) + sizeof(pgraph);
|
||||
|
||||
calcLine:
|
||||
/* width determines how long this line is in characters; thus, where
|
||||
the break for word wrap will occur */
|
||||
if (curLine == 0) width = (ruler->rightMargin - ruler->indentMargin)/8;
|
||||
else width = (ruler->rightMargin - ruler->leftMargin)/8;
|
||||
|
||||
while (*txt != 0x0d) {
|
||||
switch (*txt) {
|
||||
case 1: txt+=3; break;
|
||||
case 2:
|
||||
style = *(++txt);
|
||||
if (noboldflag) { ++txt; break; }/* turn off boldfacing */
|
||||
if (style & 3) paraBuf[curLine][col++] = 15;
|
||||
else paraBuf[curLine][col++] = 14;
|
||||
txt++;
|
||||
break;
|
||||
case 3: txt+=2; break;
|
||||
case 4: txt+=2; break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7: break;
|
||||
|
||||
default:
|
||||
if (printcol == width) {
|
||||
numctrl = 0;
|
||||
for (z = col - 1; z > 0; z--) {
|
||||
if (paraBuf[curLine][z] == ' ') {
|
||||
if (z != col - 1)
|
||||
memcpy(¶Buf[curLine+1][0],¶Buf[curLine][z+1],
|
||||
(size_t) (col - z - 1));
|
||||
paraBuf[curLine][z] = 0;
|
||||
curLine++; printcol -= (z + 1 + numctrl);
|
||||
col -= (z + 1);
|
||||
goto calcLine;
|
||||
}
|
||||
else if (paraBuf[curLine][z] < ' ') numctrl++;
|
||||
}
|
||||
curLine++; col = printcol = 0;
|
||||
/* one big word... don't break line */
|
||||
goto calcLine;
|
||||
}
|
||||
paraBuf[curLine][col] = *(txt++);
|
||||
printcol++; col++;
|
||||
}
|
||||
}
|
||||
paraBuf[curLine][col] = 0;
|
||||
for (z = 0; z <= curLine; z++) {
|
||||
if (z == 0) {
|
||||
width = (ruler->rightMargin - ruler->indentMargin)/8;
|
||||
left = (ruler->indentMargin)/8;
|
||||
}
|
||||
else {
|
||||
width = (ruler->rightMargin - ruler->leftMargin)/8;
|
||||
left = (ruler->leftMargin)/8;
|
||||
}
|
||||
for (i = 0; i < left; i++) putchar(' ');
|
||||
printf("%s\n",paraBuf[z]);
|
||||
}
|
||||
}
|
||||
|
||||
/* this is an obsolete routine that prints a paragraph with no
|
||||
formatting at all */
|
||||
#ifdef NOTDEFINED
|
||||
void printPara(RulerPtr ruler, pgraphPtr pptr)
|
||||
{
|
||||
char *txt;
|
||||
|
||||
txt = ((char *)pptr) + sizeof(pgraph);
|
||||
while (*txt != 0x0D) {
|
||||
switch (*txt) {
|
||||
case 1: txt+=2; break;
|
||||
case 2: txt++; break;
|
||||
case 3: txt++; break;
|
||||
case 4: txt++; break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7: break;
|
||||
|
||||
default: putchar(*txt);
|
||||
}
|
||||
txt++;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* go through each textBlock, sending each paragraph in turn to printPara. */
|
||||
|
||||
void printAWGS(void)
|
||||
{
|
||||
int z;
|
||||
pgraphPtr pptr;
|
||||
char *txt;
|
||||
char x;
|
||||
|
||||
for (z = 0; z < docSACount; z++) {
|
||||
pptr = (pgraphPtr) (((byte *)docTextBlocks[docSaveArray[z].textBlock])
|
||||
+ docSaveArray[z].offset);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"[%d] offset %d paragraph : %08lX",z,docSaveArray[z].offset,
|
||||
pptr);
|
||||
fprintf(stderr," textBlock: %08lX\n",docTextBlocks[docSaveArray[z].textBlock]);
|
||||
#endif
|
||||
printPara(&docRulers[docSaveArray[z].rulerNum],pptr);
|
||||
}
|
||||
}
|
8
bin/binprint/Makefile
Normal file
8
bin/binprint/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
binprint.a: binprint.c
|
||||
compile -p binprint.c keep=binprint
|
||||
|
||||
bprasm.a: binprint.asm
|
||||
compile -p binprint.asm
|
||||
|
||||
binprint: binprint.a bprasm.a
|
||||
link -p binprint bprasm keep=binprint
|
123
bin/binprint/binprint.asm
Normal file
123
bin/binprint/binprint.asm
Normal file
@ -0,0 +1,123 @@
|
||||
case on
|
||||
|
||||
keep bprasm
|
||||
|
||||
doline start
|
||||
pha
|
||||
tsc
|
||||
phd
|
||||
tcd
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
|
||||
counter equ 1
|
||||
RTLs equ 3
|
||||
dest equ 6
|
||||
source equ 10
|
||||
cols equ 14
|
||||
actual equ 16
|
||||
PREVIOUS equ 18
|
||||
|
||||
pei actual
|
||||
stz counter
|
||||
ldy #0
|
||||
loop anop
|
||||
lda [source],y
|
||||
jsr puthex
|
||||
iny
|
||||
dec cols
|
||||
dec actual
|
||||
bne loop
|
||||
ldy counter
|
||||
loop2 lda cols
|
||||
beq done
|
||||
lda #$2020
|
||||
sta [dest],y
|
||||
iny
|
||||
sta [dest],y
|
||||
iny
|
||||
iny
|
||||
dec cols
|
||||
bra loop2
|
||||
|
||||
done anop
|
||||
pla
|
||||
sta actual
|
||||
tya
|
||||
clc
|
||||
inc a
|
||||
adc actual
|
||||
sta counter
|
||||
ldy actual
|
||||
chrloop dey
|
||||
cpy #$ffff
|
||||
beq endloop
|
||||
lda [source],y
|
||||
and #$ff
|
||||
cmp #$7f
|
||||
bcs noprint
|
||||
cmp #$20
|
||||
bcs printable
|
||||
noprint lda #'.'
|
||||
printable sep #$20
|
||||
sta [source],y
|
||||
rep #$20
|
||||
bra chrloop
|
||||
endloop ldy actual
|
||||
dey
|
||||
lda [source],y
|
||||
and #$00ff
|
||||
ora #$0d00
|
||||
sta [source],y
|
||||
|
||||
ldy counter
|
||||
plb
|
||||
lda 4
|
||||
sta PREVIOUS-2
|
||||
lda 3
|
||||
sta PREVIOUS-3
|
||||
pld
|
||||
tsc
|
||||
clc
|
||||
adc #PREVIOUS-4
|
||||
tcs
|
||||
tya
|
||||
rtl
|
||||
end
|
||||
|
||||
puthex private
|
||||
counter equ 1
|
||||
RTLs equ 3
|
||||
dest equ 6
|
||||
source equ 10
|
||||
cols equ 14
|
||||
phy
|
||||
ldy counter
|
||||
pha
|
||||
lsr a
|
||||
lsr a
|
||||
lsr a
|
||||
lsr a
|
||||
and #$f
|
||||
tax
|
||||
lda hexdigits,x
|
||||
sta [<dest],y
|
||||
iny
|
||||
pla
|
||||
and #$f
|
||||
tax
|
||||
lda hexdigits,x
|
||||
and #$00ff
|
||||
ora #$2000
|
||||
sta [<dest],y
|
||||
iny
|
||||
iny
|
||||
sty counter
|
||||
ply
|
||||
rts
|
||||
end
|
||||
|
||||
hexdigits privdata
|
||||
dc c'0123456789ABCDEF'
|
||||
end
|
107
bin/binprint/binprint.c
Normal file
107
bin/binprint/binprint.c
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
BINPRINT.C
|
||||
|
||||
Displays files in hex-dump format (with ascii subdisplay if desired)
|
||||
|
||||
v1.2 Optimized and fixed input from terminal bug (pv)
|
||||
v1.1 Added stacksize directive (jb)
|
||||
v1.0 Original version by Derek Taubert
|
||||
|
||||
*/
|
||||
|
||||
#pragma optimize -1
|
||||
#pragma stacksize 1024
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern FILE *fdopen(int,char *);
|
||||
|
||||
unsigned int doline(char *dest, char *source,
|
||||
unsigned int actual, unsigned int cols);
|
||||
|
||||
unsigned char *buffer2;
|
||||
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int duh;
|
||||
int a;
|
||||
int c,errflg = 0,columns = 16;
|
||||
size_t pos = 0;
|
||||
unsigned char *buffer;
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern int getopt(int,char **,char*);
|
||||
|
||||
while ((c = getopt(argc,argv, "Vc:")) != EOF)
|
||||
switch (c) {
|
||||
case 'c' :
|
||||
columns = atoi(optarg);
|
||||
break;
|
||||
case 'V' :
|
||||
fprintf(stdout, "binprint v1.2 for GNO/ME\n");
|
||||
exit(0);
|
||||
default : errflg++;
|
||||
}
|
||||
if (errflg) {
|
||||
fprintf(stderr,"usage: binprint [-c<columns>] files...\n");
|
||||
exit(2);
|
||||
}
|
||||
argv += optind;
|
||||
if (columns < 8) columns = 8;
|
||||
if ((buffer2 = (unsigned char *)malloc((size_t)(columns*4)+1)) == NULL) {
|
||||
fprintf(stderr,"Cannot allocate buffer space\n");
|
||||
exit(1);
|
||||
}
|
||||
buffer = (unsigned char *)(buffer2+(columns*3));
|
||||
if (optind == argc) {
|
||||
duh = STDIN_FILENO;
|
||||
goto action;
|
||||
}
|
||||
for (;optind<argc;optind++) {
|
||||
if ((duh = open(*argv,O_RDONLY|O_BINARY)) == -1) {
|
||||
fprintf(stderr,"error opening %s\n",*argv);
|
||||
exit(1);
|
||||
}
|
||||
printf("\n%s\n",*argv);
|
||||
action: while ((a = (int)read(duh, buffer,
|
||||
(size_t)(columns * sizeof(unsigned char)))) != 0) {
|
||||
printGood(pos,buffer,a,columns);
|
||||
pos += a;
|
||||
}
|
||||
close(duh);
|
||||
}
|
||||
free(buffer);
|
||||
free(buffer2);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printGood(off,buf,real,form)
|
||||
long off;
|
||||
unsigned char *buf;
|
||||
int real;
|
||||
int form;
|
||||
{
|
||||
if (!real) return;
|
||||
/*
|
||||
printf("%8lX: ",off);
|
||||
*/
|
||||
|
||||
/* The following is a hack required because of buffering by the stdio
|
||||
libraries. I wish it was not necesary... */
|
||||
|
||||
{
|
||||
static char puthere[11];
|
||||
int howmany;
|
||||
|
||||
howmany = sprintf(puthere,"%8lX: ",off);
|
||||
write(STDOUT_FILENO, puthere, (size_t)howmany);
|
||||
}
|
||||
|
||||
write(STDOUT_FILENO, buffer2, (size_t)doline(buffer2,buf,form,real));
|
||||
}
|
123
bin/binprint/doline.asm
Normal file
123
bin/binprint/doline.asm
Normal file
@ -0,0 +1,123 @@
|
||||
case on
|
||||
|
||||
keep bprasm
|
||||
|
||||
doline start
|
||||
pha
|
||||
tsc
|
||||
phd
|
||||
tcd
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
|
||||
counter equ 1
|
||||
RTLs equ 3
|
||||
dest equ 6
|
||||
source equ 10
|
||||
cols equ 14
|
||||
actual equ 16
|
||||
PREVIOUS equ 18
|
||||
|
||||
pei actual
|
||||
stz counter
|
||||
ldy #0
|
||||
loop anop
|
||||
lda [source],y
|
||||
jsr puthex
|
||||
iny
|
||||
dec cols
|
||||
dec actual
|
||||
bne loop
|
||||
ldy counter
|
||||
loop2 lda cols
|
||||
beq done
|
||||
lda #$2020
|
||||
sta [dest],y
|
||||
iny
|
||||
sta [dest],y
|
||||
iny
|
||||
iny
|
||||
dec cols
|
||||
bra loop2
|
||||
|
||||
done anop
|
||||
pla
|
||||
sta actual
|
||||
tya
|
||||
clc
|
||||
inc a
|
||||
adc actual
|
||||
sta counter
|
||||
ldy actual
|
||||
chrloop dey
|
||||
cpy #$ffff
|
||||
beq endloop
|
||||
lda [source],y
|
||||
and #$ff
|
||||
cmp #$7f
|
||||
bcs noprint
|
||||
cmp #$20
|
||||
bcs printable
|
||||
noprint lda #'.'
|
||||
printable sep #$20
|
||||
sta [source],y
|
||||
rep #$20
|
||||
bra chrloop
|
||||
endloop ldy actual
|
||||
dey
|
||||
lda [source],y
|
||||
and #$00ff
|
||||
ora #$0d00
|
||||
sta [source],y
|
||||
|
||||
ldy counter
|
||||
plb
|
||||
lda 4
|
||||
sta PREVIOUS-2
|
||||
lda 3
|
||||
sta PREVIOUS-3
|
||||
pld
|
||||
tsc
|
||||
clc
|
||||
adc #PREVIOUS-4
|
||||
tcs
|
||||
tya
|
||||
rtl
|
||||
end
|
||||
|
||||
puthex private
|
||||
counter equ 1
|
||||
RTLs equ 3
|
||||
dest equ 6
|
||||
source equ 10
|
||||
cols equ 14
|
||||
phy
|
||||
ldy counter
|
||||
pha
|
||||
lsr a
|
||||
lsr a
|
||||
lsr a
|
||||
lsr a
|
||||
and #$f
|
||||
tax
|
||||
lda hexdigits,x
|
||||
sta [<dest],y
|
||||
iny
|
||||
pla
|
||||
and #$f
|
||||
tax
|
||||
lda hexdigits,x
|
||||
and #$00ff
|
||||
ora #$2000
|
||||
sta [<dest],y
|
||||
iny
|
||||
iny
|
||||
sty counter
|
||||
ply
|
||||
rts
|
||||
end
|
||||
|
||||
hexdigits privdata
|
||||
dc c'0123456789ABCDEF'
|
||||
end
|
5
bin/center/Makefile
Normal file
5
bin/center/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
center.a: center.c
|
||||
compile center.c keep=center
|
||||
|
||||
center: center.a
|
||||
link center 2/direct256 keep=center
|
133
bin/center/center.c
Normal file
133
bin/center/center.c
Normal file
@ -0,0 +1,133 @@
|
||||
|
||||
/* "center", (c) 1992 Marek Pawlowski. v1.0
|
||||
Takes input from stdin, center's it, and puts it to
|
||||
stdout.
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
#pragma stacksize 1024
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#define VERSION "1.00"
|
||||
|
||||
char input[81];
|
||||
char output[81];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int t, i, x, s, fflag;
|
||||
FILE *in;
|
||||
|
||||
/* _INITGNOSTDIO();
|
||||
setvbuf(stdin,NULL,_IOLBF,256l); */
|
||||
if (argc > 3)
|
||||
usage(argv[0]);
|
||||
|
||||
s = 1;
|
||||
|
||||
if(argc > 1) {
|
||||
for(x = 0 ; x <= (strlen(argv[1])-1) ; x++) {
|
||||
s = isdigit(argv[1][x]);
|
||||
t = atoi(argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
else if (argc == 1)
|
||||
t = 80;
|
||||
|
||||
fflag = 0;
|
||||
|
||||
if (argc == 3) {
|
||||
in = fopen(argv[2], "r");
|
||||
if(!in) error(argv[1], argv[2]);
|
||||
fflag = 1;
|
||||
}
|
||||
|
||||
if(s != 0) {
|
||||
if(fflag == 1)
|
||||
center(in, t);
|
||||
else
|
||||
center(stdin, t);
|
||||
}
|
||||
|
||||
else
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
/* Function to call on other subroutines to result in a completely
|
||||
centered line! */
|
||||
|
||||
center(stream, t)
|
||||
FILE *stream;
|
||||
int t;
|
||||
{
|
||||
int x, i;
|
||||
|
||||
while(feof(stream) == 0) {
|
||||
fgets(input, 80, stream);
|
||||
|
||||
i = (t - strlen(input)) / 2;
|
||||
|
||||
fillit(i, 0);
|
||||
|
||||
for(x = 0 ; x <= strlen(input) ; x++)
|
||||
output[i+x] = input[x];
|
||||
if(feof(stream) == 0)
|
||||
fputs(output, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
{
|
||||
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] = ' ';
|
||||
}
|
||||
}
|
71
bin/less/CHANGES
Normal file
71
bin/less/CHANGES
Normal file
@ -0,0 +1,71 @@
|
||||
Well, first off:
|
||||
|
||||
we are: Mike Horwath
|
||||
James Brookes
|
||||
Dave Huang
|
||||
|
||||
5/12/92
|
||||
Jawaid bitched about some stack overflowing, so, between us both, we searched
|
||||
diligently for the error. Inside one of the functions, there was a stack
|
||||
allocated variable over 2K in size. So, the fix was to make it a static
|
||||
variable, so that it is gloabally allocated from normal memory, instead of the
|
||||
stack. That error is now fixed.
|
||||
|
||||
Jawaid also has fixed the getenv() library call, and that was the problem with
|
||||
using a $editor variable in LESS. That is now fixed.
|
||||
|
||||
Less now also works with either files terminated with lf's (unix normal) or
|
||||
cr's (Apple IIgs normal). Works GREAT.
|
||||
|
||||
Fixed a bug where pipes would cause a problem if you shelled out '!' (alone),
|
||||
added GS/OS specific code to take care of which stdin to use, either the pipe
|
||||
or normal stuff...
|
||||
|
||||
5/11/92
|
||||
Well, with big help from Jawaid "The God" Bazyar, piping and redirection are
|
||||
now working correctly. Problems stemmed from file descriptors being set to
|
||||
numbers that were not correct, meaning that, it was trying to write to the
|
||||
input of a pipe or stdin.
|
||||
|
||||
JB put assembly into the putchr() and putstr() calls, noticable speed increase
|
||||
and some savings on disk.
|
||||
|
||||
It prints the control codes by default, so that when you use man, it will do
|
||||
things like inverse and the like correctly.
|
||||
|
||||
did a #pragma noroot so that it cuts off about 1K of exec file. Kind of nice
|
||||
of jawaid to tell me this. Nice little savings I must say.
|
||||
|
||||
Reset the stacksize from 4.5K to 1K, as I was wrong about the stack usage.
|
||||
Thanks go to jawaid for this bit of news also.
|
||||
|
||||
5/5/92
|
||||
Well, another change this time to prchr(), so that you can pass terrible
|
||||
command lines, and have them done right. Problem came from not outputing the
|
||||
right escape type character for end of line stuff. So, that now works. NOW, I
|
||||
only wish I had a terminal to test all this on, hope everythign is fine, if not
|
||||
we are screwed for alot of work here.
|
||||
|
||||
Made the default as -e (let you hit space or return to quit when at eof) and
|
||||
-m (medium prompt line, shows you the file you are viewing, nothing more).
|
||||
|
||||
5/4/92
|
||||
changed most of the open()'s to use the correct modes of the file. solves
|
||||
errors with coming back from vi and such.
|
||||
|
||||
changed the stacksize from default of 8K to 4.5K, seems to work like a dream.
|
||||
|
||||
put in an optimize -1 into the code.
|
||||
|
||||
Worked on the lsystem() call, as it is really messed in the head. Hopefully,
|
||||
by the time you have read this, it will be written from scratch, and working
|
||||
as it should.
|
||||
|
||||
5/3/92-5/4/92
|
||||
Dave fixed all the problems with \n and \r's being wrong in places.
|
||||
|
||||
Dave also fixed the gno termcap entry, as sr and sl (am I right?) were not
|
||||
correct for less to work right.
|
||||
|
||||
5/2/92-5/4/92
|
||||
James and Dave did all the prototyping into the sourcecode.
|
16
bin/less/Info
Normal file
16
bin/less/Info
Normal file
@ -0,0 +1,16 @@
|
||||
Okay, less, for GNO:
|
||||
|
||||
if you use the newest version of MAN (v1.6), then set pager=less will let you
|
||||
use less as your pager.
|
||||
|
||||
copy less.hlp to 31:bin so that less can find its help file.
|
||||
|
||||
copy less to 31:bin and type rehash to get it updated in your path.
|
||||
|
||||
Thats all there is to it, enjoy.
|
||||
|
||||
many thanks go to Jawaid Bazyar for his assembly added to 2 routines for screen
|
||||
updating, as it was a major speed increase.
|
||||
|
||||
the termcap file included is fixed for less and alot of other utilities.
|
||||
please, copy this to your 31:etc directory or there will be problems.
|
104
bin/less/Makefile
Normal file
104
bin/less/Makefile
Normal file
@ -0,0 +1,104 @@
|
||||
o/gsos.a: gsos.c
|
||||
compile gsos.c keep=o/gsos
|
||||
|
||||
o/ttyin.a: ttyin.c less.h defines.h proto.h
|
||||
compile ttyin.c keep=o/ttyin
|
||||
|
||||
o/edit.a: edit.c less.h defines.h proto.h
|
||||
compile edit.c keep=o/edit
|
||||
|
||||
o/lsystem.a: lsystem.c less.h defines.h proto.h position.h
|
||||
compile lsystem.c keep=o/lsystem
|
||||
|
||||
o/line.a: line.c less.h defines.h proto.h
|
||||
compile line.c keep=o/line
|
||||
|
||||
o/help.a: help.c less.h defines.h proto.h
|
||||
compile help.c keep=o/help
|
||||
|
||||
o/output.a: output.c less.h defines.h proto.h
|
||||
compile output.c keep=o/output
|
||||
|
||||
o/position.a: position.c less.h defines.h proto.h position.h
|
||||
compile position.c keep=o/position
|
||||
|
||||
o/tags.a: tags.c less.h defines.h proto.h
|
||||
compile tags.c keep=o/tags
|
||||
|
||||
o/input.a: input.c less.h defines.h proto.h
|
||||
compile input.c keep=o/input
|
||||
|
||||
o/command.a: command.c less.h defines.h proto.h position.h option.h cmd.h
|
||||
compile command.c keep=o/command
|
||||
|
||||
o/optfunc.a: optfunc.c less.h defines.h proto.h option.h
|
||||
compile optfunc.c keep=o/optfunc
|
||||
|
||||
o/screen.a: screen.c less.h defines.h proto.h
|
||||
compile screen.c keep=o/screen
|
||||
|
||||
o/jump.a: jump.c less.h defines.h proto.h position.h
|
||||
compile jump.c keep=o/jump
|
||||
|
||||
o/ifile.a: ifile.c less.h defines.h proto.h
|
||||
compile ifile.c keep=o/ifile
|
||||
|
||||
o/charset.a: charset.c less.h defines.h proto.h
|
||||
compile charset.c keep=o/charset
|
||||
|
||||
o/search.a: search.c less.h defines.h proto.h position.h
|
||||
compile search.c keep=o/search
|
||||
|
||||
o/mark.a: mark.c less.h defines.h proto.h position.h
|
||||
compile mark.c keep=o/mark
|
||||
|
||||
o/os.a: os.c less.h defines.h proto.h
|
||||
compile os.c keep=o/os
|
||||
|
||||
o/main.a: main.c less.h defines.h proto.h position.h
|
||||
compile main.c keep=o/main
|
||||
|
||||
o/option.a: option.c less.h defines.h proto.h option.h
|
||||
compile option.c keep=o/option
|
||||
|
||||
o/opttbl.a: opttbl.c less.h defines.h proto.h option.h
|
||||
compile opttbl.c keep=o/opttbl
|
||||
|
||||
o/forwback.a: forwback.c less.h defines.h proto.h position.h
|
||||
compile forwback.c keep=o/forwback
|
||||
|
||||
o/version.a: version.c less.h defines.h proto.h
|
||||
compile version.c keep=o/version
|
||||
|
||||
o/signal.a: signal.c less.h defines.h proto.h
|
||||
compile signal.c keep=o/signal
|
||||
|
||||
o/cmdbuf.a: cmdbuf.c less.h defines.h proto.h
|
||||
compile cmdbuf.c keep=o/cmdbuf
|
||||
|
||||
o/linenum.a: linenum.c less.h defines.h proto.h position.h
|
||||
compile linenum.c keep=o/linenum
|
||||
|
||||
o/ch.a: ch.c less.h defines.h proto.h
|
||||
compile ch.c keep=o/ch
|
||||
|
||||
o/decode.a: decode.c less.h defines.h proto.h cmd.h
|
||||
compile decode.c keep=o/decode
|
||||
|
||||
o/filename.a: filename.c less.h defines.h proto.h
|
||||
compile filename.c keep=o/filename
|
||||
|
||||
o/prompt.a: prompt.c less.h defines.h proto.h position.h
|
||||
compile prompt.c keep=o/prompt
|
||||
|
||||
o/brac.a: brac.c less.h defines.h proto.h position.h
|
||||
compile brac.c keep=o/brac
|
||||
|
||||
less: o/BRAC.A o/FILENAME.A o/LINENUM.A o/OS.A o/TAGS.A o/CH.A o/FORWBACK.A \
|
||||
o/LSYSTEM.A o/OUTPUT.A o/TTYIN.A o/CHARSET.A o/HELP.A o/MAIN.A \
|
||||
o/POSITION.A o/VERSION.A o/CMDBUF.A o/IFILE.A o/MARK.A o/PROMPT.A \
|
||||
o/COMMAND.A o/INPUT.A o/OPTFUNC.A o/SCREEN.A o/DECODE.A o/JUMP.A \
|
||||
o/OPTION.A o/SEARCH.A o/EDIT.A o/LINE.A o/OPTTBL.A o/SIGNAL.A o/GSOS.A
|
||||
purge
|
||||
compile linkscr
|
||||
purge
|
94
bin/less/brac.c
Normal file
94
bin/less/brac.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Routines to perform bracket matching functions.
|
||||
*/
|
||||
#pragma noroot
|
||||
#include "less.h"
|
||||
#include "position.h"
|
||||
|
||||
#ifdef _ORCAC_
|
||||
segment "LoadSegONE";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Try to match the n-th open bracket
|
||||
* which appears in the top displayed line (forwdir),
|
||||
* or the n-th close bracket
|
||||
* which appears in the bottom displayed line (!forwdir).
|
||||
* The characters which serve as "open bracket" and
|
||||
* "close bracket" are given.
|
||||
*/
|
||||
public void match_brac(obrac, cbrac, forwdir, n)
|
||||
register int obrac;
|
||||
register int cbrac;
|
||||
int forwdir;
|
||||
int n;
|
||||
{
|
||||
register int c;
|
||||
register int nest;
|
||||
POSITION pos;
|
||||
int (*chget)();
|
||||
|
||||
extern int ch_forw_get(), ch_back_get();
|
||||
|
||||
/*
|
||||
* Seek to the line containing the open bracket.
|
||||
* This is either the top or bottom line on the screen,
|
||||
* depending on the type of bracket.
|
||||
*/
|
||||
pos = position((forwdir) ? TOP : BOTTOM);
|
||||
if (pos == NULL_POSITION || ch_seek(pos))
|
||||
{
|
||||
if (forwdir)
|
||||
error("Nothing in top line", NULL_PARG);
|
||||
else
|
||||
error("Nothing in bottom line", NULL_PARG);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look thru the line to find the open bracket to match.
|
||||
*/
|
||||
do
|
||||
{
|
||||
/* if ((c = ch_forw_get()) == '\n' || c == EOI) */
|
||||
if ((c = ch_forw_get()) == '\r' || c == EOI)
|
||||
{
|
||||
if (forwdir)
|
||||
error("No bracket in top line", NULL_PARG);
|
||||
else
|
||||
error("No bracket in bottom line", NULL_PARG);
|
||||
return;
|
||||
}
|
||||
} while (c != obrac || --n > 0);
|
||||
|
||||
/*
|
||||
* Position the file just "after" the open bracket
|
||||
* (in the direction in which we will be searching).
|
||||
* If searching forward, we are already after the bracket.
|
||||
* If searching backward, skip back over the open bracket.
|
||||
*/
|
||||
if (!forwdir)
|
||||
(void) ch_back_get();
|
||||
|
||||
/*
|
||||
* Search the file for the matching bracket.
|
||||
*/
|
||||
chget = (forwdir) ? ch_forw_get : ch_back_get;
|
||||
nest = 0;
|
||||
while ((c = (*chget)()) != EOI)
|
||||
{
|
||||
if (c == obrac)
|
||||
nest++;
|
||||
else if (c == cbrac && --nest < 0)
|
||||
{
|
||||
/*
|
||||
* Found the matching bracket.
|
||||
* If searching backward, put it on the top line.
|
||||
* If searching forward, put it on the bottom line.
|
||||
*/
|
||||
jump_line_loc(ch_tell(), forwdir ? -1 : 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
error("No matching bracket", NULL_PARG);
|
||||
}
|
576
bin/less/ch.c
Normal file
576
bin/less/ch.c
Normal file
@ -0,0 +1,576 @@
|
||||
/*
|
||||
* Low level character input from the input file.
|
||||
* We use these special purpose routines which optimize moving
|
||||
* both forward and backward from the current read pointer.
|
||||
*/
|
||||
#pragma noroot
|
||||
#include "less.h"
|
||||
|
||||
#ifdef _ORCAC_
|
||||
segment "LoadSegONE";
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
public int file = -1; /* File descriptor of the input file */
|
||||
public int ignore_eoi;
|
||||
|
||||
/*
|
||||
* Pool of buffers holding the most recently used blocks of the input file.
|
||||
*/
|
||||
#ifdef BUFSIZ
|
||||
#undef BUFSIZ
|
||||
#define BUFSIZ 1840 /* was 1024, but 80x23 == 1840 */
|
||||
#endif
|
||||
struct buf {
|
||||
struct buf *next, *prev; /* Must be first to match struct filestate */
|
||||
long block;
|
||||
unsigned int datasize;
|
||||
unsigned char data[BUFSIZ];
|
||||
};
|
||||
|
||||
/*
|
||||
* The buffer pool is kept as a doubly-linked circular list,
|
||||
* in order from most- to least-recently used.
|
||||
* The circular list is anchored by the file state "thisfile".
|
||||
*
|
||||
* The file state is maintained in a filestate structure.
|
||||
* There are two such structures, one used when input is a pipe
|
||||
* and the other when input is an ordinary file.
|
||||
* This is so that we can leave a pipe, look and other files,
|
||||
* and return to the pipe without losing buffered data.
|
||||
* Buffered data can be reconstructed for a non-pipe file by
|
||||
* simply re-reading the file, but a pipe cannot be re-read.
|
||||
*/
|
||||
|
||||
struct filestate {
|
||||
struct buf *next, *prev; /* Must be first to match struct buf */
|
||||
POSITION fpos;
|
||||
int nbufs;
|
||||
long block;
|
||||
int offset;
|
||||
POSITION fsize;
|
||||
};
|
||||
|
||||
#define END_OF_CHAIN ((struct buf *)thisfile)
|
||||
#define buf_head thisfile->next
|
||||
#define buf_tail thisfile->prev
|
||||
#define ch_nbufs thisfile->nbufs
|
||||
#define ch_block thisfile->block
|
||||
#define ch_offset thisfile->offset
|
||||
#define ch_fpos thisfile->fpos
|
||||
#define ch_fsize thisfile->fsize
|
||||
|
||||
static struct filestate pipefile =
|
||||
{ (struct buf *)&pipefile, (struct buf *)&pipefile };
|
||||
|
||||
static struct filestate nonpipefile =
|
||||
{ (struct buf *)&nonpipefile, (struct buf *)&nonpipefile };
|
||||
|
||||
static struct filestate *thisfile;
|
||||
|
||||
extern int ispipe;
|
||||
extern int autobuf;
|
||||
extern int sigs;
|
||||
#if LOGFILE
|
||||
extern int logfile;
|
||||
extern char *namelogfile;
|
||||
#endif
|
||||
|
||||
static int fch_get(void);
|
||||
static int buffered(long block);
|
||||
static int ch_addbuf(int nnew);
|
||||
|
||||
/*
|
||||
* Get the character pointed to by the read pointer.
|
||||
* ch_get() is a macro which is more efficient to call
|
||||
* than fch_get (the function), in the usual case
|
||||
* that the block desired is at the head of the chain.
|
||||
*/
|
||||
#define ch_get() ((ch_block == buf_head->block && \
|
||||
ch_offset < buf_head->datasize) ? \
|
||||
buf_head->data[ch_offset] : fch_get())
|
||||
static int
|
||||
fch_get(void)
|
||||
{
|
||||
register struct buf *bp;
|
||||
register int n;
|
||||
register int slept;
|
||||
POSITION pos;
|
||||
POSITION len;
|
||||
|
||||
slept = 0;
|
||||
|
||||