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

📄 ckuus6.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (y == -3) {	    printf("?Variable name required\n");	    return(-9);	} else return(y);    }    strncpy(vnambuf,s,VNAML);    if ((y = cmnum("by amount","1",10,&x,xxstring)) < 0)      return(y);    if ((y = cmcfm()) < 0)      return(y);    z = (cx == XXINC ? 1 : 0);		/* Increment or decrement? */    if (incvar(vnambuf,x,z) < 0) {	printf("?Variable %s not defined or not numeric\n",vnambuf);	return(success = 0);    }    return(success = 1);}#endif /* NOSPL *//* Do the (_)DEFINE, (_)ASSIGN, and UNDEFINE commands */#ifndef NOSPLintdodef(cx) int cx; {    char vnambuf[VNAML];		/* Buffer for variable names */    char *vnp;				/* Pointer to same */    if (cx == XXDFX || cx == XXASX)       y = cmfld("Macro or variable name","",&s,xxstring); /* eval var name */    else       y = cmfld("Macro or variable name","",&s,NULL);     /* don't evaluate */    if (y < 0) {	if (y == -3) {	    printf("?Variable name required\n");	    return(-9);	} else return(y);    }    debug(F111,"dodef success",s,success);    strcpy(vnambuf,s);    vnp = vnambuf;    if (vnambuf[0] == CMDQ && (vnambuf[1] == '%' || vnambuf[1] == '&')) vnp++;    if (*vnp == '%' || *vnp == '&') {	if ((y = parsevar(vnp,&x,&z)) < 0) return(y);	if (cx == XXUNDEF) {		/* Undefine */	    if ((y = cmcfm()) < 0) return(y);	    delmac(vnp);	    return(success = 1);	}	debug(F101,"dodef","",x);	if (y == 1) {			/* Simple variable */	    if ((y = cmtxt("Definition of variable","",&s,NULL)) < 0)	      return(y);	    s = brstrip(s);	    debug(F110,"xxdef var name",vnp,0);	    debug(F110,"xxdef var def",s,0);	} else if (y == 2) {		/* Array element */	    if ((y = arraynam(s,&x,&z)) < 0) return(y);	    if (x == 96) {		printf("?Argument vector array is read-only\n");		return(-9);	    }	    if (chkarray(x,z) < 0) return(-2);	    if ((y = cmtxt("Definition of array element","",&s,NULL)) < 0)	      return(y);	    debug(F110,"xxdef array ref",vnp,0);	    debug(F110,"xxdef array def",s,0);	}    } else {				/* Macro */	if (cx == XXUNDEF) {		/* Undefine */	    if ((y = cmcfm()) < 0) return(y);	    delmac(vnp);	    return(success = 1);	}	if ((y = cmtxt("Definition of macro","",&s,NULL)) < 0) return(y);	debug(F110,"xxdef macro name",vnp,0);	debug(F110,"xxdef macro def",s,0);	if (*s == '{') {		/* Allow macro def to be bracketed. */	    s++;			/* If it is, remove the brackets. */	    y = (int)strlen(s);		/* FOR command depends on this! */	    if (y > 0 && s[y-1] == '}') s[y-1] = NUL;	}    }    if (*s == NUL) {			/* No arg given, undefine */	delmac(vnp);			/* silently... */	return(success = 1);		/* even if it doesn't exist... */    }     /* Defining a new macro or variable */    if (cx == XXASS || cx == XXASX) {	/* ASSIGN rather than DEFINE? */	int t;	t = LINBUFSIZ-1;	lp = line;			/* If so, expand its value now */	zzstring(s,&lp,&t);	s = line;    }    debug(F111,"calling addmac",s,(int)strlen(s));    y = addmac(vnp,s);			/* Add it to the appropriate table. */    if (y < 0) {	printf("?%s failed\n",(cx == XXASS || cx == XXASX) ?	       "ASSIGN" : "DEFINE");	return(success = 0);    } else if (cx == XXASX || cx == XXDFX) /* For _ASG or _DEF, */      return(1);			   /* don't change success variable */    else      return(success = 1);}#endif /* NOSPL */#ifndef NODIAL/*   L U D I A L  --  Lookup up dialing directory entry.     Call with string to look up and file descriptor of open dialing directory   file.  On success, returns number of matches found, with numbers stored   in an array accessible via getdnum().*/static char *dn_p[MAXDNUMS + 1];	/* Dial Number pointers */static char *dn_p2[MAXDNUMS + 1];	/* Converted dial number pointers */static int dn_x[MAXDNUMS + 1];		/* Type of call */static int dncount = 0;char * d_name = NULL;			/* Dial name pointer */char *					/* Get dial directory entry name */getdname() {    return(d_name ? d_name : "");}char *getdnum(n) int n; {			/* Get dial number n from directory */    if (n < 0 || n > dncount || n > MAXDNUMS)      return("");    else      return(dn_p[n]);}char *			/* Check area code for spurious leading digit */chk_ac(i,buf) int i; char buf[]; {    char *p;    if (!buf)      return("");    p = (char *) buf;			/* Country we are calling: */    if (i ==  44 ||			/* UK */	i ==  49 ||			/* Germany */	i ==  39 ||			/* Italy */	i ==  31 ||			/* Netherlands */	i == 351 ||			/* Portugal */	i ==  55 ||			/* Brazil */	i == 972 ||			/* Israel */	i ==  41 ||			/* Switzerland */	i ==  43 ||			/* Austria */	i ==  42 ||			/* Czech Republic */	i ==  36 ||			/* Hungary */	i ==  30 ||			/* Greece */	i == 352 ||			/* Luxembourg */	i ==  48 ||			/* Poland */	i ==  27 ||			/* South Africa */	((i == 33) && ((int) strcmp(zzndate(),"19961017") > 0))	/* France */	) {	if (buf[0] == '0')	  p++;    } else if (i == 358) {		/* Finland */	char c = '9';	if ((int) strcmp(zzndate(),"19961011") > 0)	  c = '0';	if (buf[0] == c)		/* But only until 12 Oct 96! */	  p++;    }    return(p);}static intdncvt(k,cx) int k, cx; {		/* Dial Number Convert */    int i, j, n, what;    char *ss;    char *p, *pxo;    char **pp;    char *lac;    char *npr;    char *sfx;    char ccbuf[128];    int cc;    char acbuf[24];    char *acptr;    char outbuf[256];#define DN_INTERN 0#define DN_FREE   1#define DN_LOCAL  2#define DN_UNK    3#define DN_LONG   4#define DN_INTL   5/*  First pass for strict (punctuation-based) interpretation.  If it fails, we try the looser (length-based) one.*/    what = 0;				/* Type of call */    s = dn_p[k];			/* Number to be converted. */    debug(F111,"dncvt",s,k);    if (dn_p2[k]) {	free(dn_p2[k]);	dn_p2[k] = NULL;    }    if (!s) {	printf("Error - No phone number to convert\n");	return(-1);    }    pp = &(dn_p2[k]);			/* Address for converted number */    if (tttapi) {			/* When using TAPI */	npr = "";			/* TAPI supplies all the */	sfx = "";			/* prefixes and suffixes */	pxo = "";    } else {	npr = dialnpr ? dialnpr : "";	sfx = dialsfx ? dialsfx : "";	pxo = dialpxo ? dialpxo : "";    }    lac = diallac ? diallac : "";	/* Local area code */    outbuf[0] = NUL;			/* Initialize conversion buffer */    ss = s;				/* Remember original string */    if (*s != '+') {			/* Literal number */	sprintf(outbuf,			/* Sandwich it between */		"%s%s%s%s",		/* DIAL PREFIX and SUFFIX */		pxo,npr,s,sfx		);	makestr(pp, outbuf);	dn_x[k] = DN_UNK;		/* Sort key is "unknown". */	return(0);			/* Done. */    }    i = 0;				/* Portable number */    s++;				/* Tiptoe past the plus sign */    ccbuf[0] = NUL;			/* Do country code first */    if (!diallcc) {			/* Do we know our own? */	if (cx != XXLOOK)	  printf("Error - prior SET DIAL COUNTRY-CODE command required\n");	return(-1);    }    /* Parse the number */    while (1) {				/* Get the country code */        while (*s == HT || *s == SP)	  s++;	if (!s)				/* Not in standard format */	  break;        if (*s == '(') {		/* Beginning of area code  */	    s++;			/* Skip past parenthesis   */	    ccbuf[i] = NUL;		/* End of country code */	    if (!s) {			/* Check for end of string */		printf("Error - phone number ends prematurely: \"%s\"\n",ss);		return(-1);	    }	    break;	} else {			/* Collect country code */	    if (isdigit(*s))	      ccbuf[i++] = *s;		/* copy this character */	    s++;	    if (!*s || i > 127)		/* watch out for memory leak */	      break;	}    }    cc = atoi(ccbuf);			/* Numeric version of country code */    i = 0;				/* Now get area code */    acbuf[0] = NUL;			/* Initialize area-code buffer */    acptr = acbuf;			/* and pointer. */    while (1) {        while (*s == HT || *s == SP)	/* Ignore whitespace */	  s++;	if (!s)				/* String finished */	  break;	if (*s == ')') {		/* End of area code  */	    s++;			/* Skip past parenthesis   */	    acbuf[i] = NUL;		/* Terminate area-code buffer */	    break;	} else {			/* Part of area code */	    if (isdigit(*s))		/* If it's a digit, */	      acbuf[i++] = *s;		/* copy this character */	    s++;			/* Point to next */	    if (!*s || i > 23)		/* Watch out for overflow */	      break;	}    }/*   Here we strip any leading 0 for countries that we know have   0 as a long-distance prefix and do not have any area codes that   start with 0 (ditto for "9" in Finland...)*/    i = atoi(ccbuf);    acptr = chk_ac(i,acbuf);    while (*s == HT || *s == SP)	/* Skip whitespace */      s++;/* printf("S=[%s], ACPTR=[%s]\n",s,acptr); */    if (*s && *acptr) {			/* Area code was delimited */	while (*s == '-' || *s == '.')	/* Skip past gratuitious punctuation */	  s++;	if (!*s) s--;			/* But not to end of string */	if (strcmp(diallcc,ccbuf)) {	/* Out of country? */	    char * p2;	    if (!dialixp) {		/* Need intl-prefix */		if (cx != XXLOOK)		  printf("Error - No international dialing prefix defined\n");		return(-1);	    }	    what = dn_x[k] = DN_INTL;	    if (tttapi) {		p  = "";		/* Intl-suffix */		p2 = "";		/* Intl-prefix */	    } else {		p  = dialixp ? dialixp : ""; /* Intl-prefix */		p2 = dialixs ? dialixs : ""; /* Intl-suffix */	    }	    sprintf(outbuf,		/* Form the final phone number */		    "%s%s%s%s%s%s%s%s",		    pxo,npr,p,ccbuf,acptr,s,p2,sfx		    );	} else if (strcmp(lac,acptr)) { /* In-country */	    char * p2;#ifdef COMMENT/* Wrong - Sometimes it has to be null, e.g. for NANP 10-digit dialing... */	    if (!dialldp) {		/* Out of area code */		if (cx != XXLOOK)	/* Need ld-prefix */		  printf("Error - No long-distance prefix defined\n");		return(-1);	    }#endif /* COMMENT */	    if (!diallac && cx != XXLOOK) { /* Don't know my own area code */		if (cc == 1)		  printf("WARNING - Prior SET DIAL AREA-CODE needed\n");	    }	    what = dn_x[k] = DN_LONG;	/* Long-distance */	    for (i = 0; i < ntollfree; i++) { /* Check for toll-free call */		if (!strcmp(acptr,dialtfc[i])) {		    what = dn_x[k] = DN_FREE;		  		    break;		}	    }	    if (tttapi) {		/* TAPI supplies its own */		p  = "";		/* ld-suffix */		p2 = "";		/* ld-prefix */	    } else if (what == DN_FREE) { /* Toll-free call */		p = dialtfp ? dialtfp : (dialldp ? dialldp : "");		p2 = "";		/* no suffix */	    } else {			/* normal long distance */		p  = dialldp ? dialldp : ""; /* ld-prefix */		p2 = diallds ? diallds : ""; /* ld-suffix */	    }	    sprintf(outbuf,"%s%s%s%s%s%s%s", /* Form the number to be dialed */		    pxo,npr,p,acptr,s,p2,sfx		    );	} else {			/* Same country, same area code */	    what = dn_x[k] = DN_LOCAL;	/* So it's a local call. */	    if (!dialpxo || tttapi) {	/* TAPI or not dialing out from PBX */		sprintf(outbuf,"%s%s%s",			npr,s,sfx			);	    } else {			/* Dialing from a PBX and not TAPI */		if (dialpxx) {		/* Is it internal? */		    i = (int) strlen(dialpxx);		    j = (int) strlen(s);		    x = -1;		    if (j > i)		      x = xxstrcmp(dialpxx,s,i);		    if (!x) {			what = dn_x[k] = DN_INTERN;   /* Internal call. */			s += i;			p = (dialpxi) ? dialpxi : ""; /* Internal prefix */			sprintf(outbuf,"%s%s%s%s",    				npr,p,s,sfx				);		    } else {	/* External local call */			sprintf(outbuf,"%s%s%s%s",				dialpxo,npr,s,sfx				);		    }		}	    }	}    } else {				/* Area code was not delimited */	char xbuf[256];			/* Comparison based only on length */	char ybuf[256];	s = ss;	for (i = 0; i < 255; i++) {	    if (!*s)	      break;	    while (!isdigit(*s))	/* Only pay attention to digits */	      s++;	    xbuf[i] = *s++;	}	xbuf[i] = NUL;	sprintf(ybuf,"%s%s",diallcc,lac);	n = (int) strlen(ybuf);	if (n > 0 && !xxstrcmp(xbuf,ybuf,n)) { /* Local call */	    dn_x[k] = DN_LOCAL;	    s = xbuf + n;	    sprintf(outbuf,"%s%s%s%s",pxo,npr,s,sfx);	} else {			/* Not local */	    sprintf(ybuf,"%s",diallcc);	    n = (int) strlen(ybuf);	    if (n > 0 && !xxstrcmp(xbuf,ybuf,n)) { /* Long distance */		char * p2;		dn_x[k] = DN_LONG;#ifdef COMMENT		if (!dialldp) {		    if (cx != XXLOOK && !tttapi)		      printf("Error - No long-distance prefix defined\n");		    return(-1);		}#endif /* COMMENT */		if (tttapi) {		    p = "";		    p2 = "";		} else {		    p = dialldp ? dialldp : "";		    p2 = diallds ? diallds : "";		}		s = xbuf + n;		while (*s == '-' || *s == '.')		  s++;		sprintf(outbuf,"%s%s%s%s%s%s",pxo,npr,p,s,p2,sfx);	    } else {		char * p2;		/* International */		dn_x[k] = DN_INTL;		if (!dialixp) {		    if (cx != XXLOOK && !tttapi) {			printf(			  "Error - No international dialing prefix defined\n"			       );			return(-1);		    }		}		if (tttapi) {		    p = "";		    p2 = "";		} else {		    p = dialixp ? dialixp : ""; 		    p2 = dialixs ? dialixs : "";		}		sprintf(outbuf,"%s%s%s%s%s%s",pxo,npr,p,xbuf,p2,sfx);	    }	}    }    makestr(pp, outbuf);    return(0);}static intddcvt(s, f, n) char * s; FILE * f; int n; { /* Dial Directory Convert */    char *line, *s2;			/* buffers */#ifdef VMS    char * temp;#endif /* VMS */    char *info[8];			/* Pointers to words from entry */    FILE * f2;    int x, rc;    rc = -1;    if (!s || !f)			/* No filename or file */      return(-1);    if ((int) strlen(s) < 1)      return(-1);    if (!(line = malloc(1024)))		/* Allocate input buffer */      return(-1);    f2 = NULL;    fclose(f);    znewn(s,&s2);			/* s2 = address of static buffer */#ifdef VMS    temp = s2;				/* Swap - otherwise the new */    s2 = s;				/* version has the older version */    s = temp;				/* number... */    if (temp =  (char *)malloc((int)strlen(s)+1))      strcpy(temp,s);    if (dialdir[n])			/* Replace filename in list */      free(dialdir[n]);    dialdir[n] = temp;    s = temp;#else    if (zrename(s,s2) < 0) {		/* Not VMS - rename old file */

⌨️ 快捷键说明

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