void anim_strip_key(sd_animation *ani, int kn, const char **key, int kcount, const char *tag) { int tmp = 0; switch(kn) { case 9: string_strip(ani->anim_string, tag); break; case 11: if(kcount == 2) { tmp = conv_ubyte(key[1]); if(tmp < ani->extra_string_count) { string_strip(ani->extra_strings[tmp], tag); } else { printf("Extra string table index %d does not exist!\n", tmp); return; } } else { printf("Key extra_str requires 1 parameter!\n"); return; } break; default: printf("Unknown key!\n"); return; } printf("Tag stripped!\n"); }
static bool equals(const void* a, const void* b) { wstring sa((wchar_t*)a); wstring sb((wchar_t*)b); string_strip(sa); string_strip(sb); return sa == sb; }
HashItem *construct_preset(char const *setkey, char *rest) { char *key; HashItem *mapItem; if (!(key = string_firstword(&rest))) /* get the key */ { /* e.g., title */ message_error("`preset ...: missing key"); return 0; } if (strcmp(key, "nohtmlfive") == 0) global.d_html5 = 0; else { if (!*string_strip(&rest)) /* get the value */ warning("Empty value of symbol `%s'", key); /* e.g., This is... */ if (strcmp(key, "styleopt") == 0) /* store styleopts */ lines_add(&global.d_styleopt, rest); else { /* look up the key */ mapItem = hashmap_find(&global.d_symbol, key, ANY); if (mapItem != PFAILED) /* reassign */ hashitem_set(mapItem, rest, free); /* existing value */ else /* or insert new */ hashmap_insert(&global.d_symbol, /* element */ hashitem_construct(VOIDPTR, key, new_str(rest), free)); } } free(key); return hashitem_construct(VOIDPTR, "", 0, root_nop); }
static void serializer_visit_label (Serializer* self, GtkLabel* label) { char* label_text; g_return_if_fail (self != NULL); g_return_if_fail (label != NULL); label_text = g_strdup (gtk_label_get_label (label)); g_string_append (self->priv->label_sb, label_text); g_debug ("serializer.vala:143: append text = %s", label_text); if (GTK_IS_ACCEL_LABEL (label)) { GtkLabel* _tmp0_; GtkLabel* _tmp1_; char* accel_string; gboolean _tmp2_ = FALSE; gtk_accel_label_refetch ((_tmp0_ = label, GTK_IS_ACCEL_LABEL (_tmp0_) ? ((GtkAccelLabel*) _tmp0_) : NULL)); accel_string = string_strip ((_tmp1_ = label, GTK_IS_ACCEL_LABEL (_tmp1_) ? ((GtkAccelLabel*) _tmp1_) : NULL)->accel_string); if (string_get_length (accel_string) > 0) { _tmp2_ = _vala_strcmp0 (accel_string, "-/-") != 0; } else { _tmp2_ = FALSE; } if (_tmp2_) { char* _tmp3_; g_string_append (self->priv->sb, _tmp3_ = g_markup_printf_escaped (" accel=\"%s\"", accel_string)); _g_free0 (_tmp3_); } _g_free0 (accel_string); } _g_free0 (label_text); }
string string_remove_trademark(const string &s) { string result = s; string_replace(result, "(TM)", ""); string_replace(result, "(R)", ""); return string_strip(result); }
string path_source_replace_includes(const string& source, const string& path, const string& source_filename) { /* Our own little c preprocessor that replaces #includes with the file * contents, to work around issue of opencl drivers not supporting * include paths with spaces in them. */ string result = ""; vector<string> lines; string_split(lines, source, "\n", false); for(size_t i = 0; i < lines.size(); ++i) { string line = lines[i]; if(line[0] == '#') { string token = string_strip(line.substr(1, line.size() - 1)); if(string_startswith(token, "include")) { token = string_strip(token.substr(7, token.size() - 7)); if(token[0] == '"') { size_t n_start = 1; size_t n_end = token.find("\"", n_start); string filename = token.substr(n_start, n_end - n_start); string text, filepath = path_join(path, filename); if(path_read_text(filepath, text)) { /* Replace include directories with both current path * and path extracted from the include file. * Not totally robust, but works fine for Cycles kernel * and avoids having list of include directories.x */ text = path_source_replace_includes( text, path_dirname(filepath), filename); text = path_source_replace_includes(text, path, filename); /* Use line directives for better error messages. */ line = line_directive(filepath, 1) + token.replace(0, n_end + 1, "\n" + text + "\n") + line_directive(path_join(path, source_filename), i); } } } } result += line + "\n"; } return result; }
TEST(String, Strip) { POINTERS_EQUAL(NULL, string_strip (NULL, 1, 1, NULL)); POINTERS_EQUAL(NULL, string_strip (NULL, 1, 1, ".;")); STRCMP_EQUAL("test", string_strip ("test", 1, 1, NULL)); STRCMP_EQUAL("test", string_strip ("test", 1, 1, ".;")); STRCMP_EQUAL(".-test.-", string_strip (".-test.-", 0, 0, ".-")); STRCMP_EQUAL("test", string_strip (".-test.-", 1, 1, ".-")); STRCMP_EQUAL("test.-", string_strip (".-test.-", 1, 0, ".-")); STRCMP_EQUAL(".-test", string_strip (".-test.-", 0, 1, ".-")); }
/** * Allocate and initialize the GDB structure, read the "map.txt" file * but don't look for kit folders themselves. */ void GDB::load() { GDB_DEBUG_OPEN(wlog,this->dir); GDB_DEBUG(wlog,(slog,L"Loading GDB...\n")); // process kit map file hash_map<WORD,wstring> mapFile; if (!readMap((this->dir + L"GDB\\uni\\map.txt").c_str(), mapFile)) { GDB_DEBUG(wlog,(slog,L"Unable to find uni-map: %s\n",mapFile)); LOG1S(L"Couldn't open uni-map for reading: {%s}",(this->dir + L"GDB\\uni\\map.txt").c_str()); } for (hash_map<WORD,wstring>::iterator it = mapFile.begin(); it != mapFile.end(); it++) { KitCollection kitCol(it->second); // strip off leading and trailing spaces string_strip(kitCol.foldername); // strip off quotes, if present if (kitCol.foldername[0]=='"' || kitCol.foldername[0]=='\'') kitCol.foldername.erase(0,1); int last = kitCol.foldername.length()-1; if (kitCol.foldername[last]=='"' || kitCol.foldername[last]=='\'') kitCol.foldername.erase(last); GDB_DEBUG(wlog,(slog,L"teamId = {%d}, foldername = {%s}\n", it->first, kitCol.foldername.c_str())); // store in the "uni" map this->uni.insert(pair<WORD,KitCollection>(it->first,kitCol)); // find kits for this team this->findKitsForTeam(it->first); } // create two dummy kit collections: for use with AFS kits Kit dummyKit; dummyKit.configLoaded = true; this->dummyHome.players.insert(pair<wstring,Kit>(L"pa",dummyKit)); this->dummyHome.players.insert(pair<wstring,Kit>(L"pb",dummyKit)); this->dummyHome.goalkeepers.insert(pair<wstring,Kit>(L"ga",dummyKit)); this->dummyHome.goalkeepers.insert(pair<wstring,Kit>(L"gb",dummyKit)); this->dummyHome.loaded = true; this->dummyAway.players.insert(pair<wstring,Kit>(L"pa",dummyKit)); this->dummyAway.players.insert(pair<wstring,Kit>(L"pb",dummyKit)); this->dummyAway.goalkeepers.insert(pair<wstring,Kit>(L"ga",dummyKit)); this->dummyAway.goalkeepers.insert(pair<wstring,Kit>(L"gb",dummyKit)); this->dummyAway.loaded = true; GDB_DEBUG(wlog,(slog,L"Loading GDB complete.\n")); GDB_DEBUG_CLOSE(wlog); }
TEST(String, Strip) { char *str; WEE_TEST_STR(NULL, string_strip (NULL, 1, 1, NULL)); WEE_TEST_STR(NULL, string_strip (NULL, 1, 1, ".;")); WEE_TEST_STR("test", string_strip ("test", 1, 1, NULL)); WEE_TEST_STR("test", string_strip ("test", 1, 1, ".;")); WEE_TEST_STR(".-test.-", string_strip (".-test.-", 0, 0, ".-")); WEE_TEST_STR("test", string_strip (".-test.-", 1, 1, ".-")); WEE_TEST_STR("test.-", string_strip (".-test.-", 1, 0, ".-")); WEE_TEST_STR(".-test", string_strip (".-test.-", 0, 1, ".-")); }
int hashify_read_hashes(stream_t* file, hashify_string_t** hashes) { //Read in hashes in file char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; string_const_t tokens[32]; memset(line_buffer, 0, sizeof(line_buffer)); do { string_t line = stream_read_line_buffer(file, line_buffer, sizeof(line_buffer), '\n'); string_const_t stripped_line = string_strip(STRING_ARGS(line), STRING_CONST("\n\r")); if ((string_find_string(STRING_ARGS(stripped_line), STRING_CONST("define"), 0) != STRING_NPOS) && (string_find_string(STRING_ARGS(stripped_line), STRING_CONST("static_hash"), 0) != STRING_NPOS)) { //Format is: #define HASH_<hashstring> static_hash_string( "<string>", 0x<hashvalue>ULL ) size_t num_tokens = string_explode(STRING_ARGS(stripped_line), STRING_CONST(" \t"), tokens, 32, false); if (num_tokens >= 6) { hashify_string_t hash_string; string_const_t stripped = string_strip(STRING_ARGS(tokens[3]), STRING_CONST(",")); stripped = string_strip(STRING_ARGS(stripped), STRING_CONST("\"")); hash_string.string = string_copy(hash_string.buffer, HASHIFY_STRING_LENGTH, STRING_ARGS(stripped)); hash_string.hash = string_to_uint64(STRING_ARGS(tokens[4]), true); if (hash(STRING_ARGS(hash_string.string)) != hash_string.hash) { log_errorf(0, ERROR_INVALID_VALUE, STRING_CONST(" hash output file is out of date, %.*s is set to 0x%" PRIx64 " but should be 0x%" PRIx64), STRING_FORMAT(hash_string.string), hash_string.hash, hash(STRING_ARGS(hash_string.string))); return HASHIFY_RESULT_OUTPUT_FILE_OUT_OF_DATE; } array_push_memcpy(*hashes, &hash_string); } } } while (!stream_eos(file)); return 0; }
guint16* daemon_helpers_typehelper_ParsePort (const gchar* text) { guint16* result = NULL; gchar* _tmp0_ = NULL; gchar* input; gboolean _tmp1_ = FALSE; gint _tmp2_; gint _tmp4_; gint port; gboolean _tmp5_ = FALSE; gboolean _tmp6_ = FALSE; guint16 _tmp7_; guint16* _tmp8_; g_return_val_if_fail (text != NULL, NULL); _tmp0_ = string_strip (text); input = _tmp0_; _tmp2_ = strlen (input); if (_tmp2_ == 0) { _tmp1_ = TRUE; } else { gboolean _tmp3_; _tmp3_ = daemon_helpers_typehelper_IsNumeric (input); _tmp1_ = !_tmp3_; } if (_tmp1_) { result = NULL; _g_free0 (input); return result; } _tmp4_ = atoi (input); port = _tmp4_; if (port < 0) { _tmp6_ = TRUE; } else { _tmp6_ = port < 0U; } if (_tmp6_) { _tmp5_ = TRUE; } else { _tmp5_ = port > G_MAXUINT16; } if (_tmp5_) { result = NULL; _g_free0 (input); return result; } _tmp7_ = (guint16) port; _tmp8_ = __uint16_dup0 (&_tmp7_); result = _tmp8_; _g_free0 (input); return result; }
int hashify_read_hashes( stream_t* file, hashify_string_t** hashes ) { //Read in hashes in file char* line; char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; do { stream_read_line_buffer( file, line_buffer, HASHIFY_LINEBUFFER_LENGTH-1, '\n' ); line = string_strip( line_buffer, "\n\r" ); if( ( string_find_string( line, "define", 0 ) != STRING_NPOS ) && ( string_find_string( line, "static_hash", 0 ) != STRING_NPOS ) ) { //Format is: #define HASH_<hashstring> static_hash_string( "<string>", 0x<hashvalue>ULL ) char** tokens = string_explode( line, " \t", false ); if( array_size( tokens ) >= 6 ) { hashify_string_t hash_string; string_copy( hash_string.string, string_strip( string_strip( tokens[3], "," ), "\"" ), HASHIFY_STRING_LENGTH ); hash_string.hash = string_to_uint64( tokens[4], true ); if( hash( hash_string.string, string_length( hash_string.string ) ) != hash_string.hash ) { log_errorf( ERROR_INVALID_VALUE, " hash output file is out of date, %s is set to 0x%llx but should be 0x%llx ", hash_string.string, hash_string.hash, hash( hash_string.string, string_length( hash_string.string ) ) ); string_array_deallocate( tokens ); return HASHIFY_RESULT_OUTPUT_FILE_OUT_OF_DATE; } array_push_memcpy( *hashes, &hash_string ); } string_array_deallocate( tokens ); } } while( !stream_eos( file ) ); return 0; }
string string_remove_trademark(const string &s) { string result = s; /* Special case, so we don;t leave sequential spaces behind. */ /* TODO(sergey): Consider using regex perhaps? */ string_replace(result, " (TM)", ""); string_replace(result, " (R)", ""); string_replace(result, "(TM)", ""); string_replace(result, "(R)", ""); return string_strip(result); }
const char* system_error_message( int code ) { static THREADLOCAL char errmsg[256]; if( !code ) code = GetLastError(); if( !code ) return ""; errmsg[0] = 0; FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, code & 0xBFFFFFFF, 0/*LANG_SYSTEM_DEFAULT*//*MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT )*/, errmsg, 255, 0 ); string_strip( errmsg, STRING_WHITESPACE ); return errmsg; }
int hashify_generate_preamble(stream_t* output_file, string_t output_filename) { //Read and preserve everything before #pragma once in case it contains header comments to be preserved char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; size_t capacity = 1024; string_t preamble = string_allocate(0, capacity); stream_t* prev_file = stream_open(STRING_ARGS(output_filename), STREAM_IN); memset(line_buffer, 0, sizeof(line_buffer)); while (prev_file && !stream_eos(prev_file)) { string_t line; string_const_t stripped_line; line = stream_read_line_buffer(prev_file, line_buffer, sizeof(line_buffer), '\n'); stripped_line = string_strip(STRING_ARGS(line), STRING_CONST("\n\r")); if ((string_find_string(STRING_ARGS(stripped_line), STRING_CONST("pragma"), 0) != STRING_NPOS) && (string_find_string(STRING_ARGS(stripped_line), STRING_CONST("once"), 0) != STRING_NPOS)) break; if (preamble.length + stripped_line.length + 1 >= capacity) { size_t newcapacity = capacity + 1024 + stripped_line.length; preamble.str = memory_reallocate(preamble.str, newcapacity, 0, capacity); capacity = newcapacity; } preamble = string_append(STRING_ARGS(preamble), capacity, STRING_ARGS(stripped_line)); if (line.length < sizeof(line_buffer)) preamble = string_append(STRING_ARGS(preamble), capacity, STRING_CONST(STRING_NEWLINE)); } stream_deallocate(prev_file); stream_seek(output_file, 0, STREAM_SEEK_BEGIN); if (preamble.length) stream_write_string(output_file, STRING_ARGS(preamble)); stream_write_string(output_file, STRING_CONST( "#pragma once\n\n" "#include <foundation/hash.h>\n\n" "/* ****** AUTOMATICALLY GENERATED, DO NOT EDIT ******\n" " Edit corresponding definitions file and rerun\n" " the foundation hashify tool to update this file */\n\n" )); string_deallocate(preamble.str); return 0; }
HashItem *construct_tocentry(char const *key, char *rest) { size_t level; char *section = string_firstword(&rest); if (!section) { message_error("incomplete tocentry"); return 0; } string_strip(&rest); /* find the section's index */ level = lines_find(section, section_levels, sizeofSectionLevels); if (level == UFAILED) /* no section given is err. */ { message_error("unknown toc-section `%s'", section); free(section); return 0; } free(section); /* write <dd><dl> for deeper levels */ for (; level > global.d_toclevel; ++global.d_toclevel) lines_add(&global.d_toc, "<dd><dl>"); /* write </dl></dd> when returning to shallower levels */ for (; level < global.d_toclevel; --global.d_toclevel) lines_add(&global.d_toc, "</dl></dd>"); /* add a new entry */ lines_format(&global.d_toc, "<dt>%s<a href=\"%s#l%u\">%s</a>%s</dt>", toc_section[global.d_doctype][level][0], string_str(&global.d_outName), (unsigned)++s_lastLabelNr, rest, toc_section[global.d_doctype][level][1]); return hashitem_construct(VOIDPTR, "", (void *)s_lastLabelNr, root_nop); }
int hashify_generate_preamble( stream_t* output_file ) { //Read and preserve everything before #pragma once in case it contains header comments to be preserved char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; char* preamble = 0; while( !stream_eos( output_file ) ) { char* line; uint64_t read; read = stream_read_line_buffer( output_file, line_buffer, HASHIFY_LINEBUFFER_LENGTH-1, '\n' ); line = string_strip( line_buffer, "\n\r" ); if( ( string_find_string( line, "pragma", 0 ) != STRING_NPOS ) && ( string_find_string( line, "once", 0 ) != STRING_NPOS ) ) break; preamble = string_append( preamble, line ); if( read < HASHIFY_LINEBUFFER_LENGTH ) preamble = string_append( preamble, "\n" ); } stream_seek( output_file, 0, STREAM_SEEK_BEGIN ); stream_write_string( output_file, preamble ); stream_write_string( output_file, "#pragma once\n\n" "#include <foundation/foundation.h>\n\n" "/* ****** AUTOMATICALLY GENERATED, DO NOT EDIT ******\n" " Edit corresponding definitions file and rerun\n" " the foundation hashify tool to update this file */\n\n" ); string_deallocate( preamble ); return 0; }
int process_spawn( process_t* proc ) { static char unescaped[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.:/\\"; int i, num_args; int size; #if FOUNDATION_PLATFORM_WINDOWS wchar_t* wcmdline; wchar_t* wwd; char* cmdline = 0; #endif if( !proc ) return PROCESS_INVALID_ARGS; proc->code = PROCESS_INVALID_ARGS; if( !string_length( proc->path ) ) return proc->code; //Always escape path on Windows platforms #if FOUNDATION_PLATFORM_POSIX if( string_find_first_not_of( proc->path, unescaped, 0 ) != STRING_NPOS ) #endif { if( proc->path[0] != '"' ) proc->path = string_prepend( proc->path, "\"" ); if( proc->path[ string_length( proc->path ) - 1 ] != '"' ) proc->path = string_append( proc->path, "\"" ); } size = array_size( proc->args ); for( i = 0, num_args = 0; i < size; ++i ) { char* arg = proc->args[i]; if( !string_length( arg ) ) continue; ++num_args; if( string_find_first_not_of( arg, unescaped, 0 ) != STRING_NPOS ) { if( arg[0] != '"' ) { //Check if we need to escape " characters unsigned int pos = string_find( arg, '"', 0 ); while( pos != STRING_NPOS ) { if( arg[ pos - 1 ] != '\\' ) { char* escarg = string_substr( arg, 0, pos ); char* left = string_substr( arg, pos, STRING_NPOS ); escarg = string_append( escarg, "\\" ); escarg = string_append( escarg, left ); string_deallocate( left ); string_deallocate( arg ); arg = escarg; } pos = string_find( arg, '"', pos + 2 ); } arg = string_prepend( arg, "\"" ); arg = string_append( arg, "\"" ); proc->args[i] = arg; } } } #if FOUNDATION_PLATFORM_WINDOWS # ifndef SEE_MASK_NOASYNC # define SEE_MASK_NOASYNC 0x00000100 # endif if( !( proc->flags & PROCESS_WINDOWS_USE_SHELLEXECUTE ) ) //Don't prepend exe path to parameters if using ShellExecute cmdline = string_clone( proc->path ); //Build command line string for( i = 0; i < size; ++i ) { char* arg = proc->args[i]; if( !string_length( arg ) ) continue; if( cmdline ) cmdline = string_append( cmdline, " " ); cmdline = string_append( cmdline, arg ); } if( !string_length( proc->wd ) ) proc->wd = string_clone( environment_current_working_directory() ); wcmdline = wstring_allocate_from_string( cmdline, 0 ); wwd = wstring_allocate_from_string( proc->wd, 0 ); if( proc->flags & PROCESS_WINDOWS_USE_SHELLEXECUTE ) { SHELLEXECUTEINFOW sei; wchar_t* wverb; wchar_t* wpath; wverb = ( proc->verb && string_length( proc->verb ) ) ? wstring_allocate_from_string( proc->verb, 0 ) : 0; wpath = wstring_allocate_from_string( proc->path, 0 ); ZeroMemory( &sei, sizeof( sei ) ); sei.cbSize = sizeof(SHELLEXECUTEINFOW); sei.hwnd = 0; sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; sei.lpVerb = wverb; sei.lpFile = wpath; sei.lpParameters = wcmdline; sei.lpDirectory = wwd; sei.nShow = SW_SHOWNORMAL; if( !( proc->flags & PROCESS_CONSOLE ) ) sei.fMask |= SEE_MASK_NO_CONSOLE; if( proc->flags & PROCESS_STDSTREAMS ) log_warnf( 0, WARNING_UNSUPPORTED, "Unable to redirect standard in/out through pipes when using ShellExecute for process spawning" ); log_debugf( 0, "Spawn process (ShellExecute): %s %s", proc->path, cmdline ); if( !ShellExecuteExW( &sei ) ) { log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to spawn process (ShellExecute) for executable '%s': %s", proc->path, system_error_message( GetLastError() ) ); } else { proc->hp = sei.hProcess; proc->ht = 0; proc->code = 0; } wstring_deallocate( wverb ); wstring_deallocate( wpath ); } else { STARTUPINFOW si; PROCESS_INFORMATION pi; BOOL inherit_handles = FALSE; memset( &si, 0, sizeof( si ) ); memset( &pi, 0, sizeof( pi ) ); si.cb = sizeof( si ); if( proc->flags & PROCESS_STDSTREAMS ) { proc->pipeout = pipe_allocate(); proc->pipein = pipe_allocate(); si.dwFlags |= STARTF_USESTDHANDLES; si.hStdOutput = pipe_write_handle( proc->pipeout ); si.hStdError = pipe_write_handle( proc->pipeout ); si.hStdInput = pipe_read_handle( proc->pipein ); //Don't inherit wrong ends of pipes SetHandleInformation( pipe_read_handle( proc->pipeout ), HANDLE_FLAG_INHERIT, 0 ); SetHandleInformation( pipe_write_handle( proc->pipein ), HANDLE_FLAG_INHERIT, 0 ); inherit_handles = TRUE; } log_debugf( 0, "Spawn process (CreateProcess): %s %s", proc->path, cmdline ); if( !CreateProcessW( 0/*wpath*/, wcmdline, 0, 0, inherit_handles, ( proc->flags & PROCESS_CONSOLE ) ? CREATE_NEW_CONSOLE : 0, 0, wwd, &si, &pi ) ) { log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to spawn process (CreateProcess) for executable '%s': %s", proc->path, system_error_message( GetLastError() ) ); stream_deallocate( proc->pipeout ); stream_deallocate( proc->pipein ); proc->pipeout = 0; proc->pipein = 0; } else { proc->hp = pi.hProcess; proc->ht = pi.hThread; proc->code = 0; } if( proc->pipeout ) pipe_close_write( proc->pipeout ); if( proc->pipein ) pipe_close_read( proc->pipein ); } wstring_deallocate( wcmdline ); wstring_deallocate( wwd ); string_deallocate( cmdline ); if( proc->code < 0 ) return proc->code; //Error #endif #if FOUNDATION_PLATFORM_MACOSX if( proc->flags & PROCESS_OSX_USE_OPENAPPLICATION ) { proc->pid = 0; LSApplicationParameters params; ProcessSerialNumber psn; FSRef* fsref = memory_allocate( 0, sizeof( FSRef ), 0, MEMORY_TEMPORARY | MEMORY_ZERO_INITIALIZED ); memset( ¶ms, 0, sizeof( LSApplicationParameters ) ); memset( &psn, 0, sizeof( ProcessSerialNumber ) ); char* pathstripped = string_strip( string_clone( proc->path ), "\"" ); OSStatus status = 0; status = FSPathMakeRef( (uint8_t*)pathstripped, fsref, 0 ); if( status < 0 ) { pathstripped = string_append( pathstripped, ".app" ); status = FSPathMakeRef( (uint8_t*)pathstripped, fsref, 0 ); } CFStringRef* args = 0; for( i = 0, size = array_size( proc->args ); i < size; ++i ) //App gets executable path automatically, don't include array_push( args, CFStringCreateWithCString( 0, proc->args[i], kCFStringEncodingUTF8 ) ); CFArrayRef argvref = CFArrayCreate( 0, (const void**)args, (CFIndex)array_size( args ), 0 ); params.flags = kLSLaunchDefaults; params.application = fsref; params.argv = argvref; log_debugf( 0, "Spawn process (LSOpenApplication): %s", pathstripped ); status = LSOpenApplication( ¶ms, &psn ); if( status != 0 ) { proc->code = status; log_warnf( 0, WARNING_BAD_DATA, "Unable to spawn process for executable '%s': %s", proc->path, system_error_message( status ) ); } CFRelease( argvref ); for( i = 0, size = array_size( args ); i < size; ++i ) CFRelease( args[i] ); memory_deallocate( fsref ); string_deallocate( pathstripped ); if( status == 0 ) { pid_t pid = 0; GetProcessPID( &psn, &pid ); proc->pid = pid; //Always "detached" with LSOpenApplication, not a child process at all //Setup a kqueue to watch when process terminates so we can emulate a wait proc->kq = kqueue(); if( proc->kq < 0 ) { log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to create kqueue for process watch: %s (%d)", proc->kq, system_error_message( proc->kq ) ); proc->kq = 0; } else { struct kevent changes; EV_SET( &changes, (pid_t)pid, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, 0 ); int ret = kevent( proc->kq, &changes, 1, &changes, 1, 0 ); if( ret != 1 ) { log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to setup kqueue for process watch, failed to add event to kqueue (%d)", ret ); close( proc->kq ); proc->kq = 0; } } } goto exit; } #endif #if FOUNDATION_PLATFORM_POSIX //Insert executable arg at start and null ptr at end int argc = array_size( proc->args ) + 1; array_grow( proc->args, 2 ); for( int arg = argc - 1; arg > 0; --arg ) proc->args[arg] = proc->args[arg-1]; proc->args[0] = string_clone( proc->path ); proc->args[argc] = 0; if( proc->flags & PROCESS_STDSTREAMS ) { proc->pipeout = pipe_allocate(); proc->pipein = pipe_allocate(); } proc->pid = 0; pid_t pid = fork(); if( pid == 0 ) { //Child if( string_length( proc->wd ) ) { log_debugf( 0, "Spawned child process, setting working directory to %s", proc->wd ); environment_set_current_working_directory( proc->wd ); } log_debugf( 0, "Child process executing: %s", proc->path ); if( proc->flags & PROCESS_STDSTREAMS ) { pipe_close_read( proc->pipeout ); dup2( pipe_write_fd( proc->pipeout ), STDOUT_FILENO ); pipe_close_write( proc->pipein ); dup2( pipe_read_fd( proc->pipein ), STDIN_FILENO ); } int code = execv( proc->path, proc->args ); if( code < 0 ) //Will always be true since this point will never be reached if execve() is successful log_warnf( 0, WARNING_BAD_DATA, "Child process failed execve() : %s : %s", proc->path, system_error_message( errno ) ); //Error process_exit( -1 ); } if( pid > 0 ) { log_debugf( 0, "Child process forked, pid %d", pid ); proc->pid = pid; if( proc->pipeout ) pipe_close_write( proc->pipeout ); if( proc->pipein ) pipe_close_read( proc->pipein ); if( proc->flags & PROCESS_DETACHED ) { int cstatus = 0; pid_t err = waitpid( pid, &cstatus, WNOHANG ); if( err == 0 ) { //TODO: Ugly wait to make sure process spawned correctly thread_sleep( 500 ); err = waitpid( pid, &cstatus, WNOHANG ); } if( err > 0 ) { //Process exited, check code proc->code = (int)((char)WEXITSTATUS( cstatus )); log_debugf( 0, "Child process returned: %d", proc->code ); return proc->code; } } } else { //Error proc->code = errno; log_warnf( 0, WARNING_BAD_DATA, "Unable to spawn process: %s : %s", proc->path, system_error_message( proc->code ) ); if( proc->pipeout ) stream_deallocate( proc->pipeout ); if( proc->pipein ) stream_deallocate( proc->pipein ); proc->pipeout = 0; proc->pipein = 0; return proc->code; } #endif #if !FOUNDATION_PLATFORM_WINDOWS && !FOUNDATION_PLATFORM_POSIX FOUNDATION_ASSERT_FAIL( "Process spawning not supported on platform" ); #endif #if FOUNDATION_PLATFORM_MACOSX exit: #endif if( proc->flags & PROCESS_DETACHED ) return PROCESS_STILL_ACTIVE; return process_wait( proc ); }
void vala_ccode_compiler_compile (ValaCCodeCompiler* self, ValaCodeContext* context, const gchar* cc_command, gchar** cc_options, int cc_options_length1) { gboolean use_pkgconfig; gchar* _tmp0_; gchar* pc; ValaCodeContext* _tmp1_; gboolean _tmp2_; gboolean _tmp3_; ValaCodeContext* _tmp6_; ValaProfile _tmp7_; ValaProfile _tmp8_; gchar* _tmp34_; gchar* pkgflags; gboolean _tmp35_; const gchar* _tmp45_; const gchar* _tmp46_; gchar* _tmp47_; gchar* cmdline; ValaCodeContext* _tmp48_; gboolean _tmp49_; gboolean _tmp50_; ValaCodeContext* _tmp53_; gboolean _tmp54_; gboolean _tmp55_; ValaCodeContext* _tmp93_; ValaList* _tmp94_ = NULL; ValaList* source_files; ValaCodeContext* _tmp118_; ValaList* _tmp119_ = NULL; ValaList* c_source_files; const gchar* _tmp138_; const gchar* _tmp139_; gchar* _tmp140_ = NULL; gchar* _tmp141_; gchar* _tmp142_; gchar* _tmp143_; gchar* _tmp144_; gchar** _tmp145_; gint _tmp145__length1; ValaCodeContext* _tmp154_; gboolean _tmp155_; gboolean _tmp156_; GError * _inner_error_ = NULL; g_return_if_fail (self != NULL); g_return_if_fail (context != NULL); use_pkgconfig = FALSE; _tmp0_ = g_strdup ("pkg-config --cflags"); pc = _tmp0_; _tmp1_ = context; _tmp2_ = vala_code_context_get_compile_only (_tmp1_); _tmp3_ = _tmp2_; if (!_tmp3_) { const gchar* _tmp4_; gchar* _tmp5_; _tmp4_ = pc; _tmp5_ = g_strconcat (_tmp4_, " --libs", NULL); _g_free0 (pc); pc = _tmp5_; } _tmp6_ = context; _tmp7_ = vala_code_context_get_profile (_tmp6_); _tmp8_ = _tmp7_; if (_tmp8_ == VALA_PROFILE_GOBJECT) { const gchar* _tmp9_; gchar* _tmp10_; ValaCodeContext* _tmp11_; gboolean _tmp12_; gboolean _tmp13_; use_pkgconfig = TRUE; _tmp9_ = pc; _tmp10_ = g_strconcat (_tmp9_, " gobject-2.0", NULL); _g_free0 (pc); pc = _tmp10_; _tmp11_ = context; _tmp12_ = vala_code_context_get_thread (_tmp11_); _tmp13_ = _tmp12_; if (_tmp13_) { const gchar* _tmp14_; gchar* _tmp15_; _tmp14_ = pc; _tmp15_ = g_strconcat (_tmp14_, " gthread-2.0", NULL); _g_free0 (pc); pc = _tmp15_; } } { ValaCodeContext* _tmp16_; ValaList* _tmp17_ = NULL; ValaList* _pkg_list; ValaList* _tmp18_; gint _tmp19_; gint _tmp20_; gint _pkg_size; gint _pkg_index; _tmp16_ = context; _tmp17_ = vala_code_context_get_packages (_tmp16_); _pkg_list = _tmp17_; _tmp18_ = _pkg_list; _tmp19_ = vala_collection_get_size ((ValaCollection*) _tmp18_); _tmp20_ = _tmp19_; _pkg_size = _tmp20_; _pkg_index = -1; while (TRUE) { gint _tmp21_; gint _tmp22_; gint _tmp23_; ValaList* _tmp24_; gint _tmp25_; gpointer _tmp26_ = NULL; gchar* pkg; const gchar* _tmp27_; gboolean _tmp28_ = FALSE; _tmp21_ = _pkg_index; _pkg_index = _tmp21_ + 1; _tmp22_ = _pkg_index; _tmp23_ = _pkg_size; if (!(_tmp22_ < _tmp23_)) { break; } _tmp24_ = _pkg_list; _tmp25_ = _pkg_index; _tmp26_ = vala_list_get (_tmp24_, _tmp25_); pkg = (gchar*) _tmp26_; _tmp27_ = pkg; _tmp28_ = vala_ccode_compiler_package_exists (_tmp27_); if (_tmp28_) { const gchar* _tmp29_; const gchar* _tmp30_; gchar* _tmp31_; gchar* _tmp32_; gchar* _tmp33_; use_pkgconfig = TRUE; _tmp29_ = pc; _tmp30_ = pkg; _tmp31_ = g_strconcat (" ", _tmp30_, NULL); _tmp32_ = _tmp31_; _tmp33_ = g_strconcat (_tmp29_, _tmp32_, NULL); _g_free0 (pc); pc = _tmp33_; _g_free0 (_tmp32_); } _g_free0 (pkg); } _vala_iterable_unref0 (_pkg_list); } _tmp34_ = g_strdup (""); pkgflags = _tmp34_; _tmp35_ = use_pkgconfig; if (_tmp35_) { { gint exit_status = 0; const gchar* _tmp36_; gchar* _tmp37_ = NULL; gint _tmp38_ = 0; gint _tmp39_; _tmp36_ = pc; g_spawn_command_line_sync (_tmp36_, &_tmp37_, NULL, &_tmp38_, &_inner_error_); _g_free0 (pkgflags); pkgflags = _tmp37_; exit_status = _tmp38_; if (_inner_error_ != NULL) { if (_inner_error_->domain == G_SPAWN_ERROR) { goto __catch2_g_spawn_error; } _g_free0 (pkgflags); _g_free0 (pc); g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } _tmp39_ = exit_status; if (_tmp39_ != 0) { gint _tmp40_; gchar* _tmp41_ = NULL; gchar* _tmp42_; _tmp40_ = exit_status; _tmp41_ = g_strdup_printf ("pkg-config exited with status %d", _tmp40_); _tmp42_ = _tmp41_; vala_report_error (NULL, _tmp42_); _g_free0 (_tmp42_); _g_free0 (pkgflags); _g_free0 (pc); return; } } goto __finally2; __catch2_g_spawn_error: { GError* e = NULL; GError* _tmp43_; const gchar* _tmp44_; e = _inner_error_; _inner_error_ = NULL; _tmp43_ = e; _tmp44_ = _tmp43_->message; vala_report_error (NULL, _tmp44_); _g_error_free0 (e); _g_free0 (pkgflags); _g_free0 (pc); return; } __finally2: if (_inner_error_ != NULL) { _g_free0 (pkgflags); _g_free0 (pc); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } _tmp45_ = cc_command; if (_tmp45_ == NULL) { cc_command = "cc"; } _tmp46_ = cc_command; _tmp47_ = g_strdup (_tmp46_); cmdline = _tmp47_; _tmp48_ = context; _tmp49_ = vala_code_context_get_debug (_tmp48_); _tmp50_ = _tmp49_; if (_tmp50_) { const gchar* _tmp51_; gchar* _tmp52_; _tmp51_ = cmdline; _tmp52_ = g_strconcat (_tmp51_, " -g", NULL); _g_free0 (cmdline); cmdline = _tmp52_; } _tmp53_ = context; _tmp54_ = vala_code_context_get_compile_only (_tmp53_); _tmp55_ = _tmp54_; if (_tmp55_) { const gchar* _tmp56_; gchar* _tmp57_; _tmp56_ = cmdline; _tmp57_ = g_strconcat (_tmp56_, " -c", NULL); _g_free0 (cmdline); cmdline = _tmp57_; } else { ValaCodeContext* _tmp58_; const gchar* _tmp59_; const gchar* _tmp60_; _tmp58_ = context; _tmp59_ = vala_code_context_get_output (_tmp58_); _tmp60_ = _tmp59_; if (_tmp60_ != NULL) { ValaCodeContext* _tmp61_; const gchar* _tmp62_; const gchar* _tmp63_; gchar* _tmp64_; gchar* output; gboolean _tmp65_ = FALSE; gboolean _tmp66_ = FALSE; ValaCodeContext* _tmp67_; const gchar* _tmp68_; const gchar* _tmp69_; gboolean _tmp73_; gboolean _tmp78_; const gchar* _tmp86_; const gchar* _tmp87_; gchar* _tmp88_ = NULL; gchar* _tmp89_; gchar* _tmp90_; gchar* _tmp91_; gchar* _tmp92_; _tmp61_ = context; _tmp62_ = vala_code_context_get_output (_tmp61_); _tmp63_ = _tmp62_; _tmp64_ = g_strdup (_tmp63_); output = _tmp64_; _tmp67_ = context; _tmp68_ = vala_code_context_get_directory (_tmp67_); _tmp69_ = _tmp68_; if (_tmp69_ != NULL) { ValaCodeContext* _tmp70_; const gchar* _tmp71_; const gchar* _tmp72_; _tmp70_ = context; _tmp71_ = vala_code_context_get_directory (_tmp70_); _tmp72_ = _tmp71_; _tmp66_ = g_strcmp0 (_tmp72_, "") != 0; } else { _tmp66_ = FALSE; } _tmp73_ = _tmp66_; if (_tmp73_) { ValaCodeContext* _tmp74_; const gchar* _tmp75_; const gchar* _tmp76_; gboolean _tmp77_ = FALSE; _tmp74_ = context; _tmp75_ = vala_code_context_get_output (_tmp74_); _tmp76_ = _tmp75_; _tmp77_ = g_path_is_absolute (_tmp76_); _tmp65_ = !_tmp77_; } else { _tmp65_ = FALSE; } _tmp78_ = _tmp65_; if (_tmp78_) { ValaCodeContext* _tmp79_; const gchar* _tmp80_; const gchar* _tmp81_; ValaCodeContext* _tmp82_; const gchar* _tmp83_; const gchar* _tmp84_; gchar* _tmp85_ = NULL; _tmp79_ = context; _tmp80_ = vala_code_context_get_directory (_tmp79_); _tmp81_ = _tmp80_; _tmp82_ = context; _tmp83_ = vala_code_context_get_output (_tmp82_); _tmp84_ = _tmp83_; _tmp85_ = g_strdup_printf ("%s%c%s", _tmp81_, (gint) G_DIR_SEPARATOR, _tmp84_); _g_free0 (output); output = _tmp85_; } _tmp86_ = cmdline; _tmp87_ = output; _tmp88_ = g_shell_quote (_tmp87_); _tmp89_ = _tmp88_; _tmp90_ = g_strconcat (" -o ", _tmp89_, NULL); _tmp91_ = _tmp90_; _tmp92_ = g_strconcat (_tmp86_, _tmp91_, NULL); _g_free0 (cmdline); cmdline = _tmp92_; _g_free0 (_tmp91_); _g_free0 (_tmp89_); _g_free0 (output); } } _tmp93_ = context; _tmp94_ = vala_code_context_get_source_files (_tmp93_); source_files = _tmp94_; { ValaList* _tmp95_; ValaList* _tmp96_; ValaList* _file_list; ValaList* _tmp97_; gint _tmp98_; gint _tmp99_; gint _file_size; gint _file_index; _tmp95_ = source_files; _tmp96_ = _vala_iterable_ref0 (_tmp95_); _file_list = _tmp96_; _tmp97_ = _file_list; _tmp98_ = vala_collection_get_size ((ValaCollection*) _tmp97_); _tmp99_ = _tmp98_; _file_size = _tmp99_; _file_index = -1; while (TRUE) { gint _tmp100_; gint _tmp101_; gint _tmp102_; ValaList* _tmp103_; gint _tmp104_; gpointer _tmp105_ = NULL; ValaSourceFile* file; ValaSourceFile* _tmp106_; ValaSourceFileType _tmp107_; ValaSourceFileType _tmp108_; _tmp100_ = _file_index; _file_index = _tmp100_ + 1; _tmp101_ = _file_index; _tmp102_ = _file_size; if (!(_tmp101_ < _tmp102_)) { break; } _tmp103_ = _file_list; _tmp104_ = _file_index; _tmp105_ = vala_list_get (_tmp103_, _tmp104_); file = (ValaSourceFile*) _tmp105_; _tmp106_ = file; _tmp107_ = vala_source_file_get_file_type (_tmp106_); _tmp108_ = _tmp107_; if (_tmp108_ == VALA_SOURCE_FILE_TYPE_SOURCE) { const gchar* _tmp109_; ValaSourceFile* _tmp110_; gchar* _tmp111_ = NULL; gchar* _tmp112_; gchar* _tmp113_ = NULL; gchar* _tmp114_; gchar* _tmp115_; gchar* _tmp116_; gchar* _tmp117_; _tmp109_ = cmdline; _tmp110_ = file; _tmp111_ = vala_source_file_get_csource_filename (_tmp110_); _tmp112_ = _tmp111_; _tmp113_ = g_shell_quote (_tmp112_); _tmp114_ = _tmp113_; _tmp115_ = g_strconcat (" ", _tmp114_, NULL); _tmp116_ = _tmp115_; _tmp117_ = g_strconcat (_tmp109_, _tmp116_, NULL); _g_free0 (cmdline); cmdline = _tmp117_; _g_free0 (_tmp116_); _g_free0 (_tmp114_); _g_free0 (_tmp112_); } _vala_source_file_unref0 (file); } _vala_iterable_unref0 (_file_list); } _tmp118_ = context; _tmp119_ = vala_code_context_get_c_source_files (_tmp118_); c_source_files = _tmp119_; { ValaList* _tmp120_; ValaList* _tmp121_; ValaList* _file_list; ValaList* _tmp122_; gint _tmp123_; gint _tmp124_; gint _file_size; gint _file_index; _tmp120_ = c_source_files; _tmp121_ = _vala_iterable_ref0 (_tmp120_); _file_list = _tmp121_; _tmp122_ = _file_list; _tmp123_ = vala_collection_get_size ((ValaCollection*) _tmp122_); _tmp124_ = _tmp123_; _file_size = _tmp124_; _file_index = -1; while (TRUE) { gint _tmp125_; gint _tmp126_; gint _tmp127_; ValaList* _tmp128_; gint _tmp129_; gpointer _tmp130_ = NULL; gchar* file; const gchar* _tmp131_; const gchar* _tmp132_; gchar* _tmp133_ = NULL; gchar* _tmp134_; gchar* _tmp135_; gchar* _tmp136_; gchar* _tmp137_; _tmp125_ = _file_index; _file_index = _tmp125_ + 1; _tmp126_ = _file_index; _tmp127_ = _file_size; if (!(_tmp126_ < _tmp127_)) { break; } _tmp128_ = _file_list; _tmp129_ = _file_index; _tmp130_ = vala_list_get (_tmp128_, _tmp129_); file = (gchar*) _tmp130_; _tmp131_ = cmdline; _tmp132_ = file; _tmp133_ = g_shell_quote (_tmp132_); _tmp134_ = _tmp133_; _tmp135_ = g_strconcat (" ", _tmp134_, NULL); _tmp136_ = _tmp135_; _tmp137_ = g_strconcat (_tmp131_, _tmp136_, NULL); _g_free0 (cmdline); cmdline = _tmp137_; _g_free0 (_tmp136_); _g_free0 (_tmp134_); _g_free0 (file); } _vala_iterable_unref0 (_file_list); } _tmp138_ = cmdline; _tmp139_ = pkgflags; _tmp140_ = string_strip (_tmp139_); _tmp141_ = _tmp140_; _tmp142_ = g_strconcat (" ", _tmp141_, NULL); _tmp143_ = _tmp142_; _tmp144_ = g_strconcat (_tmp138_, _tmp143_, NULL); _g_free0 (cmdline); cmdline = _tmp144_; _g_free0 (_tmp143_); _g_free0 (_tmp141_); _tmp145_ = cc_options; _tmp145__length1 = cc_options_length1; { gchar** cc_option_collection = NULL; gint cc_option_collection_length1 = 0; gint _cc_option_collection_size_ = 0; gint cc_option_it = 0; cc_option_collection = _tmp145_; cc_option_collection_length1 = _tmp145__length1; for (cc_option_it = 0; cc_option_it < _tmp145__length1; cc_option_it = cc_option_it + 1) { gchar* _tmp146_; gchar* cc_option = NULL; _tmp146_ = g_strdup (cc_option_collection[cc_option_it]); cc_option = _tmp146_; { const gchar* _tmp147_; const gchar* _tmp148_; gchar* _tmp149_ = NULL; gchar* _tmp150_; gchar* _tmp151_; gchar* _tmp152_; gchar* _tmp153_; _tmp147_ = cmdline; _tmp148_ = cc_option; _tmp149_ = g_shell_quote (_tmp148_); _tmp150_ = _tmp149_; _tmp151_ = g_strconcat (" ", _tmp150_, NULL); _tmp152_ = _tmp151_; _tmp153_ = g_strconcat (_tmp147_, _tmp152_, NULL); _g_free0 (cmdline); cmdline = _tmp153_; _g_free0 (_tmp152_); _g_free0 (_tmp150_); _g_free0 (cc_option); } } } _tmp154_ = context; _tmp155_ = vala_code_context_get_verbose_mode (_tmp154_); _tmp156_ = _tmp155_; if (_tmp156_) { FILE* _tmp157_; const gchar* _tmp158_; _tmp157_ = stdout; _tmp158_ = cmdline; fprintf (_tmp157_, "%s\n", _tmp158_); } { gint exit_status = 0; const gchar* _tmp159_; gint _tmp160_ = 0; gint _tmp161_; _tmp159_ = cmdline; g_spawn_command_line_sync (_tmp159_, NULL, NULL, &_tmp160_, &_inner_error_); exit_status = _tmp160_; if (_inner_error_ != NULL) { if (_inner_error_->domain == G_SPAWN_ERROR) { goto __catch3_g_spawn_error; } _vala_iterable_unref0 (c_source_files); _vala_iterable_unref0 (source_files); _g_free0 (cmdline); _g_free0 (pkgflags); _g_free0 (pc); g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } _tmp161_ = exit_status; if (_tmp161_ != 0) { gint _tmp162_; gchar* _tmp163_ = NULL; gchar* _tmp164_; _tmp162_ = exit_status; _tmp163_ = g_strdup_printf ("cc exited with status %d", _tmp162_); _tmp164_ = _tmp163_; vala_report_error (NULL, _tmp164_); _g_free0 (_tmp164_); } } goto __finally3; __catch3_g_spawn_error: { GError* e = NULL; GError* _tmp165_; const gchar* _tmp166_; e = _inner_error_; _inner_error_ = NULL; _tmp165_ = e; _tmp166_ = _tmp165_->message; vala_report_error (NULL, _tmp166_); _g_error_free0 (e); } __finally3: if (_inner_error_ != NULL) { _vala_iterable_unref0 (c_source_files); _vala_iterable_unref0 (source_files); _g_free0 (cmdline); _g_free0 (pkgflags); _g_free0 (pc); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } { ValaList* _tmp167_; ValaList* _tmp168_; ValaList* _file_list; ValaList* _tmp169_; gint _tmp170_; gint _tmp171_; gint _file_size; gint _file_index; _tmp167_ = source_files; _tmp168_ = _vala_iterable_ref0 (_tmp167_); _file_list = _tmp168_; _tmp169_ = _file_list; _tmp170_ = vala_collection_get_size ((ValaCollection*) _tmp169_); _tmp171_ = _tmp170_; _file_size = _tmp171_; _file_index = -1; while (TRUE) { gint _tmp172_; gint _tmp173_; gint _tmp174_; ValaList* _tmp175_; gint _tmp176_; gpointer _tmp177_ = NULL; ValaSourceFile* file; ValaSourceFile* _tmp178_; ValaSourceFileType _tmp179_; ValaSourceFileType _tmp180_; _tmp172_ = _file_index; _file_index = _tmp172_ + 1; _tmp173_ = _file_index; _tmp174_ = _file_size; if (!(_tmp173_ < _tmp174_)) { break; } _tmp175_ = _file_list; _tmp176_ = _file_index; _tmp177_ = vala_list_get (_tmp175_, _tmp176_); file = (ValaSourceFile*) _tmp177_; _tmp178_ = file; _tmp179_ = vala_source_file_get_file_type (_tmp178_); _tmp180_ = _tmp179_; if (_tmp180_ == VALA_SOURCE_FILE_TYPE_SOURCE) { ValaCodeContext* _tmp181_; gboolean _tmp182_; gboolean _tmp183_; _tmp181_ = context; _tmp182_ = vala_code_context_get_save_csources (_tmp181_); _tmp183_ = _tmp182_; if (!_tmp183_) { ValaSourceFile* _tmp184_; gchar* _tmp185_ = NULL; gchar* _tmp186_; _tmp184_ = file; _tmp185_ = vala_source_file_get_csource_filename (_tmp184_); _tmp186_ = _tmp185_; g_unlink (_tmp186_); _g_free0 (_tmp186_); } } _vala_source_file_unref0 (file); } _vala_iterable_unref0 (_file_list); } _vala_iterable_unref0 (c_source_files); _vala_iterable_unref0 (source_files); _g_free0 (cmdline); _g_free0 (pkgflags); _g_free0 (pc); }
void config_parse( stream_t* stream, hash_t filter_section, bool overwrite ) { char* buffer; hash_t section = 0; hash_t key = 0; unsigned int line = 0; #if BUILD_ENABLE_DEBUG_CONFIG log_debugf( HASH_CONFIG, "Parsing config stream: %s", stream_path( stream ) ); #endif buffer = memory_allocate_zero( 1024ULL, 0, MEMORY_TEMPORARY ); while( !stream_eos( stream ) ) { ++line; stream_read_line_buffer( stream, buffer, 1024, '\n' ); string_strip( buffer, " \t\n\r" ); if( !string_length( buffer ) || ( buffer[0] == ';' ) || ( buffer[0] == '#' ) ) continue; if( buffer[0] == '[' ) { //Section declaration unsigned int endpos = string_rfind( buffer, ']', string_length( buffer ) - 1 ); if( ( endpos == STRING_NPOS ) || ( endpos < 1 ) ) { log_warnf( HASH_CONFIG, WARNING_BAD_DATA, "Invalid section declaration on line %d in config stream '%s'", line, stream_path( stream ) ); continue; } buffer[endpos] = 0; section = hash( buffer + 1, endpos - 1 ); #if BUILD_ENABLE_DEBUG_CONFIG log_debugf( HASH_CONFIG, " config: section set to '%s' (0x%llx)", buffer + 1, section ); #endif } else if( !filter_section || ( filter_section == section ) ) { //name=value declaration char* name; char* value; unsigned int separator = string_find( buffer, '=', 0 ); if( separator == STRING_NPOS ) { log_warnf( HASH_CONFIG, WARNING_BAD_DATA, "Invalid value declaration on line %d in config stream '%s', missing assignment operator '=': %s", line, stream_path( stream ), buffer ); continue; } name = string_strip_substr( buffer, " \t", separator ); value = string_strip( buffer + separator + 1, " \t" ); if( !string_length( name ) ) { log_warnf( HASH_CONFIG, WARNING_BAD_DATA, "Invalid value declaration on line %d in config stream '%s', empty name string", line, stream_path( stream ) ); continue; } key = hash( name, string_length( name ) ); if( overwrite || !config_key( section, key, false ) ) { #if BUILD_ENABLE_DEBUG_CONFIG log_debugf( HASH_CONFIG, " config: %s (0x%llx) = %s", name, key, value ); #endif if( !string_length( value ) ) config_set_string( section, key, "" ); else if( string_equal( value, "false" ) ) config_set_bool( section, key, false ); else if( string_equal( value, "true" ) ) config_set_bool( section, key, true ); else if( ( string_find( value, '.', 0 ) != STRING_NPOS ) && ( string_find_first_not_of( value, "0123456789.", 0 ) == STRING_NPOS ) && ( string_find( value, '.', string_find( value, '.', 0 ) + 1 ) == STRING_NPOS ) ) //Exactly one "." config_set_real( section, key, string_to_real( value ) ); else if( string_find_first_not_of( value, "0123456789", 0 ) == STRING_NPOS ) config_set_int( section, key, string_to_int64( value ) ); else config_set_string( section, key, value ); } } } memory_deallocate( buffer ); }
void InitMaps() { hash_map<wstring,WORD> slots; // process boots map file hash_map<DWORD,wstring> mapFile; wstring mpath(getPesInfo()->gdbDir); mpath += L"GDB\\boots\\map.txt"; if (!readMap(mpath.c_str(), mapFile)) { LOG1S(L"Couldn't open boots map for reading: {%s}",mpath.c_str()); } else { int slot = 0; for (hash_map<DWORD,wstring>::iterator it = mapFile.begin(); it != mapFile.end(); it++) { wstring boot(it->second); string_strip(boot); if (!boot.empty()) string_strip_quotes(boot); if (!boot.empty()) { // check that the file exists, so that we don't crash // later, when it's attempted to replace a boot. wstring filename(getPesInfo()->gdbDir); filename += L"GDB\\boots\\" + boot; HANDLE handle; DWORD size; if (OpenFileIfExists(filename.c_str(), handle, size)) { CloseHandle(handle); if (slot >= MAX_BOOTS) { LOG2N(L"ERROR in bootserver map: Too many boots: %d (MAX supported = %d). Aborting map processing", slot, MAX_BOOTS); break; } hash_map<wstring,WORD>::iterator wit = slots.find(boot); if (wit != slots.end()) { // boot already has an assigned slot _boot_slots.insert(pair<DWORD,WORD>( it->first, wit->second)); } else { _boot_slots.insert(pair<DWORD,WORD>( it->first, FIRST_EXTRA_BOOT_SLOT + slot)); slots.insert(pair<wstring,WORD>( boot, FIRST_EXTRA_BOOT_SLOT + slot)); slot++; } } else LOG1N1S(L"ERROR in bootserver map for ID = %d: FAILED to open boot BIN \"%s\". Skipping", it->first, boot.c_str()); } } } if (_bootserv_config._random_boots) { // enumerate all boots and add them to the slots list wstring dir(getPesInfo()->gdbDir); dir += L"GDB\\boots\\"; // normalize the path wchar_t fullpath[MAX_PATH]; GetFullPathName(dir.c_str(), MAX_PATH, fullpath, 0); dir = fullpath; int count; LOG(L"Enumerating all boots in GDB..."); EnumerateBoots(dir, count); _num_random_boots = count; LOG1N(L"_num_random_boots = %d", _num_random_boots); } // initialize fast bin lookup table for (hash_map<wstring,WORD>::iterator sit = slots.begin(); sit != slots.end(); sit++) { _fast_bin_table[sit->second - FIRST_EXTRA_BOOT_SLOT] = new wstring(sit->first); if (k_bootserv.debug) LOG1N1S(L"slot %d <-- boot {%s}", sit->second, sit->first.c_str()); } LOG1N(L"Total assigned GDB boots: %d", slots.size()); LOG1N(L"Total random GDB boots: %d", _num_random_boots); if (slots.size() > 0) _num_slots = FIRST_EXTRA_BOOT_SLOT + slots.size(); if (_num_random_boots > 0) _num_slots = FIRST_RANDOM_BOOT_SLOT + _num_random_boots; LOG1N(L"_num_slots = %d", _num_slots); }
static int render_import_program(stream_t* stream, const uuid_t uuid) { char buffer[1024]; char pathbuf[BUILD_MAX_PATHLEN]; resource_source_t source; resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1}; uint64_t platform; tick_t timestamp; int ret = 0; resource_source_initialize(&source); resource_source_read(&source, uuid); platform = resource_platform(platformdecl); timestamp = time_system(); while (!stream_eos(stream)) { string_const_t type, ref; string_const_t fullpath; string_const_t uuidstr; uuid_t shaderuuid; hash_t typehash; string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n'); string_split(STRING_ARGS(line), STRING_CONST(" \t"), &type, &ref, false); type = string_strip(STRING_ARGS(type), STRING_CONST(STRING_WHITESPACE)); ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE)); if (!type.length || !ref.length) continue; typehash = hash(STRING_ARGS(type)); if ((typehash != HASH_VERTEXSHADER) && (typehash != HASH_PIXELSHADER)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Ignore invalid line: %.*s"), STRING_FORMAT(line)); continue; } shaderuuid = string_to_uuid(STRING_ARGS(ref)); if (uuid_is_null(shaderuuid)) { if (path_is_absolute(STRING_ARGS(ref))) { fullpath = ref; } else { string_t full; string_const_t path = stream_path(stream); path = path_directory_name(STRING_ARGS(path)); full = path_concat(pathbuf, sizeof(pathbuf), STRING_ARGS(path), STRING_ARGS(ref)); full = path_absolute(STRING_ARGS(full), sizeof(pathbuf)); fullpath = string_const(STRING_ARGS(full)); } resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { if (!resource_import(STRING_ARGS(fullpath), uuid_null())) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to import linked shader: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Import linked shader gave no UUID: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } } shaderuuid = sig.uuid; } if (!uuid_is_null(shaderuuid)) { uuidstr = string_from_uuid_static(shaderuuid); resource_source_set(&source, timestamp, typehash, platform, STRING_ARGS(uuidstr)); } } resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE, 0, STRING_CONST("program")); if (!resource_source_write(&source, uuid, false)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported program: %.*s"), STRING_FORMAT(uuidstr)); ret = -1; goto finalize; } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported program: %.*s"), STRING_FORMAT(uuidstr)); } finalize: resource_source_finalize(&source); return ret; }
DaemonSmtpConfiguration* daemon_smtp_configuration_Parse (const gchar* input, GError** error) { DaemonSmtpConfiguration* result = NULL; gchar** _tmp0_; gchar** _tmp1_ = NULL; gchar** parts; gint parts_length1; gint _parts_size_; gchar* _tmp3_ = NULL; gchar* sender; gint _tmp4_; gchar* host = NULL; guint16* port = NULL; gchar* _tmp6_ = NULL; guint16* _tmp7_ = NULL; guint16* _tmp9_; guint16* _tmp10_; guint16* _tmp13_; DaemonSmtpConfiguration* _tmp14_ = NULL; GError * _inner_error_ = NULL; g_return_val_if_fail (input != NULL, NULL); _tmp1_ = _tmp0_ = g_strsplit (input, "/", 0); parts = _tmp1_; parts_length1 = _vala_array_length (_tmp0_); _parts_size_ = _vala_array_length (_tmp0_); if (parts_length1 != 2) { GError* _tmp2_ = NULL; _tmp2_ = g_error_new_literal (DAEMON_SMTP_ERROR, DAEMON_SMTP_ERROR_InvalidConfiguration, "Invalid configuration string"); _inner_error_ = _tmp2_; if (_inner_error_->domain == DAEMON_SMTP_ERROR) { g_propagate_error (error, _inner_error_); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); return NULL; } else { parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } } _tmp3_ = string_strip (parts[0]); sender = _tmp3_; _tmp4_ = strlen (sender); if (_tmp4_ == 0) { GError* _tmp5_ = NULL; _tmp5_ = g_error_new_literal (DAEMON_SMTP_ERROR, DAEMON_SMTP_ERROR_InvalidConfiguration, "Invalid configuration string"); _inner_error_ = _tmp5_; if (_inner_error_->domain == DAEMON_SMTP_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); return NULL; } else { _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } } daemon_helpers_typehelper_ParseHostAndPort (parts[1], &_tmp6_, &_tmp7_, &_inner_error_); _g_free0 (host); host = _tmp6_; _g_free0 (port); port = _tmp7_; if (_inner_error_ != NULL) { if (_inner_error_->domain == DAEMON_HELPERS_DAEMON_ERROR) { goto __catch8_daemon_helpers_daemon_error; } _g_free0 (port); _g_free0 (host); _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } goto __finally8; __catch8_daemon_helpers_daemon_error: { GError * _error_; GError* _tmp8_ = NULL; _error_ = _inner_error_; _inner_error_ = NULL; _tmp8_ = g_error_new_literal (DAEMON_SMTP_ERROR, DAEMON_SMTP_ERROR_InvalidConfiguration, _error_->message); _inner_error_ = _tmp8_; _g_error_free0 (_error_); goto __finally8; } __finally8: if (_inner_error_ != NULL) { if (_inner_error_->domain == DAEMON_SMTP_ERROR) { g_propagate_error (error, _inner_error_); _g_free0 (port); _g_free0 (host); _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); return NULL; } else { _g_free0 (port); _g_free0 (host); _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } } _tmp9_ = __uint16_dup0 (port); _tmp10_ = _tmp9_; if (_tmp10_ == NULL) { gint _tmp11_; guint16* _tmp12_; _tmp11_ = 25; _tmp12_ = __uint16_dup0 (&_tmp11_); _g_free0 (_tmp10_); _tmp10_ = _tmp12_; } _tmp13_ = __uint16_dup0 (_tmp10_); _g_free0 (port); port = _tmp13_; _tmp14_ = daemon_smtp_configuration_new (sender, host, *port); result = _tmp14_; _g_free0 (_tmp10_); _g_free0 (port); _g_free0 (host); _g_free0 (sender); parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL); return result; }
int hashify_process_file( stream_t* input_file, stream_t* output_file, bool check_only, hashify_string_t** history ) { int result = HASHIFY_RESULT_OK; char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; hashify_string_t* local_hashes = 0; hashify_string_t* local_generated = 0; if( check_only ) result = hashify_read_hashes( output_file, &local_hashes ); else result = hashify_generate_preamble( output_file ); while( !stream_eos( input_file ) && ( result == HASHIFY_RESULT_OK ) ) { char* def_string = 0; char* value_string = 0; stream_read_line_buffer( input_file, line_buffer, HASHIFY_LINEBUFFER_LENGTH, '\n' ); string_split( line_buffer, " \t", &def_string, &value_string, false ); string_strip( def_string, STRING_WHITESPACE ); string_strip( value_string, STRING_WHITESPACE ); if( string_length( value_string ) && ( value_string[0] == '"' ) && ( value_string[ string_length( value_string ) - 1 ] == '"' ) ) { unsigned int len = string_length( value_string ); memmove( value_string, value_string + 1, len - 2 ); value_string[len-2] = 0; } if( string_length( def_string ) ) { hash_t hash_value = hash( value_string, string_length( value_string ) ); log_infof( " %s: %s -> 0x%llx", def_string, value_string, hash_value ); if( check_only ) { //Check local consistency result = hashify_check_local_consistency( value_string, hash_value, local_hashes ); } else { stream_write_format( output_file, "#define %s static_hash_string( \"%s\", 0x%llxULL )\n", def_string, value_string, hash_value ); } if( result == HASHIFY_RESULT_OK ) { hashify_string_t hash_string; //Check history result = hashify_check_collisions( value_string, hash_value, *history ); //Add to history string_copy( hash_string.string, value_string, HASHIFY_STRING_LENGTH ); hash_string.hash = hash_value; array_push_memcpy( *history, &hash_string ); array_push_memcpy( local_generated, &hash_string ); } } string_deallocate( def_string ); string_deallocate( value_string ); } if( check_only ) { //Check local consistency result = hashify_check_match( local_hashes, local_generated ); } array_deallocate( local_hashes ); array_deallocate( local_generated ); return result; }
int hashify_process_file(stream_t* input_file, stream_t* output_file, string_t output_filename, bool check_only, hashify_string_t** history) { int result = HASHIFY_RESULT_OK; char line_buffer[HASHIFY_LINEBUFFER_LENGTH]; hashify_string_t* local_hashes = 0; hashify_string_t* local_generated = 0; if (check_only) result = hashify_read_hashes(output_file, &local_hashes); else result = hashify_generate_preamble(output_file, output_filename); memset(line_buffer, 0, sizeof(line_buffer)); while (!stream_eos(input_file) && (result == HASHIFY_RESULT_OK)) { string_t line_string; string_const_t def_string; string_const_t value_string; line_string = stream_read_line_buffer(input_file, line_buffer, sizeof(line_buffer), '\n'); string_split(STRING_ARGS(line_string), STRING_CONST(" \t"), &def_string, &value_string, false); def_string = string_strip(STRING_ARGS(def_string), STRING_CONST(STRING_WHITESPACE)); value_string = string_strip(STRING_ARGS(value_string), STRING_CONST(STRING_WHITESPACE)); if (value_string.length && (value_string.str[0] == '"') && (value_string.str[ value_string.length - 1 ] == '"')) { ++value_string.str; value_string.length -= 2; } if (def_string.length) { hash_t hash_value = hash(STRING_ARGS(value_string)); log_infof(0, STRING_CONST(" %.*s: %.*s -> 0x%" PRIx64), STRING_FORMAT(def_string), STRING_FORMAT(value_string), hash_value); if (check_only) { //Check local consistency result = hashify_check_local_consistency(value_string, hash_value, local_hashes); } else { stream_write_format(output_file, STRING_CONST("#define %.*s static_hash_string(\"%.*s\", %" PRIsize ", 0x%" PRIx64 "ULL)\n"), STRING_FORMAT(def_string), STRING_FORMAT(value_string), value_string.length, hash_value); } if (result == HASHIFY_RESULT_OK) { hashify_string_t hash_string; //Check history result = hashify_check_collisions(value_string, hash_value, *history); //Add to history hash_string.string = string_copy(hash_string.buffer, HASHIFY_STRING_LENGTH, STRING_ARGS(value_string)); hash_string.hash = hash_value; array_push_memcpy(*history, &hash_string); array_push_memcpy(local_generated, &hash_string); } } } if (check_only) { //Check local consistency result = hashify_check_match(local_hashes, local_generated); } array_deallocate(local_hashes); array_deallocate(local_generated); return result; }
void Dictionary::setBool( const std::string& key, bool value ) { m_data[ string_strip(string_toUpper(key)) ] = BoolConvertor::convert( value ); }
static int render_import_shader(stream_t* stream, const uuid_t uuid) { char buffer[1024]; char pathbuf[BUILD_MAX_PATHLEN]; resource_source_t source; resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1}; uint64_t platform; tick_t timestamp; int ret = 0; resource_source_initialize(&source); resource_source_read(&source, uuid); platform = resource_platform(platformdecl); timestamp = time_system(); while (!stream_eos(stream)) { uuid_t shaderuuid; string_const_t target, ref, fullpath; string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n'); string_split(STRING_ARGS(line), STRING_CONST(" \t"), &target, &ref, false); ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE)); shaderuuid = string_to_uuid(STRING_ARGS(ref)); if (uuid_is_null(shaderuuid)) { if (path_is_absolute(STRING_ARGS(ref))) { fullpath = ref; } else { string_t full; string_const_t path = stream_path(stream); path = path_directory_name(STRING_ARGS(path)); full = path_concat(pathbuf, sizeof(pathbuf), STRING_ARGS(path), STRING_ARGS(ref)); full = path_absolute(STRING_ARGS(full), sizeof(pathbuf)); fullpath = string_const(STRING_ARGS(full)); } resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { if (!resource_import(STRING_ARGS(fullpath), uuid_null())) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to import linked shader: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Import linked shader gave no UUID: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } } shaderuuid = sig.uuid; } if (!uuid_is_null(shaderuuid)) { resource_platform_t targetplatformdecl = render_import_parse_target(STRING_ARGS(target), platformdecl); uint64_t targetplatform = resource_platform(targetplatformdecl); if (resource_autoimport_need_update(shaderuuid, targetplatform)) resource_autoimport(shaderuuid); const string_const_t uuidstr = string_from_uuid_static(shaderuuid); resource_source_set(&source, timestamp, HASH_SHADER, targetplatform, STRING_ARGS(uuidstr)); resource_source_set_dependencies(uuid, targetplatform, &shaderuuid, 1); } } resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE, 0, STRING_CONST("shader")); if (!resource_source_write(&source, uuid, false)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported shader: %.*s"), STRING_FORMAT(uuidstr)); ret = -1; goto finalize; } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported shader: %.*s"), STRING_FORMAT(uuidstr)); } finalize: resource_source_finalize(&source); return 0; }
int process_spawn(process_t* proc) { static const string_const_t unescaped = { STRING_CONST("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.:/\\") }; size_t i, num_args; size_t size; #if FOUNDATION_PLATFORM_WINDOWS wchar_t* wcmdline; wchar_t* wwd; string_t cmdline; #endif #if !FOUNDATION_PLATFORM_POSIX size_t capacity; #endif proc->code = PROCESS_INVALID_ARGS; if (!proc->path.length) return proc->code; //Always escape path on Windows platforms #if FOUNDATION_PLATFORM_POSIX if (string_find_first_not_of(STRING_ARGS(proc->path), STRING_ARGS(unescaped), 0) != STRING_NPOS) #endif { bool preesc = (proc->path.str[0] != '"'); bool postesc = (proc->path.str[ proc->path.length - 1 ] != '"'); if (preesc || postesc) { char* buffer = memory_allocate(HASH_STRING, proc->path.length + 4, 0, MEMORY_PERSISTENT); string_t pathesc = string_concat_varg(buffer, proc->path.length + 4, "\"", (size_t)(preesc ? 1 : 0), STRING_ARGS(proc->path), "\"", (size_t)(postesc ? 1 : 0), nullptr); string_deallocate(proc->path.str); proc->path = pathesc; } } size = array_size(proc->args); for (i = 0, num_args = 0; i < size; ++i) { string_t arg = proc->args[i]; if (!arg.length) continue; ++num_args; #if !FOUNDATION_PLATFORM_POSIX if (string_find_first_not_of(arg.str, arg.length, unescaped.str, unescaped.length, 0) != STRING_NPOS) { if (arg.str[0] != '"') { //Check if we need to escape " characters string_t escarg; size_t pos = string_find(arg.str, arg.length, '"', 0); while (pos != STRING_NPOS) { if (arg.str[ pos - 1 ] != '\\') { string_const_t right = string_substr(STRING_ARGS(arg), 0, pos); string_const_t left = string_substr(STRING_ARGS(arg), pos, STRING_NPOS); capacity = arg.length + 2; escarg = string_allocate(0, capacity); escarg = string_concat(escarg.str, capacity, STRING_ARGS(right), STRING_CONST("\\")); escarg = string_append(STRING_ARGS(escarg), capacity, STRING_ARGS(left)); string_deallocate(arg.str); arg = escarg; } pos = string_find(STRING_ARGS(arg), '"', pos + 2); } escarg = string_allocate_concat_varg(STRING_CONST("\""), STRING_ARGS(arg), STRING_CONST("\""), nullptr); string_deallocate(arg.str); proc->args[i] = escarg; } } #endif } #if FOUNDATION_PLATFORM_WINDOWS # ifndef SEE_MASK_NOASYNC # define SEE_MASK_NOASYNC 0x00000100 # endif capacity = BUILD_MAX_PATHLEN; cmdline = string_allocate(0, capacity); //Don't prepend exe path to parameters if using ShellExecute if (!(proc->flags & PROCESS_WINDOWS_USE_SHELLEXECUTE)) cmdline = string_copy(cmdline.str, capacity, STRING_ARGS(proc->path)); //Build command line string for (i = 0; i < size; ++i) { string_t arg = proc->args[i]; if (!arg.length) continue; if (cmdline.length + arg.length + 2 >= capacity) { string_t newline; capacity *= 2; newline = string_allocate(0, capacity); newline = string_copy(newline.str, capacity, STRING_ARGS(cmdline)); } if (cmdline.length) cmdline = string_append(STRING_ARGS(cmdline), capacity, STRING_CONST(" ")); cmdline = string_append(STRING_ARGS(cmdline), capacity, STRING_ARGS(arg)); } if (!proc->wd.length) proc->wd = string_clone(STRING_ARGS(environment_current_working_directory())); wcmdline = wstring_allocate_from_string(STRING_ARGS(cmdline)); wwd = wstring_allocate_from_string(STRING_ARGS(proc->wd)); if (proc->flags & PROCESS_WINDOWS_USE_SHELLEXECUTE) { SHELLEXECUTEINFOW sei; wchar_t* wverb; wchar_t* wpath; wverb = (proc->verb.length ? wstring_allocate_from_string(STRING_ARGS(proc->verb)) : 0); wpath = wstring_allocate_from_string(STRING_ARGS(proc->path)); ZeroMemory(&sei, sizeof(sei)); sei.cbSize = sizeof(SHELLEXECUTEINFOW); sei.hwnd = 0; sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; sei.lpVerb = wverb; sei.lpFile = wpath; sei.lpParameters = wcmdline; sei.lpDirectory = wwd; sei.nShow = SW_SHOWNORMAL; if (!(proc->flags & PROCESS_CONSOLE)) sei.fMask |= SEE_MASK_NO_CONSOLE; if (proc->flags & PROCESS_STDSTREAMS) log_warn(0, WARNING_UNSUPPORTED, STRING_CONST("Unable to redirect standard in/out" " through pipes when using ShellExecute for process spawning")); log_debugf(0, STRING_CONST("Spawn process (ShellExecute): %.*s %.*s"), STRING_FORMAT(proc->path), STRING_FORMAT(cmdline)); if (!ShellExecuteExW(&sei)) { string_const_t errstr = system_error_message(0); log_warnf(0, WARNING_SYSTEM_CALL_FAIL, STRING_CONST("Unable to spawn process (ShellExecute) for executable '%.*s': %s"), STRING_FORMAT(proc->path), STRING_FORMAT(errstr)); } else { proc->hp = sei.hProcess; proc->ht = 0; proc->code = 0; } wstring_deallocate(wverb); wstring_deallocate(wpath); } else { STARTUPINFOW si; PROCESS_INFORMATION pi; BOOL inherit_handles = FALSE; memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); if (proc->flags & PROCESS_STDSTREAMS) { proc->pipeout = pipe_allocate(); proc->pipein = pipe_allocate(); si.dwFlags |= STARTF_USESTDHANDLES; si.hStdOutput = pipe_write_handle(proc->pipeout); si.hStdInput = pipe_read_handle(proc->pipein); si.hStdError = GetStdHandle(STD_ERROR_HANDLE); //Don't inherit wrong ends of pipes SetHandleInformation(pipe_read_handle(proc->pipeout), HANDLE_FLAG_INHERIT, 0); SetHandleInformation(pipe_write_handle(proc->pipein), HANDLE_FLAG_INHERIT, 0); inherit_handles = TRUE; } log_debugf(0, STRING_CONST("Spawn process (CreateProcess): %.*s %.*s"), STRING_FORMAT(proc->path), STRING_FORMAT(cmdline)); if (!CreateProcessW(0, wcmdline, 0, 0, inherit_handles, (proc->flags & PROCESS_CONSOLE) ? CREATE_NEW_CONSOLE : 0, 0, wwd, &si, &pi)) { string_const_t errstr = system_error_message(0); log_warnf(0, WARNING_SYSTEM_CALL_FAIL, STRING_CONST("Unable to spawn process (CreateProcess) for executable '%.*s': %.*s"), STRING_FORMAT(proc->path), STRING_FORMAT(errstr)); stream_deallocate(proc->pipeout); stream_deallocate(proc->pipein); proc->pipeout = 0; proc->pipein = 0; } else { proc->hp = pi.hProcess; proc->ht = pi.hThread; proc->code = 0; } if (proc->pipeout) pipe_close_write(proc->pipeout); if (proc->pipein) pipe_close_read(proc->pipein); } wstring_deallocate(wcmdline); wstring_deallocate(wwd); string_deallocate(cmdline.str); if (proc->code < 0) return proc->code; //Error #endif #if FOUNDATION_PLATFORM_MACOSX if (proc->flags & PROCESS_MACOSX_USE_OPENAPPLICATION) { proc->pid = 0; LSApplicationParameters params; ProcessSerialNumber psn; FSRef* fsref = memory_allocate(0, sizeof(FSRef), 0, MEMORY_TEMPORARY | MEMORY_ZERO_INITIALIZED); memset(¶ms, 0, sizeof(LSApplicationParameters)); memset(&psn, 0, sizeof(ProcessSerialNumber)); string_const_t pathstripped = string_strip(proc->path.str, proc->path.length, STRING_CONST("\"")); size_t localcap = pathstripped.length + 5; string_t localpath = string_allocate(0, localcap - 1); localpath = string_copy(localpath.str, localcap, STRING_ARGS(pathstripped)); //Need it zero terminated OSStatus status = 0; status = FSPathMakeRef((uint8_t*)localpath.str, fsref, 0); if (status < 0) { localpath = string_append(localpath.str, localpath.length, localcap, STRING_CONST(".app")); status = FSPathMakeRef((uint8_t*)localpath.str, fsref, 0); } CFStringRef* args = 0; for (i = 0, size = array_size(proc->args); i < size; ++i) //App gets executable path automatically, don't include array_push(args, CFStringCreateWithCString(0, proc->args[i].str, kCFStringEncodingUTF8)); CFArrayRef argvref = CFArrayCreate(0, (const void**)args, (CFIndex)array_size(args), 0); params.flags = kLSLaunchDefaults; params.application = fsref; params.argv = argvref; log_debugf(0, STRING_CONST("Spawn process (LSOpenApplication): %.*s"), STRING_FORMAT(localpath)); status = LSOpenApplication(¶ms, &psn); if (status != 0) { int err = status; string_const_t errmsg = system_error_message(err); proc->code = status; log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to spawn process for executable '%.*s': %.*s (%d)"), STRING_FORMAT(localpath), STRING_FORMAT(errmsg), err); } CFRelease(argvref); for (i = 0, size = array_size(args); i < size; ++i) CFRelease(args[i]); array_deallocate(args); memory_deallocate(fsref); string_deallocate(localpath.str); if (status == 0) { pid_t pid = 0; GetProcessPID(&psn, &pid); proc->pid = pid; //Always "detached" with LSOpenApplication, not a child process at all //Setup a kqueue to watch when process terminates so we can emulate a wait proc->kq = kqueue(); if (proc->kq < 0) { string_const_t errmsg = system_error_message(proc->kq); log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to create kqueue for process watch: %.*s (%d)"), STRING_FORMAT(errmsg), proc->kq); proc->kq = 0; } else { struct kevent changes; EV_SET(&changes, (pid_t)pid, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, 0); int ret = kevent(proc->kq, &changes, 1, &changes, 1, 0); if (ret != 1) { int err = errno; string_const_t errmsg = system_error_message(err); log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to setup kqueue for process watch, failed to add event to kqueue: %.*s (%d)"), STRING_FORMAT(errmsg), err); close(proc->kq); proc->kq = 0; } } } goto exit; } #endif #if FOUNDATION_PLATFORM_POSIX //Insert executable arg at start and null ptr at end size_t arg; size_t argc = array_size(proc->args) + 1; array_grow(proc->args, 2); for (arg = argc - 1; arg > 0; --arg) proc->args[arg] = proc->args[arg - 1]; proc->args[0] = string_clone(STRING_ARGS(proc->path)); proc->args[argc] = (string_t) { 0, 0 }; char** argv = memory_allocate(0, sizeof(char*) * (argc + 1), 0, MEMORY_PERSISTENT); for (arg = 0; arg < argc; ++arg) argv[arg] = proc->args[arg].str; argv[argc] = 0; if (proc->flags & PROCESS_STDSTREAMS) { proc->pipeout = pipe_allocate(); proc->pipein = pipe_allocate(); } proc->pid = 0; pid_t pid = fork(); if (pid == 0) { //Child if (proc->wd.length) { log_debugf(0, STRING_CONST("Spawned child process, setting working directory to %.*s"), STRING_FORMAT(proc->wd)); environment_set_current_working_directory(STRING_ARGS(proc->wd)); } log_debugf(0, STRING_CONST("Child process executing: %.*s"), STRING_FORMAT(proc->path)); if (proc->flags & PROCESS_STDSTREAMS) { pipe_close_read(proc->pipeout); dup2(pipe_write_handle(proc->pipeout), STDOUT_FILENO); pipe_close_write(proc->pipein); dup2(pipe_read_handle(proc->pipein), STDIN_FILENO); } int code = execv(proc->path.str, (char* const*)argv); //Error int err = errno; string_const_t errmsg = system_error_message(err); log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Child process failed execve() '%.*s': %.*s (%d) (%d)"), STRING_FORMAT(proc->path), STRING_FORMAT(errmsg), err, code); process_exit(PROCESS_EXIT_FAILURE); FOUNDATION_UNUSED(code); } memory_deallocate(argv); if (pid > 0) { log_debugf(0, STRING_CONST("Child process forked, pid %d"), pid); proc->pid = pid; if (proc->pipeout) pipe_close_write(proc->pipeout); if (proc->pipein) pipe_close_read(proc->pipein); /*if (proc->flags & PROCESS_DETACHED) { int cstatus = 0; pid_t err = waitpid(pid, &cstatus, WNOHANG); if (err == 0) { //TODO: Ugly wait to make sure process spawned correctly thread_sleep(500); err = waitpid(pid, &cstatus, WNOHANG); } if (err > 0) { //Process exited, check code proc->pid = 0; proc->code = (int)((char)WEXITSTATUS(cstatus)); log_debugf(0, STRING_CONST("Child process returned: %d"), proc->code); return proc->code; } }*/ } else { //Error string_const_t errmsg; errmsg = system_error_message(proc->code); log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to spawn process '%.*s': %.*s (%d)"), STRING_FORMAT(proc->path), STRING_FORMAT(errmsg), proc->code); if (proc->pipeout) stream_deallocate(proc->pipeout); if (proc->pipein) stream_deallocate(proc->pipein); proc->pipeout = 0; proc->pipein = 0; proc->code = PROCESS_INVALID_ARGS; return proc->code; } #endif #if !FOUNDATION_PLATFORM_WINDOWS && !FOUNDATION_PLATFORM_POSIX FOUNDATION_ASSERT_FAIL("Process spawning not supported on platform"); #endif #if FOUNDATION_PLATFORM_MACOSX exit: #endif if (proc->flags & PROCESS_DETACHED) return PROCESS_STILL_ACTIVE; return process_wait(proc); }
void bservInitMaps() { WIN32_FIND_DATA fData; wstring pattern(getPesInfo()->gdbDir); pattern += L"GDB\\balls\\*"; HANDLE hff = FindFirstFile(pattern.c_str(), &fData); if (hff != INVALID_HANDLE_VALUE) { while(true) { // check if this is a file if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 && wcsicmp(fData.cFileName,L"map.txt")!=0) { ball_t ball; ball._file = fData.cFileName; if (ball._file.size() > 0x2f) { LOG1S1N(L"ERROR: Ball filename too long for {%s}: %d characters. Must be 0-47. Skipping.", ball._file.c_str(), ball._file.size()); } else { _balls.insert(pair<wstring,ball_t>( fData.cFileName, ball )); } } // proceed to next file if (!FindNextFile(hff, &fData)) break; } FindClose(hff); } // read home-ball map hash_map<WORD,wstring> entries; wstring mapFile(getPesInfo()->gdbDir); mapFile += L"GDB\\balls\\map.txt"; if (readMap(mapFile.c_str(), entries)) { for (hash_map<WORD,wstring>::iterator it = entries.begin(); it != entries.end(); it++) { wstring dir(it->second); string_strip(dir); string_strip_quotes(dir); // find this ball in the normal map ball_iter_t sit = _balls.find(dir); if (sit != _balls.end()) _home_balls.insert(pair<WORD,ball_iter_t>( it->first, sit)); else LOG1S(L"ERROR in home-balls map: ball {%s} not found. Skipping.", dir.c_str()); } } LOG1N(L"total balls: %d", _balls.size()); LOG1N(L"home balls assigned: %d", _home_balls.size()); // reset the iterator _ball_iter = _balls.end(); }
DECLARE_TEST( string, utility ) { { char* path1 = string_clone( "" ); char* path2 = string_clone( "/" ); char* path3 = string_clone( "/." ); char* path4 = string_clone( "./" ); char* path5 = string_clone( "./." ); char* path6 = string_clone( "././" ); char* path7 = string_clone( "././//" ); char* path8 = string_clone( "././//./////././////.//////.//." ); char* path9 = string_clone( "http://././//./////././////.//////.//." ); char* path10 = string_clone( "" ); char* path11 = string_clone( "\\" ); char* path12 = string_clone( "/\\." ); char* path13 = string_clone( ".\\/" ); char* path14 = string_clone( "./\\." ); char* path15 = string_clone( ".\\.//\\" ); char* path16 = string_clone( ".\\.\\\\\\" ); char* path17 = string_clone( ".\\.\\\\\\.\\\\////\\///\\\\.\\.\\\\\\\\\\.\\\\\\\\\\\\.\\\\." ); char* path18 = string_clone( "http://\\.\\.\\\\\\.\\\\\\\\//\\.\\.\\\\\\\\//\\.\\\\\\\\\\\\.\\\\." ); char* path19 = string_clone( "testing/path/ext" ); char* path20 = string_clone( "testing/path/extend" ); char* path21 = string_clone( "testing/path/extend/dyn" ); char* path22 = string_clone( "testing/./\\\\/\\/./path/././//./extend/\\\\" ); path1 = path_clean( path1, true ); path2 = path_clean( path2, true ); path3 = path_clean( path3, true ); path4 = path_clean( path4, true ); path5 = path_clean( path5, true ); path6 = path_clean( path6, true ); path7 = path_clean( path7, true ); path8 = path_clean( path8, true ); path9 = path_clean( path9, true ); path10 = path_clean( path10, true ); path11 = path_clean( path11, true ); path12 = path_clean( path12, true ); path13 = path_clean( path13, true ); path14 = path_clean( path14, true ); path15 = path_clean( path15, true ); path16 = path_clean( path16, true ); path17 = path_clean( path17, true ); path18 = path_clean( path18, true ); path19 = path_clean( path19, true ); path20 = path_clean( path20, true ); path21 = path_clean( path21, true ); path22 = path_clean( path22, true ); EXPECT_TRUE( string_equal( path1, "/" ) ); EXPECT_TRUE( string_equal( path2, "/" ) ); EXPECT_TRUE( string_equal( path3, "/" ) ); EXPECT_TRUE( string_equal( path4, "/" ) ); EXPECT_TRUE( string_equal( path5, "/" ) ); EXPECT_TRUE( string_equal( path6, "/" ) ); EXPECT_TRUE( string_equal( path7, "/" ) ); EXPECT_TRUE( string_equal( path8, "/" ) ); EXPECT_TRUE( string_equal( path9, "http://" ) ); EXPECT_TRUE( string_equal( path10, "/" ) ); EXPECT_TRUE( string_equal( path11, "/" ) ); EXPECT_TRUE( string_equal( path12, "/" ) ); EXPECT_TRUE( string_equal( path13, "/" ) ); EXPECT_TRUE( string_equal( path14, "/" ) ); EXPECT_TRUE( string_equal( path15, "/" ) ); EXPECT_TRUE( string_equal( path16, "/" ) ); EXPECT_TRUE( string_equal( path17, "/" ) ); EXPECT_TRUE( string_equal( path18, "http://" ) ); EXPECT_TRUE( string_equal( path19, "/testing/path/ext" ) ); EXPECT_TRUE( string_equal( path20, "/testing/path/extend" ) ); EXPECT_TRUE( string_equal( path21, "/testing/path/extend/dyn" ) ); EXPECT_TRUE( string_equal( path22, "/testing/path/extend" ) ); string_deallocate( path1 ); string_deallocate( path2 ); string_deallocate( path3 ); string_deallocate( path4 ); string_deallocate( path5 ); string_deallocate( path6 ); string_deallocate( path7 ); string_deallocate( path8 ); string_deallocate( path9 ); string_deallocate( path10 ); string_deallocate( path11 ); string_deallocate( path12 ); string_deallocate( path13 ); string_deallocate( path14 ); string_deallocate( path15 ); string_deallocate( path16 ); string_deallocate( path17 ); string_deallocate( path18 ); string_deallocate( path19 ); string_deallocate( path20 ); string_deallocate( path21 ); string_deallocate( path22 ); } { char** explodearr = 0; char* explodestr = string_clone( " .,testing, .,utility.,string methods ..., like,,,finds split..merge .,.explode.and. .., ., similar .,,,. " ); char* mergestr = string_clone( " testing merge string " ); char* mergestr2 = string_clone( " ., testing, .merge.string,. " ); char* merged = 0; char** mergearr, **mergearr2, **mergearr3; char* splitstr = string_clone( " testing split" ); char* splitright = 0, *splitleft = 0; char* splitright2 = 0, *splitleft2 = 0; char* substrtest = string_clone( "testing substr" ); char* substr = 0; explodearr = string_explode( explodestr, " ,.", false ); mergearr = string_explode( mergestr, " .,", true ); mergearr2 = string_explode( mergestr, " .,", false ); mergearr3 = string_explode( mergestr, " .,", true ); merged = string_merge( (const char* const*)mergearr, array_size( mergearr ), " " ); string_split( splitstr, " ", &splitleft, &splitright, false ); string_split( splitstr, " ", &splitleft2, &splitright2, true ); EXPECT_EQ( array_size( explodearr ), 11 ); EXPECT_TRUE( string_equal( explodearr[0], "testing" ) ); EXPECT_TRUE( string_equal( explodearr[1], "utility" ) ); EXPECT_TRUE( string_equal( explodearr[2], "string" ) ); EXPECT_TRUE( string_equal( explodearr[3], "methods" ) ); EXPECT_TRUE( string_equal( explodearr[4], "like" ) ); EXPECT_TRUE( string_equal( explodearr[5], "finds" ) ); EXPECT_TRUE( string_equal( explodearr[6], "split" ) ); EXPECT_TRUE( string_equal( explodearr[7], "merge" ) ); EXPECT_TRUE( string_equal( explodearr[8], "explode" ) ); EXPECT_TRUE( string_equal( explodearr[9], "and" ) ); EXPECT_TRUE( string_equal( explodearr[10], "similar" ) ); EXPECT_EQ( array_size( mergearr ), 12 ); EXPECT_TRUE( string_equal( mergearr[0], "" ) ); EXPECT_TRUE( string_equal( mergearr[1], "" ) ); EXPECT_TRUE( string_equal( mergearr[2], "" ) ); EXPECT_TRUE( string_equal( mergearr[3], "" ) ); EXPECT_TRUE( string_equal( mergearr[4], "testing" ) ); EXPECT_TRUE( string_equal( mergearr[5], "" ) ); EXPECT_TRUE( string_equal( mergearr[6], "" ) ); EXPECT_TRUE( string_equal( mergearr[7], "merge" ) ); EXPECT_TRUE( string_equal( mergearr[8], "string" ) ); EXPECT_TRUE( string_equal( mergearr[9], "" ) ); EXPECT_TRUE( string_equal( mergearr[10], "" ) ); EXPECT_TRUE( string_equal( mergearr[11], "" ) ); EXPECT_EQ( array_size( mergearr2 ), 3 ); EXPECT_TRUE( string_equal( mergearr2[0], "testing" ) ); EXPECT_TRUE( string_equal( mergearr2[1], "merge" ) ); EXPECT_TRUE( string_equal( mergearr2[2], "string" ) ); EXPECT_TRUE( string_equal( merged, mergestr ) ); EXPECT_EQ( array_size( mergearr3 ), 12 ); EXPECT_TRUE( string_equal( mergearr3[0], "" ) ); EXPECT_TRUE( string_equal( mergearr3[1], "" ) ); EXPECT_TRUE( string_equal( mergearr3[2], "" ) ); EXPECT_TRUE( string_equal( mergearr3[3], "" ) ); EXPECT_TRUE( string_equal( mergearr3[4], "testing" ) ); EXPECT_TRUE( string_equal( mergearr3[5], "" ) ); EXPECT_TRUE( string_equal( mergearr3[6], "" ) ); EXPECT_TRUE( string_equal( mergearr3[7], "merge" ) ); EXPECT_TRUE( string_equal( mergearr3[8], "string" ) ); EXPECT_TRUE( string_equal( mergearr3[9], "" ) ); EXPECT_TRUE( string_equal( mergearr3[10], "" ) ); EXPECT_TRUE( string_equal( mergearr3[11], "" ) ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 0, 4 ), "test" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 0, 14 ), "testing substr" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 0, 20 ), "testing substr" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 3, 20 ), "ting substr" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 3, 11 ), "ting substr" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 3, 1 ), "t" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 3, 0 ), "" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 20, 0 ), "" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( substr = string_substr( substrtest, 20, 20 ), "" ) ); string_deallocate( substr ); EXPECT_TRUE( string_equal( splitleft, "testing" ) ); EXPECT_TRUE( string_equal( splitright, "split" ) ); EXPECT_TRUE( string_equal( splitleft2, "" ) ); EXPECT_TRUE( string_equal( splitright2, "testing split" ) ); { char* replacestr = string_clone( "testing replace" ); char* replacestr2 = string_clone( "testing replace" ); char* replacestr3 = string_clone( "testing replacelace" ); char* replacestr4 = string_clone( "" ); char* replacestr5 = string_clone( "repppppppppp" ); replacestr = string_replace( replacestr, "rep", "testrep", false ); replacestr2 = string_replace( replacestr2, "rep", "testrep", true ); replacestr3 = string_replace( replacestr3, "replace", "testrep", true ); replacestr4 = string_replace( replacestr4, "foo", "bar", true ); replacestr5 = string_replace( replacestr5, "rep", "re", true ); EXPECT_TRUE( string_equal( replacestr, "testing testreplace" ) ); EXPECT_TRUE( string_equal( replacestr2, "testing testreplace" ) ); EXPECT_TRUE( string_equal( replacestr3, "testing testtestrep" ) ); EXPECT_TRUE( string_equal( replacestr4, "" ) ); EXPECT_TRUE( string_equal( replacestr5, "re" ) ); string_deallocate( replacestr ); string_deallocate( replacestr2 ); string_deallocate( replacestr3 ); string_deallocate( replacestr4 ); string_deallocate( replacestr5 ); } { char* stripstr = string_clone( " testing strip : " ); char* stripstr2 = string_clone( " testing strip : " ); char* stripstr3 = string_clone( " testing strip : " ); stripstr = string_strip( stripstr, " tp: " ); stripstr2 = string_strip( stripstr2, "" ); stripstr3 = string_strip( stripstr3, " tesingrp:" ); EXPECT_TRUE( string_equal( stripstr, "esting stri" ) ); EXPECT_TRUE( string_equal( stripstr2, " testing strip : " ) ); EXPECT_TRUE( string_equal( stripstr3, "" ) ); string_deallocate( stripstr ); string_deallocate( stripstr2 ); string_deallocate( stripstr3 ); } string_array_deallocate( explodearr ); string_deallocate( explodestr ); string_deallocate( mergestr ); string_deallocate( mergestr2 ); string_deallocate( merged ); string_array_deallocate( mergearr ); string_array_deallocate( mergearr2 ); string_array_deallocate( mergearr3 ); string_deallocate( splitstr ); string_deallocate( splitright ); string_deallocate( splitleft ); string_deallocate( splitright2 ); string_deallocate( splitleft2 ); string_deallocate( substrtest ); } { #define SHORTSTRING "short" #define LONGSTRING "long string with dynamic buffer storage but with no real useful data" char* clonestr = string_clone( "" ); char* clonestr2 = string_clone( SHORTSTRING ); char* clonestr3 = string_clone( LONGSTRING ); char* teststr = string_clone( clonestr ); char* teststr2 = string_clone( clonestr2 ); char* teststr3 = string_clone( clonestr3 ); char* concatstr = string_concat( clonestr, teststr ); char* concatstr2 = string_concat( clonestr, teststr2 ); char* concatstr3 = string_concat( teststr2, clonestr ); char* concatstr4 = string_concat( clonestr2, teststr2 ); char* concatstr5 = string_concat( clonestr, teststr3 ); char* concatstr6 = string_concat( teststr3, clonestr ); char* concatstr7 = string_concat( clonestr2, teststr3 ); char* concatstr8 = string_concat( teststr3, clonestr2 ); char* concatstr9 = string_concat( clonestr3, teststr3 ); char* concatstr10 = string_concat( teststr3, clonestr3 ); EXPECT_NE( teststr, clonestr ); EXPECT_TRUE( string_equal( teststr, clonestr ) ); EXPECT_NE( teststr2, clonestr2 ); EXPECT_TRUE( string_equal( teststr2, clonestr2 ) ); EXPECT_NE( teststr3, clonestr3 ); EXPECT_TRUE( string_equal( teststr3, clonestr3 ) ); EXPECT_TRUE( string_equal( concatstr, "" ) ); EXPECT_TRUE( string_equal( concatstr2, SHORTSTRING ) ); EXPECT_TRUE( string_equal( concatstr3, SHORTSTRING ) ); EXPECT_TRUE( string_equal( concatstr4, SHORTSTRING SHORTSTRING ) ); EXPECT_TRUE( string_equal( concatstr5, LONGSTRING ) ); EXPECT_TRUE( string_equal( concatstr6, LONGSTRING ) ); EXPECT_TRUE( string_equal( concatstr7, SHORTSTRING LONGSTRING ) ); EXPECT_TRUE( string_equal( concatstr8, LONGSTRING SHORTSTRING ) ); EXPECT_TRUE( string_equal( concatstr9, LONGSTRING LONGSTRING ) ); EXPECT_TRUE( string_equal( concatstr10, LONGSTRING LONGSTRING ) ); string_deallocate( teststr ); string_deallocate( clonestr ); string_deallocate( teststr2 ); string_deallocate( clonestr2 ); string_deallocate( teststr3 ); string_deallocate( clonestr3 ); string_deallocate( concatstr ); string_deallocate( concatstr2 ); string_deallocate( concatstr3 ); string_deallocate( concatstr4 ); string_deallocate( concatstr5 ); string_deallocate( concatstr6 ); string_deallocate( concatstr7 ); string_deallocate( concatstr8 ); string_deallocate( concatstr9 ); string_deallocate( concatstr10 ); #undef SHORTSTRING #undef LONGSTRING } return 0; }