/** * Parses an encoding description such as en_GB.utf8@euro into it's 3 main parts * en_GB, utf8 and euro. Then it recombines the parts using a "utf8" encoding. */ gchar *make_utf8_locale(const gchar *encoding) { static char result[256]; gchar *locale, *codeset = NULL, *extra = NULL; gchar buf[256]; gchar *t; gint len = r_strlen(encoding); if ((encoding == NULL) || (r_strlen(encoding) < 2)) { // shows in apache error_log //r_warning(NULL, "encoding is NULL or invalid [%s]... using en_US\n", encoding); return (char *)"en_US.utf8"; } g_strlcpy(buf, encoding, sizeof(buf)); locale = buf; t = g_strstr_len(buf, len, "."); if (t) { *t = '\0'; codeset = t + 1; len = r_strlen(codeset); } if (codeset) { t = g_strstr_len(codeset, len, "@"); if (t) { *t = '\0'; extra = t + 1; } } codeset = (gchar *)"utf8"; if (extra) { g_snprintf(result, sizeof(buf), "%s.%s@%s", locale, codeset, extra); } else { g_snprintf(result, sizeof(buf), "%s.%s", locale, codeset); } return result; }
gint rlib_var_concat_string(rlib_var *v, const char *str) { int len = r_strlen(v->value.ch); int tlen = len + r_strlen(str); if (tlen >= v->len) return -1; strcpy(v->value.ch + len, str); return tlen; }
int main(int argc, char *argv[]) { int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; rvm_scope_t *scope = rvm_scope_create(); rvm_scope_addstrname(scope, "a1"); rvm_scope_addstrname(scope, "a"); rvm_scope_addstrname(scope, "a"); rvm_scope_addstrname(scope, "ab"); rvm_scope_addstrname(scope, "abcd"); rvm_scope_addstrname(scope, "abce"); rvm_scope_addstrname(scope, "abcf"); rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 0); rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 1); rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 2); rvm_scope_addpointer(scope, "a5", r_strlen("a5"), &a[5]); print_var_info(scope, "a0"); print_var_info(scope, "a2"); print_var_info(scope, "a5"); rvm_scope_push(scope); rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 10); rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 11); rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 12); rvm_scope_push(scope); rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 101); rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 112); rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 223); print_var_info(scope, "a0"); print_var_info(scope, "a2"); print_var_info(scope, "a5"); rvm_scope_pop(scope); print_var_info(scope, "a0"); print_var_info(scope, "a2"); print_var_info(scope, "a5"); rvm_scope_pop(scope); print_var_info(scope, "a0"); print_var_info(scope, "a2"); print_var_info(scope, "a5"); rvm_scope_destroy(scope); fprintf(stdout, "Max alloc mem: %ld\n", r_debug_get_maxmem()); fprintf(stdout, "Leaked mem: %ld\n", r_debug_get_allocmem()); return 0; }
/* Gets an appropriately sized rlib_var and copies the string to it. */ rlib_var *rlib_var_factory_new_string(rlib_var_factory *f, const gchar *str) { int len = r_strlen(str) + 1; rlib_var *v = rlib_var_factory_get(f, len); g_strlcpy(v->value.ch, str, len); /* just strcpy maybe?? */ v->type = RLIB_VAR_STRING; return v; }
gchar *rlib_align_text(rlib *r, gchar **my_rtn, gchar *src, gint align, gint width) { gint len = 0, size = 0, lastidx = 0; gchar *rtn; if (width == 0) { rtn = *my_rtn = g_strdup(""); return rtn; } if (src != NULL) { len = r_strlen(src); size = strlen(src); lastidx = width + size - len; } if (len > width) { rtn = *my_rtn = g_strdup(src ? src : ""); return rtn; } else { rtn = *my_rtn = g_malloc(lastidx + 1); if (width >= 1) { memset(rtn, ' ', lastidx); rtn[lastidx] = 0; } if (src != NULL) memcpy(rtn, src, size); } if (!OUTPUT(r)->do_align) return rtn; if (align == RLIB_ALIGN_LEFT || width == -1) { /* intentionally do nothing here */ } else { if (align == RLIB_ALIGN_RIGHT) { gint x = lastidx - size; if (x > 0) { memset(rtn, ' ', x); if (src == NULL) rtn[x] = 0; else g_strlcpy(rtn+x, src, lastidx); } } if (align == RLIB_ALIGN_CENTER) { if (!(width > 0 && len > width)) { gint x = (width - len)/2; if (x > 0) { memset(rtn, ' ', x); if (src == NULL) rtn[x] = 0; else memcpy(rtn+x, src, size); } } } } return rtn; }
int r_strlen(char *string){ if(string==NULL){ return 0; } else{ return r_strlen(string+1)+1; } }
int main(int argc, char *argv[]) { /* NOTE: Test kodu, buraya dokunmayin! */ assert(r_strchr("ahmet mehmet\n\n\t", 'h') == 1); assert(r_strchr("ahmet", 'x') == 0); assert(r_strchr("ahmet", 'a') == 1); assert(r_strchr("hhhhhhha", 'x') == 0); printf("All tests passed for r_strchr()!\n"); assert(r_strlen("ahmet mehmet kokokoko\t\t") == 23); assert(r_strlen("ahmet") == 5); assert(r_strlen("a") == 1); assert(r_strlen("") == 0); printf("All tests passed for r_strlen()!\n"); assert(r_strcount("ahmet", 'a') == 1); assert(r_strcount("ahmeta", 'a') == 2); assert(r_strcount("ahmeta", 'x') == 0); assert(r_strcount("", 'x') == 0); assert(r_strcount("ahmet mehmet\n\n\t", 't') == 2); printf("All tests passed for r_strcount()!\n"); assert(roman_number_to_int("IIII") == 4); assert(roman_number_to_int("IV") == 4); assert(roman_number_to_int("VIIII") == 9); assert(roman_number_to_int("IX") == 9); assert(roman_number_to_int("MIM") == 1999); assert(roman_number_to_int("MCMXCIX") == 1999); assert(roman_number_to_int("D") == 500); printf("All tests passed for roman_number_to_int()!\n"); assert(r_sum_digits(0) == 0); assert(r_sum_digits(9) == 9); assert(r_sum_digits(10) == 1); assert(r_sum_digits(100) == 1); assert(r_sum_digits(1009) == 10); assert(r_sum_digits(152101) == 10); assert(r_sum_digits(999999) == 54); printf("All tests passed for r_sum_digits()!\n"); return 0; }
/*============================================================================== 函数: <ScnDir> 功能: <xh_Func:> 参数: Created By 徐崇 2012.10.17 10:39:26 For Ftp ==============================================================================*/ static int ScnDir(FILE *plistfile,int8_t *DirPath) { DIR *pDir ; struct dirent *ent; int32_t i = 0; char childpath[MAX_FILE_PATH_LEN]; int32_t ret = 0; int32_t num = 0; pDir = opendir(DirPath); if(NULL == pDir) { printf("Cannot open directory: %s",DirPath); return -1; } while((ent = readdir(pDir))!=NULL) { if(ent->d_type & DT_DIR) { if(r_strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0) continue; sprintf(childpath,"%s/%s",DirPath,ent->d_name); ret = ScnDir(plistfile, childpath); num = ret + num; } else { int8_t LocalFilePath[MAX_FILE_PATH_LEN]; sprintf(LocalFilePath,"%s/",DirPath); r_strncat(LocalFilePath, ent->d_name, r_strlen(ent->d_name)); printf("%s\n",LocalFilePath); /* 隐藏文件过滤 */ if(ent->d_name[0] == '.') { continue; } num++; fprintf(plistfile," <file>%s</file>\n",LocalFilePath); } } if(0 != closedir(pDir)) { assert(0); } return num; }
void rlib_parsecolor(struct rlib_rgb *color, const gchar *strx) { const gchar *str = colornames(strx); if(str != NULL && r_strlen(str) == 8) { guchar r; guchar g; guchar b; r = (hextochar(str[2]) << 4) | hextochar(str[3]); g = (hextochar(str[4]) << 4) | hextochar(str[5]); b = (hextochar(str[6]) << 4) | hextochar(str[7]); color->r = (gfloat)r/(gfloat)0xFF; color->g = (gfloat)g/(gfloat)0xFF; color->b = (gfloat)b/(gfloat)0xFF; } else { color->r = -1; color->g = -1; color->b = -1; } }
/*============================================================================== 函数: <UpLoadFile> 功能: <xh_Func:> 参数: Created By 徐崇 2012.10.16 16:24:27 For Ftp ==============================================================================*/ int32_t DirDetectFile(int8_t *UpLoadFilePath) { int8_t filename[MAX_FILE_PATH_LEN]; FILE *pmd5file = NULL; FILE *plistfile = NULL; int32_t ret = 0; if((UpLoadFilePath == NULL)) { return -1; } r_strcpy(filename,UpLoadFilePath); r_strncat(filename,"/filelist.xml",r_strlen("filelist.xml")+1); plistfile = fopen(filename,"w+"); if(NULL == plistfile) { return -1; } fprintf(plistfile,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(plistfile,"<DirContent>\n"); ret = ScnDir(plistfile, UpLoadFilePath); fprintf(plistfile," <num>%d</num>\n",ret); fprintf(plistfile,"</DirContent>\n"); if(plistfile != NULL) { fclose(plistfile); } return ret; }
long rex_compiler_expression_s(rexcompiler_t *co, rexdb_t *rexdb, const char *str, rexuserdata_t userdata) { return rex_compiler_expression(co, rexdb, str, r_strlen(str), userdata); }
/* Soru 2 */ int r_strlen(char *string) { /* TODO */ if(string[0]=='\0') return 0; else return 1+r_strlen(++string); }
long r_map_taillookup_s(rmap_t *map, long current, const char *name) { return r_map_taillookup(map, current, name, r_strlen(name)); }
int rpa_compiler_rule_begin_s(rpa_compiler_t *co, const char *name, rpabitmap_t bitmap) { return rpa_compiler_rule_begin(co, name, r_strlen(name), bitmap); }
void rpa_compiler_rulepref_clear_flag_s(rpa_compiler_t *co, const char *name, unsigned long flag) { rpa_compiler_rulepref_clear_flag(co, name, r_strlen(name), flag); }
void rpa_compiler_rulepref_set_s(rpa_compiler_t *co, const char *name, long ruleid, long ruleuid, unsigned long flags) { rpa_compiler_rulepref_set(co, name, r_strlen(name), ruleid, ruleuid, flags); }
void rpa_compiler_rulepref_set_ruleuid_s(rpa_compiler_t *co, const char *name, long ruleuid) { rpa_compiler_rulepref_set_ruleuid(co, name, r_strlen(name), ruleuid); }
rpa_rulepref_t *rpa_compiler_rulepref_s(rpa_compiler_t *co, const char *name) { return rpa_compiler_rulepref(co, name, r_strlen(name)); }
void rpa_compiler_reference_s(rpa_compiler_t *co, const char *name, unsigned int qflag) { rpa_compiler_reference(co, name, r_strlen(name), qflag); }
long rex_compiler_addexpression_s(rexcompiler_t *co, rexdb_t *rexdb, unsigned long prev, const char *str, rexuserdata_t userdata) { return rex_compiler_addexpression(co, rexdb, prev, str, r_strlen(str), userdata); }
int rpa_compiler_inlinerule_begin_s(rpa_compiler_t *co, const char *name, unsigned int flags) { return rpa_compiler_inlinerule_begin(co, name, r_strlen(name), flags); }
long rex_compiler_setblanks_s(rexcompiler_t *co, const char *str) { return rex_compiler_setblanks(co, str, r_strlen(str)); }
void rpa_compiler_reference_opt_s(rpa_compiler_t *co, const char *name) { rpa_compiler_reference_opt(co, name, r_strlen(name)); }
int rpa_compiler_loop_begin_s(rpa_compiler_t *co, const char *name) { return rpa_compiler_loop_begin(co, name, r_strlen(name)); }
long r_map_gckey_add_s(rmap_t *map, rgc_t* gc, const char *name, rconstpointer pval) { return r_map_gckey_add(map, gc, name, r_strlen(name), pval); }