示例#1
0
static char *GetApplicationPath(void)
{
    static char buffer[256];
    char path[256];

    if(readlink("/proc/self/exe", path, sizeof(path)) <= 0)
        return NULL;

    M_GetFilePath(path, buffer, strlen(path)+1);
    return buffer;
}
示例#2
0
//
// E_Include
//
// The normal include function. cfg_include is insufficient since it 
// looks in the current working directory unless provided a full path.
// This function interprets paths relative to the current file when 
// called from a physical input file, and uses the argument as a lump 
// name otherwise.
//
int E_Include(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
{
   char  *currentpath = NULL;
   char  *filename    = NULL;
   size_t len         =  0;
   int    lumpnum     = -1;

   if(argc != 1)
   {
      cfg_error(cfg, "wrong number of args to include()\n");
      return 1;
   }
   if(!cfg->filename)
   {
      cfg_error(cfg, "include: cfg_t filename is undefined\n");
      return 1;
   }

   // 02/09/05: support both files and lumps in this function, but
   // only one or the other depending on the calling context
   switch(cfg_lexer_source_type(cfg))
   {
   case -1: // physical file
      len = M_StringAlloca(&currentpath, 1, 2, cfg->filename);
      M_GetFilePath(cfg->filename, currentpath, len);
      
      filename = M_SafeFilePath(currentpath, argv[0]);
      
      return E_OpenAndCheckInclude(cfg, filename, -1);
   
   default: // data source
      if(strlen(argv[0]) > 8)
      {
         cfg_error(cfg, "include: %s is not a valid lump name\n", argv[0]);
         return 1;
      }

      // haleyjd 03/19/10:
      // find a lump of the requested name in the same data source only
      if((lumpnum = E_FindLumpInclude(cfg, argv[0])) < 0)
      {
         cfg_error(cfg, "include: %s not found\n", argv[0]);
         return 1;
      }

      return E_OpenAndCheckInclude(cfg, argv[0], lumpnum);
   }
}
示例#3
0
//
// bex_include
//
// 12/12/03: New include function that allows EDF to queue
// DeHackEd/BEX files for later processing.  This helps to
// integrate BEX features such as string editing into the
// EDF/BEX superlanguage.
//
// This function interprets paths relative to the current 
// file.
//
static int bex_include(cfg_t *cfg, cfg_opt_t *opt, int argc,
                       const char **argv)
{
   char *currentpath;
   char *filename = NULL;

   // haleyjd 03/18/10: deprecation warning
   E_EDFLoggedWarning(0, "Warning: bexinclude is deprecated. "
                         "Please use a GFS or DEHACKED lump instead.\n");

   if(argc != 1)
   {
      cfg_error(cfg, "wrong number of args to bexinclude()\n");
      return 1;
   }
   if(!cfg->filename)
   {
      cfg_error(cfg, "bexinclude: cfg_t filename is undefined\n");
      return 1;
   }
   if(cfg_lexer_source_type(cfg) >= 0)
   {
      cfg_error(cfg, "bexinclude: cannot call from a wad lump\n");
      return 1;
   }

   currentpath = (char *)(Z_Alloca(strlen(cfg->filename) + 1));
   M_GetFilePath(cfg->filename, currentpath, strlen(cfg->filename) + 1);

   filename = M_SafeFilePath(currentpath, argv[0]);

   // queue the file for later processing
   D_QueueDEH(filename, 0);

   return 0;
}
示例#4
0
gfs_t *G_LoadGFS(const char *filename)
{
   static bool loaded = false;
   int i;
   cfg_t *cfg;

   // only one GFS can be loaded per session
   if(loaded)
      return NULL;

   cfg = cfg_init(gfs_opts, CFGF_NOCASE);

   cfg_set_error_function(cfg, E_ErrorCB);

   if(cfg_parse(cfg, filename))
      I_Error("G_LoadGFS: failed to parse GFS file\n");

   // count number of options
   gfs.numwads = cfg_size(cfg, SEC_WADFILE);
   gfs.numdehs = cfg_size(cfg, SEC_DEHFILE);
   gfs.numcsc  = cfg_size(cfg, SEC_CSCFILE);

   if(gfs.numwads)
      gfs.wadnames = ecalloc(char **, gfs.numwads, sizeof(char *));

   if(gfs.numdehs)
      gfs.dehnames = ecalloc(char **, gfs.numdehs, sizeof(char *));

   if(gfs.numcsc)
      gfs.cscnames = ecalloc(char **, gfs.numcsc,  sizeof(char *));

   // load wads, dehs, csc
   for(i = 0; i < gfs.numwads; i++)
   {
      const char *str = cfg_getnstr(cfg, SEC_WADFILE, i);

      gfs.wadnames[i] = estrdup(str);
   }
   for(i = 0; i < gfs.numdehs; i++)
   {
      const char *str = cfg_getnstr(cfg, SEC_DEHFILE, i);
      
      gfs.dehnames[i] = estrdup(str);
   }
   for(i = 0; i < gfs.numcsc; i++)
   {
      const char *str = cfg_getnstr(cfg, SEC_CSCFILE, i);

      gfs.cscnames[i] = estrdup(str);
   }

   // haleyjd 07/05/03: support root EDF specification
   if(cfg_size(cfg, SEC_EDFFILE) >= 1)
   {
      const char *str = cfg_getstr(cfg, SEC_EDFFILE);

      gfs.edf = estrdup(str);

      gfs.hasEDF = true;
   }

   // haleyjd 04/16/03: support iwad specification for end-users
   // (this is not useful to mod authors, UNLESS their mod happens
   // to be an IWAD file ;)
   if(cfg_size(cfg, SEC_IWAD) >= 1)
   {
      const char *str = cfg_getstr(cfg, SEC_IWAD);

      gfs.iwad = estrdup(str);

      gfs.hasIWAD = true;
   }

   // haleyjd 04/16/03: basepath support
   if(cfg_size(cfg, SEC_BASEPATH) >= 1)
   {
      const char *str = cfg_getstr(cfg, SEC_BASEPATH);

      gfs.filepath = estrdup(str);
   }
   else
   {
      gfs.filepath = emalloc(char *, strlen(filename) + 1);
      M_GetFilePath(filename, gfs.filepath, strlen(filename));
   }

   cfg_free(cfg);

   loaded = true;

   return &gfs;
}
示例#5
0
void D_IdentifyVersion(void)
{
    // gamemission is set up by the D_FindIWAD function.  But if 
    // we specify '-iwad', we have to identify using 
    // IdentifyIWADByName.  However, if the iwad does not match
    // any known IWAD name, we may have a dilemma.  Try to 
    // identify by its contents.
    
    // STRIFE-TODO: some elaborate checks? for now we assume...
    // The logic in strife1.exe is simple:
    // * if strife1.wad is found, set isregistered = true
    // * if strife0.wad is found, set isdemoversion = true

    // Make sure gamemode is set up correctly
    gamemode = commercial;
    gamemission = strife;
    isregistered = true;

    // Load voices.wad 
    if(isregistered)
    {
        char *name = D_FindWADByName("voices.wad");

        if(!name) // not found?
        {
            int p;

            // haleyjd STRIFE-FIXME: Temporary?
            // If -iwad was used, check and see if voices.wad exists on the
            // same filepath.
            if((p = M_CheckParm("-iwad")) && p < myargc - 1)
            {
                char   *iwad     = myargv[p + 1];
                size_t  len      = strlen(iwad) + 24;
                char   *filename = malloc(len);
                char    sepchar;

                // how the heck is Choco surviving without this routine?
                sepchar = M_GetFilePath(iwad, filename, len);
                filename[strlen(filename)] = sepchar;
                M_StringConcat(filename, "voices.wad", sizeof(filename));

                if(!M_FileExists(filename))
                    disable_voices = 1;
                else
                    name = filename; // STRIFE-FIXME: memory leak!!
            }
            else
                disable_voices = 1;
        }

        if(disable_voices) // voices disabled?
        {
            if(devparm)
                 printf("Voices disabled\n");
            return;
        }

        D_AddFile(name);
    }
}
示例#6
0
void D_IdentifyVersion(void)
{
    // gamemission is set up by the D_FindIWAD function.  But if
    // we specify '-iwad', we have to identify using
    // IdentifyIWADByName.  However, if the iwad does not match
    // any known IWAD name, we may have a dilemma.  Try to
    // identify by its contents.

    // STRIFE-TODO: some elaborate checks? for now we assume...
    // The logic in strife1.exe is simple:
    // * if strife1.wad is found, set isregistered = true
    // * if strife0.wad is found, set isdemoversion = true

    // Make sure gamemode is set up correctly
    gamemode = commercial;
    gamemission = strife;
    isregistered = true;

    // Load voices.wad
    if(isregistered)
    {
        char *name = D_FindWADByName("voices.wad");

        if(!name) // not found?
        {
            int p;

            // haleyjd STRIFE-FIXME: Temporary?
            // If -iwad was used, check and see if voices.wad exists on the
            // same filepath.
            if((p = M_CheckParm("-iwad")) && p < myargc - 1)
            {
                char   *iwad     = myargv[p + 1];
                size_t  len      = strlen(iwad) + 1;
                char   *iwadpath = Z_Malloc(len, PU_STATIC, NULL);
                char   *voiceswad;

                // extract base path of IWAD parameter
                M_GetFilePath(iwad, iwadpath, len);

                // concatenate with /voices.wad
                voiceswad = M_SafeFilePath(iwadpath, "voices.wad");
                Z_Free(iwadpath);

                if(!M_FileExists(voiceswad))
                {
                    disable_voices = 1;
                    Z_Free(voiceswad);
                }
                else
                    name = voiceswad; // STRIFE-FIXME: memory leak!!
            }
            else
                disable_voices = 1;
        }

        if(disable_voices) // voices disabled?
        {
            if(devparm)
                printf("Voices disabled\n");
            return;
        }

        D_AddFile(name);
    }
}