📄 support.c
字号:
}
GLOBAL BYTE * copy_char(dest, source)
REG BYTE **dest, **source;
{
if (dbcs_lead(**source))
{
if (*(*source + 1) >= ' ')
{
*(*dest)++ = *(*source)++;
*(*dest)++ = *(*source);
}
}
else
{
*(*dest)++ = *(*source);
}
(*source)++;
return(*source);
}
/* Check if character in string is blank.
Return size in bytes of blank character, zero if not blank character. */
GLOBAL WORD is_blank(s)
REG BYTE *s;
{
WORD blank_size;
if (*s == ' ' || *s == '\t')
blank_size = 1;
else if (dbcs_expected() && *s == 0x81 && *(s + 1) == 0x40)
blank_size = 2; /* KANJI space */
else
blank_size = 0;
return(blank_size);
}
GLOBAL BYTE * deblank(s) /* scan off leading white space */
REG BYTE *s; /* starting address of scan */
{
REG WORD blank_size;
while ((blank_size = is_blank(s)) != 0)
s += blank_size;
return (s); /* return deblanked string */
}
#if !(defined(MSC) || defined(MWC) || defined(TURBOC) || defined(WATCOMC))
GLOBAL BYTE * strchr(s, b)
BYTE *s, b;
{
while(b != *s && *s)
s++;
if(*s)
return s;
else
return NULL;
}
#endif
/* Convert all uppercase characters in ASCIIZ string to lowercase.
If country code is JAPAN Kanji character code pairs (ie 8 bit Kanji
escape code followed immediatly by 8 bit Kanji character code) are
not changed. */
GLOBAL BYTE *strlwr(s)
BYTE *s;
{
REG BYTE *bp;
if (dbcs_expected()) /* are we looking out for DBCS? */
{ /* yes - DON'T CHANGE DBCS CODES */
for (bp = s; *bp; bp++)
{
if (dbcs_lead(*bp)) /* is this first of a DBCS pair? */
{
bp++; /* yes - skip over it */
if (*bp == '\0') /* it is followed by its partner? */
break; /* no - invalid DBCS, exit loop */
}
else
*bp = tolower(*bp); /* no - lower case it */
}
}
else
for (bp = s; *bp; bp++)
*bp = tolower(*bp);
return s;
}
/* Convert all lowercase characters in ASCIIZ string to uppercase.
Double byte characters are not changed. */
GLOBAL BYTE *strupr(s)
BYTE *s;
{
REG BYTE *bp;
if (dbcs_expected()) /* are we looking out for DBCS? */
{ /* yes - DON'T CHANGE DBCS CODES */
for (bp = s; *bp; bp++)
{
if (dbcs_lead(*bp)) /* is this first of a DBCS pair? */
{
bp++; /* yes - skip over it */
if (*bp == '\0') /* it is followed by its partner? */
break; /* no - invalid DBCS, exit loop */
}
else
*bp = toupper(*bp); /* no - upper case it */
}
}
else
for (bp = s; *bp; bp++)
*bp = toupper(*bp);
return s;
}
/*
* STRNICMP does a caseless match on the two input strings for LEN
* characters. This function is only used for token matching for
* commands like FOR and IF. Double byte character set aware.
*/
GLOBAL WORD strnicmp(str1, str2, len)
REG BYTE *str1, *str2;
UWORD len;
{
while (len--) /* loop until len == 0 */
{
if (dbcs_lead(*str1) || dbcs_lead(*str2))
{ /* one or both characters are DBCS */
if (*str1 != *str2) /* are they identical? */
return -1; /* no - return SMALER */
if(!*str1)
break;
str1++; str2++; /* skip DBCS escape */
if (*str1 != *str2) /* are DBCS char codes identical? */
return -1; /* no - return SMALLER */
}
else
if (toupper(*str1) != toupper(*str2))
return -1;
if(!*str1)
break;
str1++; str2++;
}
return 0; /* return EQUAL */
}
/*
* ZAP_SPACES removes all white space from a string
*/
GLOBAL VOID zap_spaces(cp)
REG BYTE *cp;
{
REG BYTE *cp1;
do {
cp1 = deblank(cp); /* Skip leading whitespace */
if (cp1 != cp) /* If whitespace has been */
strcpy(cp, cp1); /* skipped then move string */
while (*cp && !is_blank(cp)) /* Now skip over */
cp++; /* normal characters */
/* and repeat till the end */
} while (*cp);
}
GLOBAL VOID strip_path(path, dir)
BYTE *path;
BYTE *dir;
{
REG BYTE *cp;
REG WORD i;
i = 0; /* assume empty path */
for (cp=path; *cp; cp++) { /* scan the file name */
if(dbcs_lead(*cp)) { /* If this is a DBCS */
cp++; /* character then skip */
continue; /* the next char */
}
if ((*cp == *pathchar) || /* if path delimiter */
(*cp == ':')) /* or drive specifier */
i = (cp+1)-path; /* remember offset */
}
strcpy (dir, path); /* make a copy */
dir[i] = '\0'; /* discard all but path */
}
GLOBAL BOOLEAN getdigit(n, s)
WORD *n; /* Pointer to the word number to save */
BYTE **s; /* String to Process */
{
*n = 0; /* Zero the number */
while(!isdigit(**s) && **s) /* Skip all non digits */
(*s)++;
if(**s) {
while(isdigit(**s)) { /* Add all the digits in */
*n = **s - '0' + *n * 10;
(*s)++;
}
return TRUE; /* and return success */
}
else
return FALSE;
}
/*
* Check that the number input by the user and held in S is in
* the range specified by MIN and MAX if this is so then update
* VALUE and return SUCCESS otherwise VALUE is unchabged and
* return FAILURE.
*/
GLOBAL BOOLEAN check_num(s, min, max, value)
BYTE *s; /* Input String */
WORD min, max; /* Minimum and Maximum values */
UWORD *value; /* Value Input */
{
WORD u;
deblank(s);
if(getdigit(&u, &s) == FALSE)
return FAILURE;
if(*s)
return FAILURE;
if(u < min || u > max)
return FAILURE;
*value = u;
return SUCCESS;
}
GLOBAL BOOLEAN iswild (path)
REG BYTE *path;
{
while (*path && (*path != '*') && (*path != '?'))
path ++;
return (*path != '\0');
}
GLOBAL BOOLEAN is_filechar(s)
REG BYTE *s;
{
if (*s == 0) return FALSE;
if (is_blank(s) || strchr(invalid_filechar, *s))
return FALSE;
return TRUE;
}
GLOBAL BOOLEAN is_pathchar(s)
REG BYTE *s;
{
if (is_filechar(s) ||
*s == *pathchar ||
*s == '.' ||
*s == ':' ||
(*s >= 'Z'+1 && *s <= 'Z'+6))
return TRUE;
return FALSE;
}
/*
* Copy the file specification from OLDPATH to the buffer NEWPATH
* and return a pointer to the first byte after the extracted name.
* Remove any terminating ':' character from the file specification
* as the FDOS/PCMODE will try to match all characters in the string.
*/
GLOBAL BYTE * get_filename(newpath, oldpath, ambiguous)
REG BYTE *oldpath, *newpath;
BOOLEAN ambiguous;
{
UWORD count = 0;
BYTE *pathname = oldpath;
#if defined(PASSWORD)
while(is_pathchar(oldpath) ||
((*oldpath == *pwdchar) && (is_pathchar(oldpath + 1))) ||
(ambiguous && (*oldpath == '*' || *oldpath == '?'))) {
#else
while(is_pathchar(oldpath) ||
(ambiguous && (*oldpath == '*' || *oldpath == '?'))) {
#endif
if(++count < MAX_PATHLEN) {
*newpath++ = *oldpath;
if(dbcs_lead(*oldpath)) {
*newpath++=*++oldpath;
count++;
}
}
if(*oldpath++ == ':' && count > 2 && !is_pathchar(oldpath)) {
/* Handle the CON:filename */
newpath--; /* so loved by the users of */
break; /* the COPY command. */
}
}
*newpath = '\0'; /* Terminate newpath with \0 */
if(count >= MAX_PATHLEN) {
longjmp(break_env, IA_FILENAME);
}
return oldpath;
}
/*
* Returns the offset of the filename in a correctly formatted
* pathname string.
*/
GLOBAL BYTE * fptr(s)
REG BYTE *s;
{
REG BYTE *tp;
for(tp = s; *s; s++) {
if(dbcs_lead(*s)) {
s++;
continue;
}
if(*s == ':' || *s == *pathchar)
tp = s+1;
}
return(tp);
}
/* repwild replaces the wildcards in the destination filespec with
* the relevant information from the source filespec
* src is an explicit filename
* dest is a filename with wildcards
*
* eg src = fred.lst
* dest = *.txt becomes fred.txt
* dest = ?.* becomes f.lst
* dest = z*.* becomes zred.lst
*
* nb dest must be in a buffer with room for expansion
*/
GLOBAL VOID repwild(src,dest)
REG BYTE *src,*dest;
{
BYTE t[13];
BYTE *temp;
temp=&t[0]; /* ptr to temp array */
if(!iswild(dest)) /* return if not wild */
return;
src = fptr(src); /* point to filename */
if(!*src) /* If a blank filename has been */
return; /* specified then return as an */
/* invalid source specification */
dest = fptr(dest);
strcpy(temp,dest); /* copy wild dest to temp, as dest will get overwritten */
while (*temp) { /* while still more temp to process */
if(*temp=='.') { /* advance src ptr to '.' */
while(*src && *src!='.')
src++;
} /* drop into next check */
if(*src=='.') {
if(*temp=='.') {
*dest=*temp; /* copy '.' */
goto inc;
}
else { /* advance temp to '.' or '\0', copying valid chars to dest */
while(*temp && *temp!='.') {
if(*temp!='*' && *temp!='?') {
*dest=*temp;
dest++;
}
temp++;
}
goto skipinc;
}
}
if(*temp=='*') {
while(*src && *src!='.') { /* copy rest of src till */
*dest=*src; /* src = '.' or '\0' */
dest++;
src++;
}
while(*temp && *temp!='.') /* inc temp past '*' */
temp++;
goto skipinc;
}
if (*temp=='?')
*dest=*src; /* copy src character to dest */
else /* else *temp==normal char */
*dest=*temp; /* copy temp character to dest */
inc:
if(*src) /* dont advance past terminator */
src++;
dest++;
temp++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -