int Config_open(const char *path) { int ret=0, counter=0, counter1=1; char temp[LINE_LENGTH], *result; config_content = (struct conf*)calloc(1, sizeof(struct conf)); config_path = (char*) path; if(!(pFile=fopen(config_path,"r"))) { return 1; } while (fgets(temp,LINE_LENGTH,pFile)) { config_lines_qty++; } config_content = (struct conf*)realloc(config_content, (config_lines_qty+50)*sizeof(struct conf)); int i; for (i=0;i<config_lines_qty+50;i++) { strcpy(config_content[i].config_line, ""); strcpy(config_content[i].param_name, ""); strcpy(config_content[i].param_value, ""); } rewind(pFile); while (fgets(temp,LINE_LENGTH,pFile)) { if (strlen(temp)>LINE_LENGTH) { printf("Config error. Too long line: %d\n", counter1); ret=1; break; } if (strlen(temp)<4) { counter1++; continue; } strcpy(config_content[counter].config_line,temp); result=strtok(temp,"="); result=str_trim_right(result); if (!result) { printf("Config error. Line: %d\n", counter1); ret=1; break; } strcpy(config_content[counter].param_name,result); result=strtok(NULL,"\n"); result=str_trim_left(result); if (!result) { printf("Config error. Line: %d\n", counter1); ret=1; break; } strcpy(config_content[counter].param_value,result); counter++; counter1++; } fclose(pFile); return ret; }
void size_cache_clean( const char *s ) { VString str = size_cache_compose_key( s, 0 ); str_trim_left( str, SIZE_CACHE_OFFSET_CLEAN ); int sl = str_len( str ); int z = 0; while( z < size_cache.count() ) { const char* ps = size_cache[z].data() + SIZE_CACHE_OFFSET_CLEAN; if ( ( strncmp( ps, str, sl ) == 0 && (ps[sl] == '/' || ps[sl] == 0) ) || ( size_cache[z][SIZE_CACHE_OFFSET_CLEAN] != '|' ) ) size_cache.del( z ); else z++; } }
void tree_view() { VString str; if (dir_tree.count() == 0) { tree_load(); if (dir_tree.count() == 0) tree_rebuild(); } say1( " " ); int new_pos = tree_index( work_path ); if ( new_pos == -1 ) new_pos = 0; BSet set; /* used for searching */ set.set_range1( 'a', 'z' ); set.set_range1( 'A', 'Z' ); set.set_range1( '0', '9' ); set.set_str1( "._-~" ); set.set_str1( "?*>[]" ); ScrollPos scroll; scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.set_pagesize( PS+2 ); scroll.go( new_pos ); int key = 0; int opos = -1; int opage = -1; while( key != 27 && key != 13 && key != '-' && toupper( key ) != 'Q' && toupper( key ) != 'X' && key != KEY_ALT_X ) { if ( key >= 'A' && key <= 'Z' ) key = tolower( key ); if ( key == 's' ) { str = ""; say1( "Enter search pattern: ( use TAB to advance )" ); key = con_getch(); while( set.in( key ) || key == 8 || key == KEY_BACKSPACE || key == 9 ) { if ( key == 8 || key == KEY_BACKSPACE ) str_trim_right( str, 1 ); else if ( key != 9 ) str_add_ch( str, key ); say2( str ); if ( dir_tree.count() == 0 ) { key = con_getch(); continue; } int z; if ( key == 9 ) { z = scroll.pos() + 1; if (z > scroll.max() ) z = scroll.min(); } else z = scroll.pos(); int direction = 1; int found = 0; int loops = 0; VString s_mask = str; vfu_expand_mask( s_mask ); while(1) { if ( z > scroll.max() ) z = scroll.min(); if ( z < scroll.min() ) z = scroll.max(); VString str1 = dir_tree[z]; str_trim_right( str1, 1 ); int j = str_rfind(str1,'/'); if (j < 0) str1 = ""; else str_trim_left( str1, j+1 ); found = ( FNMATCH( s_mask, str1 ) == 0 ); if ( found ) break; z += direction; if ( loops++ > dir_tree.count() ) break; } if (found) { scroll.go(z); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); } key = con_getch(); } say1( "" ); say2( "" ); } else switch( key ) { case KEY_UP : scroll.up(); break; case KEY_DOWN : scroll.down(); break; case KEY_PPAGE : scroll.ppage(); break; case KEY_NPAGE : scroll.npage(); break; case KEY_HOME : scroll.home(); break; case KEY_END : scroll.end(); break; case 'r' : tree_rebuild(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); say1( "Rebuild done." ); break; case 'w' : tree_save(); break; case 'l' : tree_load(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); break; case 'z' : case KEY_CTRL_Z : str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); size_cache_set( str, vfu_dir_size( str ) ); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); say1( "Done." ); break; } if (opage != scroll.page()) tree_draw_page( scroll ); if (opos != scroll.pos() - scroll.page() || opage != scroll.page()) tree_draw_pos( scroll, opos ); opos = scroll.pos() - scroll.page(); opage = scroll.page(); key = con_getch(); } if ( key == 13 ) { str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); vfu_chdir( str ); } do_draw = 2; };
void tree_draw_item( int page, int index, int hilite ) { if ( page + index >= dir_tree.count() ) return; VString s1 = dir_tree[page+index]; str_trim_right(s1,1); VString s2 = s1; int j = str_rfind( s1,'/'); str_trim_right(s1,str_len(s2)-j-1); str_trim_left(s2,j+1); for(j = 0; j < str_len(s1); j++) { if (s1[j] == '/') str_set_ch(s1,j, '|'); else if (s1[j] == '\\') str_set_ch(s1,j, '\\'); else str_set_ch(s1,j, '+'); } if (opt.tree_compact) { str_replace(s1,"+", ""); str_replace(s1,"|", "| "); str_replace(s1,"\\"," "); str_trim_right(s1,2); s1 += "--"; } else { str_replace(s1,"+", " "); str_replace(s1,"\\", " "); s1 += "--"; } VString str = dir_tree[page+index]; str_tr( str,"\\", "/" ); VString sz; sz.fi( size_cache_get( str ) ); if ( sz == "-1" ) sz = "n/a"; else str_comma( sz ); str_pad( sz, 14 ); s1 = sz + " " + s1; int m = con_max_x() - 1; /* doesn't speed the code... :) */ if ( str_len( s1 ) > m ) { str_sleft( s1, m ); s2 = ""; } else if ( str_len( s1 ) + str_len( s2 ) > m ) { str_sleft( s2, m - str_len( s1 ) ); } con_xy(1,3+1+index); if (hilite) { con_puts( s1, cBAR ); con_puts( s2, cBAR ); con_ce( cBAR ); } else { con_puts( s1, cSTATUS ); con_puts( s2, cMESSAGE ); con_ce( cSTATUS ); } }
int vfu_get_dir_name( const char *prompt, VString &target, int should_exist ) { int res = -1; /* #ifdef _TARGET_UNIX_ leaveok(stdscr, FALSE); #endif */ VArray dir_list; say1(prompt); say2(""); int pos = 0; int page = 0; int ch = 0; int insert = 1; int firsthit = 1; pos = str_len( target ); //------------------------------------------------------------------ con_cshow(); say2( target, firsthit ? cINPUT2 : cINPUT ); while(1) { int mx = con_max_x() - 1; VString target_out = target; if ( (pos < page) || (pos+1 > page + mx) || (page > 0 && pos == page) ) page = pos - mx / 2; if ( page < 0 ) page = 0; str_trim_left( target_out, page ); str_sleft( target_out, mx ); str_pad( target_out, -mx ); if ( page > 0 ) str_set_ch( target_out, 0, '<' ); if ( str_len( target ) - page > mx ) str_set_ch( target_out, mx-1, '>' ); say2( target_out, firsthit ? cINPUT2 : cINPUT ); con_xy( pos-page+1, con_max_y() ); if (ch == 0) ch = con_getch(); if (ch == '\\') ch = '/'; /* dos hack :)) */ if ( ch == '/' && str_find( target, '/' ) == -1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); pos = str_len( target ); ch = 0; } if ((ch == 8 || ch == KEY_BACKSPACE) && pos > 0) { pos--; str_del( target, pos, 1 ); } else if (ch == KEY_CTRL_A && str_len( target ) > 0) { int z = str_len( target )-1; if ( str_get_ch(target, z) == '/' ) z--; while ( z > 0 && str_get_ch(target,z) != '/' ) z--; z++; str_sleft(target,z); pos = z; } else if ( ch == 9 && str_len( target ) > 0) { int z; dir_list.undef(); VString dmain; /* main/base path */ VString dtail; /* item that should be expanded/glob */ dmain = str_file_path( target ); dtail = str_file_name_ext( target ); /* int lastslash = str_rfind(target, '/'); if ( lastslash == -1 ) { dmain = ""; dtail = target; } else { dmain = target; dtail = target; str_sleft( dmain, lastslash+1 ); str_trim_left( dtail, lastslash+1 ); } */ __glob_gdn( dmain, dtail, dir_list ); z = dir_list.count()-1; if (dir_list.count()) { if ( dir_list.count() > 1) { int mc = 0; /* match count */ int mi = 0; /* match letter index */ while(4) { mc = 0; int li; /* counter */ for ( li = 0; li < dir_list.count(); li++ ) { if ( str_get_ch( dir_list[ 0], mi ) == str_get_ch( dir_list[li], mi ) ) mc++; } if ( mc != dir_list.count() ) break; mi++; } target.setn( dmain + dir_list[0], str_len( dmain ) + mi ); pos = str_len( target ); say2( target, cINPUT ); con_xy( pos+1, con_max_y() ); vfu_beep(); ch = con_getch(); if ( ch != 9 ) { dir_list.undef(); continue; } dir_list.sort(); con_chide(); z = vfu_menu_box( 10, 5, "Complete...", &dir_list ); con_cshow(); ch = 0; } else ch = 0; if ( z != -1 ) { while( str_len( target ) > 0 && target[-1] != '/' ) str_chop( target ); target += dir_list[z]; } pos = str_len( target ); dir_list.undef(); if (ch != 0) continue; } else { /* no match found -- cannot complete */ vfu_beep(); } } else if (ch == 13) { res = 1; break; } else if (ch == 27) { target = ""; res = 0; break; } if (ch == KEY_CTRL_U) { target = ""; pos = 0; } else if (ch == KEY_CTRL_X) { char t[MAX_PATH]; if ( target[0] == '~' ) target = tilde_expand( target ); expand_path( target, t ); str_fix_path( t ); target = t; pos = str_len( target ); } else if (ch >= 32 && ch <= 255 ) // && pos < 70) { if (firsthit) { target = ""; pos = 0; } if (!insert) str_del( target, pos, 1 ); str_ins_ch( target, pos, ch ); pos++; } else if( ch == KEY_LEFT ) { if (pos > 0) pos--; } else if( ch == KEY_RIGHT ) { if (pos < str_len( target )) pos++; } else if ( ch == KEY_IC ) insert = !insert; else if ( ch == KEY_HOME ) pos = 0; else if ( ch == KEY_END ) pos = str_len(target); else if ( ch == KEY_DC && pos < str_len(target) ) str_del( target, pos, 1 ); else if ( ch == KEY_NPAGE || ch == KEY_PPAGE ) { con_chide(); int zz = vfu_hist_menu( 5, 5, ( ch == KEY_PPAGE ) ? "Dir Entry History" : "ChDir History", ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR ); con_cshow(); if (zz != -1) { const char* pc = vfu_hist_get( ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR, zz ); if ( pc ) { target = pc; pos = str_len( target ); } } } ch = 0; firsthit = 0; } con_chide(); //------------------------------------------------------------------ str_cut_spc( target ); if ( res == 1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); } /* if ( target.len() > 0 ) { // well this tmp is kind of s... ama k'vo da pravi chovek :) // FIXME: dos version? if ( __ExpandGetDirName && target[0] != '/' #ifdef _TARGET_GO32_ && !( target[1] == ':' && target[2] == '/' ) #endif ) target = CPath + target; StrFixPath( target ); // add trailing slash if not exist } */ /* #ifdef _TARGET_UNIX_ leaveok(stdscr, TRUE); #endif */ if ( res == 1 && str_len( target ) > 0 && should_exist && !dir_exist( target )) { vfu_beep(); int ch = tolower( vfu_ask( "Directory does not exist! Create? " "( ENTER=Yes, ESC=cancel )", "\033\rcC" )); if ( ch == 27 ) { res = 0; target = ""; } else if ( ch == 13 ) if (make_path( target )) { if(tolower( vfu_ask( "Cannot create path! ( ESC=cancel, C=continue-anyway )", "\033Cc" )) == 27) { res = 0; target = ""; } } } say1(" "); say2(" "); if ( str_len( target ) > 0) { str_fix_path( target ); vfu_hist_add( HID_GETDIR, target ); } str_cut_spc( target ); ASSERT( res == 0 || res == 1 ); return res; }
//파일에 있는 문장 번역(영한 mode에 상관없이 번역) int fio_translation (char *fname, char *fname2, BTREE** ws, BTREE** wi, BTREE** hb[], int mode, BTREE* rs, QUEUE** qk, int flag) { FILE *fp, *fp2; char rows[SSIZE], keys[SSIZE], *rowp; register int i=0; int ch, rown=0, kcnt, trans_cnt=0; unsigned int h; BTREE* t1; void* data; printf ("File (%s >> %s) Translating...\n", fname, fname2); fp = fopen (fname, "r"); if (fp == NULL) { printf (", Input file(%s) not exist!\n", fname); return 0; } fp2 = fopen (fname2, "w"); if (fp2 == NULL) { printf (", Output file(%s) creating error!\n", fname2); return 0; } //문장 단위로 읽음 ch = fgetc (fp); while (ch != EOF) { while (ch != '\n' && ch != EOF && i < SSIZE-2) { //문장끝 rows[i++] = ch; if (um_end(ch)) break; //문장끝 부호(. ? !) ch = fgetc (fp); } if (i >= SSIZE-2) break; rows[i] = '\0'; rowp = str_trim_left (rows); if (*rowp == '/' && *(rowp+1) == '/') { //주석 fputs (rowp, fp2); //원문출력 fputc ('\n', fp2); ch = fgetc (fp); i = 0; continue; } if (ch == '\n') { rows[i++] = ' '; //fputc ('\n', fp2); } ch = fgetc (fp); if (ch != EOF && !um_whites(ch)) continue; //문장끝이 아님으로 판단하고 계속 읽음 rows[i] = '\0'; rowp = str_trim (rows); mode = str_is_eng_kor (rowp); //0:영문, 1:한글, -1:특수문자(개행문자도 특수문자로 취급) if (mode >= 0) { fputs (rowp, fp2); //원문출력 fputc ('\n', fp2); //문장을 인덱스키로 변환 str_copy (keys, rowp); if ((kcnt = tw1_words_input ("", keys, ws[mode], wi[mode], rs, qk[mode], FLAG_NONE)) > 0) { //printf (">> %s\n", keys); //해시값으로 번역키 B+트리 선택 h = hash_value (keys); t1 = hb[mode][h]; data = bpt_search (t1, keys); //번역키 if (data) { //번역 문장 보관용 스택에 입력 tw2_stack_push (rowp); ///번역정보(완전일치)를 파일에 출력 if (_fio_export_data (fp2, wi[!mode], data) > 0) trans_cnt++; else tw2_stack_pop (); //스택에 저장된 번역대상 문장 제거 } else { //완전일치키가 없을때, 번역키를 하나씩 분리하여 단어단위로 검색하여 출력 if (_fio_trans_key_each (fp2, keys, hb, wi, mode, kcnt) > 0) trans_cnt++; } } fputc ('\n', fp2); } printf ("%c*line: %u: ", CR, ++rown); //라인 수 i = 0; if (flag==FLAG_NONE && trans_cnt==TRANS_CNT) { //무료 //파일에 출력 fputs ("** 문장번역 개수를 제한합니다.\n", fp2); fputs ("** 유료 회원으로 등록하시면 제한없이 번역합니다.\n\n", fp2); //화면에 출력 printf ("** 문장번역을 %d개로 제한합니다.\n", TRANS_CNT); printf ("** 유료 회원으로 등록하시면 제한없이 번역합니다.\n\n"); break; } } //while fclose (fp2); fclose (fp); return trans_cnt; //번역한 문장 수 }
//번역 데이터 파일(txt)에서 번역행들을 읽어서 저장(입력) //mode 구분, 0:영문(한글번역), 1:한글(영문번역) int fio_import (char *fname, BTREE** ws, BTREE** wi, BTREE** hb[], int mode, BTREE* rs, QUEUE** qk) { FILE *fp; register int i=0; char ch, row[SSIZE], rows[2][SSIZE], *rowp; int idx, rown=0, cnt=0, ie; bool brun; printf ("Reading data from the %s...\n", fname); fp = fopen (fname, "r"); if (fp == NULL) { printf (", Not exist!\n"); return 0; } rows[0][0] = '\0'; rows[1][0] = '\0'; //개행문자, 문장 단위로 읽음 ch = fgetc (fp); while (ch != EOF) { ie = 0; while (ch != '\n' && ch != EOF && i < SSIZE-2) { //문장끝 row[i++] = ch; if (um_end(ch)) ie = 1; //문장끝 부호(. ? !)가 있는지 여부 ch = fgetc (fp); } if (i >= SSIZE-2) break; row[i] = '\0'; rowp = str_trim_left (row); if (*rowp == '/' && *(rowp+1) == '/') { //주석 ch = fgetc (fp); i = 0; continue; } if (ch == '\n') row[i++] = ' '; ch = fgetc (fp); if (ch != EOF && !ie) continue; //문장끝이 아님으로 판단하고 계속 읽음 row[i] = '\0'; rowp = str_trim (row); //0:영문, 1:한글, -1:특수문자 idx = str_is_eng_kor (rowp); if (idx >= 0) { if (*rowp == '*') str_copy (rows[idx], rowp+1); else str_copy (rows[idx], rowp); brun = (mode) ? !idx: idx; //0:영문(한글번역), 1:한글(영문번역) if (brun && *rows[mode]) cnt += tw1_insertion_from_file (ws, wi, hb, mode, rs, qk, rows, -1); //저장 문장 수 누적 } printf ("%c*line: %d/%d: ", CR, cnt, ++rown); //문장수 i = 0; } fclose (fp); printf ("%d rows have saved.\n", cnt); return cnt; //저장한 문장 수 }
//번역 데이터 파일(txt)에서 CAPTION 문장들을 읽어서 저장(입력) //mode 구분, 0:영문(한글번역), 1:한글(영문번역) int fio_import_caption (char *fname, BTREE** ws, BTREE** wi, BTREE** hb[], int mode, BTREE* rs, QUEUE** qk) { FILE *fp; register int i=0; char ch, row[SSIZE], rows[2][SSIZE], *rowp; char caps[2][ASIZE], capn[ASIZE]; int idx, skip=0, ie; int rown=0, cnt=0, cnt_sum=0; bool brun, bcap; printf ("Reading data from the %s...\n", fname); fp = fopen (fname, "r"); if (fp == NULL) { printf (", Not exist!\n"); return 0; } rows[0][0] = '\0'; rows[1][0] = '\0'; //개행문자, 문장 단위로 읽음 ch = fgetc (fp); while (ch != EOF) { ie = 0; while (ch != '\n' && ch != EOF && i < SSIZE-2) { //문장끝 row[i++] = ch; if (um_end(ch)) ie = 1; //문장끝 부호(. ? !)가 있는지 여부 ch = fgetc (fp); } if (i >= SSIZE-2) break; row[i] = '\0'; rowp = str_trim_left (row); if (*rowp == '/' && *(rowp+1) == '/') { //주석 ch = fgetc (fp); i = 0; continue; } if (ch == '\n') row[i++] = ' '; ch = fgetc (fp); if (ch != EOF && !ie) continue; //문장끝이 아님으로 판단하고 계속 읽음 row[i] = '\0'; rowp = str_trim (row); //0:영문, 1:한글, -1:특수문자 idx = str_is_eng_kor (rowp); if (idx >= 0) { //캡션 문장인가? bcap = (*rowp == '*') ? true : false; str_copy (rows[idx], rowp); if (bcap) str_copy (caps[idx], rowp+1); brun = (mode) ? !idx: idx; //0:영문(한글번역), 1:한글(영문번역) if (brun && *rows[mode]) { if (bcap) { tw2_insertion_caption (ws, wi, mode, rs, qk, caps); //캡션 문장 저장 idx = str_len (caps[0]) - 1; caps[0][idx] = ' '; //마침표 제거 caps[0][idx+1] = '\0'; idx = str_len (caps[1]) - 1; caps[1][idx] = ' '; //마침표 제거 caps[1][idx+1] = '\0'; cnt = 0; } else { tw1_insertion_from_file (ws, wi, hb, mode, rs, qk, rows, -1); //저장 문장 수 누적 //캡션을 문장 머리에 붙여 저장 str_copy (row, caps[0]); str_cat (row, uint_to_str (cnt, capn)); str_cat (row, ": "); str_cat (row, rows[0]); str_copy (rows[0], row); str_copy (row, caps[0]); str_cat (row, uint_to_str (cnt, capn)); str_cat (row, ": "); str_cat (row, rows[1]); str_copy (rows[1], row); //캡션 문장은 해시값을 0으로 정함. cnt += tw1_insertion_from_file (ws, wi, hb, mode, rs, qk, rows, 0); cnt_sum++; } } } printf ("%c*line: %d/%d: ", CR, cnt_sum, ++rown); //라인 수 i = 0; } //while fclose (fp); printf ("%d rows have saved.\n", cnt_sum); return cnt_sum; //저장한 문장 수 }
std::string str_trim(const std::string &s) { return str_trim_left(str_trim_right(s)); }