示例#1
0
int symlink(const char *src, const char *dest)
{
	HRESULT res;
	char fullsrc[MAX_PATH];
	char fulldst[MAX_PATH];
	char *fs, *fd;
#ifdef TEST
	fprintf(stderr, "symlink\n");
	fprintf(stderr, "     src:  %s\n", src);
	fprintf(stderr, "     dest: %s\n", dest);
#endif
	fs = unix2winpath (getfullpath(src, fullsrc));
//	fs = strcpy(fullsrc, src);
#ifdef TEST
	fprintf(stderr, "symlink 2\n");
	fprintf(stderr, "     dest: %s\n", dest);
//	fprintf(stderr, "     fd: %s\n", fd);
	fprintf(stderr, "     fullsrc: %s\n", fullsrc);
	fprintf(stderr, "     fs: %s\n", fs);
#endif
	fd = unix2winpath (getfullpath (dest, fulldst));
//	fd = strcpy(fulldst, dest);
	strcat (fulldst, ".lnk");
#ifdef TEST
	fprintf(stderr, "symlink 3\n");
	fprintf(stderr, "     fulldst: %s\n", fulldst);
#endif

	res = CreateLink ((LPCSTR) fullsrc, (LPSTR) fulldst, (LPSTR) fullsrc);
#ifdef TEST
	fprintf(stderr, "symlink 4\n");
	fprintf(stderr, "     res: %ld\n", res);
#endif
	return (int) res;
}
示例#2
0
int cctools_renameat (int dirfd, const char *path, int newdirfd, const char *newpath)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	char newfullpath[PATH_MAX];
	if (getfullpath(newdirfd, newpath, newfullpath) == -1)
		return -1;
	return rename(fullpath, newfullpath);
}
示例#3
0
int cctools_linkat (int dirfd, const char *path, int newdirfd, const char *newpath, int flag)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	char newfullpath[PATH_MAX];
	if (getfullpath(newdirfd, newpath, newfullpath) == -1)
		return -1;
	(void)flag;
	return link(fullpath, newfullpath);
}
示例#4
0
int cctools_readlinkat (int dirfd, const char *path, char *buf, size_t bufsize)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	return readlink(fullpath, buf, bufsize);
}
示例#5
0
int cctools_mkdirat (int dirfd, const char *path, mode_t mode)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	return mkdir(fullpath, mode);
}
示例#6
0
DIR *cctools_fdopendir (int dirfd)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, ".", fullpath) == -1)
		return NULL;
	return opendir(fullpath);
}
示例#7
0
int cctools_symlinkat (const char *target, int dirfd, const char *path)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	return symlink(target, fullpath);
}
示例#8
0
int cctools_openat (int dirfd, const char *path, int oflag, mode_t cmode)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	return open(fullpath, oflag, cmode);
}
示例#9
0
KMapDataManager::KMapDataManager(const char* mapDir)
{
	char path[512];
	ASSERT(mapDir && mapDir[0]);
	getfullpath(path, mapDir, sizeof(path));
	m_mapDir = path;
}
示例#10
0
int cctools_fchmodat (int dirfd, const char *path, mode_t mode, int flag)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	(void)flag;
	return chmod(fullpath, mode);
}
示例#11
0
int cctools_faccessat (int dirfd, const char *path, int amode, int flag)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	(void)flag;
	return access(fullpath, amode);
}
示例#12
0
string	filepath::getfullname(){
	string tmp;
	tmp = getfullpath();
	if(tmp != ""){
		tmp += "\\";
	}
	tmp += getfilename();
	return tmp;
}
示例#13
0
int cctools_fstatat (int dirfd, const char *path, struct stat *buf, int flag)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	if (flag & AT_SYMLINK_NOFOLLOW) {
		return lstat(fullpath, buf);
	} else {
		return stat(fullpath, buf);
	}
}
示例#14
0
int cctools_unlinkat (int dirfd, const char *path, int flag)
{
	char fullpath[PATH_MAX];
	if (getfullpath(dirfd, path, fullpath) == -1)
		return -1;
	if (flag == AT_REMOVEDIR) {
		return rmdir(fullpath);
	} else {
		return unlink(fullpath);
	}
}
示例#15
0
FILE* fopen(const char* filename, const char *mode)
{
        FILE* res;
        int imode;
        imode=0;
        if (*mode=='r')
        {
                imode=FILE_OPEN_READ;
                mode++;
        }else if (*mode=='w')
        {
                imode=FILE_OPEN_WRITE;
                mode++;
        }else if (*mode=='a')
        {
                imode=FILE_OPEN_APPEND;
                mode++;
        }else
                return 0;
        if (*mode=='t')
        {
                imode|=FILE_OPEN_TEXT;
                mode++;
        }else if (*mode=='b')
                mode++;
        if (*mode=='+')
        {
                imode|=FILE_OPEN_PLUS;
                mode++;
        }
        if (*mode!=0)
                return 0;
        res=malloc(sizeof(FILE));
        res->buffer=malloc(256);
        res->buffersize=256;
        res->filesize=0;
        res->filepos=0;
        res->mode=imode;
        res->filename=getfullpath(filename);

	if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
	{
		res->filesize=_ksys_get_filesize(res->filename);
	}
        return res;
}
示例#16
0
文件: main.c 项目: callaa/luola
/* Do initializations that require datafiles */
static int load_data(void) {
    LDAT *graphics;
    graphics = ldat_open_file(getfullpath(DATA_DIRECTORY,"gfx.ldat"));
    if(graphics==NULL)
        return 1;

    init_critters(graphics);
    init_intro(graphics);
    init_game(graphics);
    init_selection(graphics);
    init_players(graphics);
    init_pilots(graphics);
    init_ships(graphics);
    init_specials(graphics);
    init_projectiles(graphics);

    ldat_free(graphics);

    return 0;
}
示例#17
0
bool
tool_trace_mode(vogl::vector<command_line_param_desc> *desc)
{
    arguments_t args;

    if (desc)
    {
        desc->append(g_command_line_param_descs_dump, VOGL_ARRAY_SIZE(g_command_line_param_descs_dump));
        desc->append(g_tracer_cmdline_opts, VOGL_ARRAY_SIZE(g_tracer_cmdline_opts));
        return true;
    }

    // Get steam gameid / local application name.
    args.gameid = g_command_line_params().get_value_as_string_or_empty("", 1);

    if (!args.gameid.size())
        errorf(VOGL_FUNCTION_INFO_CSTR, "ERROR: No application or steamid specified.\n");

    // Get logfile and tracefile names.
    args.vogl_tracefile = g_command_line_params().get_value_as_string("vogl_tracefile");
    args.vogl_logfile = g_command_line_params().get_value_as_string("vogl_logfile");

    args.dryrun = g_command_line_params().get_value_as_bool("dry-run");
    args.xterm = g_command_line_params().get_value_as_bool("xterm");

    // Loop through all the arguments looking for "vogl_*".
    for (vogl::command_line_params::param_map_const_iterator param = g_command_line_params().begin();
         param != g_command_line_params().end();
         ++param)
    {
        const dynamic_string &first = param->first;

        // If this is a vogl command and it's not logfile / tracefile, add it to the vogl_cmdline.
        const dynamic_string prefix = param->first.get_clone().left(5);
        if (prefix == "vogl_" && (first != "vogl_logfile" && first != "vogl_tracefile"))
        {
            args.vogl_cmdline += " --" + first;
            for (uint32_t i = 0; i < param->second.m_values.size(); i++)
            {
                args.vogl_cmdline += " " + param->second.m_values[i];
            }
        }
    }

    // Check for -- or --args and add everything after to game_args.
    const dynamic_string& command_line = get_command_line();

    int args_index = command_line.find_left("-- ");
    if (args_index == -1)
        args_index = command_line.find_left("--args ");
    if (args_index != -1)
    {
        args_index = command_line.find_left(' ', args_index);
        if (args_index != -1)
        {
            args.game_args += command_line.get_clone().right(args_index + 1);
        }
    }

    bool is_steam_file = true;
    if (atoi(args.gameid.c_str()) == 0)
    {
        if (access(args.gameid.c_str(), F_OK))
            errorf(VOGL_FUNCTION_INFO_CSTR, "\nCould not find executable '%s'\n", args.gameid.c_str());

        char *filename = realpath(args.gameid.c_str(), NULL);
        if (filename)
        {
            // This is a local executable.
            is_steam_file = false;
            args.gameid = filename;
            free(filename);
        }
    }

    int steam_appid = is_steam_file ? atoi(args.gameid.c_str()) : -1;
    if (!steam_appid)
        errorf(VOGL_FUNCTION_INFO_CSTR, "ERROR: Could not find game number for %s\n", args.gameid.c_str());

    dynamic_string gameid_str;
    if (is_steam_file)
    {
        gameid_str = "appid" + args.gameid;
        vogl_printf("\nGame AppID: %d", steam_appid);

        const char *game_name = get_game_name(steam_appid);
        if (game_name)
        {
            dynamic_string game_name_str(cVarArg, "%s", game_name);
            vogl_printf(" (%s)", game_name_str.c_str());

            // Trim some characters that don't go well with filenames.
            game_name_str.replace(" ", "_");
            game_name_str.replace(":", "");
            game_name_str.replace("'", "");
            game_name_str.replace("!", "");
            game_name_str.replace("?", "");
            gameid_str += "_" + game_name_str;
        }

        vogl_printf("\n");
    }
    else
    {
        gameid_str = basename((char *)args.gameid.c_str());
        vogl_printf("\nGame: %s\n", args.gameid.c_str());
    }

    // If a tracefile / logfile wasn't specified, set em up.
    if (!args.vogl_tracefile.size() || !args.vogl_logfile.size())
    {
        char timestr[200];
        time_t t = time(NULL);

        timestr[0] = 0;
        struct tm *tmp = localtime(&t);
        if (tmp)
        {
            strftime(timestr, sizeof(timestr), "%Y_%m_%d-%H_%M_%S", tmp);
        }

        dynamic_string fname(cVarArg, "%s/vogltrace.%s.%s", P_tmpdir, gameid_str.c_str(), timestr);
        if (!args.vogl_tracefile.size())
            args.vogl_tracefile = fname + ".bin";
        if (!args.vogl_logfile.size())
            args.vogl_logfile = fname + ".log";
    }

    vogl_printf("\n");
    vogl_message_printf("Tracefile: %s\n", args.vogl_tracefile.c_str());
    vogl_message_printf("Logfile: %s", args.vogl_logfile.c_str());
    vogl_printf(" (will have PID appended)\n");

    dynamic_string vogltracepath32 = getfullpath("libvogltrace32.so");
    dynamic_string vogltracepath64 = getfullpath("libvogltrace64.so");

    // set up LD_PRELOAD string
    dynamic_string LD_PRELOAD = "LD_PRELOAD=\"";
    LD_PRELOAD += vogltracepath32 + ":" + vogltracepath64;

    if (is_steam_file || getenv("LD_PRELOAD"))
        LD_PRELOAD += ":$LD_PRELOAD";
    LD_PRELOAD += "\" ";
    vogl_printf("\n%s\n", LD_PRELOAD.c_str());

    // set up VOGL_CMD_LINE string
    dynamic_string VOGL_CMD_LINE = "VOGL_CMD_LINE=\"";
    VOGL_CMD_LINE += "--vogl_tracefile " + args.vogl_tracefile;
    VOGL_CMD_LINE += " --vogl_logfile " + args.vogl_logfile;
    VOGL_CMD_LINE += args.vogl_cmdline;
    VOGL_CMD_LINE += "\"";
    vogl_printf("\n%s\n", VOGL_CMD_LINE.c_str());

    dynamic_string xterm_str;
    if (args.xterm)
    {
        xterm_str = "xterm -geom 120x80+20+20";
        const char *env_user = getenv("USER");

        // If this is mikesart, specify using the Consolas font (which he likes).
        if (env_user && !strcmp(env_user, "mikesart"))
            xterm_str += " -fa Consolas -fs 10";

        // Add the xterm command part.
        xterm_str += " -e ";
    }

    if (is_steam_file)
    {
        // set up xterm string
        dynamic_string steam_cmd_str;

        steam_cmd_str = xterm_str + "%command% " + args.game_args;
        steam_cmd_str.trim();

        // set up steam string
        dynamic_string steam_str = "steam steam://run/" + args.gameid + "//";
        dynamic_string steam_args = VOGL_CMD_LINE + " " + LD_PRELOAD + steam_cmd_str;
        dynamic_string steam_fullcmd = steam_str + url_encode(steam_args.c_str());

        // Spew this whole mess out.
        vogl_printf("\nLaunch string:\n%s\n", (steam_str + steam_args).c_str());
        vogl_printf("\nURL encoded launch string:\n%s\n", steam_fullcmd.c_str());

        // And launch it...
        if (!args.dryrun)
            system(steam_fullcmd.c_str());
    }
    else
    {
        dynamic_string system_cmd;

        system_cmd = VOGL_CMD_LINE + " " + LD_PRELOAD + " " + xterm_str + args.gameid + " " + args.game_args;

        vogl_printf("\nlaunch string:\n%s\n", system_cmd.c_str());

        if (!args.dryrun)
            system(system_cmd.c_str());
    }

    return true;
}
示例#18
0
int main( int argc, char *argv[] )
{
    char * filename = NULL, dcbname[ __MAX_PATH ], *ptr, *arg0, *ext ;
    int i, j, ret = -1;
    file * fp = NULL;
    INSTANCE * mainproc_running;
    dcb_signature dcb_signature;

    /* disable stdout buffering */
    setvbuf( stdout, NULL, _IONBF, BUFSIZ );

    /* get my executable name */

#ifdef _WIN32
    if ( strlen( argv[0] ) < 4 || strncmpi( &argv[0][strlen( argv[0] ) - 4], ".exe", 4 ) )
    {
        arg0 = malloc( strlen( argv[0] ) + 5 );
        sprintf( arg0, "%s.exe", argv[0] );
    }
    else
    {
#endif
        arg0 = strdup( argv[0] );
#ifdef _WIN32
    }
#endif

    ptr = arg0 + strlen( arg0 );
    while ( ptr > arg0 && ptr[-1] != '\\' && ptr[-1] != '/' ) ptr-- ;

    appexename = strdup( ptr );

    /* get executable full pathname  */
    fp = NULL;
    appexefullpath = getfullpath( arg0 );
    if ( ( !strchr( arg0, '\\' ) && !strchr( arg0, '/' ) ) )
    {
        struct stat st;
        if ( stat( appexefullpath, &st ) || !S_ISREG( st.st_mode ) )
        {
            char *p = whereis( appexename );
            if ( p )
            {
                char * tmp = calloc( 1, strlen( p ) + strlen( appexename ) + 2 );
                free( appexefullpath );
                sprintf( tmp, "%s/%s", p, appexename );
                appexefullpath = getfullpath( tmp );
                free( tmp );
            }
        }
    }

    /* get pathname of executable */
    ptr = strstr( appexefullpath, appexename );
    appexepath = calloc( 1, ptr - appexefullpath + 1 );
    strncpy( appexepath, appexefullpath, ptr - appexefullpath );

    standalone = ( strncmpi( appexename, "bgdi", 4 ) == 0 ) ;

    /* add binary path */
    file_addp( appexepath );

#ifdef TARGET_WII
    // Initialize the Wii FAT filesystem, check stuff
    if (!fatInitDefault()) {
        printf("Sorry, I cannot access the FAT filesystem on your card :(\n");
        exit(1);
    }
#endif

    if ( !standalone )
    {
        /* Hand-made interpreter: search for DCB at EOF */
        fp = file_open( appexefullpath, "rb0" );
        if ( fp )
        {
            file_seek( fp, -( int )sizeof( dcb_signature ), SEEK_END );
            file_read( fp, &dcb_signature, sizeof( dcb_signature ) );

            if ( strcmp( dcb_signature.magic, DCB_STUB_MAGIC ) == 0 )
            {
                ARRANGE_DWORD( &dcb_signature.dcb_offset );
                embedded = 1;
            }
        }

        filename = appexefullpath;
    }

    if ( standalone )
    {
        /* Calling BGDI.EXE so we must get all command line params */

        for ( i = 1 ; i < argc ; i++ )
        {
            if ( argv[i][0] == '-' )
            {
                j = 1 ;
                while ( argv[i][j] )
                {
                    if ( argv[i][j] == 'd' ) debug++;
                    if ( argv[i][j] == 'i' )
                    {
                        if ( argv[i][j+1] == 0 )
                        {
                            if ( i == argc - 1 )
                            {
                                fprintf( stderr, "You must provide a directory" ) ;
                                exit( 0 );
                            }
                            file_addp( argv[i+1] );
                            i++ ;
                            break ;
                        }
                        file_addp( &argv[i][j + 1] ) ;
                        break ;
                    }
                    j++ ;
                }
            }
            else
            {
                if ( !filename )
                {
                    filename = argv[i] ;
                    if ( i < argc - 1 ) memmove( &argv[i], &argv[i+1], sizeof( char* ) * ( argc - i - 1 ) ) ;
                    argc-- ;
                    i-- ;
                }
            }
        }

        if ( !filename )
        {
            printf( BGDI_VERSION "\n"
                    "Bennu Game Development Interpreter\n"
                    "\n"
                    "Copyright (c) 2006-2012 SplinterGU (Fenix/BennuGD)\n"
                    "Copyright (c) 2002-2006 Fenix Team (Fenix)\n"
                    "Copyright (c) 1999-2002 José Luis Cebrián Pagüe (Fenix)\n"
                    "\n"
                    "Usage: %s [options] <data code block file>[.dcb]\n"
                    "\n"
                    "   -d       Activate DEBUG mode (several -d for increment debug level)\n"
                    "   -i dir   Adds the directory to the PATH\n"
                    "\n"
                    "This software is provided 'as-is', without any express or implied\n"
                    "warranty. In no event will the authors be held liable for any damages\n"
                    "arising from the use of this software.\n"
                    "\n"
                    "Permission is granted to anyone to use this software for any purpose,\n"
                    "including commercial applications, and to alter it and redistribute it\n"
                    "freely, subject to the following restrictions:\n"
                    "\n"
                    "   1. The origin of this software must not be misrepresented; you must not\n"
                    "   claim that you wrote the original software. If you use this software\n"
                    "   in a product, an acknowledgment in the product documentation would be\n"
                    "   appreciated but is not required.\n"
                    "\n"
                    "   2. Altered source versions must be plainly marked as such, and must not be\n"
                    "   misrepresented as being the original software.\n"
                    "\n"
                    "   3. This notice may not be removed or altered from any source\n"
                    "   distribution.\n"
                    , appexename ) ;
            return -1 ;
        }
    }

    /* Initialization (modules needed before dcb_load) */

    string_init() ;
    init_c_type() ;

    /* Init application title for windowed modes */

    strcpy( dcbname, filename ) ;

    ptr = filename + strlen( filename );
    while ( ptr > filename && ptr[-1] != '\\' && ptr[-1] != '/' ) ptr-- ;

    appname = strdup( ptr ) ;
    if ( strlen( appname ) > 3 )
    {
        char ** dcbext = dcb_exts, *ext = &appname[ strlen( appname ) - 4 ];
#ifdef _WIN32
        if ( !strncmpi( ext, ".exe", 4 ) )
        {
            *ext = '\0';
        }
        else
#endif
        while ( dcbext && *dcbext )
        {
            if ( !strncmpi( ext, *dcbext, 4 ) )
            {
                *ext = '\0';
                break;
            }
            dcbext++;
        }
    }

#ifdef __DEBUG__
printf( "appname        %s\n", appname);
printf( "appexename     %s\n", appexename);
printf( "appexepath     %s\n", appexepath);
printf( "appexefullpath %s\n", appexefullpath);
printf( "dcbname        %s\n", dcbname);
fflush(stdout);
#endif

    if ( !embedded )
    {
        /* First try to load directly (we expect myfile.dcb) */
        if ( !dcb_load( dcbname ) )
        {
            char ** dcbext = dcb_exts;
            int dcbloaded = 0;

            while ( dcbext && *dcbext )
            {
                strcpy( dcbname, appname ) ;
                strcat( dcbname, *dcbext ) ;
                if (( dcbloaded = dcb_load( dcbname ) ) ) break;
                dcbext++;
            }

            if ( !dcbloaded )
            {
                printf( "%s: doesn't exist or isn't version %d DCB compatible\n", filename, DCB_VERSION >> 8 ) ;
                return -1 ;
            }
        }
示例#19
0
文件: audio.c 项目: callaa/luola
/* Initialize */
void init_audio ()
{
#if HAVE_LIBSDL_MIXER
    Uint16 audio_format;
    LDAT *ldat;
    int w;

    /* Initialize SDL_mixer library */
    audio_format = MIX_DEFAULT_FORMAT;
    if (Mix_OpenAudio
        (luola_options.audio_rate, audio_format, 2,
         luola_options.audio_chunks) < 0) {
        fprintf (stderr,"Cannot open audio: %s\n", SDL_GetError ());
        audio_available = 0;
        return;
    } else {
        audio_available = 1;
        Mix_QuerySpec (&luola_options.audio_rate, &audio_format,
                       NULL);
    }
    /* Continue to the next song if it ends */
    Mix_HookMusicFinished (playlist_forward);

    /* Load samples */
    ldat = ldat_open_file(getfullpath(DATA_DIRECTORY,"sfx.ldat"));
    if(!ldat) {
        fprintf(stderr,"Can't load sound effects!");
    } else {
        for (w = 0; w < SAMPLE_COUNT; w++) {
            samples[w] = Mix_LoadWAV_RW(ldat_get_item(ldat,"SFX",w),0);
            if (samples[w] == NULL) {
                fprintf (stderr,"Couldn't get SFX %d\n", w);
            }
        }
    }
    ldat_free(ldat);

    /* Load playlist */
    playlist = NULL;
    {
        FILE *fp;
        char tmps[512];
        char *line = NULL;
        fp = fopen (getfullpath (HOME_DIRECTORY, "battle.pls"), "r");
        if (!fp) {
            fprintf (stderr,"No playlist file battle.pls\n");
            return;
        }
        for (; fgets (tmps, sizeof (tmps) - 1, fp); free (line)) {
            line = strip_white_space (tmps);
            if (line == NULL || strlen (line) == 0)
                continue;
            if (line[0] == '#')
                continue;
            if(playlist)
                dllist_append(playlist,strdup(line));
            else
                playlist = dllist_append(NULL,strdup(line));
        }
        fclose (fp);

        playlist_original = NULL;

        /* Load the first song */
        load_music();
    }
#endif
}
示例#20
0
int main( int argc, char *argv[] )
{
    time_t curtime;
    struct tm *loctime;
    int value, code;
    char * d, *d1;

    char * sourcefile = 0;
    char basepathname[__MAX_PATH] = "";
    char dcbname[__MAX_PATH] = "";
    char stubname[__MAX_PATH] = "";
    char importname[__MAX_PATH] = "";
    char compilerimport[__MAX_PATH] = "";
    int i, j;
    char *ptr;

    /* get my executable name */
    ptr = argv[0] + strlen( argv[0] );
    while ( ptr > argv[0] && ptr[-1] != '\\' && ptr[-1] != '/' ) ptr-- ;
    appexename = strdup( ptr );

    /* get executable full pathname  */
    appexefullpath = getfullpath( argv[0] );
    if ( ( !strchr( argv[0], '\\' ) && !strchr( argv[0], '/' ) ) && !file_exists( appexefullpath ) )
    {
        char *p = whereis( appexename );
        if ( p )
        {
            char * tmp = calloc( 1, strlen( p ) + strlen( appexename ) + 2 );
            free( appexefullpath );
            sprintf( tmp, "%s/%s", p, appexename );
            appexefullpath = getfullpath( tmp );
            free( tmp );
        }
    }

    /* get pathname of executable */
    ptr = strstr( appexefullpath, appexename );
    appexepath = calloc( 1, ptr - appexefullpath + 1 );
    strncpy( appexepath, appexefullpath, ptr - appexefullpath );

    printf( BGDC_VERSION "\n"
            "Bennu Game Development Compiler\n"
            "\n"
            "Copyright (c) 2006-2016 SplinterGU (Fenix/BennuGD)\n"
            "Copyright (c) 2002-2006 Fenix Team (Fenix)\n"
            "Copyright (c) 1999-2002 José Luis Cebrián Pagüe (Fenix)\n"
            "\n" );

    /* Default lang to EN */
    strcpy( langinfo, "EN" );
    /* LANG detect */
#ifdef WIN32
    GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, langinfo, 64 );
    strlwr( langinfo );
#else
    if ( getenv( "LANG" ) != NULL && strlen( getenv( "LANG" ) ) >= 2 )
        strcpy( langinfo, getenv( "LANG" ) );
#endif
    langinfo[2] = 0;

    srand( time( NULL ) );

    /* build error messages list */
    err_buildErrorTable();

    init_c_type();
    identifier_init();
    constants_init();
    string_init();
    compile_init();

    mainproc = procdef_new( procdef_getid(), identifier_search_or_add( "MAIN" ) ) ;

    /* Init vars */

    char tmp_version[ 32 ];
    sprintf( tmp_version, "\"%s\"", VERSION );
    add_simple_define( "COMPILER_VERSION", tmp_version );
    add_simple_define( "__VERSION__", tmp_version );

    curtime = time( NULL ); /* Get the current time. */
    loctime = localtime( &curtime ); /* Convert it to local time representation. */

    strftime( timebuff, sizeof( timebuff ), "%Y/%m/%d", loctime );
    value = string_new( timebuff );
    code = identifier_search_or_add( "__DATE__" ) ;
    constants_add( code, typedef_new( TYPE_STRING ), value ) ;

    strftime( timebuff, sizeof( timebuff ), "%H:%M:%S", loctime );
    value = string_new( timebuff );
    code = identifier_search_or_add( "__TIME__" ) ;
    constants_add( code, typedef_new( TYPE_STRING ), value ) ;
/*
    value = string_new( VERSION );
    code = identifier_search_or_add( "__VERSION__" ) ;
    constants_add( code, typedef_new( TYPE_STRING ), value ) ;
    code = identifier_search_or_add( "COMPILER_VERSION" ) ;
    constants_add( code, typedef_new( TYPE_STRING ), value ) ;
*/
    strcpy( _tmp, VERSION );
                d = strchr( _tmp, '.' ); *d = '\0'; add_simple_define( "__BGD__", _tmp );
    d1 = d + 1; d = strchr(   d1, '.' ); *d = '\0'; add_simple_define( "__BGD_MINOR__", d1 );
    d1 = d + 1;                                     add_simple_define( "__BGD_PATCHLEVEL__", d1 );

    memset( &dcb, 0, sizeof( dcb ) );

    core_init();
    sysproc_init();

    /* Get command line parameters */

    for ( i = 1 ; i < argc ; i++ )
    {
        if ( argv[i][0] == '-' )
        {
            if ( !strcmp( argv[i], "--pedantic" ) )
            {
                autodeclare = 0 ;
                continue;
            }

            if ( !strcmp( argv[i], "--libmode" ) )
            {
                libmode = 1 ;
                continue;
            }

            j = 1;
            while ( argv[i][j] )
            {
                if ( argv[i][j] == 'd' )
                {
                    if ( argv[i][j + 1] >= '0' && argv[i][j + 1] <= '9' )
                    {
                        debug = atoi( &argv[i][j + 1] );
                    }
                    else
                    {
                        debug = 1;
                    }
                }

                if ( argv[i][j] == 'o' )
                {
                    if ( argv[i][j + 1] )
                        strncpy( dcbname, &argv[i][j + 1], sizeof( dcbname ) );
                    else if ( argv[i + 1] && argv[i + 1][0] != '-' )
                        strncpy( dcbname, argv[++i], sizeof( dcbname ) );
                    break;
                }

                if ( argv[i][j] == 'c' ) dos_chars = 1;

                if ( argv[i][j] == 'a' ) autoinclude = 1;

                if ( argv[i][j] == 'g' ) dcb_options |= DCB_DEBUG;

                if ( argv[i][j] == 'p' ) autodeclare = 0 ;

                if ( argv[i][j] == 's' )
                {
                    /* -s "stub": Use a stub */

                    if ( argv[i][j + 1] )
                        strncpy( stubname, &argv[i][j + 1], __MAX_PATH );
                    else if ( argv[i + 1] && argv[i + 1][0] != '-' )
                        strncpy( stubname, argv[++i], __MAX_PATH );
                    break;
                }

                if ( argv[i][j] == 'f' )
                {
                    /* -f "file": Embed a file to the DCB */

                    if ( argv[i][j + 1] )
                        dcb_add_file( &argv[i][j + 1] );
                    else while ( argv[i + 1] )
                        {
                            if ( argv[i + 1][0] == '-' ) break;
                            dcb_add_file( argv[i + 1] );
                            i++;
                        }
                    break;
                }

                if ( argv[i][j] == 'i' )
                {
                    /* -i "path": add a file to the path for include files */

                    if ( argv[i][j + 1] == 0 )
                    {
                        if ( i == argc - 1 )
                        {
                            printf( MSG_DIRECTORY_MISSING "\n" );
                            exit( 1 );
                        }
                        file_addp( argv[i + 1] );
                        i++;
                        break;
                    }
                    file_addp( &argv[i][j + 1] );
                    break;
                }

                if ( argv[i][j] == 'l' )
                {
                    /* -lLANG:  Set the language for errors and messages */

                    if ( argv[i][j + 1] == 0 )
                    {
                        if ( i != argc - 1 )
                        {
                            strcpy( langinfo, argv[i + 1] );
                        }
                        i++;
                        break;
                    }
                    strcpy( langinfo, &argv[i][j + 1] );
                    break;
                }

                if ( argv[i][j] == 'D' )
                {
                    char * macro = NULL ;
                    char * text = NULL ;

                    /* -D<macro>=<text> */

                    if ( argv[i][j + 1] )
                    {
                        macro = strdup( &argv[i][j + 1] );
                    }
                    else
                    {
                        if ( argv[i + 1][0] == '-' ) break;
                        macro = strdup( argv[i + 1] );
                        i++;
                    }

                    if (( text = strchr( macro, '=' ) ) )
                    {
                        * text = '\0';
                        text++;
                    }
                    else
                    {
                        text = "";
                    }

                    add_simple_define( macro, text );
                    free( macro );
                    break;
                }

                if ( argv[i][j] == 'C' )
                {
                    if ( argv[i][j + 1] == 'a' ) autodeclare = 1 ;
                    break;
                }

                if ( argv[i][j] == 'L' )
                {
                    int r = 1;
                    char * f;
                    if ( argv[i][j + 1] )
                        r = dcb_load_lib( ( f = &argv[i][j + 1] ) );
                    else if ( argv[i + 1] && argv[i + 1][0] != '-' )
                    {
                        r = dcb_load_lib( ( f = argv[i + 1] ) );
                        i++;
                    }

                    switch ( r )
                    {
                        case    0:
                                printf( "ERROR: %s doesn't exist or isn't version DCB compatible\n", f ) ;
                                exit( -1 );

                        case    -1:
                                printf( "ERROR: %s isn't 7.10 DCB version, you need a 7.10 version or greater for use this feature\n", f ) ;
                                exit( -1 );
                    }
                    break;
                }

                j++;
            }
        }
        else
        {
/*
            if ( sourcefile )
            {
                printf( MSG_TOO_MANY_FILES "\n" );
                return 0;
            }
*/
            char * p, * pathend = NULL;

            sourcefile = argv[i];
            p = main_path = strdup( argv[i] );
            while ( p && *p )
            {
                if ( *p == ':' || *p == '\\' || *p == '/' ) pathend = p;
                p++;
            }
            if ( pathend )
            {
                *( pathend + 1 ) = '\0';
                file_addp( main_path );
            }
            else
            {
                free( main_path );
                main_path = getcwd(malloc(__MAX_PATH), __MAX_PATH);
                strcat(main_path, PATH_SEP);
            }

            /* Files names */

            strcpy( basepathname, sourcefile );
            REMOVE_EXT( basepathname );

            /* Default compiler imports */
            strcpy( compilerimport, argv[0] );
#ifdef WIN32
            REMOVE_EXT( compilerimport );
#endif
            strcat( compilerimport, ".imp" );
            import_files( compilerimport );
            strcat( compilerimport, "ort" ); /* name.import */
            import_files( compilerimport );

            /* Project imports */
            strcpy( importname, basepathname ); strcat( importname, ".imp" );
            import_files( importname );

            strcat( importname, "ort" ); /* name.import */
            import_files( importname );

            /* Load Main Source File */
            load_file( sourcefile );

            if ( !dcbname[0] )
            {
                strcpy( dcbname, basepathname ); strcat( dcbname, !libmode ? ".dcb" : ".dcl" );
            }
        }
    }

    if ( !sourcefile )
    {
        printf( MSG_USING
                MSG_OPTION_D
                MSG_OPTIONS
                MSG_LICENSE, argv[0] );
        return 0;
    }

    compile_program();

    if ( stubname[0] != 0 )
    {
        if ( !file_exists( stubname ) )
        {
#ifdef WIN32
            char exepath[__MAX_PATH];

            GetModuleFileName( NULL, exepath, sizeof( exepath ) );
            PathRemoveFileSpec( exepath );
            strcat( exepath, "\\" );
            memmove( stubname + strlen( exepath ), stubname, strlen( stubname ) + 1 );
            memcpy( stubname, exepath, strlen( exepath ) );
#else
            const char * ptr = argv[0] + strlen( argv[0] );
            while ( ptr > argv[0] && *ptr != '\\' && *ptr != '/' ) ptr--;
            if ( *ptr == '\\' || *ptr == '/' ) ptr++;
            if ( ptr > argv[0] )
            {
                memmove( stubname + ( ptr - argv[0] ), stubname, strlen( stubname ) + 1 );
                memcpy( stubname, argv[0], ptr - argv[0] );
            }
#endif
            if ( !file_exists( stubname ) )
            {
#ifdef WIN32
                strcat( stubname, ".exe" );
                if ( !file_exists( stubname ) )
                {
#endif
                    compile_error( "Can't open stub file %s", stubname );
#ifdef WIN32
                    return -1;
                }
#endif

            }
        }

        REMOVE_EXT( dcbname );
#ifdef WIN32
        strcat( dcbname, ".exe" );
#endif
        dcb_save( dcbname, dcb_options, stubname );
    }
    else
    {
        dcb_save( dcbname, dcb_options, NULL );
    }

    /* destroy error messages list */
    err_destroyErrorTable();

    return 1;
}