home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_100
/
157_01
/
qed1
< prev
next >
Wrap
Text File
|
1987-10-12
|
12KB
|
561 lines
/* VERSION 0004 (DATE: 03/03/87) (TIME: 11:07) */
/*
e (qed) screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W.Haefner)
March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W.Haefner)
FILE: qe1
FUNCTIONS: dirmsk,
printdirectory, envir, files, putonoff, getnumb, getlow
PURPOSE: environment; change files.
*/
#include "qed.h"
#define EXTENT 12
#define RECORDS 15
#define EXTSIZ 128
#if CPM /*NOTE: <<NOT>> debugged for CP/M86*/
dirmsk()
{
char *pattp;
sint drv;
pattp = patt; /* use pattern find array to save extnl space */
if (scans(patt,FILELEN) == ESCKEY) return (YES);
drv = curdsk+1; /* drv = num for bdos file search */
if (!*pattp) pattp = "*.*";
else
if (patt[1] == ':') {
if ( ((drv = (toupper(*pattp) - '@')) < 1) || (drv > 16) )
drv = curdsk+1;
pattp += 2;
}
expmsk(drv,pattp);
}
expmsk(drv,str) /* create wildcard cp/m filename from str*/
sint drv;
char *str;
/* input: str: a user input string to expand to legal cp/m wildcard name
output: dirmsk: a string wh/ is a legal cp/m wildcard file name */
{ /* 10 */
sint stop,inmsk,inwild;
char c, wildarray[15], *wildname;
for (inwild=0;inwild<15;wildarray[inwild++]=' ');
wildname = wildarray; /* use pattern change array to save space */
wildname[0] = drv;
wildname[12] = '?';
wildname[14] = '\0';
stop = 8;
inmsk = 0; /* index for input mask */
inwild = 1; /* index for directory mask (output) */
while ((wildname[inwild]) && (str[inmsk])) {
switch (c=str[inmsk++]) { /*30*/
case '*' :
for( ; (inwild <= stop);inwild++)
wildname[inwild] = '?';
stop = 11;
break;
case '.' :
inwild = 9;
stop = 11;
break;
default:
wildname[inwild++] = toupper(c);
break;
} /*30*/
}
printdirectory(wildname);
} /*10*/
printdirectory(wildname)
char *wildname;
{
int y, *dsm, cols, loc, i, ndb, pos;
unsigned blsr, used, recs;
char c, a, entriesonline, *bsh, exm, al0;
char *parms;
sint dmabuf[128],drive;
putclr();
gotoxy(0,6);
putstr("Can't print directory yet.");
_os(SETDMA,dmabuf);
drive = wildname[0]-1;
gotoxy(0,6);
putstr("Directory of ");
putch(drive + 'A');
putch(':');
if (curdsk != (drive) && seldisk(drive) != FAIL) {
putstr(" |(default drive is ");
putch(curdsk+'A');
putstr(":|)");
}
used=0;
parms=_os(DSKPARAMS);
bsh = parms+2;
exm = *(parms+4);
dsm = parms+5;
al0 = *(parms+9);
blsr = (1 << *bsh)/8;
/*block size in kbytes*/
for(ndb=0;al0;al0 <<= 1, ndb++);
entriesonline=0;
begdim();
deleteline(2,(y=8));
pos=_os(SEARCH1,wildname);
while (pos != 0xff) {
loc= pos << 5;
recs = (exm) ? EXTSIZ*(dmabuf[loc+EXTENT]%((exm)+1))
+ dmabuf[loc+RECORDS]
: dmabuf[loc+RECORDS];
used += (recs/(8*blsr))*blsr;
if (recs%(8*blsr)) used += blsr;
if (dmabuf[loc+EXTENT] <= exm) {
for (i=1, cols=0; i < 12; i++) {
c= dmabuf[loc+i] & 0x7f;
if (i == 9 && c != ' ') {
cols++;
putch('.');
}
if (c != ' ') {
cols++;
putch( (i >= 9 ? tolower(c) : c));
}
}
while (cols++ < 12) putch(' ');
if (++entriesonline == 5) {
deleteline(2,++y);
if (y == SHEIGHT) {
putstr("[||<cr>| for MORE...]");
a = getkey();
begdim();
delpage((y=8));
gotoxy(2,8);
/* goto incomplete; */
}
entriesonline=0;
}
else putstr(" : ");
}
pos=_os(SEARCHN,wildname);
}
gotoxy(50,SHEIGHT);
for (i=1;((wildname[i]=='?') && (i<12)); i++);
if (i==12) {
putstr("Free = ");
uspr((((*dsm+1)-ndb)*blsr)-used);
putstr("k ");
}
putstr("Files = ");
uspr(used);
putch('k');
if (curdsk != drive) seldisk(curdsk);
enddim();
gotoxy(0,0);
return;
}
#endif
#if DOS2
dirmsk() /* in MSDOS 2.x just pass the string to showdir
maintain dirmsk call for other functions */
{
char *pattp;
pattp=patt;
if (scans(patt,FILELEN) == ESCKEY) return YES;
if (!*pattp) pattp = "*.*";
showdir(pattp);
}
showdir(msk) /* show msdos directory from ambiguous mask */
char *msk; /* assumes vers.2.x, allows path names */
{
char dtabuf[43], *dirsp, curdir[64], *curdirp;
char *bufp,first, driven, drivel, entriesonline, a, c;
long fsize,*sizep,used,free;
int x,y,i;
/* init display */
putclr();
/* has a drive been specified?*/
for (i=0;( (c=msk[i++]) && (c != ':') ););
if (c) {
drivel = toupper(msk[(i-=2)]);
{
if ( ((driven = drivel-'A') < 0) || (driven > 15)) {
driven=curdsk;
drivel=driven+'A';
}
}
}
else {
driven=curdsk;
drivel=driven+'A';
}
curdirp=curdir;
*curdirp=0;
gotoxy(0,6);
if (getpath(curdirp,(driven+1))==FAIL) return NO;
putstr("Directory of ");
dispch(drivel);
putstr(":\\");
putstr(curdirp);
if (curdsk != (driven) && seldisk(driven) != FAIL) {
putstr(" |(default drive is ");
putch(curdsk+'A');
putstr(":|)");
}
/* get disk free space */
_rax = (FREESP << 8);
_rds = -1;
_rdx = driven+1;
_rcx = 0x00;
_doint(DOSINT);
if(_rax==0xffff) {
error("Bad drive");
return (_rax);
}
/*use "1L" to force unsigned to long conversion*/
free = 1L*(_rax) * (_rbx) * (_rcx);
deleteline((x=2),(y=8));
dirsp="=||dir|";
entriesonline=0;
used=0;
for (i=0;i<43;i++)
dtabuf[i]=0;
_os(SETDMA,dtabuf);
first=TRUE;
do {
_rax = ( (first) ? (0x4e << 8) : (0x4f << 8) ); /* find first&next */
_rdx = msk; /* point to path */
_rds = -1; /* use current ds */
_rcx = 0x30; /* show normal, dir and archived files */
_doint(DOSINT); /* goto DOS */
if (_rax == 2) { /* bad path */
error("Bad path");
return NO;
}
if ( (_rax != 18) ) { /* name is found */
begdim();
first=FALSE;
sizep=&dtabuf[0x1a];
fsize= *sizep;
used+=fsize;
bufp=&dtabuf[0x1e];
putstr(bufp);
if (dtabuf[0x15]==0x10) putstr(dirsp); /*entry is directory*/
/*put code to show if archive bit set, here */
if ((++entriesonline<5))
gotoxy((x+=15),y);
else {
deleteline((x=2),++y);
if (y==SHEIGHT) {
putstr("[||<cr>| for MORE...]");
a=getkey();
begdim();
delpage((y=8));
gotoxy((x=2),y);
}
entriesonline=0;
}
}
}
while ( (_rax != 18) );
gotoxy(40,SHEIGHT);
putstr("Free = ");
uspr(0,free);
putstr(" Files = ");
uspr(0,used);
if (curdsk != driven) seldisk(curdsk);
enddim();
gotoxy(0,0);
return (_rax);
}
#endif
envir()
{
char c;
int maxlines;
struct addr anaddr;
puttext();
do {
putclr();
putstatusline(cline);
gotoxy(0,3);
putstr("Edit context: |(|F| for file context)|\n\n");
putstr("A|uto indent ");
putonoff(autoin);
putstr("B|ackup altered file ");
putonoff(backup);
putstr("D|efault backup path ");
putstr(bakpath);
putstr("\nT|ab stops every ");
uspr(tabwidth,0L);
putstr("\nS|trip trailing blanks ");
putonoff(!trail);
putstr("L|ine and column ");
putonoff(displaypos);
#if WWRAP
putstr("R|ight margin ");
uspr(rtmarg,0L);
#endif
putstr("\nH|orizontal scroll page ");
putonoff(blockscroll);
putstr("E|xpert prompts ");
putonoff(expert);
putstr("O|nscreen help ");
putonoff(helpon);
#if VRSNNUM
putstr("V|ersion update ");
putonoff(version);
#endif
/*
putstr("\n|Memory allows for no more than ");
uspr( ((slotsinmem-2)*(PAGESIZE/(sizeof(anaddr)))) ,0L);
putstr("| lines of text");
*/
putstr("\n|Current line ");
uspr(cline,0L);
putstr(" is |");
maxlines=(slotsinmem-2)*(PAGESIZE/(sizeof(anaddr)));
uspr( (unsigned)(((long)cline*100)/maxlines),0L);
putstr("% |of ");
uspr(maxlines,0L);
putstr(" maximum lines.");
putstr("\n\n\nTo change context, enter letter, or |Q| to return: ");
switch((c=getlow())) {
case 'a':
autoin= !autoin;
break;
case 'b':
backup= !backup;
break;
case 'd':
putstr("\n\n|Enter path for |quick backup|: ");
scans(bakpath,PATHLEN);
break;
case 'e':
expert= !expert;
break;
case 'o':
helpon = !helpon;
break;
case 'l':
displaypos=!displaypos;
break;
#if WWRAP
case 'r':
putstr("\n\n|Enter new |right margin|: ");
if (!(rtmarg=getnumb())) rtmarg=LLIM;
if (rtmarg<LLIM) {
trail=YES;
autoin=NO;
}
if (rtmarg==LLIM) {
trail=NO;
autoin=YES;
}
break;
#endif
#if VRSNNUM
case 'v':
version = !version;
break;
#endif
case 'h':
blockscroll=!blockscroll;
break;
case 't':
putstr("\n\n|Enter new |tab width|: ");
if (!(tabwidth=getnumb())) tabwidth=0;
break;
case 's':
trail=!trail;
break;
case 'f':
if(files()) goto escape;
break;
case 'q':
case ESCKEY:
goto escape;
}
}
while (YES);
escape:
putclr();
topline=1;
if (helpon) dohelp();
putpage();
}
getpath(curdirp,drvnum)
char *curdirp;
int drvnum;
{
_rax = (GETDIR << 8); /* GETDIR = 0x47 */
_rds = -1;
_rsi = curdirp;
_rdx = drvnum;
_doint(DOSINT);
if ((_carryf) && (_rax==0x15)) {
error("Bad drive");
return FAIL;
}
return YES;
}
files()
{
char oldname[15], newname[15], dc, c;
char curdir[64], *curdirp, *tp;
int dir;
do {
putclr();
putstatusline(cline);
newcomm:
dir=curdsk;
errmess=NULL;
gotoxy(0,1);
putstr("|Enter |Q| to return to Edit context |D| to delete a file\n");
putstr(" R| to rename a file |P| to change/show path |>| to view directory \n");
deleteline(0,3);
putstr(" C| to change the name of the edited file ");
putstr(filename);
deleteline(0,4);
deleteline(0,5);
/*gotoxy(6,4);*/
deleteline(6,4);
c=getlow();
putstatusline(cline);
switch (c) {
case ESCKEY:
return YES;
case 'q':
return NO;
case '>':
deleteline(6,4);
putstr("Enter [drv:]mask| (RET for all) ");
dirmsk();
goto newcomm;
case 'p':
tp=curdirp=curdir;
*curdirp=0;
deleteline(6,4);
putstr("Drive: ");
if((c=getscankey()) == CR || c==ESCKEY) dir++;
else dir=(toupper(c)-'@'); /*A=1,B=2...*/
if (getpath(curdirp,(dir))==FAIL) goto newcomm;
deleteline(6,4);
putstr("|Current directory: |");
dispch((dir+'@'));
putstr(":\\");
putstr(curdirp);
putstr("| Enter new directory: |");
scans(curdir,FILELEN);
if (!(*curdirp)) goto newcomm;
/* drive specified? */
while( (dc=*(tp++)) && dc != ':');
if (dc) {
if ( (dir=toupper(*(tp-2))-'A') <0 || dir>16) {
/*if (seldisk(dir)) continue;
curdsk=dir;*/
*curdirp=curdsk+'A';
}
}
_rax = (SETDIR << 8); /* SETDIR = 0x3b */
_rds = -1;
_rdx = curdirp;
_doint(DOSINT);
deleteline(6,4);
if (_carryf) error("Bad path");
goto newcomm;
default:
if (c == 'r' || c == 'd' || c == 'c') {
deleteline(6,4);
putstr("Name of file: ");
scans(oldname,FILELEN);
if (!oldname[0]) goto newcomm;
format(oldname);
}
switch (c) {
case 'd':
if (funlink(oldname) == FAIL) {
error("Can't delete");
goto newcomm;
}
break;
case 'r' :
deleteline(6,5);
putstr("New name: ");
scans(newname,15);
format(newname);
if (!newname[0] || frename(oldname,newname) == FAIL) {
error("Can't rename");
goto newcomm;
}
break;
case 'c' :
strcpy(filename,oldname);
setstatusname();
putstatusline(cline);
default:
goto newcomm;
}
}
}
while (YES);
}
putonoff(flag)
int flag;
{
putstr((flag) ? "ON\n" : "OFF\n");
}
getnumb()
{
int i, n;
char c, numb[5];
scans(numb,5);
n=qatoi(numb);
return n;
}
qatoi(nstr)
char *nstr;
{
int i,n;
char c;
n=0;
for (i=0; (c=nstr[i]); i++)
if (c >= '0' && c <= '9') n=n*10+c-'0';
return n;
}