G:/ScriptBasic/source/variations/standalone/libscriba.c

Go to the documentation of this file.
00001 /* 
00002 
00003 FILE:   libscriba.c
00004 HEADER: libscriba.h
00005 
00006 --GNU LGPL
00007 This library is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU Lesser General Public
00009 License as published by the Free Software Foundation; either
00010 version 2.1 of the License, or (at your option) any later version.
00011 
00012 This library is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public
00018 License along with this library; if not, write to the Free Software
00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 TO_HEADER:
00022 
00023 */
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 #include "../../getopt.h"
00029 #include "../../scriba.h"
00030 
00031 #include "../../basext.h"
00032 
00033 #if BCC32
00034 char *_pgmptr;
00035 #endif
00036 
00037 
00038 static int libscriba_LoadBinaryProgram(pSbProgram pProgram
00039   ){
00040 /*noverbatim
00041 Before calling this function the function R<scriba_SetFileName()> should have been called specifying the
00042 file name.
00043 CUT*/
00044   pBuildObject pBuild;
00045 
00046   extern unsigned long ulGlobalVariables;
00047   extern unsigned long ulNodeCounter;
00048   extern unsigned long ulStartNode;
00049   extern unsigned long ulStringTableSize;
00050   extern unsigned char szCommandArray[];
00051   extern char szStringTable[];
00052 
00053   pProgram->pBUILD = alloc_Alloc( sizeof(BuildObject) , pProgram->pMEM);
00054   if( pProgram->pBUILD == NULL )return 1;
00055 
00056   pProgram->pBUILD->memory_allocating_function = pProgram->maf;
00057   pProgram->pBUILD->memory_releasing_function  = pProgram->mrf;
00058   pProgram->pBUILD->iErrorCounter = 0;
00059   pProgram->pBUILD->reportptr = pProgram->pReportPointer;
00060   pProgram->pBUILD->report   = pProgram->fpReportFunction;
00061   pProgram->pBUILD->fErrorFlags = pProgram->fErrorFlags;
00062   pBuild = pProgram->pBUILD;
00063 
00064   pBuild->pMemorySegment = alloc_InitSegment(pBuild->memory_allocating_function,
00065                                              pBuild->memory_releasing_function);
00066   if( pBuild->pMemorySegment == NULL ){
00067     return BU_ERROR_MEMORY_LOW;
00068     }
00069 
00070   pBuild->cGlobalVariables = ulGlobalVariables;
00071   pBuild->NodeCounter      = ulNodeCounter;
00072   pBuild->StartNode        = ulStartNode;
00073   pBuild->CommandArray     = (struct _cNODE *)szCommandArray;
00074   pBuild->cbStringTable    = ulStringTableSize;
00075   pBuild->StringTable      = szStringTable;
00076   pBuild->cbFTable         = 0;
00077   pBuild->FTable           = NULL;
00078   pBuild->cbVTable         = 0;
00079   pBuild->VTable           = NULL;
00080   return pProgram->pBUILD->iErrorCounter;
00081   }
00082 
00083 
00084 int GetC(void *f){ return getc((FILE *)f); }
00085 
00086 #ifdef _DEBUG
00087 #define ERREXIT do{getchar();scriba_destroy(pProgram);exit(iError);}while(0)
00088 #else
00089 #define ERREXIT exit(iError)
00090 #endif
00091 
00092 #ifdef WIN32
00093 main(int argc, char *argv[]){
00094 #else
00095   char **_environ;
00096 main(int argc, char *argv[], char *env[]){
00097 #endif
00098   int iError;
00099   int iErrorCounter;
00100   pSbProgram pProgram;
00101   unsigned long fErrorFlags;
00102 #define FULL_PATH_BUFFER_LENGTH 1024
00103   char CmdLinBuffer[FULL_PATH_BUFFER_LENGTH];
00104   extern int GlobalDebugDisplayFlag;
00105   int i;
00106   
00107   CmdLinBuffer[0] = (char)0;
00108   for( i=1 ; i < argc ; i++ ){
00109     strcat(CmdLinBuffer,argv[i]);
00110     if( i < argc-1 )strcat(CmdLinBuffer," ");
00111     }
00112 
00113 /*pSbData p,psb;
00114 SbData RetVale;*/
00115 #ifndef WIN32
00116   _environ = env;
00117 #endif
00118 
00119 #if BCC32
00120   _pgmptr = argv[0];
00121 #endif
00122 
00123 #ifdef _DEBUG
00124 #define malloc testa_Alloc
00125 #define free testa_Free
00126   testa_InitSegment();
00127 #endif
00128   /* default values for command line options */
00129 #define pszForcedConfigurationFileName NULL
00130   GlobalDebugDisplayFlag = 0;
00131 
00132   pProgram = scriba_new(malloc,free);
00133   if( pProgram == NULL ){
00134     iError = COMMAND_ERROR_MEMORY_LOW;
00135     ERREXIT;
00136     }
00137 
00138   scriba_LoadConfiguration(pProgram,pszForcedConfigurationFileName);
00139 
00140   scriba_SetFileName(pProgram,argv[0]);
00141 
00142   if( (iError = libscriba_LoadBinaryProgram(pProgram)) != 0 ){
00143     ERREXIT;
00144     }
00145   if( iError=scriba_Run(pProgram,CmdLinBuffer) ){
00146     report_report(stderr,"",0,iError,REPORT_ERROR,&iErrorCounter,NULL,&fErrorFlags);
00147     ERREXIT;
00148     }
00149 
00150   scriba_destroy(pProgram);
00151   exit(iError);
00152   }
00153 

Generated on Sun Mar 12 23:56:32 2006 for ScriptBasic by  doxygen 1.4.6-NO