int cd_dir( char *tpath_on_disk, char *default_dir, int verbose) { char *dir = NULL; int nb_found; int result; size_t i; DIR_ITEM *ditem; if (validate_regexp(tpath_on_disk) != NULL) { result = set_directory(default_dir, verbose); return result; } nb_found = 0; for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; ditem=get_next_dir_item(ditem)) { if (match(tpath_on_disk, ditem->tpath)) { i = strlen(ditem->tpath); if((i > 0 && ditem->tpath[i-1] == '/') || (i > 1 && ditem->tpath[i-2] == '/' && ditem->tpath[i-1] == '.')) { /* It is a directory */ char *dir1, *dir2; nb_found++; g_free(dir); dir = g_strdup(ditem->path); if(dir[strlen(dir)-1] == '/') dir[strlen(dir)-1] = '\0'; /* remove last / */ /* remove everything before the last / */ dir1 = strrchr(dir,'/'); if (dir1) { dir1++; dir2 = g_strdup(dir1); amfree(dir); dir = dir2; } } } } if(nb_found==0) { result = set_directory(default_dir, verbose); } else if(nb_found==1) { result = set_directory(dir, verbose); } else { g_printf(_("Too many directories matching '%s'\n"), default_dir); result = 0; } amfree(dir); return result; }
void tm_frame_rep::choose_file (object fun, string title, string type, string prompt, url name) { command cb = dialogue_command (get_server(), fun, 1); widget wid = file_chooser_widget (cb, type, prompt); if (!is_scratch (name)) { set_directory (wid, as_string (head (name))); if ((type != "image") && (type != "")) { url u= tail (name); string old_suf= suffix (u); string new_suf= format_to_suffix (type); if ((suffix_to_format (suffix (u)) != type) && (old_suf != "") && (new_suf != "")) { u= unglue (u, N(old_suf) + 1); u= glue (u, "." * new_suf); } set_file (wid, as_string (u)); } } else set_directory (wid, "."); dialogue_start (title, wid); if (type == "directory") send_keyboard_focus (get_directory (dialogue_wid)); else send_keyboard_focus (get_file (dialogue_wid)); }
void cd_dir( char * path_on_disk, char * default_dir) { char *path_on_disk_slash = NULL; char *dir = NULL; int nb_found; size_t i; DIR_ITEM *ditem; path_on_disk_slash = g_strconcat(path_on_disk, "/", NULL); nb_found = 0; for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; ditem=get_next_dir_item(ditem)) { if (match(path_on_disk, ditem->path) || match(path_on_disk_slash, ditem->path)) { i = strlen(ditem->path); if((i > 0 && ditem->path[i-1] == '/') || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.')) { /* It is a directory */ char *dir1, *dir2; nb_found++; g_free(dir); dir = g_strdup(ditem->path); if(dir[strlen(dir)-1] == '/') dir[strlen(dir)-1] = '\0'; /* remove last / */ /* remove everything before the last / */ dir1 = strrchr(dir,'/'); if (dir1) { dir1++; dir2 = g_strdup(dir1); amfree(dir); dir = dir2; } } } } amfree(path_on_disk_slash); if(nb_found==0) { set_directory(default_dir); } else if(nb_found==1) { set_directory(dir); } else { g_printf(_("Too many directory\n")); } amfree(dir); }
void process_list_change(HWND hWnd, Bool add_to_pl) { TCHAR sTxt[GF_MAX_PATH]; if (!SendMessage(hList, LB_GETSELCOUNT, 0, 0)) return; u32 idx = SendMessage(hList, LB_GETCURSEL, 0, 0); SendMessage(hList, LB_GETTEXT, idx, (LPARAM)(LPCTSTR) sTxt); DWORD param = SendMessage(hList, LB_GETITEMDATA, idx, 0); if (param==1) { if (!wcscmp(sTxt, _T("+ ..") ) ) { if (add_to_pl) return; current_dir[strlen((const char *) current_dir)-1] = 0; char *b = strrchr((const char *) current_dir, '\\'); if (b) b[1] = 0; else b[0] = '\\'; CE_CharToWide((char *) current_dir, (u16 *) w_current_dir); set_directory(w_current_dir); } else { if (add_to_pl) { char dir[MAX_PATH]; TCHAR wdir[MAX_PATH]; wcscpy(wdir, w_current_dir); wcscat(wdir, sTxt+2); wcscat(wdir, _T("\\")); CE_WideToChar((u16 *) wdir, (char *) dir); gf_enum_directory(dir, GF_FALSE, add_files, NULL, NULL); } else { wcscat(w_current_dir, sTxt+2); wcscat(w_current_dir, _T("\\")); CE_WideToChar((u16 *) w_current_dir, (char *) current_dir); set_directory(w_current_dir); } } } else { char szTxt[1024]; CE_WideToChar((u16 *) sTxt, (char *) szTxt); strcpy((char *) out_url, (const char *) current_dir); strcat(out_url, szTxt); if (add_to_pl) { gf_cfg_set_key(cfg, "Playlist", out_url, ""); strcpy(out_url, ""); } else { if (playlist_mode) { const char *file; char szPLE[20]; sprintf(szPLE, "%d", idx); gf_cfg_set_key(cfg, "General", "PLEntry", szPLE); file = gf_cfg_get_key_name(cfg, "Playlist", idx); strcpy(out_url, file); } gf_cfg_set_key(cfg, "General", "LastWorkingDir", (const char *) current_dir); EndDialog(hWnd, 1); } } }
void prim_frm(PRIM_PROTOTYPE) { char *filename; CHECKOP(1); oper1 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string."); if(!oper1->data.string) abort_interp("Argument 1 is a null string."); filename = oper1->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif result = unlink(filename); if(tp_log_files) log2filetime("logs/files", "#%d by %s FRM: %s \n", program, unparse_object(player, player), oper1->data.string->data); CLEAR(oper1); PushInt(result); }
void prim_fsize(PRIM_PROTOTYPE) { FILE *fh; char *filename; int result; long offset; CHECKOP(1); oper1 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if (oper1->type != PROG_STRING) abort_interp("Arguement 1 is not a string."); if (!oper1->data.string) abort_interp("Arguement 1 is a null string."); filename = oper1->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "r"); if (fh == NULL) { offset = -1; } else { fseek(fh, 0, SEEK_END); offset = ftell(fh); if(tp_log_files) log2filetime("logs/files", "#%d by %s FSIZE: %s \n", program, unparse_object(player, player), oper1->data.string->data); } fclose(fh); CLEAR(oper1); PushInt(offset); }
int unlock_buffer(char *srvName,char *dirName,char *idBucket,BUCKET_T *buffer){ char lock_flag; BUCKET_T header; header = *buffer; state = set_server(cluster,srvName,&ioctx); if(state < 0){ fprintf(stderr,"[unlock_buffer/iceph.c] Servidor não localizado!\n"); return 1; } //seta o diretorio state = set_directory(dirName,&ioctx); if(state >= 0){ lock_flag = '0'; //altera o valor do flag no sa state = write_object(ioctx,idBucket,&lock_flag,LOCK_FLAG_SIZE,0,0); if(state >= 0){ //altera no buffer *(header+LCKFLAG_OFFSET) = lock_flag; //altera o parametro locked no buffer_pool state = set_locked(idBucket,srvName,lock_flag); }else return 1; //retorna 1 pois nao conseguiu escrever no buffer }else{ fprintf(stderr,"[unlock_buffer/iceph.c] Diretório não localizado!\n"); return 1; } return 0; }
void cupsetup( int argc, char *argv[] ) { register int i; progname = argv[0]; /* Sorry for the pointer, but easy to expand argument, Suttipong */ while ( ( --argc > 0 ) && ( ( i = ( *++argv )[0] ) == '/' || i == '-' ) ) { strupr( ++argv[0] ); while ( i = *( argv[0]++ ) ) { switch ( i ) { case 'H': scrmode = HERCMONO; break; case 'E':/* e alone = ega, em = ega monochrome */ scrmode = EGA; break; case 'M':/* m alone = mcga */ if ( scrmode == EGA ) { scrmode = EGAMONO; } else { scrmode = MCGA; } break; case 'V': scrmode = VGA; break; case 'A': scrmode = ATT400; break; case 'L':/* /HL for Hercules, left-justified */ herc_align = 0; break; case 'N': case 'W': case 'P': break; default: usage( ); } } } if ( argc >= 1 && ( file_exist( argv[0] ) || strchr( argv[0], '*' ) || strchr( argv[0], '?' ) ) ) { placekey( RETKEY ); while ( i = *argv[0]++ ) { placekey( i ); } placekey( RETKEY ); } set_directory( ); readoption( AUTO_FIND ); readscrfont( dfont, "NORMAL.FON", cup_dir ); readscrfont( ditalicfont, "ITALIC.FON", cup_dir ); harderr( handler ); filename[0] = '\0'; }
/*prototipo: int getBucket(char *srvName,char *dirName,char *idBucket) *objetivo: Retorna um Bucket, de um Diretorio e Servidor especificados nos parametros de entrada*/ int ss_get_bucket(char *srvName,char *dirName,char *idBucket,BUCKET_T *buff_bucket,int* hit){ uint64_t len_bucket; time_t mtime; char path[PATH_SIZE+1]; *buff_bucket = NULL; *hit = 0; //0 sem cache 1 com cache snprintf(path,PATH_SIZE,"%s %s %s",srvName,dirName,idBucket); //cria um contexto de io no ceph, associando ao Pool que faz o papel de servidor state = set_server(cluster,srvName,&ioctx); if(state >= 0){ /*se o contexto for criado seta o diretorio *(associa uma chave ao contexto para influenciar o hash)*/ state = set_directory(dirName,&ioctx); /*obtem o tamanho do bucket e a data de modficacao *sera utilizado na leitura do bucket e para alocar memoria quando nao obtiver cache*/ state = get_object_size(ioctx, idBucket, &len_bucket, &mtime); if(state < 0){ fprintf(stderr,"[get_bucket/iceph.c] Bucket não localizado!\n"); destroy_ioctx(&ioctx); return 1; } }else{ fprintf(stderr,"[get_bucket/iceph.c] Servidor não localizado!\n"); destroy_ioctx(&ioctx); return 1; } /*busca no cache o Bucket desejado, se nao encontrar *requisita no sistema de armazenamento e disponibiliza no cache*/ *hit = get_buffer(idBucket,buff_bucket); if(*hit == 0){ //o bucket ainda nao foi para o buffer /*se tiver cache disponivel registra o bucket no cache *apos a execucao buff_bucket aponta para a area disponivel*/ *hit = put_buffer(idBucket,path,buff_bucket); if(*hit == 0) //se nao tiver cache disponivel aloca individual *buff_bucket = (BUCKET_T) xmalloc(len_bucket); //busca o bucket no sistema de armazenamento state = read_object(ioctx,idBucket,*buff_bucket,len_bucket,0,0); //IF TEMPORARIO APENAS DEBUG if(*hit == 1) fprintf(stdout,"[get_bucket/iceph.c] cache:\n"); else fprintf(stdout,"[get_bucket/iceph.c] no cache:\n"); }else //APENAS DEBUG fprintf(stdout,"[get_bucket/iceph.c] cache:\n"); destroy_ioctx(&ioctx); return ( (state >= 0) ? 0 : 1); }
/*prototipo: int get_lock(char *srvName,char *dirName,char *idBucket,BUCKET_T *buffer) *objetivo: verificar se o servidor que ira executar operacao de escrita adquiriu o lock ou nao*/ int get_lock(char *srvName,char *dirName,char *idBucket,BUCKET_T *buffer){ char lock_flag; BUCKET_T header; char lock_owner[SRVNAME_SIZE]; int locked; lock_flag = ' '; locked = 0; header = *buffer; memset(lock_owner,'\0',SRVNAME_SIZE); /*utilizar check_locked() para verifcar se o servidor ja adquiriu o lock se ele ja tiver adquirido lock, locked vai retornar 1 e lock_owner vai retornar o nome do servidor*/ state = check_locked(idBucket,srvName,&locked,lock_owner); /*somente sera requerido lock se nao houver lock no bufffer se o buffer ja tiver bloqueado pelo proprio servidor que esta pedindo vai retornar 1 permitindo a operacao de escrita*/ if((state == 1) && (locked == 0) && (strlen(lock_owner) == 0) ){ // conecta-se ao pool/servidor state = set_server(cluster,srvName,&ioctx); if(state < 0){ fprintf(stderr,"[get_lock/iceph.c] Servidor não localizado!\n"); return 1; } //seta o diretorio state = set_directory(dirName,&ioctx); if(state >= 0){ state = read_object(ioctx,idBucket,&lock_flag,LOCK_FLAG_SIZE,0,0); if(state >= 0){ if(lock_flag == '0'){ lock_flag = '1'; //altera o flag em disco state = write_object(ioctx,idBucket,&lock_flag,LOCK_FLAG_SIZE,0,0); if(state >= 0){ //altera no buffer *(header+LCKFLAG_OFFSET) = lock_flag; //altera o parametro locked no buffer_pool state = set_locked(idBucket,srvName,lock_flag); } }else return 0; }else return 0; //retorna 0 pois nao conseguir escrever no bucket }else{ fprintf(stderr,"[get_lock/iceph.c] Diretório não localizado!\n"); return 0; } header = NULL; }else if((state == 1) && (locked == 1)) return 1; //srvName ja adquiriu o lock neste buffer return 1; }
void prim_fren(PRIM_PROTOTYPE) { char *oldname, *newname; char tempB[BUFFER_LEN] = ""; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string."); if(!oper1->data.string) abort_interp("Argument 1 is a null string."); if(oper2->type != PROG_STRING) abort_interp("Argument 2 is not a string."); if(!oper2->data.string) abort_interp("Argument 2 is a null string."); newname = oper1->data.string->data; oldname = oper2->data.string->data; /* ( s<old> s<new> -- i ) */ #ifdef SECURE_FILE_PRIMS if (!(valid_name( newname ))) abort_interp( "Invalid file name. (2)"); if ( strchr( newname, '$' ) == NULL ) newname = set_directory(newname); else newname = parse_token( newname ); if ( newname == NULL ) abort_interp( "Invalid shortcut used. (2)" ); strcpy( tempB, newname ); if (!(valid_name(oldname))) abort_interp( "Invalid file name. (1)"); if ( strchr( oldname, '$' ) == NULL ) oldname = set_directory(oldname); else oldname = parse_token( oldname ); if ( oldname == NULL ) abort_interp( "Invalid shortcut used. (1)" ); newname = tempB; #endif result = rename(oldname, newname); if(tp_log_files) log2filetime("logs/files", "#%d by %s FREN: %s -> %s \n", program, unparse_object(player, player), oper2->data.string->data, oper1->data.string->data); CLEAR(oper1); CLEAR(oper2); PushInt(result); }
BOOL InitFileDialog(const HWND hWnd) { TCHAR psz[80]; ZeroMemory(psz, sizeof(psz)); SHINITDLGINFO sid; ZeroMemory(&sid, sizeof(sid)); sid.dwMask = SHIDIM_FLAGS; sid.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; sid.hDlg = hWnd; if (FALSE == SHInitDialog(&sid)) return FALSE; SHMENUBARINFO mbi; ZeroMemory(&mbi, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId = IDR_MENU_OPEN; mbi.hInstRes = g_hInst; if (FALSE == SHCreateMenuBar(&mbi)) { return FALSE; } g_hWndMenuBar = mbi.hwndMB; ShowWindow(g_hWndMenuBar, SW_SHOW); the_wnd = hWnd; hDirTxt = GetDlgItem(hWnd, IDC_DIRNAME); hList = GetDlgItem(hWnd, IDC_FILELIST); g_hMenuView = (HMENU)SendMessage(g_hWndMenuBar, SHCMBM_GETSUBMENU, 0, ID_OF_VIEW); RECT rc; GetClientRect(hWnd, &rc); u32 caption_h = GetSystemMetrics(SM_CYCAPTION) - 3; MoveWindow(hDirTxt, 0, 0, rc.right - rc.left, caption_h, 1); MoveWindow(hList, 0, caption_h, rc.right - rc.left, rc.bottom - rc.top - caption_h, 1); if (playlist_mode) { refresh_playlist(); } else { if (!strcmp((const char *) current_dir, "\\")) { char *opt = (char *) gf_cfg_get_key(cfg, "General", "LastWorkingDir"); if (opt) CE_CharToWide(opt, (u16 *) w_current_dir); } set_directory(w_current_dir); } switch_menu_pl(); return TRUE; }
/* *header definition *|----------|----------|----------|----------|----------| | LOCK |qtdChaves | bitmap | OFFSET#1 | LENGTH#1 | |----------|----------|----------|----------|----------| | KEY#1 | OFFSET#2 | LENGTH#2 | KEY#2 | OFFSET#N | |----------|----------|----------|----------|----------| | LENGTH#N | KEY#N | VALUE#1 ... VALUE#N | |----------|----------|--------------------------------| * *max_keys = inteiro *bitmap = variavel *key (char(10)) conteudo da chave *offset (int) = localizacao dentro do bucket do value (deslocamento em relacao ao inicio do arquivo) *length = int tamanho de value *value (variavel) = valor do par chave-valor * *slot (key+offset+length) */ int ss_create_bucket(char *srvName,char *dirName,char *idBucket,unsigned int maxKeys) { char *header; unsigned char bitMap[maxKeys+1]; unsigned int hsize,i; char caux[BYTES_LIMIT+1]; char lock_flag; size_t len_head; lock_flag = '0'; //gravacao do header //inicializacao do bitMap,preenche o vetor com zeros e o ultimo caracter nulo memset(bitMap,'\0',maxKeys+1); memset(bitMap,'0',maxKeys); //converte maxKeys para char[4]; ntochr(caux, maxKeys); //define o tamanho do header, para a criacao do bucket hsize = HEADER_SIZE(maxKeys); header = (unsigned char*) xmalloc(sizeof(unsigned char) * hsize); //inicializacao do header //escreve a qtd e chaves e o mapa de bits no header sprintf(header,"%c%s%s",lock_flag,caux,bitMap); //preenche o restante do header com espacos em branco len_head = strlen(header); memset(header+len_head,' ',hsize - len_head); //conecta no pool/servidor state = set_server(cluster,srvName,&ioctx); if(state >= 0){ //seta o diretorio state = set_directory(dirName,&ioctx); //grava o bucket no diretorio state = write_object_full(ioctx, idBucket, header, hsize); }else fprintf(stderr,"[create_bucket/iceph.c] Servidor não localizado!\n"); free(header); //encerra o contexto de io destroy_ioctx(&ioctx); return ((state >= 0)? 0 : 1); }
void prim_fread(PRIM_PROTOTYPE) { FILE *fh; char *filename; double offset; char tempchr[2]; int result; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if(oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer."); if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number."); if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string."); if(!oper2->data.string) abort_interp("Argueemnt 2 is a null string."); offset = oper1->data.number; filename = oper2->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "r"); if (fh == NULL) { result = 0; } else { fseek(fh, offset, SEEK_SET); tempchr[0] = (char) fgetc(fh); tempchr[1] = '\0'; fclose(fh); sprintf(buf, "%s", tempchr); result = 1; if(tp_log_files) log2filetime("logs/files", "#%d by %s FREAD: %s \n", program, unparse_object(player, player), oper2->data.string->data); if ( tempchr[0] == EOF ) result = 0; } CLEAR(oper1); CLEAR(oper2); if( result ) PushString(buf); else PushNullStr; }
void prim_bwrite(PRIM_PROTOTYPE) { FILE *fh; char *filename; int result, tempdat; double offset; CHECKOP(3); oper1 = POP(); oper2 = POP(); oper3 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if (oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer."); if (oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number."); if (oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string."); if (!oper2->data.string) abort_interp("Arguement 2 is a null string."); if (oper3->type != PROG_INTEGER) abort_interp("Arguement 3 is not an integer."); if (oper3->data.number < 0 ) abort_interp("Arguement 3 is a negative number."); offset = oper1->data.number; filename = oper2->data.string->data; tempdat = (int) oper3->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "w"); if (fh == NULL) { result = 0; } else { fseek(fh, offset, SEEK_SET); fputc(tempdat - 8, fh); fclose(fh); result = 1; if(tp_log_files) log2filetime("logs/files", "#%d by %s BWRITE : %s \n", program, unparse_object(player, player), oper2->data.string->data); } CLEAR(oper1); CLEAR(oper2); CLEAR(oper3); PushInt(result); }
/*prototipo int write_buffer_disk(char* srvName,char* dirName,char *idBucket,BUCKET_T *buffer,size_t len_buffer){ * descricao: escreve o buffer do bucket em disco, esta funcao deve ficar neste arquivo * pois a escrita do buffer em disco depende da interface do sa * parametros: srvName ->servidor em que o bucket esta armazenado * dirName -> diretorio em que o bucket esta armazenado * idBucket -> identificador do bucket * buffer -> buffer que sera gravado * len_buffer -> tamanho do buffer que sera gravado * retorno: inteiro indicativo de sucesso ou falha da operacao*/ int write_buffer_disk(char* srvName,char* dirName,char *idBucket,BUCKET_T *buffer,size_t len_buffer){ // conecta-se ao pool/servidor state = set_server(cluster,srvName,&ioctx); if(state < 0){ fprintf(stderr,"[write_buffer_disk/iceph.c] Servidor não localizado!\n"); return 1; } //seta o diretorio state = set_directory(dirName,&ioctx); if(state >= 0) state = write_object_full(ioctx, idBucket,*buffer, len_buffer); destroy_ioctx(&ioctx); return state; }
void prim_bread(PRIM_PROTOTYPE) { FILE *fh; /* Should return -1 for file open error. */ char *filename; /* -2 for EOF. */ double offset; int result; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if(oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer."); if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number."); if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string."); if(!oper2->data.string) abort_interp("Argueemnt 2 is a null string."); offset = oper1->data.number; filename = oper2->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "r"); if (fh == NULL) { result = -1; } else { fseek(fh, offset, SEEK_SET); result = fgetc(fh); if(tp_log_files) log2filetime("logs/files", "#%d by %s BREAD: %s \n", program, unparse_object(player, player), oper2->data.string->data); if (result == EOF) { result = -2; } fclose(fh); } CLEAR(oper1); CLEAR(oper2); PushInt(result); }
/*prototipo: int drop_bucket(char *idBucket,char *dirName,char *srvrName) *objetivo: Remove um Bucket, do Servidor e Diretório especificados por *parametros em conjunto com o identificador do Bucket*/ int ss_drop_bucket(char *idBucket,char *dirName,char *srvName) { // conecta no pool/servidor state = set_server(cluster, srvName,&ioctx); if(state >= 0){ //seta o diretorio state = set_directory(dirName,&ioctx); /* remove o bucket do Diretorio se a operacao falhar error > 0*/ state = remove_object(ioctx,idBucket); } else fprintf(stderr,"[drop_bucket/iceph.c] Servidor não localizado!\n"); destroy_ioctx(&ioctx); return ((state >= 0)? 0 : 1); }
void prim_fappend(PRIM_PROTOTYPE) { FILE *fh; char *filename; char *writestring; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (getuid() == 0 ) abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string."); if(!oper1->data.string) abort_interp("Argument 1 is a null string."); if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string."); if(!oper2->data.string) abort_interp("Arguement 2 is a null string."); filename = oper1->data.string->data; writestring = oper2->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "a"); if (fh == NULL) { result = 0; } else { fputs(writestring, fh); fclose(fh); result = 1; if(tp_log_files) log2filetime("logs/files", "#%d by %s FAPPEND: %s \n", program, unparse_object(player, player), oper1->data.string->data); } CLEAR(oper1); CLEAR(oper2); PushInt(result); }
void parse_option(struct file_system_info *fsinfo, int argc, char **argv, int *index){ if ((strcmp(argv[*index], OPT_INCREMENTS) == 0) || (strcmp(argv[*index], OPT_INCREMENTS_FULL) == 0)){ if (set_increments(argc, argv, index) != 0) fail(ERR_PARAMETRES); } else if ((strcmp(argv[*index], OPT_FULL) == 0) || (strcmp(argv[*index], OPT_FULL_FULL) == 0)) structure = STRUCTURE_FULL; else if ((strcmp(argv[*index], OPT_LAST) == 0) || (strcmp(argv[*index], OPT_LAST_FULL) == 0)) { layout = LAYOUT_LAST; structure = STRUCTURE_FULL; } else if ((strcmp(argv[*index], OPT_CACHING) == 0) || (strcmp(argv[*index], OPT_CACHING_FULL) == 0)){ if (set_caching(argc, argv, index) != 0) fail(ERR_PARAMETRES); } else if ((strcmp(argv[*index], OPT_DIR) == 0) || (strcmp(argv[*index], OPT_DIR_FULL) == 0)){ if (set_directory(argc, argv, index) != 0) fail(ERR_PARAMETRES); } else if ((strcmp(argv[*index], OPT_VERSION) == 0) || (strcmp(argv[*index], OPT_VERSION_FULL) == 0)) { printf(PROGRAM_NAME " - filesystem in userspace for rdiff-backup repositories; version %s\n", PACKAGE_VERSION); exit(0); } else if (strcmp(argv[*index], OPT_DEBUG_FULL) == 0) { if (set_debug_level(argc, argv, index) != 0) fail(ERR_PARAMETRES); } else if (strcmp(argv[*index], OPT_FUSE) == 0) { if (add_fuse_option(argc, argv, index) != 0) fail(ERR_PARAMETRES); } else if (strcmp(argv[*index], OPT_DIR_LOCAL_TIME_FULL) == 0) fsinfo->rev_dir_time = REV_LOCAL_TIME; else fail(ERR_UNKNOWN_OPTION); };
BOOL CALLBACK FileDialogProc(const HWND hWnd, const UINT Msg, const WPARAM wParam, const LPARAM lParam) { BOOL bProcessedMsg = TRUE; switch (Msg) { case WM_INITDIALOG: if (FALSE == InitFileDialog(hWnd)) EndDialog(hWnd, -1); break; case WM_ACTIVATE: if (WA_INACTIVE != LOWORD(wParam)) SetFocus(hWnd); break; case WM_CLOSE: EndDialog(hWnd, 0); break; case WM_COMMAND: if (LOWORD(wParam) == IDC_FILELIST) { if (HIWORD(wParam) == LBN_DBLCLK) { process_list_change(hWnd, GF_FALSE); } else { bProcessedMsg = FALSE; } } else { switch (LOWORD(wParam)) { case IDOK: process_list_change(hWnd, GF_FALSE); break; case IDCANCEL: EndDialog(hWnd, 0); break; case IDM_OF_VIEW_ALL: bViewUnknownTypes = (Bool) !bViewUnknownTypes; refresh_menu_states(); set_directory(w_current_dir); break; case IDM_OF_PLAYLIST: playlist_mode = (Bool) !playlist_mode; if (playlist_mode) refresh_playlist(); else set_directory(w_current_dir); switch_menu_pl(); break; case IDM_OF_PL_ACT: if (playlist_mode) { playlist_act(0); } else { process_list_change(hWnd, GF_TRUE); } break; case IDM_OF_PL_UP: playlist_act(1); break; case IDM_OF_PL_DOWN: playlist_act(2); break; case IDM_OF_PL_CLEAR: playlist_act(3); break; default: bProcessedMsg = FALSE; break; } } break; case WM_KEYDOWN: switch (wParam) { case VK_LEFT: case '1': playlist_act(1); break; case VK_RIGHT: case '2': playlist_act(2); break; default: bProcessedMsg = FALSE; break; } break; default: bProcessedMsg = FALSE; } return bProcessedMsg; }
int main( int argc, char ** argv) { in_port_t my_port; struct servent *sp; int i; time_t timer; char *lineread = NULL; struct sigaction act, oact; extern char *optarg; extern int optind; char cwd[STR_SIZE], *dn_guess = NULL, *mpt_guess = NULL; char *service_name; char *line = NULL; struct tm *tm; /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); safe_fd(-1, 0); set_pname("amoldrecover"); /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); dbopen(DBG_SUBDIR_CLIENT); localhost = g_malloc(MAX_HOSTNAME_LENGTH+1); if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) { error(_("cannot determine local host name\n")); /*NOTREACHED*/ } localhost[MAX_HOSTNAME_LENGTH] = '\0'; g_free(config); config = g_strdup(DEFAULT_CONFIG); dbrename(config, DBG_SUBDIR_CLIENT); check_running_as(RUNNING_AS_ROOT); amfree(server_name); server_name = getenv("AMANDA_SERVER"); if(!server_name) server_name = DEFAULT_SERVER; server_name = g_strdup(server_name); amfree(tape_server_name); tape_server_name = getenv("AMANDA_TAPESERVER"); if(!tape_server_name) tape_server_name = DEFAULT_TAPE_SERVER; tape_server_name = g_strdup(tape_server_name); config_init(CONFIG_INIT_CLIENT, NULL); if (config_errors(NULL) >= CFGERR_WARNINGS) { config_print_errors(); if (config_errors(NULL) >= CFGERR_ERRORS) { g_critical(_("errors processing config file")); } } if (argc > 1 && argv[1][0] != '-') { /* * If the first argument is not an option flag, then we assume * it is a configuration name to match the syntax of the other * Amanda utilities. */ char **new_argv; new_argv = (char **) g_malloc((size_t)((argc + 1 + 1) * sizeof(*new_argv))); new_argv[0] = argv[0]; new_argv[1] = "-C"; for (i = 1; i < argc; i++) { new_argv[i + 1] = argv[i]; } new_argv[i + 1] = NULL; argc++; argv = new_argv; } while ((i = getopt(argc, argv, "C:s:t:d:U")) != EOF) { switch (i) { case 'C': g_free(config); config = g_strdup(optarg); break; case 's': g_free(server_name); server_name = g_strdup(optarg); break; case 't': g_free(tape_server_name); tape_server_name = g_strdup(optarg); break; case 'd': g_free(tape_device_name); tape_device_name = g_strdup(optarg); break; case 'U': case '?': (void)g_printf(USAGE); return 0; } } if (optind != argc) { (void)g_fprintf(stderr, USAGE); exit(1); } amfree(disk_name); amfree(mount_point); amfree(disk_path); dump_date[0] = '\0'; /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); /* set up signal handler */ act.sa_handler = sigint_handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; #ifdef SA_RESTORER act.sa_restorer = NULL; #endif if (sigaction(SIGINT, &act, &oact) != 0) { error(_("error setting signal handler: %s"), strerror(errno)); /*NOTREACHED*/ } service_name = "amandaidx"; g_printf(_("AMRECOVER Version %s. Contacting server on %s ...\n"), VERSION, server_name); if ((sp = getservbyname(service_name, "tcp")) == NULL) { error(_("%s/tcp unknown protocol"), service_name); /*NOTREACHED*/ } server_socket = stream_client_privileged(server_name, (in_port_t)ntohs((in_port_t)sp->s_port), 0, 0, &my_port, 0); if (server_socket < 0) { error(_("cannot connect to %s: %s"), server_name, strerror(errno)); /*NOTREACHED*/ } if (my_port >= IPPORT_RESERVED) { aclose(server_socket); error(_("did not get a reserved port: %d"), my_port); /*NOTREACHED*/ } /* get server's banner */ if (grab_reply(1) == -1) { aclose(server_socket); exit(1); } if (!server_happy()) { dbclose(); aclose(server_socket); exit(1); } /* do the security thing */ line = get_security(); if (converse(line) == -1) { aclose(server_socket); exit(1); } if (!server_happy()) { aclose(server_socket); exit(1); } memset(line, '\0', strlen(line)); amfree(line); /* try to get the features from the server */ { char *our_feature_string = NULL; char *their_feature_string = NULL; our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); line = g_strconcat("FEATURES ", our_feature_string, NULL); if(exchange(line) == 0) { their_feature_string = g_strdup(server_line+13); indexsrv_features = am_string_to_feature(their_feature_string); } else { indexsrv_features = am_set_default_feature_set(); } amfree(our_feature_string); amfree(their_feature_string); amfree(line); } /* set the date of extraction to be today */ (void)time(&timer); tm = localtime(&timer); if (tm) strftime(dump_date, sizeof(dump_date), "%Y-%m-%d", tm); else error(_("BAD DATE")); g_printf(_("Setting restore date to today (%s)\n"), dump_date); line = g_strconcat("DATE ", dump_date, NULL); if (converse(line) == -1) { aclose(server_socket); exit(1); } amfree(line); line = g_strconcat("SCNF ", config, NULL); if (converse(line) == -1) { aclose(server_socket); exit(1); } amfree(line); if (server_happy()) { /* set host we are restoring to this host by default */ amfree(dump_hostname); set_host(localhost); if (dump_hostname) { /* get a starting disk and directory based on where we currently are */ switch (guess_disk(cwd, sizeof(cwd), &dn_guess, &mpt_guess)) { case 1: /* okay, got a guess. Set disk accordingly */ g_printf(_("$CWD '%s' is on disk '%s' mounted at '%s'.\n"), cwd, dn_guess, mpt_guess); set_disk(dn_guess, mpt_guess); set_directory(cwd); if (server_happy() && !g_str_equal(cwd, mpt_guess)) g_printf(_("WARNING: not on root of selected filesystem, check man-page!\n")); amfree(dn_guess); amfree(mpt_guess); break; case 0: g_printf(_("$CWD '%s' is on a network mounted disk\n"), cwd); g_printf(_("so you must 'sethost' to the server\n")); /* fake an unhappy server */ server_line[0] = '5'; break; case 2: case -1: default: g_printf(_("Use the setdisk command to choose dump disk to recover\n")); /* fake an unhappy server */ server_line[0] = '5'; break; } } } quit_prog = 0; do { if ((lineread = readline("amrecover> ")) == NULL) { clearerr(stdin); putchar('\n'); break; } if (lineread[0] != '\0') { add_history(lineread); process_line(lineread); /* act on line's content */ } amfree(lineread); } while (!quit_prog); dbclose(); aclose(server_socket); return 0; }
BOOL LASwriteOpener::parse(int argc, char* argv[]) { int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '\0') { continue; } else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0) { usage(); return TRUE; } else if (strcmp(argv[i],"-o") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: file_name\n", argv[i]); return FALSE; } set_file_name(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-odir") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: directory\n", argv[i]); return FALSE; } set_directory(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-odix") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: appendix\n", argv[i]); return FALSE; } set_appendix(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-ocut") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: number of characters to cut\n", argv[i]); return FALSE; } set_cut(atoi(argv[i+1])); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-oforce") == 0) { force = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-olas") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_LAS; *argv[i]='\0'; } else if (strcmp(argv[i],"-olaz") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_LAZ; *argv[i]='\0'; } else if (strcmp(argv[i],"-otxt") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_TXT; *argv[i]='\0'; } else if (strcmp(argv[i],"-obin") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_BIN; *argv[i]='\0'; } else if (strcmp(argv[i],"-oqi") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_QFIT; *argv[i]='\0'; } else if (strcmp(argv[i],"-owrl") == 0) { specified = TRUE; format = LAS_TOOLS_FORMAT_VRML; *argv[i]='\0'; } else if (strcmp(argv[i],"-stdout") == 0) { use_stdout = TRUE; use_nil = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-nil") == 0) { use_nil = TRUE; use_stdout = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-buffered") == 0) { buffered = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-v1") == 0) { use_v1 = TRUE; use_chunking = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-v2") == 0) { use_v1 = FALSE; use_chunking = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-no_chunk") == 0) { use_chunking = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-chunk") == 0) { use_chunking = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-chunk_size") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: number_points\n", argv[i]); return FALSE; } use_chunking = TRUE; chunk_size = atoi(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-oparse") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: string\n", argv[i]); return FALSE; } set_parse_string(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-osep") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: separator\n", argv[i]); return FALSE; } set_separator(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-oscale_rgb") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: scale\n", argv[i]); return FALSE; } set_scale_rgb((F32)atof(argv[i+1])); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-opts") == 0) { opts = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-optx") == 0) { optx = TRUE; *argv[i]='\0'; } } return TRUE; }
/* * RTEMS Startup task */ rtems_task Init (rtems_task_argument ignored) { int i; char *argv[3] = { NULL, NULL, NULL }; char *cp; rtems_task_priority newpri; rtems_status_code sc; rtems_time_of_day now; /* * Explain why we're here */ logReset(); /* * Architecture-specific hooks */ if (epicsRtemsInitPreSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPreSetBootConfigFromNVRAM"); if (rtems_bsdnet_config.bootp == NULL) { extern void setBootConfigFromNVRAM(void); setBootConfigFromNVRAM(); } if (epicsRtemsInitPostSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPostSetBootConfigFromNVRAM"); /* * Override RTEMS configuration */ rtems_task_set_priority ( RTEMS_SELF, epicsThreadGetOssPriorityValue(epicsThreadPriorityIocsh), &newpri); /* * Create a reasonable environment */ initConsole (); putenv ("TERM=xterm"); putenv ("IOCSH_HISTSIZE=20"); /* * Display some OS information */ printf("\n***** RTEMS Version: %s *****\n", rtems_get_version_string()); /* * Start network */ if ((cp = getenv("EPICS_TS_NTP_INET")) != NULL) rtems_bsdnet_config.ntp_server[0] = cp; if (rtems_bsdnet_config.network_task_priority == 0) { unsigned int p; if (epicsThreadHighestPriorityLevelBelow(epicsThreadPriorityScanLow, &p) == epicsThreadBooleanStatusSuccess) { rtems_bsdnet_config.network_task_priority = epicsThreadGetOssPriorityValue(p); } } printf("\n***** Initializing network *****\n"); rtems_bsdnet_initialize_network(); initialize_remote_filesystem(argv, initialize_local_filesystem(argv)); /* * More environment: iocsh prompt and hostname */ { char hostname[1024]; gethostname(hostname, 1023); char *cp = mustMalloc(strlen(hostname)+3, "iocsh prompt"); sprintf(cp, "%s> ", hostname); epicsEnvSet ("IOCSH_PS1", cp); epicsEnvSet("IOC_NAME", hostname); } /* * Use BSP-supplied time of day if available otherwise supply default time. * It is very likely that other time synchronization facilities in EPICS * will soon override this value. */ if (rtems_clock_get(RTEMS_CLOCK_GET_TOD,&now) != RTEMS_SUCCESSFUL) { now.year = 2001; now.month = 1; now.day = 1; now.hour = 0; now.minute = 0; now.second = 0; now.ticks = 0; if ((sc = rtems_clock_set (&now)) != RTEMS_SUCCESSFUL) printf ("***** Can't set time: %s\n", rtems_status_text (sc)); } if (getenv("TZ") == NULL) { const char *tzp = envGetConfigParamPtr(&EPICS_TIMEZONE); if (tzp == NULL) { printf("Warning -- no timezone information available -- times will be displayed as GMT.\n"); } else { char tz[10]; int minWest, toDst = 0, fromDst = 0; if(sscanf(tzp, "%9[^:]::%d:%d:%d", tz, &minWest, &toDst, &fromDst) < 2) { printf("Warning: EPICS_TIMEZONE (%s) unrecognizable -- times will be displayed as GMT.\n", tzp); } else { char posixTzBuf[40]; char *p = posixTzBuf; p += sprintf(p, "%cST%d:%.2d", tz[0], minWest/60, minWest%60); if (toDst != fromDst) p += sprintf(p, "%cDT", tz[0]); epicsEnvSet("TZ", posixTzBuf); } } } tzset(); osdTimeRegister(); /* * Run the EPICS startup script */ printf ("***** Starting EPICS application *****\n"); iocshRegisterRTEMS (); set_directory (argv[1]); epicsEnvSet ("IOC_STARTUP_SCRIPT", argv[1]); atexit(exitHandler); i = main ((sizeof argv / sizeof argv[0]) - 1, argv); printf ("***** IOC application terminating *****\n"); epicsThreadSleep(1.0); epicsExit(0); }
void prim_freadn(PRIM_PROTOTYPE) { FILE *fh; char *filename; double offset; double range; char tempBuf[BUFFER_LEN] = ""; int result; int i; int found_end = 0; char tempChr; CHECKOP(3); oper1 = POP(); /*The range*/ oper2 = POP(); /*The offset*/ oper3 = POP(); /*The filename*/ if (getuid() == 0 ) /*Permissions checks*/ abort_interp("Muck is running under root privs, file prims disabled."); if (mlev < LBOY) abort_interp("BOY primitive only."); /*Type Checking*/ if(oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer."); if(oper1->data.number > BUFFER_LEN - 10) abort_interp("Range is too large. (1)"); if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number."); if(oper2->type != PROG_INTEGER) abort_interp("Arguement 2 is not an integer."); if(oper2->data.number < 0 ) abort_interp("Arguement 2 is a negative number."); if(oper3->type != PROG_STRING) abort_interp("Arguement 3 is not a string."); if(!oper3->data.string) abort_interp("Argueemnt 3 is a null string."); /*Value assignments*/ range = oper1->data.number; offset = oper2->data.number; filename = oper3->data.string->data; #ifdef SECURE_FILE_PRIMS if (!(valid_name(filename))) abort_interp( "Invalid file name."); if ( strchr( filename, '$' ) == NULL ) filename = set_directory(filename); else filename = parse_token( filename ); if ( filename == NULL ) abort_interp( "Invalid shortcut used." ); #endif fh = fopen(filename, "r"); if (fh == NULL) { result = 0; } else { for ( i = 0; i < range && found_end != 1; i++, offset++ ) { fseek(fh, offset, SEEK_SET); tempChr = (char) fgetc(fh); if (tempChr == EOF) found_end = 1; else tempBuf[i] = tempChr; } i++; tempBuf[i] = '\0'; fclose(fh); if ( tempBuf[0] != EOF ) result = 1; if(tp_log_files) log2filetime("logs/files", "#%d by %s FREADN: %s \n", program, unparse_object(player, player), oper3->data.string->data); } CLEAR(oper1); CLEAR(oper2); CLEAR(oper3); if( result ) PushString(tempBuf); else PushNullStr; }
static void ScanConflicts(char *path, unsigned inx, int argc, char **argv) { DIR *dp; struct dirent *de; struct stat sb; int j; unsigned k; #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX char save_wd[MAXPATHLEN]; #endif /* * When scanning a directory, we first chdir to it, mostly to make * the scan+stat work faster, but also because some systems don't * scan properly otherwise. * * MSDOS and OS/2 are a little more complicated, because each drive * has its own current directory. */ #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX (void) strcpy(save_wd, dot); if (!strcmp(".", path)) { path = dot; } else if (!same_drive(dot, path)) { if (!set_drive(path)) return; getwd(save_wd); } #endif if (v_opt > 2) printf("ScanConflicts \"%s\"\n", path); if (set_directory(path) && (dp = opendir(path)) != NULL) { while ((de = readdir(dp)) != NULL) { register type_t ok = 0; int found = FALSE; char buffer[MAXPATHLEN]; char *the_name; char *the_NAME; if (do_blips) blip('.'); (void) sprintf(buffer, "%.*s", (int) NAMLEN(de), de->d_name); the_name = MakeString(DOS_upper(buffer)); the_NAME = ToCompare(the_name); /* If arguments are given, restrict search to them */ if (argc > optind) { for (j = optind; j < argc; j++) { if (SameName(argv[j], the_name)) { found = TRUE; break; } } if (!found) continue; } /* Verify that the name is a file, and executable */ if (stat(the_name, &sb) < 0) continue; if ((sb.st_mode & S_IFMT) != S_IFREG) continue; #if SYS_UNIX || SYS_OS2 || SYS_OS2_EMX if (access(the_name, acc_mask) < 0) continue; ok = 1; #endif if (FileTypes != 0) { if ((ok = LookupType(the_name)) == 0) continue; } /* Find the name in our array of all names */ found = FALSE; for (k = 0; k < total; k++) { if (SameName(inpath[k].ip_NAME, the_NAME)) { FoundNode(&inpath[k], inx); found = TRUE; break; } } /* If not there, add it */ if (found) { if (the_NAME != the_name) { FreeString(the_NAME); } } else { if (!(total & CHUNK)) { size_t need = (((total * 3) / 2) | CHUNK) + 1; if (inpath != 0) inpath = TypeRealloc(INPATH, inpath, need); else inpath = TypeAlloc(INPATH, need); } j = (int) total++; inpath[j].ip_name = the_name; inpath[j].ip_NAME = the_NAME; inpath[j].node = TypeAlloc(NODE, path_len); FoundNode(&inpath[j], inx); } if (v_opt > 2) { (void) printf("%c %s%c%s\n", found ? '+' : '*', path, PATHNAME_SEP, buffer); } } (void) closedir(dp); } #if SYS_MSDOS || SYS_OS2 || SYS_WIN32 || SYS_OS2_EMX if (strcmp(dot, save_wd)) { chdir(save_wd); } #endif (void) set_directory(dot); }
BOOL PULSEwriteOpener::parse(int argc, char* argv[]) { int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '\0') { continue; } else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0) { usage(); return TRUE; } else if (strcmp(argv[i],"-o") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: file_name\n", argv[i]); return FALSE; } set_file_name(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-odir") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: directory\n", argv[i]); return FALSE; } set_directory(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-odix") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: appendix\n", argv[i]); return FALSE; } set_appendix(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-opls") == 0) { format = PULSEWAVES_FORMAT_PLS; *argv[i]='\0'; } else if (strcmp(argv[i],"-otxt") == 0) { format = PULSEWAVES_FORMAT_TXT; *argv[i]='\0'; } else if (strcmp(argv[i],"-oplz") == 0) { format = PULSEWAVES_FORMAT_PLZ; compress_waves = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-owvz") == 0) { compress_waves = TRUE; *argv[i]='\0'; } else if (strcmp(argv[i],"-stdout") == 0) { use_stdout = TRUE; use_nil = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-nil") == 0) { use_nil = TRUE; use_stdout = FALSE; *argv[i]='\0'; } else if (strcmp(argv[i],"-oparse") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: string\n", argv[i]); return FALSE; } set_parse_string(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-sep") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: separator\n", argv[i]); return FALSE; } set_separator(argv[i+1]); *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } } return TRUE; }