G:/ScriptBasic/source/tools/calldllbasic.c

Go to the documentation of this file.
00001 #include <windows.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 
00006 #include "../getopt.h"
00007 #include "../variations/win32dll/basicdll.h"
00008 
00009 #ifdef _DEBUG
00010 
00011 int mymain();
00012 main(){
00013   char *myargv[] = {
00014      "basic",
00015      "D:\\MyProjects\\sb\\source\\examples\\hello.bas",
00016      NULL
00017      };
00018   int myargc= 2;
00019 
00020   mymain(myargc, myargv);
00021   }
00022 #define main mymain
00023 
00024 #endif
00025 
00026 int GetC(void *f){ return getc((FILE *)f); }
00027 static MyOutput(char q){
00028   printf("*%c",q);
00029   }
00030 static char *s = "alma van a fa alatt\n";
00031 static int MyInput(void){
00032 
00033   if( *s == (char)0 )return EOF;
00034   return *s++;
00035   }
00036 
00037 main(int argc, char *argv[]){
00038   char *szInputFile;
00039   char *optarg,opt;
00040   int giveusage,binarycode;
00041   int execute,OptionIndex;
00042   char CmdLinBuffer[256];
00043 
00044   /* default values for command line options */
00045   szInputFile = NULL;
00046   giveusage  = 0; /* assume the command line is correct, we need not display usage and stop */
00047   binarycode = 0; /* input is not binary by default */
00048   execute    = 0; /* do not execute by default after binary format save */
00049 
00050   OptionIndex = 0;
00051 
00052   while( (opt = getoptt(argc, argv, "veb",&optarg,&OptionIndex)) != ':'){
00053     switch( opt ){
00054       case 'e' :
00055         if( execute )giveusage = 1;
00056         execute = 1;
00057         break;
00058       case 'b':
00059         binarycode =1;
00060         break;
00061       case 'v':
00062 #define S fprintf(stderr,
00063 #define E );
00064         exit(0);
00065       case '!' :
00066         giveusage = 1;
00067         break;
00068       case '?':
00069         if( szInputFile )giveusage = 1;
00070         szInputFile = optarg;
00071         CmdLinBuffer[0] = (char)0;
00072         while( OptionIndex < argc ){
00073           strcat(CmdLinBuffer,argv[OptionIndex++]);
00074           if( OptionIndex < argc )
00075             strcat(CmdLinBuffer," ");
00076           }
00077         goto CmdLineFinished;
00078       }
00079     }
00080 
00081 CmdLineFinished:
00082   if( execute && binarycode )giveusage=1;
00083 
00084 
00085   if( szInputFile == NULL || giveusage ){
00086 #define U(x) fprintf(stderr,"%s\n",(x));
00087     U("Usage: basic [options] program.bas")
00088     U("")
00089     U("options: -o file_name")
00090     U("            save binary format to file but don't execute")
00091     U("         -b file_name")
00092     U("            load binary format from file and execute")
00093     U("         -e")
00094     U("            execute after binary format was saved")
00095     U("         -v")
00096     U("            print version info and stop")
00097     
00098     exit(1);
00099     }
00100 
00101   execute = basic(szInputFile,(void *)MyInput,(void *)MyOutput,NULL,CmdLinBuffer,NULL,binarycode);
00102   exit(execute);
00103   }

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