?? instutil.c
字號(hào):
/*===================================================================
FILE : @(#)instutil.c 2.3 - 08/04/99
===================================================================*/
/*===================================================================
PURPOSE: Utility functions.
SYSTEM : RECON II
-------------------------------------------------------------------*/
/*==[ INCLUDES ]=====================================================*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "r2.h"
#include "r2inst.h"
#include "instutil.h"
#include "vb_print.h"
#define good_start(x) (isalpha(x) || (x == '_'))
#define valid(x) (good_start(x) || isdigit(x))
/*==[ PRIVATE FUNCTION DECLARATIONS ]================================*/
char SimpleGet(void);
/*==[ PUBLIC FUNCTION IMPLEMENTATIONS ]==============================*/
/*===================================================================
FUNCTION: GetToken
===================================================================
PURPOSE : Obtains valid tokens delimited by white space. Also
returns last non-alphanumeric character.
CALLS : IsWhiteSpace
GetChar
USED BY : various functions
HISTORY :
VER DATE AUTHOR DESCRIPTION
1.00 6 Feb 93 L. McCallie Created file.
-------------------------------------------------------------------*/
char GetToken(char *Token)
{
static char ch = '\0';
char *TokenPtr = Token;
if (good_start(ch))
while (valid(ch))
{
*(TokenPtr++) = ch;
*TokenPtr = '\0';
ch = GetChar();
}
else
ch = GetChar();
while(IsWhiteSpace(ch)|| isdigit(ch))
ch = GetChar();
if(ch == EOF)
{
ch = '\0';
return(EOF);
}
vb_print(TOKEN_LEVEL,"%d\t\t\tToken: %s\n",gLineNumber,Token);
return(ch);
}
/*===================================================================
FUNCTION: FixBackslash
===================================================================
PURPOSE : Replace backslashes in a file path to "escaped"
backslashes
CALLS : none
USED BY :
HISTORY :
-------------------------------------------------------------------*/
char *FixBackslash(char *cpInputPath)
{
char *cpTemp = cpInputPath;
char TmpStr[MAXPATH];
char *cpTmpStr = TmpStr;
while ('\0' != *cpTemp)
{
if ('\\' == *cpTemp)
*cpTmpStr++ = '\\';
*cpTmpStr++ = *cpTemp++;
}
*cpTmpStr = '\0';
cpTemp = (char *)malloc(strlen(TmpStr)+1);
strcpy(cpTemp,TmpStr);
return(cpTemp);
}
/*===================================================================
FUNCTION: FindEndParen()
===================================================================
PURPOSE : Find the end of the current parenthetical phrase.
CALLS : GetChar
USED BY : various functions
HISTORY :
-------------------------------------------------------------------*/
void FindEndParen(void)
{
char ch;
int ParenState = 1;
while (EOF != (ch = GetChar()))
{
if ('(' == ch)
ParenState++;
if (')' == ch)
{
ParenState--;
if (0 == ParenState)
return; /* return when paren count gets to 0 */
}
}
}
/*===================================================================
FUNCTION: IsWhiteSpace
===================================================================
PURPOSE : Returns TRUE if the character in question is white space.
CALLS : None
USED BY : GetToken
HISTORY :
VER DATE AUTHOR DESCRIPTION
1.00 6 Feb 93 L. McCallie Created file.
-------------------------------------------------------------------*/
int IsWhiteSpace(char ch)
{
char *WhiteSpace = " \n\t\r\f";
int i;
for (i=0;i<5;i++)
if (WhiteSpace[i] == ch)
return(TRUE);
return(FALSE);
}
/*====================================================================
FUNCTION : SplitPath()
PURPOSE : Duplicates the functionality of the DOS only
function fnsplit() except that it is a void
function.
HISTORY :
VER DATE AUTHOR DESCRIPTION
1.01 26 Mar 93 L. Richard Created function.
-------------------------------------------------------------------*/
void SplitPath(
char *path, /* Path to be parsed */
char *drive, /* Drive letter plus ':' */
char *dir, /* Directory with '\' */
char *file, /* Name portion */
char *ext /* Extension plus '.' */
)
{
/* All strings defaulted to null */
char t_drv[ MAXDRIVE ]; /* Drive portion of path */
char t_dir[ MAXDIR ]; /* Directory portion of path */
char t_fil[ MAXFILE ]; /* Name portion of path */
char t_ext[ MAXEXT ]; /* Extension portion of path */
char *temp; /* Temporary string */
t_drv[0] = '\0';
t_dir[0] = '\0';
t_fil[0] = '\0';
t_ext[0] = '\0';
/* Extract drive including ':' */
if (NULL != (temp = strrchr( path, ':' )))
{
strncat( t_drv, path, 2 );
path = ++temp;
}
strcpy( drive, t_drv );
/* Extract complete directory path including '\' */
if (NULL != (temp = strrchr( path, SLASH )))
{
strncat( t_dir, path, (++temp - (char *) path) );
path = temp;
}
strcpy( dir, t_dir );
/* Extract name and extension */
if (NULL == (temp = strrchr( path, '.' )))
strcpy( t_fil, path );
else
{
strncat( t_fil, path, (temp - (char *) path) );
strcpy( t_ext, temp );
}
strcpy( file, t_fil );
strcpy( ext, t_ext );
} /* SplitPath()*/
/*===================================================================
FUNCTION: GetChar
===================================================================
PURPOSE : Obtains the next character of input. Maintains a local
state variable and skips characters which are delimited by comment
delimiters or double quotes. Recognizes, but does not skip,
characters delimited by single quotes.
CALLS : SimpleGet
USED BY : Various functions
-------------------------------------------------------------------*/
char GetChar(void)
{
char ch;
enum STATE{IDLE,SINGLE,DOUBLE,CPP_COMMENT, C_COMMENT} state=IDLE;
short finished = FALSE; /* finished is set TRUE to return the
current character in ch and exit
*/
while((!finished) && ((ch = SimpleGet()) != EOF))
switch(state)
{
case IDLE:
switch(ch)
{
case '\'':
state = SINGLE;
finished = FALSE;
break;
case '"':
state = DOUBLE;
finished = FALSE;
break;
/* -------------- MADE CHANGES TO HANDLE C++ COMMENTS --------------*/
case '/':
if('*' == gHoldChar)
{
ch = SimpleGet(); /* skip to handle slash*slash */
state = C_COMMENT;
finished = FALSE;
}
else if ('/' == gHoldChar)
{
state = CPP_COMMENT;
finished = FALSE;
}
else
{
state = IDLE;
finished = TRUE;
}
break;
/* --------------MADE COMMENT CHANGES -----------------------------*/
default:
state = IDLE;
finished = TRUE;
break;
}
break;
case SINGLE:
if('\\' == ch)
{ /* skip over \x for any x */
ch = SimpleGet();
state = SINGLE;
finished = FALSE;
}
else if(ch == '\'')
{
state = IDLE;
finished = TRUE;
}
else
{
state = SINGLE;
finished = FALSE;
}
break;
case DOUBLE:
if('\\' == ch)
{ /* skip over \x for any x */
ch = SimpleGet();
state = DOUBLE;
finished = FALSE;
}
else if(ch == '"')
{
state = IDLE;
finished = TRUE; /* return the '"' */
}
else
{
state = DOUBLE;
finished = FALSE;
}
break;
/* --------------------- COMMENT CHANGES ---------------------------*/
/* Below changes made to distinguish between C and C++ comments */
case C_COMMENT:
if(('*' == ch) && ('/' == gHoldChar))
{
ch = SimpleGet(); /* skip the * and slash */
ch = ' '; /* return a blank */
state = IDLE;
finished = TRUE;
}
else
{
state = C_COMMENT;
finished = FALSE;
}
break;
case CPP_COMMENT:
if ('\n' == gHoldChar)
{
state = IDLE;
finished = TRUE;
ch = ' ';
}
/* -------------------------- ^^^^^ COMMENT CHANGES ^^^^^ -------------*/
} /* switch and while */
return(ch);
} /* GetChar()*/
/*===================================================================
FUNCTION: SkipPreprocessor
===================================================================
PURPOSE : Skips characters that are part of a preprocessor
directive.
CALLS : None
USED BY : GetFunction
HISTORY :
VER DATE AUTHOR DESCRIPTION
1.00 9 Mar 99 D. Fralish Created function.
-------------------------------------------------------------------*/
char SkipPreprocessor(char *Token)
{
char ch;
char LastNonWhiteSpaceChar = ' ';
char *TokenPtr = Token;
short finished = FALSE;
ch = SimpleGet();
while(IsWhiteSpace(ch)|| isdigit(ch))
{
ch = SimpleGet();
}
while (valid(ch))
{
*(TokenPtr++) = ch;
*TokenPtr = '\0';
ch = SimpleGet();
}
while((!finished) && ((ch = SimpleGet()) != EOF))
{
if (!IsWhiteSpace(ch))
{
LastNonWhiteSpaceChar = ch;
}
if ('\n' == gHoldChar && '\\' != LastNonWhiteSpaceChar)
{
finished = TRUE;
}
}
return(ch);
}
/*==[ PRIVATE FUNCTION IMPLEMENTATIONS ]=============================*/
/*===================================================================
FUNCTION: SimpleGet
===================================================================
PURPOSE : Obtains the next character from the source file and
writes the previous character read to the output file. Returns
the last character written. Maintains the last character read as a
one character look-ahead in global character variable gHholdChar.
Also maintains the global integer variable gLineNumber.
CALLS : None
USED BY : GetChar
-------------------------------------------------------------------*/
char SimpleGet(void)
{
char ch;
if (EOF == gHoldChar)
gHoldChar = fgetc(gSrcFILE);
ch = gHoldChar;
if ('\n' == ch)
gLineNumber++;
if (EOF != ch)
{
fputc(gHoldChar, gInstFILE);
gHoldChar = fgetc(gSrcFILE);
}
return(ch);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -