📄 misc.c
字号:
/* * $Id: misc.c,v 1.2 2003/02/07 17:21:16 andrew_belov Exp $ * --------------------------------------------------------------------------- * Various system-independent routines are kept here. This module is needed if * the ENVIRON.C is linked, since both of them cross-reference each other. * */#include "arj.h"DEBUGHDR(__FILE__) /* Debug information block *//* Compact filelist array */#if SFX_LEVEL>=ARJSFXV static unsigned char FAR * FAR *flist_array=NULL; static FILE_COUNT cfa_allocated; /* # of allocated blocks */#endif/* Extended wildcard specifiers */static char xwild_symbols[]="?*[]^";/* Forward references */static int xwild_propagate(char *wcstr, char *str);#if SFX_LEVEL>=ARJ/* Dumb extended wildcard lookup routine */static int xwild_lookup(char *str){ char *p; char c; for(p=str; *p!='\0'; p++) { c=*p; if(c=='*'||c=='?'||c=='['||c=='^') return(XW_OK); } return(XW_NONE);}/* An extended wildcard parser */static int xwild_parser(char *wcstr, int *rc){ char *p; char c; *rc=XWP_NONE; for(p=wcstr; *p!='\0'; p++) { c=*p; if(c=='^') { p++; if(*p=='\0') { *rc=XWP_TERM; return(XW_NONE); } } else if(c=='[') { p++; if((c=*p)==']') { *rc=XWP_NBRACKET; return(XW_NONE); } if(c=='\0') { *rc=XWP_OBRACKET; return(XW_NONE); } while(*p!=']') { if(*p=='^') { p++; if((c=*p)=='\0') { *rc=XWP_TERM; return(XW_NONE); } } else p++; if((c=*p)=='\0') { *rc=XWP_OBRACKET; return(XW_NONE); } if(*p=='-') { c=*++p; if(c=='\0'||c==']') { *rc=XWP_MDASH; return(XW_NONE); } if(*p=='^') p++; if((c=*p++)=='\0') { *rc=XWP_TERM; return(XW_NONE); } } } } else p++; } return(XW_OK);}/* Extended wildcard expansion and matching routine */static int xwild_match(char *wcstr, char *str){ char *wptr; char *sptr; char c, sc; char fchar; int xchar; int pflag; int unproc; char xc, xpc; /* Wildcard processed characters */ wptr=wcstr; sptr=str; while(*wptr!='\0') { if((c=*sptr)=='\0') return((*wptr=='*'&&*++wptr=='\0')?XW_OK:XW_OWC); fchar=*wptr; switch(fchar) { case '*': return(xwild_propagate(wptr, sptr)); case '[': xchar=0; wptr++; if(*wptr=='!') { xchar=1; wptr++; } unproc=0; pflag=1; while(pflag!=0) { if(*wptr!=']') { c=(*wptr=='^')?*++wptr:*wptr; /* Escape character */ xpc=xc=toupper(c); if(c=='\0') return(XW_TERM); wptr++; if(*wptr=='-') { c=*++wptr; if(c=='\0'&&c!=']') return(XW_TERM); xc=toupper(c); if(xc=='^') { c=*++wptr; xc=toupper(c); if(xc=='\0') return(XW_TERM); } wptr++; } sc=toupper(*sptr); if(xpc>=xc&&sc>=xc&&sc<=xpc||sc>=xpc&&sc<=xc) { unproc=1; pflag=0; } } else pflag=0; } if(xchar!=0&&unproc||xchar==0&&!unproc) return(XW_UNPROC); if(!unproc) break; /* Skip the rest, applying usual check-ups */ while(*wptr!=']') { if(*wptr=='\0') return(XW_TERM); if(*wptr=='^') { if(*++wptr=='\0') return(XW_TERM); } wptr++; } break; case '?': break; /* Skip the comparision */ case '^': wptr++; if(*wptr=='\0') return(XW_TERM); default: /* fallthru */ if(toupper(*wptr)!=toupper(*sptr)) return(XW_MISMATCH); break; } wptr++; sptr++; } return((*sptr=='\0')?XW_OK:XW_PREM_END);}/* Propagates (expands) wildcard markers */static int xwild_propagate(char *wcstr, char *str){ int rc=0; char c; while(*wcstr=='?'||*wcstr=='*') { if(*wcstr=='?') { if(*++str=='\0') return(XW_OWC); } wcstr++; } if(*wcstr=='\0') return(XW_OK); if((c=*wcstr)=='^') { if((c=*++wcstr)=='\0') return(XW_TERM); } do { if(toupper(c)==toupper(*str)||c=='[') rc=xwild_match(wcstr, str); if(*str++=='\0') rc=XW_OWC; } while(rc!=XW_OK&&rc!=XW_OWC&&rc!=XW_TERM); return(rc);}/* Wildcard matching routine wrapper (provides boolean RCs) */static int xwild_compare(char *wcstr, char *str){ int xrc; xrc=xwild_match(wcstr, str); return((xrc==XW_OK)?XW_OK:XW_NONE);}/* Change all UNIX-style path specifiers to DOS-style ones in a given string */void unix_path_to_dos(char *path){ int i=0; if(translate_unix_paths) { while(path[i]!='\0') { if(path[i]==PATHSEP_UNIX) path[i]=PATHSEP_DEFAULT; i++; } }}#endif#if SFX_LEVEL>=ARJSFXV/* Allocate a block of memory that will exactly fit the length of string, and copy the string into this newly-created block. */void *malloc_str(char *str){ return(strcpy((char *)malloc_msg(strlen(str)+1), str));}#endif#if SFX_LEVEL>=ARJ/* The same as malloc_str, but it allocates near memory for far strings */void *malloc_far_str(char FAR *str){ char *k; k=malloc_msg(far_strlen(str)+1); far_strcpy((char FAR *)k, str); return(k);}#endif#if SFX_LEVEL>=ARJ/* Converts current time to a standard timestamp */void cur_time_stamp(struct timestamp *dest){ time_t cur_unixtime; cur_unixtime=time(NULL); ts_store(dest, OS_UNIX, cur_unixtime);}/* A strchr() function for far strings */#if COMPILER!=MSC&&defined(TILED)char FAR *far_strchr(char FAR *str, char chr){ while(str[0]!=chr) { if(str[0]=='\0') return(NULL); str++; } return(str);}#endif#endif#if SFX_LEVEL>=ARJSFXV||defined(REARJ)/* A strcmp() function for far strings */#if COMPILER!=MSC&&defined(TILED)int far_strcmp(char FAR *str1, char FAR *str2){ unsigned int k; for(k=0; str1[k]!='\0'&&str2[k]!='\0'; k++); return((int)(str1[k]-str2[k]));}#endif/* A stricmp() function for far strings */#if COMPILER!=MSC&&defined(TILED)int far_stricmp(char FAR *str1, char FAR *str2){ unsigned int k; for(k=0; toupper(str1[k]!='\0')&&toupper(str2[k]!='\0'); k++); return(toupper(str1[k])-toupper(str2[k]));}#endif#endif#if SFX_LEVEL>=ARJ||defined(REARJ)/* A strcat() function for far strings */#if COMPILER!=MSC&&defined(TILED)char FAR *far_strcat(char FAR *dest, char FAR *src){ char FAR *tmp_dest; tmp_dest=dest; while(tmp_dest[0]!='\0') tmp_dest++; do (tmp_dest++)[0]=src[0]; while((src++)[0]!='\0'); return(dest);}#endif#endif#if SFX_LEVEL>=ARJSFXV||defined(REARJ)/* A strcpy() function for far strings */#if COMPILER!=MSC&&defined(TILED)char FAR *far_strcpy(char FAR *dest, char FAR *src){ int k; for(k=0; src[k]!='\0'; k++) dest[k]=src[k]; dest[k]='\0'; return(dest);}#endif#endif#if SFX_LEVEL>=ARJ/* A strlen() function for far strings */#if COMPILER!=MSC&&defined(TILED)unsigned int far_strlen(char FAR *str){ unsigned int k=0; while(str[k]!='\0') k++; return(k);}#endif#endif#if SFX_LEVEL>=ARJSFXV/* Fills a buffer with the specified value */#if COMPILER!=MSC&&defined(TILED)void FAR *far_memset(void FAR *buf, int filler, unsigned int size){ char FAR *p; unsigned int l; p=(char FAR *)buf; for(l=0; l<size; l++) *p++=(char)filler; return(buf);}#endif#endif#if SFX_LEVEL>=ARJSFXV/* Copies at most n characters */char FAR *far_strcpyn(char FAR *dest, char FAR *src, int limit){ int k; for(k=1; k<limit&&src[0]!='\0'; k++) { (dest++)[0]=(src++)[0]; } if(limit>0) dest[0]='\0'; return(dest);}#endif#if SFX_LEVEL>=ARJSFX/* Converts the given string to 7-bit */void to_7bit(char *str){ while(*str!='\0') *str++&=0x7F;}#endif#if SFX_LEVEL>=ARJSFX||defined(REARJ)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -