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

📄 ckucmd.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (s2 && (b = (char *) malloc(cmd_cols + 1))) { /* Make a line buffer   */	char * bx;	bx = b + cmd_cols;	width += (int)strlen(pre) + (int)strlen(post) + 2;	cols = cmd_cols / width;	/* How many columns? */	if (cols < 1) cols = 1;	height = n / cols;		/* How long is each column? */	if (n % cols) height++;		/* Add one for remainder, if any */	for (i = 0; i < height; i++) {	    /* Loop for each row */	    for (j = 0; j < cmd_cols; j++)  /* First fill row with blanks */	      b[j] = SP;	    for (j = 0; j < cols; j++) {    /* Loop for each column in row */		k = i + (j * height);       /* Index of next keyword */		if (k < n) {		    /* In range? */		    pa = pre;		    px = post;		    p = s2[k];		    /* Point to verb name */		    q = b + (j * width) + 1; /* Where to copy it to */		    while ((q < bx) && (*q++ = *pa++)) ; /* Copy prefix */		    q--;		                 /* Back up over NUL */		    while ((q < bx) && (*q++ = *p++)) ;	 /* Copy filename */		    q--;		                 /* Back up over NUL */		    while ((q < bx) && (*q++ = *px++)) ; /* Copy suffix */		    if (j < cols - 1) {			q--;			*q = SP;	/* Replace the space */		    }		}	    }	    p = b + cmd_cols - 1;	/* Last char in line */	    while (*p-- == SP) ;	/* Trim */	    *(p+2) = NUL;	    printf("%s\n",b);		/* Print the line */	    if (++lc > (cmd_rows - 2)) { /* Screen full? */		if (!askmore())		/* Do more-prompting... */		  goto xkwdhelp;		else		  lc = 0;	    }	}	/* printf("\n"); */		/* Blank line at end of report */    } else {				/* Malloc failure, no columns */	for (i = 0; i < n; i++) {	    if (s[i].flgs & CM_INV)	/* Use original keyword table */	      continue;			/* skipping invisible entries */	    printf("%s%s%s\n",pre,s[i].kwd,post);	    if (++lc > (cmd_rows - 2)) { /* Screen full? */		if (!askmore())		/* Do more-prompting... */		  goto xkwdhelp;		else		  lc = 0;	    }	}    }  xkwdhelp:    if (xhlp & 4) {	if (tmpbuf) free(tmpbuf);	for (i = 0; i < n; i++)	  if (s2[i]) free(s2[i]);    }    if (s2) free(s2);			/* Free array copy */    if (b) free(b);			/* Free line buffer */    return;}/*  F I L H E L P  --  Given a file list, print names in columns.  *//*  Call with:    n     - number of entries    pre   - prefix to add to each filename    post  - suffix to add to each filename    off   - offset on first screenful, allowing room for introductory text    cmdirflg - 1 if only directory names should be listed, 0 to list all files  Arranges filenames in columns with width based on longest filename.  Does "more?" prompting at end of screen.  Uses global cmd_rows and cmd_cols for screen size.*/intfilhelp(n,pre,post,off,cmdirflg) int n, off; char *pre, *post; int cmdirflg; {    char filbuf[CKMAXPATH + 1];		/* Temp buffer for one filename */    int width = 0;    int cols, height, i, j, k, lc, n2 = 0, rc = 0, itsadir = 0;    char *b = NULL, *p, *q;    char *pa, *px;    char **s2 = NULL;#ifdef VMS    char * cdp = zgtdir();#endif /* VMS */    if (n < 1) return(0);    if (off < 0) off = 0;		/* Offset for first page */    if (!pre) pre = "";			/* Handle null string pointers */    if (!post) post = "";    lc = off;				/* Screen-line counter */    if (s2 = (char **) malloc(n * sizeof(char *))) {	for (i = 0; i < n; i++) {	/* Loop through filenames */	    itsadir = 0;	    s2[i] = NULL;		/* Initialize each pointer to NULL */	    znext(filbuf);		/* Get next filename */	    if (!filbuf[0])		/* Shouldn't happen */	      break;#ifdef COMMENT	    itsadir = isdir(filbuf);	/* Is it a directory? */	    if (cmdirflg && !itsadir)	/* No, listing directories only? */	      continue;			/* So skip this one. */#endif /* COMMENT */#ifdef VMS	    ckstrncpy(filbuf,zrelname(filbuf,cdp),CKMAXPATH);#endif /* VMS */	    j = strlen(filbuf);#ifndef VMS	    if (itsadir && j < CKMAXPATH - 1 && j > 0) {		if (filbuf[j-1] != dirsep) {		    filbuf[j++] = dirsep;		    filbuf[j] = NUL;		}	    }#endif /* VMS */	    if (!(s2[n2] = malloc(j+1))) {		printf("?Memory allocation failure\n");		rc = -9;		goto xfilhelp;	    }	    if (j <= CKMAXPATH) {		strcpy(s2[n2],filbuf);		n2++;	    } else {		printf("?Name too long - %s\n", filbuf);		rc = -9;		goto xfilhelp;	    }	    if (j > width)		/* Get width of widest one */	      width = j;	}	n = n2;				/* How many we actually got */    }    sh_sort(s2,NULL,n,0,0,filecase);	/* Alphabetize the list */    rc = 1;    if (s2 && (b = (char *) malloc(cmd_cols + 1))) { /* Make a line buffer */	char * bx;	bx = b + cmd_cols;	width += (int)strlen(pre) + (int)strlen(post) + 2;	cols = cmd_cols / width;	/* How many columns? */	if (cols < 1) cols = 1;	height = n / cols;		/* How long is each column? */	if (n % cols) height++;		/* Add one for remainder, if any */	for (i = 0; i < height; i++) {	    /* Loop for each row */	    for (j = 0; j < cmd_cols; j++)  /* First fill row with blanks */	      b[j] = SP;	    for (j = 0; j < cols; j++) {    /* Loop for each column in row */		k = i + (j * height);       /* Index of next filename */		if (k < n) {		    /* In range? */		    pa = pre;		    px = post;		    p = s2[k];		               /* Point to filename */		    q = b + (j * width) + 1;             /* and destination */		    while ((q < bx) && (*q++ = *pa++)) ; /* Copy prefix */		    q--;		                 /* Back up over NUL */		    while ((q < bx) && (*q++ = *p++)) ;	 /* Copy filename */		    q--;		                 /* Back up over NUL */		    while ((q < bx) && (*q++ = *px++)) ; /* Copy suffix */		    if (j < cols - 1) {			q--;			*q = SP;	/* Replace the space */		    }		}	    }	    p = b + cmd_cols - 1;	/* Last char in line */	    while (*p-- == SP) ;	/* Trim */	    *(p+2) = NUL;	    printf("%s\n",b);		/* Print the line */	    if (++lc > (cmd_rows - 2)) { /* Screen full? */		if (!askmore()) {	/* Do more-prompting... */		    rc = 0;		    goto xfilhelp;		} else		  lc = 0;	    }	}	printf("\n");			/* Blank line at end of report */	goto xfilhelp;    } else {				/* Malloc failure, no columns */	for (i = 0; i < n; i++) {	    znext(filbuf);	    if (!filbuf[0]) break;	    printf("%s%s%s\n",pre,filbuf,post);	    if (++lc > (cmd_rows - 2)) { /* Screen full? */		if (!askmore()) {	 /* Do more-prompting... */		    rc = 0;		    goto xfilhelp;		} else lc = 0;	    }	}xfilhelp:	if (b) free(b);	for (i = 0; i < n2; i++)	  if (s2[i]) free(s2[i]);	if (s2) free(s2);	return(rc);    }}/*  C M S E T U P  --  Set up command buffers  */#ifdef DCMDBUFintcmsetup() {    if (!(cmdbuf = malloc(CMDBL + 4))) return(-1);    if (!(savbuf = malloc(CMDBL + 4))) return(-1);    savbuf[0] = '\0';#ifdef OLDHELP    if (!(hlpbuf = malloc(HLPBL + 4))) return(-1);#endif /* OLDHELP */    if (!(atmbuf = malloc(ATMBL + 4))) return(-1);    if (!(atxbuf = malloc(CMDBL + 4))) return(-1);    if (!(atybuf = malloc(ATMBL + 4))) return(-1);    if (!(filbuf = malloc(ATMBL + 4))) return(-1);    if (!(cmprom = malloc(PROMPTL + 4))) return(-1);    if (!(cmprxx = malloc(PROMPTL + 4))) return(-1);#ifdef CK_RECALL    cmrini(cm_recall);#endif /* CK_RECALL */    return(0);}#endif /* DCMDBUF *//*  C M S E T P  --  Set the program prompt.  */VOIDcmsetp(s) char *s; {    if (!s) s = "";    ckstrncpy(cmprxx,s,PROMPTL);    psetf = 1;                          /* Flag that prompt has been set. */}/*  C M S A V P  --  Save a copy of the current prompt.  */VOID#ifdef CK_ANSICcmsavp(char s[], int n)#elsecmsavp(s,n) char s[]; int n;#endif /* CK_ANSIC *//* cmsavp */ {    if (psetf)				/* But not if no prompt is set. */      ckstrncpy(s,cmprxx,n);}intcmgbrk() {    return(brkchar);}intcmgkwflgs() {    return(cmkwflgs);}/*  P R O M P T  --  Issue the program prompt.  */VOIDprompt(f) xx_strp f; {    char *sx, *sy; int n;#ifdef CK_SSL    extern int ssl_active_flag, tls_active_flag;#endif /* CK_SSL */#ifdef OS2    extern int display_demo;    /* If there is a demo screen to be displayed, display it */    if (display_demo && cmdsrc() == 0) {        demoscrn();        display_demo = 0;    }#endif /* OS2 */    if (psetf == 0)			/* If no prompt set, set default. */      cmsetp(dfprom);    sx = cmprxx;			/* Unevaluated copy */    if (f) {				/* If conversion function given */	sy = cmprom;			/* Evaluate it */	debug(F101,"prompt sx","",sx);	debug(F101,"prompt sy","",sy);	n = PROMPTL;	if ((*f)(sx,&sy,&n) < 0)	/* If evaluation failed */	  sx = cmprxx;			/* revert to unevaluated copy */	else if (!*cmprom)		/* ditto if it came up empty */	  sx = cmprxx;	else	  sx = cmprom;    } else      ckstrncpy(cmprom,sx,PROMPTL);    cmprom[PROMPTL-1] = NUL;    if (!*sx)				/* Don't print if empty */      return;#ifdef OSK    fputs(sx, stdout);#else#ifdef MAC    printf("%s", sx);#else    printf("\r%s",sx);			/* Print the prompt. */#ifdef CK_SSL    if (!(ssl_active_flag || tls_active_flag))#endif /* CK_SSL */      fflush(stdout);			/* Now! */#endif /* MAC */#endif /* OSK */}#ifndef NOSPLVOIDpushcmd(s) char * s; {			/* For use with IF command. */    if (!s) s = np;    ckstrncpy(savbuf,s,CMDBL);		/* Save the dependent clause,  */    cmres();				/* and clear the command buffer. */    debug(F110, "pushcmd savbuf", savbuf, 0);}VOIDpushqcmd(s) char * s; {			/* For use with ELSE command. */    char c, * p = savbuf;		/* Dest */    if (!s) s = np;			/* Source */    while (*s) {			/* Get first nonwhitespace char */	if (*s != SP)	  break;	else	  s++;    }    if (*s != '{') {			/* If it's not "{" */	pushcmd(s);			/* do regular pushcmd */	return;    }    while (c = *s++) {			/* Otherwise insert quotes */	if (c == CMDQ)	  *p++ = CMDQ;	*p++ = c;    }    cmres();				/* and clear the command buffer. */    debug(F110, "pushqcmd savbuf", savbuf, 0);}#endif /* NOSPL */#ifdef COMMENT/* no longer used... */VOIDpopcmd() {    ckstrncpy(cmdbuf,savbuf,CMDBL);	/* Put back the saved material */    *savbuf = '\0';			/* and clear the save buffer */    cmres();}#endif /* COMMENT *//*  C M R E S  --  Reset pointers to beginning of command buffer.  */VOIDcmres() {    inword = 0;				/* We're not in a word */    cc = 0;				/* Character count is zero *//* Initialize pointers */    pp = cmdbuf;			/* Beginning of current field */    bp = cmdbuf;			/* Current position within buffer */    np = cmdbuf;			/* Where to start next field */    cmfldflgs = 0;    cmflgs = -5;                        /* Parse not yet started. */    ungw = 0;				/* Don't need to unget a word. */}/*  C M I N I  --  Clear the command and atom buffers, reset pointers.  *//*The argument specifies who is to echo the user's typein --  1 means the cmd package echoes  0 somebody else (system, front end, terminal) echoes*/VOIDcmini(d) int d; {#ifdef DCMDBUF    if (!atmbuf)      if (cmsetup()<0)	fatal("fatal error: unable to allocate command buffers");#endif /* DCMDBUF */#ifdef USE_MEMCPY    memset(cmdbuf,0,CMDBL);    memset(atmbuf,0,ATMBL);#else    for (bp = cmdbuf; bp < cmdbuf+CMDBL; bp++) *bp = NUL;    for (bp = atmbuf; bp < atmbuf+ATMBL; bp++) *bp = NUL;#endif /* USE_MEMCPY */    *atmbuf = *savbuf = *atxbuf = *atybuf = *filbuf = NUL;#ifdef OLDHELP    *hlpbuf = NUL;#endif /* OLDHELP */    blocklvl = 0;		/* Block level is 0 */    linebegin = 1;		/* And we're at the beginning of a line */    dpx = d;			/* Make a global copy of the echo flag */    debug(F101,"cmini dpx","",dpx);    crflag = 0;    qmflag = 0;    esflag = 0;#ifdef CK_RECALL    no_recall = 0;#endif /* CK_RECALL */    cmres();}#ifndef NOSPL/* The following bits are to allow the command package to call itself *//* in the middle of a parse.  To do this, begin by calling cmpush, and *//* end by calling cmpop. */#ifdef DCMDBUFstruct cmp {    int i[5];				/* stack for integers */    char *c[3];				/* stack for pointers */    char *b[8];				/* stack for buffer contents */};struct cmp *cmp = 0;#elseint cmp_i[CMDDEP+1][5];			/* Stack for integers */char *cmp_c[CMDDEP+1][5];		/* for misc pointers */char *cmp_b[CMDDEP+1][7];		/* for buffer contents pointers */#endif /* DCMDBUF */int cmddep = -1;			/* Current stack depth */intcmpush() {				/* Save the command environment */    char *cp;				/* Character pointer */    if (cmddep >= CMDDEP)		/* Enter a new command depth */      return(-1);    cmddep++;    debug(F101,"&cmpush","",cmddep);#ifdef DCMDBUF    /* allocate memory for cmp if not already done */    if (!cmp && !(cmp = (struct cmp *) malloc(sizeof(struct cmp)*(CMDDEP+1))))      fatal("cmpush: no memory for cmp");    cmp[cmddep].i[0] = cmflgs;		/* First do the global ints */    cmp[cmddep].i[1] = cmfsav;    cmp[cmddep].i[2] = atxn;    cmp[cmddep].i[3] = ungw;    cmp[cmddep].c[0] = bp;		/* Then the global pointers */    cmp[cmddep].c[1] = pp;    cmp[cmddep].c[2] = np;#else    cmp_i[cmddep][0] = cmflgs;		/* First do the global ints */    cmp_i[cmddep][1] = cmfsav;    cmp_i[cmddep][2] = atxn;    cmp_i[cmddep][3] = ungw;    cmp_c[cmddep][0] = bp;		/* Then the global pointers */    cmp_c[cmddep][1] = pp;

⌨️ 快捷键说明

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