?? pcmdfile.c
字號(hào):
} if(!strchr(switches,'n')) fputc(NL,pfile[filenum].f);RETURN: esdfree(buf); return(erc);} /* end of pcmd_fputs *//*+------------------------------------------------------------------------- pcmd_fwrite(param)fwrite <filenum-int> <str>--------------------------------------------------------------------------*//*ARGSUSED*/intpcmd_fwrite(param)ESD *param;{ return(eNotImplemented);#ifdef USE_FWRITEint erc;int filenum;ESD *buf = (ESD *)0; if(!proc_level) return(eNotExecutingProc); if(erc = _gfilenum(param,&filenum)) return(erc); if(!pfile[filenum].f) return(_file_not_open(filenum)); if((buf = esdalloc(256)) == (ESD *)0) return(eNoMemory); if(erc = gstr(param,buf,1)) goto RETURN; if(!fputs(buf->pb,pfile[filenum].f) && strlen(buf->pb)) { pprintf(fwrite_error_fmt,filenum); erc = eFATAL_ALREADY; }RETURN: esdfree(buf); return(erc);#endif} /* end of pcmd_fwrite *//*+------------------------------------------------------------------------- pcmd_fchmod(param)fchmod <mode-str> | <mode-int> <filenum-int> | <filename-str>$i0 = 0 if successful, else errno--------------------------------------------------------------------------*/intpcmd_fchmod(param)ESD *param;{ int erc; int filenum; ESD *fname = (ESD *)0; ESD *mode = (ESD *)0; long new_mode; char *path = "??";; if((fname = esdalloc(256)) == (ESD *)0) return(eNoMemory); if((mode = esdalloc(64)) == (ESD *)0) { esdfree(fname); return(eNoMemory); } if(erc = skip_cmd_break(param)) goto RETURN; else if(!gstr(param,mode,0)) { if(erc = str_to_filemode(mode->pb,&new_mode)) goto RETURN; } else if(erc = gint(param,&new_mode)) { erc = eBadParameter; goto RETURN; } if(erc = skip_cmd_break(param)) goto RETURN; else if(!gstr(param,fname,1)) { path = fname->pb; if(iv[0] = (long)(chmod(path,(unsigned short)new_mode))) { iv[0] = (long)errno; if(proctrace) pperror(path); } } else if(!_gfilenum(param,&filenum)) { if(!pfile[filenum].f) { erc = (_file_not_open(filenum)); iv[0] = EBADF; } else if(iv[0] = (long)chmod(pfile[filenum].n->pb, (unsigned short)new_mode)) { iv[0] = (long)errno; if(proctrace) { sprintf(fname->pb,"file %d",filenum); pperror(fname->pb); } } if(!iv[0]) path = pfile[filenum].n->pb; } else erc = eBadParameter; if(proctrace && !erc && !iv[0]) pprintf("'%s' mode set to %o\n",path,(int)new_mode);RETURN: esdfree(mode); esdfree(fname); return(erc);} /* end of pcmd_fchmod *//*+------------------------------------------------------------------------- pcmd_fdel(param)fdel <filename-str>$i0 = 0 if successful, else errno--------------------------------------------------------------------------*/intpcmd_fdel(param)ESD *param;{int erc;ESD *fname = (ESD *)0; if((fname = esdalloc(256)) == (ESD *)0) return(eNoMemory); if(erc = gstr(param,fname,1)) goto RETURN; if(iv[0] = (long)unlink(fname->pb)) iv[0] = (long)errno; if(proctrace) { if(iv[0]) pperror(fname->pb); else pprintf("'%s' deleted\n",fname->pb); }RETURN: esdfree(fname); return(erc);} /* end of pcmd_fdel *//*+------------------------------------------------------------------------- pcmd_fseek(param)fseek <filenum-int> <filepos-int>sets $i0 with result--------------------------------------------------------------------------*/intpcmd_fseek(param)ESD *param;{int erc;int filenum;long seekpos; if(!proc_level) return(eNotExecutingProc); if(erc = _gfilenum(param,&filenum)) return(erc); if(!pfile[filenum].f) return(_file_not_open(filenum)); if(erc = gint(param,&seekpos)) return(erc); iv[0] = 0; if(fseek(pfile[filenum].f,seekpos,0) < 0) { iv[0] = (long)errno; if(proctrace) { pprintf("file %d ",filenum); pperror("seekerror"); } } else if(proctrace) pprintf("file %d set to position %ld\n",filenum,seekpos); return(erc);} /* end of pcmd_fseek *//*+------------------------------------------------------------------------- pcmd_mkdir(param)mkdir <filename-str>$i0 = 0 if successful, else errno--------------------------------------------------------------------------*/intpcmd_mkdir(param)ESD *param;{int erc;ESD *fname = (ESD *)0; if((fname = esdalloc(256)) == (ESD *)0) return(eNoMemory); if(erc = gstr(param,fname,1)) goto RETURN; if(iv[0] = (long)mkdir(fname->pb,0755)) iv[0] = (long)errno; if(proctrace) { if(iv[0]) pperror(fname->pb); else pprintf("'%s' deleted\n",fname->pb); }RETURN: esdfree(fname); return(erc);} /* end of pcmd_mkdir *//*+------------------------------------------------------------------------- pcmd_pclose(param)pclose <filenum-int>--------------------------------------------------------------------------*/intpcmd_pclose(param)ESD *param;{int erc;int filenum; if(!proc_level) return(eNotExecutingProc); if(erc = _gfilenum(param,&filenum)) return(erc); if(pfile[filenum].f) { pclose(pfile[filenum].f); pfile[filenum].f = (FILE *)0; esdfree(pfile[filenum].n); } return(0);} /* end of pcmd_pclose *//*+------------------------------------------------------------------------- pcmd_popen(param)popen [-<popen_switches>] <filenum-int> <filename-str>sets $i0 with result--------------------------------------------------------------------------*/intpcmd_popen(param)ESD *param;{int erc;int filenum;ESD *fname = (ESD *)0;char switches[8];#if !defined(M_UNIX)FILE *popen();#endif if(!proc_level) return(eNotExecutingProc); if(get_switches(param,switches,sizeof(switches))) { strcpy(switches,"-r"); if(proctrace) { pputs("Warning: popen defaulting to read\n"); show_error_position(pcb_stack[proc_level - 1]); } } if(erc = _gfilenum(param,&filenum)) return(erc); if(pfile[filenum].f) { pprintf("file %d already open\n",filenum); return(eFATAL_ALREADY); } if((fname = esdalloc(256)) == (ESD *)0) return(eNoMemory); if(erc = gstr(param,fname,1)) goto RETURN; iv[0] = 0; if(pfile[filenum].f = popen(fname->pb,switches + 1)) { iv[0] = (long)errno; if(proctrace) { pprintf("'%s'",fname->pb); pperror(" "); } } else if(proctrace) pprintf("opened '%s' as file %d\n",fname->pb,filenum); if(!erc) pfile[filenum].n = fname;RETURN: if(erc) esdfree(fname); return(erc);} /* end of pcmd_popen *//*+------------------------------------------------------------------------- ifunc_ftell(param,pvalue)%ftell(<filenum-int>)--------------------------------------------------------------------------*/intifunc_ftell(param,pvalue)ESD *param;long *pvalue;{int erc;int filenum;long ftell(); if(!proc_level) return(eNotExecutingProc); if(erc = skip_paren(param,1)) return(erc); if(erc = _gfilenum(param,&filenum)) return(erc); if(!pfile[filenum].f) return(_file_not_open(filenum)); if(erc = skip_paren(param,0)) return(erc); *pvalue = ftell(pfile[filenum].f); return(0);} /* end of ifunc_ftell *//*+------------------------------------------------------------------------- _param_to_stat(param,pstat_rtnd)--------------------------------------------------------------------------*/int_param_to_stat(param,pstat_rtnd)ESD *param;struct stat **pstat_rtnd;{int erc;int filenum;static struct stat fst;struct stat *pstat = &fst;ESD *fname; errno = 0; if(erc = skip_paren(param,1)) return(erc); if((fname = esdalloc(256)) == (ESD *)0) return(eNoMemory); if(!gstr(param,fname,1)) { if(stat(fname->pb,pstat)) pstat = (struct stat *)0; } else if(param->index = param->old_index,!_gfilenum(param,&filenum)) { if(!pfile[filenum].f) { esdfree(fname); return(_file_not_open(filenum)); } if(stat(pfile[filenum].n->pb,pstat)) pstat = (struct stat *)0; } else erc = eBadParameter; esdfree(fname); if(erc) return(erc); if(erc = skip_paren(param,0)) return(erc); *pstat_rtnd = pstat; if(proctrace && !pstat) pperror("stat"); return(0);} /* end of _param_to_stat *//*+------------------------------------------------------------------------- ifunc_fsize(param,pvalue)%fsize(<filenum-int>)%fsize('filename')--------------------------------------------------------------------------*/intifunc_fsize(param,pvalue)ESD *param;long *pvalue;{register erc;struct stat *pstat; if(erc = _param_to_stat(param,&pstat)) return(erc); if(!pstat) *pvalue = -1; else *pvalue = pstat->st_size; return(0);} /* end of ifunc_fsize *//*+------------------------------------------------------------------------- ifunc_fatime(param,pvalue)%fatime(<filenum-int>)%fatime('filename')--------------------------------------------------------------------------*/intifunc_fatime(param,pvalue)ESD *param;long *pvalue;{register erc;struct stat *pstat; if(erc = _param_to_stat(param,&pstat)) return(erc); if(!pstat) *pvalue = -1; else *pvalue = pstat->st_atime; return(0);} /* end of ifunc_fatime *//*+------------------------------------------------------------------------- ifunc_fmtime(param,pvalue)%fmtime(<filenum-int>)%fmtime('filename')--------------------------------------------------------------------------*/intifunc_fmtime(param,pvalue)ESD *param;long *pvalue;{register erc;struct stat *pstat; if(erc = _param_to_stat(param,&pstat)) return(erc); if(!pstat) *pvalue = -1; else *pvalue = pstat->st_mtime; return(0);} /* end of ifunc_fmtime *//*+------------------------------------------------------------------------- ifunc_fmode(param,pvalue)%fmode(<filenum-int>)%fmode('filename')--------------------------------------------------------------------------*/intifunc_fmode(param,pvalue)ESD *param;long *pvalue;{register erc;struct stat *pstat; if(erc = _param_to_stat(param,&pstat)) return(erc); if(!pstat) *pvalue = -1; else *pvalue = (long)pstat->st_mode; return(0);} /* end of ifunc_fmode *//*+------------------------------------------------------------------------- ifunc_isreg(param,pvalue)%isreg(<filenum-int>)%isreg('filename')--------------------------------------------------------------------------*/intifunc_isreg(param,pvalue)ESD *param;long *pvalue;{register erc; if(erc = ifunc_fmode(param,pvalue)) return(erc); if(*pvalue != -1) *pvalue = ((*pvalue & S_IFMT) == S_IFREG); return(0);} /* end of ifunc_isreg *//*+------------------------------------------------------------------------- ifunc_isdir(param,pvalue)%isdir(<filenum-int>)%isdir('filename')--------------------------------------------------------------------------*/intifunc_isdir(param,pvalue)ESD *param;long *pvalue;{register erc; if(erc = ifunc_fmode(param,pvalue)) return(erc); if(*pvalue != -1) *pvalue = ((*pvalue & S_IFMT) == S_IFDIR); return(0);} /* end of ifunc_isdir *//*+------------------------------------------------------------------------- ifunc_ischr(param,pvalue)%ischr(<filenum-int>)%ischr('filename')--------------------------------------------------------------------------*/intifunc_ischr(param,pvalue)ESD *param;long *pvalue;{register erc; if(erc = ifunc_fmode(param,pvalue)) return(erc); if(*pvalue != -1) *pvalue = ((*pvalue & S_IFMT) == S_IFCHR); return(0);} /* end of ifunc_ischr *//* vi: set tabstop=4 shiftwidth=4: *//* end of pcmdfile.c */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -