/********************************************************************************
*										*
*	Company: Telelogic AB							*
*	Copyright (c) by Telelogic AB, 1993 - 2000				*
*										*
*										*
*	This Program is owned by Telelogic and is protected by national 	*
*	copyright laws and international copyright treaties. Telelogic 		*
*	grants you the right to use this Program on one computer or in 		*
*	one local computer network at any one time. 				*
*	Under this License you may only modify the source code for the purpose 	*
*	of adapting it to your environment. You must reproduce and include 	*
*	any copyright and trademark notices on all copies of the source code. 	*
*	You may not use, copy, merge, modify or transfer the Program except as	*
*	provided in this License.						*
*	Telelogic does not warrant that the Program will meet your		*
*	requirements or that the operation of the Program will be		*
*	uninterrupted and error free. You are solely responsible that the	*
*	selection of the Program and the modification of the source code 	*
*	will achieve your intended results and that the results are actually 	*
*	obtained.								*
*										*
*										*
*	File: 	sccd.c	"SDT C-Compiler Driver"					*
*										*
*	Use: cpp, pretty print and compile a C or C++ module.			*
*	Sets -DXHS as extra cpp option for better *.hs file management 		*
*	  espec. for OSE. I.e. - Only "Includes" the .hs file in the 2:nd (real	*
*	  compiler ) pass. Otherwise all signals would only be available as	*
*	  numbers for debugging ( instead of names ).				*
*										*
*	Author: C.O.Hydbom							*
*	Date:   931208								*
*	Modified: 940307							*
*	Modified: 941111, 941114						*
*	Modified: V.1.71 - 961025 fix av .hs					*
*	Modified: V.1.80 - 970516 added C++ comment support + '\n' after ';'	*
*	Modified: V.2.00 - 970518 added sccd.cfg file and search algorithm	*
*	Modified: V.2.11 - 970519 prepare DOS version				*
*	Modified: V.2.20 - 970520 added COMPILE variable			*
*	Modified: V.2.21 - 970520 updates & bug-fixes				*
*	Modified: V.2.30 - 970521 added USER_CMD3 and DOSsupport		*
*	Modified: V.2.31 - 970521 ansi/K&R fix					*
*	Modified: V.2.33 - 970522 .cfg file info in help.			*
*	Modified: V.2.34 - 970522 buffer initialization added			*
*	Modified: V.2.35 - 970630 Microsoft Visual C++ support added + errcode	*
*	Modified: V.2.40 - 970630 %p, %f, %d added				*
*	Modified: V.2.41 - 970701 extended "TmpDir" functionality		*
*	Modified: V.2.42 - 970702 print ExitCode info in "help"			*
*	Modified: V.2.43 - 970904 fixed XHS management				*
*	Modified: V.2.44 - 980130 fixed SCTDIR for "DOS"			*
*	Modified: V.2.50 - 980210 Updated to manage response-files on PC	*
*				   based on Fabrizio Pugnetti's original code.	*
*	Modified: V.2.51 - 980211 Modified sccdUSER_CMD1			*
*	Modified: V.2.52 - 980211 Added CPP response file			*
*	Modified: V.3.00 - 980211 Added OSE sim/debugger support		*
*	Modified: V.3.01 - 980212 Minor error reporting update			*
*	Modified: V.3.02 - 980212 SunOS4 fix					*
*	Modified: V.3.03 - 980212 "DOS" compiler file redirect fix		*
*	Modified: V.3.04 - 980212 Added new-line after OSE format statement	*
*	Modified: V.3.05 - 980213 Minor updates					*
*	Modified: V.3.10 - 980325 Increased CompileLineX size from 400b to 5kb	*
*	Modified: V.3.11 - 980512 Fixed "very long" comments + "sccd -v"	*
*	Modified: V.3.4  - 980701 bumped sccd version number to 3.4		*
*	Modified: V.3.41 - 980929 Fixed bug in c++ comment handling		*
*	Modified: V.3.42 - 981208 Added use of absolute temp-dir path		*
*										*
*	Modified: V.3.50 - 991122 Tornado support added "sccd -t"		*
*	Modified: V.3.51 - 000315 Bumped version number				*
*										*
*										*
*	Compile in SunOS4.1.x environment using 'cc' with:			*
*		 cc -DUNIX -DSunOS4_1_1 sccd.c -o sccd				*
*										*
*	Compile in Sun Solaris2, HPUX, OSF1 & AIX environment using 'cc' with:	*
*		 cc -DUNIX sccd.c -o sccd					*
*										*
*	Compile in QNX environment using Watcom CC v.10.6  with:		*
*		 cc -DUNIX -mf -N100k sccd.c -o sccd				*
*										*
*	Compile with gcc using: 						*
*		 gcc -DUNIX -DXANSI -Wall -ansi -pedantic sccd.c -o sccd	*
*										*
*	Compile with Borland C 3.1 in 16 bit DOS using:				*
*		 bcc -DDOS -DXANSI -ml sccd.c					*
*										*
*	Compile with Borland C 5.0 in Win32 mode using: 			*
*		 bcc32 -DDOS -DXANSI sccd.c					*
*										*
*	Compile with Microsoft CL using: 					*
*		 cl /DDOS /DXANSI sccd.c					*
*										*
*										*
*										*
********************************************************************************/


/********************************************************************************
*										*
*	EXIT CODE :=								*
*										*
*	0	on success !							*
*										*
*	> 0 => abort								*
*	code	reason for abort						*
*	------------------------						*
*	1	after printing "help"						*
*	2	no .sccdINFILESUFFIX file					*
*	3	could not open  InFile.sccdINFILESUFFIX				*
*	4	could not open  InFile.i for write				*
*	5	sccdMOVE or sccdOUTFILEREDIR needs to be defined		*
*	6	could not open  InFile.<sccdTEMPSUFFIX> for read		*
*	7	could not open/create TmpDir/InFile.<sccdINFILESUFFIX>		*
*	8	could not open the input response-file for read			*
*	9	could not open/create the compile response-file for write	*
*	10	could not open/create the preprocessor response-file for write	*
*	11	Tornado code generation error					*
*										*
********************************************************************************/

#if defined(SUN) || defined(HPUX) || defined(ALPHA) || defined(AIXV3)
#define UNIX
#endif


#ifdef UNIX
#undef DOS
#endif

#ifdef DOS
#undef UNIX
#ifdef __BORLANDC__
extern unsigned _stklen = 56000U;	/* 56k */
#endif
#endif

#include <stdio.h>

#if defined( __GNUC__ ) && defined( SunOS4_1_1 )
extern int printf( char *format,  ... );
extern int fprintf( FILE *stream, char *format, ... );
extern char *strcat ( char *, const char * );
extern int system (char *command );
extern int fgetc ( FILE *stream );
extern int fclose( FILE *stream );
extern int putenv(char *string);
#endif


#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define VERSION     	351

#define STRING_EQUALITY 0

#ifndef FALSE
#define FALSE 		0
#define TRUE  		1
#endif
typedef unsigned char boolean;

#define NAME_BUF_LEN		1024
#define BUF_LEN			5120

#define MAX_ARGS 		NAME_BUF_LEN
#define MAXPATH  		NAME_BUF_LEN

 char  FileName[MAXPATH + 1];	/* name for command-line response file */
 char  CompileLine[BUF_LEN];	/* buffer for compile line */
 char  CompileLine1[BUF_LEN];	/* buffer for the redirected arguments in a compile line */
 char* Args[MAX_ARGS];		/* array of pointers to argument strings (=argv[])*/
 int   UsedArgs = 0;		/* total # of arguments on command line */
 int   FileArgs = 0;		/* # of arguments in response file */
 int   FirstFileArg = 0;	/* first argument # from the response file */
 int   clc = 0;			/* Command (Line) Counter */
 boolean sccd_debug;		/* Dynamic debug flag, read from .cfg file */
 boolean sccd_silent;		/* Verbose flag, read from .cfg file */
 boolean sccd_tornado;	        /* command line option '-t' enables Tornado support */
 boolean sccd_tornado_exp;      /* command line option '-e' enables Tornado support for 
				   an expanded file */

/* Tornado parser variable declarations */
 boolean GenCalled;
 boolean ProcCalled;
 boolean inProc;

 long int lineNbr;
 int LineCharPos;
 int procType; /*  0=process, 1=procedure */

 FILE* infile;
 FILE* genFile1;
 FILE* genFile2;
 FILE* genFile3;
 FILE* outFile;

 char LineBuf[BUF_LEN];
 char StrBuf[NAME_BUF_LEN ];
 char procName[NAME_BUF_LEN];

 char GenFile1Name[NAME_BUF_LEN]; /* default "gen1" */
 char GenFile2Name[NAME_BUF_LEN]; /* default "gen2" */
 char GenFile3Name[NAME_BUF_LEN]; /* default "gen3" */
 char OutFileName[NAME_BUF_LEN];  /* default "sctsymb.c" */
/* end of Tornado variables */



/****+*******************************************************************
     SmartCommandLine()		Constructor
************************************************************************/

#ifdef XANSI
  void SmartCommandLine( void )		/* ANSI C version */
#else
  SmartCommandLine()			/* K&R C version */
#endif
{
 int i;
 UsedArgs = 0;
 FileArgs = 0;
 for ( i = 0; i < MAXPATH + 1; i++ ) FileName[ i ] = '\0';	/* clear FileName[] */
 for ( i = 0; i < MAX_ARGS;    i++ )     Args[ i ] = NULL;	/* clear Args[] */
}

/****+*******************************************************************
     DSmartCommandLine()	Destructor
************************************************************************/

#ifdef XANSI
  void DSmartCommandLine(void)		/* ANSI C version */
#else
  DSmartCommandLine()			/* K&R C version */
#endif
{
 int i;
 for ( i = 0; i < MAX_ARGS; i++ ){
   if ( Args[i] )
     free( Args[i] );
 }
}

/****+*******************************************************************
     cleanexit()		Clean-up before exit
************************************************************************/

#ifdef XANSI
  void cleanexit( int exitcode )	/* ANSI C version */
#else
  cleanexit( exitcode )			/* K&R C version */
	int exitcode ;
#endif
{
 DSmartCommandLine();			/* clean up */
 exit( exitcode );
}

#ifndef linux
/****+*******************************************************************
     strdup()		Return a pointer 2 a newly allocated copy of s
************************************************************************/

#ifdef XANSI
  char *strdup( const char *s)		/* ANSI C version */
#else
  char *strdup(s)			/* K&R C version */
	 char *s;
#endif
{
 char* ptr;
 if ( ( ptr = calloc( strlen(s) + 1, sizeof(*s) ) ) == NULL ) return (char*)NULL;
 return ( strcpy( ptr, s) );
}

#endif
/****+*******************************************************************
     GetNum()		get the number of args ( approx. = argc )
************************************************************************/

#ifdef XANSI
  int GetNum( void )			/* ANSI C version */
#else
  int GetNum()				/* K&R C version */
#endif
{
 return UsedArgs;
}

/****+*******************************************************************
     Get()		get a single argument; Args[0] == argv[0]
************************************************************************/

#ifdef XANSI
  char* Get( int argindex )		/* ANSI C version */
#else
  char* Get( argindex )			/* K&R C version */
	int argindex;
#endif
{
 return Args[ argindex ];
}

/****+*******************************************************************
     Set()		modify the selected argument
************************************************************************/

#ifdef XANSI
  void Set( char* argument, int index )/* ANSI C version */
#else
  Set( argument, index )		/* K&R C version */
	 char* argument;
	int index;
#endif
{
 if( Args[ index ] )	
   free( Args[ index ] );
 Args[ index ] = strdup( argument);	/* Enter the new argument into Args[] */
}

/****+*******************************************************************
     IsResponseFile()	return TRUE if the passed name is a generated commandfile
************************************************************************/

#ifdef XANSI
 int IsResponseFile(  char* argument )/* ANSI C version */
#else
 int IsResponseFile( argument )		/* K&R C version */
	 char* argument;
#endif
{
 return ( argument[0] == '@' );
}

/****+*******************************************************************
     ParseResponseFile()		
************************************************************************/
 /*
    Scan the generated response file "filename" for compiler command tokens.
    Copy the tokens to Args[], starting at index "argsindex".
    Return the first unused "Args index"
    This scanner manages embedded new-lines in "filename" as well!!
 */

#ifdef XANSI
  int ParseResponseFile(  char* filename, int argsindex )/* ANSI C version */
#else
  int ParseResponseFile( filename, argsindex )		/* K&R C version */
	char* filename;
	int argsindex;
#endif
{
 char LineBuf[BUF_LEN], TmpBuf[ sizeof( LineBuf ) ];
 boolean Loop;
 int charpos;
 int tcharpos;
 FILE* f;

 for ( charpos = 0; charpos < BUF_LEN; charpos++ ) LineBuf[ charpos ] = '\0';	/* clear LineBuf[] */
 strcpy( FileName, (char*)( filename + 1 ) );/* set the file name & pass '@' */
 FirstFileArg = argsindex;		/* set the first file's argument index */
 if ( ( f = fopen( FileName, "r") ) == '\0' ){ /* open the response file for read */
   printf("\n*** ERROR, Could not open input response-file %s for read. Aborting!\n", FileName );
   cleanexit(8);
 }

 while ( fgets( LineBuf, sizeof(LineBuf), f ) ){  /* LineBuf := 1 response file line */
   charpos = 0;				/* parse each token */
   while ( LineBuf[ charpos ] != '\0' ){ /* scan for new token until EOL */
     tcharpos = 0;
     while ( LineBuf[ charpos ] == ' '  ||  /* pass white-space and new-line */
             LineBuf[ charpos ] == '\t' ||
             LineBuf[ charpos ] == '\n'    ){ charpos++;
     }
     Loop = TRUE;
     while ( Loop ){			/* scan for 1 token & copy it to TmpBuf[] */
       switch ( LineBuf[ charpos ] ){	/* scan until next white-space or new-line */
         case '\0':	Loop = FALSE;	/* at EOL */
			break;		/* found 1 token !, go store it */
         case  ' ':
         case '\t':
         case '\n':	charpos++;
			Loop = FALSE;
			break;		/* found 1 token !, go store it */
         default:	TmpBuf[ tcharpos++ ] = LineBuf[ charpos++ ];
       }
     }					/* one token found ! */
     TmpBuf[ tcharpos ] = '\0';		/* append string delimiter ( NULL) */
     if ( strlen( TmpBuf ) ) 		/* if a non-empty token has been found, */
       Set( TmpBuf, argsindex++ );	/*  create a new Args[] entry and store it*/
   }					/* go for the next token */
 }					/* go for the next response file line */
 fclose ( f );
 FileArgs = argsindex - FirstFileArg;	/* set the total n of file args */
 return argsindex;
}

/****+*******************************************************************
     Load()		load from the original command line
************************************************************************/

#ifdef XANSI
  void Load( int argc, char *argv[] )	/* ANSI C version */
#else
  Load( argc, argv)
	int argc;
	char *argv[];			/* K&R C version */
#endif
{
  int argindex = 0;
  int argcindex = 0;
  int Limit = argc;
  int i;
/*
   Read in command line arguments.
   If a response file is found, begin parsing args from response file instead
*/
  while ( argindex < Limit ){
    if ( IsResponseFile( argv[ argindex ] ) ){ /* "file" argument, parse it */
      argindex = ( ParseResponseFile( argv[ argindex ], argindex ) - 1 );
      Limit += FileArgs - 1;		/* update "argc" with response file args */
      argcindex++;			/* consume 1 argv[] per response file */
    }
    else { 				/* standard argument, catch it */
      Set( argv[ argcindex++ ], argindex );/* Args[i] := copy of argv[i] */
    }
    argindex++;				/* index to next argument */
  }
  UsedArgs = Limit;
  for ( i = 0; i < BUF_LEN; i++ ) CompileLine[ i ] = '\0';	/* clear CompileLine[] */
}


/****+*******************************************************************
     GetCompileLine()		
************************************************************************/
/*
  build & return the compile command line, with items modified by
  the Set function
*/

#ifdef XANSI
  char* GetCompileLine( void )		/* ANSI C version */
#else
  char* GetCompileLine()		/* K&R C version */
#endif
{
 int argsindex;
 int no_of_args = FirstFileArg ;
 FILE* f;

 if ( CompileLine[0] == '\0' ){		/* if not yet done, create the line */
   if ( FirstFileArg == 0 ) no_of_args = GetNum();
   for ( argsindex = 1;			/* copy from "argv[1]" until response file or */
         argsindex < no_of_args;	/*  if no response file, until "argv[argc-1]" . */
         argsindex++ ){			/* copy arguments preceeding the response file name */
     strcat( CompileLine, Get( argsindex ) );
     strcat( CompileLine, " " );
   }

   if ( FileArgs != 0 ){		/* if a response file was used, insert it in line */
     strcat( CompileLine, "@" );
     strcat( CompileLine, FileName );
     strcat( CompileLine, " " );
     /* arguments beyond the file (almost never present!) */
     for ( argsindex = FirstFileArg + FileArgs;
           argsindex < GetNum();
           argsindex++                          ){
       strcat( CompileLine, Get( argsindex ) );
       strcat( CompileLine, " " );
     }
   }
   if ( FileArgs != 0 ){
     /* recreate automated response file in output */
     if ( !sccd_debug ){
       f = fopen( FileName, "w" );
       if ( f == '\0' ){
         printf("\n*** ERROR, Could not open/create the compile response-file %s for write. Aborting!\n", FileName );
         cleanexit(9);
       }
       for ( argsindex = FirstFileArg; argsindex < FirstFileArg + FileArgs; argsindex++ ){
         fprintf( f, "%s ", Get( argsindex ) );
       }
       fclose( f );
     }
       if ( !sccd_silent ){
         printf("[%d]response file=    (%s): \"", clc++, FileName );
         for ( argsindex = FirstFileArg; argsindex < FirstFileArg + FileArgs; argsindex++ ){
           printf( "%s ", Get( argsindex ) );
         }
         printf("\"\n");
       }
   }
 }
 return CompileLine;
}


/****+*******************************************************************
     strpos()
************************************************************************/

#ifdef XANSI 
 int strpos( char *s, char c)		/* ANSI C version */
#else
 int strpos( s, c)			/* K&R C version */
    char *s, c;
#endif
{
 int retval = 0;
 while ( (*s != '\0') && (*s != c) ){ ++s; ++retval; }
 return ( *s != '\0' ? retval : -1 );
}

/****+*******************************************************************
     strrpos()
************************************************************************/

#ifdef XANSI
 int strrpos( char *s, char c)		/* ANSI C version */
#else
 int strrpos( s, c)			/* K&R C version */
    char *s, c;
#endif
{
 int i;
 int position = -1;

 for ( i = strlen(s) - 1; i >= 0; i-- ){
   if ( s[i] == c ){
     position = i;
     break;
   }
 }
 return position;
}
             
/****+*******************************************************************
     isfile()
************************************************************************/

#ifdef XANSI
 boolean isfile( char* filename )	/* ANSI C version */
#else
 boolean isfile( filename )		/* K&R C version */
  char *filename;
#endif
{
 FILE *TmpFile;
 /* file existence test, return FALSE if file does NOT exist or TRUE */
 if( ( TmpFile = fopen( filename, "r") ) == '\0' ){
   return FALSE;
 }
 fclose( TmpFile );
 return TRUE;
}

/****+*******************************************************************
     generate()
************************************************************************/
/*
  generate Tornado code by checking the parameter 'command'.
  The generated code will be placed in outFile, genFile1, genFile2 or genFile3
*/
#ifdef XANSI
 void generate(char* command)
#else
 generate( command )
  char* command;
#endif
{
  boolean lineFound;
  int charpos;
  int tcharpos;
  int tmpint;
  char* ch;
  char tmpBuf[NAME_BUF_LEN];
  char varBuf[NAME_BUF_LEN];  
  char tmpLine[BUF_LEN];
  char outLine[BUF_LEN];

  if (!GenCalled){
    sprintf(outLine,"/* Generated trace functions for Tornadointegration */\n\n");
    fputs(outLine, genFile1);
    
    sprintf(outLine,"/* Start of Tornado Integration generated section */\n");
    fputs(outLine, genFile2);

    GenCalled = TRUE;
  }    
    
  /* printf("In generate: %s - %s\n", StrBuf, command); */

  for (charpos=0; charpos < NAME_BUF_LEN; charpos++){
    tmpBuf[charpos]= '\0'; /* clear tmpBuf[] */
    varBuf[charpos]= '\0'; /* clear varBuf[] */
  }
  for (charpos=0; charpos < BUF_LEN; charpos++){
    tmpLine[charpos]= '\0' ;/* clear tmpLine */
    outLine[charpos]= '\0' ;/* clear outLine */
  }
  charpos=0;
  tcharpos=0;
  strcpy(outLine,""); 

  /* ============= */  
  if (strcmp(command, "xFileName")==0){
    /* Found for example:
       static char  xFileName[] = "/vobs/sdt/alfa/simui/impl/TORNADOINT/SDLVxWorks2/test.c"; */

    while (LineBuf[charpos] != '"') /* go to beginning of filepath */
      charpos++;
    charpos++;
    while (LineBuf[charpos] != '"') /* go to end of filepath */
      charpos++;
    
    charpos--;
#ifdef UNIX  /* Path_Delim */ 
    while (LineBuf[charpos] !='/' &&  
	   LineBuf[charpos] !='"')
#else
    while (LineBuf[charpos] !='\\' &&
           LineBuf[charpos] !='"')  
#endif                             
      {/* move from end to beginning to get filename without path */
	tmpBuf[tcharpos++] = LineBuf[charpos--] ;
      }    
   
    for (charpos=0; charpos < strlen(tmpBuf) ; charpos++)
      varBuf[charpos] = tmpBuf[ strlen(tmpBuf)-charpos-1 ] ;
  
    /* Line in outFile should be:
       printf(" xFileNameShort[] = \"%s\"\n",varBuf); */
    
    fputs(LineBuf, outFile); /* write LineBuf to file */
    sprintf(outLine, "static char  xFileNameShort[] = \"%s\";\n", varBuf);
   
    /*copy outLine to LineBuf so it will be written to file in the main loop*/
    strcpy(LineBuf, outLine);  
    
    return;
  }
  
  /* ============= */
  if (strcmp(command, "ProcStart")==0){
    
    /* Found for example:
       "YPAD_FUNCTION(yPAD_z00_Pr1)" */   
 
    ProcCalled = TRUE;
    inProc=TRUE;
    
    strcpy(procName,"");
    strcpy(tmpBuf, StrBuf); 

    while (tmpBuf[charpos] != '(' )
      charpos++;

    if(procType==0){
      while (tmpBuf[charpos] != '_' )  /* process name is z00_Pr1 */ 
	charpos++;          
      charpos++;
    } else
      charpos++;

    while (tmpBuf[charpos] != ')' )  
      procName[tcharpos++]=tmpBuf[charpos++]; /* copy proc name from tmpBuf */
    
    procName[ tcharpos ] = '\0';    /* append string delimiter ( NULL) */           
    
    /* Line in genFile1 should be:
       "void xSetTraceInfo_z00_Pr1 XPP((int InstNu, char * PrefixNameInst, char *PrefixName))
    {"
    */    
    sprintf(outLine, "void xSetTraceInfo_%s XPP((int InstNu, char * PrefixNameInst, char *PrefixName))\n{\n",procName);    
    fputs(outLine, genFile1);    

    /* Line in genFile2 should be:
      "xInitTraceList(xFileNameShort,"z00_Pr1",(xPrsIdNode)yPrsN_z00_Pr1,xSetTraceInfo_z00_Pr1);"*/

    sprintf(outLine, "  xInitTraceList(xFileNameShort,\"%s\",(xPrsIdNode)yPr%cN_%s,xSetTraceInfo_%s);\n",
	    procName,procType ? 'd' : 's' , procName, procName );
    fputs(outLine, genFile2);
    
    /* Line in genFile2 should be:
       "xSetTraceInfoAll((xIdNode)yPrsN_z00_Pr1);" */

    sprintf(outLine, "  xSetTraceInfoAll((xIdNode)yPr%cN_%s);\n", 
	    (procType == 0 ? 's' : 'd'), procName);
    fputs(outLine, genFile2);
    
    return;
  }
    
  /* ============== */

  if (strcmp(command, "ProcCall")==0){  
    /* Found for example:
       XAT_FIRST_SYMBOL(0)     (at row 413)
       XBETWEEN_SYMBOLS(6, 449) 
       XBETWEEN_SYMBOLS_PRD(2, 672) */

    while (StrBuf[charpos] != '(' )  
      charpos++;
    charpos++;
    while (StrBuf[charpos] == ' ') /* pass space */
      charpos++;
    
    while(StrBuf[charpos] != ',' && StrBuf[charpos] != ')' )
      tmpBuf[tcharpos++] = StrBuf[charpos++];

    if (tmpBuf[0]== '0' || atoi(tmpBuf) != NULL)
      {
	/* Line in outFile should be:
	   xSetTraceInfo(0, 413,yRef_z00_Pr1,PrefixNameInst,PrefixName,InstNu); */   

	if (!sccd_tornado_exp) /* line number will be lineNbr (413) or "?" */
	  sprintf(outLine, "  xSetTraceInfo(%s, %ld,yRef_%s,PrefixNameInst,PrefixName,InstNu);\n", tmpBuf, lineNbr,procName);
	else 
	  /* set line number to "?" and the correct line number will 
	     later be entered, just before compile */
	  sprintf(outLine, "  xSetTraceInfo(%s, ?,yRef_%s,PrefixNameInst,PrefixName,InstNu);\n", tmpBuf,procName);
	
	fputs(outLine, genFile1);
      }
    
    return;
  }

  /* ============== */
  if (strcmp(command, "ProcEnd")==0){
    inProc=FALSE;
    sprintf(outLine, "}\n\n");
    fputs(outLine, genFile1);
     
    return;
  }

  /* ============== */
  if (strcmp(command, "VarCall")==0){

    /* XCONST struct xVarIdStruct yVarR_z005_Counter */

    /* type3 is found="xVarIdStruct" and the next character is the 
       beginning of the variable so lets get the variable*/

    charpos=LineCharPos;
    while(LineBuf[charpos] != '\0' && 
	  LineBuf[charpos] != ';' && 
	  LineBuf[charpos] != ' ')  /* copy next string from LineBuf */
      tmpBuf[tcharpos++] = LineBuf[charpos++] ; 
    
    /* move to first '_' in the full variable name */
    charpos=0;
    while (tmpBuf[charpos] != '_')
      charpos++;
   
    charpos++;
    tcharpos=0;
    while (tmpBuf[charpos] != '\0' && 
	   tmpBuf[charpos] != ';' && 
	   tmpBuf[charpos] != ' ' ) /* copy after '_' into varBuf to get small variabel name */
      varBuf[tcharpos++] = tmpBuf[charpos++] ; 

    /* xSetVarPrefixName(&yVarR_z005_Counter,"z005_Counter"); */

    sprintf(outLine, "  xSetVarPrefixName(&%s,\"%s\");\n", tmpBuf, varBuf);
    fputs(outLine, genFile2);
  
    return;
  }

  /* ============= */
  if (strcmp(command, "Init")==0){
    while (charpos++ < BUF_LEN) /* clear tmpLine */
      tmpLine[charpos]='\0';

    charpos=0;
    while (LineBuf[charpos] != '\0')
      {	
	while (LineBuf[charpos] == ' '){
	  charpos++;
	  strcat(tmpLine, " ");	 
	}
	
	while (LineBuf[charpos] != ' ' &&
	       LineBuf[charpos] != '\0' )
	  tmpBuf[tcharpos++] = LineBuf[charpos++];
	tmpBuf[tcharpos]='\0';

	if (strcmp(tmpBuf, "yInit")==0)
	  strcpy(tmpBuf, "yInit_symb");
	
	strcat(tmpLine, tmpBuf);	

	tcharpos=0;
	strcpy(tmpBuf, "");
      }
    strcpy(LineBuf, tmpLine);
    
    return;
  }

  /* ============ */
  if (strcmp(command, "InitEnd")==0){       
    sprintf(outLine, "/* End of Tornado Integration generated section */\n");
    fputs(outLine, genFile2);
    
    return;
  }   
  
  /* ============ */
  if (strcmp(command, "setLineNbr")==0)
    {   
      strcpy(tmpLine,"");     
      lineFound=FALSE;
      while (!lineFound && (fgets( tmpLine, sizeof(tmpLine), genFile1 )) )
	/* if ( (strstr( tmpLine, "xSetTraceInfo(" )) != 0 )  */  /*line with "?" */
	  { 
	    charpos=0;
	    while( tmpLine[charpos] != '\0' && tmpLine[charpos] != '?' )
	      charpos++;
	    
	    if ( tmpLine[charpos] == '?')
	      {
		lineFound=TRUE;
		strncpy(outLine, tmpLine, charpos);
		sprintf(outLine, "%s%d", outLine, lineNbr);
		
		charpos++;
		tcharpos=strlen(outLine);
		while ( tmpLine[charpos] != '\0')
		  outLine[tcharpos++]=tmpLine[charpos++];
		
		outLine[tcharpos] = '\0';
				
		fputs( outLine, genFile3);
	      }
	       else
		 fputs( tmpLine, genFile3);
	    
	  }/*while fgets */     
      
      return;
    }/*if "setLineNbr" */

  /* ============ */
   if (strcmp(command, "genFile3end")==0)
    {   
      while ( fgets( tmpLine, sizeof(tmpLine), genFile1 ) ) 
	fputs( tmpLine, genFile3);
      
      return;
    }

   printf("\nWARNING: Tornado parser: generate(): unknown command=\"%s\" \n", command);
   printf("                   or forgotten \"return\" in generate() \n");
}/* generate */


/****+*******************************************************************
     insert()
************************************************************************/
/*
  close the the genFile to be inserted and open it in read mode
  and insert all lines to the outFile.
*/

#ifdef XANSI
void insert(char* str)
#else
     insert( str)
     char* str;
#endif
{                       
  char inLine[BUF_LEN];
  FILE* genFile;
  char GenFileName[NAME_BUF_LEN];  
  strcpy(GenFileName, "");

#ifdef DEBUG
  printf("insert: str= '%s'\n",str);
#endif

  if (strcmp(str, "GenFile1")==0){ 
    genFile = genFile1;
    strcpy(GenFileName, GenFile1Name);       
  }
  
  if (strcmp(str, "GenFile2")==0){
    genFile = genFile2;
    strcpy(GenFileName, GenFile2Name);      
  }

  if (strcmp(str, "GenFile3")==0){
    genFile = genFile3;
    strcpy(GenFileName, GenFile3Name);      
  } 
  
  if ( strcmp(GenFileName,"") != 0)
    {
      fclose(genFile); /* close the genfile on writemode */
      
      if ( ( genFile = fopen( GenFileName, "r") ) == '\0' ){  /* open file for read */
	printf("\n*** ERROR, Could not open generated file %s for read", GenFileName);
	cleanexit(11);
      }  
      /* insert all lines from genFile to outFile */
      while ( fgets( inLine, sizeof(inLine), genFile ) ) 
	fputs(inLine, outFile);
      
      fclose(genFile);
    }
  else
    printf("ERROR: Tornado parser - Insert: Gen-file %s unknown",str); 
#ifdef DEBUG
  printf("insert:ready\n");
#endif
}


/****+*******************************************************************
     CheckWord()
************************************************************************/
/*
  compare the parameter 'str' and return an int>0 if it matches one of
  the special strings wich may lead to tornado code generation. 
  if no match found a zero is returned 
*/
#ifdef XANSI
int CheckWord(char* str)
#else
     int CheckWord( str )
     char* str;
#endif
{
 
  /*type1*/
  if(strncmp(str,"YPAD_FUNCTION", strlen("YPAD_FUNCTION"))==0 )
    {
      procType=0; /* "YPAD" = Process */
      return 1;
    }
  if (strncmp(str,"YPRD_FUNCTION", strlen("YPRD_FUNCTION"))==0 )
    {
      procType=1; /* "YPRD" = Procedure */
      return 1;
    }
  
  /* type2: reference containing an integer value and the lines number.
            only the integer will be extracted.
	    the line number are counted by this program so it will not
	    be extracted. */
  if (strncmp(str,"XAT_FIRST_SYMBOL", strlen("XAT_FIRST_SYMBOL"))==0 ||      
      strncmp(str,"XBETWEEN_SYMBOLS(", strlen("XBETWEEN_SYMBOLS("))==0 ||      
      strncmp(str,"XBETWEEN_SYMBOLS_PRD", strlen("XBETWEEN_SYMBOLS_PRD"))==0 )
    {
      return 2;
    }
  
  /* type3: variable declaration  */
  if (strncmp(str,"xVarIdStruct", strlen("xVarIdStruct"))==0 )
    {
      return 3; /* next string will be variable. For example:"yVarR_z005_Counter" */ 
    }

  
  /*type4: a new section of the code will come, propably 'SECTION Initialization' */
  if (strncmp(str,"/******", strlen("/******"))==0 )
    {
      return 4;	           
    }
  
   
  /* type5 = "yInit" which should be changed into "yInit_symb" */
  if (strcmp(str,"yInit") == 0 )  /* str is exactly 'yInit' and nothing more */
    {
      return 5;
    }
  
  /* type6: marks place where genFile2 should be inserted. insertion will 
     be made before this place */
  if (strncmp(str,"xInsertIdNode", strlen("xInsertIdNode"))==0 )
    {
      return 6;
    }    
  
  /* type7: a line will be added after this one with "xFileNameShort[] = ..." */
  if (strncmp(str, "xFileName[]", strlen("xFileName[]"))==0 )
    {      
      return 7;  /* "xFileName" is early in the file but its 
		    code is '7' because this was implemented late */
    }

  /* type8: same function as type6, but will be used when scanning an expanded file */
  if (strncmp(str, "xInitTimer(", strlen("xInitTimer("))==0 )
   {
     return 8;
   }


  return 0; /* if no special type has been found */
}


/****+*******************************************************************
     TornadoParse()		
************************************************************************/
/*    
      Scan the 'inName' file for special strings 
      and generate code for Tornado.
      Place the result in 'outName' file.

      If 'InMode' = 0 a normal generation will be made and if sccd_tornado_exp is
      TRUE the line numbers for genFile1 will be "?":s.

      If 'InMode' = 1 assumes that a normal generation has been made but
      the line numbers in genFile1 contain "?":s. Now a scan will be made
      on the expanded file and the correct line numbers will replace the "?":s.

      If 'InMODE' = 2 then everything is the same as for 'InMODE' = 0 except that
      genFile3 is used for insertion instead of genFile1. This because genFile3
      has been created and contains the correct line numbers. 
*/

#ifdef XANSI
  int TornadoParse(  char *inName, char *outName, int InMODE)/* ANSI C version */
#else
  int TornadoParse( inName, outName, InMODE )		/* K&R C version */
	char *inName;
	char *outName;	
	int InMODE;
#endif

{
  boolean Loop;
  boolean jumpLine; 
  boolean procMODE;
  boolean initMODE;

  boolean changeMODE;
  boolean chgLineFound; /* check if a type3 has been found */
  boolean chgInitMODE;  /* check if "yInit" should come as next wordType */
  boolean passLine;     /* do not write the current LineBuf to outFile */
  boolean Flush;   /* controls if rest of infile will be copied directly to outFile */

  int tcharpos;
  int wordType; 

  char openMode[NAME_BUF_LEN];

  GenCalled = FALSE;
  ProcCalled = FALSE;
  procMODE = TRUE;
  initMODE= FALSE;

  changeMODE = FALSE;
  chgLineFound = FALSE; /* check if a type3 has been found */
  chgInitMODE = FALSE;  /* check if "yInit" should come as next wordType */
  passLine = FALSE;     /* do not write the current LineBuf to outFile */
  
  inProc  = FALSE;
  Flush   = FALSE; 
  lineNbr = 0; 
  procType= 0;
  
  if (InMODE == 1){
    procMODE = FALSE;
    changeMODE = TRUE;
  }

  strcpy(FileName, inName);      
  strcpy(OutFileName,  outName) ;                 
  strcpy(procName, "");   
  
  for ( LineCharPos = 0; LineCharPos < BUF_LEN; LineCharPos++ ) 
    LineBuf[ LineCharPos ] = '\0';	/* clear LineBuf[] */
  
  if ( ( infile = fopen( FileName, "r") ) == '\0' ){ /* open the response file for read */
    printf("\n*** ERROR, Could not open input file %s for read. Aborting!\n", FileName );
    cleanexit(8);
  }
  
  if (!changeMODE)
    strcpy(openMode, "w");
  else
    strcpy(openMode, "r");     
  
  if ( ( genFile1 = fopen( GenFile1Name, openMode) )  == '\0'){
    printf("\n*** ERROR, Could not open %s file %s for write. Aborting!\n", 
	   (changeMODE ? "output" : "input"), GenFile1Name );
    cleanexit(11);
  } 
  
  if ( ( genFile2 = fopen( GenFile2Name, openMode) ) == '\0'){
    printf("\n*** ERROR, Could not open %s file %s for write. Aborting!\n", 
	   (changeMODE ? "output" : "input"), GenFile2Name );
    cleanexit(11);
  } 

  if (changeMODE)
    if ( ( genFile3 = fopen( GenFile3Name, "w") ) == '\0'){
    printf("\n*** ERROR, Could not open output file %s for write. Aborting!\n", GenFile3Name );
    cleanexit(11);
  } 
  
  if (InMODE == 2)
    if ( ( genFile3 = fopen( GenFile3Name, "r") ) == '\0'){
      printf("\n*** ERROR, Could not open file %s for read. Aborting!\n", GenFile3Name );
      cleanexit(11);
    }
  
  if ( ( outFile = fopen( OutFileName, "w") ) == '\0'){
    printf("\n*** ERROR, Could not open output file %s for write. Aborting!\n", OutFileName );
    cleanexit(11);
  } 

    
  while ( fgets( LineBuf, sizeof(LineBuf), infile ) )
    {  /* LineBuf := 1 file line */
      
      LineCharPos = 0;				/* parse each token */
      lineNbr++;
      jumpLine = FALSE;
      passLine = FALSE;
      /*  printf("%s",LineBuf); */
      while (!Flush && LineBuf[ LineCharPos ] != '\0' && !jumpLine)
	{ /* scan for new token until EOL */
	  
	  while ( LineBuf[ LineCharPos ] == ' '  ||  /* pass white-space and new-line */
		  LineBuf[ LineCharPos ] == '\t' ||
		  LineBuf[ LineCharPos ] == '\n'    )
	    { LineCharPos++;}
	  
	  tcharpos = 0;
	  Loop = TRUE;
	  
	  while ( Loop )
	    {			/* scan for 1 token & copy it to StrBuf[] */
	      switch ( LineBuf[ LineCharPos ] ){	/* scan until next white-space or new-line */
	      case '\0':	Loop = FALSE;	/* at EOL */
		break;		/* found 1 token !, go store it */
	      case  ' ':
	      case '\t':
	      case '\n':	LineCharPos++;
		                Loop = FALSE;
				break;		/* found 1 token !, go store it */
		
	      default:	StrBuf[ tcharpos++ ] = LineBuf[ LineCharPos++ ];
	      }/* switch */
	    }/* while (Loop) */			/* one token found ! */
	  
	  StrBuf[ tcharpos ] = '\0';  /* append string delimiter ( NULL) */
	  if ( strlen( StrBuf ) ){ 	/* if a non-empty token has been found, */
	    wordType = CheckWord(StrBuf);
	    if ( !Flush && wordType !=0 )  /* check word and return int */      
	      {						
		jumpLine=TRUE;		
		if (procMODE)
		  {			    
		    if ( (inProc) ) 
		      {
			switch (wordType) {
			case 1 : generate("ProcEnd");
			         generate("ProcStart");
			         break; 
			case 2 : generate("ProcCall");
			         break;
			case 3 : generate("ProcEnd");			         
			         break;
			case 4 : generate("ProcEnd");
			         if (InMODE == 0)
				   insert("GenFile1");
				 else
				   insert("GenFile3");
			         procMODE  = FALSE;
				 initMODE = TRUE;
			         break;
			case 5 : printf("WARNING: Tornado parser: Missed wordType 4 !!! ");
			         generate("ProcEnd");
			         insert("GenFile1");
			         procMODE  = FALSE;
				 initMODE = TRUE;
			         break;
			case 6 : break;	
			case 7 : break;		
			}/*switch*/
		      }
		    else
		      {
			switch (wordType) {
			case 1 : generate("ProcStart");
			         break; 
			case 2 : printf("ERROR: Tornado parser: No proc. for\nxs %s\n", StrBuf);
			         cleanexit(11);
			         break;
			case 3 : if (!ProcCalled) /* we have come procs */
			           generate("VarCall");
			         break;
			case 4 : if (ProcCalled) /* we have procs */
			           {
				     if (InMODE == 0)
				       insert("GenFile1");
				     else
				       insert("GenFile3");
				     procMODE  = FALSE;
				     initMODE = TRUE;
				   }
			         break;
			case 5 : printf("**WARNING: Tornado parser: in procMODE found type%d\n",wordType);
			         if (!ProcCalled)
				   printf("WARNING: Tornado parser: Have not seen any procs");
			         break;
			case 6 : break;
			case 7 : generate("xFileName");
			         break;
			}/*switch*/
		      } 		    		      
		  }/*if (procMODE) */
		else
		  if (initMODE)
		    {
		      switch (wordType) {
		      case 1 :
		      case 2 :
		      case 3 :			
		      case 4 : printf("WARNING: Tornado parser: in initMODE found type%d \n",wordType); 			       
			       break;
		      case 5 : generate("Init");/* change "yInit" to "yInit_symb" */
			       break;
		      case 6 : generate("InitEnd");
			       insert("GenFile2");
			       initMODE=FALSE;
			       Flush   =TRUE;			    
			       break;
		      case 7 : break;
		      default : printf("WARNING: Tornado parser missed wordType '%d'", wordType);
		      }/*switch*/
		    }/*if initMODE*/
		else 
		  if (changeMODE) /* change "?" in genFile1 to correct line numbers */
		    {		    
		      switch (wordType){
		      case 1 : break;
		      case 2 : generate("setLineNbr");
			       lineNbr--;
			       passLine=TRUE;
			       chgLineFound=TRUE;
			       break;
		      case 3 : break;
		      case 4 : if (chgLineFound)       /* "/******" */
			         {				   
				   generate("genFile3end");
				   insert("GenFile3"); 
				   chgInitMODE = TRUE; 
				 }
				 break;
		      case 5 : if (chgInitMODE)     /* "yInit" */ 
			         generate("Init"); 
			       break;
		      case 6 : break;
		      case 7 : generate("xFileName");
			       lineNbr++;
			       break;
		      case 8 : insert("GenFile2");   /* "yInitTimer(" */
			       Flush = TRUE;      
			       break;
		      default : printf("WARNING: Tornado parser: in changeMODE: unknown wordType\n");
		      }/*switch*/
		    }/*if changeMODE*/

	      }/* if (wordtype... */
	  }/* if StrBuf*/
	}/* go for the next token */

      if (!passLine) /* if passLine the line will be passed over and not written to file */
	fputs(LineBuf, outFile);

    }/*while (fgets...   ,  go for the next file line */

  fclose ( infile );
  fclose ( genFile1 );
  fclose ( genFile2 );
  fclose ( genFile3 );
  fclose ( outFile ); 
}



/****+*******************************************************************
     main()
************************************************************************/

#ifdef XANSI
 void main( int argc, char *argv[] )	/* ANSI C version */
#else
 main( argc, argv )			/* K&R C version */
  int argc;
  char *argv[];
#endif
{

 boolean this_line_blank = TRUE;
 boolean prev_line_blank = TRUE;
/* boolean path_flag	 = FALSE;	*//* -> FilenamePath not used */
 boolean ALTSUFFIX       = FALSE;				

 char FileBuf[BUF_LEN];
 char Cfg_Filename[NAME_BUF_LEN];
 char In_Filename[NAME_BUF_LEN];	/* In_Filename string, temporary variable */
 char Out_Filename[NAME_BUF_LEN];	/* Out_Filename string, temporary variable */
 char Tmp_Filename[NAME_BUF_LEN];       /* temporary variable */
 char OrgIn_Filename[NAME_BUF_LEN];	/* OrgIn_Filename string */
 char TornadoFileName[MAXPATH + 1];     /* Name of file with Tornado code */
 char TornadoFileName_wo_ext[MAXPATH + 1]; /* Name of file with Tornado code without suffix */
 
 char Filename_wo_ext[NAME_BUF_LEN];
 char FilenamePath[NAME_BUF_LEN];
 char TmpFileName[BUF_LEN];
 char TmpDir[BUF_LEN];
 char command_line[BUF_LEN];
 char cc_arg_buffer[BUF_LEN];
 char line_buffer[2][BUF_LEN];		/*  temporary buffers */
 char l_buffer[BUF_LEN];		/*  temporary buffers */
 char cfg_buffer[BUF_LEN];
 char argv0[NAME_BUF_LEN];		/* argv[0] stripped from path and extension */
 char PathDelim[2];			/* '/'(UNIX) or '\'(DOS) */

 FILE *InFile;				/* stream */
 FILE *OutFile;				/* stream */
 FILE *TmpFile;				/* stream */

 int version = VERSION;			/* version number */

 int i;
 int index;
 int position = 0;			/* temporary variables */
 int InFile_index = 0;			/* argv index for original input file name */
 unsigned int line_buffer_no = 0;

#ifdef XANSI
 int strrpos( char *s, char c);
 int strrpos( char *s, char c);
 boolean isfile( char* filename );
#endif

/*========= Configuration variables =============================*/

 char sccdNAME[100];
 char sccdINFILESUFFIX[100];
 char sccdALTSUFFIX[100];
 char sccdTEMPSUFFIX[100];
 char sccdCPP[100];
 char sccdCPPFLAGS[1000];
 char sccdMACROPREFIX[100];
 char sccdINCLUDE1[100];
 char sccdINCLUDE2[100];
 char sccdOUTFILEREDIR[100];
 char sccdFMOVE[100];
 char sccdDELETE[100];
 char sccdCOPY[100];

 char sccdCOMPILE[10];
 char sccdDEBUG[10];
 /* boolean sccd_debug; Moved to be globally defined [V2.45] */
 char sccdPURGE[10];
 boolean sccd_purge;
 char sccdUSE_HS[10];
 boolean sccd_use_hs;
 char sccdSILENT[10];
/* boolean sccd_silent; Moved to be globally defined [V2.51] */
 char sccdTORNADO[10];
 char sccdTORNADO_EXP[10];

 char sccdTMPDIR[BUF_LEN];
 char sccdTMPDIR2[NAME_BUF_LEN];

 char sccdUSER_CMD1[NAME_BUF_LEN];
 char sccdUSER_CMD2[NAME_BUF_LEN];
 char sccdUSER_CMD3[NAME_BUF_LEN];
 char sccdUSER_CMD4[NAME_BUF_LEN];


/*====== Set the path delimiter dependent on Operating System ======*/

#ifdef UNIX
 PathDelim[0] = '/';
 PathDelim[1] = '\0';
#else
 PathDelim[0] = '\\';
 PathDelim[1] = '\0';
#endif

 SmartCommandLine();		/* initialize SmartCommandLine buffers */

/*========= Strip path from argv[0] and put in argv0 ===============*/

 {
   int pos;
   if ( ( pos = strrpos( argv[0], PathDelim[0]) ) != -1 ){
     strcpy( argv0, argv[0] + (pos+1) );
   }
   else {
     strcpy( argv0, argv[0] );
   }
#ifdef DOS
   if ( ( pos = strrpos( argv0, '.' ) ) != -1 ){ /* strip ".EXE" */
     argv0[pos] = '\0';
   }
#endif
 }

/*========= Initialize defaults (for gcc-like compilers) ===========*/

 strcpy(sccdNAME,		"Default");
 strcpy(sccdINFILESUFFIX,	".c"   );
 strcpy(sccdALTSUFFIX,  	""     );
 strcpy(sccdTEMPSUFFIX,		".i"   );
 strcpy(sccdCPP,		""     );
 strcpy(sccdCPPFLAGS,		""     );
 strcpy(sccdMACROPREFIX,	"-D"   );
 strcpy(sccdINCLUDE1,		"-I"   );
 strcpy(sccdINCLUDE2,		""     );
 strcpy(sccdOUTFILEREDIR,	"-o "  );
 strcpy(sccdFMOVE,		""     );
 strcpy(sccdDELETE,		"rm -f");
 strcpy(sccdCOPY,		"cp"   );

 strcpy(sccdCOMPILE,		"ON"  );
 strcpy(sccdDEBUG,		"OFF" );
 sccd_debug=			FALSE;
 strcpy(sccdPURGE,		"ON"  );
 sccd_purge=			TRUE;
 strcpy(sccdUSE_HS,		"OFF" );
 sccd_use_hs=			FALSE;
 strcpy(sccdSILENT,		"OFF" );
 sccd_silent =			FALSE;
 
 strcpy(sccdTORNADO,		"" ); /* alternative is '-t' */
 sccd_tornado =			FALSE; 
 strcpy(sccdTORNADO_EXP,	"" ); /* alternative is '-e' */ 
 sccd_tornado_exp = 		FALSE;

 strcpy(sccdTMPDIR,		"sccdtmp");
 strcpy(sccdTMPDIR2,		"sccdtmp2");

 strcpy(sccdUSER_CMD1,		"");
 strcpy(sccdUSER_CMD2,		"");
 strcpy(sccdUSER_CMD3,		"");
 strcpy(sccdUSER_CMD4,		"");


/*======================== collect info from sccd.cfg =====================*/

 if ( (getenv( "sctdir" ) != '\0') || (getenv( "SCTDIR" ) != '\0')  ){

   if ( getenv( "sctdir" ) != '\0' ) 
     strcpy( FilenamePath, getenv( "sctdir" ) );
   else
      strcpy( FilenamePath, getenv( "SCTDIR" ) );

   strcat( FilenamePath, PathDelim );	/* FilenamePath := <$sctdir>/ or <$SCTDIR>\ */
   strcpy( TmpFileName, FilenamePath );
   strcat( TmpFileName, argv0 );
   strcat( TmpFileName, ".cfg" );	/* TmpFileName := <FilenamePath><argv[0]>.cfg */

   if ( isfile( TmpFileName ) == TRUE ){
     goto cfg_file_found;
   }

   goto use_defaults;	/* use internal defaults if $sctdir exists but no .cfg file */
 }
 else { /* Create a config-file name */
   strcpy ( Cfg_Filename, argv0 );
   strcat ( Cfg_Filename, ".cfg" );	/* Cfg_Filename := <argv[0]>.cfg */
 }

   /* Look for config-file in current directory */
   strcpy( TmpFileName, Cfg_Filename );
   if ( isfile( TmpFileName ) == TRUE ){
     goto cfg_file_found;
   }

 if ( getenv( "SCCD" ) != '\0' ){
   strcpy( FilenamePath, getenv("SCCD") );
   strcat( FilenamePath, PathDelim );	/* FilenamePath := <$SCCD>/ or <$SCCD>\ */
   strcpy( TmpFileName, FilenamePath );
   strcat( TmpFileName, Cfg_Filename );	/* TmpFileName := <FilenamePath><argv[0]>.cfg */
   if ( isfile( TmpFileName ) == TRUE ){
     goto cfg_file_found;
   }
 }   

 if ( getenv( "HOME" ) != '\0' ){
   strcpy( FilenamePath, getenv("HOME") );
   strcat( FilenamePath, PathDelim );	/* FilenamePath := <$HOME>/ or <$HOME>\ */
   strcpy( TmpFileName, FilenamePath );
   strcat( TmpFileName, Cfg_Filename );	/* TmpFileName := <FilenamePath><argv[0]>.cfg */
   if ( isfile( TmpFileName ) == TRUE ){
     goto cfg_file_found;
   }
 }

use_defaults:
 strcpy ( TmpFileName, "" );	/* clear buffer */
 if ( !( ( argc == 1 ) || (( argc == 2 ) &&
        ( strncmp( argv[1], "-h", strlen("-h") ) == STRING_EQUALITY )) ) ) {
   printf("\n****** WARNING ******\n");

   if ( ( getenv( "sctdir" ) != '\0' ) || ( getenv( "SCTDIR" ) != '\0') ){

     if ( getenv( "sctdir" ) != '\0' ) {
       printf("$sctdir%c%s.cfg", PathDelim[0], argv0 );
     }

     if ( getenv( "SCTDIR" ) != '\0'){
       printf("$SCTDIR%c%s.cfg", PathDelim[0], argv0 );
     }
     printf(" does not exist; Using internal defaults.\n\n" );
   }
   else {
     printf("Could not find a configuration file; Using internal defaults.\n\n" );
   }
 }
 goto defaultparam;

cfg_file_found:
 TmpFile = fopen( TmpFileName, "r");

/*============ copy sccd.cfg to memory @ cfg_buffer  ===========*/
/*		and remove all comments.			*/

 index = 0;
 {
   char c;
   int int_c;
   enum cfg_state_t{ normal, comment, back_slash }  cfg_state;

   cfg_state = normal;
   while ( ( int_c = getc( TmpFile ) ) != EOF ){
     c = (char)int_c; 
     cfg_buffer[index++] = c;
     switch(cfg_state){

       case normal:
		if ( c == '#' ){
		  index-- ;
		  cfg_state = comment;
		  break;
		}

		if ( c == '\\' ){
		  cfg_state = back_slash;
		  break;
		}  

		break;

       case comment:
		if ( c == '\n' ){
		  index--;
		  cfg_state = normal;
		  break;
		}

		index--;
		break;

       case back_slash:
		if ( c == '\"'){
		  cfg_state = normal;
		  break;
		}

		if ( c == '#' ){
		  cfg_state = normal;
		  break;
		}

		cfg_state = normal;
		break;

       default:
		;
     }  /* switch */
   }  /* while */
 }  /* compound statement */

 fclose( TmpFile );
 cfg_buffer[index] = '\0'; /* NULL terminate buffer */
 /* done ! */

/*=========== read in all .cfg parameters into their variables ====================*/

 for ( index = 0; cfg_buffer[index] != '\0' ; index++ ) {

   if ( strncmp( &(cfg_buffer[index]), "sccdINFILESUFFIX", strlen("sccdINFILESUFFIX") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdINFILESUFFIX, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdALTSUFFIX", strlen("sccdALTSUFFIX") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdALTSUFFIX, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdTEMPSUFFIX", strlen("sccdTEMPSUFFIX") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdTEMPSUFFIX, l_buffer );
   }
   
   if ( strncmp( &(cfg_buffer[index]), "sccdNAME", strlen("sccdNAME") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdNAME, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdINCLUDE1", strlen("sccdINCLUDE1") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdINCLUDE1, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdINCLUDE2", strlen("sccdINCLUDE2") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdINCLUDE2, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdCPPFLAGS", strlen("sccdCPPFLAGS") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdCPPFLAGS, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdOUTFILEREDIR", strlen("sccdOUTFILEREDIR") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdOUTFILEREDIR, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdMACROPREFIX", strlen("sccdMACROPREFIX") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdMACROPREFIX, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdCPP", strlen("sccdCPP") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdCPP, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdFMOVE", strlen("sccdFMOVE") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdFMOVE, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdDELETE", strlen("sccdDELETE") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdDELETE, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdCOPY", strlen("sccdCOPY") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdCOPY, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdCOMPILE", strlen("sccdCOMPILE") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     strcpy( sccdCOMPILE	, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdDEBUG", strlen("sccdDEBUG") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "ON") == STRING_EQUALITY ) sccd_debug = TRUE;
     strcpy( sccdDEBUG, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdPURGE", strlen("sccdPURGE") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "OFF") == STRING_EQUALITY ) sccd_purge = FALSE;
     strcpy( sccdPURGE, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdUSE_HS", strlen("sccdUSE_HS") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "ON") == STRING_EQUALITY ) sccd_use_hs = TRUE;
     strcpy( sccdUSE_HS, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdSILENT", strlen("sccdSILENT") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;	/* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "ON") == STRING_EQUALITY ) sccd_silent = TRUE;
     strcpy( sccdSILENT, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdTORNADO", strlen("sccdTORNADO") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;   /* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "-t") == STRING_EQUALITY ) sccd_tornado = TRUE;
     strcpy( sccdTORNADO, l_buffer );
   }
       
   if ( strncmp( &(cfg_buffer[index]), "sccdTORNADO_EXP", strlen("sccdTORNADO_EXP") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;   /* pass '"' */
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ l_buffer[i++] = cfg_buffer[index++]; }
     l_buffer[i] = '\0';
     if ( strcmp( l_buffer , "-e") == STRING_EQUALITY ) 
       if(sccd_tornado)
	 sccd_tornado_exp = TRUE;
       else
	 {
	   printf("#ERROR: In config file sccdTORNADO_EXP = \"-e\" , but Tornado support is not enabled\n");
	   printf("        with sccdTORNADO = \"-t\" in config file\n\n");	 
	   cleanexit(1); 
	 }
     strcpy( sccdTORNADO_EXP, l_buffer );
   }

   /* comparison must be before 'sccdTMPDIR' to be recognised as 'sccdTMPDIR2' */
   if ( strncmp( &(cfg_buffer[index]), "sccdTMPDIR2", strlen("sccdTMPDIR2") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
	    ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
	    ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
	 index++;					/* skip \  */
	 l_buffer[i++] = cfg_buffer[index++];		/* store " | # | \ */
       }
       else {
	 if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
	   break;					/*  yes, end of command ! */
	 }
	 else {
	   l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
	 }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdTMPDIR2, l_buffer );
   }
   
   if ( strncmp( &(cfg_buffer[index]), "sccdTMPDIR", strlen("sccdTMPDIR") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
	    ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
	    ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
	 index++;					/* skip \  */
	 l_buffer[i++] = cfg_buffer[index++];		/* store " | # | \ */
       }
       else {
	 if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
	   break;					/*  yes, end of command ! */
	 }
	 else {
	   l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
	 }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdTMPDIR, l_buffer );
   }

  

   if ( strncmp( &(cfg_buffer[index]), "sccdUSER_CMD1", strlen("sccdUSER_CMD1") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
         index++;					/* skip \  */
	 l_buffer[i++] = cfg_buffer[index++];		/* store "| # | \ */
       }
       else {
         if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
           break;					/*  yes, end of command ! */
         }
         else {
           l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
         }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdUSER_CMD1, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdUSER_CMD2", strlen("sccdUSER_CMD2") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
         index++;					/* skip \  */
         l_buffer[i++] = cfg_buffer[index++];		/* store " | # | \ */
       }
       else {
         if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
           break;					/*  yes, end of command ! */
         }
         else {
           l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
         }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdUSER_CMD2, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdUSER_CMD3", strlen("sccdUSER_CMD3") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
         index++;					/* skip \  */
         l_buffer[i++] = cfg_buffer[index++];		/* store " | # | \ */
       }
       else {
         if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
	   break;					/*  yes, end of command ! */
         }
         else {
           l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
         }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdUSER_CMD3, l_buffer );
   }

   if ( strncmp( &(cfg_buffer[index]), "sccdUSER_CMD4", strlen("sccdUSER_CMD4") ) == STRING_EQUALITY ){
     while ( ( cfg_buffer[index] != '\0' ) && ( cfg_buffer[index] != '\"' ) ){ index++; }
     i = 0;
     index++;						/* pass 1:st '"' */
     while ( cfg_buffer[index] != '\0'){
       if ( ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\"') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '#') ) ||
            ( ( cfg_buffer[index] == '\\' ) && ( cfg_buffer[index+1] == '\\') ) ) {
         index++;					/* skip \  */
	 l_buffer[i++] = cfg_buffer[index++];		/* store "| # | \ */
       }
       else {
         if ( cfg_buffer[index] == '\"' ){		/* 2:nd " ? */
           break;					/*  yes, end of command ! */
         }
         else {
           l_buffer[i++] = cfg_buffer[index++];		/* copy other character */
         }
       }
     }
     l_buffer[i] = '\0';				/* terminate command */
     strcpy( sccdUSER_CMD4, l_buffer );
   }
 }

defaultparam:
 ;

/*========================= Version =====================================*/

 if ( ( argc == 2 ) && (( strncmp( argv[1], "-v", strlen("-v") ) == STRING_EQUALITY )) ) {
   printf("\n%s (SDT C-Compiler Driver) V%.1d.%.2d\n\n", argv0, (version / 100), (version % 100) );
   cleanexit(1);
 }

/*========================= sccd command line options ===================*/

 /* check if there are any command line options.  
    receive options and remove them from argv[] and decrease argc.
    to add more options: 1. or-statement to while-statement 
                         2. if-statement in while-loop
			 3. help information
			 4. global variabel
			 5. support for the option to be declared in config-file
    */
 
 while( (argc >= 2) && ( 
			(( strncmp (argv[1], "-t", strlen("-t") ) == STRING_EQUALITY )) ||   /* tornado */
			(( strncmp (argv[1], "-e", strlen("-e") ) == STRING_EQUALITY ))      /*expanded file */
			)
	){
    
   /* ===== option '-t' : Tornado code generation  =====*/
        
   /* If there is nothing after '-t' in the commandline information about Tornado 
      will be printed and a clean exit made. */
   if ( ( argc == 2) && (( strncmp (argv[1], "-t", strlen("-t") ) == STRING_EQUALITY )) ){
     printf("\n%s (SDT C-Compiler Driver) V%.1d.%.2d \n\n", argv0, (version / 100), (version %100) );
     printf("For Tornado code generation use option '-t':\n\n"); 
     printf("         %s -t [-e] cc [compiler options] <filename>%s \n\n\n", argv0, sccdINFILESUFFIX ); 
     sccd_tornado = TRUE ; /* set the boolean flag to enable tornado changes */
     cleanexit(2);
   }
   else
     /* If there is more after '-t' then the settings for Tornado are made */ 
     if ( ( argc > 2) && (( strncmp (argv[1], "-t", strlen("-t") ) == STRING_EQUALITY )) ){ 
       if (!sccd_tornado)
	 printf("\nOption '-t' : Tornado code generation \n");
       else {
	 printf("Option '-t' : Tornado code generation already enabled,\n");
	 printf("              but for extra safety it will be enabled again");
       }
       sccd_tornado = TRUE ; /* set the boolean flag to enable tornado changes */          
     } 

   
   /* ===== option '-e' : Tornado code generation for an expanded file =====*/
   
   if ( ( argc > 2) && (( strncmp (argv[1], "-e", strlen("-e") ) == STRING_EQUALITY )) ){
     if (sccd_tornado){
       if (!sccd_tornado_exp)
	 printf("Option '-e' : Tornado code generation with expanded file \n");  
       else{
	 printf("Option '-e' : Tornado code generation with expanded file already enabled");
	 printf("              but for extra safety it will be enabled again");
       }
      sccd_tornado_exp = TRUE;  
     }
     else
       {
	 printf("#ERROR: Option '-e' received, but Tornado support is not enabled\n");
	 printf("        with command line option '-t' or with sccdTORNADO in config file\n\n");	 
	 cleanexit(1);
       }
   }

      
   /* ==== remove received option ====
      remove option argv[1] from command line arguments to make sure that
      the rest of this program will not be confused by this option since
      there has not been any support for options earlier */     
   { 	
     int opt_pos = 1;
     int tmp_argc;
     char* tmp_argv[MAX_ARGS];      
     
     tmp_argc = argc;
     
     for (index=0; index < argc ; index++)        /* copy argv to tmp_argv */  
       tmp_argv[index] = strdup( argv[index] );     
     
     argc = tmp_argc-1;
     
     for (index=opt_pos; index < argc ; index++)
       argv[index] = strdup( tmp_argv[index+1] ); /* copy tmp_argv to argv but 
						     skip the option */    
     if( !sccd_silent){ /* for debug purpose */     
       printf("New command line: ");
       for (index=0; index < argc ; index++)
	 printf("%s ", argv[index] );
       
       printf("\n");
     }

     for (index=0; index < tmp_argc; index++)     /* free memory */
       if ( tmp_argv[index] )
	 free( tmp_argv[index] );	     
   }  

 printf("\n");

 } /* end of while */



/*========================= Usage =====================================*/

 if ( ( argc == 1 ) || (( argc == 2 ) && ( strncmp( argv[1], "-h", strlen("-h") ) == STRING_EQUALITY )) ) {
   printf("\n%s (SDT C-Compiler Driver) V%.1d.%.2d ", argv0, (version / 100), (version % 100) );
   printf("Syntax:\n\
    %s [-t] <C-compiler command line> <ret>  - Execute ! ('-t' for Tornado)\n\
 or %s<ret>                                  - print %s.cfg variables' values\n\
 or %s -h [ | more]<ret>                     - as above + extra help\n\
 or %s -v <ret>                              - print version number\n\n\
 If run in SDT mode, it uses $sctdir%c%s.cfg or $SCTDIR%c%s.cfg as\n\
 configuration file, else, %s searches for %s.cfg in:\n\
 current dir, $SCCD, and $HOME ;\n\
 If %s.cfg not found it uses hard-coded defaults suitable for GCC.\n",
     argv0, argv0, argv0, argv0, argv0, PathDelim[0], argv0, PathDelim[0], argv0, argv0, argv0, argv0 );


 if ( TmpFileName[0] != '\0' ){
   if (  (getenv( "sctdir" ) != '\0') || (getenv( "SCTDIR" ) != '\0') ){
     printf("\n* %s is running in SDT mode, using $%s,\n  and %s as configuration file.\n",
       argv0, (getenv( "sctdir" ) ? "sctdir" : "SCTDIR" ), TmpFileName );
   }
   else {
     printf("\n* %s is running standalone,\n  using %s as configuration file.\n", argv0, TmpFileName);
   }
 }
 else { /* did not find a .cfg file */
   printf("\n****** WARNING ******\n");
   if ( ( getenv( "sctdir" ) != '\0' ) || ( getenv( "SCTDIR" ) != '\0') ){

     if ( getenv( "sctdir" ) != '\0' ) {
       printf("$sctdir%c%s.cfg", PathDelim[0], argv0 );
     }

     if ( getenv( "SCTDIR" ) != '\0'){
       printf("$SCTDIR%c%s.cfg", PathDelim[0], argv0 );
     }
     printf(" does not exist; Using internal defaults.\n\n" );
   }
   else {
     printf("Could not find a configuration file; Using internal defaults.\n\n" );
   }
 }
   if ( ( argc == 2) && ( strncmp( argv[1], "-h", strlen("-h") ) == STRING_EQUALITY) ){
     printf("\n%s actions:\n", argv0 );
     printf("* receive %s command line options\n", argv0 );
     printf("* execute an optional first user defined command.\n");
     printf("* create a directory for temporary files and the preprocessed %s files.\n", sccdINFILESUFFIX );
     printf("* execute an optional second user defined command.\n");
     printf("* run a C-preprocessor pass to expand all macros.\n");
     printf("* execute an optional third user defined command.\n");
     printf("* pretty print the file.\n");
     printf("* optional clean-up of the temporary directory.\n");
     printf("* optionally copy .hs files to temporary directory.\n");
     printf("* execute an optional fourth user defined command.\n");
     printf("* optionally compile, i.e. run the original command line.\n");
     printf("* optional clean-up of the sub-directory, but leave the preprocessed\n\
  %s file(s) for debugging purposes.\n",
		sccdINFILESUFFIX );
     printf("\n- Exit codes:  -  > 0 => abort\n");
     printf("  code\taction\n");
     printf("  -------------------\n");
     printf("  0\ton success !\n");
     printf("  1\tafter printing \"help\".\n");
     printf("  2\tno %s file.\n", sccdINFILESUFFIX );
     printf("  3\tcould not open InFile%s\n", sccdINFILESUFFIX );
     printf("  4\tcould not open InFile.<sccdTEMPSUFFIX> for write.\n");
     printf("  5\tsccdMOVE or sccdOUTFILEREDIR needs to be defined in %s.\n", TmpFileName );
     printf("  6\tcould not open InFile.<sccdTEMPSUFFIX> for read.\n");
     printf("  7\tcould not open/create TmpDir%cInFile%s\n", PathDelim[0], sccdINFILESUFFIX );
     printf("  8\tcould not open input response-file for read.\n" );
     printf("  9\tcould not open/create the compile response-file for write.\n");
     printf("  10\tcould not open/create the preprocessor response-file for write.\n\n" );
   }

   printf("\nThese are the current values of the variables that control %s's behaviour:\n", argv0 );

   if ( ( argc == 2) && (strncmp( argv[1], "-h", strlen("-h") ) == STRING_EQUALITY) ){
     printf("\n** To make a new %s.cfg file, cut from \"#%s.cfg\" until the end and paste the **", argv0, argv0 );
     printf("\n** text into an editor. Edit the configuration parameters and save as %s.cfg **", argv0 );
     printf("\n\n# %s.cfg V%.1d.%.2d", argv0, (version / 100), (version % 100) );
     printf("\n\n# Please NOTE that the first character in an option\n#  may NOT be a white-space !\n");
   }

   printf("\nsccdNAME         = \"%s\"  # The detailed compiler definition\n\
\t\t\t # is found in your current scttypes.h\n", sccdNAME );

   printf("sccdINFILESUFFIX = \"%s\"  # %s\n", sccdINFILESUFFIX,
     "The file name suffix of the In-file(s),\n\
\t\t\t # Default \".c\" "
   );

   printf("sccdALTSUFFIX    = \"%s\"  # %s\n", sccdALTSUFFIX,
     "The alternative file name suffix of the In-file(s),\n\
\t\t\t # Default \"\" "
   );

   printf("sccdTEMPSUFFIX    = \"%s\"  # %s\n", sccdTEMPSUFFIX,
     "The file name suffix of the temporary file,\n\
\t\t\t # Default \".i\" "
   );

   printf("sccdCPP          = \"%s\"  # %s\n",
     (
       sccdCPP
     ),
     "Alternate name for CPP.\n\
\t\t\t # Used for preprocessing if different from \"\"."
   );

   printf("sccdCPPFLAGS     = \"%s\"  # %s\n",
     (
       sccdCPPFLAGS
     ),
     "C-COMPILER DEPENDENT!!\n\
\t\t\t # Enable CPP and do not remove comments. \n\
\t\t\t # Default for gcc = \"-P -E -C\" (and cc = \"-C -P\")"
   );

   printf("sccdMACROPREFIX  = \"%s\"  # %s\n",
     (
       sccdMACROPREFIX
     ),
     "CPP Command-line MACRO prefix. Default \"-D\""
   );

   printf("sccdINCLUDE1     = \"%s\"  # %s\n",
     (
       sccdINCLUDE1
     ),
     "CPP Command-line include-path prefix.\n\
\t\t\t # Default \"-I\""
   );

   printf("sccdINCLUDE2     = \"%s\"  # %s\n",
     (
       sccdINCLUDE2
     ),
     "Alternate CPP Command-line include-path prefix.\n\
\t\t\t # Default \"\""
   );

   printf("sccdOUTFILEREDIR = \"%s\"  # %s\n",
     (
       sccdOUTFILEREDIR
     ),
     "Character sequence to control CPP output file name.\n\
\t\t\t # If empty, use sccdFMOVE instead."
   );

   printf("sccdFMOVE        = \"%s\"  # %s\n",
     (
       sccdFMOVE
     ),
     "O/S forced file move or copy command.\n\
\t\t\t # Used instead of OUTFILEREDIR. Default: \"\" "
   );

   printf("sccdDELETE       = \"%s\"  # %s\n",
     (
       sccdDELETE
     ),
     "O/S forced delete file command.\n\
\t\t\t # Default: \"rm -f \" "
   );

   printf("sccdCOPY         = \"%s\"  # %s\n\n",
     (
       sccdCOPY
     ),
     "O/S normal copy command. Default: \"cp \" "
   );

   printf("sccdCOMPILE      = \"%s\"  # %s\n",
     (
       sccdCOMPILE
     ),
     "Controls whether the final compilation pass\n\
\t\t\t # should be run or not. Default: \"ON\""
   );

   printf("sccdDEBUG        = \"%s\"  # %s%s\n",
     (
       sccd_debug ?
       "ON" :
       "OFF"
     ),
     ( sccd_debug ? "Disable" : "Enable" ),
     " execution.\n\
\t\t\t # Values are: \"ON\"  and Default = \"OFF\""
   );

   printf("sccdPURGE        = \"%s\"  # %s%s\n",
     (
       sccd_purge ?
       "ON" :
       "OFF"
     ),
     ( sccd_purge ? "Purge" : "Leave" ),
     " temporary files.\n\
\t\t\t # Values are: \"OFF\" and Default = \"ON\" "
   );

   printf("sccdUSE_HS       = \"%s\"  # %s%s\n",
     (
       sccd_use_hs ?
       "ON" :
       "OFF"
     ),
     ( sccd_use_hs ? "Enable" : "Disable" ),
     " use of *.hs files.    \n\
\t\t\t # Values are: \"ON\"  and Default = \"OFF\""
   );

   printf("sccdSILENT       = \"%s\"  # %s%s\n\n",
     (
       sccd_silent ?
       "ON" :
       "OFF"
     ),
     ( sccd_silent ? "Disable" : "Enable" ),
     " trace printout.    \n\
\t\t\t # Values are: \"ON\"  and Default = \"OFF\""
   );

   printf("sccdTORNADO       = \"%s\" %s%s\n\n",
     (
       sccd_tornado ?
       "-t" :
       ""
     ),
     ( sccd_tornado ? "# Disable" : "  # Enable" ),
     " Tornado code generation.    \n\
\t\t\t # Values are: \"-t\"  and Default = \"\""
   );

/*
   printf("sccdTORNADO_EXP   = \"%s\" %s%s\n\n",
	  (
	   sccd_tornado_exp ?
	   "-e" :
	   ""
	   ),
	  ( sccd_tornado_exp ? "# Disable" : "  # Enable" ),
	  " Tornado code generation for an expanded file.    \n\
\t\t\t # Values are: \"-e\"  and Default = \"\""
	  );
*/
   
   printf("\n\
\t\t\t # to enter # in sccdUSER_CMDx & sccdTMPDIR & sccdTMPDIR2 use \\#\n\
\t\t\t # to enter \" in sccdUSER_CMDx & sccdTMPDIR & sccdTMPDIR2 use \\\"\n\
\t\t\t # to enter \\ in sccdUSER_CMDx & sccdTMPDIR & sccdTMPDIR2 use \\\\\n\n"
   );

   printf("sccdTMPDIR       = \"%s\"  # %s\n\n",
     (
       sccdTMPDIR
     ),
     "Temporary directory for the preprocessing. \n\
\t\t\t # Default \"sccdtmp\"; Setting sccdTMPDIR = \"\" or \".\"\n\
\t\t\t # in the configuration (.cfg) file suppresses\n\
\t\t\t # directory creation. A dir name starting with\n\
\t\t\t # \"\\ or \"/ or Drive-name: ( e.g. \"C:\\TEMP\") \n\
\t\t\t # that it refers to an absolute path."
   );

   printf("sccdTMPDIR2      = \"%s\"  # %s\n\n",
     (
      sccdTMPDIR2
      ),
      "Replaces sccdTMPDIR as temporary directory when Tornado code generation is enabled. \n\
\t\t\t # In addition to files in normal sccdTMPDIR this contains two (2)\n\
\t\t\t # Tornado code generation files.\n\
\t\t\t # Default \"sccdtmp2\"; Setting sccdTMPDIR2 = \"\" or \".\"\n\
\t\t\t # in the configuration (.cfg) file suppresses\n\
\t\t\t # directory creation."
   );

   printf("sccdUSER_CMD1    = \"%s\"\n\t\t\t # %s\n\n",
     (
       sccdUSER_CMD1
     ),
     "User defined command.\n\t\t\t # Will be used as is for command line."
   );


 /* replace "%d" with "TmpDir" and replace "%p" with "FilenamePath" and */
 /* replace '%f' with 'Filename_wo_ext' for all occurences */
   printf("sccdUSER_CMD2    = \"%s\"\n\t\t\t # %s\n\n",
     (
       sccdUSER_CMD2
     ),
     "User defined command. Available pseudo variables:\n\
\t\t\t # %f expands to In-file name without extension,\n\
\t\t\t # %p expands to In-file path and \n\
\t\t\t # %d expands to the value of sccdTMPDIR.\n\
\t\t\t #  E.g. echo \\\"Pre-processed C-file = %p/%d/%f.c\\\""
   );

   /* as sccdCMD2 */
   printf("sccdUSER_CMD3    = \"%s\"\n\t\t\t # %s\n\n",
     (
       sccdUSER_CMD3
     ),
     "User defined command. See sccdUSER_CMD2."
   );


   /* as sccdCMD2 */
   printf("sccdUSER_CMD4    = \"%s\"\n\t\t\t # %s\n\n",
     (
       sccdUSER_CMD4
     ),
     "User defined command. See sccdUSER_CMD2."
   );

   printf("#\t\t\tCopyright (c) by Telelogic AB, 1993 - 2000\n\n");
   cleanexit(1);
 }

/*========================== Optional user command 1 ==================*/

 if ( sccdUSER_CMD1 != "" ){
   strcpy( command_line, sccdUSER_CMD1 ); /* read the User defined command */
 }
 else {
   strcpy( command_line, "" );
 }

 if ( sccdUSER_CMD1[0] != '\0' ){
   if ( !sccd_silent ){
     printf("[%d]user command1=    %s\n", clc++, command_line );
   }
   if ( !sccd_debug ) system( command_line );
 }

/*=================== Command line parser =========================================*/

 Load( argc, argv );		/* initialize SmartCommandLine Args */

	/* initialize all temporary buffers */
  for ( index = 0 ; index < NAME_BUF_LEN ; ){ OrgIn_Filename[index++] = '\0'; }
  for ( index = 0 ; index < NAME_BUF_LEN ; ){ Filename_wo_ext[index++] = '\0'; }
  for ( index = 0 ; index < NAME_BUF_LEN ; ){ In_Filename[index++] = '\0'; }
  for ( index = 0 ; index < NAME_BUF_LEN ; ){ Out_Filename[index++] = '\0'; }
  for ( index = 0 ; index < NAME_BUF_LEN ; ){ FilenamePath[index++] = '\0'; }
  for ( index = 0 ; index < BUF_LEN ; ){ TmpDir[index++] = '\0'; }
  for ( index = 0 ; index < BUF_LEN ; ){ command_line[index++] = '\0'; }
  for ( index = 0 ; index < BUF_LEN ; ){ line_buffer[0][index++] = '\0'; }
  for ( index = 0 ; index < BUF_LEN ; ){ line_buffer[1][index++] = '\0'; }
  for ( index = 0 ; index < BUF_LEN ; ){ cc_arg_buffer[index++] = '\0'; }


 /* loop over all the command line arguments and extract the relevant
    information used for cpp, pretty_printer and C-compiler */

 for ( index = 0; index < GetNum(); ++index ) {

   /* look for command line defines */
   if ( sccdMACROPREFIX[0] != '\0' ) { /* if sccdMACROPREFIX defined */
     if ( isspace(sccdMACROPREFIX[strlen(sccdMACROPREFIX)-1]) ){ /* prefix ends with 'whitespace' */
       if ( ( strncmp( Get(index), sccdMACROPREFIX, strlen(sccdMACROPREFIX) - 1 ) == STRING_EQUALITY ) &&
            ( strlen( Get(index) ) == ( strlen(sccdMACROPREFIX) - 1 ) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
         strcat( cc_arg_buffer, Get(index+1) );
         strcat( cc_arg_buffer, " " );
       }
     }
     else {
       if ( ( strncmp( Get(index), sccdMACROPREFIX, strlen(sccdMACROPREFIX) ) == STRING_EQUALITY )  &&
            ( strlen(Get(index) ) > strlen(sccdMACROPREFIX) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
       }
     }
   }

   /* look for added include paths */
   if ( sccdINCLUDE1[0] != '\0' ) { /* if sccdINCLUDE1 defined */
     if ( isspace(sccdINCLUDE1[strlen(sccdINCLUDE1)-1]) ){ /* prefix ends with 'whitespace' */
       if ( ( strncmp( Get(index), sccdINCLUDE1, strlen(sccdINCLUDE1) - 1 ) == STRING_EQUALITY ) &&
            ( strlen( Get(index) ) == ( strlen(sccdINCLUDE1) - 1 ) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
         strcat( cc_arg_buffer, Get(index+1) );
         strcat( cc_arg_buffer, " " );
       }
     }
     else {
       if ( ( strncmp( Get(index), sccdINCLUDE1, strlen(sccdINCLUDE1) ) == STRING_EQUALITY )  &&
            ( strlen( Get(index) ) > strlen(sccdINCLUDE1) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
       }
     }
   }

   /* look for added EXTRA include paths */
   if ( sccdINCLUDE2[0] != '\0' ) { /* if sccdINCLUDE2 defined */
     if ( isspace(sccdINCLUDE2[strlen(sccdINCLUDE2)-1]) ){ /* prefix ends with 'whitespace' */
       if ( ( strncmp( Get(index), sccdINCLUDE2, strlen(sccdINCLUDE2) - 1 ) == STRING_EQUALITY ) &&
            ( strlen( Get(index) ) == ( strlen(sccdINCLUDE2) - 1 ) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
         strcat( cc_arg_buffer, Get(index+1) );
         strcat( cc_arg_buffer, " " );
       }
     }
     else {
       if ( ( strncmp( Get(index), sccdINCLUDE2, strlen(sccdINCLUDE2) ) == STRING_EQUALITY )  &&
            ( strlen( Get(index) ) > strlen(sccdINCLUDE2) ) ){
         strcat( cc_arg_buffer, Get(index) );
         strcat( cc_arg_buffer, " " );
       }
     }
   }


   if ( ( InFile_index == 0 ) && ( strlen(sccdINFILESUFFIX) != 0 )){
     /* look for the source file name, i.e. the sccdINFILESUFFIX-file */
     if ( (strncmp( Get(index), "-", strlen("-") ) != STRING_EQUALITY) ){
       position = strlen( Get(index) );		/* no leading '-' */
       if ( strncmp( &( Get(index)[position - strlen(sccdINFILESUFFIX)]), sccdINFILESUFFIX, strlen(sccdINFILESUFFIX) ) == STRING_EQUALITY ){
         strcpy( In_Filename, Get(index) );	/* ends with 'sccdINFILESUFFIX' ! */
         position = position -strlen(sccdINFILESUFFIX);		/* point at start of suffix */
         InFile_index = index;			/* use as a flag here and a value at 'Compile' */
       }
     } /* found token without leading '-' and with "sccdINFILESUFFIX" !! */
   }

   if ( ( InFile_index == 0 ) && ( strlen(sccdALTSUFFIX) != 0 ) ){
   /* look for the source file name, i.e. the sccdALTSUFFIX-file */
     if ( (strncmp( Get(index), "-", strlen("-") ) != STRING_EQUALITY) ){
       position = strlen( Get(index) );		/* no leading '-' */
       if ( strncmp( &( Get(index)[position - strlen(sccdALTSUFFIX)]), sccdALTSUFFIX, strlen(sccdALTSUFFIX) ) == STRING_EQUALITY ){
         strcpy( In_Filename, Get(index) );	/* ends with 'sccdALTSUFFIX' ! */
         position = position -strlen(sccdALTSUFFIX);		/* point at start of suffix */
         ALTSUFFIX = TRUE;
         InFile_index = index;			/* use as a flag here and a value at 'Compile' */
       }
     } /* found token without leading '-' and with "sccdALTSUFFIX" !! */
   }
 }

 if ( InFile_index == 0 ){
   if ( strlen(sccdALTSUFFIX) == 0 ){
     printf("\n*** ERROR, no '%s' file found on command line. Aborting!\n", sccdINFILESUFFIX );
   }
   else {
     printf("\n*** ERROR, no '%s' or '%s' file found on command line. Aborting!\n", sccdINFILESUFFIX, sccdALTSUFFIX );
   }
   cleanexit(2);
 }

 if ( ALTSUFFIX ) strcpy( sccdINFILESUFFIX, sccdALTSUFFIX );
/* save original generated sccdINFILESUFFIX file name. This can be changed in Tornado section */
 strcpy( OrgIn_Filename, In_Filename );

/* create a base filename ( without a sccdINFILESUFFIX ) to be used below */
 index = strrpos( In_Filename, PathDelim[0] );
 if ( index != -1 ){ /* path exist => separate path and file name! */
   strncpy( FilenamePath, In_Filename, index );
   strncpy( Filename_wo_ext, In_Filename + ( index + 1 ), position - index - 1  );
  /* path_flag = TRUE; */
 }
 else {
   strcpy( FilenamePath, "." );
   strncpy( Filename_wo_ext, In_Filename, position );
   Filename_wo_ext[position] = '\0';
 }

/*========================== Create a temporary directory ====================*/

/* create temporary directory := "sccdTMPDIR" or Default := "./sccddir" 
   if Tornado enabled temporary directory := "sccdTMPDIR2" or Default := "./sccdtmp2" */
 if (!sccd_tornado)
   strcpy( TmpDir, sccdTMPDIR );
 else
   strcpy( TmpDir, sccdTMPDIR2 );

 if ( TmpDir[0] != '\0' ){ /* => TmpDir is different from current directory */
   strcpy( command_line, "mkdir ");
     if ( ( FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
    }
   strcat( command_line, TmpDir);

   /* test if TmpDir exists */
   strcpy( TmpFileName, "" );			/* clear buffer */
   if ( ( FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
     strcat( TmpFileName, FilenamePath );
     strcat( TmpFileName, PathDelim );
   }
   strcat( TmpFileName, TmpDir);

   if( ( TmpFile = fopen( TmpFileName, "r") ) == '\0' ){ /* if TmpDir does not exist */
     if ( !sccd_silent ){
       printf("[%d]create dir   =    %s\n", clc++, command_line );
     }
     if( !sccd_debug ) system( command_line );
   }
 }

 if ( TmpDir[0] == '\0' ){ strcat( TmpDir, "." ); } /* if TmpDir == "" then TmpDir = "." */

/*========================== Tornado parser pass 1   =======================*/

/* Filename.c -> "sccdTMPDIR2"/sctsymb.c or "sccdTMPDIR2"/sctsymb.t */

 if (sccd_tornado)
   {        
     /* set file names for tornado files */

     strcpy( TmpFileName, "" );			/* clear buffer */
     if ( FilenamePath[0] != '.' ){
       strcat( TmpFileName, FilenamePath );
       strcat( TmpFileName, PathDelim );
     }
     if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
       strcat( TmpFileName, TmpDir );
       strcat( TmpFileName, PathDelim );
     }
     
     sprintf(GenFile1Name, "%sgen1.t", TmpFileName);
     sprintf(GenFile2Name, "%sgen2.t", TmpFileName);
     sprintf(GenFile3Name, "%sgen3.t", TmpFileName);     
     sprintf(TornadoFileName_wo_ext,"%ssctsymb", TmpFileName);     
     
     strcat( TmpFileName, "sctsymb" );
     
     if (!sccd_tornado_exp)
       strcat( TmpFileName, sccdINFILESUFFIX ); /* or should it be '.c' */    
     else
       strcat( TmpFileName, ".t" );      
    
     strcpy(TornadoFileName, TmpFileName); 
     
     
     TornadoParse( OrgIn_Filename , TornadoFileName , 0); 

     if (!sccd_tornado_exp)
       {
	 printf("Tornado code generation complete.\n\nResult file: \"%s\"\n\n", TornadoFileName);
	 cleanexit(0);
       }  

      if ( !sccd_silent ){
       printf("[%d]tornado pass 1 =  %s => %s \n", clc++, OrgIn_Filename, TornadoFileName );
     }
      
   }
 
/*========================== Optional user command 2 ==================*/


 if ( sccdUSER_CMD2 != "" ){
   strcpy( line_buffer[0], sccdUSER_CMD2 ); /* read the User defined command */

 /* copy all chars in 'line_buffer[0]' up to '%f' or until '\0' to command_line */
 /* replace "%d" with "TmpDir" and replace "%p" with "FilenamePath" and */
 /* replace '%f' with 'Filename_wo_ext' for all occurences */

   index = 0;
   command_line[0] = '\0';		/* command_line[] = "" */
   line_buffer[1][1] = '\0';		/* line_buffer[1] = "?" */

   while ( line_buffer[0][index] != '\0' ) {
     if( strncmp( &line_buffer[0][index],
	  "%f",
          strlen("%f") ) == STRING_EQUALITY ){
       /* pass "%f" */
       index = index + strlen("%f");
       strcat( command_line, Filename_wo_ext );
     }
     if( strncmp( &line_buffer[0][index],
          "%p",
          strlen("%p") ) == STRING_EQUALITY ){
       /* pass "%p" */
       index = index + strlen("%p");
       strcat( command_line, FilenamePath );
     }
     if( strncmp( &line_buffer[0][index],
          "%d",
          strlen("%d") ) == STRING_EQUALITY ){
       /* pass "%d" */
       index = index + strlen("%d");
       strcat( command_line, TmpDir );
     }
     if( line_buffer[0][index] == '\0' ) break;
     line_buffer[1][0] = line_buffer[0][index++];
     strcat( command_line, line_buffer[1]);
   }      
   line_buffer[1][0] = '\0';
   strcat( command_line, line_buffer[1] );
 }
 else {
   strcpy( command_line, "" );
 }

 if ( sccdUSER_CMD2[0] != '\0' ){
   if ( !sccd_silent ){
     printf("[%d]user command2=    %s\n", clc++, command_line );
   }
   if ( !sccd_debug ) system( command_line );
 }

/*========================== CPP ======================================*/

/* Filename.c -> "sccdTMPDIR"/Filename.<sccdTEMPSUFFIX> */

 /* error test */
 strcpy( TmpFileName, OrgIn_Filename );
 if ( !sccd_debug ){
   if( ( TmpFile = fopen( TmpFileName, "r") ) == '\0' ){
     printf("\n*** ERROR, Could not open %s for read. Aborting!\n", TmpFileName );
     cleanexit(3);
   }
   else  fclose( TmpFile );
 }

 strcpy( TmpFileName, "" );			/* clear buffer */
 if ( (FilenamePath[0] != '.') && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
   strcat( TmpFileName, FilenamePath );
   strcat( TmpFileName, PathDelim );
 }
 if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
   strcat( TmpFileName, TmpDir );
   strcat( TmpFileName, PathDelim );
 }
 strcat( TmpFileName, Filename_wo_ext );
 strcat( TmpFileName, sccdTEMPSUFFIX );
 if ( !sccd_debug ){
   if( ( TmpFile = fopen( TmpFileName, "r") ) != '\0' ){
     fclose( TmpFile );
     if( ( TmpFile = fopen( TmpFileName, "r+") ) == '\0' ){
       printf("\n*** ERROR, Could not write to %s . Aborting!\n", TmpFileName );
       cleanexit(4);
     }
     else fclose( TmpFile );
   }
 }
 /* end of error test */

 for ( i = 0; i < BUF_LEN;  i++ ) CompileLine[i] = '\0';	/* clear the compile line buffer */
 for ( i = 0; i < BUF_LEN;  i++ ) CompileLine1[i] = '\0';	/* clear the extra compile line buffer */
 line_buffer[0][0] = '\0';
 line_buffer[1][0] = '\0';

 if ( sccdCPPFLAGS[0] != '\0' ){
   strcpy( line_buffer[line_buffer_no ^ 1], sccdCPPFLAGS );	/* copy sccdCPPFLAGS to line_buffer */
 }
 else {
   line_buffer[line_buffer_no ^ 1][0] = '\0';			/* clear line_buffer */
 }

 if ( sccdCPP[0] != '\0' ){
   strcpy( command_line, sccdCPP );				/* use sccdCPP */
 }
 else {
   strcpy( command_line, Get(1) );			/* use compiler name from compile command */
 }

 strcat( command_line, " " );

 /* the command_line now contains the name of the preprocessor ! */

 if ( ( strncmp( command_line, "gcc", strlen("gcc") ) == STRING_EQUALITY ) ||
      ( strncmp( command_line, "g++", strlen("g++") ) == STRING_EQUALITY ) ){
   if ( (line_buffer[line_buffer_no ^ 1][0] == '\0') ||
        (line_buffer[line_buffer_no ^ 1][0] >= 0x7F) ){
     strcpy( line_buffer[line_buffer_no ^ 1], "-C -P -E" );
   }

   strcat( CompileLine, line_buffer[line_buffer_no ^ 1] );
   strcat( CompileLine, " " );
 }
 else {
   if ( (line_buffer[line_buffer_no ^ 1][0] == '\0') ||
        (line_buffer[line_buffer_no ^ 1][0] >= 0x7F) )/* assume Sun 'cc' */
     strcpy( line_buffer[line_buffer_no ^ 1], "-C -P" );
   strcat( CompileLine, line_buffer[line_buffer_no ^ 1] );
   strcat( CompileLine, " " );
 }

 strcat( CompileLine, cc_arg_buffer );		/* add command line macros and include paths */
 strcat( CompileLine, OrgIn_Filename );		/* add name of file to preprocess */


 if ( sccdOUTFILEREDIR[0] != '\0' ){		/* last part of CPP command line for */
   strcat( CompileLine1, " " );			/*  compilers with output-redirect capability */
   strcat( CompileLine1, sccdOUTFILEREDIR );
   if ( (FilenamePath[0] != '.') && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
     strcat( CompileLine1, FilenamePath );
     strcat( CompileLine1, PathDelim );
   }
   if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
     /* TmpDir != "" or "." */
     strcat( CompileLine1, TmpDir );
     strcat( CompileLine1, PathDelim );
   }
   strcat( CompileLine1, Filename_wo_ext );
   strcat( CompileLine1, sccdTEMPSUFFIX );
 }

 if ( FileArgs != 0 ){				/* if a response file was used, insert it in line */
   FILE* f;
   strcat( command_line, "@" );
   strcat( command_line, FileName );
   strcat( command_line, " " );
   if ( sccdOUTFILEREDIR[0] == '>' ){
     strcat( command_line, CompileLine1 );
   }

   /* create a response file */
/*   if ( !sccd_debug ){ */
     f = fopen( FileName, "w" );
     if ( f == '\0' ){
       printf("\n*** ERROR, Could not open/create the preprocessor response-file %s for write. Aborting!\n",
                FileName );
       cleanexit(10);
     }
     fprintf( f, "%s ", CompileLine );
     if ( sccdOUTFILEREDIR[0] != '>' ){
       fprintf( f, "%s ", CompileLine1 );
     }
     fclose( f );
/*   } */
   if ( !sccd_silent ){
     printf("[%d]response file=    (%s): \"", clc++, FileName );
     f = fopen( FileName, "r" );
       {
	 int i = 0;
         while ( ( i = fgetc( f ) ) != EOF ){ printf("%c", (char)i ); }
         printf("\"\n");
         fclose( f );
       }
   }
 }
 else {  /* No response file */
   strcat( command_line, CompileLine );
   strcat( command_line, CompileLine1 );
 }

 if ( !sccd_silent ){
   printf("[%d]expand macro =    %s\n", clc++, command_line );
 }
 if ( !sccd_debug ) system( command_line );		/* Run the preprocessor !! */



 if ( ( sccdOUTFILEREDIR[0] == '\0' ) && ( sccdFMOVE[0] == '\0' ) ){
   /* ERROR, you need to define "sccdMOVE" if "sccdOUTFILEREDIR" == '\0' !! */
   if ( !sccd_silent ){ printf("\n*** ERROR, you need to define\
 \"sccdMOVE\" or \"sccdOUTFILEREDIR\". Aborting!\n" ); }
   cleanexit(5);
 }
 if ( ( sccdOUTFILEREDIR[0] == '\0' ) && ( sccdFMOVE[0] != '\0' ) ){
   /* For compilers without output-redirect, do a rename, copy or move */
   if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
     /* TmpDir != "" or "." */
     strcpy( command_line, sccdFMOVE );
     strcat( command_line, " " );
     if ( (FilenamePath[0] != '.') && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
     }
     strcat( command_line, Filename_wo_ext );
     strcat( command_line, sccdTEMPSUFFIX );
     strcat( command_line, " " );
     if ( (FilenamePath[0] != '.') && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
     }
     strcat( command_line, TmpDir );

     if ( !sccd_silent ){
       printf("[%d]move file =       %s\n", clc++, command_line );
     }
     if ( !sccd_debug ) system( command_line );
   }  /* TmpDir ... */
 } /* end of 'if ( sccdOUTFILEREDIR[ ... */

/*========================== Optional user command 3 ==================*/


 if ( sccdUSER_CMD3 != "" ){
   strcpy( line_buffer[0], sccdUSER_CMD3 ); /* read the User defined command */

 /* copy all chars in 'line_buffer[0]' up to '%f' or until '\0' to command_line */
 /* replace "%d" with "TmpDir" and replace "%p" with "FilenamePath" and */
 /* replace '%f' with 'Filename_wo_ext' for all occurences */

   index = 0;
   command_line[0] = '\0';		/* command_line[] = "" */
   line_buffer[1][1] = '\0';		/* line_buffer[1] = "?" */

   while ( line_buffer[0][index] != '\0' ) {
     if( strncmp( &line_buffer[0][index],
	  "%f",
          strlen("%f") ) == STRING_EQUALITY ){
       /* pass "%f" */
       index = index + strlen("%f");
       strcat( command_line, Filename_wo_ext );
     }
     if( strncmp( &line_buffer[0][index],
          "%p",
          strlen("%p") ) == STRING_EQUALITY ){
       /* pass "%p" */
       index = index + strlen("%p");
       strcat( command_line, FilenamePath );
     }
     if( strncmp( &line_buffer[0][index],
          "%d",
          strlen("%d") ) == STRING_EQUALITY ){
       /* pass "%d" */
       index = index + strlen("%d");
       strcat( command_line, TmpDir );
     }
     if( line_buffer[0][index] == '\0' ) break;
     line_buffer[1][0] = line_buffer[0][index++];
     strcat( command_line, line_buffer[1]);
   }      
   line_buffer[1][0] = '\0';
   strcat( command_line, line_buffer[1] );
 }
 else {
   strcpy( command_line, "" );
 }

 if ( sccdUSER_CMD3[0] != '\0' ){
   if ( !sccd_silent ){
     printf("[%d]user command3=    %s\n", clc++, command_line );
   }
   if ( !sccd_debug ) system( command_line );
 }

/*========================== pretty print *.i => *.c  =========================*/

/* Filename.<sccdTEMPSUFFIX> -> Filename.c */

 strcpy( In_Filename, "" );			/* clear buffer */
 if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
   strcat( In_Filename, FilenamePath );
   strcat( In_Filename, PathDelim );
 }
 if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
   /* TmpDir != "" or "." */
   strcat( In_Filename, TmpDir );
   strcat( In_Filename, PathDelim );
 }
 strcat( In_Filename, Filename_wo_ext );
 strcat( In_Filename, sccdTEMPSUFFIX );
 if ( !sccd_debug ){
   InFile  = fopen( In_Filename, "r" );
   if ( InFile == '\0' ) {
     printf("\n*** ERROR, Could not open %s for read. Aborting!\n", In_Filename );
     cleanexit(6);
   }
 }

 strcpy( Out_Filename, "" );			/* clear buffer */
 if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
   strcat( Out_Filename, FilenamePath );
   strcat( Out_Filename, PathDelim );
 }
 if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
   /* TmpDir != "" or "." */
   strcat( Out_Filename, TmpDir );
   strcat( Out_Filename, PathDelim );
 }
 strcat( Out_Filename, Filename_wo_ext );
 strcat( Out_Filename, sccdINFILESUFFIX );
 if ( !sccd_debug ){
   OutFile = fopen( Out_Filename, "w" );
   if ( OutFile == '\0' ) {
     printf("\n*** ERROR, Could not open/create %s for write. Aborting!\n", Out_Filename );
     cleanexit(7);
   }
 }

 if ( !sccd_silent ){
   printf("[%d]pretty print =    %s => %s\t%s\n",
     clc++, In_Filename, Out_Filename,
     ( (TmpDir[0] == '.') && ( TmpDir[1] == '\0' ) ? "\n# ==>\t\t\
     N.B. This overwrites the original In-File" : "" )  );
/*     ( TmpDir[0] == '.' ? "\n# ==>\t\t     N.B. This overwrites the original In-File" : "" )  ); */
 }

 if ( !sccd_debug ) {
  /* do whatever is necessary, i.e. parse & modify the .i file => .c */

{
 char c;
 char buffer[10];	/* including '\0' */
 int  int_c;
 int  i = 0;
 int  n = 0;

 enum state_var{ empty_line, el_slash,
                not_empty, ne_back_slash, ne_single_quote, ne_slash, at_eol_questionmark,
                ne_single_qoute_semi_colon, ne_single_quote_double_quote, ne_ose_fmt,
                cplusplus_comment, cc_slash, cc_star,
                comment, comment_star,
                in_string, is_single_quote,  is_single_quote_double_quote, is_back_slash
              } state ;

   state = empty_line;
   prev_line_blank = FALSE;
   position = 0;
   line_buffer_no = 0;
   line_buffer[0][0]  = '\0';
   line_buffer[1][0]  = '\0';


   /* read the input file char-by-char, i.e. treat input as a stream  */
   while ( ( int_c = getc( InFile ) ) != EOF ){
     c = (char)int_c;
iLoop:
     line_buffer[line_buffer_no][position++] = c;

     switch(state){
	case empty_line:
			if ( c == '\n' ){
			  this_line_blank = TRUE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  if ( prev_line_blank == FALSE ){
			    fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  }
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  break;
			}

			if ( c == '/' ){
			  state = el_slash;
			  break;
			}

			if ( isspace(c) ){
			  break;					  /* remain in state */
			}

			if ( c == '"' ){
			  state = in_string;
			  break;
			}

			state = not_empty;
			break;

	case el_slash:
			if ( c == '/' ){
			  state = cplusplus_comment;
			  break;
			}

			if ( c == '*' ){
			  state = comment;
			  break;
			}

			state = not_empty;
			break;

	case not_empty:
			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			if ( c == '\\' ){
			  state = ne_back_slash;
			  break;
			}


			if ( c == '\'' ){
			  state = ne_single_quote;
			  break;
			}

			if ( c == '/' ){
			  state = ne_slash;
			  break;
			}

			if ( c == ';' ){ /* scan for a OSE debugger/simulator format statment */
					 /* such as "'/''*''!''-''F''O''R''M''A''T'...'*''/' " */
			  if ( 	( ( int_c = getc( InFile ) ) != EOF ) &&
				( ( c = (char)int_c )        == '/' ) ){
			    buffer[1] = c;	/* make room for optional '\n' */
			    /* this is a potential OSE format string, load the next 9 characters */
			    if ( fgets( &buffer[2], 4, InFile ) != NULL ){
                              if ( strncmp( &buffer[1], "/*!-", strlen("/*!-") ) == STRING_EQUALITY ){
			       /* FOUND!, copy buffer to line_buffer and remain in state until '\n' ( see above ) */
			        for ( i = 1; i < 5; i++ ){
			          line_buffer[line_buffer_no][position++] = (char)buffer[ i ];
			        }
			        state = ne_ose_fmt;
			        goto switch_exit;
			      }
			      else {	/* use buffer instead of getc() until it's empty. */
			        buffer[0] = '\n';
			        n = 5;
			        i = 0;
			        goto switch_exit;
			      }
			    }
			    else {	/* EOF condition */
			      goto switch_exit;
			    }
			  }
			  else { /* c(n+1) != '/' */
			    ungetc( c, InFile ); /* no OSE format string, restore c ! */
			  }
			  /* c(n) == ';' && c(n+1) != '/' */
Label_nlq:		  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position++] = '\n'; /* add line break */
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = at_eol_questionmark;			  /* ex empty_line; */
			  break;
			}

			if ( c == '"' ){
			  state = in_string;
			  break;
			}

			if ( c == '{' ){
			  goto Label_nlq;
			}

			break;						  /* remain in state */

	case ne_ose_fmt:
			if ( c == '/' ){
			  goto Label_nlq;
			}

			break;

	case at_eol_questionmark:
			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  prev_line_blank = this_line_blank;
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			if ( c == '/' ){
			  state = ne_slash;
			  break;
			}

			if ( isspace(c) ){
			  break;					  /* remain in state */
			}

			state = not_empty;
			break;

	case ne_back_slash:
			state = not_empty;
			break;

	case ne_single_quote:
			if ( c == ';' ){
			  state = ne_single_qoute_semi_colon;
			  break;
			}

			if ( c == '"' ){
			  state = ne_single_quote_double_quote;
			  break;
			}

			state = not_empty;
			break;

	case ne_single_qoute_semi_colon:
			if ( c == '\'' ){
			  state = not_empty;
			  break;
			}

			this_line_blank = FALSE;
			line_buffer[line_buffer_no][position++] = '\n'; /* add line break */
			line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			prev_line_blank = this_line_blank;
			line_buffer_no ^= 0x01;			  	/* toggle buffer */
			position = 0;					/* start a new line */
			state = at_eol_questionmark;
			break;

	case ne_single_quote_double_quote:
			if ( c == '\'' ){
			  state = not_empty;
			  break;
			}

			state = in_string;
			break;

	case ne_slash:
			if ( c == '*' ){
			  state = comment;
			  break;
			}

			if ( c == '/' ){
			  state = cplusplus_comment;
			  break;
			}

			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position++] = '\n'; /* add line break */
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			state = not_empty;
			break;

	case comment:
			if ( c == '*' ){
			  state = comment_star;
			  break;
			}

			if ( c == '\n' ){				/* [COH 980512, v3.11, 6L */
			  line_buffer[line_buffer_no][position] = '\0'; /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  position = 0;					/* re-use line buffer */
			break;						/* remain in state */
			}

			break;						/* remain in state */

	case comment_star:
			if ( c == '/' ){
			  state = not_empty;
			  break;
			}

			if ( c == '*' ){
			  break;					/* remain in state */
			}

			state = comment;
			break;

	case cplusplus_comment:
			if ( c == '*' ){
			  state = cc_star;
			  break;
			}

			if ( c == '/' ){
			  state = cc_slash;
			  break;
			}

			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			break;						/* remain in state */

	case cc_star:
			if ( c == '/' ){
			  position = position - 2;
			  state = cplusplus_comment;
			  break;
			}

			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			state = cplusplus_comment;
			break;

	case cc_slash:
			if ( c == '*' ){
			  position = position - 2;
			  state = cplusplus_comment;
			  break;
			}

			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			state = cplusplus_comment;
			break;

	case in_string:
			if ( c == '\'' ){
			  state = is_single_quote;
			  break;
			}

			if ( c == '\\' ){
			  state = is_back_slash;
			  break;
			}

			if ( c == '\n' ){
			  this_line_blank = FALSE;
			  line_buffer[line_buffer_no][position] = '\0';   /* terminate line */
			  fprintf( OutFile, "%s", line_buffer[line_buffer_no] );
			  prev_line_blank = this_line_blank;
			  line_buffer_no ^= 0x01;			  /* toggle buffer */
			  position = 0;					  /* start a new line */
			  state = empty_line;
			  break;
			}

			if ( c == '"' ){
			  state = not_empty;
			  break;
			}

			break;						/* remain in state */

	case is_single_quote:
			if ( c == '"' ){
			  state = is_single_quote_double_quote;
			  break;
			}

			state = in_string;
			break;						/* remain in state */

	case is_back_slash:
			state = in_string;
			break;						/* remain in state */

	case is_single_quote_double_quote:
			if ( c == '\'' ){
			  state = in_string;
			  break;
			}

			state = not_empty;
			break;
switch_exit:
	default: ;
     }  /* end of switch */
     if ( n ){
       c = buffer[ i++ ];
       n--;
       goto iLoop;
     }
   }	/* end of while */
}

   fprintf( OutFile, "\n" ); /* add xtra '\n' */
   fclose( OutFile );
   fclose( InFile );
 }


/*========================== Clean up *.<sccdTEMPSUFFIX> =============================*/

/* clean up */

 if ( sccd_purge == TRUE ){	/* Default */
   strcpy( command_line, sccdDELETE );
   strcat( command_line, " " );
   strcat( command_line, In_Filename );

   if ( !sccd_silent ){
     printf("[%d]clean up =        %s\n", clc++, command_line );
   }
    if ( !sccd_debug )  system( command_line );
 }

/*========== copy FilenamePath/Filename_wo_ext.hs to =================*/
/*========== FilenamePath/TmpDir/Filename_wo_ext.hs ==================*/

 if ( (sccd_use_hs == TRUE) && ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ) ){
                                          /* TmpDir != "" or "." */
   
   strcpy( TmpFileName, "" );			/* clear buffer */
   if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
     strcat( TmpFileName, FilenamePath );
     strcat( TmpFileName, PathDelim );
   }
   strcat( TmpFileName, Filename_wo_ext );
   strcat( TmpFileName, ".hs" );

   if( ( TmpFile = fopen( TmpFileName, "r") ) != '\0' ){  /* exists ! */
     fclose( TmpFile );  				/* restore its status */

/*--------- Remove FilenamePath/TmpDir/Filename_wo_ext.hs ---------*/

     strcpy( command_line, sccdDELETE );
     strcat( command_line, " " );
     if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
     }
     if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
       /* TmpDir != "" or "." */
       strcat( command_line, TmpDir );
       strcat( command_line, PathDelim );
     }
     strcat( command_line, Filename_wo_ext );
     strcat( command_line, ".hs" );

     if ( !sccd_silent ){
       printf("[%d]remove .hs file = %s\n", clc++, command_line );
     }
     if ( !sccd_debug ) system( command_line );


/*--------- and copy Filename_wo_ext.hs to TmpDir/ ---------*/

     strcpy( command_line, sccdCOPY );
     strcat( command_line, " " );
     if ( ! ( (FilenamePath[0] == '.' ) && ( FilenamePath[1] == '\0' ) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
     }
     strcat( command_line, Filename_wo_ext );
     strcat( command_line, ".hs " );

     if ( ! ( (FilenamePath[0] == '.' ) && ( FilenamePath[1] == '\0' ) ) ){
       strcat( command_line, FilenamePath );
       strcat( command_line, PathDelim );
     }

     strcat( command_line, TmpDir );
 
     if ( !sccd_silent ){
       printf("[%d]copy .hs file =   %s\n", clc++, command_line );
     }
     if ( !sccd_debug ) system( command_line );
   }
 }

/*========================== Optional user command 4 ==================*/


 if ( sccdUSER_CMD4 != "" ){
   strcpy( line_buffer[0], sccdUSER_CMD4 ); /* read the User defined command */

 /* copy all chars in 'line_buffer[0]' up to '%f' or until '\0' to command_line */
 /* replace "%d" with "TmpDir" and replace "%p" with "FilenamePath" and */
 /* replace '%f' with 'Filename_wo_ext' for all occurences */

   index = 0;
   command_line[0] = '\0';		/* command_line[] = "" */
   line_buffer[1][1] = '\0';		/* line_buffer[1] = "?" */

   while ( line_buffer[0][index] != '\0' ) {
     if( strncmp( &line_buffer[0][index],
          "%f",
          strlen("%f") ) == STRING_EQUALITY ){
       /* pass "%f" */
       index = index + strlen("%f");
       strcat( command_line, Filename_wo_ext );
     }
     if( strncmp( &line_buffer[0][index],
          "%p",
          strlen("%p") ) == STRING_EQUALITY ){
       /* pass "%p" */
       index = index + strlen("%p");
       strcat( command_line, FilenamePath );
     }
     if( strncmp( &line_buffer[0][index],
          "%d",
          strlen("%d") ) == STRING_EQUALITY ){
       /* pass "%d" */
       index = index + strlen("%d");
       strcat( command_line, TmpDir );
     }
     if( line_buffer[0][index] == '\0' ) break;
     line_buffer[1][0] = line_buffer[0][index++];
     strcat( command_line, line_buffer[1]);
   }      
   line_buffer[1][0] = '\0';
   strcat( command_line, line_buffer[1] );
 }
 else {
   strcpy( command_line, "" );
 }

 if ( sccdUSER_CMD4[0] != '\0' ){
   if ( !sccd_silent ){
     printf("[%d]user command4=    %s\n", clc++, command_line );
   }
   if ( !sccd_debug ) system( command_line );
 }

 /*========================== Tornado parser pass 2 ====================*/
 /*          
   Use FileName.c to create TornadoFileName with correct line numbers 
   TornadoParse( Filename.c, TornadoFileName);   
 */
 
if(sccd_tornado_exp) {
 strcpy( In_Filename, "" );			/* clear buffer */
 if ( FilenamePath[0] != '.' ){
   strcat( In_Filename, FilenamePath );
   strcat( In_Filename, PathDelim );
 }
 if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
   /* TmpDir != "" or "." */
   strcat( In_Filename, TmpDir );
   strcat( In_Filename, PathDelim );
 }
 strcat( In_Filename, Filename_wo_ext );
 strcat( In_Filename, sccdINFILESUFFIX );
 if ( !sccd_debug ){
   InFile  = fopen( In_Filename, "r" );
   if ( InFile == '\0' ) {
     printf("\n*** ERROR, Could not open %s for read. Aborting!\n", In_Filename );
     cleanexit(6);
   }
   else
     fclose(InFile);
 }
 strcpy(TmpFileName, TornadoFileName_wo_ext);
 strcat(TmpFileName, ".a"); /* trash file which will not be used */
 
 if ( !sccd_debug ){
   OutFile = fopen( TmpFileName, "w" );
   if ( OutFile == '\0' ) {
     printf("\n*** ERROR, Could not open/create %s for write. Aborting!\n", TmpFileName );
     cleanexit(7);
   }
   fclose(OutFile);
 }

 /* get correct line numbers and generate correct line numbers to genFile3 */
 

 TornadoParse(In_Filename, TmpFileName, 1);   /* test.c => sctsymb.t */


 printf("[%d]tornado pass 2 =  %s => %s\n",
	clc++, In_Filename, GenFile3Name);
  
 strcpy(In_Filename, OrgIn_Filename );
 
 strcpy(Out_Filename, TornadoFileName_wo_ext);
 strcat(Out_Filename, sccdINFILESUFFIX);
 
  if ( !sccd_debug ){
   OutFile = fopen( Out_Filename, "w" );
   if ( OutFile == '\0' ) {
     printf("\n*** ERROR, Could not open/create %s for write. Aborting!\n", Out_Filename );
     cleanexit(7);
   }
   fclose(OutFile);
 }
 
 /* make same parsing as in pass 1, but insert genFile3 instead of genFile1 */

 TornadoParse(In_Filename, Out_Filename, 2);   /* test.c => sctsymb.c */

 printf("[%d]tornado pass 2 =  %s => %s\n",
	clc++, In_Filename, Out_Filename);

 
 /*--------- Remove FilenamePath/TmpDir/.a ---------*/
 
  if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ) 
    {
      /* TmpDir != "" or "." */
   
      strcpy( TmpFileName, "" );			/* clear buffer */
      if ( FilenamePath[0] != '.' ){
	strcat( TmpFileName, FilenamePath );
	strcat( TmpFileName, PathDelim );
      }
      strcat( TmpFileName, TornadoFileName_wo_ext);
      strcat( TmpFileName, ".a" );
      
      if( ( TmpFile = fopen( TmpFileName, "r") ) != '\0' ){  /* exists ! */
	fclose( TmpFile );  				/* restore its status */
	
/*--------- Remove FilenamePath/TmpDir/.a ---------*/

	strcpy( command_line, sccdDELETE );
	strcat( command_line, " " );	
	
	strcat( command_line, TornadoFileName_wo_ext );
	strcat( command_line, ".a" );
	
	if ( !sccd_silent ){
	  printf("[%d]remove .a file = %s\n", clc++, command_line );
	}
	if ( !sccd_debug ) system( command_line );
      }

    }
}
/*========================== Compile ==================================*/


 if ( strncmp( sccdCOMPILE, "ON", strlen("ON") ) == STRING_EQUALITY ){
   for ( i = 0; i < BUF_LEN;  i++ ) CompileLine[i] = '\0';	/* clear the compile line buffer */
   for ( index = 2; index < GetNum(); ++index ){
     if ( InFile_index == index ){
       for ( i = 0; i < BUF_LEN;  i++ ) FileBuf[i] = '\0';	/* clear FileBuf[] */
       if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
         strcat( FileBuf, FilenamePath );
         strcat( FileBuf, PathDelim );
       }
       if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
         /* TmpDir != "" or "." */
         strcat( FileBuf, TmpDir );
         strcat( FileBuf, PathDelim );
       }
       strcat( FileBuf, Filename_wo_ext );
       strcat( FileBuf, sccdINFILESUFFIX );
       Set( FileBuf, index );  /* modify source file name */
     }
   }

   if ( !sccd_silent ){
     printf("[%d]compile =         %s\n", clc++, GetCompileLine() );
   }

   if ( !sccd_debug ) system( GetCompileLine() );
 }

/*======= rm FilenamePath/TmpDir/Filename_wo_ext.hs ===================*/

 if ( (sccd_use_hs == TRUE) &&
      ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ) ){
        /* TmpDir != "" or "." */
   if ( sccd_purge == TRUE ){  /* Default */

     if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
       /* TmpDir != "" or "." */
       /* Do not delete a local .hs file !! */

       strcpy( command_line, sccdDELETE );
       strcat( command_line, " " );
       if ( (FilenamePath[0] != '.' ) && ( ! ((TmpDir[0] == PathDelim[0]) || (TmpDir[1] == ':')) ) ){
         strcat( command_line, FilenamePath );
         strcat( command_line, PathDelim );
       }
       if ( ! ( ( TmpDir[0] == '.' ) && ( TmpDir[1] == '\0' ) ) ){
         /* TmpDir != "" or "." */
         strcat( command_line, TmpDir );
         strcat( command_line, PathDelim );
       }
       strcat( command_line, Filename_wo_ext );
       strcat( command_line, ".hs" );

       if ( !sccd_silent ){
         printf("[%d]clean up =        %s\n", clc++, command_line );
       }
       if ( !sccd_debug ) system( command_line );
     }
   }
 }

/*=====================================================================*/

 cleanexit(0);
}

/******************************* END ************************************/
