/* cmdline.c by Yoshioka Tsuneo(QWF00133@niftyserve.or.jp) welcome any e-mail!! You can use this file as Public Domain Software. Copy,Edit,Re-distibute and for any purpose,you can use this file. */ #include "cmdline.h" #include #include #include #include #include #include /* 多分記号は全部0x40未満だからうまくいくだろう・・・ */ #ifdef WIN32 #define KANJI #endif #ifdef KANJI #define UCH(c) ((unsigned char)(c)) #define iskanji1(c) ((0x81<=UCH(c)&&UCH(c)<=0x9F)||(0xE0<=UCH(c)&&UCH(c)<=0xFC)) #define iskanji2(c) ((0x40<=UCH(c)&&UCH(c)<=0x7E)||(0x80<=UCH(c)&&UCH(c)<=0xFC)) #endif /* ptr の配列の長さを求める(NULLポインタが終端) */ int ptrarraylen(void **ptr) { int len=0; while(*ptr++){ len++; } return len; } /* 文字列の(ポインタの)配列をまるごとコピー(複製)する */ /* 一列にまとめることで一回freeを呼ぶだけで配列まるごと開放できる*/ /* strarray[0] strarray[1] strarray[2] NULL *strarray[0] *strarray[1] *strarray[2] */ char **strarraydup(char **strarray) { char **files_dup=NULL; int filenum; int alllen; int i; char *ptr; filenum=ptrarraylen((void**)strarray); alllen=0; for(i=0;i=filelen2-5){ filelen2+=4096; if((realloc2((void**)&file,filelen2))==NULL) goto endlabel; filep=file+filelen; } #ifdef KANJI /* if 2 byte charactor then copy on more byte */ if(iskanji1(*ptr) && iskanji2(*(ptr+1))){ *filep++=*ptr++; filelen+=1; } #endif *filep++=*ptr++; filelen+=1; } } *filep='\0'; /*if((p=malloc(sizeof(char)*(strlen(file)+1)))==NULL) goto errorlabel; strcpy(p,file);*/ if(realloc2((void**)&files,sizeof(char *)*(filenum+1))==NULL){ free(file); goto endlabel; } filenum++; files[filenum-1]=file; while(isspace((unsigned char)*ptr)){ptr++;} } if(realloc2((void**)&files,sizeof(char *)*(filenum+1))==NULL){ free(file); goto endlabel; } files[filenum]=NULL; files2=strarraydup(files); endlabel: if(files!=NULL){ for(i=0;i