Run `indent' on the whole tree

Can't indent the .y files yet, they need special treatment.

Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
Vegard Nossum
2009-06-11 07:59:46 +02:00
parent 660f5daac3
commit b6c749ffbd
47 changed files with 5105 additions and 5495 deletions

View File

@@ -21,21 +21,21 @@
*
*/
struct sContext *pFileStack;
struct sSymbol *pCurrentMacro;
YY_BUFFER_STATE CurrentFlexHandle;
FILE *pCurrentFile;
ULONG nCurrentStatus;
char tzCurrentFileName[_MAX_PATH + 1];
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
SLONG NextIncPath = 0;
ULONG nMacroCount;
struct sContext *pFileStack;
struct sSymbol *pCurrentMacro;
YY_BUFFER_STATE CurrentFlexHandle;
FILE *pCurrentFile;
ULONG nCurrentStatus;
char tzCurrentFileName[_MAX_PATH + 1];
char IncludePaths[MAXINCPATHS][_MAX_PATH + 1];
SLONG NextIncPath = 0;
ULONG nMacroCount;
char *pCurrentREPTBlock;
ULONG nCurrentREPTBlockSize;
ULONG nCurrentREPTBlockCount;
char *pCurrentREPTBlock;
ULONG nCurrentREPTBlockSize;
ULONG nCurrentREPTBlockCount;
ULONG ulMacroReturnValue;
ULONG ulMacroReturnValue;
/*
* defines for nCurrentStatus
@@ -45,18 +45,17 @@ ULONG ulMacroReturnValue;
#define STAT_isMacroArg 2
#define STAT_isREPTBlock 3
ULONG filesize (char *s)
ULONG filesize(char *s)
{
FILE *f;
ULONG size = 0;
FILE *f;
ULONG size = 0;
if( (f=fopen(s,"rt"))!=NULL )
{
fseek (f, 0, SEEK_END);
size = ftell (f);
fclose (f);
}
return (size);
if ((f = fopen(s, "rt")) != NULL) {
fseek(f, 0, SEEK_END);
size = ftell(f);
fclose(f);
}
return (size);
}
/*
@@ -66,115 +65,110 @@ ULONG filesize (char *s)
*
*/
void pushcontext (void)
void pushcontext(void)
{
struct sContext **ppFileStack;
struct sContext **ppFileStack;
ppFileStack = &pFileStack;
while (*ppFileStack)
ppFileStack = &((*ppFileStack)->pNext);
ppFileStack = &pFileStack;
while (*ppFileStack)
ppFileStack = &((*ppFileStack)->pNext);
if( (*ppFileStack=(struct sContext *)malloc(sizeof (struct sContext)))!=NULL )
{
if ((*ppFileStack =
(struct sContext *)malloc(sizeof(struct sContext))) != NULL) {
(*ppFileStack)->FlexHandle = CurrentFlexHandle;
(*ppFileStack)->pNext = NULL;
strcpy ( (char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
strcpy((char *)(*ppFileStack)->tzFileName,
(char *)tzCurrentFileName);
(*ppFileStack)->nLine = nLineNo;
switch ((*ppFileStack)->nStatus = nCurrentStatus)
{
case STAT_isMacroArg:
case STAT_isMacro:
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pMacro = pCurrentMacro;
break;
case STAT_isInclude:
(*ppFileStack)->pFile = pCurrentFile;
break;
case STAT_isREPTBlock:
sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
break;
switch ((*ppFileStack)->nStatus = nCurrentStatus) {
case STAT_isMacroArg:
case STAT_isMacro:
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pMacro = pCurrentMacro;
break;
case STAT_isInclude:
(*ppFileStack)->pFile = pCurrentFile;
break;
case STAT_isREPTBlock:
sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
(*ppFileStack)->nREPTBlockCount =
nCurrentREPTBlockCount;
break;
}
nLineNo = 0;
}
else
fatalerror ("No memory for context");
} else
fatalerror("No memory for context");
}
int popcontext (void)
int popcontext(void)
{
struct sContext *pLastFile,
**ppLastFile;
struct sContext *pLastFile, **ppLastFile;
if (nCurrentStatus == STAT_isREPTBlock)
{
if (--nCurrentREPTBlockCount)
{
yy_delete_buffer (CurrentFlexHandle);
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer (CurrentFlexHandle);
sym_UseCurrentMacroArgs ();
sym_SetMacroArgID (nMacroCount++);
sym_UseNewMacroArgs ();
return (0);
if (nCurrentStatus == STAT_isREPTBlock) {
if (--nCurrentREPTBlockCount) {
yy_delete_buffer(CurrentFlexHandle);
CurrentFlexHandle =
yy_scan_bytes(pCurrentREPTBlock,
nCurrentREPTBlockSize);
yy_switch_to_buffer(CurrentFlexHandle);
sym_UseCurrentMacroArgs();
sym_SetMacroArgID(nMacroCount++);
sym_UseNewMacroArgs();
return (0);
}
}
}
if( (pLastFile=pFileStack)!=NULL )
{
if ((pLastFile = pFileStack) != NULL) {
ppLastFile = &pFileStack;
while (pLastFile->pNext)
{
ppLastFile = &(pLastFile->pNext);
pLastFile = *ppLastFile;
while (pLastFile->pNext) {
ppLastFile = &(pLastFile->pNext);
pLastFile = *ppLastFile;
}
yy_delete_buffer (CurrentFlexHandle);
yy_delete_buffer(CurrentFlexHandle);
nLineNo = pLastFile->nLine;
if (nCurrentStatus == STAT_isInclude)
fclose (pCurrentFile);
if (nCurrentStatus == STAT_isMacro)
{
sym_FreeCurrentMacroArgs ();
nLineNo += 1;
fclose(pCurrentFile);
if (nCurrentStatus == STAT_isMacro) {
sym_FreeCurrentMacroArgs();
nLineNo += 1;
}
if (nCurrentStatus == STAT_isREPTBlock)
nLineNo += 1;
nLineNo += 1;
CurrentFlexHandle = pLastFile->FlexHandle;
strcpy ((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
switch (nCurrentStatus = pLastFile->nStatus)
{
case STAT_isMacroArg:
case STAT_isMacro:
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
pCurrentMacro = pLastFile->pMacro;
break;
case STAT_isInclude:
pCurrentFile = pLastFile->pFile;
break;
case STAT_isREPTBlock:
sym_RestoreCurrentMacroArgs (pLastFile->tzMacroArgs);
pCurrentREPTBlock = pLastFile->pREPTBlock;
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
break;
strcpy((char *)tzCurrentFileName,
(char *)pLastFile->tzFileName);
switch (nCurrentStatus = pLastFile->nStatus) {
case STAT_isMacroArg:
case STAT_isMacro:
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
pCurrentMacro = pLastFile->pMacro;
break;
case STAT_isInclude:
pCurrentFile = pLastFile->pFile;
break;
case STAT_isREPTBlock:
sym_RestoreCurrentMacroArgs(pLastFile->tzMacroArgs);
pCurrentREPTBlock = pLastFile->pREPTBlock;
nCurrentREPTBlockSize = pLastFile->nREPTBlockSize;
nCurrentREPTBlockCount = pLastFile->nREPTBlockCount;
break;
}
free (*ppLastFile);
free(*ppLastFile);
*ppLastFile = NULL;
yy_switch_to_buffer (CurrentFlexHandle);
yy_switch_to_buffer(CurrentFlexHandle);
return (0);
}
else
} else
return (1);
}
int yywrap (void)
int yywrap(void)
{
return (popcontext ());
return (popcontext());
}
/*
@@ -184,19 +178,18 @@ int yywrap (void)
*
*/
void fstk_Dump (void)
void fstk_Dump(void)
{
struct sContext *pLastFile;
struct sContext *pLastFile;
pLastFile = pFileStack;
pLastFile = pFileStack;
while (pLastFile)
{
printf ("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
while (pLastFile) {
printf("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
pLastFile = pLastFile->pNext;
}
}
printf ("%s(%ld)", tzCurrentFileName, nLineNo);
printf("%s(%ld)", tzCurrentFileName, nLineNo);
}
/*
@@ -206,35 +199,32 @@ void fstk_Dump (void)
*
*/
void fstk_AddIncludePath (char *s)
void fstk_AddIncludePath(char *s)
{
strcpy (IncludePaths[NextIncPath++], s);
strcpy(IncludePaths[NextIncPath++], s);
}
void fstk_FindFile (char *s)
void fstk_FindFile(char *s)
{
char t[_MAX_PATH + 1];
SLONG i = -1;
char t[_MAX_PATH + 1];
SLONG i = -1;
strcpy (t, s);
strcpy(t, s);
while (i < NextIncPath)
{
FILE *f;
while (i < NextIncPath) {
FILE *f;
if( (f=fopen(t,"rb"))!=NULL )
{
fclose (f);
strcpy (s, t);
return;
if ((f = fopen(t, "rb")) != NULL) {
fclose(f);
strcpy(s, t);
return;
}
i += 1;
if (i < NextIncPath)
{
strcpy (t, IncludePaths[i]);
strcat (t, s);
if (i < NextIncPath) {
strcpy(t, IncludePaths[i]);
strcat(t, s);
}
}
}
}
/*
@@ -244,35 +234,33 @@ void fstk_FindFile (char *s)
*
*/
ULONG fstk_RunInclude (char *s)
ULONG fstk_RunInclude(char *s)
{
FILE *f;
char tzFileName[_MAX_PATH + 1];
FILE *f;
char tzFileName[_MAX_PATH + 1];
//printf( "INCLUDE: %s\n", s );
strcpy (tzFileName, s);
fstk_FindFile (tzFileName);
strcpy(tzFileName, s);
fstk_FindFile(tzFileName);
//printf( "INCLUDING: %s\n", tzFileName );
if( (f=fopen(tzFileName,"rt"))!=NULL )
{
pushcontext ();
if ((f = fopen(tzFileName, "rt")) != NULL) {
pushcontext();
nLineNo = 1;
nCurrentStatus = STAT_isInclude;
strcpy (tzCurrentFileName, tzFileName);
strcpy(tzCurrentFileName, tzFileName);
pCurrentFile = f;
CurrentFlexHandle = yy_create_buffer (pCurrentFile);
yy_switch_to_buffer (CurrentFlexHandle);
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle);
// Dirty hack to give the INCLUDE directive a linefeed
// Dirty hack to give the INCLUDE directive a linefeed
yyunput( '\n' );
nLineNo-=1;
yyunput('\n');
nLineNo -= 1;
return (1);
}
else
} else
return (0);
}
@@ -283,24 +271,24 @@ ULONG fstk_RunInclude (char *s)
*
*/
ULONG fstk_RunMacro (char *s)
ULONG fstk_RunMacro(char *s)
{
struct sSymbol *sym;
struct sSymbol *sym;
if( (sym=sym_FindMacro(s))!=NULL )
{
pushcontext ();
sym_SetMacroArgID (nMacroCount++);
if ((sym = sym_FindMacro(s)) != NULL) {
pushcontext();
sym_SetMacroArgID(nMacroCount++);
nLineNo = -1;
sym_UseNewMacroArgs ();
sym_UseNewMacroArgs();
nCurrentStatus = STAT_isMacro;
strcpy (tzCurrentFileName, s);
strcpy(tzCurrentFileName, s);
pCurrentMacro = sym;
CurrentFlexHandle = yy_scan_bytes (pCurrentMacro->pMacro, pCurrentMacro->ulMacroSize);
yy_switch_to_buffer (CurrentFlexHandle);
CurrentFlexHandle =
yy_scan_bytes(pCurrentMacro->pMacro,
pCurrentMacro->ulMacroSize);
yy_switch_to_buffer(CurrentFlexHandle);
return (1);
}
else
} else
return (0);
}
@@ -311,25 +299,23 @@ ULONG fstk_RunMacro (char *s)
*
*/
void fstk_RunMacroArg (SLONG s)
void fstk_RunMacroArg(SLONG s)
{
char *sym;
char *sym;
if (s == '@')
if (s == '@')
s = -1;
else
else
s -= '0';
if( (sym=sym_FindMacroArg(s))!=NULL )
{
pushcontext ();
if ((sym = sym_FindMacroArg(s)) != NULL) {
pushcontext();
nCurrentStatus = STAT_isMacroArg;
sprintf (tzCurrentFileName, "%c", (UBYTE)s);
CurrentFlexHandle = yy_scan_bytes (sym, strlen (sym));
yy_switch_to_buffer (CurrentFlexHandle);
}
else
fatalerror ("No such macroargument");
sprintf(tzCurrentFileName, "%c", (UBYTE) s);
CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym));
yy_switch_to_buffer(CurrentFlexHandle);
} else
fatalerror("No such macroargument");
}
/*
@@ -339,20 +325,19 @@ void fstk_RunMacroArg (SLONG s)
*
*/
void fstk_RunString (char *s)
void fstk_RunString(char *s)
{
struct sSymbol *pSym;
struct sSymbol *pSym;
if( (pSym=sym_FindSymbol(s))!=NULL )
{
pushcontext ();
if ((pSym = sym_FindSymbol(s)) != NULL) {
pushcontext();
nCurrentStatus = STAT_isMacroArg;
strcpy (tzCurrentFileName, s);
CurrentFlexHandle = yy_scan_bytes (pSym->pMacro, strlen (pSym->pMacro));
yy_switch_to_buffer (CurrentFlexHandle);
}
else
yyerror ("No such string symbol");
strcpy(tzCurrentFileName, s);
CurrentFlexHandle =
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
yy_switch_to_buffer(CurrentFlexHandle);
} else
yyerror("No such string symbol");
}
/*
@@ -362,21 +347,21 @@ void fstk_RunString (char *s)
*
*/
void fstk_RunRept (ULONG count)
void fstk_RunRept(ULONG count)
{
if (count)
{
pushcontext ();
sym_UseCurrentMacroArgs ();
sym_SetMacroArgID (nMacroCount++);
sym_UseNewMacroArgs ();
if (count) {
pushcontext();
sym_UseCurrentMacroArgs();
sym_SetMacroArgID(nMacroCount++);
sym_UseNewMacroArgs();
nCurrentREPTBlockCount = count;
nCurrentStatus = STAT_isREPTBlock;
nCurrentREPTBlockSize = ulNewMacroSize;
pCurrentREPTBlock = tzNewMacro;
CurrentFlexHandle = yy_scan_bytes (pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer (CurrentFlexHandle);
}
CurrentFlexHandle =
yy_scan_bytes(pCurrentREPTBlock, nCurrentREPTBlockSize);
yy_switch_to_buffer(CurrentFlexHandle);
}
}
/*
@@ -386,26 +371,24 @@ void fstk_RunRept (ULONG count)
*
*/
ULONG fstk_Init (char *s)
ULONG fstk_Init(char *s)
{
char tzFileName[_MAX_PATH + 1];
char tzFileName[_MAX_PATH + 1];
sym_AddString ("__FILE__", s);
sym_AddString("__FILE__", s);
strcpy (tzFileName, s);
fstk_FindFile (tzFileName);
strcpy(tzFileName, s);
fstk_FindFile(tzFileName);
pFileStack = NULL;
if( (pCurrentFile=fopen(tzFileName,"rt"))!=NULL )
{
pFileStack = NULL;
if ((pCurrentFile = fopen(tzFileName, "rt")) != NULL) {
nMacroCount = 0;
nCurrentStatus = STAT_isInclude;
strcpy (tzCurrentFileName, tzFileName);
CurrentFlexHandle = yy_create_buffer (pCurrentFile);
yy_switch_to_buffer (CurrentFlexHandle);
strcpy(tzCurrentFileName, tzFileName);
CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1;
return (1);
}
else
} else
return (0);
}
}