int main (int argc, char *argv[]) { int opt = 0; char* str = NULL; char* find = NULL; char* replace = NULL; char* new_str = NULL; while ((opt = getopt(argc, argv, "s:f:r:")) != -1) { switch(opt) { case 's': str = duplicate_string(optarg); break; case 'f': find = duplicate_string(optarg); break; case 'r': replace = duplicate_string(optarg); break; case '?': printf("invalid charachter\n"); break; } } new_str = replace_str(str, find, replace); printf("====== new_str=%s ======\n", new_str); // Free memory free(str); free(find); free(replace); }
void get_options (int argc, char **argv, gs_table *t) { extern char *optarg; int optch; while ((optch = getopt (argc, argv, "c:hn:p:s:")) != -1) { switch (optch) { case 'c': free ((*t) -> channelname); (*t) -> channelname = duplicate_string (optarg); break; case 'n': free ((*t) -> botname); (*t) -> botname = duplicate_string (optarg); break; case 'p': (*t) -> serverport = (unsigned short) atoi (optarg); break; case 's': free ((*t) -> servername); (*t) -> servername = duplicate_string (optarg); break; case 'h': case '?': default: usage (argv [0]); } } }
/* * object_to_string() - convert object to string * return: formatted string * object(in): object value to convert * format(in): conversion format type */ static char * object_to_string (DB_OBJECT * object, int format) { if (object == NULL) return NULL; if (format == OBJECT_FORMAT_OID) { char temp_string[OBJECT_SYMBOL_MAX]; if (!db_print_mop (object, temp_string, OBJECT_SYMBOL_MAX)) { return (NULL); } return (duplicate_string (temp_string)); } else { char *name; name = (char *) db_get_class_name (object); if (name == NULL) { return (NULL); } else { return (duplicate_string (name)); } } }
SV * Widget_hint( Handle self, Bool set, SV *hint) { enter_method; if ( set) { if ( var-> stage > csFrozen) return nilSV; my-> first_that( self, (void*)hint_notify, (void*)hint); free( var-> hint); var-> hint = duplicate_string( SvPV_nolen( hint)); opt_assign( optUTF8_hint, prima_is_utf8_sv(hint)); if ( application && (( PApplication) application)-> hintVisible && (( PApplication) application)-> hintUnder == self) { SV * hintText = my-> get_hint( self); Handle hintWidget = (( PApplication) application)-> hintWidget; if ( strlen( var-> hint) == 0) my-> set_hintVisible( self, 0); if ( hintWidget) CWidget(hintWidget)-> set_text( hintWidget, hintText); sv_free( hintText); } opt_clear( optOwnerHint); } else { hint = newSVpv( var-> hint ? var-> hint : "", 0); if ( is_opt( optUTF8_hint)) SvUTF8_on( hint); return hint; } return nilSV; }
/* * numeric_to_string() - convert numeric value to string * return: formatted string * value(in): numeric value to convert * commas(in): whether or not to display commas */ static char * numeric_to_string (DB_VALUE * value, bool commas) { char str_buf[NUMERIC_MAX_STRING_SIZE]; char *return_string; int prec; int comma_length; int max_length; /* * Allocate string length based on precision plus the commas plus a * character for each of the sign, decimal point, and NULL terminator. */ prec = DB_VALUE_PRECISION (value); comma_length = COMMAS_OFFSET (commas, prec); max_length = prec + comma_length + 3; return_string = (char *) malloc (max_length); if (return_string == NULL) { return (NULL); } numeric_db_value_print (value, str_buf); if (strlen (str_buf) > max_length - 1) { free_and_init (return_string); return (duplicate_string ("NUM OVERFLOW")); } strcpy (return_string, str_buf); return return_string; }
NValue n_symbol_pool_get_symbol(const char* contents, NError* error) { n_error_clear(error); if (contents != NULL) { int32_t index = _find_symbol(contents); if (index < 0) { const char* dup_contents = duplicate_string(contents); if (dup_contents == NULL) { n_error_set(error, N_E_BAD_ALLOCATION); n_error_set_msg(error, "contents"); return N_UNDEFINED; } index = n_symbol_array_append(&_pool, dup_contents); if (index < 0) { n_error_set(error, N_E_BAD_ALLOCATION); n_error_set_msg(error, "inner-pool"); return N_UNDEFINED; } } return n_wrap_symbol(index); } else { n_error_set(error, N_E_INVALID_ARGUMENT); n_error_set_msg(error, "contents"); return N_UNDEFINED; } }
bool Frame::archive( const char* directory, char** output_path) const { assert(directory); // Construct the name of the image file. const string filename = "autosave." + get_time_stamp_string() + ".exr"; // Construct the path to the image file. const string file_path = (filesystem::path(directory) / filename).string(); // Return the path to the image file. if (output_path) *output_path = duplicate_string(file_path.c_str()); Image transformed_image(*impl->m_image); transform_to_output_color_space(transformed_image); return write_image( file_path.c_str(), transformed_image, ImageAttributes::create_default_attributes()); }
/* * string_to_string() - Copy the string and return it * return: formatted string * string_value(in): source string to duplicate * string_delimiter(in): delimiter to surround string with (0 if none) * string_introducer(in): introducer for the string (0 if none) * length(in): length of the source string * result_length(out): : length of output string * plain_string(in): refine string for plain output */ static char * string_to_string (const char *string_value, char string_delimiter, char string_introducer, int length, int *result_length, bool plain_string) { char *return_string; char *ptr; char *con_buf_ptr = NULL; int con_buf_size = 0; if (plain_string == true) { return csql_string_to_plain_string (string_value, length, result_length); } if (string_delimiter == '\0') { return (duplicate_string (string_value)); } if (string_value == NULL) { return NULL; } if ((return_string = (char *) malloc (length + 4)) == NULL) { return (NULL); } ptr = return_string; if (string_introducer) { *ptr++ = string_introducer; } *ptr++ = string_delimiter; memcpy (ptr, string_value, length); ptr[length] = string_delimiter; ptr = ptr + length + 1; *ptr = 0; if (csql_text_utf8_to_console != NULL && (*csql_text_utf8_to_console) (return_string, strlen (return_string), &con_buf_ptr, &con_buf_size) == NO_ERROR) { if (con_buf_ptr != NULL) { free (return_string); return_string = con_buf_ptr; ptr = con_buf_ptr + con_buf_size; } } if (result_length) { *result_length = CAST_STRLEN (ptr - return_string); } return return_string; }
void xml_get_string(struct xml_application * xptr, char ** target ) { char * sptr; if ((sptr = *target) != (char *) 0) liberate( sptr ); sptr = duplicate_string( xptr->buffer ); *target = sptr; return; }
/* LOAD CONTENTS OF DIRECTORY */ DIR *opendir_filter( char *dir_name, char *filter ) { long i, bp, bc; long nalloc = 100; char *list_name; char command[200], file_name[200]; FILE *fd; DIR *pd = NULL; if ( YES != opendir_exists( dir_name ) ) {aside( "Unable to find directory file %s", dir_name ); return( NULL ); } list_name = opendir_unique_fname(); sprintf( command, "dir/nohead/notrail/out=%s %s%s%s", list_name, dir_name, filter, ( YES == opendir_generic ) ? ";" : " " ); aside( "COM=%s", command ); system( command ); if ( NULL == ( fd = fopen( list_name, "r" ) ) ) {aside( "Unable to get listing for directory \"%s\"" ); return( NULL ); } pd = (DIR *) xmalloc( sizeof(DIR) ); pd->nfiles = pd->nret = 0; pd->d = (DIRENT *) xmalloc( ( nalloc + 2 ) * sizeof(DIRENT) ); while ( EOF != read_line( fd, file_name, 200 ) ) {bp = 0; while ( file_name[bp] != ']' && file_name[bp] != EOS ) {bp++; } if ( EOS == file_name[bp] || EOS == file_name[bp+1]) {aside( "bad file name \"%s\"", file_name ); return( NULL ); /* VMS SYNTAX VIOLATED */ } if ( YES == opendir_generic ) /* REMOVE VERSION NUMBER */ {bc = bp + 1; while ( SEMICOLON != file_name[bc] && EOS != file_name[bc] ) {bc++; } file_name[bc] = EOS; } pd->d[ pd->nfiles ].d_name = duplicate_string( file_name+bp+1 ); if ( ++(pd->nfiles) >= nalloc ) {nalloc += 100; pd->d = (DIRENT *) xrealloc( pd->d, ( nalloc + 2 ) * sizeof(DIRENT) ); } } fclose( fd ); return( pd ); }
SV * Widget_text( Handle self, Bool set, SV *text) { if ( set) { if ( var-> stage > csFrozen) return nilSV; free( var-> text); var-> text = duplicate_string( SvPV_nolen( text)); opt_assign( optUTF8_text, prima_is_utf8_sv(text)); } else { text = newSVpv( var-> text ? var-> text : "", 0); if ( is_opt( optUTF8_text)) SvUTF8_on( text); return text; } return nilSV; }
static struct xml_parser * xml_open( char * nptr, void * payload ) { struct xml_application * xptr; struct xml_parser * sptr; FILE * h; if (!( h = fopen(nptr,"r"))) return((struct xml_parser*) 0); else if (!( sptr = allocate( sizeof( struct xml_parser ) ) )) { fclose(h); return( sptr); } else { sptr->handle = h; sptr->lines = 0; sptr->length = 0; sptr->column = 0; sptr->ungotch = 0; sptr->punctuation = 0; sptr->state = _TAG_IDLE; sptr->nesting = 0; sptr->echo = xml_echo_state; sptr->name = (char *) 0; sptr->work = (struct xml_application *) 0; sptr->user = (struct xml_relay *) 0; if (!( sptr->work = allocate( sizeof ( struct xml_application ) ) )) return( xml_close( sptr ) ); else { xml_reset(sptr->work,xml_echo_state, payload); if (!( sptr->name = duplicate_string( nptr ) )) return( xml_close( sptr ) ); else if (!(sptr->user = allocate( sizeof( struct xml_relay ) ))) return( xml_close( sptr ) ); else { sptr->user->open_tag = xml_open_tag; sptr->user->atb_name = xml_atb_name; sptr->user->atb_value = xml_atb_value; sptr->user->white_space = xml_white_space; sptr->user->token = xml_data_token; sptr->user->punctuation = xml_data_punctuation; sptr->user->close_tag = xml_close_tag; sptr->user->failure = xml_failure; return( sptr ); } } } }
/* * time_as_string() - convert time value to string * return: formatted string * time_value(in): time value to convert * conversion(in): conversion format string */ static char * time_as_string (DB_TIME * time_value, const char *conversion) { char temp_string[TIME_STRING_MAX]; if (time_value == NULL) { return NULL; } if (!db_strftime (temp_string, (int) TIME_STRING_MAX, conversion, (DB_DATE *) NULL, time_value)) { return (NULL); } return (duplicate_string (temp_string)); }
struct Context *Cmiss_context_create(const char *id) { struct Context *context = NULL; if (ALLOCATE(context, struct Context, 1)) { context->graphics_module = NULL; context->root_region = NULL; context->id = duplicate_string(id); //-- context->UI_module = NULL; context->any_object_selection = NULL; context->element_point_ranges_selection = NULL; context->scene_viewer_package = NULL; //-- context->event_dispatcher = NULL; context->io_stream_package = NULL; context->curve_manager = NULL; context->access_count = 1; } return context; }
void xml_get_filename_string(struct xml_application * xptr, char ** target ) { int i; char * sptr; if ((sptr = *target) != (char *) 0) liberate( sptr ); sptr = duplicate_string( xptr->buffer ); #ifdef WIN32 for (i=0; *(sptr+i) != 0; i++ ) if ( *(sptr+i) == '/' ) *(sptr+i) = '\\'; #else for (i=0; *(sptr+i) != 0; i++ ) if ( *(sptr+i) == '\\' ) *(sptr+i) = '/'; #endif *target = sptr; return; }
void * Clipboard_register_format_proc( Handle self, char * format, void * serverProc) { PClipboardFormatReg list = first_that( self, (void*)find_format, format); if ( list) { my-> deregister_format( self, format); } if (!( list = allocn( ClipboardFormatReg, formatCount + 1))) return nil; if ( formats != nil) { memcpy( list, formats, sizeof( ClipboardFormatReg) * formatCount); free( formats); } formats = list; list += formatCount++; list-> id = duplicate_string( format); list-> server = ( ClipboardExchangeFunc *) serverProc; list-> sysId = ( Handle) list-> server( self, list, cefInit, nilSV); return list; }
void AbstractMenu_set_variable( Handle self, char * varName, SV * newName) { PMenuItemReg m; if ( var-> stage > csFrozen) return; m = find_menuitem( self, varName, true); if ( m == nil) return; free( m-> variable); if ( SvTYPE(newName) != SVt_NULL) { STRLEN len; char * v; v = SvPV( newName, len); if ( len > 0) { m-> variable = duplicate_string( v); m-> flags. utf8_variable = prima_is_utf8_sv( newName); return; } } m-> variable = nil; m-> flags. utf8_variable = 0; }
SV * AbstractMenu_text( Handle self, Bool set, char * varName, SV * text) { PMenuItemReg m; if ( var-> stage > csFrozen) return nilSV; m = find_menuitem( self, varName, true); if ( m == nil) return nilSV; if ( m-> text == nil) return nilSV; if ( !set) { SV * sv = newSVpv( m-> text ? m-> text : "", 0); if ( m-> flags. utf8_text) SvUTF8_on( sv); return sv; } free( m-> text); m-> text = nil; m-> text = duplicate_string( SvPV_nolen( text)); m-> flags. utf8_accel = prima_is_utf8_sv( text); if ( m-> id > 0) if ( var-> stage <= csNormal && var-> system) apc_menu_item_set_text( self, m); return nilSV; }
SV * AbstractMenu_action( Handle self, Bool set, char * varName, SV * action) { PMenuItemReg m; if ( var-> stage > csFrozen) return nilSV; m = find_menuitem( self, varName, true); if ( !m) return nilSV; if ( !set) { if ( m-> code) return newSVsv( m-> code); if ( m-> perlSub) { SV * sv = newSVpv( m-> perlSub, 0); if ( m-> flags. utf8_perlSub) SvUTF8_on( sv); return sv; } return nilSV; } if ( m-> flags. divider || m-> down) return nilSV; if ( SvROK( action)) { if ( m-> code) sv_free( m-> code); m-> code = nil; if ( SvTYPE( SvRV( action)) == SVt_PVCV) { m-> code = newSVsv( action); free( m-> perlSub); m-> perlSub = nil; } m-> flags. utf8_perlSub = 0; } else { char * line = ( char *) SvPV_nolen( action); free( m-> perlSub); if ( m-> code) sv_free( m-> code); m-> code = nil; m-> perlSub = duplicate_string( line); m-> flags. utf8_perlSub = prima_is_utf8_sv( action); } return nilSV; }
/** Generator function for command completion. STATE lets us know whether * to start from scratch; without any state (i.e. STATE == 0), then we * start at the top of the list. */ static char* command_generator(const char* text, int state) { static int list_index, len; const char *name; // If this is a new word to complete, initialize now. This includes // saving the length of TEXT for efficiency, and initializing the index // variable to 0. if (!state) { list_index = 0; len = strlen(text); } // Return the next name which partially matches from the command list. while ( (name = Command::CmdToken(list_index)) != 0 ) { list_index++; if (strncmp(name, text, len) == 0) return (duplicate_string(name)); } // If no names matched, then return NULL. return 0; }
static inlineobj_t* parse_object(parser_t* p) { inlineobj_t* obj = (inlineobj_t*)malloc(sizeof(inlineobj_t)); obj->keys = create_list(); obj->values = create_list(); match(p, TT_OP_COPEN); token_type_t tok = get_token(p->t); while (tok == TT_STRING) { list_insert(obj->keys, duplicate_string((char*)(p->t->token_value))); match(p, TT_OP_COLON); list_insert(obj->values, parse_expression(p)); tok = get_token(p->t); if (tok != TT_OP_COMMA) { expect(p, TT_OP_CCLOSE); break; } tok = get_token(p->t); } return obj; }
void xml_get_text(struct xml_application * xptr, char ** rptr ) { char * sptr; int s; int t; int m; sptr=xptr->buffer; s=0; t=0; while ( *(sptr+s) != 0 ) { if ( *(sptr+s) != '&' ) { *(sptr+t) = *(sptr+s); s++; t++; } else { for ( m=0; m < MAX_MNEMONIC; m++ ) { if ( xml_mnemonic( (sptr+s+1) , Mnemonix[m] ) ) { s += (strlen( Mnemonix[m] ) + 2); *(sptr+t) = Mnemonich[m]; t++; break; } } if ( m < MAX_MNEMONIC ) continue; else { *(sptr+t) = *(sptr+s); s++; t++; continue; } } } *(sptr+t) = 0; sptr = duplicate_string( xptr->buffer ); *rptr = sptr; return; }
Bool apc_prn_get_option( Handle self, char * option, char ** value) { long v; char * c = nil, buf[256]; LPDEVMODE dev = sys s. prn. ppi. pDevMode; *value = nil; objCheck false; if ( !dev) return false; v = ctx_prn_find_value( ctx_options, sizeof(ctx_options)/sizeof(PrnKey), option); if ( v == BADVAL) return false; #define LOOKUP_STR(table,value) \ /* is a defined string? */ \ if (( c = ctx_prn_find_string( \ table, sizeof(table)/sizeof(PrnKey), value) \ ) == nil) { \ /* return just a number */ \ sprintf( c = buf, "%d", value); \ } switch ( v) { case DM_ORIENTATION: LOOKUP_STR( ctx_orientation, dev-> dmOrientation); break; case DM_PAPERSIZE: LOOKUP_STR( ctx_papersize, dev-> dmPaperSize); break; case DM_PAPERLENGTH: sprintf( c = buf, "%d", dev-> dmPaperLength); break; case DM_PAPERWIDTH: sprintf( c = buf, "%d", dev-> dmPaperWidth); break; case DM_SCALE: sprintf( c = buf, "%d", dev-> dmScale); break; case DM_COPIES: sprintf( c = buf, "%d", dev-> dmCopies); break; case DM_DEFAULTSOURCE: LOOKUP_STR( ctx_defsource, dev-> dmDefaultSource); break; case DM_PRINTQUALITY: LOOKUP_STR( ctx_quality, dev-> dmPrintQuality); break; case DM_COLOR: LOOKUP_STR( ctx_color, dev-> dmColor); break; case DM_DUPLEX: LOOKUP_STR( ctx_duplex, dev-> dmDuplex); break; case DM_TTOPTION: LOOKUP_STR( ctx_ttoption, dev-> dmTTOption); break; case DM_YRESOLUTION: sprintf( c = buf, "%d", dev-> dmYResolution); break; case DM_COLLATE: sprintf( c = buf, "%d", dev-> dmCollate); break; case DM_FORMNAME: strncpy( c = buf, dev-> dmFormName, CCHFORMNAME); break; default: return false; } if ( c) *value = duplicate_string( c); return true; }
/* Global functions ---------------- */ #if defined (WX_USER_INTERFACE) bool wxCmguiApp::OnInit() { return (true); } wxAppTraits * wxCmguiApp::CreateTraits() { return new wxGUIAppTraits; } void wxCmguiApp::OnIdle(wxIdleEvent& event) { if (event_dispatcher) { if (Event_dispatcher_process_idle_event(event_dispatcher)) { event.RequestMore(); } } } void wxCmguiApp::SetEventDispatcher(Event_dispatcher *event_dispatcher_in) { event_dispatcher = event_dispatcher_in; } BEGIN_EVENT_TABLE(wxCmguiApp, wxApp) EVT_IDLE(wxCmguiApp::OnIdle) END_EVENT_TABLE() IMPLEMENT_APP_NO_MAIN(wxCmguiApp) #endif /*defined (WX_USER_INTERFACE)*/ #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) int main(int argc,const char *argv[]) #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ int WINAPI WinMain(HINSTANCE current_instance,HINSTANCE previous_instance, LPSTR command_line,int initial_main_window_state) /* using WinMain as the entry point tells Windows that it is a gui and to use the graphics device interface functions for I/O */ /*???DB. WINDOWS a zero return code if WinMain does get into the message loop. Other application interfaces may expect something else. Should this failure code be #define'd ? */ /*???DB. Win32 SDK says that don't have to call it WinMain */ #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /******************************************************************************* LAST MODIFIED : 7 January 2003 DESCRIPTION : Main program for the CMISS Graphical User Interface ==============================================================================*/ { int return_code = 0; #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) int argc = 1, i; const char **argv; char *p, *q; #endif /* defined (WIN32_USER_INTERFACE) */ struct Cmiss_context_app *context = NULL; struct User_interface_module *UI_module = NULL; struct Cmiss_command_data *command_data; #if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER) ENTER(main); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ ENTER(WinMain); //_CrtSetBreakAlloc(28336); for (p = command_line; p != NULL && *p != 0;) { p = strchr(p, ' '); if (p != NULL) p++; argc++; } argv = (const char **)malloc(sizeof(*argv) * argc); argv[0] = "cmgui"; for (i = 1, p = command_line; p != NULL && *p != 0;) { q = strchr(p, ' '); if (q != NULL) *q++ = 0; if (p != NULL) argv[i++] = p; p = q; } #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ /* display the version */ display_message(INFORMATION_MESSAGE, "%s version %s\n%s\n" "Build information: %s %s\n", CMISS_NAME_STRING, CMISS_VERSION_STRING, CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); #if defined (CARBON_USER_INTERFACE) || (defined (WX_USER_INTERFACE) && defined (DARWIN)) ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN,kProcessTransformToForegroundApplication); #endif context = Cmiss_context_app_create("default"); #if defined (WX_USER_INTERFACE) int wx_entry_started = 0; #endif if (context) { #if defined (WX_USER_INTERFACE) || (!defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)) UI_module = Cmiss_context_create_user_interface(context, argc, argv, NULL); #else /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ UI_module = Cmiss_context_create_user_interface(context, argc, argv, current_instance, previous_instance, command_line, initial_main_window_state, NULL); #endif /* !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)*/ if (UI_module) { #if defined (WX_USER_INTERFACE) if (UI_module->user_interface) { char **temp_argv = NULL, **cleanup_argv = NULL; int temp_argc = argc, cleanup_argc = argc; if (cleanup_argc > 0) { ALLOCATE(temp_argv, char *, cleanup_argc); ALLOCATE(cleanup_argv, char *, cleanup_argc); for (int i = 0; i < cleanup_argc; i++) { cleanup_argv[i] = temp_argv[i] = duplicate_string(argv[i]); } } if (wxEntryStart(temp_argc, temp_argv)) { wx_entry_started = 1; wxXmlResource::Get()->InitAllHandlers(); wxCmguiApp &app = wxGetApp(); if (&app) { app.SetEventDispatcher(UI_module->event_dispatcher); } else { display_message(ERROR_MESSAGE, "initialiseWxApp. wxCmguiApp not initialised."); } } else { display_message(ERROR_MESSAGE, "initialiseWxApp. Invalid arguments."); } if (cleanup_argv) { for (int i = 0; i < cleanup_argc; i++) { DEALLOCATE(cleanup_argv[i]); } DEALLOCATE(temp_argv); DEALLOCATE(cleanup_argv); } } #endif Cmiss_graphics_module_id graphics_module = NULL; if (NULL != (graphics_module = Cmiss_context_get_default_graphics_module(Cmiss_context_app_get_core_context(context)))) { Cmiss_graphics_module_define_standard_materials(graphics_module); Cmiss_graphics_module_destroy(&graphics_module); } if (NULL != (command_data = Cmiss_context_get_default_command_interpreter(context))) { Cmiss_command_data_set_cmgui_string(command_data, CMISS_NAME_STRING, CMISS_VERSION_STRING, "CMISS_DATE_STRING", CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING, CMISS_SVN_REVISION_STRING); Cmiss_command_data_main_loop(command_data); Cmiss_command_data_destroy(&command_data); return_code = 0; } else { return_code = 1; } User_interface_module_destroy(&UI_module); } else { return_code = 1; } Cmiss_context_app_destroy(&context); Context_internal_cleanup(); #if defined (WX_USER_INTERFACE) if (wx_entry_started) wxEntryCleanup(); #endif /* FieldML does not cleanup the global varaibles xmlParser, xmlSchematypes and * xmlCatalog at this moment, so we clean it up here instead*/ xmlCatalogCleanup(); xmlSchemaCleanupTypes(); xmlCleanupParser(); } else { return_code = 1; } #if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER) free(argv) #endif LEAVE; return (return_code); } /* main */
/** Function called when an event occured (buttons, led status, ...) @param status_str Event type */ void StatusEventCallback(char *status_str) { char *status = NULL; char *type = NULL; char *value = NULL; char *pch = NULL; pch = strtok (status_str,":"); status = duplicate_string(pch); pch = strtok (NULL, ":"); type = duplicate_string(pch); pch = strtok (NULL, ":"); value = duplicate_string(pch); if(!strcmp(status,"head_button")) { if(!strcmp(value,"True")) { TuxLogger_Debug("Head's button pressed",NULL); if(OnTuxHeadButtonPressed != NULL) OnTuxHeadButtonPressed(); } else if(!strcmp(value,"False")) { TuxLogger_Debug("Head's button released",NULL); if(OnTuxHeadButtonReleased != NULL) OnTuxHeadButtonReleased(); } } if(!strcmp(status,"left_wing_button")) { if(!strcmp(value,"True")) { TuxLogger_Debug("Left wing pressed",NULL); if(OnTuxLeftButtonPressed != NULL) OnTuxLeftButtonPressed(); } else if(!strcmp(value,"False")) { TuxLogger_Debug("Left wing released",NULL); if(OnTuxLeftButtonReleased != NULL) OnTuxLeftButtonReleased(); } } if(!strcmp(status,"right_wing_button")) { if(!strcmp(value,"True")) { TuxLogger_Debug("Right wing pressed",NULL); if(OnTuxRightButtonPressed != NULL) OnTuxRightButtonPressed(); } else if(!strcmp(value,"False")) { TuxLogger_Debug("Right wing released",NULL); if(OnTuxRightButtonReleased != NULL) OnTuxRightButtonReleased(); } } if(!strcmp(status,"remote_button")) { char button[30]; TuxDrv_GetStatusValue(SW_ID_REMOTE_BUTTON, button); TuxLogger_Debug("Remote's button pressed: %s",button); if(!strcmp(button,"RELEASE")) { if(OnTuxRemoteButtonReleased != NULL) OnTuxRemoteButtonReleased(NULL); } else { if(OnTuxRemoteButtonPressed != NULL) OnTuxRemoteButtonPressed(NULL, button); } } if(!strcmp(status,"charger_state")) { char state[30]; TuxDrv_GetStatusValue(SW_ID_CHARGER_STATE, state); TuxLogger_Debug("Charger state (Etat: %s)",state); if(!strcmp(state,"CHARGING")) { if(OnTuxChargerPlugged != NULL) OnTuxChargerPlugged(); } else { if(OnTuxChargerUnPlugged != NULL) OnTuxChargerUnPlugged(); } } free(status); status = NULL; free(value); value = NULL; free(type); type = NULL; }
char *StringFieldValueCache::getAsString() { return duplicate_string(stringValue); }
/** Start server */ void *startServer(void *data) { TuxLogger_Debug( "Initializing TuxDroidInterface..",NULL); if (!InitializeTuxDroid()) /* Initializing TuxDroidInterface */ { TuxLogger_Info( "Can't initialize TuxDroid :(",NULL); tprintf("\n\n%s\n", TuxLang_getTranslation("START_INIT_ERROR_L1")); tprintf("%s\n", TuxLang_getTranslation("START_INIT_ERROR_L2")); tprintf("%s\n\n", TuxLang_getTranslation("START_INIT_ERROR_L3")); tprintf("%s", TuxLang_getTranslation("START_INIT_ERROR_L4")); while (1) { } } #ifdef _WIN32 Sleep(2000); #else TuxSleep(2000); #endif TuxLogger_Debug( "Starting server...",NULL); TuxLogger_Debug( "Initializing sockets..",NULL); /* Initializing TCP server */ #ifdef _WIN32 WSADATA WSAData; WSAStartup(MAKEWORD(2,0), &WSAData); #endif int sock; int csock=-1; struct sockaddr_in sin; struct sockaddr_in csin; sock = socket(AF_INET, SOCK_STREAM, 0); sin.sin_addr.s_addr = INADDR_ANY; sin.sin_family = AF_INET; sin.sin_port = htons((u_short) config->SERVER_PORT); bind(sock, (struct sockaddr *) &sin, sizeof(sin)); listen(sock, 0); socklen_t sinsize = sizeof(csin); TuxLogger_Debug( "Socket initialization done",NULL); isRunning = 1; server_started = true; pthread_t SocketThreads; pthread_attr_t SocketThreads_attr; tprintf("\n%s\n", TuxLang_getTranslation("SERVER_STARTED")); if(!config->ASR_ENABLED) { tprintf("\n%s\n",TuxLang_getTranslation("ASR_DISABLED")); } printf("\nTuxDroidServer> "); /* Waiting for connections */ while (isRunning) { if ((csock = accept(sock, (struct sockaddr *) &csin, &sinsize))) { clients = (tux_client*) realloc(clients, sizeof(tux_client) * (nClients + 1)); TuxLogger_Debug( "New incoming connection accepted",NULL); TuxLogger_Debug( "IP Client: %s", inet_ntoa(csin.sin_addr)); TuxLogger_Debug( "Creating new client -> %d..", nClients); clients[nClients] = (tux_client) malloc(sizeof(tux_client_t)); /* allocating memory */ TuxLogger_Debug("New client created",NULL); clients[nClients]->id = nClients; clients[nClients]->sock = csock; clients[nClients]->uKey = duplicate_string("0"); clients[nClients]->pID = NULL; clients[nClients]->username = duplicate_string("0"); TuxLogger_Debug("Starting new thread..",NULL); pthread_attr_init(&SocketThreads_attr); pthread_attr_setdetachstate(&SocketThreads_attr, PTHREAD_CREATE_DETACHED); pthread_create(&SocketThreads, &SocketThreads_attr, ReadClient, clients[nClients]); TuxLogger_Debug("New thread started for client %d", nClients); nClients++; } } /* If we fall here, that's because server has been shutdown, close all connections */ if (csock) { TuxLogger_Debug( "Closing temporary socket",NULL); close(csock); } if (sock) { TuxLogger_Debug( "Closing server socket",NULL); close(sock); } #ifdef _WIN32 WSACleanup(); #endif return 0; }
Bool window_subsystem_set_option( char * option, char * value) { Mdebug("%s=%s\n", option, value); if ( strcmp( option, "no-x11") == 0) { if ( value) warn("`--no-x11' option has no parameters"); do_x11 = false; return true; } else if ( strcmp( option, "yes-x11") == 0) { do_x11 = true; return true; } else if ( strcmp( option, "display") == 0) { free( do_display); do_display = duplicate_string( value); return true; } else if ( strcmp( option, "icccm") == 0) { if ( value) warn("`--icccm' option has no parameters"); do_icccm_only = true; return true; } else if ( strcmp( option, "no-shmem") == 0) { if ( value) warn("`--no-shmem' option has no parameters"); do_no_shmem = true; return true; } else if ( strcmp( option, "debug") == 0) { if ( !value) { warn("`--debug' must be given parameters. `--debug=A` assumed\n"); guts. debug |= DEBUG_ALL; do_debug = guts. debug; return true; } while ( *value) switch ( tolower(*(value++))) { case '0': guts. debug = 0; break; case 'c': guts. debug |= DEBUG_CLIP; break; case 'e': guts. debug |= DEBUG_EVENT; break; case 'f': guts. debug |= DEBUG_FONTS; break; case 'm': guts. debug |= DEBUG_MISC; break; case 'p': guts. debug |= DEBUG_COLOR; break; case 'x': guts. debug |= DEBUG_XRDB; break; case 'a': guts. debug |= DEBUG_ALL; break; } do_debug = guts. debug; } else if ( prima_font_subsystem_set_option( option, value)) { return true; } else if ( prima_color_subsystem_set_option( option, value)) { return true; } return false; }
symbol_data const & find(const char * str, size_t strlen) { mutex.lock_shared(); lookup_result_type lookup_result = symbol_lookup(str); mutex.unlock_shared(); if (lookup_result.second) return *lookup_result.first; boost::unique_lock<nova::nonrecursive_rw_mutex> lock(mutex); lookup_result = symbol_lookup(str); if (lookup_result.second) return *lookup_result.first; std::pair<table_type::iterator, bool> inserted = table.insert(symbol_data(duplicate_string(str, strlen))); assert(inserted.second); return *inserted.first; }
void StringFieldValueCache::setString(const char *string_in) { if (stringValue) DEALLOCATE(stringValue); stringValue = duplicate_string(string_in); }