📄 misc.c
字号:
while(*s!='\0') { *s=toupper(*s); s++; } #endif}#endif#if SFX_LEVEL>=ARJSFXV/* Convert a string to lowercase (note: no locale hack here - the one in strupper() was made exclusively for filename matching under DOS) */void strlower(char *s){ while(*s!='\0') { *s=tolower(*s); s++; }}#endif#if SFX_LEVEL>=ARJ/* Finds an entry in the filelist, returns 1 if matched. Wildcards allowed. */int flist_find(struct flist_root *root, char *name){ char tmp_name[FILENAME_MAX]; /* Hash filename storage */ char n_path[FILENAME_MAX], f_path[FILENAME_MAX]; FILE_COUNT entry; int pathname_length; int tmp_pathname_length; if(root==NULL) return(0); pathname_length=split_name(name, n_path, NULL); for(entry=0; entry<root->files; entry++) { flist_retrieve(tmp_name, NULL, root, entry); tmp_pathname_length=split_name(tmp_name, f_path, NULL); if(marksym_expansion) { if(tmp_pathname_length!=0&&strlen(tmp_name)==tmp_pathname_length&&xwild_compare(f_path, n_path)==XW_OK) return(1); if(tmp_pathname_length==0||xwild_compare(f_path, n_path)==XW_OK) { if(xwild_compare(tmp_name+tmp_pathname_length, name+pathname_length)==XW_OK) return(1); } } else { /* If it was a directory specification, return OK */ if(tmp_pathname_length!=0&&strlen(tmp_name)==tmp_pathname_length&&!strncmp_os(tmp_name, name, tmp_pathname_length)) return(1); /* For filename specifications, proceed with compare */ if(tmp_pathname_length==0||(tmp_pathname_length==pathname_length&&!strncmp_os(tmp_name, name, tmp_pathname_length))) if(match_wildcard(&name[pathname_length], &tmp_name[tmp_pathname_length])) return(1); } } return(0);}/* Checks if a file already exists in the archive */int flist_is_in_archive(struct flist_root *root, char *name){ char tmp_name[CCHMAXPATHCOMP]; /* For names retrieved from the hash */ char case_name[CCHMAXPATHCOMP]; /* and for converting them to u-case */ FILE_COUNT entry; for(entry=0; entry<root->files; entry++) { if(cfa_get(entry)==FLFLAG_PROCESSED) { flist_retrieve(tmp_name, NULL, root, entry); default_case_path(case_name, tmp_name); if(!stricmp(name, case_name)) return(1); } } return(0);}/* Returns 1 if the file properties given match the current search narrowing criteria (such as "same or newer", and so on) */int match_attrib(struct file_properties *properties){ int matched; /* First, check if the attributes match */ if(filter_attrs) { matched=0; if(file_attr_mask&TAG_DIREC&&properties->type==ARJT_DIR) matched=1; if(file_attr_mask&TAG_UXSPECIAL&&properties->type==ARJT_UXSPECIAL) matched=1; if(file_attr_mask&TAG_NORMAL&& !(properties->attrib&FATTR_DIREC)&& !(properties->attrib&FATTR_RDONLY)&& !(properties->attrib&FATTR_SYSTEM)&& !(properties->attrib&FATTR_HIDDEN)&& properties->type!=ARJT_UXSPECIAL) matched=1; if(file_attr_mask&TAG_RDONLY&&properties->attrib&FATTR_RDONLY) matched=1; if(file_attr_mask&TAG_HIDDEN&&properties->attrib&FATTR_HIDDEN) matched=1; if(file_attr_mask&TAG_SYSTEM&&properties->attrib&FATTR_SYSTEM) matched=1; if(file_attr_mask&TAG_ARCH&&!(properties->attrib&FATTR_ARCH)) return(0); if(file_attr_mask&TAG_NOT_ARCH&&properties->attrib&FATTR_ARCH) return(0); if(!matched) return(0); } if(filter_fa_arch==FAA_BACKUP||filter_fa_arch==FAA_BACKUP_CLEAR) { if(!properties->isarchive) return(0); } /* Now, check the file against the time limits for it */ /* ftime */ if(ts_valid(tested_ftime_newer)&&(filter_same_or_newer==TCHECK_NDAYS||filter_same_or_newer==TCHECK_FTIME)) { if(properties->ftime<ts_native(&tested_ftime_newer, OS)) return(0); } if(ts_valid(tested_ftime_older)&&(filter_older==TCHECK_NDAYS||filter_older==TCHECK_FTIME)) { if(properties->ftime>=ts_native(&tested_ftime_older, OS)) return(0); } /* ctime */ if(ts_valid(tested_ftime_newer)&&filter_same_or_newer==TCHECK_CTIME) { if(properties->ctime<ts_native(&tested_ftime_newer, OS)) return(0); } if(ts_valid(tested_ftime_older)&&filter_older==TCHECK_CTIME) { if(properties->ctime>=ts_native(&tested_ftime_older, OS)) return(0); } /* atime */ if(ts_valid(tested_ftime_newer)&&filter_same_or_newer==TCHECK_ATIME) { if(properties->atime<ts_native(&tested_ftime_newer, OS)) return(0); } if(ts_valid(tested_ftime_older)&&filter_older==TCHECK_ATIME) { if(properties->atime>=ts_native(&tested_ftime_older, OS)) return(0); } return(1);}/* Frees memory allocated for the hash table */void flist_cleanup(struct flist_root *root){ flist_cleanup_proc(root);}/* Adds an entry to the filelist if it does not already exist. Returns -1 if an error occured. */int flist_add(struct flist_root *root, struct flist_root *search_flist, char *name, FILE_COUNT *count, struct file_properties *properties){ FILE_COUNT i; if(search_flist!=NULL) { /* If an existing entry has been found, don't add anything */ if(flist_find(search_flist, name)) { if(count!=NULL) (*count)++; return(0); } } if(root!=NULL&&root->fsptr!=NULL&&!xwild_compare(root->fsptr, name)) { if(count!=NULL) (*count)++; return(0); } if(properties!=NULL&&root==&flist_main&&!match_attrib(properties)) { if(count!=NULL) (*count)++; return(0); } #if TARGET==UNIX /* Resolve hard links if there are any */ if(properties!=NULL&& properties->l_search.refcount>1&& !suppress_hardlinks) link_search(&l_entries, &properties->l_search, properties, root->files); #endif return(add_entry(root, name, count, properties));}/* Initializes the filelist storage structures */void flist_init(struct flist_root *root, FILE_COUNT maxfiles, char type){ flist_init_proc(root, maxfiles, type);}/* Retrieves an entry from the filelist */void flist_retrieve(char *dest, struct file_properties *properties, struct flist_root *root, FILE_COUNT entry){ retrieve_entry(dest, properties, root, entry);}/* Converts an extended wildcard to canonical wildcard */static void xwild_to_canonical(char *name){ char *tmp_name; char *xwptr; int entry; tmp_name=malloc_str(name); xwptr=strpbrk(tmp_name, xwild_symbols); if(xwptr!=NULL) { *(xwptr+1)='\0'; entry=split_name(tmp_name, NULL, NULL); if(entry>0) { tmp_name[entry-1]='\0'; sprintf(name, "%s%c%s", tmp_name, PATHSEP_DEFAULT, all_wildcard); } else strcpy(name, all_wildcard); } free(tmp_name);}#endif#if SFX_LEVEL>=ARJSFXV/* Expands wildcards and prepares a file list */int flist_add_files(struct flist_root *root, struct flist_root *search_flist, char *name, int expand_wildcards, int recurse_subdirs, int file_type, FILE_COUNT *count){ int result; char *tmp_name; #if SFX_LEVEL>=ARJ int parse_rc; #endif #if SFX_LEVEL>=ARJ if(expand_wildcards&&marksym_expansion&&xwild_lookup(name)==XW_OK&& xwild_parser(name, &parse_rc)==XW_OK) { /* ASR fix for variable all_wildcard length follows: */ tmp_name=(char *)malloc_msg(strlen(name)+strlen(all_wildcard)+1); strcpy(tmp_name, name); root->fsptr=malloc_str(tmp_name); xwild_to_canonical(tmp_name); result=wild_list(root, search_flist, tmp_name, expand_wildcards, recurse_subdirs, file_type, count); root->no_dupl=1; free(tmp_name); } else { result=wild_list(root, search_flist, name, expand_wildcards, recurse_subdirs, file_type, count); root->no_dupl=1; } #else if((tmp_name=(char *)malloc(strlen(name)+1))==NULL) { msg_cprintf(0, M_HASH_MEM_LACK, name); result=-1; } else { result=0; strcpy(tmp_name, name); case_path(tmp_name); if(add_entry(root, search_flist, tmp_name, count)) result=-1; free(tmp_name); } #endif return(result);}#if SFX_LEVEL>=ARJSFXV/* Returns pointer to the idx-th element, enlarging the CFA if required */static unsigned char FAR *cfa_get_index(FILE_COUNT idx){ FILE_COUNT fblock; if(flist_array==NULL) cfa_allocated=0L; fblock=idx/CFA_BLOCK_SIZE; /* Enlarge the CFA */ if(fblock>=cfa_allocated) { flist_array=(unsigned char FAR * FAR *) farrealloc_msg( flist_array, (fblock+1)*sizeof(char FAR *) ); while(cfa_allocated<=fblock) flist_array[cfa_allocated++]=NULL; } /* Allocate a new block if it has been empty before */ if(flist_array[fblock]==NULL) flist_array[fblock]=(char FAR *)farmalloc_msg((CFA_BLOCK_SIZE+3)>>2); return(flist_array[fblock]+((idx%CFA_BLOCK_SIZE)>>2));}/* Releases the CFA structure */void cfa_shutdown(){ unsigned long i; if(flist_array!=NULL) { for(i=0; i<cfa_allocated; i++) { if(flist_array[i]!=NULL) { farfree(flist_array[i]); flist_array[i]=NULL; } } farfree(flist_array); flist_array=NULL; }}/* Retrieves a CFA element */int cfa_get(FILE_COUNT num){ int pos_num; unsigned char bit_mask, value_bits; pos_num=(int)(num%4)<<1; bit_mask=(unsigned char)3<<pos_num; value_bits=*cfa_get_index(num)&bit_mask; return(value_bits>>pos_num);}/* Stores an element in the CFA */void cfa_store(FILE_COUNT num, int value){ int pos_num; unsigned char bit_mask, value_bits; unsigned char FAR *p; pos_num=(int)(num%4)<<1; bit_mask=(unsigned char)3<<pos_num; value_bits=(unsigned char)value<<pos_num; p=cfa_get_index(num); *p=(*p&=~bit_mask)|value_bits;}/* Initializes the CFA structures */int cfa_init(FILE_COUNT capacity){ unsigned long bytes; FILE_COUNT i; bytes=(unsigned long)capacity>>2; flist_array=farmalloc_msg(bytes+1); for(i=0; i<capacity; i++) cfa_store(i, FLFLAG_TO_PROCESS); return(0); /* ASR fix for High C -- 01/04/2001 */}#endif/* Allocates a block of memory, executes error stub if failed */void *malloc_msg(unsigned int size){ void *tmp; #ifdef DEBUG if(debug_enabled&&strchr(debug_opt, 'm')!=NULL) printf("(Nm%u", size); #endif if((tmp=malloc(size))==NULL) error(M_OUT_OF_NEAR_MEMORY); #ifdef DEBUG if(debug_enabled&&strchr(debug_opt, 'm')!=NULL) printf(")"); #endif return(tmp);}#endif#if SFX_LEVEL>=ARJSFXV||defined(ARJUTIL)/* Allocates a block of far memory, executes error stub if failed. Implementation-dependent (farmalloc for Borland, _fmalloc for MS C) */void FAR *farmalloc_msg(unsigned long size){ void FAR *tmp; #if defined(DEBUG)&&!defined(ARJUTIL) if(debug_enabled&&strchr(debug_opt, 'm')!=NULL) printf("(Fm%u", size); #endif if((tmp=farmalloc(size))==NULL) #ifdef ARJUTIL { printf("Failed to farmalloc(%lu)\n", size); exit(1); } #else error(M_OUT_OF_MEMORY); #endif #if defined(DEBUG)&&!defined(ARJUTIL) if(debug_enabled&&strchr(debug_opt, 'm')!=NULL) printf(")"); #endif return(tmp);}#endif#if SFX_LEVEL>=ARJSFX/* Reallocates a block of far memory, executes error stub if failed. Implementation-dependent (farrealloc for Borland, _frealloc for MS C) */void FAR *farrealloc_msg(void FAR *memblock, unsigned long size){ void FAR *tmp; if((tmp=farrealloc(memblock, size))==NULL) error(M_OUT_OF_MEMORY); return(tmp);}#endif#ifdef REARJ/* Replaces all LF characters with 0's, returning the end of string */char *tokenize_lf(char *str){ while(*str!='\0') { if(*str=='\n') *str='\0'; str++; } return(str);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -