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

📄 ckuus6.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef LUDEBUGif (zz) printf("MATCHING: [%s] [%s], n1=%d\n",s,info[1],n1);#endif /* LUDEBUG */	    if (ckstrcmp(s,info[1],n1,0)) /* Caseless string comparison */	      continue;#ifdef LUDEBUGif (zz) printf("MATCH OK: [%s] [%s], n1=%d\n",s,info[1],n1);#endif /* LUDEBUG */	    if (!info[2])		/* No phone number given */	      continue;	    if ((n2 = (int) strlen(info[2])) < 1) /* Length of phone number */	      continue;			/* Ignore empty phone numbers */	    /* Got one */	    if (!(pp = (char *)malloc(n2 + 1))) { /* Allocate storage for it */		printf("?internal error - ludial malloc 1\n");		if (line) {		    free(line);		    line = NULL;		}		dncount = 0;		return(-1);	    }	    strcpy(pp,info[2]);		/* Copy number into malloc'd storage */	    if (dncount > MAXDNUMS) {		printf("Warning: %d matches found, %d max\n",		       dncount,		       MAXDNUMS		       );		dncount = MAXDNUMS;		break;	    }	    dn_p[dncount++] = pp;	/* Add pointer to array. */	    if (dncount == 1) {		/* First one... */		if (d_name) free(d_name);		if (!(d_name = (char *)malloc(n3 + 1))) { /* Save its name */		    printf("?internal error - ludial malloc 2\n");		    if (line) {			free(line);			line = NULL;		    }		    dncount = 0;		    return(-1);		}		t = n3;			/* And its length */		strcpy(d_name,info[1]);	    } else {			/* Second or subsequent one */#ifdef LUDEBUG		if (zz)		  printf("d_name=[%s],info[1]=%s,t=[%d]\n",d_name,info[1],t);#endif /* LUDEBUG */		if ((int) strlen(info[1]) == t) /* Lengths compare */		  if (!ckstrcmp(d_name,info[1],t,0)) /* Caseless compare OK */		    continue;		/* Name given by user matches entries with different names */		if (ambiguous)		/* Been here before */		  break;		ambiguous = 1;		/* Now an exact match is required */		for (j = 0; j < dncount; j++) { /* Clean out previous list */		    if (dn_p[j]) {			free(dn_p[j]);			dn_p[j] = NULL;		    }		}		pass++;			/* Second pass... */		goto lu_again;		/* Do it all over again. */	    }	}    }    if (line) free(line);    if (dncount == 0 && ambiguous) {	printf(" Lookup: \"%s\" - ambiguous%s\n",	       s,	       cx == XXLOOK ? "" : " - dialing skipped"	       );	return(-2);    }    return(dncount);}char *pncvt(s) char *s; {			/* Phone number conversion */    char *p = NULL;			/* (just a wrapper for dncvt() */    char *q = NULL;    static char pnbuf[128];    makestr(&p,dn_p[0]);		/* Save these in case they are */    makestr(&q,dn_p2[0]);		/* being used */    makestr(&dn_p[0],s);		/* Copy the argument string to here */    dncvt(0,XXLOOK,1,1);		/* Convert it */    if (!dn_p2[0])			/* Put result where can return it */      pnbuf[0] = NUL;    else      ckstrncpy(pnbuf,dn_p2[0],127);    makestr(&dn_p[0],p);		/* Restore these */    makestr(&dn_p2[0],q);    makestr(&p,NULL);			/* Free these */    makestr(&q,NULL);    return((char *)pnbuf);}intdodial(cx) int cx; {			/* DIAL or REDIAL */    int i = 0, x = 0;			/* Workers */    int sparity = -1;			/* For saving global parity value */    int previous = 0;    int len = 0;    int literal = 0;    int flowsave;    int lufound = 0;			/* Did any lookup succeed? */    int prefix = 1;    int postfix = 1;    int wasalpha = 0;    int xredial = 0;    int braces = 0;    char *p = NULL, *s3 = NULL, * sav = NULL;    int j = 0, t = 0, n = 0;    int xretries, xlcc;    extern int what;    debug(F101,"dodial cx","",cx);    debug(F111,"dodial diallcc",diallcc,diallcc);    xretries = dialrtr;			/* If retries not set, */    if (diallcc) {			/* choose default based on */        xlcc = atoi(diallcc);		/* local country code. */	if (xretries < 0) {	  switch (xlcc) {	    case 1: xretries = 10; break; /* No restrictions in NANP */	      /* Add other country codes here */	      /* that are known to have no restrictions on redialing. */	    default: xretries = 1;	  }	}    }    if (cx == XXPDIA) {			/* Shortcut... */	cx = XXDIAL;	partial = 1;	debug(F100,"PDIAL sets partial=1","",0);	postfix = 0;                    /* Do not add postfix */    } else {	partial = 0;	debug(F100,"DIAL sets partial=0","",0);    }    previous = dialsta;			/* Status of previous call, if any */    if (previous == DIA_PART) {	prefix = 0;			/* do not add prefix */    }    if (cx != XXLOOK) {			/* Not LOOKUP */#ifdef IKSD        if (inserver) {            printf("Sorry, dialing is disabled.\r\n");            return(success = 0);        }#endif /* IKSD */#ifdef CK_TAPI	if (tttapi && !tapipass) {	  ; 				/* Skip the modem test if TAPI */	} else#endif /* CK_TAPI */	if (mdmtyp < 1 && !dialtest) {	    if (network)	      printf("Please SET HOST first, and then SET MODEM TYPE\n");	    else	      printf("Sorry, you must SET MODEM TYPE first\n");	    dialsta = DIA_NOMO;	    return(success = 0);	}	if (!local && !dialtest) {	    printf("Sorry, you must SET %s or SET HOST first\n",#ifdef OS2		   "PORT"#else		   "LINE"#endif /* OS2 */		   );	    dialsta = DIA_NOLI;	    return(success = 0);	}	if (!network && !dialtest &&#ifdef CK_TAPI	     !tttapi &&#endif /* CK_TAPI */	    (speed < 0L)#ifdef UNIX	    && (strcmp(ttname,"/dev/null"))#else#ifdef OSK	    && (strcmp(ttname,"/nil"))#endif /* OSK */#endif /* UNIX */	    ) {	    printf("\nSorry, you must SET SPEED first\n");	    dialsta = DIA_NOSP;	    return(success = 0);	}    }    s = NULL;				/* Initialize user's dial string */    if (cx == XXRED) {			/* REDIAL or... */	if ((y = cmcfm()) < 0)	  return(y);    } else if (cx == XXANSW) {		/* ANSWER or ... */	if ((y = cmnum("timeout (seconds)","0",10,&x,xxstring)) < 0)	  return(y);	dialatmo = x;	if ((y = cmcfm()) < 0)	  return(y);    } else {				/* DIAL or LOOKUP */	if (ndialdir > 0)	  s3 = "Number to dial or entry from dial directory";	else	  s3 = "Number to dial";	if ((x = cmtxt(s3, dialnum ? dialnum : "",&s,xxstring)) < 0)	  return(x);	if (s) {	    len = (int) strlen(s);	    ckstrncpy(tmpbuf,s,TMPBUFSIZ); /* Save literal copy */	    if (len > 1) {		/* Strip outer braces if given */		if (*s == '{') {		    if (s[len-1] == '}') {			s[len-1] = NUL;			s++;			len -= 2;		    }		}	    }	}    }    if (cx != XXANSW) {	for (j = 0; j < MAXDNUMS; j++) { /* Initialize dial-number list */	    if (!dialnum) {		/* First time dialing */		dn_p[j] = NULL;		/* initialize all pointers. */		dn_p2[j] = NULL;	    } else if (dn_p[j]) {	/* Not the first time, */		free(dn_p[j]);		/* free previous, if any, */		dn_p[j] = NULL;		/* then set to NULL. */		if (dn_p2[j])		  free(dn_p2[j]);		dn_p2[j] = NULL;	    } else break;		/* Already NULL */	}	if (len == 0)	  s = NULL;	if (!s)	  s = dialnum;	if (!s) {	    if (cx == XXLOOK)	      printf("?Lookup what?\n");	    else	      printf("%s\n", (cx == XXRED) ?		   "?No DIAL command given yet" :		   "?You must specify a number to dial"		   );	    return(-9);	}    /* Now we have the "raw" dial or lookup string and s is not NULL */	makestr(&dscopy,s);		/* Put it in a safe place */	s = dscopy;	n = 0;	debug(F111,"dodial",s,ndialdir);	wasalpha = 0;	if (isalpha(*s)) {	    wasalpha = 1;	    if (ndialdir > 0) {		/* Do we have a dialing directory? */		n = ludial(s,cx);	/* Look up what the user typed */		if (n == 0)		  printf(" Lookup: \"%s\" - not found%s\n",			 s,			 cx == XXLOOK ? "" : " - dialing as given\n"			 );	    }	    debug(F101,"dodial",s,n);	    if (n < 0 && cx != XXLOOK) { /* Error out if they wanted to dial */		if (n == -1)		/* -2 means ludial already gave msg */		  printf(" Lookup: fatal error - dialing skipped\n");		dialsta = DIA_DIR;		return(-9);	    }	    if (n > 0)			/* A successful lookup */	      lufound = 1;	} else if (*s == '=') {		/* If number starts with = sign */	    s++;			/* strip it */	    literal = 1;		/* remember this */	    while (*s == SP) s++;	/* and then also any leading spaces */	} else if (tmpbuf[0] == '{' && tmpbuf[1] == '{') {	    makelist(tmpbuf,dn_p,MAXDNUMS);	    makestr(&dscopy,tmpbuf);	    s = tmpbuf;	    for (n = 0; n < MAXDNUMS; n++) /* (have to count how many) */	      if (!dn_p[n]) break;	    braces = 1;	}	if (cx == XXLOOK && !wasalpha && !braces) {	    /* We've been told to lookup a number or a quoted name */	    char *p;	    n = 0;	    p = literal ? s : pncvt(dscopy);	    if (!p) p = "";	    if (*p) {		printf("%s  => %s\n", dscopy, p);		return(success = 1);	    } else {		printf("?Bad phone number\n");		return(success = 0);	    }	}	/* Save DIAL or successful LOOKUP string for future DIAL or REDIAL */	/* But don't save pieces of partial dial ... */	debug(F101,"DIAL save dialnum partial","",partial);	debug(F101,"DIAL save dialnum previous","",previous);	if ((cx == XXDIAL && partial == 0 && previous != DIA_PART) ||	    (cx == XXLOOK && n > 0)) {	    makestr(&dialnum,dscopy);	    if (!quiet && dscopy && !dialnum)	      printf("WARNING - memory allocation failure: redial number\n");	}	if (n > 0) {	    if (!quiet && !backgrd && !braces /* && dialdpy */ ) {		if (!strcmp(d_name,s))		  printf(" Lookup: \"%s\" - exact match\n",s);		else		  printf(" Lookup: \"%s\" - uniquely matches \"%s\"\n",			 s,			 d_name			 );	    }	    if ((cx == XXLOOK) || (n > 1)  &&		!quiet && !backgrd /* && dialdpy */ ) {		printf(" %d telephone number%sfound for \"%s\"%s\n",		       n,		       (n == 1) ? " " : "s ",		       s,		       (n > 0) ? ":" : "."		       );		s3 = getdname();	    }	    for (i = 0; i < n; i++) {	/* Convert */		dn_x[i] = -1;		if (dncvt(i,cx,prefix,postfix) < 0) {		    if (cx != XXLOOK) {			dialsta = DIA_DIR;			return(-9);		    }		}	    }	    if (dialsrt && n > 1) {	/* Sort into optimal order */		for (i = 0; i < n-1; i++) {		    for (j = i+1; j < n; j++) {			if (dn_x[j] < dn_x[i]) {			    t = dn_x[j];			    dn_x[j] = dn_x[i];			    dn_x[i] = t;			    p = dn_p[j];			    dn_p[j] = dn_p[i];			    dn_p[i] = p;			    p = dn_p2[j];			    dn_p2[j] = dn_p2[i];			    dn_p2[i] = p;			}		    }		}	    }	    if ((cx == XXLOOK) || (n > 1)  &&		!quiet && !backgrd /* && dialdpy */ ) {		int nn = n;#ifndef NOSPL		char * p;#endif /* NOSPL */		if (cx != XXLOOK)		  if (n > 12) nn = 12;		for (i = 0; i < nn; i++) {		    printf("%3d. %-12s  %-20s =>  %-20s  (%d)\n",i+1,			   s3, dn_p[i],			   dn_p2[i] ? dn_p2[i] : "(processing failed)",			   dn_x[i]			   );		}		if (cx != XXLOOK && n != nn)		  printf("And %d more...\n", n - nn);	    }	} else if (n == 0) {		/* Not found in directory */	    makestr(&(dn_p[0]),literal ? s : dscopy);	    makestr(&d_name,literal ? s : dscopy);	    dncount = 1;	    n = 1;	    if (dncvt(0,cx,prefix,postfix) < 0) { /* In case they typed a */		dialsta = DIA_DIR;	/* portable-format number ... */		return(-9);	    }	}#ifndef NONET#ifdef NETCONN	/* It's not good that the networks directory depends on NOT-NODIAL.. */	if (cx == XXLOOK && dscopy) {	/* Networks here too... */	    extern char *nh_p[], *nh_p2[], *n_name;	    extern char *nh_px[4][MAXDNUMS+1];	    n = -1;	    if (nnetdir > 0) {		/* Do we have a network directory? */		dirline = 0;		n = lunet(dscopy);	/* Look up what the user typed */	    }	    if (n > -1) {		int k;		if (n > 0)		/* A successful lookup */		  lufound = 1;		if (cx == XXLOOK && n == 0)		  printf(" Lookup: \"%s\" - not found\n",dscopy);		else		  printf("%s %d network entr%s found for \"%s\"%s\n",			 cx == XXLOOK ? " Lookup:" : "",			 n,			 (n == 1) ? "y" : "ies",			 dscopy,			 (n > 0) ? ":" : "."			 );		for (i = 0; i < n; i++) {		    printf("%3d. %-12s => %-9s %s",			   i+1,n_name,nh_p2[i],nh_p[i]);		    for (k = 0; k < 4; k++) {			if (nh_px[k][i]) {			    printf(" %s",nh_px[k][i]);			} else			  break;		    }		    printf("\n");		}	    }	}#endif /* NETCONN */#endif /* NONET */	if (cx == XXLOOK)	  return(success = lufound);    } /* cx != XXANSW */#ifdef VMS    conres();			/* So Ctrl-C/Y will work */#endif /* VMS *//*  Some modems do not react well to parity.  Also, if we are dialing through a  TCP/IP TELNET modem server, parity can be fatally misinterpreted as TELNET  negotiations.  This should wo

⌨️ 快捷键说明

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