// Logging of char arrays void log_print(char* _info, char* _in) { if (txtLog == NULL) return; // Move lines on step down int i; for (i=LOG_LINES-1; i > 0; i--) { str_cpy((txtLog.pstring)[i], (txtLog.pstring)[i-1]); } char cbuffer[128]; sprintf(cbuffer, "%d: %s %s", total_frames, _info, _in); str_cpy((txtLog.pstring)[0], cbuffer); // Print to file? if (nLogToFile == 1) { vLogFileHandle = file_open_append(strLogFile); char cbuffer2[10]; // Change color to hex for HTML coding log_rgb_to_hex(cbuffer2,(long)cLogColor.red,(long)cLogColor.green,(long)cLogColor.blue); sprintf(cbuffer, "\n\t\t\t<tr BGCOLOR=\"%s\"><td>%d</td><td>%s</td><td>%s</td></tr>", cbuffer2, total_frames, _info, _in); file_str_write(vLogFileHandle, cbuffer); file_close(vLogFileHandle); } }
unsigned long callc encoder_file_create(string fname, unsigned long fcreatemode) { unsigned long id; id = encoder_local_locateindex(); if(id == fennec_invalid_index)return fennec_invalid_index; pestreams[id].bmode = fennec_plugintype_audioencoder; pestreams[id].smode = fennec_encoder_file; str_cpy(pestreams[id].filepath, fname); pestreams[id].fhandle = v_error_sys_file_create; pestreams[id].cfrequency = 0; pestreams[id].cbitspersample = 0; pestreams[id].cchannels = 0; /* set defaults */ encoder_setdefaults(id); encoder_appendextension(id, pestreams[id].filepath); str_cpy(fname, pestreams[id].filepath); encoder_initialize(id, fcreatemode); return id; }
void load_config() { char buffer[128]; char value[32]; FILE *file = fopen("/Config", "r"); if (file != NULL) { while (fgets(buffer, 128, file) != NULL) { if(strncmp(buffer,"ID=",3)==0) { str_cpy(buffer+3,record_id,16); } else if(strncmp(buffer,"PlayRate=",9)==0) { str_cpy(buffer+9,value,16); play_rate=atoi(value); } } fclose(file); } }
static void multiplex(const char *exe, const char *tx_addr, int port) { Queue *runq = queue_new(); Queue *waitq = queue_new(); for (int i = 0; i < THREADS; ++i) { Exec *e = mem_alloc(sizeof(Exec)); str_cpy(e->exe, exe); str_cpy(e->tx, tx_addr); e->runq = runq; e->waitq = waitq; sys_thread(exec_thread, e); if (i == 0) /* only one waitq thread (reuses the same operand) */ sys_thread(waitq_thread, e); } IO *sio = sys_socket(&port); sys_log('E', "started port=%d, tx=%s\n", port, tx_addr); for (;;) { IO *io = sys_accept(sio, IO_STREAM); queue_put(waitq, conn_new(io)); } queue_free(waitq); queue_free(runq); }
unsigned int fileassociation_geticonid(const string ext) { letter apext[255]; letter apcls[255]; letter rvalue[260]; unsigned long rvsize = sizeof(rvalue); const string cls_name = uni("fennec.player.file."); int iconid = 0; string pt; apext[0] = uni('.'); str_cpy(apext + 1, ext); str_cpy(apcls, cls_name); str_cat(apcls, ext); /* i.e. "fennec.player.file.ogg" */ str_cat(apcls, uni("\\DefaultIcon")); if(RegQueryValue(HKEY_CLASSES_ROOT, apcls, rvalue, (PLONG)&rvsize) != ERROR_SUCCESS) goto pt_retdefaultid; if(!rvsize) goto pt_retdefaultid; pt = str_rchr(rvalue, uni(',')); if(!pt) goto pt_retdefaultid; pt++; /* ',' */ while(*pt == uni(' '))pt++; iconid = str_stoi(pt); return iconid; pt_retdefaultid: /* default icon ids */ return get_default_file_icon(ext); }
void list_split_str(hlist_t hlist, hcchar * str,hcchar *split_chars,InvokeTickDeclare){ if(hlist && str && split_chars){ hchar * p = (hchar *)str; hchar *s = NULL; hbuffer_t buffer = buffer_alloc(1024, 1024); while(*p !='\0'){ if(list_split_str_exist_char(split_chars,p,InvokeTickArg) ){ if(buffer_length(buffer) > 0){ s = NULL; str_cpy(&s, buffer_to_str(buffer)); list_add(hlist, s,InvokeTickArg); buffer_clear(buffer); } } else{ buffer_append(buffer, p, 1); } p++; } if(buffer_length(buffer) >0){ s = NULL; str_cpy(&s, buffer_to_str(buffer)); list_add(hlist, s,InvokeTickArg); } buffer_dealloc(buffer); } }
static data_xpath_tag_filter_t * data_xpath_tag_filter_attr_alloc(hcchar *attrName,hcchar * attrValue,InvokeTickDeclare){ data_xpath_tag_filter_attr_t * filter = (data_xpath_tag_filter_attr_t *)mem_malloc( sizeof(data_xpath_tag_filter_attr_t)); memset(filter,0,sizeof(data_xpath_tag_filter_attr_t)); filter->type = DATA_XPATH_TAG_FILTER_ATTR; str_cpy(&filter->name, attrName); str_cpy(&filter->value, attrValue); return (data_xpath_tag_filter_t *)filter; }
int main(int argc, char *argv[]) { char *s = NULL; str_cpy(&s, "Hola Hola"); str_cpy(&s, s+5); str_cat(&s, " World"); str_printf(&s, "%s!", s); puts(s); /* result: "Hola World!" */ str_free(&s); return 0; }
void sort(char **p,int length) { char tmp[LENG]; for (int i = 0;i < length - 1;i++) for (int j = 0;j < length - i - 1;j++) if (strcmp(p[j],p[j + 1]) < 0) { str_cpy(p[j],tmp,0,length); str_cpy(p[j + 1],p[j],0,length); str_cpy(tmp,p[j + 1],0,length); } }
void add_subfile(const string fpath, const string fname, int lid) { int id; id = sub_file_count; sub_file_count++; sub_files = (struct subtitle_file*) realloc(sub_files, sub_file_count * sizeof(struct subtitle_file)); sub_files[id].language_id = lid; str_cpy(sub_files[id].path, fpath); str_cpy(sub_files[id].name, fname); }
size_t const createfilename ( Char_type * result, Char_type const * filename, Char_type const * ext, Char_type const * helper ) { size_t len = 0; if ( str_len ( filename ) > 1 ) { while ( *filename != '\0' ) { // check if characters have grapnical // reprasentation if ( 0 != ::std::isgraph ( *filename ) ) { *result = *filename; ++result; ++len; } else { // convert space to underscore if ( *filename == ' ' ) { *result = '_'; ++result; ++len; } } ++filename; } // add extension str_cat ( result, ext ); *result = '\0'; } else if(str_len ( helper ) > 1) { result = &result[0]; len = str_cpy ( result, helper ); } #ifdef __WIN32__ // ColorKeeperHack else { result = &result[0]; std::string truc = getuserProfile(); len = str_cpy ( result, truc.c_str() ); } #endif return len; }
static void sort_word(char ar[][100], int n) { int i, j; for(i = 0; i < n; i++) { for (j = 0; j < n - i - 1; j++) { if (str_cmp(ar[j], ar[j+1]) > 0) { char tmp[100]; str_cpy(tmp, ar[j]); str_cpy(ar[j], ar[j+1]); str_cpy(ar[j+1], tmp); } } } }
//------------------------------------------------------------------------------ static int find_files_impl(lua_State* state, int dirs_only) { DIR* dir; struct dirent* entry; char buffer[512]; const char* mask; int i; int case_map; // Check arguments. i = lua_gettop(state); if (i == 0 || lua_isnil(state, 1)) { return 0; } mask = lua_tostring(state, 1); // Should the mask be adjusted for -/_ case mapping? if (_rl_completion_case_map && i > 1 && lua_toboolean(state, 2)) { char* slash; str_cpy(buffer, mask, sizeof_array(buffer)); mask = buffer; slash = strrchr(buffer, '\\'); slash = slash ? slash : strrchr(buffer, '/'); slash = slash ? slash + 1 : buffer; while (*slash) { char c = *slash; if (c == '_' || c == '-') { *slash = '?'; } ++slash; } } lua_createtable(state, 0, 0); i = 1; dir = opendir(mask); while (entry = readdir(dir)) { if (dirs_only && !(entry->attrib & _A_SUBDIR)) { continue; } lua_pushstring(state, entry->d_name); lua_rawseti(state, -2, i++); } closedir(dir); return 1; }
bool Db_Record::Record (void *_record, int size) { bool flag = (_record != Record ()); if (size > 0) { if (!Record_Size (size)) return (false); } else { size = Max_Size (); } if (record_format == BINARY) { if (flag) { memcpy (Record (), _record, size); } } else { if (flag) { str_cpy (((char *) Record ()), size + 1, ((char *) _record)); } size = (int) strlen (Record ()); } if (nest) { nest_rec_size = size; } else { record_size = size; } return (true); }
int ini_read(STRING *targetValue, STRING *filename, char* section, STRING *entry, STRING *defaultValue) { int length = GetPrivateProfileString(section, _chr(entry), _chr(defaultValue), iniBuffer, 2047, _chr(filename)); if(targetValue != NULL) str_cpy(targetValue, iniBuffer); return length; }
function dialogs_init() { STRING *file = "#256"; make_path(file, "messages.ini"); int i; for(i = 0; i < MAX_DIALOG_ENTRIES; i++) { /* [Message 0] text=Oh man, nice bell! sound=just_stupid_sound.wav */ STRING *section = "#64"; str_cpy(section, "Message "); str_cat(section, str_for_int(NULL, i)); char buffer[256]; ini_read_buffer(file, section, "text", "FIXIT: You forgot a message here!", buffer, 256); if(strlen(buffer) > 0) { dialogEntries[i].initialized = 1; dialogEntries[i].text = str_create(buffer); ini_read_buffer(file, section, "sound", "", buffer, 256); if(strlen(buffer) > 0) dialogEntries[i].sound = snd_create(buffer); else dialogEntries[i].sound = NULL; } } dialogText = txt_create(1, 20); dialogText->flags |= CENTER_X | TRANSLUCENT | OUTLINE; dialogText->font = dialogFont; }
/** Copy from hiscore table score with index src to dest * */ static void copyhiscore(int dest, int src) { str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, scores[src].hs_name); scores[dest].hs_score = scores[src].hs_score; scores[dest].hs_level = scores[src].hs_level; }
char * Time_Range::Range_Label (int num, bool pad_flag) { char start [40], end [40]; Range_Data *range_ptr = (Range_Data *) Record (num); if (range_ptr == NULL) return (NULL); str_cpy (start, sizeof (start), Time_Label (range_ptr->Low (), pad_flag)); str_cpy (end, sizeof (end), Time_Label (range_ptr->High ()+1, pad_flag)); //---- set time string ---- str_fmt (buffer, sizeof (buffer), "%s_%s", start, end); return (buffer); }
static hdata_object_tick_t * hdata_object_tick_alloc(hcchar * key, hdata_t value,InvokeTickDeclare){ hdata_object_tick_t * tick = mem_malloc( sizeof(hdata_object_tick_t)); memset(tick,0,sizeof(hdata_object_tick_t)); str_cpy(&tick->key, key); tick->value = value; return tick; }
// Initialize log void log_init(STRING* _logFile) { txtLog = txt_create(LOG_LINES,999); txtLog.font = fontLog; txtLog.size_x = screen_size.x; txtLog.size_y = 100; set(txtLog, SHOW | OUTLINE); int i; for(i=0; i<txtLog.strings; i++) { (txtLog.pstring)[i] = str_create("#256"); } // Color for log text vec_set(cLogColor, vector(255,255,255)); // Log to file, too? if (_logFile != NULL) { nLogToFile = 1; str_cpy(strLogFile, _logFile); } // If logging to file, initialize file IO if (nLogToFile == 1) { log_write_header(); } }
/** Perform sparc64-specific initialization before main_bsp() is called. */ void arch_pre_main(bootinfo_t *bootinfo) { /* Copy init task info. */ init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); size_t i; for (i = 0; i < init.cnt; i++) { init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr); init.tasks[i].size = bootinfo->taskmap.tasks[i].size; str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN, bootinfo->taskmap.tasks[i].name); } /* Copy physical memory map. */ memmap.total = bootinfo->memmap.total; memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS); for (i = 0; i < memmap.cnt; i++) { memmap.zones[i].start = bootinfo->memmap.zones[i].start; memmap.zones[i].size = bootinfo->memmap.zones[i].size; } /* Copy boot allocations info. */ ballocs.base = bootinfo->ballocs.base; ballocs.size = bootinfo->ballocs.size; ofw_tree_init(bootinfo->ofw_root); }
void log_clear() { if (txtLog == NULL) return; int i; for(i=0; i<txtLog.strings; i++) { str_cpy((txtLog.pstring)[i], ""); } }
void Arcview_File::Write_Projection (void) { if (shape_file.Is_Open ()) { Projection_Service service; char *projcs = service.Get_Projection_String (Output_Projection ()); if (projcs [0] != '\0') { char pathname [FILE_NAME_SIZE]; FILE *fp; int n; str_cpy (pathname, sizeof (pathname), shape_file.Filename ()); n = (int) strlen (pathname); memcpy (pathname + n - 3, "prj", 3); fp = f_open (pathname, "wb"); if (fp) { fputs (projcs, fp); fclose (fp); } } } }
void LoadMenu(unsigned char Menu_Index,unsigned char Permission) { unsigned char i,j,k ; // 导入菜单配置项 // unsigned char temp,temp1,temp2 ; // temp = Menu.MenuConfig[0] ; // 备份菜单项数目 // temp1 = Menu.MenuConfig[8] ; // 备份页数 // temp2 = Menu.MenuConfig[9] ; Menu.MenuIndex = Menu_Index ; str_cpy((char *)Menu.MenuConfig,(char *)Menus[Menu_Index].MenuConfig,10) ; // 拷贝菜单配置项 strcpy((char *)Menu.MenuTitle,(char *)Menus[Menu_Index].MenuTitle) ; // 拷贝菜单标题 Menu.MenuConfig[0] = 0 ; // 菜单项数清0 for(i=1;i< Menus[Menu_Index].MenuConfig[0]+1;i++) // 导入菜单标题字符串 { // temp = Menus[Menu_Index].ItemIndex[i-1] ; // temp = MENU_ITEM[temp].AccessLevel ; // if(Permission>=temp) if(Permission>=(MENU_ITEM[Menus[Menu_Index].ItemIndex[i-1]].AccessLevel)) { j = Menu.MenuConfig[0]++ ; // 计算菜单项数目 Menu.ItemIndex[j] = Menus[Menu_Index].ItemIndex[i-1] ; // 记录菜单项索引 for(k=0;k<20;k++) Menu.ItemTitle[j][k] = 0x00 ; strcpy((char *)Menu.ItemTitle[j], (char *)MENU_ITEM[Menus[Menu_Index].ItemIndex[i-1]].ItemTitle) ; // 拷贝菜单项标题 Menu.ItemConfig[j] = MENU_ITEM[Menus[Menu_Index].ItemIndex[i-1]].Config ; // 拷贝菜单项配置字 } } // Menu.MenuConfig[0] = temp ; // Menu.MenuConfig[8] = temp1 ; // Menu.MenuConfig[9] = temp2 ; }
int main() { char str[LENG]; int length = 0; while (scanf("%s",str) == 1) { length = strlen(str) + 1; char **p =(char **)malloc(sizeof(char *) * (length)); for (int i = 0;i < length;i++) p[i] = (char *)malloc(LENG * sizeof(char)); for (int i = 0;i < length - 1;i++) { str_cpy(str,p[i],i,length); } sort(p,length); for (int i = length - 2;i >= 0;i--) printf("%s\n",p[i]); for (int i = 0;i < length;i++) free(p[i]); free(p); } return 0; }
static void rpc_set_queue(rpc_t *rpc, void *c) { unsigned int queue_no = MAX_QUEUES, pipe_no = MAX_PIPES; str method, method_buf; if (rpc->scan(c, "dSd", &queue_no, &method, &pipe_no) < 3) return; if (pipe_no >= MAX_PIPES || (int)pipe_no < 0) { LM_ERR("Invalid pipe number: %d\n", pipe_no); rpc->fault(c, 400, "Invalid pipe number"); return; } if (str_cpy(&method_buf, &method)) { LM_ERR("out of memory\n"); rpc->fault(c, 400, "OOM"); return; } LOCK_GET(rl_lock); if (queue_no >= *nqueues) { LM_ERR("MAX_QUEUES reached for queue: %d\n", queue_no); rpc->fault(c, 400, "MAX_QUEUES reached"); LOCK_RELEASE(rl_lock); return; } *queues[queue_no].pipe = pipe_no; if (!queues[queue_no].method->s) shm_free(queues[queue_no].method->s); queues[queue_no].method->s = method_buf.s; queues[queue_no].method->len = method_buf.len; LOCK_RELEASE(rl_lock); }
int callc fennec_visualization_initialize(struct general_visualization_data *sdata, string plgtitle) { memcpy(&sfennec, sdata->shared, sizeof(struct fennec)); memcpy(&visdata, sdata, sizeof(struct general_visualization_data)); sdata->uninitialize = visualization_uninitialize; sdata->refresh = visualization_refresh; sdata->settings = visualization_settings; sdata->about = visualization_about; sdata->fsettings.plugin_settings_getnum("vis.spectrum", "intense", &intensecolors, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "showfall", &showfall, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "showbars", &showbars, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "fallco", &fallco, 0, 0); sdata->fsettings.plugin_settings_getnum("vis.spectrum", "barscount", &bars_count, 0, 0); str_cpy(plgtitle, uni("Spectrum Analyzer")); visdata.getdata(get_visual_dc, 0, &dc, 0); visdata.getdata(set_msg_proc, 0, vis_message, 0); visdata.getdata(get_visual, 0, &window_vis, 0); vwx = visdata.getdata(get_visual_x, 0, 0, 0); vwy = visdata.getdata(get_visual_y, 0, 0, 0); vww = visdata.getdata(get_visual_w, 0, 0, 0); vwh = visdata.getdata(get_visual_h, 0, 0, 0); draw_rect(vwx, vwy, vww, vwh, 0); timer_id = SetTimer(0, 0, 30, timer_display); col_bar_line = color_adjust(visdata.getdata(get_color, color_dark, 0, 0), 0.3); col_bar_fill = (COLORREF)visdata.getdata(get_color, color_dark, 0, 0); return 1; }
//------------------------------------------------------------------------------ static void load_lua_scripts(const char* path) { int i; char path_buf[1024]; HANDLE find; WIN32_FIND_DATA fd; str_cpy(path_buf, path, sizeof_array(path_buf)); str_cat(path_buf, "\\", sizeof_array(path_buf)); i = strlen(path_buf); str_cat(path_buf, "*.lua", sizeof_array(path_buf)); find = FindFirstFile(path_buf, &fd); path_buf[i] = '\0'; while (find != INVALID_HANDLE_VALUE) { if (_stricmp(fd.cFileName, "clink.lua") != 0) { str_cat(path_buf, fd.cFileName, sizeof_array(path_buf)); load_lua_script(path_buf); path_buf[i] = '\0'; } if (FindNextFile(find, &fd) == FALSE) { FindClose(find); break; } } }
/* * void encrypt_string( STRING *sstr, STRING *estr, int shift ) * * Performs encrypting on a single string. Both the source string * (sstr) and the container (estr) must be valid. * Additionally a custom shift value can be passed. * * Another variant using the default shift macro (__SHIFT) can be found below. */ void encrypt_string( STRING *sstr, STRING *estr, int shift ) { if( !sstr || !estr ) return; sstr = str_create(sstr); estr = str_create(""); STRING *buffer = ""; int counter = 0; int temp_val = 0; int length = str_len(sstr); while( counter < length ) { str_cpy(buffer, sstr); str_clip(buffer, counter); str_trunc(buffer, length - counter - 1); temp_val = str_to_asc(buffer) + shift; str_for_asc(buffer, temp_val); str_cat(estr, buffer); counter++; } }
static void test_param() { Expr *e = NULL; int i = 12345; double d = 12.345; long long l = 9223372036854775807LL; char *s = "string_1"; Arg arg; arg.vals[0].v_int = i; arg.vals[1].v_real = d; arg.vals[2].v_long = l; str_cpy(arg.vals[3].v_str, s); e = expr_eq(expr_int(i), expr_param(0, Int)); if (expr_bool_val(e, NULL, &arg) == 0) fail(); expr_free(e); e = expr_eq(expr_real(d), expr_param(1, Real)); if (expr_bool_val(e, NULL, &arg) == 0) fail(); expr_free(e); e = expr_eq(expr_long(l), expr_param(2, Long)); if (expr_bool_val(e, NULL, &arg) == 0) fail(); expr_free(e); e = expr_eq(expr_str(s), expr_param(3, String)); if (expr_bool_val(e, NULL, &arg) == 0) fail(); expr_free(e); }