📄 futility.cpp
字号:
break; // ..and wait for another..
}
x--; // move left one character
// ..and fall into delete key
case DELETE: // delete key
i = x - c; // set up string index
strcpy(&w[i], &w[i + 1]); // simulate delete
w[m - 1] = ' '; // ..and put a blank at end
sprintf(b, "%s", &w[i]); // make into string
win->AtSayReverse(x, r, b); // ..display remainder
break; // ..and wait for next key
case HOME: // home key
x = c; // reset pointer to start
break; // ..and wait for next key
case END: // end key
x = c + m - 1; // reset pointer to end
break; // ..and wait for next key
case CR: // carriage return
case UP: // up arrow key
case DOWN: // down arrow key
NOCURSOR(); // turn cursor off
free(org); // release original data
*s = w; // store addr of new data
win->AtSay(c, r, w); // ..display field normally
return(DOWN); // ..then return to caller
case ESC: // escape key
NOCURSOR(); // turn cursor off
win->AtSay(c, r, w); // ..display field normally
free(w); // release work copy
return(0); // ..then return to caller
case INSERT: // insert toggle
if (ins) // q. insert mode active?
{
ins = 0; // a. yes .. turn it off
CURSOR(); // ..and use proper cursor
}
else
{
ins = 1; // else .. set on insert
BIGCURSOR(); // ..and show insert cursor
}
break; // then wait for next key
default: // error case
if (k & 0xff00 || // q. function key..
k < ' ') // ..or less than a blank?
{
printf(BELL); // a. yes .. ring the bell
break; // ..and wait for next key
}
i = x - c; // get string index
if (ins) // q. insert mode active?
{
memmove(&w[i + 1], &w[i], // a. yes .. move everything
m - i); // ..for the remainder over
w[m] = 0; // ..and overlay the overflow
w[i] = (char) k; // put new char its place
sprintf(b, "%s", &w[i]); // make into a displayable
}
else
{
w[i] = (char) k; // save character in string
sprintf(b, "%c", k); // make into a string
}
win->AtSayReverse(x, r, b); // display new char/string
if (i < (m - 1)) // q. upto right margin?
x++; // a. no .. advance one
break; // ..then get next key
}
win->GotoXY(x, r); // ..then go there
}
}
/* ******************************************************************** *
*
* set_bits() -- set on a string of bits
*
* ******************************************************************** */
void set_bits(char *s, // target string
int n, // starting bit nbr (0 based)
int l) // length of bits
{
char mask; // work mask
int f; // first bit number
if (NOT l) // q. zero length?
return; // a. yes .. then just return
s += n / 8; // get to 1st target byte
f = n % 8; // bit within byte
mask = 0xff >> f; // initial mask
f = 8 - f; // remaining bits after 1st
if (f >= l) // q. too many already?
{
mask &= (0xff00 >> ((n % 8) + l)); // a. yes .. clear off extras
*s |= mask; // ..set the bits on
return; // ..and return to caller
}
else
*s++ |= mask; // else .. set on first group
for (l -= f; l >= 8; l -= 8) // for each group of 8 bits
*s++ = 0xff; // ..mark all of them on
if (l) // q. any straglers?
*s |= 0xff00 >> l; // a. yes .. turn them on too
}
/* ******************************************************************** *
*
* get_bit() -- get a bit from a string of bits
*
* ******************************************************************** */
UINT get_bit(unsigned char *s, // target string
int n) // starting bit nbr (0 based)
{
return((s[n / 8] >> (7 - (n % 8))) & 1); // return with requested bit
}
/* ******************************************************************** *
*
* get_bits() -- get a string of bits
*
* ******************************************************************** */
UINT get_bits(unsigned char *s, // target string
int n, // starting bit nbr (0 based)
int l) // length of bits
{
UINT x; // bits from bit string
if (NOT l || l > 16) // q. too much or too little?
return(0); // a. yes .. then just return
for (x = 0; l--; n++) // while there is work to do
x = (x << 1) | get_bit(s, n); // ..get another bit
return(x); // finally, return to caller
}
/* ******************************************************************** *
*
* reverse_scan() -- backscan for dissimilar character
*
* ******************************************************************** */
char *reverse_scan(char *p, // starting point
char c, // character to scan against
int len) // length of search
{
for (p += len - 1; len--; p--) // loop thru memory
if (*p != c) // q. find last one?
return(p); // a. yes .. return w/address
return(0); // else .. return empty handed
}
/* ******************************************************************** *
*
* trim() -- trim trailing blanks
*
* ******************************************************************** */
char *trim(char *s) // source and target string
{
char *p; // work pointer
for (p = s + strlen(s) - 1; // starting at the end..
*p == ' ' && p > s; p--) // ..work backwards
;
*(++p) = 0; // set in new terminator
return(s); // ..and return w/source
}
/* ******************************************************************** *
*
* control_break() -- control break intercept routine
*
* ******************************************************************** */
#pragma option -O2-b-e // no global reg allocation
// ..or dead code elimination
void interrupt control_break(...)
{
asm mov al, 20 // al = end of interrupt cmd
asm out 20, al // clear kb interrupt on 8259
}
/* ******************************************************************** *
*
* critical_rtn() -- DOS critical error handler
*
* ******************************************************************** */
#pragma option -O2-b-e // no global reg allocation
// ..or dead code elimination
void interrupt critical_routine(...)
{
if (_AX & 0x800) // q. fail allowed?
_AX = (_AX & 0xff00) | 3; // a. yes .. show failed
else
_AX = (_AX & 0xff00) | 2; // else .. abort
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -