mirror of
https://github.com/ZDoom/acc.git
synced 2025-02-17 00:51:26 +00:00
- Added CodeImp's submission for specifying include paths to ACC.
SVN r1292 (trunk)
This commit is contained in:
parent
9bf49aace6
commit
d310c2c361
8 changed files with 155 additions and 41 deletions
71
acc.c
71
acc.c
|
@ -127,6 +127,7 @@ static void DisplayBanner(void)
|
||||||
fprintf(stderr, "Even more changes by James Bentler\n");
|
fprintf(stderr, "Even more changes by James Bentler\n");
|
||||||
fprintf(stderr, "Some additions by Michael \"Necromage\" Weber\n");
|
fprintf(stderr, "Some additions by Michael \"Necromage\" Weber\n");
|
||||||
fprintf(stderr, "Error reporting improvements and limit expansion by Ty Halderman\n");
|
fprintf(stderr, "Error reporting improvements and limit expansion by Ty Halderman\n");
|
||||||
|
fprintf(stderr, "Include paths added by Pascal vd Heiden\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -158,21 +159,25 @@ static void Init(void)
|
||||||
//
|
//
|
||||||
// ProcessArgs
|
// ProcessArgs
|
||||||
//
|
//
|
||||||
|
// Pascal 12/11/08
|
||||||
|
// Allowing space after options (option parameter as the next argument)
|
||||||
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static void ProcessArgs(void)
|
static void ProcessArgs(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i = 1;
|
||||||
int count;
|
int count = 0;
|
||||||
char *text;
|
char *text;
|
||||||
char option;
|
char option;
|
||||||
|
|
||||||
count = 0;
|
while(i < ArgCount)
|
||||||
for(i = 1; i < ArgCount; i++)
|
|
||||||
{
|
{
|
||||||
text = ArgVector[i];
|
text = ArgVector[i];
|
||||||
|
|
||||||
if(*text == '-')
|
if(*text == '-')
|
||||||
{
|
{
|
||||||
|
// Option
|
||||||
text++;
|
text++;
|
||||||
if(*text == 0)
|
if(*text == 0)
|
||||||
{
|
{
|
||||||
|
@ -181,44 +186,63 @@ static void ProcessArgs(void)
|
||||||
option = toupper(*text++);
|
option = toupper(*text++);
|
||||||
switch(option)
|
switch(option)
|
||||||
{
|
{
|
||||||
|
case 'I':
|
||||||
|
if((i + 1) < ArgCount)
|
||||||
|
{
|
||||||
|
TK_AddIncludePath(ArgVector[++i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
acs_DebugMode = YES;
|
acs_DebugMode = YES;
|
||||||
acs_VerboseMode = YES;
|
acs_VerboseMode = YES;
|
||||||
if(*text != 0)
|
if((i + 1) < ArgCount)
|
||||||
{
|
{
|
||||||
OpenDebugFile(text);
|
OpenDebugFile(ArgVector[++i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'H':
|
case 'H':
|
||||||
pc_NoShrink = TRUE;
|
pc_NoShrink = TRUE;
|
||||||
pc_HexenCase = TRUE;
|
pc_HexenCase = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DisplayUsage();
|
DisplayUsage();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
count++;
|
else
|
||||||
switch(count)
|
|
||||||
{
|
{
|
||||||
case 1:
|
// Input/output file
|
||||||
strcpy(acs_SourceFileName, text);
|
count++;
|
||||||
MS_SuggestFileExt(acs_SourceFileName, ".acs");
|
switch(count)
|
||||||
break;
|
{
|
||||||
case 2:
|
case 1:
|
||||||
strcpy(ObjectFileName, text);
|
strcpy(acs_SourceFileName, text);
|
||||||
MS_SuggestFileExt(ObjectFileName, ".o");
|
MS_SuggestFileExt(acs_SourceFileName, ".acs");
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
DisplayUsage();
|
case 2:
|
||||||
break;
|
strcpy(ObjectFileName, text);
|
||||||
|
MS_SuggestFileExt(ObjectFileName, ".o");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
DisplayUsage();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next arg
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count == 0)
|
if(count == 0)
|
||||||
{
|
{
|
||||||
DisplayUsage();
|
DisplayUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count == 1)
|
if(count == 1)
|
||||||
{
|
{
|
||||||
strcpy(ObjectFileName, acs_SourceFileName);
|
strcpy(ObjectFileName, acs_SourceFileName);
|
||||||
|
@ -236,8 +260,9 @@ static void ProcessArgs(void)
|
||||||
static void DisplayUsage(void)
|
static void DisplayUsage(void)
|
||||||
{
|
{
|
||||||
puts("\nUsage: ACC [options] source[.acs] [object[.o]]\n");
|
puts("\nUsage: ACC [options] source[.acs] [object[.o]]\n");
|
||||||
puts("-d[file] Output debugging information");
|
puts("-i [path] Add include path to find include files");
|
||||||
puts("-h Create pcode compatible with Hexen and old ZDooms");
|
puts("-d [file] Output debugging information");
|
||||||
|
puts("-h Create pcode compatible with Hexen and old ZDooms");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
common.h
4
common.h
|
@ -56,6 +56,10 @@
|
||||||
|
|
||||||
#define MAX_IMPORTS 256
|
#define MAX_IMPORTS 256
|
||||||
|
|
||||||
|
// Max number of include paths the user can specify
|
||||||
|
// This includes the "working directory"!
|
||||||
|
#define MAX_INCLUDE_PATHS 16
|
||||||
|
|
||||||
// Maximum number of translations that can be used
|
// Maximum number of translations that can be used
|
||||||
#define MAX_TRANSLATIONS 32
|
#define MAX_TRANSLATIONS 32
|
||||||
|
|
||||||
|
|
1
error.c
1
error.c
|
@ -175,6 +175,7 @@ static struct
|
||||||
{ ERR_DISCONNECT_NEEDS_1_ARG, "Disconnect scripts must have 1 argument." },
|
{ ERR_DISCONNECT_NEEDS_1_ARG, "Disconnect scripts must have 1 argument." },
|
||||||
{ ERR_UNCLOSED_WITH_ARGS, "Most special scripts must not have arguments." },
|
{ ERR_UNCLOSED_WITH_ARGS, "Most special scripts must not have arguments." },
|
||||||
{ ERR_NOT_A_CHAR_ARRAY, "%s has %d dimensions. Use %d subscripts to get a char array." },
|
{ ERR_NOT_A_CHAR_ARRAY, "%s has %d dimensions. Use %d subscripts to get a char array." },
|
||||||
|
{ ERR_CANT_FIND_INCLUDE, "Couldn't find include file \"%s\"." },
|
||||||
{ ERR_NONE, NULL }
|
{ ERR_NONE, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
3
error.h
3
error.h
|
@ -142,7 +142,8 @@ typedef enum
|
||||||
ERR_NEED_ARRAY_SIZE,
|
ERR_NEED_ARRAY_SIZE,
|
||||||
ERR_DISCONNECT_NEEDS_1_ARG,
|
ERR_DISCONNECT_NEEDS_1_ARG,
|
||||||
ERR_UNCLOSED_WITH_ARGS,
|
ERR_UNCLOSED_WITH_ARGS,
|
||||||
ERR_NOT_A_CHAR_ARRAY
|
ERR_NOT_A_CHAR_ARRAY,
|
||||||
|
ERR_CANT_FIND_INCLUDE
|
||||||
} error_t;
|
} error_t;
|
||||||
|
|
||||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||||
|
|
16
misc.c
16
misc.c
|
@ -171,6 +171,22 @@ int MS_LoadFile(char *name, char **buffer)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// MS_FileExists
|
||||||
|
//
|
||||||
|
// Pascal 21/11/08
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
boolean MS_FileExists(char *name)
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
int ret = stat(name, &info);
|
||||||
|
return (ret == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// MS_SaveFile
|
// MS_SaveFile
|
||||||
|
|
1
misc.h
1
misc.h
|
@ -35,6 +35,7 @@ U_WORD MS_LittleUWORD(U_WORD val);
|
||||||
// U_LONG MS_LittleULONG(U_LONG val);
|
// U_LONG MS_LittleULONG(U_LONG val);
|
||||||
U_INT MS_LittleUINT(U_INT val);
|
U_INT MS_LittleUINT(U_INT val);
|
||||||
int MS_LoadFile(char *name, char **buffer);
|
int MS_LoadFile(char *name, char **buffer);
|
||||||
|
boolean MS_FileExists(char *name);
|
||||||
boolean MS_SaveFile(char *name, void *buffer, int length);
|
boolean MS_SaveFile(char *name, void *buffer, int length);
|
||||||
int MS_StrCmp(char *s1, char *s2);
|
int MS_StrCmp(char *s1, char *s2);
|
||||||
char *MS_StrLwr(char *string);
|
char *MS_StrLwr(char *string);
|
||||||
|
|
99
token.c
99
token.c
|
@ -62,7 +62,7 @@ typedef struct
|
||||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||||
|
|
||||||
static int SortKeywords(const void *a, const void *b);
|
static int SortKeywords(const void *a, const void *b);
|
||||||
static void MakeIncludePath(char *sourceName);
|
static void SetLocalIncludePath(char *sourceName);
|
||||||
static int PopNestedSource(enum ImportModes *prevMode);
|
static int PopNestedSource(enum ImportModes *prevMode);
|
||||||
static void ProcessLetterToken(void);
|
static void ProcessLetterToken(void);
|
||||||
static void ProcessNumberToken(void);
|
static void ProcessNumberToken(void);
|
||||||
|
@ -114,10 +114,15 @@ static nestInfo_t OpenFiles[MAX_NESTED_SOURCES];
|
||||||
static boolean AlreadyGot;
|
static boolean AlreadyGot;
|
||||||
static int NestDepth;
|
static int NestDepth;
|
||||||
static boolean IncLineNumber;
|
static boolean IncLineNumber;
|
||||||
static char IncludePath[MAX_FILE_NAME_LENGTH];
|
|
||||||
static char *FileNames;
|
static char *FileNames;
|
||||||
static size_t FileNamesLen, FileNamesMax;
|
static size_t FileNamesLen, FileNamesMax;
|
||||||
|
|
||||||
|
// Pascal 11/12/08
|
||||||
|
// Include paths. Lowest is searched first.
|
||||||
|
// Include path 0 is always set to the directory of the file being parsed.
|
||||||
|
static char IncludePaths[MAX_INCLUDE_PATHS][MAX_FILE_NAME_LENGTH];
|
||||||
|
static int NumIncludePaths;
|
||||||
|
|
||||||
static struct keyword_s
|
static struct keyword_s
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -229,6 +234,7 @@ void TK_Init(void)
|
||||||
tk_String = TokenStringBuffer;
|
tk_String = TokenStringBuffer;
|
||||||
IncLineNumber = FALSE;
|
IncLineNumber = FALSE;
|
||||||
tk_IncludedLines = 0;
|
tk_IncludedLines = 0;
|
||||||
|
NumIncludePaths = 1; // the first path is always the parsed file path - Pascal 12/11/08
|
||||||
SourceOpen = FALSE;
|
SourceOpen = FALSE;
|
||||||
*MasterSourceLine = '\0'; // master line - Ty 07jan2000
|
*MasterSourceLine = '\0'; // master line - Ty 07jan2000
|
||||||
MasterSourcePos = 0; // master position - Ty 07jan2000
|
MasterSourcePos = 0; // master position - Ty 07jan2000
|
||||||
|
@ -264,7 +270,7 @@ void TK_OpenSource(char *fileName)
|
||||||
TK_CloseSource();
|
TK_CloseSource();
|
||||||
size = MS_LoadFile(fileName, &FileStart);
|
size = MS_LoadFile(fileName, &FileStart);
|
||||||
tk_SourceName = AddFileName(fileName);
|
tk_SourceName = AddFileName(fileName);
|
||||||
MakeIncludePath(fileName);
|
SetLocalIncludePath(fileName);
|
||||||
SourceOpen = TRUE;
|
SourceOpen = TRUE;
|
||||||
FileEnd = FileStart+size;
|
FileEnd = FileStart+size;
|
||||||
FilePtr = FileStart;
|
FilePtr = FileStart;
|
||||||
|
@ -299,23 +305,55 @@ static char *AddFileName(const char *name)
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// MakeIncludePath
|
// AddIncludePath
|
||||||
|
// This adds an include path with less priority than the ones already added
|
||||||
|
//
|
||||||
|
// Pascal 11/12/08
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static void MakeIncludePath(char *sourceName)
|
void TK_AddIncludePath(char *sourcePath)
|
||||||
{
|
{
|
||||||
strcpy(IncludePath, sourceName);
|
if(NumIncludePaths < MAX_INCLUDE_PATHS)
|
||||||
if(MS_StripFilename(IncludePath) == NO)
|
|
||||||
{
|
{
|
||||||
IncludePath[0] = 0;
|
// Add to list
|
||||||
}
|
strcpy(IncludePaths[NumIncludePaths], sourcePath);
|
||||||
else
|
|
||||||
{ // Add a directory delimiter to the include path
|
// Not ending with directory delimiter?
|
||||||
strcat(IncludePath, DIRECTORY_DELIMITER);
|
if((IncludePaths[NumIncludePaths] + strlen(IncludePaths[NumIncludePaths]) - 1) != DIRECTORY_DELIMITER_CHAR)
|
||||||
|
{
|
||||||
|
// Add a directory delimiter to the include path
|
||||||
|
strcat(IncludePaths[NumIncludePaths], DIRECTORY_DELIMITER);
|
||||||
|
}
|
||||||
|
NumIncludePaths++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// SetLocalIncludePath
|
||||||
|
// This sets the first include path
|
||||||
|
//
|
||||||
|
// Pascal 11/12/08
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
static void SetLocalIncludePath(char *sourceName)
|
||||||
|
{
|
||||||
|
strcpy(IncludePaths[0], sourceName);
|
||||||
|
if(MS_StripFilename(IncludePaths[0]) == NO)
|
||||||
|
{
|
||||||
|
IncludePaths[0][0] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Add a directory delimiter to the include path
|
||||||
|
strcat(IncludePaths[0], DIRECTORY_DELIMITER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// TK_Include
|
// TK_Include
|
||||||
|
@ -325,9 +363,10 @@ static void MakeIncludePath(char *sourceName)
|
||||||
void TK_Include(char *fileName)
|
void TK_Include(char *fileName)
|
||||||
{
|
{
|
||||||
char sourceName[MAX_FILE_NAME_LENGTH];
|
char sourceName[MAX_FILE_NAME_LENGTH];
|
||||||
int size;
|
int size, i;
|
||||||
nestInfo_t *info;
|
nestInfo_t *info;
|
||||||
|
boolean foundfile = FALSE;
|
||||||
|
|
||||||
MS_Message(MSG_DEBUG, "*Including %s\n", fileName);
|
MS_Message(MSG_DEBUG, "*Including %s\n", fileName);
|
||||||
if(NestDepth == MAX_NESTED_SOURCES)
|
if(NestDepth == MAX_NESTED_SOURCES)
|
||||||
{
|
{
|
||||||
|
@ -342,8 +381,29 @@ void TK_Include(char *fileName)
|
||||||
info->incLineNumber = IncLineNumber;
|
info->incLineNumber = IncLineNumber;
|
||||||
info->lastChar = Chr;
|
info->lastChar = Chr;
|
||||||
info->imported = NO;
|
info->imported = NO;
|
||||||
strcpy(sourceName, IncludePath);
|
|
||||||
strcat(sourceName, fileName);
|
// Pascal 11/12/08
|
||||||
|
// Find the file in the include paths
|
||||||
|
for(i = 0; i < NumIncludePaths; i++)
|
||||||
|
{
|
||||||
|
strcpy(sourceName, IncludePaths[i]);
|
||||||
|
strcat(sourceName, fileName);
|
||||||
|
if(MS_FileExists(sourceName))
|
||||||
|
{
|
||||||
|
foundfile = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!foundfile)
|
||||||
|
{
|
||||||
|
ERR_ErrorAt(tk_SourceName, tk_Line);
|
||||||
|
ERR_Exit(ERR_CANT_FIND_INCLUDE, YES, fileName, tk_SourceName, tk_Line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now change the first include path to the file directory
|
||||||
|
SetLocalIncludePath(sourceName);
|
||||||
|
|
||||||
tk_SourceName = AddFileName(sourceName);
|
tk_SourceName = AddFileName(sourceName);
|
||||||
size = MS_LoadFile(tk_SourceName, &FileStart);
|
size = MS_LoadFile(tk_SourceName, &FileStart);
|
||||||
FileEnd = FileStart+size;
|
FileEnd = FileStart+size;
|
||||||
|
@ -379,7 +439,7 @@ void TK_Import(char *fileName, enum ImportModes prevMode)
|
||||||
static int PopNestedSource(enum ImportModes *prevMode)
|
static int PopNestedSource(enum ImportModes *prevMode)
|
||||||
{
|
{
|
||||||
nestInfo_t *info;
|
nestInfo_t *info;
|
||||||
|
|
||||||
MS_Message(MSG_DEBUG, "*Leaving %s\n", tk_SourceName);
|
MS_Message(MSG_DEBUG, "*Leaving %s\n", tk_SourceName);
|
||||||
free(FileStart);
|
free(FileStart);
|
||||||
SY_FreeConstants(NestDepth);
|
SY_FreeConstants(NestDepth);
|
||||||
|
@ -394,6 +454,11 @@ static int PopNestedSource(enum ImportModes *prevMode)
|
||||||
Chr = info->lastChar;
|
Chr = info->lastChar;
|
||||||
tk_Token = TK_NONE;
|
tk_Token = TK_NONE;
|
||||||
AlreadyGot = FALSE;
|
AlreadyGot = FALSE;
|
||||||
|
|
||||||
|
// Pascal 11/12/08
|
||||||
|
// Set the first include path back to this file directory
|
||||||
|
SetLocalIncludePath(tk_SourceName);
|
||||||
|
|
||||||
*prevMode = info->prevMode;
|
*prevMode = info->prevMode;
|
||||||
return info->imported ? 2 : 0;
|
return info->imported ? 2 : 0;
|
||||||
}
|
}
|
||||||
|
|
1
token.h
1
token.h
|
@ -146,6 +146,7 @@ void TK_Undo(void);
|
||||||
void TK_SkipLine(void);
|
void TK_SkipLine(void);
|
||||||
void TK_SkipPast(tokenType_t token);
|
void TK_SkipPast(tokenType_t token);
|
||||||
void TK_SkipTo(tokenType_t token);
|
void TK_SkipTo(tokenType_t token);
|
||||||
|
void TK_AddIncludePath(char *sourceName);
|
||||||
|
|
||||||
// PUBLIC DATA DECLARATIONS ------------------------------------------------
|
// PUBLIC DATA DECLARATIONS ------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue