Updating preprocessor files

This commit is contained in:
Alexander S.Kresin
1999-06-15 19:12:24 +00:00
parent 660be190e7
commit a3096c9aab
3 changed files with 120 additions and 19 deletions

View File

@@ -16,6 +16,12 @@ typedef long LONG;
typedef unsigned long ULONG;
#define PATH_DELIMITER "/\\"
#define IS_PATH_SEP( c ) (strchr(PATH_DELIMITER, (c))!=NULL)
#define OPT_DELIMITER "/-"
#define IS_OPT_SEP( c ) (strchr(OPT_DELIMITER, (c))!=NULL)
typedef struct _PATHNAMES { /* the list of pathnames to search with #include */
char *szPath;
struct _PATHNAMES *pNext;
} PATHNAMES;
#ifndef _POSIX_PATH_MAX
#define _POSIX_PATH_MAX 255
#endif

View File

@@ -58,6 +58,7 @@ int strotrim ( char* );
char* strodup ( char * );
int NextWord ( char**, char*, int);
int NextName ( char**, char*, char**);
int Include( char *, PATHNAMES *, FILE** );
#define isname(c) (isalnum(c) || c=='_' || (c) > 0x7e)
#define SKIPTABSPACES(sptr) while ( *sptr == ' ' || *sptr == '\t' ) (sptr)++
@@ -90,6 +91,7 @@ int nline=0;
int Repeate;
char groupchar;
extern PATHNAMES *_pIncludePath;
extern DEFINES aDefines[] ;
extern int koldef;
DEFINES *aDefnew ;
@@ -134,9 +136,9 @@ int ParseDirective( char* sLine )
if ( *(sLine+i) != '\"' ) return 1000;
*(sLine+i) = '\0';
if ((handl_i = fopen(sLine, "r")) == NULL)
// if ((handl_i = fopen(sLine, "r")) == NULL)
if ( !OpenInclude( sLine, _pIncludePath, &handl_i ) )
{ printf("\nCan't open %s",sLine); return 1001; }
lInclude++;
Hp_Parse(handl_i, 0 );
lInclude--;
@@ -1400,3 +1402,33 @@ int NextName ( char** sSource, char* sDest, char **sOut )
*sDest = '\0';
return i;
}
int OpenInclude( char * szFileName, PATHNAMES *pSearch, FILE** fptr )
{
if( ! ( *fptr = fopen( szFileName, "r" ) ) )
{
if( pSearch )
{
FILENAME *pFileName =SplitFilename( szFileName );
char szFName[ _POSIX_PATH_MAX ]; /* filename to parse */
pFileName->name =szFileName;
pFileName->extension =NULL;
while( pSearch && !*fptr )
{
pFileName->path =pSearch->szPath;
MakeFilename( szFName, pFileName );
if( ! ( *fptr = fopen( szFName, "r" ) ) )
{
pSearch = pSearch->pNext;
if( ! pSearch )
return 0;
}
}
_xfree( pFileName );
}
else
return 0;
}
return 1;
}

View File

@@ -33,33 +33,74 @@ extern DEFINES *aDefnew ;
extern COMMANDS *aCommnew ;
extern TRANSLATES *aTranslates ;
PATHNAMES *_pIncludePath = NULL;
void AddSearchPath( char *, PATHNAMES * * ); /* add pathname to a search list */
int main (int argc,char* argv[])
{
FILE *handl_i,*handl_o;
char szFileName[ _POSIX_PATH_MAX ];
FILENAME *pFileName =NULL;
int iArg = 1;
if(argc<2) { printf("File name absent"); return 1; }
pFileName =SplitFilename( argv[1] );
if( !pFileName->extension )
pFileName->extension =".prg";
MakeFilename( szFileName, pFileName );
while( iArg < argc )
{
if( IS_OPT_SEP(argv[ iArg ][ 0 ]))
{
switch( argv[ iArg ][ 1 ] )
{
case 'd':
case 'D': /* defines a Lex #define from the command line */
{
unsigned int i = 0;
char * szDefText = strdup( argv[ iArg ] + 2 );
while( i < strolen( szDefText ) && szDefText[ i ] != '=' )
i++;
if( szDefText[ i ] != '=' )
AddDefine( szDefText, 0 );
else
{
szDefText[ i ] = 0;
AddDefine( szDefText, szDefText + i + 1 );
}
free( szDefText );
}
break;
case 'i':
case 'I':
AddSearchPath( argv[ iArg ]+2, &_pIncludePath );
break;
default:
printf( "Invalid command line option: %s\n", &argv[ iArg ][ 1 ] );
break;
}
}
else pFileName =SplitFilename( argv[ iArg ] );
iArg++;
}
if( pFileName )
{
if( !pFileName->extension ) pFileName->extension =".prg";
MakeFilename( szFileName, pFileName );
if ((handl_i = fopen(szFileName, "r")) == NULL)
{ printf("Can't open %s",szFileName); return 1; }
if ((handl_i = fopen(szFileName, "r")) == NULL)
{ printf("Can't open %s",szFileName); return 1; }
}
else { printf("File name absent"); return 1; }
pFileName->extension =".ppo";
MakeFilename( szFileName, pFileName );
if ((handl_o = fopen(szFileName, "wt" )) == NULL)
{ printf("Can't open %s",szFileName); return 1; }
pFileName->extension =".ppo";
MakeFilename( szFileName, pFileName );
aCondCompile = (int*) _xgrab( sizeof(int) * 5 );
aDefnew = ( DEFINES * ) _xgrab( sizeof(DEFINES) * 50 );
aCommnew = ( COMMANDS * ) _xgrab( sizeof(COMMANDS) * INITIAL_ACOM_SIZE );
aTranslates = ( TRANSLATES * ) _xgrab( sizeof(TRANSLATES) * 50 );
if ((handl_o = fopen(szFileName, "wt" )) == NULL)
{ printf("Can't open %s",szFileName); return 1; }
Hp_Parse(handl_i,handl_o );
fclose(handl_i); fclose(handl_o);
aCondCompile = (int*) _xgrab( sizeof(int) * 5 );
aDefnew = ( DEFINES * ) _xgrab( sizeof(DEFINES) * 50 );
aCommnew = ( COMMANDS * ) _xgrab( sizeof(COMMANDS) * INITIAL_ACOM_SIZE );
aTranslates = ( TRANSLATES * ) _xgrab( sizeof(TRANSLATES) * 50 );
Hp_Parse(handl_i,handl_o );
fclose(handl_i); fclose(handl_o);
/*
for (int i=0;i<kolcommands;i++)
{
@@ -244,6 +285,28 @@ char *MakeFilename( char *szFileName, FILENAME *pFileName )
return szFileName;
}
/*
* Function that adds specified path to the list of pathnames to search
*/
void AddSearchPath( char *szPath, PATHNAMES * *pSearchList )
{
PATHNAMES *pPath = *pSearchList;
if( pPath )
{
while( pPath->pNext )
pPath = pPath->pNext;
pPath->pNext = ( PATHNAMES * ) OurMalloc( sizeof( PATHNAMES ) );
pPath = pPath->pNext;
}
else
{
*pSearchList =pPath =(PATHNAMES *)OurMalloc( sizeof(PATHNAMES) );
}
pPath->pNext = NULL;
pPath->szPath = szPath;
}
void * OurMalloc( LONG lSize )
{
void * pMem = malloc( lSize );