Beispiel #1
0
/** Locate the prefix in which the current application is installed.
 *
 * The prefix is generated by the following pseudo-code evaluation:
 * \code
 * dirname(dirname(exename))
 * \endcode
 *
 * @param default_prefix  A default prefix which will used as fallback.
 * @return A string containing the prefix, which must be freed when no
 *         longer necessary. If BinReloc is not initialized, or if the
 *         initialization function failed, then a copy of default_prefix
 *         will be returned. If default_prefix is NULL, then NULL will be
 *         returned.
 */
gchar *
gnc_gbr_find_prefix (const gchar *default_prefix)
{
#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION
    gchar *id = gtkosx_application_get_bundle_id ();
    gchar *path = gtkosx_application_get_resource_path ();
    if (id == NULL)
    {
        gchar *dirname = g_path_get_dirname (path);
        g_free (path);
        g_free (id);
        return dirname;
    }
    g_free (id);
    return path;
#else
    gchar *dir1, *dir2;

    if (exe == NULL)
    {
        /* BinReloc not initialized. */
        if (default_prefix != NULL)
            return g_strdup (default_prefix);
        else
            return NULL;
    }
    dir1 = g_path_get_dirname (exe);
    dir2 = g_path_get_dirname (dir1);
    g_free (dir1);
    return dir2;
#endif //ENABLE_BINRELOC && defined MAC_INTEGRATION
}
static gchar *
get_locale_dir (void)
{
	gchar *locale_dir;

#ifdef G_OS_WIN32
	gchar *win32_dir;

	win32_dir = g_win32_get_package_installation_directory_of_module (NULL);

	locale_dir = g_build_filename (win32_dir, "share", "locale", NULL);

	g_free (win32_dir);
#elif defined (OS_OSX)
	if (gtkosx_application_get_bundle_id () != NULL)
	{
		locale_dir = g_build_filename (gtkosx_application_get_resource_path (), "share", "locale", NULL);
	}
	else
	{
		locale_dir = g_build_filename (DATADIR, "locale", NULL);
	}
#else
	locale_dir = g_build_filename (DATADIR, "locale", NULL);
#endif

	return locale_dir;
}
Beispiel #3
0
void read_rc_file(char *override_rc)
{
FILE *handle;
int i;
int num_rcitems = sizeof(rcitems)/sizeof(struct rc_entry);

for(i=0;i<(num_rcitems-1);i++)
	{
	if(strcmp(rcitems[i].name, rcitems[i+1].name) > 0)
		{
		fprintf(stderr, "rcitems misordering: '%s' vs '%s'\n", rcitems[i].name, rcitems[i+1].name);
		exit(255);
		}
	}

/* move defaults first and only go whitescreen if instructed to do so */
if(GLOBALS->possibly_use_rc_defaults) vanilla_rc();

if((override_rc)&&((handle=fopen(override_rc,"rb"))))
	{
	/* good, we have a handle */
	wave_gconf_client_set_string("/current/rcfile", override_rc);
	}
else
#if !defined __MINGW32__ && !defined _MSC_VER
if(!(handle=fopen(rcname,"rb")))
	{
	char *home;
	char *rcpath;

	home=getpwuid(geteuid())->pw_dir;
	rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1);
	strcpy(rcpath,home);
	strcat(rcpath,"/");
	strcat(rcpath,rcname);

	if(!(handle=fopen(rcpath,"rb")))
		{
#ifdef MAC_INTEGRATION
		const gchar *bundle_id = gtkosx_application_get_bundle_id();
		if(bundle_id)
			{
			const gchar *rpath = gtkosx_application_get_resource_path();
			const char *suf = "/gtkwaverc";

			rcpath = NULL;
			if(rpath)
				{
				rcpath = (char *)alloca(strlen(rpath) + strlen(suf) + 1);
				strcpy(rcpath, rpath);
				strcat(rcpath, suf);
				}

			if(!rcpath || !(handle=fopen(rcpath,"rb")))
				{
				wave_gconf_client_set_string("/current/rcfile", "");
				errno=0;
				return; /* no .rc file */
				}
				else
				{
				wave_gconf_client_set_string("/current/rcfile", rcpath);
				}
			}
			else
#endif
			{
			wave_gconf_client_set_string("/current/rcfile", "");
			errno=0;
			return; /* no .rc file */
			}
		}
		else
		{
		wave_gconf_client_set_string("/current/rcfile", rcpath);
		}
	}
#else
if(!(handle=fopen(rcname,"rb")))		/* no concept of ~ in win32 */
	{
        /* Try to find rcname in USERPROFILE */
        char *home;
        char *rcpath;

        home=getenv("USERPROFILE");
        if (home != NULL) {
            /* printf("USERPROFILE = %s\n", home); */
            rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1);
            strcpy(rcpath,home);
            strcat(rcpath,"\\");
            strcat(rcpath,rcname);
            /* printf("rcpath = %s\n", rcpath); */
        }
        if ((home == NULL) || (!(handle=fopen(rcpath,"rb")))) {
            /* printf("No rc file\n"); */
	    wave_gconf_client_set_string("/current/rcfile", "");
  	    errno=0;
	    if(GLOBALS->possibly_use_rc_defaults) vanilla_rc();
	    return; /* no .rc file */
	    }

	wave_gconf_client_set_string("/current/rcfile", rcpath);
	}
#endif

GLOBALS->rc_line_no=0;
while(!feof(handle))
	{
	char *str;

	GLOBALS->rc_line_no++;
	if((str=fgetmalloc(handle)))
		{
		int len;
		len=strlen(str);
		if(len)
			{
			for(i=0;i<len;i++)
				{
				int pos;
				if((str[i]==' ')||(str[i]=='\t')) continue;	/* skip leading ws */
				if(str[i]=='#') break; 				/* is a comment */
				for(pos=i;i<len;i++)
					{
					if((str[i]==' ')||(str[i]=='\t'))
						{
						str[i]=0; /* null term envname */

						for(i=i+1;i<len;i++)
							{
							struct rc_entry *r;

							if((str[i]==' ')||(str[i]=='\t')) continue;
							if((r=bsearch((void *)(str+pos), (void *)rcitems,
								sizeof(rcitems)/sizeof(struct rc_entry),
								sizeof(struct rc_entry), rc_compare)))
								{
								int j;

								for(j=len-1;j>=i;j--)
									{
									if((str[j]==' ')||(str[j]=='\t')) /* nuke trailing spaces */
										{
										str[j]=0;
										continue;
										}
										else
										{
										break;
										}
									}
								r->func(str+i); /* call resolution function */
								}
							break;
							}
						break;	/* added so multiple word values work properly*/
						}
					}
				break;
				}

			}
		free_2(str);
		}
	}

fclose(handle);
errno=0;
return;
}
Beispiel #4
0
void
gedit_dirs_init ()
{
#ifdef G_OS_WIN32
	gchar *win32_dir;

	win32_dir = g_win32_get_package_installation_directory_of_module (NULL);

	gedit_locale_dir = g_build_filename (win32_dir,
					     "share",
					     "locale",
					     NULL);
	gedit_lib_dir = g_build_filename (win32_dir,
					  "lib",
					  "gedit",
					  NULL);
	gedit_plugins_data_dir = g_build_filename (win32_dir,
						   "share",
						   "gedit",
						   "plugins",
						   NULL);

	g_free (win32_dir);
#endif /* G_OS_WIN32 */

#ifdef OS_OSX
	if (gtkosx_application_get_bundle_id () != NULL)
	{
		const gchar *bundle_resource_dir = gtkosx_application_get_resource_path ();

		gedit_locale_dir = g_build_filename (bundle_resource_dir,
						     "share",
						     "locale",
						     NULL);
		gedit_lib_dir = g_build_filename (bundle_resource_dir,
						  "lib",
						  "gedit",
						  NULL);
		gedit_plugins_data_dir = g_build_filename (bundle_resource_dir,
							   "share",
							   "gedit",
							   "plugins",
							   NULL);
	}
#endif /* OS_OSX */

	if (gedit_locale_dir == NULL)
	{
		gedit_locale_dir = g_build_filename (DATADIR,
						     "locale",
						     NULL);
		gedit_lib_dir = g_build_filename (LIBDIR,
						  "gedit",
						  NULL);
		gedit_plugins_data_dir = g_build_filename (DATADIR,
							   "gedit",
							   "plugins",
							   NULL);
	}

	user_cache_dir = g_build_filename (g_get_user_cache_dir (),
					   "gedit",
					   NULL);
	user_config_dir = g_build_filename (g_get_user_config_dir (),
					    "gedit",
					    NULL);
	user_styles_dir = g_build_filename (g_get_user_data_dir (),
					    "gedit",
					    "styles",
					    NULL);
	user_plugins_dir = g_build_filename (g_get_user_data_dir (),
					     "gedit",
					     "plugins",
					     NULL);
	gedit_plugins_dir = g_build_filename (gedit_lib_dir,
					      "plugins",
					      NULL);
}