/** Get the name of a subdirectory of our data directory. * This function does not create the subdirectory, just make the correct name. * @param subdir The name of the directory desired. * @returns The full path to the directory. This string should be freed * after use. */ gchar * dia_get_data_directory(const gchar* subdir) { #ifdef G_OS_WIN32 gchar *tmpPath = NULL; gchar *returnPath = NULL; /* * Calculate from executable path */ gchar *sLoc = _dia_get_module_directory (); # if defined(PREFIX) && defined(DATADIR) tmpPath = replace_prefix(sLoc, DATADIR); if (strlen (subdir) == 0) returnPath = g_strdup(tmpPath); else returnPath = g_build_path(G_DIR_SEPARATOR_S, tmpPath, subdir, NULL); g_free(tmpPath); # else returnPath = g_strconcat (sLoc , subdir, NULL); # endif g_free (sLoc); return returnPath; #else if (strlen (subdir) == 0) return g_strconcat (DATADIR, NULL); else return g_strconcat (DATADIR, G_DIR_SEPARATOR_S, subdir, NULL); #endif }
/* If first OLD_PREFIX_LEN bytes of DIR->NAME name match OLD_PREFIX, replace them with NEW_PREFIX. */ void rebase_directory (struct directory *dir, const char *old_prefix, size_t old_prefix_len, const char *new_prefix, size_t new_prefix_len) { replace_prefix (&dir->name, old_prefix, old_prefix_len, new_prefix, new_prefix_len); }
/* * === FUNCTION ====================================================================== * Name: uri_remove_dot_segments * Description: Implements RFC 3986 section 5.2.4 * use for interpreting and removing the special "." and ".." complete * path segments from a referenced path. This is done after the path is * extracted from a reference, whether or not the path was relative, in * order to remove any invalid or extraneous dot-segments prior to * forming the target URI. Although there are many ways to accomplish * this removal process, we describe a simple method using two string * buffers. * * ===================================================================================== */ extern char * uri_remove_dot_segments( char **path ) { char *ou_buffer = NULL, *in_buffer = NULL, *segment = NULL, sl = '\0'; int len = 0; if( *(path) == NULL ) { return NULL; } in_buffer = strdup( *(path)); len = strlen( in_buffer ) + 1; ou_buffer = (char *) malloc( len ); ou_buffer[0] = '\0'; while( in_buffer != NULL ){ segment = get_next_segment( &in_buffer); if( strcmp( segment, "../") == 0 || strcmp(segment,"./") == 0){ shift_segment( &in_buffer, 0); } else if( strcmp(segment, "/./") == 0 || strcmp(segment,"/.") == 0){ replace_prefix( &in_buffer); } else if( strcmp( segment,"/../") == 0 || strcmp(segment,"/..") == 0){ replace_prefix(&in_buffer); pop_segment(&ou_buffer); } else if( strcmp( in_buffer, ".") == 0 || strcmp( in_buffer, "..") == 0){ in_buffer = NULL; } else if( segment) { sl = segment[ strlen(segment) - 1]; if( sl == '/'){ segment = shift_segment(&in_buffer, 0); } else { segment = shift_segment(&in_buffer, 1); } strcat(ou_buffer, segment); } } len = strlen(ou_buffer) + 1; realloc( (void *) ou_buffer, len); return ou_buffer; }
void dirlist_replace_prefix (const char *pref, const char *repl) { struct directory *dp; size_t pref_len = strlen (pref); size_t repl_len = strlen (repl); for (dp = dirhead; dp; dp = dp->next) replace_prefix (&dp->name, pref, pref_len, repl, repl_len); }
void sparql_parser::do_parse(vector<string>& token_vec){ if(!valid) return ; remove_header(token_vec); if(!valid) return ; replace_prefix(token_vec); if(!valid) return ; if(token_vec.size()%4!=0){ cout<<"[error token number] "<<endl; valid=false; return ; } int iter=0; while(iter<token_vec.size()){ string strs[3]={token_vec[iter+0],token_vec[iter+1],token_vec[iter+2]}; int ids[3]; if(token_vec[iter+3]=="<-"){ swap(strs[0],strs[2]); } for(int i=0;i<3;i++){ ids[i]=str2id(strs[i]); } if(token_vec[iter+3]=="." || token_vec[iter+3]=="->"){ req_template.cmd_chains.push_back(ids[0]); req_template.cmd_chains.push_back(ids[1]); req_template.cmd_chains.push_back(direction_out); req_template.cmd_chains.push_back(ids[2]); iter+=4; } else if(token_vec[iter+3]=="<-"){ req_template.cmd_chains.push_back(ids[0]); req_template.cmd_chains.push_back(ids[1]); req_template.cmd_chains.push_back(direction_in); req_template.cmd_chains.push_back(ids[2]); iter+=4; } else { cout<<"[error seperator] "<<endl; valid=false; return ; } } for(int i=0;i<req_template.cmd_chains.size();i++){ if(req_template.cmd_chains[i]==place_holder){ req_template.place_holder_position.push_back(i); return ; } } }
gchar* dia_get_locale_directory(void) { #ifdef G_OS_WIN32 # if defined(PREFIX) && defined(LOCALEDIR) gchar *ret; gchar *sLoc = _dia_get_module_directory (); ret = replace_prefix(sLoc, LOCALEDIR); g_free (sLoc); return ret; # else return dia_get_lib_directory ("locale"); # endif #else return g_strconcat (LOCALEDIR, G_DIR_SEPARATOR_S, "", NULL); #endif }
/** Get a subdirectory of our lib directory. This does not create the * directory, merely the name of the full path. * @param subdir The name of the subdirectory wanted. * @return The full path of the named directory. The string should be * freed after use. */ gchar* dia_get_lib_directory(const gchar* subdir) { #ifdef G_OS_WIN32 gchar *sLoc = _dia_get_module_directory (); gchar *returnPath = NULL; # if defined(PREFIX) && defined(LIBDIR) { gchar *tmpPath = replace_prefix(sLoc, LIBDIR); returnPath = g_build_path(G_DIR_SEPARATOR_S, tmpPath, subdir, NULL); g_free(tmpPath); } # else returnPath = g_strconcat (sLoc , subdir, NULL); # endif g_free (sLoc); return returnPath; #else return g_strconcat (LIBDIR, G_DIR_SEPARATOR_S, subdir, NULL); #endif }
static void setup (void) { gchar *full_prefix; gchar *cp_prefix; G_LOCK (mutex); if (localedir != NULL) { G_UNLOCK (mutex); return; } /* This requires that the libeutil DLL is installed in $bindir */ full_prefix = g_win32_get_package_installation_directory_of_module(hmodule); cp_prefix = g_win32_locale_filename_from_utf8(full_prefix); localedir = replace_prefix (cp_prefix, EVOLUTION_LOCALEDIR); g_free (cp_prefix); prefix = g_strdup (full_prefix); /* It makes sense to have some of the paths overridable with * environment variables. */ bindir = replace_prefix (full_prefix, EVOLUTION_BINDIR); datadir = replace_prefix (full_prefix, EVOLUTION_DATADIR); ecpsdir = replace_prefix (full_prefix, EVOLUTION_ECPSDIR); etspecdir = replace_prefix (full_prefix, EVOLUTION_ETSPECDIR); galviewsdir = replace_prefix (full_prefix, EVOLUTION_GALVIEWSDIR); helpdir = replace_prefix (full_prefix, EVOLUTION_HELPDIR); if (g_getenv ("EVOLUTION_ICONDIR") && g_file_test (g_getenv ("EVOLUTION_ICONDIR"), G_FILE_TEST_IS_DIR)) icondir = g_getenv ("EVOLUTION_ICONDIR"); else icondir = replace_prefix (full_prefix, EVOLUTION_ICONDIR); if (g_getenv ("EVOLUTION_IMAGESDIR") && g_file_test (g_getenv ("EVOLUTION_IMAGESDIR"), G_FILE_TEST_IS_DIR)) imagesdir = g_getenv ("EVOLUTION_IMAGESDIR"); else imagesdir = replace_prefix (full_prefix, EVOLUTION_IMAGESDIR); libdir = replace_prefix (full_prefix, EVOLUTION_LIBDIR); libexecdir = replace_prefix (full_prefix, EVOLUTION_LIBEXECDIR); moduledir = replace_prefix (full_prefix, EVOLUTION_MODULEDIR); plugindir = replace_prefix (full_prefix, EVOLUTION_PLUGINDIR); privdatadir = replace_prefix (full_prefix, EVOLUTION_PRIVDATADIR); ruledir = replace_prefix (full_prefix, EVOLUTION_RULEDIR); sounddir = replace_prefix (full_prefix, EVOLUTION_SOUNDDIR); sysconfdir = replace_prefix (full_prefix, EVOLUTION_SYSCONFDIR); toolsdir = replace_prefix (full_prefix, EVOLUTION_TOOLSDIR); uidir = replace_prefix (full_prefix, EVOLUTION_UIDIR); g_free (full_prefix); G_UNLOCK (mutex); }