Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@
fix -I, take precedence over ADMS_INCLUDEDIR
allow semicolon after identifier in disciple/nature declaration
add basic support for escaped identifiers
resolve include directives relative to each file
85 changes: 85 additions & 0 deletions admsXml/preprocessorLex.l
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,81 @@ FILE *adms_preprocessor_getfile_output (void)

#define tkreturn(token) {pproot()->cr_scanner->cur_char_position+=yyleng; return token;}

/* examples: /a/b => \0,a,b and a/b/ => a,b,\0*/
static p_slist adms_split_new (const char* myname)
{
p_slist mypath=NULL;
const char* sj=myname;
const char* si=myname;
while(*sj!='\0')
{
if((*sj=='/')||(*sj=='\\'))
{
if(si==sj)
adms_slist_push(&mypath,NULL);
else
adms_slist_push(&mypath,(p_adms)adms_m2nclone(si,sj));
si=sj+1;
}
sj++;
}
adms_slist_push(&mypath,(p_adms)adms_m2nclone(si,sj));
return adms_slist_reverse(mypath);
}
static void free_strlist (p_slist myli0)
{
p_slist myli;
for(myli=myli0;myli;myli=myli->next)
free(myli->data);
adms_slist_free(myli0);
}
static char* dirname (const char* myname)
{
p_slist myli0=adms_split_new(myname);
char* mydirname=NULL;
p_slist myli=myli0;
int first=1;
#if defined(ADMS_OS_MS)
if((myli->data==NULL)&&myli->next&&(!strcmp((char*)(myli->next->data),"cygdrive")))
{
myli=myli->next->next;
if(myli)
{
adms_k2strconcat(&mydirname,(char*)(myli->data));
adms_k2strconcat(&mydirname,":/");
myli=myli->next;
}
else
adms_k2strconcat(&mydirname,ADMS_PATH_SEPARATOR);
}
#endif
for(;myli;myli=myli->next,first=0)
{
if(myli->data==NULL)
adms_k2strconcat(&mydirname,ADMS_PATH_SEPARATOR);
else if(myli->next==NULL)
{
if(!strcmp((char*)(myli->data),".")||!strcmp((char*)(myli->data),".."))
{
if(!first)
adms_k2strconcat(&mydirname,ADMS_PATH_SEPARATOR);
adms_k2strconcat(&mydirname,(char*)(myli->data));
}
}
else
{
adms_k2strconcat(&mydirname,(char*)(myli->data));
if(myli->next->next)
adms_k2strconcat(&mydirname,ADMS_PATH_SEPARATOR);
}
}
free_strlist(myli0);
if(mydirname)
return mydirname;
else
return adms_kclone(".");
}

static char* adms_preprocessor_lex_remove_leading_quote (char* name)
{
char* unquoted_name;
Expand Down Expand Up @@ -133,12 +208,20 @@ static void adms_preprocessor_lex_include_file (char* fileName)
FILE*myfh;
p_preprocessor scanner;
char*message=NULL;
char*mydir=NULL;
p_slist l; for(l=pproot()->Scanner;l;l=l->next)
{
adms_k2strconcat(&mydir,dirname(((p_preprocessor)l->data)->filename));
adms_k2strconcat(&mydir,ADMS_PATH_SEPARATOR);
}
adms_k2strconcat(&mydir,dirname(pproot()->cr_scanner->filename));
adms_k2strconcat(&message,pproot()->cr_scanner->filename);
adms_k2strconcat(&message,":");
adms_strconcat(&message,adms_integertostring(adms_preprocessor_get_line_position (pproot()->cr_scanner, 0)));
if(pproot()->cr_filename)
free(pproot()->cr_filename);
pproot()->cr_filename=strdup(fileName);
adms_slist_push(&pproot()->includePath,(p_adms)mydir);
if(!(myfh=adms_file_open_read_with_path(fileName,(p_slist)(pproot()->includePath))))
{
if(!strcmp(fileName,"discipline.h")||!strcmp(fileName,"disciplines.h")||!strcmp(fileName,"discipline.vams")||!strcmp(fileName,"disciplines.vams"))
Expand All @@ -161,6 +244,7 @@ static void adms_preprocessor_lex_include_file (char* fileName)
else
adms_message_fatal(("[%s]: failed to open file ... '%s'\n",message,fileName))
}
adms_slist_pull(&pproot()->includePath);
scanner=(p_preprocessor)malloc(sizeof(t_preprocessor));
adms_message_verbose(("include file '%s'\n",fileName))
scanner->buffer=NULL;
Expand All @@ -182,6 +266,7 @@ static void adms_preprocessor_lex_include_file (char* fileName)
adms_k2strconcat(&preprocessorlval.mystr,"\"\n");
BEGIN( INITIAL );
free(message);
free(mydir);
}

static char *adms_preprocessor_lex_skipp_text ()
Expand Down