📄 ckuus6.c
字号:
while (x-- > 0) { if (!znext(name)) break; dstr = zfcdat(name); month = (dstr[4]-48)*10 + (dstr[5]-48); switch(month) { case 1: mstr = "Jan"; break; case 2: mstr = "Feb"; break; case 3: mstr = "Mar"; break; case 4: mstr = "Apr"; break; case 5: mstr = "May"; break; case 6: mstr = "Jun"; break; case 7: mstr = "Jul"; break; case 8: mstr = "Aug"; break; case 9: mstr = "Sep"; break; case 10: mstr = "Oct"; break; case 11: mstr = "Nov"; break; case 12: mstr = "Dec"; break; default: mstr = " "; } date = (dstr[6]-48)*10 + (dstr[7]-48); year = (((dstr[0]-48)*10 + (dstr[1]-48))*10 + (dstr[2]-48))*10 + (dstr[3]-48); hour = (dstr[9]-48)*10 + (dstr[10]-48); minute = (dstr[12]-48)*10 + (dstr[13]-48); seconds = (dstr[15]-48)*10 + (dstr[16]-48); len = zchki(name); /* find just the name of the file */ for (p = name + (int) strlen(name); p != name && *p != '/' && *p != '\\' && *p != ':' ; p-- ) ; if (*p == '/' || *p == '\\' || *p == ':') p++ ; if (len > -1L) { nfiles++; nbytes += len; printf(" %3s-%02d-%04d %02d:%02d %10ld %s\n", mstr, date, year, hour, minute, len, p ); } else { ndirs++; printf(" %3s-%02d-%04d %02d:%02d %10s %s\n", mstr, date, year, hour, minute, "<DIR>", p); } } printf("\n%ld director%s, %ld file%s, %ld byte%s\n\n", ndirs, (ndirs == 1) ? "y" : "ies", nfiles, (nfiles == 1) ? "" : "s", nbytes, (nbytes == 1) ? "" : "s" ); return(success = 1); }#else /* ONETERMUPD */ tmpbuf[0] = NUL; if ((x = cmifi2("Device, directory, and/or file specification,\n\ or switch(es), or '> file'","*.*", &s,&y,1,NULL,xxstring)) < 0) { debug(F101,"DIR cmifi2","",x); if (x == -3) { /* Done. */ goto sw_skip; } else if (x == -2 && (*s == '/' || *s == '>')) { strncpy(tmpbuf,s,TMPBUFSIZ); /* Switch or redirect */ if ((y = cmcfm()) < 0) return(y); else goto sw_skip; } else if (x == -2 && !strchr(s,'.')) { /* Maybe ".*" is missing */ goto fs_copy; } else if (x == -2) { printf("%s - not found\n",s); return(-9); } else return(x); }#endif /* ONETERMUPD */#else /* General Case */ if ((x = cmdir("Directory/file specification","",&s,xxstring)) < 0) if (x != -3) return(x);#endif /* OS2 */#endif /* datageneral */#endif /* AMIGA */#ifdef OS2fs_copy:#endif /* OS2 */ debug(F110,"DIR fs_copy",s,0); strncpy(tmpbuf,s,TMPBUFSIZ); /* Copy the filespec */#ifdef OS2 { /* Lower level functions change / to \, not good for CMD.EXE. */ /* Only do this to filenames, not switches! */ char *p = tmpbuf; while (*p) { /* Change them back to \ */ if (*p == '/') *p = '\\'; p++; } } debug(F110,"DIR tmpbuf 1",tmpbuf,0); /* Now parse trailing switches like /P/O-D... */ if ((x = cmtxt("Optional switches and/or redirect for OS/2 DIR command", "",&s,xxstring)) < 0) return(x); strcat(tmpbuf,s); /* Append them to the filespec */ debug(F110,"DIR tmpbuf 2",tmpbuf,0);sw_skip:#else if ((y = cmcfm()) < 0) return(y);#endif /* OS2 */ s = tmpbuf; lp = line; if (!(dc = getenv("CK_DIR"))) dc = DIRCMD; sprintf(lp,"%s %s",dc,s); debug(F110,"DIR",line,0); xsystem(line); return(success = 1); /* who cares... */#endif /* VMS */#endif /* MAC */}#ifndef NOSERVER#ifndef NOFRILLS/* Do the ENABLE and DISABLE commands */intdoenable(y,x) int y, x; { switch (x) { case EN_ALL: en_cwd = en_cpy = en_del = en_dir = en_fin = en_get = y; en_ren = en_sen = en_set = en_spa = en_typ = en_who = en_ret = y; en_mai = en_pri = y;#ifndef datageneral en_bye = y;#endif /* datageneral */#ifndef NOPUSH if (!nopush) en_hos = y;#endif /* NOPUSH */#ifndef NOSPL en_asg = en_que = y;#endif /* NOSPL */ break; case EN_BYE:#ifndef datageneral/* In Data General AOS/VS Kermit can't log out its superior process.*/ en_bye = y;#endif /* datageneral */ break; case EN_CPY: en_cpy = y; break; case EN_CWD: en_cwd = y; break; case EN_DEL: en_del = y; break; case EN_DIR: en_dir = y; break; case EN_FIN: en_fin = y; break; case EN_GET: en_get = y; break;#ifndef NOPUSH case EN_HOS: if (!nopush) en_hos = y; break;#endif /* NOPUSH */ case EN_REN: en_ren = y; break; case EN_SEN: en_sen = y; break; case EN_SET: en_set = y; break; case EN_SPA: en_spa = y; break; case EN_TYP: en_typ = y; break; case EN_WHO: en_who = y; break;#ifndef NOSPL case EN_ASG: en_asg = y; break; case EN_QUE: en_que = y; break;#endif /* NOSPL */ case EN_RET: en_ret = y; break; case EN_MAI: en_mai = y; break; case EN_PRI: en_pri = y; break; default: return(-2); } return(1);}#endif /* NOFRILLS */#endif /* NOSERVER */#ifndef NOFRILLSintdodel() { /* DELETE */#ifndef MAC long zl;#endif /* MAC */ if ((x = cmifi("File(s) to delete","",&s,&y,xxstring)) < 0) { if (x == -3) { printf("?A file specification is required\n"); return(-9); } else return(x); }#ifdef MAC strcpy(line,s);#else strncpy(tmpbuf,s,TMPBUFSIZ); /* Make a safe copy of the name. */#ifdef OS2 { /* Lower level functions change / to \, not good for CMD.EXE. */ char *p = tmpbuf; while (*p) { /* Change them back to \ */ if (*p == '/') *p = '\\'; p++; } } debug(F110,"xxdel tmpbuf",tmpbuf,0); strcpy(line,tmpbuf); /* Now copy it back */#else /* OS2 */ debug(F110,"xxdel tmpbuf",tmpbuf,0); sprintf(line,"%s %s",DELCMD,tmpbuf); /* Construct the system command. */#endif /* OS2 */#endif /* MAC */ debug(F110,"xxdel line",line,0); if ((y = cmcfm()) < 0) return(y); /* Confirm the user's command. */#ifdef VMS conres();#endif /* VMS */#ifdef MAC s = line; success = (zdelet(line) == 0);#else#ifdef OS2 { int filespace = 0; int len = 0; int count = 0; s = line; z = zxpand(line); if (z > 0) { int i; success = 1; if ( msgflg ) printf("\n"); for ( i = 0; i < z; i++) { znext(tmpbuf); len = zchki(tmpbuf); if (len >= 0) { zdelet(tmpbuf); if (zchki(tmpbuf) < 0) { filespace += len; count++; if (msgflg) printf(" %s - deleted\n",tmpbuf); } else { success = 0; if (msgflg) printf(" %s - not deleted\n",tmpbuf); } } } if (msgflg) printf("\n%d files deleted, %d bytes freed\n",count,filespace); } else { if (msgflg) printf("?Can not delete file: %s\n", line ); } }#else /* OS2 */ s = tmpbuf; xsystem(line); /* Let the system do it. */ zl = zchki(tmpbuf); success = (zl == -1L);#endif /* OS2 */#endif /* MAC */#ifndef OS2 if (msgflg) printf("%s - %sdeleted\n",s, success ? "" : "not ");#ifdef VMS concb((char)escape);#endif /* VMS */#endif /* OS2 */ return(success);}#endif /* NOFRILLS */#ifndef NOSPL /* The ELSE command */intdoelse() { if (!ifcmd[cmdlvl]) { printf("?ELSE doesn't follow IF\n"); return(-2); }#ifdef COMMENT/* Wrong. This prevents IF..ELSE IF...ELSE IF...ELSE IF...ELSE... from working.*/ ifcmd[cmdlvl] = 0;#endif /* COMMENT */ if (!iftest[cmdlvl]) { /* If IF was false do ELSE part */ if (maclvl > -1) { /* In macro, */ pushcmd(); /* save rest of command. */ } else if (tlevel > -1) { /* In take file, */ pushcmd(); /* save rest of command. */ } else { /* If interactive, */ cmini(ckxech); /* just start a new command */ printf("\n"); /* (like in MS-DOS Kermit) */ if (pflag) prompt(xxstring); } } else { /* Condition is false */ if ((y = cmtxt("command to be ignored","",&s,NULL)) < 0) return(y); /* Gobble up rest of line */ } return(0);}#endif /* NOSPL */#ifndef NOSPLintdoswitch() { char *lp, *ap; /* macro argument pointer */ /* Get variable name */ if ((y = cmfld("Variable name","",&s,xxstring)) < 0) return(y); if (*s == CMDQ) { if (chkvar(s) < 1) { printf("?Variable name required\n"); return(-9); } } lp = line; strcpy(lp,"_switx "); /* _switx + space */ lp += (int)strlen(line); ap = lp; debug(F110,"SWITCH",atmbuf,0); strcpy(lp,atmbuf); /* + variable name */ lp += (int)strlen(atmbuf); strcat(lp," "); /* + space */ lp++; debug(F110,"SWITCH 2",line,0); /* Get body */ if ((y = cmtxt("series of cases","",&s,NULL)) < 0) return(y); if ((int)strlen(s) < 1) return(-2); if (litcmd(&s,&lp) < 0) { printf("?Unbalanced brackets\n"); return(0); } debug(F110,"SWITCH 3",line,0); x = mlook(mactab,"_switx",nmac); /* Look up SWITCH macro definition */ if (x < 0) { /* Not there? */ addmmac("_switx",sw_def); /* Put it back. */ if ((x = mlook(mactab,"_switx",nmac)) < 0) { /* Look it up again. */ printf("?SWITCH macro definition gone!\n"); /* Shouldn't happen. */ return(success = 0); } } debug(F110,"SWITCH command",line,0); /* Execute the SWITCH macro. */ return(success = dodo(x,ap,cmdstk[cmdlvl].ccflgs));}intdofor() { /* The FOR command. */ int fx, fy, fz; /* loop variables */ char *ap; /* macro argument pointer */ if ((y = cmfld("Variable name","",&s,NULL)) < 0) { /* Get variable name */ if (y == -3) { printf("?Variable name required\n"); return(-9); } else return(y); } if ((y = parsevar(s,&x,&z)) < 0) /* Check it. */ return(y); lp = line; /* Build a copy of the command */ strcpy(lp,"_forx "); lp += (int)strlen(line); /* "_for" macro. */ ap = lp; /* Save pointer to macro args. */ if (*s == CMDQ) s++; /* Skip past backslash if any. */ while (*lp++ = *s++) ; /* copy it */ lp--; *lp++ = SP; /* add a space */ if ((y = cmnum("initial value","",10,&fx,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } debug(F101,"dofor fx","",fx); s = atmbuf; /* Copy the atom buffer */ if ((int)strlen(s) < 1) goto badfor;/* In edit 192, we change the loop variables to be evaluated at loop entry, not each time through the loop. This was required in order to allow \v(argc) to be used as a loop variable, or in a loop-variable expression. Thus, we can't have FOR loops that modify their own exit conditions by changing the final value or the increment. The problem with \v(argc) was that it is on the macro stack; after entry into the _forx macro, it is at the wrong */ sprintf(tmpbuf,"%d",fx); /* Substitute actual value */ s = tmpbuf; while (*lp++ = *s++) ; /* (what they actually typed) */ lp--; *lp++ = SP; if ((y = cmnum("final value","",10,&fy,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } debug(F101,"dofor fy","",fy); s = atmbuf; /* Same deal */ if ((int)strlen(s) < 1) goto badfor; sprintf(tmpbuf,"%d",fy); s = tmpbuf; while (*lp++ = *s++) ; lp--; *lp++ = SP; if ((y = cmnum("increment","1",10,&fz,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } debug(F101,"dofor fz","",fz); s = atmbuf; /* Same deal */ if ((int)strlen(s) < 1) goto badfor; sprintf(tmpbuf,"%d",fz); s = tmpbuf; while (*lp++ = *s++) ; lp--; *lp++ = SP; /* Insert the appropriate comparison operator */ if (fz < 0) *lp++ = '<'; else *lp++ = '>'; *lp++ = SP; if ((y = cmtxt("Command to execute","",&s,NULL)) < 0) return(y); if ((int)strlen(s) < 1) return(-2); if (litcmd(&s,&lp) < 0) { printf("?Unbalanced brackets\n"); return(0); }#ifdef COMMENT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -