EnglishРусский  

   ..

   exe.c

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2006, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * ID: exe 24.10.06 0.0.A.
 11 *
 12 * Author: Alexey Krivonogov
 13 *
 14 ******************************************************************************/
 15 
 16 #include "../../genteeapi/gentee.h"
 17 #ifdef WINDOWS
 18  #include "windows.h"
 19 #endif
 20 #include "../../os/user/defines.h"
 21 pubyte      profile = NULL;
 22 pubyte      inifile = NULL;
 23 ubyte       exepath[512];
 24 ubyte       gpath[512];
 25 pubyte      gname = NULL;
 26 #ifdef LINUX
 27    pubyte*      __argv;
 28    int         __argc;
 29    #define getchar getchar
 30 #else
 31    #define getchar _getch
 32 #endif
 33 
 34 void __cdecl printc( pubyte text )
 35 {
 36 #ifdef LINUX
 37    write( 1, text, strlen( text ));
 38 #else
 39    uint  write;
 40    WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), text, lstrlen( text ),
 41                 &write, 0 );
 42 #endif
 43 //   printf( "%s", text );
 44 }
 45 
 46 pubyte getpath( pubyte filename )
 47 {
 48    uint i = 0, last = 0, dot = 0;
 49 
 50    while ( filename[i] )
 51    {
 52       if ( filename[i] == '\\' )
 53          last = i;
 54       if ( filename[i] == '.' )
 55          dot = i;
 56       i++;
 57    }
 58    if ( !last )
 59    {
 60       ubyte  temp[512];
 61       #ifdef LINUX
 62          os_filefullname( filename, temp );
 63       #else
 64          GetFullPathName( filename, 512, temp, NULL );
 65 	   #endif 
 66       mem_copyuntilzero( filename, temp );
 67       return getpath( filename );
 68    }
 69    filename[dot] = 0;
 70    filename[last] = 0;
 71 
 72    return filename + last + 1;
 73 }
 74 
 75 pubyte copymacros( pubyte dest, pubyte src )
 76 {
 77    while ( *src )
 78    {
 79       if ( !mem_cmpign( src, "%GNAME%", 7 ))
 80       {
 81          dest += mem_copyuntilzero( dest, gname ) - 1;
 82          src += 7;
 83       }
 84       else
 85          if ( !mem_cmpign( src, "%GPATH%", 7 ))
 86          {
 87             dest += mem_copyuntilzero( dest, gpath ) - 1;
 88             src += 7;
 89          }
 90          else
 91             if ( !mem_cmpign( src, "%EXEPATH%", 9 ))
 92             {
 93                dest += mem_copyuntilzero( dest, exepath ) - 1;
 94                src += 9;
 95             }
 96             else
 97                *dest++ = *src++;
 98    }
 99    *dest++ = 0;
100    return dest;
101 }
102 
103 pubyte getprofile( pubyte key, puint pflag, uint flagval )
104 {
105    pubyte      ret = ( pubyte )pflag;
106    ubyte       val[512];
107    #ifdef LINUX
108     struct      CfgStruct this_var;
109    #endif
110 
111    if ( flagval < 0xFFF0 )
112    {
113       #ifdef LINUX
114        this_var.Name   = key;
115        this_var.DataPtr = val;
116        this_var.VarType = Cfg_String;
117        ReadCfg(inifile, profile, &this_var);
118       #else
119        GetPrivateProfileString( profile, key, *pflag & flagval ? "1" : "0",val, 512, inifile );
120       #endif
121       if ( val[0] == '1' )
122          *pflag |= flagval;
123       else
124          *pflag &= ~flagval;
125    }
126    if ( flagval == 0xFFF0 )
127    {
128       #ifdef LINUX
129        this_var.Name   = key;
130        this_var.DataPtr = val;
131        this_var.VarType = Cfg_String;
132        ReadCfg(inifile, profile, &this_var);
133       #else
134        GetPrivateProfileString( profile, key, ( pubyte )pflag,val, 512, inifile );
135        #endif
136       copymacros( ( pubyte )pflag, val );
137    }
138    if ( flagval == 0xFFF1 )
139    {
140       ubyte keyi[64];
141       uint  i = 0;
142 
143       mem_copyuntilzero( keyi, key );
144       while ( 1 )
145       {
146           #ifdef LINUX
147            this_var.Name   = keyi;
148            this_var.DataPtr = val;
149            this_var.VarType = Cfg_String;
150            ReadCfg(inifile, profile, &this_var);
151           #else
152             GetPrivateProfileString( profile, keyi, "", val, 512, inifile );
153           #endif
154          if ( !val[0] )
155             break;
156 
157          ( pubyte )pflag = copymacros( ( pubyte )pflag, val );
158          sprintf( keyi, "%s%i", key, ++i );
159       }
160       ret = ( pubyte )pflag;
161    }
162    return ret;
163 }
164 
165 /*
166 uint  _stdcall myexport( uint par1, uint par2 )
167 {
168    return par1 * par2;
169 }
170 
171 pvoid  __stdcall export( pubyte name )
172 {
173    if ( mem_iseqzero( name, "myexport" ))
174       return &myexport;
175    return NULL;
176 }
177 */
178 
179 int __cdecl main( int argc, char *argv[] )
180 {
181    pubyte    head = "\nGentee Programming Language Version 3.6.1\n\
182 Freeware open source compiler & the run-time engine\n\
183 Copyright (C) 2004-08 The Gentee Group. All rights reserved.\n\n\
184 Internet: http://www.gentee.com  Email: info@gentee.com\n\n";
185 
186    compileinfo cmplinfo;
187    int         next = 1;
188    uint        flag = G_CONSOLE;// | G_CHARPRN;
189    pvoid       cargs;
190    pubyte      curargs;
191    pubyte      defargs = NULL;
192    pubyte      libdirs = NULL;
193    pubyte      include = NULL;
194    pubyte      exename;
195    ubyte       proname[ 512 ];
196 #ifdef LINUX
197    ubyte       fdrive_[FILENAME_MAX+1];
198    ubyte       fpath_[PATH_MAX+1];
199    ubyte       fname_[FILENAME_MAX+1];
200    ubyte       fext_[FILENAME_MAX+1];
201 #endif
202    if ( argc < 2 )
203    {
204       printc( head );
205       printc( "How to compile: \n\
206 gentee.exe [<switches>] <source .g or .ge file> [command line arguments]\n\n\
207 <switches>\n\
208    -c - Compiling only. Do not run the program after compiling\n\
209    -m <define macros>- Define macros for compiling\n\
210        Example: -d \"MODE=1;NAME=\\\"My Company, Inc\\\"\"\n\
211    -f - Create GE file.\n\
212    -n - Ignore the command line #!...\n\
213    -o <output file> - Output GE filename (not default) will be specified.\n\
214    -p <profile name> - Use the profile from gentee.ini file.\n\
215    -s - Do not display any messages during the compiling or the executing\n\
216    -t - Convert print strings to OEM-defined character set\n\
217    -d - Include debug information\n\
218    Examples\n\
219       gentee.exe -f myfile.g\n\n\
220 \nPress any key...\n\n");
221       getchar();
222       return 0;
223    }
224    #ifdef LINUX
225       __argv = argv;
226       __argc = argc;
227       strcpy(exepath,argv[0]);
228     //exepath = __argv[0];
229       exename = getpath( exepath );
230       os_splitpath(exepath, fdrive_, fpath_, fname_, fext_);
231       strcpy(exename,fname_);
232    #else
233       GetModuleFileName( NULL, exepath, 512 );
234       exename = getpath( exepath );   
235    #endif
236 
237    gentee_init( flag );
238    mem_zero( &cmplinfo, sizeof( compileinfo ));
239 
240    cmplinfo.defargs = mem_alloc( 8192 );
241    defargs = cmplinfo.defargs;
242    cmplinfo.output = cmplinfo.defargs + 2048;
243    cmplinfo.output[0] = 0;
244    cmplinfo.libdirs = cmplinfo.output + 512;
245    libdirs = cmplinfo.libdirs;
246    cmplinfo.include = cmplinfo.libdirs + 2048;
247    include = cmplinfo.include;
248 
249    cmplinfo.flag |= CMPL_LINE;// | CMPL_THREAD;
250 
251    while ( next < argc && argv[ next ][0] == '-')
252    {
253       switch ( argv[ next ][ 1 ] ) {
254          case 'c':
255          case 'C':
256             cmplinfo.flag |= CMPL_NORUN;
257             break;
258          case 'n':
259          case 'N':
260             cmplinfo.flag &= ~CMPL_LINE;
261             break;
262          case 'm':
263          case 'M':
264             if ( next + 1 == argc )
265             {
266                printc("Please specify macros after '-m' option.\n\n\
267 gentee.exe [<switches>] -m <macros> <source file>");
268                getchar();
269                return 0;
270             }
271             defargs += mem_copyuntilzero( defargs, argv[ ++next ] );
272             break;
273          case 'f':
274          case 'F':
275             cmplinfo.flag |= CMPL_GE;
276             break;
277          case 'o':
278          case 'O':
279             cmplinfo.flag |= CMPL_GE;
280             if ( next + 1 == argc )
281             {
282                printc("Please specify an output filename after '-o' option.\n\n\
283 gentee.exe [<switches>] -o <output file> <source file>");
284                getchar();
285                return 0;
286             }
287             mem_copyuntilzero( cmplinfo.output, argv[ ++next ] );
288             break;
289          case 's':
290          case 'S':
291             flag |= G_SILENT;
292             break;
293          case 't':
294          case 'T':
295             flag |= G_CHARPRN;
296             break;
297          case 'd':
298          case 'D':
299             cmplinfo.flag |= CMPL_DEBUG;
300             break;
301          case 'p':
302          case 'P':
303             if ( next + 1 == argc )
304             {
305                printc("Please specify a profile name after '-p' option.\n\n\
306 gentee.exe -p <profile name> <source file>");
307                getchar();
308                return 0;
309             }
310             profile = argv[ ++next ];
311             break;
312       }
313       next++;
314    }
315    if ( next == argc )
316    {
317       printc( head );
318       printc("Please specify a source filename.\n\n\
319 gentee.exe [<switches>] <source file>");
320       getchar();
321       return 0;
322    }
323    cmplinfo.input = argv[ next++ ];
324    mem_copyuntilzero( gpath, cmplinfo.input );
325    gname = getpath( gpath );
326 
327    if ( profile )
328    {
329       sprintf( proname, "%s\\%s.ini", exepath, exename );
330       inifile = proname;
331 
332       // Load options from profile
333       getprofile( "silent", &flag, G_SILENT );
334       getprofile( "charoem", &flag, G_CHARPRN );
335       getprofile( "gefile", &cmplinfo.flag, CMPL_GE );
336       getprofile( "norun", &cmplinfo.flag, CMPL_NORUN );
337       getprofile( "debug", &cmplinfo.flag, CMPL_DEBUG );
338       getprofile( "firstline", &cmplinfo.flag, CMPL_LINE );
339       getprofile( "gename", ( puint )cmplinfo.output, 0xFFF0 );
340       defargs = getprofile( "define", ( puint )defargs, 0xFFF1 );
341       libdirs = getprofile( "libdir", ( puint )libdirs, 0xFFF1 );
342       include = getprofile( "include", ( puint )include, 0xFFF1 );
343    }
344    gentee_set( GSET_FLAG, ( pvoid )flag );
345 //   gentee_set( GSET_MESSAGE, &message );
346 //   gentee_set( GSET_EXPORT, &export );
347 
348    *( pushort )defargs = 0;
349    *( pushort )libdirs = 0;
350    *( pushort )include = 0;
351 
352    // Getting command-line parameters
353    cargs = mem_alloc( 1024 );
354    curargs = cargs;
355    while ( next < argc )
356    {
357       curargs += mem_copyuntilzero( curargs, argv[ next++ ] );
358 //      curargs += mem_len( curargs ) + 1;
359    }
360    *curargs = 0;
361    if ( *( pubyte )cargs )
362       gentee_set( GSET_ARGS, cargs );
363 
364    if ( !( flag & G_SILENT ) && !getenv("GNUMSIGN"))
365       printc( head );
366 
367 //   cmplinfo.libs = "k:\\gentee\\open source\\gentee\\lib\\stdlib\\stdlib.g\00";
368    gentee_compile( &cmplinfo );
369 //   getch();
370    mem_free( cargs );
371 //   mem_free( cmplinfo.defargs );
372    gentee_deinit();
373    return 0;
374 }
Редактировать