⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckucmd.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
		    }		}#ifdef OS2		if (d && ((int)strlen(*xp) == 2))		  if (isalpha(**xp) && *(*xp + 1) == ':')		    return(x);		tries = 0;i_again:		if (tries > 0)#endif /* OS2 */		if (f) {		/* If a conversion function is given */		    zq = atxbuf;	/* ... */		    atxn = CMDBL;		    if ((y = (*f)(*xp,&zq,&atxn)) < 0) return(-2);		    *xp = atxbuf;		}		debug(F110,"cmifi atxbuf",atxbuf,0);		if (!sv) {			     /* Only do this once */		    sv = malloc((int)strlen(*xp)+1); /* Make a safe copy */		    if (!sv) {			printf("?malloc error 73, cmifi\n");			return(-9);		    }		    strcpy(sv,*xp);		    debug(F110,"cmifi sv",sv,0);		}		y = zxpand(*xp);		*wild = (y > 1);		debug(F111,"cmifi sv wild",sv,*wild);		if (y == 0) {		    if (path && !isabsolute(sv)) {			char * ptr = path;			char c;			while (1) {			    c = *ptr;			    if (c == PATHSEP || c == NUL) {				if (!*path) {				    path = NULL;				    break;				}				*ptr = NUL;				strcpy(atmbuf,path);				strcat(atmbuf,sv);				debug(F110,"cmifip add path",atmbuf,0);				if (c == PATHSEP) ptr++;				path = ptr;				break;			    }			    ptr++;			}			x = 1;			inword = 0;			cc = 0;			xc = (int) strlen(atmbuf);			*xp = "";			goto i_path;		    }#ifdef OS2		    if (tries++ < 1)		      goto i_again;#endif /* OS2 */		    if (sv) free(sv);		    if (d) {			return(-2);		    } else {			printf("?No files match - %s\n",*xp);			return(-9);		    }		} else if (y < 0) {		    printf("?Too many files match - %s\n",*xp);		    if (sv) free(sv);		    return(-9);		} else if (y > 1) {		    if (sv) free(sv);		    return(x);		}                /* If not wild, see if it exists and is readable. */ 		debug(F111,"cmifi sv not wild",sv,*wild);		znext(*xp);		/* Get first (only?) matching file */                y = zchki(*xp);		/* Check its accessibility */		zxpand(sv);		/* Rewind so next znext() gets 1st */		free(sv);		/* done with this */		sv = NULL;                if (y == -3) {                    printf("?Read permission denied - %s\n",*xp);                    return(-9);                } else if (y == -2) {		    if (d) return(0);                    printf("?File not readable - %s\n",*xp);                    return(-9);                } else if (y < 0) {                    printf("?File not found - %s\n",*xp);                    return(-9);                }                return(x);#ifndef MAC            case 2:                     /* ESC */		debug(F101,"cmifi esc, xc","",xc);#ifdef OS2		tries = 0;#endif /* OS2 */                if (xc == 0) {                    if (*xdef != '\0') {                        printf("%s ",xdef); /* If at beginning of field, */#ifdef GEMDOS			fflush(stdout);#endif /* GEMDOS */			inword = cmflgs = 0;                        addbuf(xdef);   /* Supply default. */                        if (setatm(xdef,0) < 0) {			    printf("Default input filename too long\n");			    return(-9);			}                    } else {            /* No default */                        bleep(BP_WARN);                    }                    break;                }#ifdef OS2e_again:		if (tries > 0)#endif /* OS2 */		if (f) {		/* If a conversion function is given */		    zq = atxbuf;	/* ... */		    atxn = CMDBL;		    if ((x = (*f)(*xp,&zq,&atxn)) < 0) return(-2);                    /* reduce cc by number of \\ consumed by conversion */		    /* function (needed for OS/2, where \ is path separator) */                    cc -= (strlen(*xp) - strlen(atxbuf));		    *xp = atxbuf;		}#ifdef DTILDE		dirp = tilde_expand(*xp); /* Expand tilde, if any, */		if (*dirp != '\0') {	/* in the atom buffer. */		    if (setatm(dirp,0) < 0) {			printf("Expanded input filename too long\n");			return(-9);		    }		}                *xp = atmbuf;#endif /* DTILDE */                sp = *xp + cc;#ifdef datageneral                *sp++ = '+';		/* Data General AOS wildcard */#else                *sp++ = '*';		/* Others */#endif /* datageneral */                *sp-- = '\0';#ifdef GEMDOS		if (! strchr(*xp, '.'))	/* abde.e -> abcde.e* */		  strcat(*xp, ".*");	/* abc -> abc*.* */#endif /* GEMDOS */                y = zxpand(*xp);	/* Add wildcard and expand list. */		if (y > 0)#ifdef OS2		  znext(filbuf);else		  strcpy(filbuf,mtchs[0]);#endif /* OS2 */		else		  *filbuf = NUL;                *sp = '\0';             /* Remove wildcard. */		*wild = (y > 1);                if (y == 0) {#ifdef OS2		    if (tries++ < 1)		      goto e_again;		    else#endif /* OS2 */		      printf("?No files match - %s\n",atmbuf);                    return(-9);                } else if (y < 0) {                    printf("?Too many files match - %s\n",atmbuf);                    return(-9);                } else if (y > 1) {     /* Not unique. */#ifndef NOPARTIAL/* Partial filename completion */		    int i, j, k; char c;		    k = 0;		    debug(F111,"cmifi partial",filbuf,cc);#ifdef OS2                    {                        int cur = 0,			len = 0,			len2 = 0,			min = strlen(filbuf);                        char localfn[257];                        len = min;                        for (j = 1; j < y; j++) {                            znext(localfn);                            len2 = strlen(localfn);                            for (cur=cc;                                  cur < len && cur < len2 && cur <= min;                                  cur++				 ) {                                if (tolower(filbuf[cur]) !=                                     tolower(localfn[cur])				    )                                  break;                            }                            if (cur < min)                              min = cur;                        }                        filbuf[min] = NUL;                        if (min > cc)			  k++;                    }#else /* OS2 */		    for (i = cc; (c = filbuf[i]); i++) {			for (j = 1; j < y; j++)			  if (mtchs[j][i] != c) break;			if (j == y) k++;			else filbuf[i] = filbuf[i+1] = NUL;		    }#endif /* OS2 */		    debug(F111,"cmifi partial k",filbuf,k);		    if (k > 0) {	/* Got more characters */			sp = filbuf + cc; /* Point to new ones */#ifdef VMS			for (i = 0; i < cc; i++) {			    cmdchardel(); /* Back up over old partial spec */			    bp--;			}			sp = filbuf;	/* Point to new word start */			debug(F100,"cmifi vms erase ok","",0);#endif /* VMS */			cc = k;		/* How many new ones we just got */			printf("%s",sp);        /* Print them */			while (*bp++ = *sp++) ;	/* Copy to command buffer */			bp--;	    	        /* Back up over NUL */			debug(F110,"cmifi partial cmdbuf",cmdbuf,0);			if (setatm(filbuf,0) < 0) {			    printf("?Partial filename too long\n");			    return(-9);			}			debug(F111,"cmifi partial atmbuf",atmbuf,cc);			*xp = atmbuf;		    }#endif /* NOPARTIAL */		    bleep(BP_WARN);                 } else {                /* Unique, complete it.  */#ifndef VMS#ifdef CK_TMPDIR    		    /* isdir() function required for this! */		    if (isdir(filbuf)) {#ifdef UNIX			strcat(filbuf,"/");#endif#ifdef OS2			strcat(filbuf,"/");#endif#ifdef AMIGA			strcat(filbuf,"/");#endif#ifdef OSK			strcat(filbuf,"/");#endif#ifdef datageneral			strcat(filbuf,":");#endif#ifdef MAC			strcat(filbuf,":");#endif#ifdef STRATUS			strcat(filbuf,">");#endif#ifdef GEMDOS			strcat(filbuf,"\\");#endif			sp = filbuf + cc;			bleep(BP_WARN);			printf("%s",sp);			cc++;			while (*bp++ = *sp++) ;			bp--;			if (setatm(filbuf,0) < 0) {			    printf("?Directory name too long\n");			    return(-9);			}			debug(F111,"cmifi directory atmbuf",atmbuf,cc);			*xp = atmbuf;		    } else { /* Not a directory... */#endif /* CK_TMPDIR */#endif /* VMS */			sp = filbuf + cc; /* Point past what user typed. */#ifdef VMS			for (i = 0; i < cc; i++) {			    cmdchardel(); /* Back up over old partial spec */			    bp--;			}			sp = filbuf;	/* Point to new word start */#endif /* VMS */			printf("%s ",sp); /* Complete the name. */#ifdef GEMDOS			fflush(stdout);#endif /* GEMDOS */			addbuf(sp);	/* Add the characters to cmdbuf. */			if (setatm(filbuf,0) < 0) { /* And to atmbuf. */			    printf("?Completed filename too long\n");			    return(-9);			}			inword = cmflgs = 0;			*xp = atmbuf;	/* Return pointer to atmbuf. */			return(0);#ifndef VMS#ifdef CK_TMPDIR		    }#endif /* CK_TMPDIR */#endif /* VMS */                }                break;             case 3:                     /* Question mark */#ifdef OS2		tries = 0;#endif /* OS2 */                if (*xhlp == NUL)		  printf(" Input file specification");                else		  printf(" %s",xhlp);#ifdef GEMDOS		fflush(stdout);#endif /* GEMDOS */                if (xc > 0) {#ifdef OS2q_again:		    if (tries > 0)#endif /* OS2 */		    if (f) {		/* If a conversion function is given */			zq = atxbuf;	/* ... */			atxn = CMDBL;			if ((x = (*f)(*xp,&zq,&atxn)) < 0) return(-2);			*xp = atxbuf;		    }#ifdef DTILDE		    dirp = tilde_expand(*xp);    /* Expand tilde, if any */		    if (*dirp != '\0') {			if (setatm(dirp,0) < 0) {			    printf("?Expanded filename too long\n");			    return(-9);			}		    }		    *xp = atmbuf;#endif /* DTILDE */		    debug(F111,"cmifi ? *xp, cc",*xp,cc);                    sp = *xp + cc;	/* Insert "*" at end */#ifdef datageneral                    *sp++ = '+';        /* Insert +, the DG wild card */#else                    *sp++ = '*';#endif /* datageneral */                    *sp-- = '\0';#ifdef GEMDOS		    if (! strchr(*xp, '.'))	/* abde.e -> abcde.e* */		      strcat(*xp, ".*");	/* abc -> abc*.* */#endif /* GEMDOS */		    debug(F110,"cmifi ? wild",*xp,0);                    y = zxpand(*xp);                    *sp = '\0';                    if (y == 0) {#ifdef OS2			if (tries++ < 1)			  goto q_again;			else#endif /* OS2 */			  printf("?No files match - %s\n",atmbuf);                        return(-9);                    } else if (y < 0) {                        printf("?Too many files match - %s\n",atmbuf);                        return(-9);                    } else {                        printf(", one of the following:\n");                        clrhlp();                        for (i = 0; i < y; i++) {                            znext(filbuf);#ifdef VMS			    printf(" %s\n",filbuf); /* VMS names can be long */#else                            addhlp(filbuf);#endif /* VMS */                        }                        dmphlp();                    }                } else printf("\n");                printf("%s%s",cmprom,cmdbuf);		fflush(stdout);                break;#endif /* MAC */        }#ifdef BS_DIRSEP	cmdirflg = 1;        x = gtword();                   /* No, get a word */	cmdirflg = 0;#else        x = gtword();                   /* No, get a word */#endif /* BS_DIRSEP */    *xp = atmbuf;    }#endif /* NEWCMIFI */}/*  C M D I R  --  Parse a directory specification  *//* This function depends on the external functions:   zchki()  - Check if input file exists and is readable. If these functions aren't available, then use cmfld() to parse dir names. Note: this function quickly cobbled together, mainly by deleting lots of lines from cmifi().  It seems to work, but various services are missing, like completion, lists of matching directories on "?", etc.*//* Returns   -4 EOF   -3 if no input present when required,   -2 if out of space or other internal error,   -1 if reparse needed,    0 or 1, with xp pointing to name, if directory specified,    2 if a wildcard was included.*/intcmdir(xhlp,xdef,xp,f) char *xhlp, *xdef, **xp; xx_strp f; {    int x, xc; char *zq;#ifdef DTILDE    char *tilde_expand(), *dirp;#endif /* DTILDE */    inword = 0;				/* Initialize counts & pointers */    cc = 0;    xc = 0;    *xp = "";    if ((x = cmflgs) != 1) {            /* Already confirmed? */#ifdef BS_DIRSEP	cmdirflg = 1;        x = gtword();                   /* No, get a word */	cmdirflg = 0;#else        x = gtword();                   /* No, get a word */#endif /* BS_DIRSEP */    } else {        if (setatm(xdef,0) < 0) {	/* If so, use default, if any. */	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -