📄 ckuus6.c
字号:
file. On success, returns pointer to phone number and sets speed and parity according to the directory entry. On failure, returns the NULL pointer.*/char *ludial(s,f) char *s; FILE *f; { int n, n1, n2, i, t; /* Workers */ long xspeed = -1L, x2; /* Speed to set from directory entry */ int xparity = -1; /* Parity to set ...*/ char *info[5]; /* Array of words from entry */ if (!s || !f) return(NULL); /* Validate arguments */ if ((n1 = strlen(s)) < 1) return(NULL);/* We make one or two passes. The first pass searches for an exact match. If it fails, the second pass searches for the first entry of which the search string is an abbreviation. Of course this could be done in one pass, but it was safer to add a couple lines for the for-loop than to totally rearrange the code at the last minute. (Edit 186)*/ for (i = 0; i < 2; i++) { /* Do this twice */ debug(F101,"ludial pass","",i+1); rewind(f); /* Go to beginning of directory file */ while (1) { if (fgets(line,LINBUFSIZ,f) == NULL) { /* Read a line */ if (i == 0) /* EOF */ break; /* If first pass, start second pass */ if (!backgrd && !quiet) /* If second pass, give message */ printf(" %s not in %s\n",s,dialdir); debug(F110,"ludial fails",s,0); return(NULL); } n = strlen(line); /* Strip terminator(s) */ while ((n > 0) && (line[n-1] < '!')) line[--n] = NUL; debug(F111,"ludial",line,n); info[0] = NULL; info[1] = NULL; info[2] = NULL; info[3] = NULL; info[4] = NULL; xwords(line,4,info); /* Get the words. */ if (info[1]) { /* First word. */ if ((n2 = (int) strlen(info[1])) < 1) /* Its length */ continue; /* If no first word, keep looking. */ if (n2 < n1) /* If directory entry name shorter */ continue; /* than search name, then no match. */ if (i == 0 && n2 != n1) /* Require exact match on first pass */ continue; if (xxstrcmp(s,info[1],n1)) /* Caseless string comparison */ continue; /* up to length of search name */ if (!backgrd && !quiet) printf(" From dialing directory %s: %s=%s\n", dialdir,info[1],info[2]); if (info[3]) { /* Third word = speed */ if (*info[3] != '=') { /* "=" means don't change it */ xspeed = atol(info[3]); x2 = xspeed / 10L; if (x2 > 0) { if (ttsspd((int) x2) < 0) printf("\n Can't set speed to %s\n",info[3]); else speed = xspeed; } } } if (info[4]) { /* 4th word = parity */ if (*info[4] != '=') { /* "=" means don't change it */ if ((xparity = lookup(partab,info[4],5,&t)) > -1) parity = xparity; } } return(info[2]); /* Return 2nd word = phone number */ } } }}intdodial(cx) int cx; { /* DIAL or REDIAL */ if (cx == XXRED) { /* REDIAL or... */ if ((y = cmcfm()) < 0) return(y); if (dialnum) { s = dialnum; } else { printf("?No DIAL command given yet\n"); return(-9); } } else if (cx == XXDIAL) { /* DIAL command */ char *s2; if (dialdir && *dialdir) s2 = "Number to dial or entry from dial directory"; else s2 = "Number to dial"; if ((x = cmtxt(s2,"",&s,xxstring)) < 0) return(x); if (s == NULL || (int)strlen(s) == 0) { printf("?You must specify a number to dial\n"); return(-9); } if (dialfd) { /* Have dialing directory? */ if (s2 = ludial(s,dialfd)) /* Look up in dialing directory */ s = s2; /* Make substitution if found */ } if (dialnum) free(dialnum); /* Make copy for REDIAL */ dialnum = malloc((int)strlen(s) + 1); if (dialnum) strcpy(dialnum,s); } else return(-2);#ifdef VMS conres(); /* So Ctrl-C/Y will work */#endif /* VMS */ success = ckdial(s); /* Try to dial */#ifdef OS2 ttres();#endif /* OS2 */#ifdef VMS concb((char)escape); /* Back to command parsing mode */#endif /* VMS */ return(success);}#endif /* NODIAL */#ifndef MACint /* Do the DIRECTORY command */dodir() { char *dc;#ifdef VMS if ((x = cmtxt("Directory/file specification","",&s,xxstring)) < 0) return(x); /* now do this the same as a shell command - helps with LAT */ conres(); /* make console normal */ lp = line; if (!(dc = getenv("CK_DIR"))) dc = DIRCMD; sprintf(lp,"%s %s",dc,s); debug(F110,"Directory string: ", line, 0); xsystem(lp); return(success = 0);#else#ifdef AMIGA if ((x = cmtxt("Directory/file specification","",&s,xxstring)) < 0) return(x);#else#ifdef datageneral if ((x = cmtxt("Directory/file specification","+",&s,xxstring)) < 0) return(x);#else /* General Case */ if ((x = cmdir("Directory/file specification","",&s,xxstring)) < 0) if (x != -3) return(x); strcpy(tmpbuf,s); if ((y = cmcfm()) < 0) return(y); s = tmpbuf;#endif /* datageneral */#endif /* AMIGA */ /* General case again */ lp = line; if (!(dc = getenv("CK_DIR"))) dc = DIRCMD; sprintf(lp,"%s %s",dc,s); xsystem(line); return(success = 1); /* who cares... */#endif /* VMS */}#endif /* MAC */#ifndef NOFRILLS/* Do the ENABLE and DISABLE commands */intdoenable(cx,x) int cx, x; { y = ((cx == XXENA) ? 1 : 0); switch (x) { case EN_ALL: en_cwd = en_del = en_dir = en_fin = en_get = y; en_sen = en_set = en_spa = en_typ = en_who = y;#ifndef datageneral en_bye = y;#endif /* datageneral */#ifndef NOPUSH en_hos = y;#endif /* NOPUSH */ break; case EN_BYE:#ifndef datageneral/* In Data General AOS/VS Kermit can't log out its superior process.*/ en_bye = y;#endif /* datageneral */ break; case EN_CWD: en_cwd = y; break; case EN_DEL: en_del = y; break; case EN_DIR: en_dir = y; break; case EN_FIN: en_fin = y; break; case EN_GET: en_get = y; break;#ifndef NOPUSH case EN_HOS: en_hos = y; break;#endif /* NOPUSH */ case EN_SEN: en_sen = y; break; case EN_SET: en_set = y; break; case EN_SPA: en_spa = y; break; case EN_TYP: en_typ = y; break; case EN_WHO: en_who = y; break; default: return(-2); } return(1);}#endif /* NOFRILLS */#ifndef NOFRILLSintdodel() { /* DELETE */ long zl; if ((x = cmifi("File(s) to delete","",&s,&y,xxstring)) < 0) { if (x == -3) { printf("?A file specification is required\n"); return(-9); } else return(x); }#ifdef MAC strcpy(line,s);#else strncpy(tmpbuf,s,50); /* Make a safe copy of the name. */ debug(F110,"xxdel tmpbuf",s,0); sprintf(line,"%s %s",DELCMD,s); /* Construct the system command. */#endif /* MAC */ debug(F110,"xxdel line",line,0); if ((y = cmcfm()) < 0) return(y); /* Confirm the user's command. */#ifdef VMS conres();#endif /* VMS */#ifdef MAC s = line; success = (zdelet(line) == 0);#else s = tmpbuf; xsystem(line); /* Let the system do it. */ zl = zchki(tmpbuf); success = (zl == -1L);#endif /* MAC */ if (msgflg) printf("%s - %sdeleted\n",s, success ? "" : "not "); return(success);}#endif /* NOFRILLS */#ifndef NOSPL /* The ELSE command */intdoelse() { if (!ifcmd[cmdlvl]) { printf("?ELSE doesn't follow IF\n"); return(-2); }#ifdef COMMENT/* Wrong. This prevents IF..ELSE IF...ELSE IF...ELSE IF...ELSE... from working.*/ ifcmd[cmdlvl] = 0;#endif /* COMMENT */ if (!iftest[cmdlvl]) { /* If IF was false do ELSE part */ if (maclvl > -1) { /* In macro, */ pushcmd(); /* save rest of command. */ } else if (tlevel > -1) { /* In take file, */ pushcmd(); /* save rest of command. */ } else { /* If interactive, */ cmini(ckxech); /* just start a new command */ printf("\n"); /* (like in MS-DOS Kermit) */ if (pflag) prompt(xxstring); } } else { /* Condition is false */ if ((y = cmtxt("command to be ignored","",&s,NULL)) < 0) return(y); /* Gobble up rest of line */ } return(0);}#endif /* NOSPL */#ifndef NOSPLintdofor() { /* The FOR command. */ int fx, fy, fz; /* loop variables */ char *ap; /* macro argument pointer */ if ((y = cmfld("Variable name","",&s,NULL)) < 0) { /* Get variable name */ if (y == -3) { printf("?Variable name required\n"); return(-9); } else return(y); } if ((y = parsevar(s,&x,&z)) < 0) /* Check it. */ return(y); lp = line; /* Build a copy of the command */ strcpy(lp,"_forx "); lp += (int)strlen(line); /* "_for" macro. */ ap = lp; /* Save pointer to macro args. */ if (*s == CMDQ) s++; /* Skip past backslash if any. */ while (*lp++ = *s++) ; /* copy it */ lp--; *lp++ = SP; /* add a space */ if ((y = cmnum("initial value","",10,&fx,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } s = atmbuf; /* Copy the atom buffer */ if ((int)strlen(s) < 1) goto badfor; while (*lp++ = *s++) ; /* (what they actually typed) */ lp--; *lp++ = SP; if ((y = cmnum("final value","",10,&fy,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } s = atmbuf; /* Same deal */ if ((int)strlen(s) < 1) goto badfor; while (*lp++ = *s++) ; lp--; *lp++ = SP; if ((y = cmnum("increment","1",10,&fz,xxstring)) < 0) { if (y == -3) return(-2); else return(y); } sprintf(tmpbuf,"%d ",fz); s = atmbuf; /* same deal */ if ((int)strlen(s) < 1) goto badfor; while (*lp++ = *s++) ; lp--; *lp++ = SP; /* Insert the appropriate comparison operator */ if (fz < 0) *lp++ = '<'; else *lp++ = '>'; *lp++ = SP; if ((y = cmtxt("Command to execute","",&s,NULL)) < 0) return(y); if ((int)strlen(s) < 1) return(-2); if (litcmd(&s,&lp) < 0) { printf("?Unbalanced brackets\n"); return(0); } if (fz == 0) { printf("?Zero increment not allowed\n"); return(0); } x = mlook(mactab,"_forx",nmac); /* Look up FOR macro definition */ if (x < 0) { /* Not there? */ addmmac("_forx",for_def); /* Put it back. */ if ((x = mlook(mactab,"_forx",nmac)) < 0) { /* Look it up again. */ printf("?FOR macro definition gone!\n"); /* Shouldn't happen. */ return(success = 0); } } debug(F110,"FOR command",line,0); return(success = dodo(x,ap)); /* Execute the FOR macro. */badfor: printf("?Incomplete FOR command\n"); return(-2);}#endif /* NOSPL */#ifndef NOFRILLS/* Do the BUG command */intdobug() { printf("\n%s,%s\n Numeric: %ld",versio,ckxsys,vernum); if (verwho) printf("-%d",verwho); printf("\nTo report C-Kermit bugs, send e-mail to:\n"); printf(" Info-Kermit@columbia.edu (Internet)\n"); printf(" KERMIT@CUVMA (EARN/BITNET)\n"); printf(" ...!uunet!columbia.edu!info-kermit (Usenet)\n"); printf("Or write to:\n Kermit Development\n Columbia University\n"); printf(" Center for Computing Activities\n 612 W 115 Street\n"); printf(" New York, NY 10025 USA\nOr call:\n (212) 854-5126 (USA)\n\n");#ifndef NOSHOW#ifndef NOFRILLS printf("Before reporting problems, please use the SHOW VERSION and SHOW FEATURES\n"); printf("commands to get detailed program version and configuration information.\n\n");#endif /* NOFRILLS */#endif /* NOSHOW */ return(1);}#endif /* NOFRILLS */#ifndef NOSPLintdopaus(cx) int cx; { /* Both should take not only secs but also hh:mm:ss as argument. */ if (cx == XXWAI) y = cmnum("seconds to wait","1",10,&x,xxstring); else if (cx == XXPAU) y = cmnum("seconds to pause","1",10,&x,xxstring); else y = cmnum("milliseconds to sleep","100",10,&x,xxstring); if (y < 0) return(y); if (x < 0) x = 0; switch (cx) { case XXPAU: /* PAUSE */ case XXMSL: /* MSLEEP */ if ((y = cmcfm()) < 0) return(y); break; case XXWAI: /* WAIT */ z = 0; /* Modem signal mask */ while (1) { /* Read zero or more signal names */ y = cmkey(mstab,nms,"modem signal","",xxstring); if (y == -3) break; /* -3 means they typed CR */ if (y < 0) return(y); /* Other negatives are errors */ z |= y; /* OR the bit into the signal mask */ } break; default: /* Shouldn't happen */ return(-2); }/* Command is entered, now do it. */ if (cx == XXMSL) { /* Millisecond sleep */ msleep(x); return(success = 1); } while (x--) { /* Sleep loop */ int mdmsig; if (y = conchk()) { /* Did they type something? */ while (y--) coninc(0); /* Yes, gobble it up */ break; /* And quit PAUSing or WAITing */ } if (cx == XXWAI && z != 0) { mdmsig = ttgmdm(); if (mdmsig < 0) return(success = 0); if ((mdmsig & z) == z) return(success = 1); } sleep(1); /* No interrupt, sleep one second */ } if (cx == XXWAI) success = 0; else success = (x == -1); /* Set SUCCESS/FAILURE for PAUSE. */ return(0);}#endif /* NOSPL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -