コード例 #1
0
/**
 * configpath: get path of configuration file.
 *
 *	@param[in]	rootdir	Project root directory
 *	@return		path name of the configuration file or NULL
 */
static char *
configpath(const char *rootdir)
{
	STATIC_STRBUF(sb);
	const char *p;

	strbuf_clear(sb);
	/*
	 * at first, check environment variable GTAGSCONF.
	 */
	if (getenv("GTAGSCONF") != NULL)
		strbuf_puts(sb, getenv("GTAGSCONF"));
	/*
	 * if GTAGSCONF not set then check standard config files.
	 */
	else if (rootdir && *rootdir && test("r", makepath(rootdir, "gtags.conf", NULL)))
		strbuf_puts(sb, makepath(rootdir, "gtags.conf", NULL));
	else if ((p = get_home_directory()) && test("r", makepath(p, GTAGSRC, NULL)))
		strbuf_puts(sb, makepath(p, GTAGSRC, NULL));
#ifdef __DJGPP__
	else if ((p = get_home_directory()) && test("r", makepath(p, DOS_GTAGSRC, NULL)))
		strbuf_puts(sb, makepath(p, DOS_GTAGSRC, NULL));
#endif
	else if (test("r", GTAGSCONF))
		strbuf_puts(sb, GTAGSCONF);
	else if (test("r", DEBIANCONF))
		strbuf_puts(sb, DEBIANCONF);
	else if (test("r", makepath(SYSCONFDIR, "gtags.conf", NULL)))
		strbuf_puts(sb, makepath(SYSCONFDIR, "gtags.conf", NULL));
	else
		return NULL;
	return strbuf_value(sb);
}
コード例 #2
0
ファイル: main.c プロジェクト: Telegram-FFOS/tg
void parse_config (void) {
  printf ("libconfig not enabled\n");
  tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE);
  tasprintf (&state_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, STATE_FILE);
  tasprintf (&secret_chat_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, SECRET_CHAT_FILE);
  tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
  tasprintf (&binlog_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, BINLOG_FILE);
}
コード例 #3
0
ファイル: main.cpp プロジェクト: shazz/freelan
std::vector<fs::path> get_configuration_files()
{
	std::vector<fs::path> configuration_files;

#ifdef WINDOWS
	configuration_files.push_back(get_home_directory() / "freelan.cfg");
	configuration_files.push_back(get_application_directory() / "freelan.cfg");
#else
	configuration_files.push_back(get_home_directory() / ".freelan/freelan.cfg");
	configuration_files.push_back(get_application_directory() / "freelan.cfg");
#endif

	return configuration_files;
}
コード例 #4
0
ファイル: Resources.cpp プロジェクト: SuperNascher/goatattack
void Resources::load_resources(bool home_paks_only) throw (ResourcesException) {
    try {
        if (!home_paks_only) {
            /* scan main directories */
            subsystem << "scanning main directories" << std::endl;
            read_all(resource_directory + dir_separator, 0, true);

            /* read main paks */
            Directory dir(resource_directory, ".pak");
            const char *entry = 0;
            while ((entry = dir.get_entry())) {
                subsystem << "scanning " << entry << ".pak" << std::endl;
                try {
                    ZipReader zip(resource_directory + dir_separator + entry + ".pak");
                    read_all("", &zip, true);
                    loaded_paks.push_back(LoadedPak(zip.get_zip_filename(), zip.get_zip_short_filename(), zip.get_hash(), false));
                } catch (const ZipException& e) {
                    subsystem << e.what() << std::endl;
                }
            }
        }

        /* scan user directories */
        subsystem << "scanning user directories" << std::endl;
        read_all(get_home_directory() + dir_separator + UserDirectory + dir_separator, 0, false);

        /* read home directory */
        std::string hdir = get_home_directory() + dir_separator + UserDirectory;
        Directory dir(hdir, ".pak");
        const char *entry = 0;
        while ((entry = dir.get_entry())) {
            subsystem << "scanning " << entry << ".pak" << std::endl;
            try {
                ZipReader zip(hdir + dir_separator + entry + ".pak");
                read_all("", &zip, false);
                loaded_paks.push_back(LoadedPak(zip.get_zip_filename(), zip.get_zip_short_filename(), zip.get_hash(), true));
            } catch (const ZipException& e) {
                subsystem << e.what() << std::endl;
            }
        }

        /* prepare all resources for quick accesses */
        subsystem.set_scanlines_icon(get_icon("scanlines"));
        prepare_resources();
    } catch (const Exception& e) {
        destroy_resources(false);
        throw ResourcesException(e.what());
    }
}
コード例 #5
0
ファイル: mingw32.c プロジェクト: ahnan4arch/ptex-ng
void
init_user_info (void)
{
  /* Ensure HOME and SHELL are defined. */
  char *home = get_home_directory();
  if (home) {
    putenv(concat("HOME=", home));
  }
  else {
    putenv ("HOME=c:/");
  }
  if (getenv ("SHELL") == NULL)
    putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");

  {
    /* Win2K problem : we need a specific TEMP directory with
       full access rights so that any user building a format file
       or a font file will build it with full access rights. The installer
       takes care of defining TEXMFTEMP=$SELFAUTOPARENT/tmp in the environment.
       If it is defined, then use it as the TEMP and TMP variables.
    */
    char *p;
    if ((p = getenv("TEXMFTEMP")) != NULL) {
      putenv(concat("TEMP=", p));
      putenv(concat("TMP=", p));
    }
  }
}
コード例 #6
0
ファイル: pg_enc.c プロジェクト: pgpool/pgpool2
static void
print_usage(const char prog[], int exit_code)
{
	char		homedir[POOLMAXPATHLEN];
	FILE	   *stream = (exit_code == EXIT_SUCCESS) ? stdout : stderr;

	if (!get_home_directory(homedir, sizeof(homedir)))
		strncpy(homedir, "USER-HOME-DIR", POOLMAXPATHLEN);

	fprintf(stream, "%s version %s (%s),\n", PACKAGE, VERSION, PGPOOLVERSION);
	fprintf(stream, "  password encryption utility for Pgpool\n\n");
	fprintf(stream, "Usage:\n");
	fprintf(stream, "  %s [OPTIONS] <PASSWORD>\n", prog);
	fprintf(stream, "  -k, --key-file=KEY_FILE\n");
	fprintf(stream, "                       Set the path to the encryption key file.\n");
	fprintf(stream, "                       Default: %s/%s\n", homedir, POOLKEYFILE);
	fprintf(stream, "                       Can be overridden by the %s environment variable.\n", POOLKEYFILEENV);
	fprintf(stream, "  -K, --enc-key=ENCRYPTION_KEY\n");
	fprintf(stream, "                       Encryption key to be used for encrypting database passwords.\n");
	fprintf(stream, "  -f, --config-file=CONFIG_FILE\n");
	fprintf(stream, "                       Specifies the pgpool.conf file.\n");
	fprintf(stream, "  -p, --prompt         Prompt for database password using standard input.\n");
	fprintf(stream, "  -P, --prompt-for-key Prompt for encryption key using standard input.\n");
	fprintf(stream, "  -m, --update-pass    Create encrypted password entry in the pool_passwd file.\n");
	fprintf(stream, "  -u, --username       The username for the pool_password entry.\n");
	fprintf(stream, "  -h, --help           Print this help.\n\n");

	exit(exit_code);
}
コード例 #7
0
ファイル: path.c プロジェクト: ni742015/git
void home_config_paths(char **global, char **xdg, char *file)
{
	char *xdg_home = getenv("XDG_CONFIG_HOME");
	const char *home = get_home_directory();
	char *to_free = NULL;

	if (!home) {
		if (global)
			*global = NULL;
	} else {
		if (!xdg_home) {
			to_free = mkpathdup("%s/.config", home);
			xdg_home = to_free;
		}
		if (global)
			*global = mkpathdup("%s/.gitconfig", home);
	}

	if (!xdg_home)
		*xdg = NULL;
	else
		*xdg = mkpathdup("%s/git/%s", xdg_home, file);

	free(to_free);
}
コード例 #8
0
ファイル: path.c プロジェクト: ni742015/git
/*
 * Return a string with ~ and ~user expanded via getpw*.  If buf != NULL,
 * then it is a newly allocated string. Returns NULL on getpw failure or
 * if path is NULL.
 */
char *expand_user_path(const char *path)
{
	struct strbuf user_path = STRBUF_INIT;
	const char *first_slash = strchrnul(path, '/');
	const char *to_copy = path;

	if (path == NULL)
		goto return_null;
	if (path[0] == '~') {
		const char *username = path + 1;
		size_t username_len = first_slash - username;
		if (username_len == 0) {
			const char *home = get_home_directory();
			if (!home)
				goto return_null;
			strbuf_add(&user_path, home, strlen(home));
		} else {
			struct passwd *pw = getpw_str(username, username_len);
			if (!pw)
				goto return_null;
			strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
		}
		to_copy = first_slash;
	}
	strbuf_add(&user_path, to_copy, strlen(to_copy));
	return strbuf_detach(&user_path, NULL);
return_null:
	strbuf_release(&user_path);
	return NULL;
}
コード例 #9
0
const char* Application::get_user_settings_path()
{
    static char user_settings_buffer[FOUNDATION_MAX_PATH_LENGTH + 1];
    static bool user_settings_initialized = false;

    if (!user_settings_initialized)
    {
// Windows.
#if defined _WIN32

        return 0;

// OS X.
#elif defined __APPLE__

        return 0;

// Other Unices.
#elif defined __linux__ || defined __FreeBSD__

        bf::path p(get_home_directory());
        p /= ".appleseed/settings";
        copy_directory_path_to_buffer(p, user_settings_buffer);

// Other platforms.
#else

        #error Unsupported platform.

#endif
        user_settings_initialized = true;
    }

    return user_settings_buffer;
}
コード例 #10
0
ファイル: shell.c プロジェクト: 1974kpkpkp/git
static void cd_to_homedir(void)
{
	const char *home = get_home_directory();
	if (!home)
		die("could not determine user's home directory; HOME is unset");
	if (chdir(home) == -1)
		die("could not chdir to user's home directory");
}
コード例 #11
0
ファイル: main.c プロジェクト: analani/tg
char *make_full_path (char *s) {
  if (*s != '/') {
    char *t = s;
    tasprintf (&s, "%s/%s", get_home_directory (), s);
    tfree_str (t);
  }
  return s;
}
コード例 #12
0
ファイル: gozilla.c プロジェクト: cage433/global_with_scala
/*
 * load_alias: load alias value.
 *
 * [$HOME/.gozillarc]
 * +-----------------------
 * |a:http://www.gnu.org
 * |f = file:/usr/share/xxx.html
 * |www	http://www.xxx.yyy/
 */
static void
load_alias(void)
{
	FILE *ip;
	STRBUF *sb = strbuf_open(0);
	char *p;
	int flag = STRBUF_NOCRLF;
	struct sh_entry *ent;

	sh = strhash_open(10);
	if (!(p = get_home_directory()))
		goto end;
	if (!test("r", makepath(p, gozillarc, NULL)))
#ifdef __DJGPP__
		if (!test("r", makepath(p, dos_gozillarc, NULL)))
#endif
			goto end;
	if (!(ip = fopen(makepath(p, gozillarc, NULL), "r")))
#ifdef __DJGPP__
		if (!(ip = fopen(makepath(p, dos_gozillarc, NULL), "r")))
#endif
			goto end;
	while ((p = strbuf_fgets(sb, ip, flag)) != NULL) {
		char *name, *value;

		flag &= ~STRBUF_APPEND;
		if (*p == '#')
			continue;
		if (strbuf_unputc(sb, '\\')) {
			flag |= STRBUF_APPEND;
			continue;
		}
		while (*p && isblank(*p))	/* skip spaces */
			p++;
		name = p;
		while (*p && isalnum(*p))	/* get name */
			p++;
		*p++ = 0;
		while (*p && isblank(*p))	/* skip spaces */
			p++;
		if (*p == '=' || *p == ':') {
			p++;
			while (*p && isblank(*p))/* skip spaces */
				p++;
		}
		value = p;
		while (*p && !isblank(*p))	/* get value */
			p++;
		*p = 0;
		ent = strhash_assign(sh, name, 1);
		if (ent->value)
			(void)free(ent->value);
		ent->value = check_strdup(value);
	}
	fclose(ip);
end:
	strbuf_close(sb);
}
コード例 #13
0
ファイル: file.c プロジェクト: davidben/zephyr
FILE *locate_file(char *override_filename,
		  char *home_dir_filename,
		  char *fallback_filename)
{
    char *filename;
    FILE *result;

    errno = 0;

    if (override_filename) {
	if (string_Eq(override_filename, "-"))
	  return(stdin);
	
	result = fopen(override_filename, "r");
	if (!(result = fopen(override_filename, "r"))) {
	    /* <<<>>> */
	    fprintf(stderr, "zwgc: error while opening %s for reading: ",
		   override_filename);
	    perror("");
	}
	return(result);
    }

    if (home_dir_filename) {
	filename = get_home_directory();
	if (filename) {
	    filename = string_Concat(filename, "/");
	    filename = string_Concat2(filename, home_dir_filename);
	    result = fopen(filename, "r");
	    if (result) {
		free(filename);
		return(result);
	    }
	    if (errno != ENOENT) {
		/* <<<>>> */
		fprintf(stderr, "zwgc: error while opening %s for reading: ",
			filename);
		perror("");
		free(filename);
		return(result);
	    }
	    free(filename);
	} else
	  ERROR("unable to find your home directory.\n");
    }

    if (fallback_filename) {
	if (!(result = fopen(fallback_filename, "r"))) {
	    /* <<<>>> */
	    fprintf(stderr, "zwgc: error while opening %s for reading: ",
		   fallback_filename);
	    perror("");
	}
	return(result);
    }

    return(NULL);
}
コード例 #14
0
ファイル: main.cpp プロジェクト: RoPe93/freelan-all
std::vector<fs::path> get_configuration_files()
{
	std::vector<fs::path> configuration_files;

	configuration_files.push_back(get_home_directory() / "freelan.cfg");
	configuration_files.push_back(get_configuration_directory() / "freelan.cfg");

	return configuration_files;
}
コード例 #15
0
ファイル: Resources.cpp プロジェクト: SuperNascher/goatattack
/* class implementation begins here */
Resources::Resources(Subsystem& subsystem, const std::string& resource_directory) throw (ResourcesException)
    : subsystem(subsystem), resource_directory(resource_directory)
{
    subsystem << "initializing resources" << std::endl;
    srand(static_cast<unsigned int>(time(0)));

    create_directory(UserDirectory, get_home_directory());

    load_resources(false);
}
コード例 #16
0
ファイル: ccache.c プロジェクト: wereHamster/ccache
int main(int argc, char *argv[])
{
	char *p;

	cache_dir = getenv("CCACHE_DIR");
	if (!cache_dir) {
		x_asprintf(&cache_dir, "%s/.ccache", get_home_directory());
	}

	temp_dir = getenv("CCACHE_TEMPDIR");
	if (!temp_dir) {
		temp_dir = cache_dir;
	}

	cache_logfile = getenv("CCACHE_LOGFILE");

	setup_uncached_err();
	

	/* the user might have set CCACHE_UMASK */
	p = getenv("CCACHE_UMASK");
	if (p) {
		mode_t mask;
		errno = 0;
		mask = strtol(p, NULL, 8);
		if (errno == 0) {
			umask(mask);
		}
	}


	/* check if we are being invoked as "ccache" */
	if (strlen(argv[0]) >= strlen(MYNAME) &&
	    strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) == 0) {
		if (argc < 2) {
			usage();
			exit(1);
		}
		/* if the first argument isn't an option, then assume we are
		   being passed a compiler name and options */
		if (argv[1][0] == '-') {
			return ccache_main(argc, argv);
		}
	}

	/* make sure the cache dir exists */
	if (create_dir(cache_dir) != 0) {
		fprintf(stderr,"ccache: failed to create %s (%s)\n", 
			cache_dir, strerror(errno));
		exit(1);
	}

	ccache(argc, argv);
	return 1;
}
コード例 #17
0
ファイル: util.c プロジェクト: gregory144/path-manager
bool install_in_shell(bool global) {
  // keep track of the number of files
  // that we've written to (should end up being 2)
  int wrote_files = 0;

  char* script = bash_script();
  if (script) {
    print_verbose("Writing \"%s\"\n", script);

    char *profile_filename = NULL;

    if (global) {
      //global mode - install in /etc/profile and /etc/bash.bashrc
      if (directory_exists("/etc/profile.d")) {
        profile_filename = "/etc/profile.d/path.sh";
      } else if (file_exists("/etc/profile")) {
        profile_filename = "/etc/profile";
      }
      if (profile_filename) {
        if (write_script(profile_filename, script)) wrote_files++;
      }
      if (file_exists("/etc/bash.bashrc")) {
        if (write_script("/etc/bash.bashrc", script)) wrote_files++;
      }
    } else {
      //user mode - install in profile, rc file
      char* home_dir = get_home_directory();
      int i;
      char* profile_search_list[] = {".bash_profile", ".bash_login", ".profile"};
      for (i = 0; i < 3; i++) {
        char* filename = file_join(home_dir, profile_search_list[i]);
        if (file_exists(filename)) {
          profile_filename = filename;
          break;
        }
        free(filename);
      }
      if (!profile_filename) {
        profile_filename = file_join(home_dir, profile_search_list[0]);
      }
      if (write_script(profile_filename, script)) wrote_files++;
      free(profile_filename);

      char* rc_filename = file_join(home_dir, ".bashrc");
      if (write_script(rc_filename, script)) wrote_files++;
      free(rc_filename);

      free(home_dir);
    }

    free(script);
  }
  return wrote_files == 2;
}
コード例 #18
0
ファイル: win32lib.c プロジェクト: luigiScarso/luatexjit
void
kpathsea_init_user_info (kpathsea kpse)
{
   char  *home;
   DWORD nSize = 256;

   if (!GetUserName (kpse->the_passwd.pw_name, &nSize))
      strcpy (kpse->the_passwd.pw_name, "unknown");
   kpse->the_passwd.pw_uid = 123;
   kpse->the_passwd.pw_gid = 123;

   /* Ensure HOME and SHELL are defined. */

   home = get_home_directory();
   if (home) {
      putenv(concat("HOME=", home));
   }
   else {
      putenv ("HOME=c:/");
   }

   if (getenv ("SHELL") == NULL)
      putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");

   {
   /* If TEXMFTEMP is defined, then use it as the TEMP and TMP variables. */
      char *p;
      if ((p = getenv("TEXMFTEMP")) != NULL) {
         putenv(concat("TEMP=", p));
         putenv(concat("TMP=", p));
      }
   }

   /* Set dir and shell from environment variables. */
   strcpy (kpse->the_passwd.pw_dir, get_home_directory());
   strcpy (kpse->the_passwd.pw_shell, getenv ("SHELL"));
}
コード例 #19
0
ファイル: main.c プロジェクト: analani/tg
void parse_config (void) {
  if (!disable_output) {
    printf ("libconfig not enabled\n");
  }
  tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
  
  if (binlog_enabled) {
    tasprintf (&binlog_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, BINLOG_FILE);
    tgl_set_binlog_mode (1);
    tgl_set_binlog_path (binlog_file_name);
  } else {
    tgl_set_binlog_mode (0);
    //tgl_set_auth_file_path (auth_file_name;
    tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE);
    tasprintf (&state_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, STATE_FILE);
    tasprintf (&secret_chat_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, SECRET_CHAT_FILE);
  }
  tgl_set_download_directory (downloads_directory);
  if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", downloads_directory);
    }
  }
}
コード例 #20
0
ファイル: main.c プロジェクト: pwrtelegram/tg
char *get_config_directory (void) {
  char *config_directory;
  config_directory = getenv("TELEGRAM_CONFIG_DIR");
  if (!str_empty (config_directory)) { return tstrdup (config_directory); }
  // XDG: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
  config_directory = getenv("XDG_CONFIG_HOME");
  if (!str_empty (config_directory)) {
    tasprintf (&config_directory, "%s/" PROG_NAME, config_directory);
    // :TODO: someone check whether it could be required to pass tasprintf
    //        a tstrdup()ed config_directory instead; works for me without.
    //        should work b/c this scope's lifespan encompasses tasprintf()
    return config_directory;
  }
  tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ());
  return config_directory;
}
コード例 #21
0
ファイル: main.c プロジェクト: analani/tg
void running_for_first_time (void) {
  check_type_sizes ();
  if (config_filename) {
    return; // Do not create custom config file
  }
  tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE);
  config_filename = make_full_path (config_filename);

  int config_file_fd;
  char *config_directory = get_config_directory ();
  //char *downloads_directory = get_downloads_directory ();

  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }

  tfree_str (config_directory);
  config_directory = NULL;
  // see if config file is there
  if (access (config_filename, R_OK) != 0) {
    // config file missing, so touch it
    config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
    if (config_file_fd == -1)  {
      perror ("open[config_file]");
      exit (EXIT_FAILURE);
    }
    if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
      perror ("write[config_file]");
      exit (EXIT_FAILURE);
    }
    close (config_file_fd);
    /*int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
    int x = -1;
    assert (write (auth_file_fd, &x, 4) == 4);
    close (auth_file_fd);

    printf ("[%s] created\n", config_filename);*/
  
    /* create downloads directory */
    /*if (mkdir (downloads_directory, 0755) !=0) {
      perror ("creating download directory");
      exit (EXIT_FAILURE);
    }*/
  }
}
コード例 #22
0
ファイル: pcp.c プロジェクト: ysd001/pgpool2
/*
 * get the password file name which could be either pointed by PCPPASSFILE
 * environment variable or resides in user home directory.
 */
static bool
getPoolPassFilename(char *pgpassfile)
{
	char       *passfile_env;
	
	if ((passfile_env = getenv("PCPPASSFILE")) != NULL)
	{
		/* use the literal path from the environment, if set */
		strlcpy(pgpassfile, passfile_env, MAXPGPATH);
	}
	else
	{
		char            homedir[MAXPGPATH];
		if (!get_home_directory(homedir, sizeof(homedir)))
			return false;
		snprintf(pgpassfile, MAXPGPATH, "%s/%s", homedir, PCPPASSFILE);
	}
	return true;
}
コード例 #23
0
ファイル: pg_enc.c プロジェクト: pgpool/pgpool2
static bool
get_pool_key_filename(char *poolKeyFile)
{
	char	   *passfile_env;

	if ((passfile_env = getenv(POOLKEYFILEENV)) != NULL)
	{
		/* use the literal path from the environment, if set */
		strlcpy(poolKeyFile, passfile_env, POOLMAXPATHLEN);
	}
	else
	{
		char		homedir[POOLMAXPATHLEN];

		if (!get_home_directory(homedir, sizeof(homedir)))
			return false;
		snprintf(poolKeyFile, POOLMAXPATHLEN + sizeof(POOLKEYFILE) + 1, "%s/%s", homedir, POOLKEYFILE);
	}
	return true;
}
コード例 #24
0
ファイル: conf.c プロジェクト: venkrao/ccache
/* Create a conf struct with default values. */
struct conf *
conf_create(void)
{
	size_t i;
	struct conf *conf = x_malloc(sizeof(*conf));
	conf->base_dir = x_strdup("");
	conf->cache_dir = format("%s/.ccache", get_home_directory());
	conf->cache_dir_levels = 2;
	conf->compiler = x_strdup("");
	conf->compiler_check = x_strdup("mtime");
	conf->compression = false;
	conf->compression_level = 6;
	conf->cpp_extension = x_strdup("");
	conf->direct_mode = true;
	conf->disable = false;
	conf->extra_files_to_hash = x_strdup("");
	conf->hard_link = false;
	conf->hash_dir = false;
	conf->log_file = x_strdup("");
	conf->max_files = 0;
	conf->max_size = (uint64_t)5 * 1000 * 1000 * 1000;
	conf->path = x_strdup("");
	conf->prefix_command = x_strdup("");
	conf->read_only = false;
	conf->read_only_direct = false;
	conf->recache = false;
	conf->run_second_cpp = false;
	conf->sloppiness = 0;
	conf->stats = true;
	conf->temporary_dir = x_strdup("");
	conf->umask = UINT_MAX; /* default: don't set umask */
	conf->unify = false;
	conf->cache_repo_path = x_strdup("");
	conf->item_origins = x_malloc(CONFITEMS_TOTAL_KEYWORDS * sizeof(char *));
	for (i = 0; i < CONFITEMS_TOTAL_KEYWORDS; ++i) {
		conf->item_origins[i] = "default";
	}
	return conf;
}
コード例 #25
0
ファイル: sysipaq.c プロジェクト: webushka/reduce
void process_file_name(char *filename, char *old, size_t n)
/*
 * This procedure maps filenames by expanding some environment
 * variables.  It is very thoroughly system specific, which is why it
 * is in this file.  See also LONGEST_LEGAL_FILENAME in "tags.h" for a
 * limit on the permitted size of an expanded filename.
 * The input (old) is not necessarily properly terminated as a C string,
 * so n says how many characters to inspect.  Build a converted name
 * in filename.
 * At present the expansions I allow are:
 *
 *    $xxx   (terminated by '.', '/' or '\' with at least one char x)
 *    ${xxx} (self-terminating)
 *           First check for a Lisp variable $xxx. If this is set (and is
 *           a string or a symbol) then its value is used. If not then
 *           next inspect the environment variable xxx and dump its
 *           value into the output.  If the variable is unset then a check
 *           is made for the value of a global lisp variable called @xxx,
 *           and if that exists and is a string or symbol it is used.
 *           If @xxx is undefined a null string is inserted.
 *           If one of the variables is defined but has an improper value
 *           then the whole file-translation fails.
 *           The use of two Lisp variables makes it possible to control
 *           precedence between these and shell variables.
 *
 *    ~      ) followed by '.', '/' or '\'
 *    ~xxx   )
 *           On Unix these try to find home directories using
 *           getpwuid(getuid()) for '~' and getpwnam() for ~xxx.
 *           If that fails ~ expands into nothing at all.
 *           This syntax is only recognised at the very start of a file-name.
 *           For systems other than Unix this syntax will not be useful and
 *           should be avoided, however as an experimental place-holder I
 *           may do things with environment variables called HOME etc.
 * 
 * 
 * I convert file-names of the form aaa/bbb/ccc.ddd into something
 * acceptable to the system being used, even though this may result in
 * some native file titles that include '/' characters becoming unavailable.
 * The reasoning here is that scripts and programs can then use Unix-like
 * names and non-Unix hosts will treat them forgivingly.
 *
 *
 */
{
    int i;
    int c;
    char *o;
    if (n == 0)
    {   *filename = 0;
        return;    /* deem zero-length name to be illegal */
    }
    o = filename;
    c = *old;
/*
 * First I deal with a leading "~"
 */
    if (c == '~')
    {   old++;
        n--;
        while (n != 0)
        {   c = *old;
            if (c == '.' || c == '/' || c == '\\') break;
            old++;
            n--;
            *o++ = (char)c;
        }
        *o = 0;
/*
 * actually deciding what the home directory is is passed down to a
 * system-specific call, but it is not to be relied upon especially
 * on personal computers.
 */
        if (o == filename)  /* '~' on its own */
        {   get_home_directory(filename, LONGEST_LEGAL_FILENAME);
            o = filename + strlen(filename);
        }
        else
        {   get_users_home_directory(filename, LONGEST_LEGAL_FILENAME);
            o = filename + strlen(filename);
        }
    }
/*
 * Having copies a user-name across (if there was one) I now copy the
 * rest of the file-name, expanding $xxx and ${xxx} as necessary.
 */
    while (n != 0)
    {   c = *old++;
        n--;
/*
 * If I find a "$" that is either at the end of the file-name or that is
 * immediately followed by ".", "/" or "\" then I will not use it for
 * parameter expansion. This at least gives me some help with the RISCOS
 * file-name $.abc.def where the "$" is used to indicate the root of the
 * current disc.
 */
        if (c == '$' && n != 0 &&
            (c = *old) != '.' && c != '/' && c != '\\')
        {   char *p = o;
            const char *w;
/*
 * I collect the name of the parameter at the end of my file-name buffer,
 * but will over-write it later on when I actually do the expansion.
 */
            if (c == '{')
            {   old++;
                n--;
                while (n != 0)
                {   c = *old++;
                    n--;
                    if (c == '}') break;
                    *p++ = (char)c;
                }
            }
            else
            {   while (n != 0)
                {   c = *old;
                    if (c == '.' || c == '/' || c == '\\') break;
                    old++;
                    n--;
                    *p++ = (char)c;
                }
            }
            *p = 0;
            i = strlen(o) + 2;
            while (i-- != 0) o[i] = o[i-1];
#ifdef CSL
            if ((p = look_in_lisp_variable(o, '$')) != NULL &&
                p != o) o = p;
            else 
#endif
            if ((w = my_getenv(o+1)) != NULL)    /* Shell variable? */
            {   strcpy(o, w);
                o = o + strlen(o);
            }
#ifdef CSL
            else if ((p = look_in_lisp_variable(o, '@')) != NULL)
                o = p;
#endif
            else
            {   *filename = 0;  /* return reporting failure */
                return;
            }
        }
        else *o++ = (char)c;
    }
    *o = 0;


#ifdef WIN32
/*
 * Now the filename has had $ and ~ prefix things expanded - I "just"
 * need to deal with sub-directory representation issues. Specifically I need
 * to map "/" separators into "\" so that if a user presents a file
 * name such as aaa/bbb/ccc.d it gets passed to the operating system
 * as aaa\bbb\ccc.d
 * Note that I enable this code under the heading MS_DOS but really it
 * means any file-system (eg Windows too) that uses "\" as its main
 * directory separator character.
 * As of September 2004 I will also map an intial sequence
 *         /cygdrive/x/
 * onto    x:\
 */

    if (strncmp(filename, "/cygdrive/", 10) == 0 &&
                filename[11] == '/')
    {   char *p = filename+2, *tail = filename+11;
        filename[0] = filename[10];
        filename[1] = ':';
        while (*tail != 0) *p++ = *tail++;
        *p = 0;
    }
/*
 * I map "/" characters in MSDOS filenames into "\" so that users
 * can give file names with Unix-like slashes as separators if they want.
 * People who WANT to use filenames with '/' in them will be hurt.
 */
    {   int j;
        char *tail = filename;
        while ((j = *tail) != 0)
        {   if (j == '/') *tail = '\\';
            tail++;
        }
/*
 * stat and friends do not like directories referred to as "\foo\", so check
 * for a trailing slash, being careful to respect directories with names
 * like "\" and "a:\".
 */
       j = strlen(filename);
       if (j > 0 && j != 1 && !(j == 3 && *(filename+1) == ':'))
       {
           if ( (*(tail - 1) == '\\')) *(tail - 1) = 0;
       }
    }
#endif /* WIN32 */
}
コード例 #26
0
void Client::sevt_data(ServerEvent& evt) {
    GTransport *t = reinterpret_cast<GTransport *>(evt.data);

    while (true) {
        t->from_net();
        switch (t->cmd) {
            case GPCServerMessage:
            {
                size_t sz = 0;
                std::string msg(reinterpret_cast<char *>(t->data), t->len);
                std::vector<std::string> lines;
                while (true) {
                    sz++;
                    size_t pos = msg.find("|");
                    if (pos == std::string::npos) {
                        lines.push_back(msg);
                        break;
                    }
                    lines.push_back(msg.substr(0, pos));
                    msg = msg.substr(pos + 1);
                }
                int vw = subsystem.get_view_width();
                int vh = subsystem.get_view_height();
                int ww = 200;
                int wh = 130;
                int x = 10;
                int y = 10;
                GuiWindow *window = push_window(x, y, ww, wh, "Server Message");

                Font *f = get_font();
                int text_height = 0;
                int ly = Spc;
                int maxw = 0;
                for (size_t i = 0; i < sz; i++) {
                    create_label(window, Spc, ly, lines[i]);
                    ly += f->get_font_height();
                    text_height += f->get_font_height();
                    int tw = f->get_text_width(lines[i]) + 2 * Spc;
                    maxw = (tw > maxw ? tw : maxw);
                }
                int maxh = text_height + 2 * Spc;
                int bw = 46;
                int bh = 18;
                create_button(window, maxw / 2 - bw / 2, maxh, bw, bh, "Okay", static_window_close_click, this);
                maxh += bh + Spc;
                window->set_width(window->get_width() - window->get_client_width() + maxw);
                window->set_height(window->get_height() - window->get_client_height() + maxh);
                window->set_x(vw / 2 - window->get_width() / 2);
                window->set_y(vh / 2 - window->get_height() / 2);
                break;
            }

            case GPCMapState:
            {
                GTournament *tour = reinterpret_cast<GTournament *>(t->data);
                tour->from_net();
                if (tournament) {
                    delete tournament;
                }

                /* reload resources? */
                if (reload_resources) {
                    resources.reload_resources();
                    load_resources();
                    reload_resources = false;
                }

                /* setup tournament */
                bool warmup = ((tour->flags & TournamentFlagWarmup) != 0);
                GamePlayType type = static_cast<GamePlayType>(tour->gametype);
                MapConfiguration config(type, tour->map_name, tour->duration, tour->warmup);
                tournament = factory.create_tournament(config, false, warmup, players, 0);
                factory.set_tournament_id(tour->tournament_id);
                tournament->set_following_id(my_id);
                tournament->set_player_configuration(&player_config);
                tournament->set_team_names(team_red_name, team_blue_name);

                /* reopen, if join request window is already open */
                if (me && me->joining) {
                    tournament->reopen_join_window(me);
                }

                break;
            }

            case GPCIdentifyPlayer:
            {
                player_id_t *nid = reinterpret_cast<player_id_t *>(t->data);
                my_id = ntohs(*nid);
                if (tournament) {
                    tournament->set_following_id(my_id);
                }
                break;
            }

            case GPCReady:
            {
                if (tournament) {
                    tournament->set_ready();
                }
                if (me) {
                    me->state.client_server_state.key_states = 0;
                }
                break;
            }

            case GPCAddPlayer:
            {
                GPlayerInfo *info = reinterpret_cast<GPlayerInfo *>(t->data);
                info->from_net();

                Player *p = new Player(resources, 0, info->id,
                    info->desc.player_name, info->desc.characterset_name);
                players.push_back(p);

                p->state.server_state = info->server_state;
                p->state.client_server_state = info->client_server_state;
                p->state.client_state = info->client_state;

                if (p->state.id == my_id) {
                    me = p;
                    p->mark_as_me();
                }

                if (tournament) {
                    tournament->player_added(p);
                }

                break;
            }

            case GPCResetPlayer:
            {
                GPlayerInfo *info = reinterpret_cast<GPlayerInfo *>(t->data);
                info->from_net();

                for (Players::iterator it = players.begin();
                    it != players.end(); it++)
                {
                    Player *p = *it;
                    if (p->state.id == info->id) {
                        p->state.server_state = info->server_state;
                        p->state.client_server_state = info->client_server_state;
                        p->state.client_state = info->client_state;
                        if (tournament) {
                            tournament->reset_player(p);
                        }
                        break;
                    }
                }
                break;
            }

            case GPCRemovePlayer:
            {
                player_id_t *nid = reinterpret_cast<player_id_t *>(t->data);
                player_id_t id = ntohs(*nid);
                for (Players::iterator it = players.begin();
                    it != players.end(); it++)
                {
                    Player *p = *it;
                    if (p->state.id == id) {
                        if (id == my_id) {
                            me = 0;
                        }

                        if (tournament) {
                            tournament->player_removed(p);
                        }

                        players.erase(it);
                        delete p;
                        break;
                    }
                }
                break;
            }

            case GPCSpawnPlayer:
            {
                GPlayerState *state = reinterpret_cast<GPlayerState *>(t->data);
                state->from_net();
                for (Players::iterator it = players.begin();
                    it != players.end(); it++)
                {
                    Player *p = *it;
                    if (p->state.id == state->id) {
                        if (p == me) {
                            p->state.server_state = state->server_state;
                        } else {
                            p->state = *state;
                        }
                        p->respawning = false;
                        if (tournament) {
                            tournament->add_player_spawn_animation(p);
                        }
                        break;
                    }
                }
                break;
            }

            case GPCUpdateGameState:
            {
                if (t->tournament_id == factory.get_tournament_id()) {
                    GGameState *state = reinterpret_cast<GGameState *>(t->data);
                    state->from_net();
                    if (tournament) {
                        tournament->get_game_state() = *state;
                    }
                }
                break;
            }

            case GPCUpdatePlayerState:
            {
                if (t->tournament_id== factory.get_tournament_id()) {
                    GPTAllStates *state = reinterpret_cast<GPTAllStates *>(t->data);
                    state->from_net();

                    for (Players::iterator it = players.begin();
                        it != players.end(); it++)
                    {
                        Player *p = *it;
                        if (p->state.id == state->id) {
                            p->state.server_state = state->server_state;
                            if (p != me) {
                                p->state.client_server_state = state->client_server_state;
                            }
                            break;
                        }
                    }
                }
                break;
            }

            case GPCUpdateObject:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        GObjectState *state = reinterpret_cast<GObjectState *>(t->data);
                        state->from_net();
                        Tournament::GameObjects& objects = tournament->get_game_objects();
                        for (Tournament::GameObjects::iterator it = objects.begin();
                            it != objects.end(); it++)
                        {
                            GameObject *obj = *it;
                            if (obj->state.id == state->id) {
                                obj->state = *state;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            case GPCUpdateAnimation:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        GAnimationState *state = reinterpret_cast<GAnimationState *>(t->data);
                        state->from_net();
                        Tournament::GameAnimations& animations = tournament->get_game_animations();
                        for (Tournament::GameAnimations::iterator it = animations.begin();
                            it != animations.end(); it++)
                        {
                            GameAnimation *ani = *it;
                            if (ani->state.id == state->id) {
                                ani->state = *state;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            case GPCUpdateSpawnableNPC:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        GNPCState *state = reinterpret_cast<GNPCState *>(t->data);
                        state->from_net();
                        Tournament::SpawnableNPCs& spawnable_npcs = tournament->get_spawnable_npcs();
                        for (Tournament::SpawnableNPCs::iterator it = spawnable_npcs.begin();
                            it != spawnable_npcs.end(); it++)
                        {
                            SpawnableNPC *npc = *it;
                            if (npc->state.id == state->id) {
                                npc->state = *state;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            case GPCSpawnNPC:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        GSpawnNPC *state = reinterpret_cast<GSpawnNPC *>(t->data);
                        state->from_net();
                        tournament->add_spawnable_npc(state);
                    }
                }
                break;
            }

            case GPCRemoveNPC:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        GRemoveNPC *rnpc = reinterpret_cast<GRemoveNPC *>(t->data);
                        rnpc->from_net();
                        tournament->remove_spawnable_npc(rnpc);
                    }
                }
                break;
            }

            case GPCTextMessage:
            {
                std::string msg(reinterpret_cast<char *>(t->data), t->len);
                ClientTextMessage *cmsg = new ClientTextMessage;
                cmsg->text = msg;
                client_text_messages.push_back(cmsg);
                break;
            }

            case GPCPlaySound:
            {
                GGenericName *name = reinterpret_cast<GGenericName *>(t->data);
                try {
                    subsystem.play_sound(resources.get_sound(name->name), 0);
                } catch (...) {
                    /* chomp */
                }
                break;
            }

            case GPCChatMessage:
            {
                std::string msg(reinterpret_cast<char *>(t->data), t->len);
                ClientTextMessage *cmsg = new ClientTextMessage;
                cmsg->text = msg;
                client_text_messages.push_back(cmsg);
                subsystem.play_sound(resources.get_sound("chat"), 0);
                break;
            }

            case GPCAddAnimation:
            {
                GAnimation *ani = reinterpret_cast<GAnimation *>(t->data);
                ani->from_net();
                if (tournament) {
                    tournament->add_animation(ani);
                }
                break;
            }

            case GPCAddTextAnimation:
            {
                GTextAnimation *ani = reinterpret_cast<GTextAnimation *>(t->data);
                ani->from_net();
                if (tournament) {
                    tournament->add_text_animation(ani);
                }
                break;
            }

            case GPCPlayerRecoil:
            {
                GPlayerRecoil *prec = reinterpret_cast<GPlayerRecoil *>(t->data);
                prec->from_net();
                for (Players::iterator it = players.begin(); it != players.end(); it++) {
                    Player *p = *it;
                    if (p->state.id == prec->id) {
                        p->state.client_server_state.accel_x += prec->x_recoil;
                        break;
                    }
                }
                break;
            }

            case GPCPlayerHurt:
            {
                if (tournament) {
                    if (t->tournament_id == factory.get_tournament_id()) {
                        subsystem.play_sound(resources.get_sound("hurt"), 0);
                    }
                }
                break;
            }

            case GPCPickObject:
            {
                GPickObject *po = reinterpret_cast<GPickObject *>(t->data);
                po->from_net();
                if (tournament) {
                    tournament->add_pick_object(po);
                }
                break;
            }

            case GPCPlaceObject:
            {
                GPlaceObject *po = reinterpret_cast<GPlaceObject *>(t->data);
                po->from_net();
                if (tournament) {
                    tournament->add_place_object(po);
                }
                break;
            }

            case GPCSpawnObject:
            {
                GSpawnObject *so = reinterpret_cast<GSpawnObject *>(t->data);
                so->from_net();
                if (tournament) {
                    tournament->spawn_object(so);
                }
                break;
            }

            case GPCJoinAccepted:
            {
                if (tournament) {
                    tournament->join_accepted();
                }
                break;
            }

            case GPCJoinRefused:
            {
                if (tournament) {
                    tournament->join_refused();
                    ClientTextMessage *cmsg = new ClientTextMessage;
                    cmsg->text = "YOUR JOIN REQUEST WAS REFUSED";
                    client_text_messages.push_back(cmsg);
                    subsystem.play_sound(resources.get_sound("error"), 0);
                }
                break;
            }

            case GPCTeamScore:
            {
                GTeamScore *ts = reinterpret_cast<GTeamScore *>(t->data);
                ts->from_net();
                if (tournament) {
                    tournament->add_team_score(ts);
                }
                break;
            }

            case GPCTimeRemaining:
            {
                GTimeRemaining *remain = reinterpret_cast<GTimeRemaining *>(t->data);
                remain->from_net();
                if (tournament) {
                    tournament->update_wearable_remaining(remain);
                }
                break;
            }

            case GPCFriendlyFire:
            {
                GFriendyFireAlarm *alarm = reinterpret_cast<GFriendyFireAlarm *>(t->data);
                alarm->from_net();
                if (tournament) {
                    if (tournament->friendly_fire_alarm(alarm)) {
                        subsystem.play_controlled_sound(resources.get_sound("friendly_fire"), 0);
                        ClientTextMessage *cmsg = new ClientTextMessage;
                        cmsg->text = "FRIENDLY FIRE: WATCH OUT!!!";
                        client_text_messages.push_back(cmsg);
                    }
                }
                break;
            }

            case GPCGamePlayUnbalanced:
            {
                if (tournament) {
                    subsystem.play_controlled_sound(resources.get_sound("unbalanced"), 0);
                    ClientTextMessage *cmsg = new ClientTextMessage;
                    cmsg->text = "GAMEPLAY IS UNBALANCED";
                    client_text_messages.push_back(cmsg);
                }
                break;
            }

            case GPCWarmUp:
            {
                if (tournament) {
                    subsystem.play_system_sound(resources.get_sound("warm_up"));
                    ClientTextMessage *cmsg = new ClientTextMessage;
                    cmsg->text = "please warm up";
                    client_text_messages.push_back(cmsg);
                }
                break;
            }

            case GPCGameBegins:
            {
                if (tournament) {
                    subsystem.play_system_sound(resources.get_sound("ready"));
                    ClientTextMessage *cmsg = new ClientTextMessage;
                    cmsg->text = "game begins";
                    client_text_messages.push_back(cmsg);
                }
                break;
            }

            case GPCGameOver:
            {
                if (tournament) {
                    subsystem.play_system_sound(resources.get_sound("game_over"));
                    ClientTextMessage *cmsg = new ClientTextMessage;
                    cmsg->text = "GAME IS OVER";
                    client_text_messages.push_back(cmsg);
                }
                break;
            }

            case GPCPlayerChanged:
            {
                GPlayerDescription *pdesc = reinterpret_cast<GPlayerDescription *>(t->data);
                pdesc->from_net();
                for (Players::iterator it = players.begin(); it != players.end(); it++) {
                    Player *p = *it;
                    if (p->state.id == pdesc->id) {
                        std::string old_name = p->get_player_name();
                        std::string new_name(pdesc->player_name);
                        std::string old_skin(p->get_characterset()->get_name());
                        std::string new_skin(pdesc->characterset_name);

                        /* change player name */
                        if (old_name != new_name) {
                            p->set_player_name(new_name);
                            p->font = 0;
                            ClientTextMessage *cmsg = new ClientTextMessage;
                            cmsg->text = old_name + " is now known as " + new_name;
                            client_text_messages.push_back(cmsg);
                        }

                        /* change skin */
                        if (old_skin != new_skin) {
                            try {
                                p->set_characterset(new_skin);
                                ClientTextMessage *cmsg = new ClientTextMessage;
                                cmsg->text = p->get_player_name() + " changed the skin to " + new_skin;
                                client_text_messages.push_back(cmsg);
                            } catch (const Exception& e) {
                                subsystem << e.what() << std::endl;
                            }
                        }
                        break;
                    }
                }
                break;
            }

            case GPCScoreTransportRaw:
            {
                if (tournament) {
                    tournament->score_transport_raw(t->data);
                }
                break;
            }

            case GPCClanNames:
            {
                GClanNames *names = reinterpret_cast<GClanNames *>(t->data);
                names->from_net();
                team_red_name = names->red_name;
                team_blue_name = names->blue_name;
                if (tournament) {
                    tournament->set_team_names(team_red_name, team_blue_name);
                }
                break;
            }

            case GPCXferHeader:
            {
                reload_resources = true;
                GXferHeader *header = reinterpret_cast<GXferHeader *>(t->data);
                header->from_net();
                if (!fhnd) {
                    xfer_filename = header->filename;
                    current_download_filename = get_home_directory() + dir_separator + UserDirectory + dir_separator + header->filename;
                    fhnd = fopen(current_download_filename.c_str(), "wb");
                    if (fhnd) {
                        total_xfer_sz = remaining_xfer_sz = header->filesize;
                    } else {
                        subsystem << "WARNING: cannot open file " << strerror(errno) << std::endl;
                    }
                } else {
                    subsystem << "WARNING: cannot receive " << xfer_filename << ". a file is already opened." << std::endl;
                }
                break;
            }

            case GPCXferDataChunk:
            {
                GXferDataChunk *chunk = reinterpret_cast<GXferDataChunk *>(t->data);
                chunk->from_net();
                if (fhnd) {
                    fwrite(chunk->data, chunk->chunksize, 1, fhnd);
                    remaining_xfer_sz -= chunk->chunksize;
                    if (remaining_xfer_sz < 1) {
                        fclose(fhnd);
                        fhnd = 0;
                        current_download_filename = "";
                    }
                }
                {
                    ScopeMutex lock(mtx);
                    send_data(evt.c, 0, GPSPakSyncAck, NetFlagsReliable, 0, 0);
                }
                break;
            }

            case GPCGenericData:
            {
                if (tournament) {
                    tournament->generic_data_delivery(t->data);
                }
                break;
            }

            case GPCServerQuit:
            {
                exception_msg.assign(reinterpret_cast<char *>(t->data), t->len);
                throw_exception = true;
                return;
                /* not necessary */
                break;
            }
        }

        /* advance to next element */
        if (t->flags & TransportFlagMorePackets) {
            unsigned char *tpb = reinterpret_cast<unsigned char *>(t);
            tpb += GTransportLen;
            tpb += t->len;
            t = reinterpret_cast<GTransport *>(tpb);
        } else {
            break;
        }
    }
}
コード例 #27
0
ファイル: main.c プロジェクト: analani/tg
char *get_config_directory (void) {
  char *config_directory;
  tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ());
  return config_directory;
}
コード例 #28
0
ファイル: dmzApplication.cpp プロジェクト: ashok/dmz
/*!

\brief Save session data.
\details Session data is saved to the session file.
\return Returns dmz::True if the session data is successfully saved.
\sa dmz::Application::load_session()

*/
dmz::Boolean
dmz::Application::save_session () {

   Boolean result (False);

   Config session;

   _state.rt.get_session_config (session);

   Config prevDirConfig;

   const String DefaultDir (_state.appState.get_default_directory ());

   if (DefaultDir) {

      if (session.lookup_config (ApplicationName, prevDirConfig)) {

         prevDirConfig.store_attribute (DirName, DefaultDir);
      }
      else if (DefaultDir != get_home_directory ()) {

         Config dirConfig (ApplicationName);
         dirConfig.store_attribute (DirName, DefaultDir);
         session.add_config (dirConfig);
      }
   }

   if (!session.is_empty () && _state.sessionDir && _state.sessionPath) {

      if (create_directory (_state.sessionDir)) {

         FILE *file = open_file (_state.sessionPath, "wb");

         if (file) {

            StreamFile fs (file);

            write_xml_header (fs);

            format_config_to_xml (session, fs);

            close_file (file); file = 0;

            result = True;

            if (!_state.quiet) {

               _state.log.info << "Saved session to file: " << _state.sessionPath << endl;
            }
         }
         else {

            _state.log.error << "Unable to create session file: "
               << _state.sessionPath << endl;
         }
      }
      else {

         _state.log.error << "Unable to create session directory: " << _state.sessionDir
            << endl;
      }
   }
   else if (session.is_empty ()) {

      if (!_state.quiet) { _state.log.info << "No session data to save." << endl; }
   }
   else if (!_state.sessionDir) {

      _state.log.error << "Session directory not found." << endl;
   }
   else if (!_state.sessionPath) {

      _state.log.error << "Session file not found." << endl;
   }

   return result;
}
コード例 #29
0
ファイル: dmzApplication.cpp プロジェクト: ashok/dmz
/*!

\brief Loads session data.
\details Attempts to load session data using the \a Name and \a Domain from the
constructor. The session file for the various platforms is as follows:
- Win32 \$(HOME)/\$(Domain)/\$(Name).xml
- MacOS ~/Library/Preferences/\$(Domain)/\$(Name).xml
- Linux ~/.\$(Domain)/\$(Name).xml

\return Returns dmz::True if the session data was read successfully.

*/
dmz::Boolean
dmz::Application::load_session () {

   Boolean result (True);

   _state.sessionDir = get_home_directory ();

   if (is_valid_path (_state.sessionDir)) {

#if defined (_WIN32)
      if (_state.Domain) { _state.sessionDir << "/" << _state.Domain; }
      else { _state.sessionDir << "/dmz"; }
#elif defined (__APPLE__) || defined (MACOSX)
      _state.sessionDir << "/Library/Preferences";
      if (_state.Domain) { _state.sessionDir << "/" << _state.Domain; }
      else { _state.sessionDir << "/dmz"; }
#else
      if (_state.Domain) { _state.sessionDir << "/." << _state.Domain; }
      else { _state.sessionDir << "/.dmz"; }
#endif
   }
   else { result = False; }

   if (_state.sessionDir) {

      if (_state.Name) { _state.sessionFile << _state.Name << ".xml"; }
      else { _state.sessionFile << "session.xml"; }

      _state.sessionPath = format_path (_state.sessionDir + "/" + _state.sessionFile);

      if (is_valid_path (_state.sessionPath)) {

         Config data ("global");

         if (xml_to_config (_state.sessionPath, data, &(_state.log))) {

            if (!_state.quiet) {

               _state.log.info << "Loaded session file: " << _state.sessionPath << endl;
            }

            Config session;
            _state.rt.get_session_config (session);

            if (data.lookup_all_config_merged (session.get_name (), session)) {

               const String DefaultDir (config_to_string (DefaultDirName, session));

               if (DefaultDir && is_valid_path (DefaultDir)) {

                  _state.appState.set_default_directory (DefaultDir);
               }
               else { _state.appState.set_default_directory (get_home_directory ()); }

               _state.rt.set_session_config (session);
            }
         }
         else {

            _state.log.error << "Failed parsing session file: " << _state.sessionPath
               << endl;
         }
      }
      else if (!_state.quiet) {

         _state.log.info << "Session file: " << _state.sessionPath << " does not exist"
            << endl;
         result = False;
      }
   }

   return result;
}
コード例 #30
0
void EditableMap::save() throw (Exception) {
    char buffer[256];

    /* drop header informations */
    int height = atoi(get_value("height").c_str());
    for (int i = 0; i < height; i++) {
        sprintf(buffer, "tiles%d", i);
        set_value(buffer, "");
        sprintf(buffer, "decoration%d", i);
        set_value(buffer, "");
    }

    /* drop objects */
    int cnt_objects = atoi(get_value("objects").c_str());
    for (int i = 0; i < cnt_objects; i++) {
        sprintf(buffer, "object_name%d", i);
        set_value(buffer, "");
        sprintf(buffer, "object_x%d", i);
        set_value(buffer, "");
        sprintf(buffer, "object_y%d", i);
        set_value(buffer, "");
    }

    /* drop light sources */
    int cnt_lights = atoi(get_value("lights").c_str());
    for (int i = 0; i < cnt_lights; i++) {
        sprintf(buffer, "light_x%d", i);
        set_value(buffer, "");
        sprintf(buffer, "light_y%d", i);
        set_value(buffer, "");
        sprintf(buffer, "light_radius%d", i);
        set_value(buffer, "");
    }

    int width = get_width();
    height = get_height();
    set_value("width", width);
    set_value("height", height);
    save_array("tiles", get_map(), width, height);
    save_array("decoration", get_decoration(), width, height);

    set_value("game_play_type", static_cast<int>(game_play_type));
    set_value("frog_spawn_init", frog_spawn_init);

    cnt_objects = static_cast<int>(objects.size());
    set_value("objects", cnt_objects);
    for (int i = 0; i < cnt_objects; i++) {
        EditableObject *eobj = objects[i];
        sprintf(buffer, "object_name%d", i);
        set_value(buffer, eobj->object->get_name());
        sprintf(buffer, "object_x%d", i);
        set_value(buffer, eobj->x);
        sprintf(buffer, "object_y%d", i);
        set_value(buffer, eobj->y);
    }

    cnt_lights = static_cast<int>(lights.size());
    set_value("lights", cnt_lights);
    for (int i = 0; i < cnt_lights; i++) {
        EditableLight *elgt = lights[i];
        sprintf(buffer, "light_x%d", i);
        set_value(buffer, elgt->x);
        sprintf(buffer, "light_y%d", i);
        set_value(buffer, elgt->y);
        sprintf(buffer, "light_radius%d", i);
        set_value(buffer, elgt->radius);
    }

    std::string save_dir = get_home_directory() + dir_separator + UserDirectory;
    create_directory("maps", save_dir);
    KeyValue::save(save_dir + dir_separator + "maps" + dir_separator + get_name() + ".map");
}