char *mend_nosemi(char *s1, char *s2, int n) { int i, vbar = 0; for (i = 0; i < n;) { while (*s2 == '|') { vbar = !vbar; s2++; } if (vbar) { if (strchr(special_chars, (int) * s2)) s1[i++] = setparity(*s2++); else s1[i++] = *s2++; } else { while ((*s2 == '~' && *(s2 + 1) == '\n')) { while (*s2 == '~' && *(s2 + 1) == '\n') s2 += 2; } if (*s2 != '|') s1[i++] = *s2++; } } s1[n] = '\0'; return (s1); }
/*ARGSUSED*/ void variable(int c) { char buf[256]; if (prompt("[set] ", buf, sizeof(buf))) return; vlex(buf); if (vtable[BEAUTIFY].v_access&CHANGED) { vtable[BEAUTIFY].v_access &= ~CHANGED; kill(tipout_pid, SIGSYS); } if (vtable[SCRIPT].v_access&CHANGED) { vtable[SCRIPT].v_access &= ~CHANGED; setscript(); /* * So that "set record=blah script" doesn't * cause two transactions to occur. */ if (vtable[RECORD].v_access&CHANGED) vtable[RECORD].v_access &= ~CHANGED; } if (vtable[RECORD].v_access&CHANGED) { vtable[RECORD].v_access &= ~CHANGED; if (boolean(value(SCRIPT))) setscript(); } if (vtable[TAND].v_access&CHANGED) { vtable[TAND].v_access &= ~CHANGED; if (boolean(value(TAND))) tandem("on"); else tandem("off"); } if (vtable[LECHO].v_access&CHANGED) { vtable[LECHO].v_access &= ~CHANGED; HD = boolean(value(LECHO)); } if (vtable[PARITY].v_access&CHANGED) { vtable[PARITY].v_access &= ~CHANGED; setparity(NOSTR); } if (vtable[HARDWAREFLOW].v_access&CHANGED) { vtable[HARDWAREFLOW].v_access &= ~CHANGED; if (boolean(value(HARDWAREFLOW))) hardwareflow("on"); else hardwareflow("off"); } if (vtable[LINEDISC].v_access&CHANGED) { vtable[LINEDISC].v_access &= ~CHANGED; linedisc(NOSTR); } }
/* ARGSUSED */ void variable(int cc) { char buf[256]; if (prompt("[set] ", buf, sizeof (buf))) return; vlex(buf); if (vtable[BEAUTIFY].v_access&CHANGED) { vtable[BEAUTIFY].v_access &= ~CHANGED; (void) kill(pid, SIGSYS); } if (vtable[SCRIPT].v_access&CHANGED) { vtable[SCRIPT].v_access &= ~CHANGED; setscript(); /* * So that "set record=blah script" doesn't * cause two transactions to occur. */ if (vtable[RECORD].v_access&CHANGED) vtable[RECORD].v_access &= ~CHANGED; } if (vtable[RECORD].v_access&CHANGED) { vtable[RECORD].v_access &= ~CHANGED; if (boolean(value(SCRIPT))) setscript(); } if (vtable[TAND].v_access&CHANGED) { vtable[TAND].v_access &= ~CHANGED; if (boolean(value(TAND))) tandem("on"); else tandem("off"); } if (vtable[LECHO].v_access&CHANGED) { vtable[LECHO].v_access &= ~CHANGED; boolean(value(HALFDUPLEX)) = boolean(value(LECHO)); } if (vtable[PARITY].v_access&CHANGED) { vtable[PARITY].v_access &= ~CHANGED; setparity(NULL); } if (vtable[BAUDRATE].v_access&CHANGED) { vtable[BAUDRATE].v_access &= ~CHANGED; ttysetup(speed(number(value(BAUDRATE)))); } if (vtable[HARDWAREFLOW].v_access & CHANGED) { vtable[HARDWAREFLOW].v_access &= ~CHANGED; if (boolean(value(HARDWAREFLOW))) hardwareflow("on"); else hardwareflow("off"); } }
void variable(void) { char buf[256]; if (prompt("[set] ", buf, sizeof(buf))) return; vlex(buf); if (vtable[BEAUTIFY].v_access&CHANGED) { vtable[BEAUTIFY].v_access &= ~CHANGED; kill(pid, SIGSYS); } if (vtable[SCRIPT].v_access&CHANGED) { vtable[SCRIPT].v_access &= ~CHANGED; setscript(); /* * So that "set record=blah script" doesn't * cause two transactions to occur. */ if (vtable[RECORD].v_access&CHANGED) vtable[RECORD].v_access &= ~CHANGED; } if (vtable[RECORD].v_access&CHANGED) { vtable[RECORD].v_access &= ~CHANGED; if (boolean(value(SCRIPT))) setscript(); } if (vtable[TAND].v_access&CHANGED) { vtable[TAND].v_access &= ~CHANGED; if (boolean(value(TAND))) tandem("on"); else tandem("off"); } if (vtable[LECHO].v_access&CHANGED) { vtable[LECHO].v_access &= ~CHANGED; HD = boolean(value(LECHO)); } if (vtable[PARITY].v_access&CHANGED) { vtable[PARITY].v_access &= ~CHANGED; setparity(value(PARITY)); } }
/* * Botch the interface to look like cu's */ void cumain(int argc, char *argv[]) { int i; static char sbuf[12]; if (argc < 2) { printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); exit(8); } CU = DV = NULL; BR = DEFBR; for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') PN = argv[1]; else switch (argv[1][1]) { case 't': HW = 1, DU = -1; --argc; continue; case 'a': CU = argv[2]; ++argv; --argc; break; case 's': if (argc < 3 || speed(atoi(argv[2])) == 0) { fprintf(stderr, "cu: unsupported speed %s\n", argv[2]); exit(3); } BR = atoi(argv[2]); ++argv; --argc; break; case 'l': DV = argv[2]; ++argv; --argc; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (CU) CU[strlen(CU)-1] = argv[1][1]; if (DV) DV[strlen(DV)-1] = argv[1][1]; break; default: printf("Bad flag %s", argv[1]); break; } } signal(SIGINT, cleanup); signal(SIGQUIT, cleanup); signal(SIGHUP, cleanup); signal(SIGTERM, cleanup); /* * The "cu" host name is used to define the * attributes of the generic dialer. */ (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); if ((i = hunt(sbuf)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); user_uid(); vinit(); setparity("none"); boolean(value(VERBOSE)) = 0; if (HW) ttysetup(speed(BR)); if (connect()) { printf("Connect failed\n"); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW) ttysetup(speed(BR)); exit(0); }
int main(int argc, char *argv[]) { char *System = NULL; int c, i; char *p; const char *q; char sbuf[12]; int cmdlineBR; int fcarg; setprogname(argv[0]); gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (strcmp(getprogname(), "cu") == 0) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) tipusage(); if (!isatty(0)) errx(EXIT_FAILURE, "must be interactive"); cmdlineBR = 0; while((c = getopt(argc, argv, "v0123456789")) != -1) { switch(c) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': cmdlineBR = cmdlineBR * 10 + (c - '0'); BR = cmdlineBR; break; default: warnx("%s, unknown option", argv[1]); break; } } argc -= optind; argv += optind; if (argc != 1) tipusage(); else System = argv[0]; if (System == NULL) goto notnumber; if (isalpha((unsigned char)*System)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(System) > sizeof PNbuf - 1) { errx(1, "phone number too long (max = %d bytes)", (int)sizeof(PNbuf) - 1); } (void)strlcpy(PNbuf, System, sizeof(PNbuf)); for (p = System; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR); System = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); if ((i = hunt(System)) == 0) { errx(3, "all ports busy"); } if (i == -1) { errx(3, "link down"); } setbuf(stdout, NULL); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NULL) PH = path_phones; vinit(); /* init variables */ setparity("none"); /* set the parity table */ /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) { if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { errx(3, "bad baud rate %d", (int)number(value(BAUDRATE))); } } if ((q = tip_connect()) != NULL) { errx(1, "\07%s\n[EOT]", q); } if (!HW) { if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { errx(3, "bad baud rate %d", (int)number(value(BAUDRATE))); } } cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ /* * Direct connections with no carrier require using O_NONBLOCK on * open, but we don't want to keep O_NONBLOCK after open because it * will cause busy waits. */ if (DC && ((fcarg = fcntl(FD, F_GETFL, 0)) < 0 || fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) { err(1, "can't clear O_NONBLOCK"); } (void)tcgetattr(0, &defterm); term = defterm; term.c_lflag &= ~(ICANON|IEXTEN|ECHO); term.c_iflag &= ~(INPCK|ICRNL); term.c_oflag &= ~OPOST; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; defchars = term; term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = term.c_cc[VLNEXT] = _POSIX_VDISABLE; raw(); (void)pipe(attndes); (void)pipe(fildes); (void)pipe(repdes); (void)signal(SIGALRM, alrmtimeout); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ (void)printf("%s", cumode ? "Connected\r\n" : "\07connected\r\n"); switch (pid = fork()) { default: tipin(); break; case 0: tipout(); break; case -1: err(1, "can't fork"); } /*NOTREACHED*/ exit(0); /* XXX: pacify gcc */ }
int main(int argc, char *argv[]) { char *system = NOSTR; int i; char *p; char sbuf[15]; gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (equal(sname(argv[0]), "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) { (void) fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); return (1); } if (!isatty(0)) { (void) fprintf(stderr, "tip: must be interactive\n"); return (1); } for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') system = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: (void) fprintf(stderr, "tip: %s, unknown option\n", argv[1]); break; } } (void) setlocale(LC_CTYPE, ""); if (system == NOSTR) goto notnumber; for (p = system; *p; p++) if (isalpha(*p)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof (PNbuf) - 1) { (void) fprintf(stderr, "tip: phone number too long (max = %d bytes)\n", sizeof (PNbuf) - 1); return (1); } (void) strncpy(PNbuf, system, sizeof (PNbuf) - 1); for (p = system; *p; p++) *p = '\0'; PN = PNbuf; (void) snprintf(sbuf, sizeof (sbuf), "tip%d", BR); system = sbuf; notnumber: (void) signal(SIGINT, (sig_handler_t)cleanup); (void) signal(SIGQUIT, (sig_handler_t)cleanup); (void) signal(SIGHUP, (sig_handler_t)cleanup); (void) signal(SIGTERM, (sig_handler_t)cleanup); if ((i = hunt(system)) == 0) { (void) printf("all ports busy\n"); return (3); } if (i == -1) { (void) printf("link down\n"); delock(uucplock); return (3); } setbuf(stdout, NULL); loginit(); /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. The saved-setuid uid and gid * allows us to get the original setuid permissions back * for removing the uucp lock. */ userperm(); /* * Kludge, there's no easy way to get the initialization * in the right order, so force it here. * Do the open here, before we change back to real uid. * We will check whether the open succeeded later, when * (and if) we actually go to use the file. */ if ((PH = getenv("PHONES")) == NOSTR) { myperm(); PH = "/etc/phones"; } phfd = fopen(PH, "r"); userperm(); vinit(); /* init variables */ setparity("none"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == NULL) { (void) printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); myperm(); delock(uucplock); return (3); } /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) ttysetup(i); if (p = connect()) { (void) printf("\07%s\n[EOT]\n", p); myperm(); delock(uucplock); return (1); } /* * Always setup the tty again here in case hardware flow * control was selected, which can only be set after the * connection is made, or in case this is not a hardwired * modem (rare these days) that likewise can only be setup * after the connection is made. */ ttysetup(i); cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ (void) ioctl(0, TCGETS, (char *)&defarg); arg = defarg; /* turn off input processing */ arg.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN); arg.c_cc[VMIN] = 1; arg.c_cc[VTIME] = 0; arg.c_iflag &= ~(INPCK|IXON|IXOFF|ICRNL); arg.c_oflag = 0; /* turn off all output processing */ /* handle tandem mode in case was set in remote file */ if (boolean(value(TAND))) tandem("on"); else tandem("off"); raw(); (void) pipe(fildes); (void) pipe(repdes); (void) signal(SIGALRM, (sig_handler_t)timeout); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ if (CM != NOSTR) { (void) sleep(2); /* let line settle */ parwrite(FD, (unsigned char *)CM, strlen(CM)); } (void) printf(cumode ? "Connected\r\n" : "\07connected\r\n"); (void) signal(SIGCHLD, (sig_handler_t)deadkid); if (pid = fork()) tipin(); else tipout(); /*NOTREACHED*/ }
int main(int argc, char *argv[]) { char *sys = NOSTR, sbuf[12], *p; int i; /* XXX preserve previous braindamaged behavior */ setboolean(value(DC), TRUE); gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); if (equal(__progname, "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } if (argc > 4) { fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); exit(1); } if (!isatty(0)) { fprintf(stderr, "%s: must be interactive\n", __progname); exit(1); } for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') sys = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case 'n': noesc++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: fprintf(stderr, "%s: %s, unknown option\n", __progname, argv[1]); break; } } if (sys == NOSTR) goto notnumber; if (isalpha(*sys)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(sys) > sizeof PNbuf - 1) { fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", __progname, (int)sizeof(PNbuf) - 1); exit(1); } strlcpy(PNbuf, sys, sizeof PNbuf - 1); for (p = sys; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); sys = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); (void)signal(SIGCHLD, SIG_DFL); if ((i = hunt(sys)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. Swap real and effective uid's * so we can get the original permissions back * for removing the uucp lock. */ user_uid(); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NOSTR) PH = _PATH_PHONES; vinit(); /* init variables */ setparity("none"); /* set the parity table */ /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW && ttysetup(number(value(BAUDRATE)))) { fprintf(stderr, "%s: bad baud rate %ld\n", __progname, number(value(BAUDRATE))); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } if ((p = con())) { printf("\07%s\n[EOT]\n", p); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW && ttysetup(number(value(BAUDRATE)))) { fprintf(stderr, "%s: bad baud rate %ld\n", __progname, number(value(BAUDRATE))); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ i = fcntl(FD, F_GETFL); if (i == -1) { perror("fcntl"); cleanup(0); } i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); if (i == -1) { perror("fcntl"); cleanup(0); } tcgetattr(0, &defterm); gotdefterm = 1; term = defterm; term.c_lflag &= ~(ICANON|IEXTEN|ECHO); term.c_iflag &= ~(INPCK|ICRNL); term.c_oflag &= ~OPOST; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; defchars = term; term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = term.c_cc[VLNEXT] = _POSIX_VDISABLE; raw(); pipe(fildes); pipe(repdes); (void)signal(SIGALRM, timeout); if (value(LINEDISC) != TTYDISC) { int ld = (int)(intptr_t)value(LINEDISC); ioctl(FD, TIOCSETD, &ld); } /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ printf(cumode ? "Connected\r\n" : "\07connected\r\n"); tipin_pid = getpid(); if ((tipout_pid = fork())) tipin(); else tipout(); /*NOTREACHED*/ exit(0); }
/* * Botch the interface to look like cu's */ void cumain(int argc, char *argv[]) { int ch, i, parity; long l; char *cp; static char sbuf[12]; if (argc < 2) cuusage(); CU = DV = NOSTR; BR = DEFBR; parity = 0; /* none */ /* * We want to accept -# as a speed. It's easiest to look through * the arguments, replace -# with -s#, and let getopt() handle it. */ for (i = 1; i < argc; i++) { if (argv[i][0] == '-' && argv[i][1] >= '0' && argv[i][1] <= '9') { asprintf(&cp, "-s%s", argv[i] + 1); if (cp == NULL) { fprintf(stderr, "%s: cannot convert -# to -s#\n", __progname); exit(3); } argv[i] = cp; } } while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) { switch (ch) { case 'a': CU = optarg; break; case 'l': if (DV != NULL) { fprintf(stderr, "%s: cannot specificy multiple -l options\n", __progname); exit(3); } if (strchr(optarg, '/')) DV = optarg; else asprintf(&DV, "/dev/%s", optarg); break; case 's': l = strtol(optarg, &cp, 10); if (*cp != '\0' || l < 0 || l >= INT_MAX) { fprintf(stderr, "%s: unsupported speed %s\n", __progname, optarg); exit(3); } BR = (int)l; break; case 'h': setboolean(value(LECHO), TRUE); HD = TRUE; break; case 't': HW = 1, DU = -1; break; case 'o': if (parity != 0) parity = 0; /* -e -o */ else parity = 1; /* odd */ break; case 'e': if (parity != 0) parity = 0; /* -o -e */ else parity = -1; /* even */ break; default: cuusage(); break; } } argc -= optind; argv += optind; switch (argc) { case 1: PN = argv[0]; break; case 0: break; default: cuusage(); break; } signal(SIGINT, cleanup); signal(SIGQUIT, cleanup); signal(SIGHUP, cleanup); signal(SIGTERM, cleanup); signal(SIGCHLD, SIG_DFL); /* * The "cu" host name is used to define the * attributes of the generic dialer. */ (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); if ((i = hunt(sbuf)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); user_uid(); vinit(); switch (parity) { case -1: setparity("even"); break; case 1: setparity("odd"); break; default: setparity("none"); break; } setboolean(value(VERBOSE), FALSE); if (HW && ttysetup(BR)) { fprintf(stderr, "%s: unsupported speed %ld\n", __progname, BR); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } if (con()) { printf("Connect failed\n"); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW && ttysetup(BR)) { fprintf(stderr, "%s: unsupported speed %ld\n", __progname, BR); daemon_uid(); (void)uu_unlock(uucplock); exit(3); } }
NODE *reader(FILE *strm, char *prompt) { int c = 0, dribbling, vbar = 0, paren = 0; int bracket = 0, brace = 0, p_pos, contin=1, insemi=0, raw=0; char *phys_line, *lookfor = ender; NODETYPES this_type = STRING; NODE *ret; char *old_stringptr = print_stringptr; int old_stringlen = print_stringlen; fix_turtle_shownness(); //readingInstruction = !strcmp(prompt, "? "); readingInstruction = (strm == stdin); #ifdef HAVE_WX wx_refresh(); if(readingInstruction) { wx_enable_scrolling(); } #endif print_stringptr = ender; print_stringlen = 99; ndprintf(NULL, "\n%p\n", theName(Name_end)); *print_stringptr = '\0'; print_stringptr = old_stringptr; print_stringlen = old_stringlen; if (!strcmp(prompt, "RW")) { /* called by readword */ prompt = ""; contin = 0; } if (!strcmp(prompt, "RAW")) { /* called by readrawline */ prompt = ""; contin = 0; raw = 1; } charmode_off(); #ifdef WIN32 dribbling = 0; #else dribbling = (dribblestream != NULL && strm == stdin); #endif if (p_line == 0) { p_line = malloc(MAX_PHYS_LINE); if (p_line == NULL) { err_logo(OUT_OF_MEM, NIL); return UNBOUND; } p_end = &p_line[MAX_PHYS_LINE-1]; } phys_line = p_line; if (strm == stdin && *prompt) { if (interactive) { rd_print_prompt(prompt); #ifdef WIN32 win32_update_text(); #endif } } if (strm == stdin) { input_blocking++; erract_errtype = FATAL; } #ifndef TIOCSTI if (!setjmp(iblk_buf)) { #endif c = rd_getc(strm); /* if ((c=='\b' || c=='\127') && strm==stdin && interactive) { silent_load(LogoLogo, logolib); c = rd_getc(strm); } */ /* 6.0 */ #ifdef mac if (c == '\r') c = '\n'; /* seen in raw mode by keyp, never read */ #endif while (c != EOF && (vbar || paren || bracket || brace || c != '\n') && NOT_THROWING) { if (dribbling) rd_putc(c, dribblestream); if (!raw && c == '\\' && (c = rd_getc(strm)) != EOF) { if (dribbling) rd_putc(c, dribblestream); c = setparity(c); this_type = BACKSLASH_STRING; if (c == setparity('\n') && strm == stdin) { if (interactive) zrd_print_prompt("\\ "); } } if (c != EOF) into_line(c); if (raw) { c = rd_getc(strm); continue; } if (*prompt && (c&0137) == ((*lookfor)&0137)) { lookfor++; if (*lookfor == 0) { if (deepend_proc_name != NIL) err_logo(DEEPEND, deepend_proc_name); else err_logo(DEEPEND_NONAME, NIL); break; } } else lookfor = ender; if (c == '|' && !insemi) { vbar = !vbar; this_type = VBAR_STRING; } else if (contin && !vbar && !insemi) { if (c == '(') paren++; else if (paren && c == ')') paren--; else if (c == '[') bracket++; else if (bracket && c == ']') bracket--; else if (c == '{') brace++; else if (brace && c == '}') brace--; else if (c == ';') insemi++; } if (this_type == STRING && strchr(special_chars, c)) this_type = VBAR_STRING; if (/* (vbar || paren ...) && */ c == '\n') { insemi = 0; if (strm == stdin) { if (interactive) zrd_print_prompt(vbar ? "| " : "~ "); } } while (!vbar && c == '~' && (c = rd_getc(strm)) != EOF) { int gotspc = 0; while (c == ' ' || c == '\t') { gotspc = 1; c = rd_getc(strm); } if (dribbling) rd_putc(c, dribblestream); if (c != '\n' && gotspc) into_line(' '); into_line(c); if (c == '\n') { insemi = 0; if (interactive && strm == stdin) zrd_print_prompt("~ "); } else if (c == '(') paren++; else if (paren && c == ')') paren--; else if (c == '[') bracket++; else if (bracket && c == ']') bracket--; else if (c == '{') brace++; else if (brace && c == '}') brace--; else if (c == ';') insemi++; } if (c != EOF) c = rd_getc(strm); } #ifndef TIOCSTI } #endif *phys_line = '\0'; input_blocking = 0; #if defined(__RZTC__) && !defined(WIN32) /* sowings */ fix_cursor(); if (interactive && strm == stdin) newline_bugfix(); #endif if (dribbling) rd_putc('\n', dribblestream); if (c == EOF && strm == stdin) { if (interactive) clearerr(stdin); rd_print_prompt("\n"); } if (phys_line == p_line) return(Null_Word); /* so emptyp works */ ret = make_strnode(p_line, (struct string_block *)NULL, (int)strlen(p_line), this_type, strnzcpy); #if 0 if (strm == stdin && !strcmp(prompt, "? ")){ char *histline = malloc(1+strlen(p_line)); strcpy(histline, p_line); *hist_inptr++ = histline; if (hist_inptr >= &cmdHistory[HIST_MAX]) { hist_inptr = cmdHistory; } if (*hist_inptr) { free(*hist_inptr); *hist_inptr = 0; } hist_outptr = hist_inptr; } #endif //added (evan) readingInstruction = 0; return(ret); }
int main(int argc, char *argv[]) { char *system = NULL; int i; char *p; char sbuf[12]; gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); #if INCLUDE_CU_INTERFACE if (equal(sname(argv[0]), "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } #endif /* INCLUDE_CU_INTERFACE */ if (argc > 4) usage(); if (!isatty(0)) errx(1, "must be interactive"); for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') system = argv[1]; else switch (argv[1][1]) { case 'v': vflag++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: warnx("%s, unknown option", argv[1]); break; } } if (system == NULL) goto notnumber; if (isalpha(*system)) goto notnumber; /* * System name is really a phone number... * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof(PNbuf) - 1) errx(1, "phone number too long (max = %zd bytes)", sizeof PNbuf - 1); strncpy(PNbuf, system, sizeof(PNbuf) - 1); for (p = system; *p; p++) *p = '\0'; PN = PNbuf; (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); system = sbuf; notnumber: (void)signal(SIGINT, cleanup); (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); (void)signal(SIGUSR1, tipdone); if ((i = hunt(system)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { printf("link down\n"); (void)uu_unlock(uucplock); exit(3); } setbuf(stdout, NULL); loginit(); /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NULL) PH = _PATH_PHONES; vinit(); /* init variables */ setparity("even"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == 0) { printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); (void)uu_unlock(uucplock); exit(3); } /* * Now that we have the logfile and the ACU open * return to the real uid and gid. These things will * be closed on exit. Swap real and effective uid's * so we can get the original permissions back * for removing the uucp lock. */ user_uid(); /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) ttysetup(i); if ((p = connect())) { printf("\07%s\n[EOT]\n", p); daemon_uid(); (void)uu_unlock(uucplock); exit(1); } if (!HW) ttysetup(i); cucommon: /* * From here down the code is shared with * the "cu" version of tip. */ #if HAVE_TERMIOS tcgetattr (0, &otermios); ctermios = otermios; #ifndef _POSIX_SOURCE ctermios.c_iflag = (IMAXBEL|IXANY|ISTRIP|IXON|BRKINT); ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOCTL|ECHOE|ECHOKE); #else ctermios.c_iflag = (ISTRIP|IXON|BRKINT); ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOE); #endif ctermios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); ctermios.c_cc[VINTR] = ctermios.c_cc[VQUIT] = -1; ctermios.c_cc[VSUSP] = ctermios.c_cc[VDSUSP] = ctermios.c_cc[VDISCARD] = ctermios.c_cc[VLNEXT] = -1; #else /* HAVE_TERMIOS */ ioctl(0, TIOCGETP, (char *)&defarg); ioctl(0, TIOCGETC, (char *)&defchars); ioctl(0, TIOCGLTC, (char *)&deflchars); ioctl(0, TIOCGETD, (char *)&odisc); arg = defarg; arg.sg_flags = ANYP | CBREAK; tchars = defchars; tchars.t_intrc = tchars.t_quitc = -1; ltchars = deflchars; ltchars.t_suspc = ltchars.t_dsuspc = ltchars.t_flushc = ltchars.t_lnextc = -1; #endif /* HAVE_TERMIOS */ raw(); pipe(fildes); pipe(repdes); (void)signal(SIGALRM, timeoutfunc); /* * Everything's set up now: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) * so, fork one process for local side and one for remote. */ printf(cumode ? "Connected\r\n" : "\07connected\r\n"); if (LI != NULL && tiplink (LI, 0) != 0) { tipabort ("login failed"); } if ((pid = fork())) tipin(); else tipout(); /*NOTREACHED*/ }