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

📄 ckuus6.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	    sprintf(outbuf,"%s%s%s%s%s%s%s", /* Form the number to be dialed */		    pxo,npr,p,acptr,s,p2,sfx		    );	    sprintf(pdsfx,"%s%s",p2,sfx);	} else {			/* Same country, same area code */	    what = dn_x[k] = DN_LOCAL;	/* So it's a local call. */	    if (!prefix || !(dialpxo || ndialpxx)) { /* Not dialing from PBX */                p  = (prefix && diallcp) ? diallcp : ""; /* local-prefix */                p2 = (suffix && diallcs) ? diallcs : ""; /* local-suffix */		if (x == 2)		  sprintf(outbuf,"%s%s%s%s%s%s",npr,p,acptr,s,p2,sfx);		else		  sprintf(outbuf,"%s%s%s%s%s",npr,p,s,p2,sfx);		sprintf(pdsfx,"%s%s",p2,sfx);	    } else {			/* Dialing from a PBX and not TAPI */		if (ndialpxx) {		/* Is it internal? */#ifdef COMMENT		    i = (int) strlen(dialpxx);		    j = (int) strlen(s);		    x = -1;		    if (j > i)		      x = ckstrcmp(dialpxx,s,i,0);#else		    int kx;		    x = -1;		    j = (int) strlen(s);		    for (kx = 0; kx < ndialpxx; kx++) {			i = (int) strlen(dialpxx[kx]);			if (j > i)			  if (!(x = ckstrcmp(dialpxx[kx],s,i,0)))			    break;		    }#endif /* COMMENT */		    if (!x) {			char * icp, buf[32];			makestr(&matchpxx,dialpxx[kx]);			debug(F111,"dncvt matchpxx",matchpxx,kx);			what = dn_x[kx] = DN_INTERN;   /* Internal call. */			s += i;			/* Internal-call prefix */			icp = dialpxi;#ifndef NOSPL			if (icp) {			    if (*icp == '\\') {				char c, *bp;				int n;				c = *(icp+1);				if (isupper(c)) c = tolower(c);				if (c == 'v' || c == 'f') {				    n = 32;				    bp = buf;				    zzstring(icp,&bp,&n);				    icp = buf;				}			    }			}#endif /* NOSPL */			p = (prefix && icp) ? icp : "";			sprintf(outbuf,"%s%s%s%s",				npr,p,s,sfx				);		    } else {		/* External local call */			/* local-prefix */                        p  = (prefix && diallcp) ? diallcp : "";			/* local-suffix */                        p2 = (prefix && diallcs) ? diallcs : "";			if (x == 2)			  sprintf(outbuf,"%s%s%s%s%s%s%s",				  dialpxo ? dialpxo : "",				  npr,p,acptr,s,p2,sfx);			else			  sprintf(outbuf,				  "%s%s%s%s%s%s",				  dialpxo ? dialpxo : "",				  npr,p,s,p2,sfx				  );		    }		}	    }	}    } else {				/* Area code was not delimited */	char xbuf[256];			/* Comparison based only on length */	char ybuf[256];	int x, j;	s = ss;	for (i = 0; i < 255; i++) {	    if (!*s) break;	    while (!isdigit(*s)) {	/* Only pay attention to digits */		s++;		if (!*s) break;	    }	    xbuf[i] = *s++;	}	xbuf[i] = NUL;	x = 1;				/* Assume LD */	n = 0;	if (!dialfld) {			/* If LD not forced */	    for (j = 0; j < nlocalac; j++) { /* check local AC list? */		sprintf(ybuf,"%s%s",diallcc,diallcac[j]);		n = (int) strlen(ybuf);		if (n > 0 && !ckstrcmp(xbuf,ybuf,n,0)) {		    x = 2;		    break;		}	    }	    if (x == 1) {		/* Or exact match with local CC+AC? */		sprintf(ybuf,"%s%s",diallcc,lac);		n = (int) strlen(ybuf);		if (n > 0 && !ckstrcmp(xbuf,ybuf,n,0))		  x = 0;	    }	}	if (x == 0 || x == 2) {		/* Local call */	    dn_x[k] = DN_LOCAL;	    p = (prefix && diallcp) ? diallcp : "";	    p2 = (suffix && diallcs) ? diallcs : "";	    s = (char *) (xbuf + ((x == 0) ? n : (int)strlen(diallcc)));	    sprintf(outbuf,"%s%s%s%s%s%s",pxo,npr,p,s,p2,sfx);	    sprintf(pdsfx,"%s%s",p2,sfx);	} else {			/* Not local */	    n = ckstrncpy(ybuf,diallcc,256);	    if (n > 0 && !ckstrcmp(xbuf,ybuf,n,0)) { /* Long distance */		dn_x[k] = DN_LONG;		p = (prefix && dialldp) ? dialldp : "";		p2 = (suffix && diallds) ? diallds : "";		s = xbuf + n;		while (*s == '-' || *s == '.')		  s++;		sprintf(outbuf,"%s%s%s%s%s%s",pxo,npr,p,s,p2,sfx);		sprintf(pdsfx,"%s%s",p2,sfx);	    } else {		dn_x[k] = DN_INTL;	/* International */		if (!dialixp) {		    if (cx != XXLOOK) {			printf(			  "Error - No international dialing prefix defined\n"			       );			return(-1);		    }		}		p = (prefix && dialixp) ? dialixp : "";		p2 = (suffix && dialixs) ? dialixs : "";		sprintf(outbuf,"%s%s%s%s%s%s",pxo,npr,p,xbuf,p2,sfx);		sprintf(pdsfx,"%s%s",p2,sfx);	    }	}    }#ifdef CK_TAPI    if (tttapi &&			/* TAPI performs the conversions */	!tapipass &&	tapiconv == CK_AUTO ||	tapiconv == CK_ON	) {	p = NULL;	dialtype = -2;	if (!cktapiConvertPhoneNumber(dn_p[k],&p))	  return(-1);	makestr(&dn_p2[k], p);	if (p) free(p);	return(0);    } else {#endif /* CK_TAPI */	makestr(&dn_p2[k], outbuf);#ifdef CK_TAPI    }#endif /* CK_TAPI */    dialtype = what;    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 */	perror(s2);			/* to new (wierd) name. */	goto ddexit;    }#endif /* VMS */    if ((f = fopen(s2,"r")) == NULL) {	/* Reopen old file with wierd name */	dirline = 0;			/* (or in VMS, old version) */	perror(s2);	goto ddexit;    }    if ((f2 = fopen(s,"w")) == NULL) {	/* Create new file with old name */	perror(s);			/* (or in VMS, new version) */	goto ddexit;    }    printf("\nSaving old directory as %s.\nConverting %s...",s2,s);    fprintf(f2,"; %s - Kermit dialing directory\n", s);    fprintf(f2,"%-16s %-20s ; %5s %-6s ; %s\n",	       "; Name","Number","Speed","Parity","Comment"	       );    while (1) {	line[0] = NUL;			/* Read a line */	if (fgets(line,1023,f) == NULL)	  break;	if (!line[0]) {			/* Empty line */	    fprintf(f2,"\n");	    continue;	}	x = (int) strlen(line);		/* Strip line terminator, */	while (x-- > 0) {		/* if any. */	    if (line[x] <= SP)	      line[x] = NUL;	    else	      break;	}	xwords(line,5,info,1);		/* Parse it the old way */	for (x = 1; x < 6; x++)	  if (!info[x]) info[x] = "";	fprintf(f2,"%-16s %-20s ; %5s %-6s %s\n",	       info[1],info[2],info[3],info[4],info[5]	       );    }    printf(" OK\n\n");    rc = 0;				/* Success */  ddexit:    if (f) fclose(f);    if (f2) fclose(f2);    if (line) free(line);    return(rc);}int					/* s = name to look up   */#ifdef CK_ANSIC				/* cx = index of command */ludial(char *s, int cx)			/* (DIAL, LOOKUP, etc)   */#elseludial(s, cx) char *s; int cx;#endif /* CK_ANSIC *//* ludial */ {    int dd, n1, n2, n3, i, j, t;	/* Workers */    int olddir, newdir, oldentry, newentry;    int pass = 0;    int oldflg = 0;    int ambiguous = 0;			/* Flag for lookup was ambiguous */    char *info[7];			/* Pointers to words from entry */    char *pp;				/* Pointer to element of array */    FILE * f;    char *line;				/* File input buffer *//* #define LUDEBUG */#ifdef LUDEBUGint zz = 1;#endif /* LUDEBUG */    if (!s || ndialdir < 1)		/* Validate arguments */      return(-1);    if ((n1 = (int) strlen(s)) < 1)	/* Length of string to look up */      return(-1);    if (!(line = malloc(1024)))		/* Allocate input buffer */      return(-1);#ifdef LUDEBUGif (zz) printf("LUDIAL 1 s[%s], n1=%d\n",s,n1);#endif /* LUDEBUG */    pass = 0;  lu_again:    f = NULL;				/* Dial directory file descriptor */    t = dncount = 0;			/* Dial-number match count */    dd = 0;				/* Directory counter */    olddir = 0;    newdir = 0;/*  We need to recognize both old- and new-style directories.  But we can't allow old-style and new-style entries in the same  directory because there is no way to tell for sure the difference between  an old-style entry like this:    foo  5551212  9600  and a new-style literal entry like this:    foo  555 9600  I.e. is the "9600" a speed, or part of the phone number?*/    while (1) {				/* We make one pass */	if (!f) {			/* Directory not open */            if (dd >= ndialdir)		/* No directories left? */	      break;			/* Done. */	    if ((f = fopen(dialdir[dd],"r")) == NULL) { /* Open it */		perror(dialdir[dd]);	/* Can't, print message saying why */		if (line) {		    free(line);		    line = NULL;		}		dd++;			/* Go on to next one, if any... */		continue;	    }	    dirline = 0;		/* Directory file line number */	    if (dialdpy && !pass)	      printf("Opening: %s...\n",dialdir[dd]);            dd++;	    if (!oldflg) olddir = 0;	    newdir = 0;	}	oldentry = 0;	newentry = 0;	line[0] = NUL;	if (getnct(line,1023,f,1) < 0) { /* Read a line */	    if (f) {			/* f can be clobbered! */		fclose(f);		/* Close the file */		f = NULL;		/* Indicate next one needs opening */		oldflg = 0;	    }	    continue;	}	if (!line[0])			/* Empty line */	  continue;#ifdef LUDEBUGif (zz) printf("LUDIAL 2 s[%s]\n",s);#endif /* LUDEBUG */	/* Make a copy and parse it the old way */	/* A copy is needed because xwords() pokes NULs into the string */	if (pp = malloc((int)strlen(line) + 1)) {	    strcpy(pp,line);	    xwords(pp,5,info,0);	/* Parse it the old way */#ifdef LUDEBUGif (zz) printf("LUDIAL 3 s[%s]\n",s);#endif /* LUDEBUG */	    if (!info[1])	      continue;	    if (*info[1] == ';') {	/* If full-line comment, */		newdir = 1;		/* (only new directories have them) */		continue;		/* keep reading. */	    }	    if (!info[2])	      continue;	    if (*info[2] == '+')	      newentry = 1;	    if (info[4]) {		if ((*info[4] == '=') ||		    !ckstrcmp(info[4],"none", 4,0) ||		    !ckstrcmp(info[4],"even", 4,0) ||		    !ckstrcmp(info[4],"space",5,0) ||		    !ckstrcmp(info[4],"mark", 4,0) ||		    !ckstrcmp(info[4],"odd",  3,0)		    )		  oldentry = 1;	    }	}	if (pp) {	    free(pp);	    pp = NULL;	}	/* Check consistency */	if ((oldentry || olddir) && (newentry || newdir)) {	    printf("\nERROR: You seem to have old- and new-format entries mixed in your\n");	    printf("dialing directory.  You'll have to edit it by hand to convert it to the\n");#ifndef NOHELP	    printf("new format.  Type HELP DIAL for further information.\n\n");#else	    printf("new format.\n\n");#endif /* NOHELP */	    if (line) {		free(line);		line = NULL;	    }	    return(-1);	}	if (!olddir && oldentry) {	    int convert = 0;	    olddir = 1;	    if (dialcvt == 2) {		/* 2 == ASK */		printf("\nWARNING: Old-style dialing directory detected:\n%s\n\n", line);		convert = getyesno("Shall I convert it for you? ",0);	    } else	      convert = dialcvt;	    if (convert) {		if (ddcvt(dialdir[dd-1],f,dd-1) < 0) {		    oldflg = 1;		    printf("  Sorry, can't convert.");		    printf("  Will ignore speed and parity fields, continuing...\n\n");		} else {		    olddir = newdir = 0;		}		dd--;		f = NULL;		continue;	    } else {		if (dialcvt == 2)		  printf("  OK, will ignore speed and parity fields, continuing...\n\n");		olddir = 1;	    }	}#ifdef LUDEBUGif (zz) printf("LUDIAL XX s[%s], n1=%d\n",s,n1);#endif /* LUDEBUG */	/* Now parse again for real */	if (oldentry)			/* Parse it the old way */	  xwords(line,5,info,0);	else				/* Parse it the new way */	  xwords(line,2,info,1);#ifdef LUDEBUGif (zz) printf("LUDIAL YY s[%s], n1=%d\n",s,n1);if (zz) printf("%s [%s]\n",info[1],info[2]);#endif /* LUDEBUG */	if (info[1]) {			/* First word is entry name */	    if ((n3 = (int) strlen(info[1])) < 1) /* Its length */	      continue;			/* If no first word, keep reading. */	    if (n3 < n1)		/* Search name is longer */	      continue;			/* Can't possibly match */	    if (ambiguous && n3 != n1)	      continue;

⌨️ 快捷键说明

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