📄 edbasic.c
字号:
return (FALSE);
return (TRUE);
}
/*
* The command allows the user
* to modify the file name associated with
* the current buffer. It is like the "f" command
* in UNIX "ed". The operation is simple; just zap
* the name in the BUFFER structure, and mark the windows
* as needing an update. You can type a blank line at the
* prompt if you wish.
*
* Bound to "C-X C-R" for Rename buffer!
* Changed 7/28/86 by CJC.
*/
#if IBM_TBC
#pragma argsused
#endif
globle int filename(
void *theEnv,
int f,
int n)
{
register WINDOW *wp;
register int s;
char fname[NFILEN];
if ((s=mlreply(theEnv,"Name: ", fname, NFILEN)) == ABORT)
return (s);
if (s == FALSE)
strcpy(curbp->b_fname, "");
else
strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
return (TRUE);
}
/* =======================================================================
* Low level File I/O commands
* =======================================================================
*/
static FILE *ffp; /* File pointer, all functions. */
/*
* The routines in this section do the low level read and write of ASCII
* files from the disk. All of the knowledge about files is here. A better
* message writing scheme should be used.
*/
/*
* Open a file for reading.
*/
globle int ffropen(
char *fn)
{
if ((ffp=fopen(fn, "r")) == NULL)
return (FIOFNF);
return (FIOSUC);
}
/*
* Open a file for writing. Return TRUE if all is well, and FALSE on error
* (cannot create).
*/
globle int ffwopen(
char *fn)
{
#if VAX_VMS
register int fd;
if ((fd=creat(fn, 0666, "rfm=var", "rat=cr")) < 0
|| (ffp=fdopen(fd, "w")) == NULL) {
#else
if ((ffp=fopen(fn, "w")) == NULL) {
#endif
mlwrite("Cannot open file for writing");
return (FIOERR);
}
return (FIOSUC);
}
/*
* Close a file. Should look at the status in all systems.
*/
globle int ffclose()
{
#if UNIX_7 || UNIX_V
if (fclose(ffp) != FALSE) {
mlwrite("Error closing file");
return(FIOERR);
}
#else
fclose(ffp);
#endif
return (FIOSUC);
}
/*
* Write a line to the already opened file. The "buf" points to the buffer,
* and the "nbuf" is its length, less the free newline. Return the status.
* Check only at the newline.
*/
globle int ffputline(
char buf[],
int nbuf)
{
register int i;
for (i = 0; i < nbuf; ++i)
fputc(buf[i]&0xFF, ffp);
fputc('\n', ffp);
if (ferror(ffp)) {
mlwrite("Write I/O error");
return (FIOERR);
}
return (FIOSUC);
}
/*
* Read a line from a file, and store the bytes in the supplied buffer. The
* "nbuf" is the length of the buffer. Complain about long lines and lines
* at the end of the file that don't have a newline present. Check for I/O
* errors too. Return status.
*/
globle int ffgetline(
char buf[],
int nbuf)
{
register int c;
register int i;
i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\n') {
if (i >= nbuf-1) {
mlwrite("File has long line");
return (FIOERR);
}
buf[i++] = (char) c;
}
if (c == EOF) {
if (ferror(ffp)) {
mlwrite("File read error");
return (FIOERR);
}
if (i != 0) {
mlwrite("File has funny line at EOF");
return (FIOERR);
}
return (FIOEOF);
}
buf[i] = 0;
return (FIOSUC);
}
/* =======================================================================
* LOW LEVEL TERMINAL I/O COMMANDS
* =======================================================================
*/
/*
* The functions in this section negotiate with the operating system for
* characters, and write characters in a barely buffered fashion on the
* display. All operating systems.
*/
/*
* This function is called once to set up the terminal device streams.
* On VMS, it translates SYS$INPUT until it finds the terminal, then assigns
* a channel to it and sets it raw.
*/
globle void ttopen()
{
#if VAX_VMS
struct dsc$descriptor idsc;
struct dsc$descriptor odsc;
char oname[40];
int iosb[2];
int status;
odsc.dsc$a_pointer = "SYS$INPUT";
odsc.dsc$w_length = strlen(odsc.dsc$a_pointer);
odsc.dsc$b_dtype = DSC$K_DTYPE_T;
odsc.dsc$b_class = DSC$K_CLASS_S;
idsc.dsc$b_dtype = DSC$K_DTYPE_T;
idsc.dsc$b_class = DSC$K_CLASS_S;
do {
idsc.dsc$a_pointer = odsc.dsc$a_pointer;
idsc.dsc$w_length = odsc.dsc$w_length;
odsc.dsc$a_pointer = &oname[0];
odsc.dsc$w_length = sizeof(oname);
status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
exit(status);
if (oname[0] == 0x1B) {
odsc.dsc$a_pointer += 4;
odsc.dsc$w_length -= 4;
}
} while (status == SS$_NORMAL);
status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
if (status != SS$_NORMAL)
exit(status);
status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
exit(status);
newmode[0] = oldmode[0];
newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
newmode[1] &= ~(TT$M_TTSYNC|TT$M_HOSTSYNC);
newmode[2] = oldmode[2] | TT2$M_PASTHRU;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
exit(status);
#endif
#if UNIX_7 || UNIX_V
ioctl(1,TIOCGETP,&ostate);
ioctl(1,TIOCGETP,&nstate);
/* gtty(1, &ostate); */ /* save old state */
/* gtty(1, &nstate); */ /* get base of new state */
nstate.sg_flags |= RAW;
nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */
/* stty(1, &nstate); */ /* set mode */
ioctl(1,TIOCSETP,&nstate);
#endif
}
/*
* This function gets called just before we go back home to the command
* interpreter. On VMS it puts the terminal back in a reasonable state.
*/
globle void ttclose()
{
#if VAX_VMS
int status;
int iosb[1];
ttflush();
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
exit(status);
status = SYS$DASSGN(iochan);
if (status != SS$_NORMAL)
exit(status);
#endif
#if UNIX_7 || UNIX_V
/* stty(1, &ostate); */
ioctl(1,TIOCSETP,&ostate);
#endif
#if IBM_ZTC || IBM_SC
disp_close();
#endif
}
/*
* Write a character to the display. On VMS, terminal output is buffered, and
* we just put the characters in the big array, after checking for overflow.
* Ditto on MS-DOS (use the very very raw console output routine).
*/
#if IBM_TBC
#pragma argsused
#endif
globle void ttputc(
int c)
{
#if VAX_VMS
if (nobuf >= NOBUF)
ttflush();
obuf[nobuf++] = c;
#endif
#if UNIX_7 || UNIX_V
fputc(c, stdout);
#endif
}
/*
* Flush terminal buffer. Does real work where the terminal output is buffered
* up. A no-operation on systems where byte at a time terminal I/O is done.
*/
globle void ttflush()
{
#if VAX_VMS
int status;
int iosb[2];
status = SS$_NORMAL;
if (nobuf != 0) {
status = SYS$QIOW(EFN, iochan, IO$_WRITELBLK|IO$M_NOFORMAT,
iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0);
if (status == SS$_NORMAL)
status = iosb[0] & 0xFFFF;
nobuf = 0;
}
#endif
#if UNIX_7 || UNIX_V
fflush(stdout);
#endif
}
/*
* Read a character from the terminal, performing no editing and doing no echo
* at all. More complex in VMS that almost anyplace else, which figures.
*/
globle int ttgetc()
{
#if VAX_VMS
int status;
int iosb[2];
long term[2]; /*Terminator block for I/O*/
while (ibufi >= nibuf) {
ibufi = 0;
term[0] = 0;
term[1] = 0;
status = SYS$QIOW(EFN, iochan,
IO$_READLBLK|IO$M_TIMED|IO$M_NOFILTR|IO$M_PURGE,
iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0);
if (status != SS$_NORMAL)
exit(status);
status = iosb[0] & 0xFFFF;
if (status!=SS$_NORMAL && status!=SS$_TIMEOUT)
exit(status);
nibuf = (iosb[0]>>16) + (iosb[1]>>16);
if (nibuf == 0) {
status = SYS$QIOW(EFN, iochan,IO$_READLBLK|
IO$M_NOFILTR|IO$M_PURGE,
iosb, 0, 0, ibuf, 1, 0, term, 0, 0);
if (status != SS$_NORMAL)
exit(status);
status = (iosb[0]&0xFFFF);
if (status != SS$_NORMAL)
exit(status);
nibuf = (iosb[0]>>16) + (iosb[1]>>16);
}
}
if (ibuf[ibufi] == ESC)
{
status = SYS$QIOW(EFN,iochan,IO$_READLBLK|IO$M_NOFILTR|IO$M_TIMED,
iosb,0,0,ibuf+1,4,0,term,0,0);
nibuf = (iosb[0]>>16) + (iosb[1]>>16) + 1;
if ((status == SS$_NORMAL) && (nibuf > 1))
return(parse_esc_seq());
if ((status != SS$_NORMAL) && (status != SS$_TIMEOUT))
exit(status);
}
return (ibuf[ibufi++] & 0xFF); /* Allow multinational */
#endif
#if IBM_MSC || IBM_TBC || IBM_ZTC || IBM_ICB || IBM_SC || IBM_GCC
return (fgetc(stdin)); /* NOTE: This won't really work */
#endif /* See file EDTERM.C for good code */
#if UNIX_7 || UNIX_V
return(fgetc(stdin));
#endif
}
#if VAX_VMS
/********************************/
/*PARSES ESCAPE SEQUENCES */
/********************************/
globle int parse_esc_seq() {
int index, num;
index = ibufi + 1;
if ((ibuf[index] != '[') && (ibuf[index] != 'O')) {
if ((ibuf[index] >= 'a') && (ibuf[index] <= 'z'))
ibuf[index] = ibuf[index] - ('a' - 'A');
if ((ibuf[index] >= '\000') && (ibuf[index] <= '\037'))
ibuf[index] = COTL | ibuf[index];
ibufi = nibuf + 1;
return (META | ibuf[index]);
}
if (ibuf[index] == '[') index++;
ibufi = nibuf + 1;
switch (ibuf[index]) {
case 'A' : return(COTL | 'P');
break;
case 'B' : return(COTL | 'N');
break;
case 'C' : return(COTL | 'F');
break;
case 'D' : return(COTL | 'B');
break;
case '1' : case '2' : case '3' :
case '4' : case '5' : case '6' :
if (ibuf[index + 1] != TERM)
num = (ibuf[index] - 48)*10 + (ibuf[++index] -48);
else num = ibuf[index] - 48;
switch (num) {
case 1 : return(COTL | 'S');
break;
case 2 : return(COTL | 'Y');
break;
case 3 : return(COTL | 'W');
break;
case 4 : return(COTL | '@');
break;
case 5 : return(META | 'V');
break;
case 6 : return(COTL | 'V');
break;
default : return BADKEY;
}
break;
default : return BADKEY;
}
return(TRUE);
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -