📄 xcmain.c
字号:
{ char tmp[SM_BUFF]; if (statflag) { fprintf(tfp,statfmt,"zmcmd", "Automatic rz command", rzcmd); return; } getword(); if (word[0] == '\0') { show(1,"Set ZMCMD must have a command"); eofflag++; return; } strcpy(tmp,word); getword(); while(word[0] != '\0') { strcat(tmp," "); strcat(tmp,word); getword(); } strcat(tmp,"\0"); strcpy(rzcmd, tmp); if (!scriptflag){ sprintf(Msg,"rz command set to '%s'", rzcmd), S; }} #if HAVE_RS232FLOW static void SET_rtscts() { if (statflag) { fprintf(tfp, statfmt, "rtscts", "Hardware Flow Control", rtscts?"ON":"OFF"); return; } set_onoff(&rtscts); set_rtscts(); if (!scriptflag) fprintf(tfp, "<<Hardware Flow control is %s>>\r\n",rtscts?"ON":"OFF"); }#endif /* HAVE_RS232FLOW */#endif /* XC_PLUS */static voidSET_xon(){ if (statflag){ fprintf(tfp, statfmt, "xoff", "Terminal Mode XON/XOFF", flowflag ? "ON" : "OFF"); return; } set_onoff(&flowflag); xc_setflow(flowflag); if (!scriptflag) sprintf(Msg,"XON/XOFF Flow control is %s", flowflag ? "ON" : "OFF"), S;}static voidSET_bps(){ if (statflag){ char br[6]; sprintf(br, "%d", mrate( NULL )); fprintf(tfp, statfmt, "bps", "Bits per Second", br); return; } getword(); if (word[0] == '\0') S1("Set BPS (or BAUD) must have a rate"); else if (!mrate(word)) sprintf(Msg,"Unsupported bps rate %s",word), S; eofflag++; if (!scriptflag) sprintf(Msg,"Bits/Second set to %d",mrate( NULL )), S;}#if HALF_DUPLEXstatic voidSET_hdplx(){ if (statflag){ fprintf(tfp, statfmt, "hdplx", "Half-duplex Mode", hdplxflag ? "ON" : "OFF"); return; } set_onoff(&hdplxflag); if (!scriptflag) sprintf(Msg,"Half-duplex Mode is %s", hdplxflag ? "ON" : "OFF"), S;}#endif#if !XC_PLUSstatic short menuflag = FALSE; /* Show mini-menu */static voidSET_menu(){ if (statflag){ fprintf(tfp, statfmt, "menu", "Mini-menu mode", menuflag ? "ON" : "OFF"); return; } set_onoff(&menuflag); if (!scriptflag) sprintf(Msg,"Mini-menu is %s shown", menuflag ? "" : "NOT"), S;}#endifstatic voidSET_autocapt(){ if (statflag){ fprintf(tfp, statfmt, "auto", "Auto Capture", autoflag ? "ON" : "OFF"); return; } set_onoff(&autoflag); if (!scriptflag) sprintf(Msg,"Auto Capture is %s", autoflag ? "ON" : "OFF"), S;}static voidSET_cfile(){ if (statflag){ fprintf(tfp, statfmt, "cfile", "Capture File", captfile); return; } getword(); if (word[0] == '\0'){ S1("Set CFILE must have file name"); eofflag++; return; } strcpy(captfile, word); if (!scriptflag) sprintf(Msg,"Capture file set to '%s'",captfile), S;}static voidSET_pfile(){ if (statflag){ fprintf(tfp, statfmt, "pfile", "Phone Number File", phonefile); return; } getword(); if (word[0] == '\0'){ S1("Set PFILE must have file name"); eofflag++; return; } strcpy(phonefile, word); if (!scriptflag) sprintf(Msg,"Phone number file set to '%s'",phonefile), S;}/* Put and Take a file to/from a UNIX-type "cu" system. Unfortunately, the stty command is one of those commands that always gets changed with different UNIX systems, so you will get (at least) a file full of ^M on the take command for systems later than V7 or work-alikes. Additionally, the Take command takes a bit too much! Fixed a lot of this: JPRadley 89/07/27*/static voidputtake(){ FILE *fp; int Ch; long i = 0; char c = word[1], fname[SM_BUFF], tname[SM_BUFF], wrkbuf[SM_BUFF]; getword(); signal(SIGINT,catch); signal(SIGQUIT,catch); xc_setflow(TRUE); if (word[0] == '\0'){ sprintf(Msg,"Must give a filename with the '%%%c' option",c); S; return; } strcpy(fname, word); getword(); if (word[0] == '\0') strcpy(tname, fname); else strcpy(tname, word); switch (c){ case 'p': if (!(fp = fopen(fname, "r"))) sprintf(Msg,"Can't open '%s'",fname), S; else { fprintf(tfp, "\r\nPutting file '%s' to '%s' on remote UNIX\r\n", fname, tname); sprintf(wrkbuf, "sh -c \"stty -echo;(cat - >%s)||cat >/dev/null;stty echo\"\n", tname); send_string(wrkbuf); /* send command string to remote shell */ while ((Ch = getc(fp)) != EOF){ sendbyte(Ch); if (Ch != '\n') i++; else i *= 3, msecs(i), /* slow down */ i = 1; } fclose(fp); sendbyte(EOT); /* send a ^D to cat */ purge(); /* get rid of whatever was sent back */ sendbyte('\n'); } break; case 't': strcpy(Name, tname); if ((fp=QueryCreate(Resume_Not_Allowed))){ fprintf(tfp, "\r\nTaking file '%s' from remote UNIX to '%s'\r\n", fname, tname); purge(); sprintf(wrkbuf, "sh -c \"stty nl;test -r %s&&cat %s;echo %c;stty -nl\"\n", fname, fname, DLE); /* if 'fname' has a DLE, we'll die */ send_string(wrkbuf); /* send command to remote shell */ while (readbyte(3) != '\n') /* discard up to the \n in wrkbuf */ ; while ((Ch=readbyte(4)) != -1 /* while chars are being sent */ && Ch != DLE) /* and we haven't seen our DLE */ fputc(Ch,fp); fclose(fp); } break; } xc_setflow(flowflag); reterm = TRUE;}voids_exit(int junk){ signal(SIGHUP,SIG_IGN); signal(SIGINT,SIG_IGN); signal(SIGQUIT,SIG_IGN); signal(SIGTERM,SIG_IGN); mode(OLDMODE); unlock_tty(); reset_crt(); exit(EXIT_SUCCESS);}static struct kw setlist[] = { {"auto", SET_autocapt}, {"baud", SET_bps}, {"bps", SET_bps}, {"cfile", SET_cfile}, {"cis", SET_cis}, {"cr", SET_cr},#if HALF_DUPLEX {"hdplx", SET_hdplx},#endif {"dir", SET_dir},#if !XC_PLUS {"menu", SET_menu},#endif {"nl", SET_nl}, {"pfile", SET_pfile}, {"proto", SET_proto}, {"escape", SET_xcape}, {"xcape", SET_xcape}, {"xon", SET_xon}, {"xoff", SET_xon},#if XC_PLUS#if HAVE_RS232FLOW {"rtscts", SET_rtscts},#endif {"del2bs", SET_del}, {"msdos", SET_dos}, {"autozm", SET_azm}, {"zmcmd", SET_zmcmd},#endif { NULL, 0}} ;/* Print the status of the program */static voidstatus(){ struct kw *ptr; char p[30]; void (*fct)() = 0; statflag = TRUE; cls(); cur_off(); sprintf(p,"Modem Port: %s",mport(NULL)); drawline(0, 0, CO);#if XC_PLUS ttgoto(1, 1); sprintf(Msg,"%s%27s",&version[4], p);#else ttgoto(1, 9); sprintf(Msg,"%-29s%29s",&version[4], p);#endif S; drawline(2, 0, CO); ttgoto(3, 0); fprintf(tfp, statfmt, "Keyword", "Description", "Status"); fprintf(tfp, statfmt, "--------", "-------------------------", "-----------"); for (ptr = setlist; ptr->keyword; ptr++) if (ptr->rtn != fct){ fct = ptr->rtn; (*fct)(); }#if XC_PLUS ttgoto(21, 5); S1("[d]ial directory [t]erminal mode [q]uit [s]cript [?]help"); ttgoto(22, 71);#else ttgoto(18, 25); S1("Type \"help\" or ? for help");#endif statflag = FALSE; cur_on();}voids_set(){ struct kw *ptr; getword(); if (word[0] == '\0' && !scriptflag){ status(); return; } else if (word[0] == '\0'){ S1("SET keyword requires an argument"); eofflag++; return; } lc_word(word); for (ptr = setlist; ptr->keyword; ptr++) if (!strcmp(ptr->keyword, word)){ (*ptr->rtn)(); return; } sprintf(Msg,"Invalid SET keyword: %s", word); S; eofflag++;}static voids_help(){ const char * const *ptr = cmdlist; int curline = 0; mode(OLDMODE); cls(); cur_off(); for ( ; *ptr; ptr++) { if (**ptr != '\014') { /* FORM FEED */ if (curline >= LI-2){ S0("PRESS ENTER"); getline(); cls(); curline = 0; } fprintf(tfp, "%s\r\n", *ptr); curline++; } else { S0("PRESS ENTER"); getline(); cls(); curline = 0; } } show_bindings(); S0("PRESS ENTER"); getline(); cls(); status();}static struct kw cmds[] = { {"c", s_cis}, {"cis", s_cis}, {"s", s_script}, {"script", s_script}, {"h", (void (*)())hangup}, {"hangup", (void (*)())hangup}, {"bindings", show_bindings},#if XC_PLUS {"ro", s_xmodem}, {"rx", s_xmodem}, {"rg", s_xmodem}, {"so", s_xmodem}, {"sx", s_xmodem}, {"sg", s_xmodem}, {"ry", s_xmodem}, {"rbg", s_xmodem}, {"ryg", s_xmodem}, {"sy", s_xmodem}, {"sbg", s_xmodem}, {"syg", s_xmodem},#endif {"rb", s_xmodem}, {"rt", s_xmodem}, {"sb", s_xmodem}, {"st", s_xmodem}, {"set", s_set}, {"t", s_term}, {"term", s_term}, {"d", s_dial}, {"dial", s_dial}, {"q", s_exit}, {"quit", s_exit}, {"exit", s_exit}, {"x", s_exit}, {"!", (void(*)()) s_shell}, {"!!", (void(*)()) s_shell}, {"$", (void(*)()) s_shell}, {"%p", puttake}, {"%t", puttake}, {"help", s_help}, {"?", s_help}, {NULL, 0}};intmain(argc, argv)int argc;char **argv;{ char *script = NULL ; extern char *optarg; int c; struct kw *ptr; tfp = stderr; if (isatty(2)) get_ttype(); tcgetattr(STDIN_FILENO, &oldmode); /* get current tty mode */ /* trap for SIGHUP and SIGTERM, make sure LCKfile gets killed */ signal(SIGHUP,s_exit); signal(SIGTERM,s_exit); newmode = oldmode; newmode.c_iflag &= ~(IXON | IXOFF | IXANY); newmode.c_lflag &= ~(ICANON | ISIG | ECHO); newmode.c_oflag = 0; newmode.c_cc[VMIN] = 1; newmode.c_cc[VTIME] = 1; BS = newmode.c_cc[VERASE]; LK = newmode.c_cc[VKILL]; sigmode = newmode; sigmode.c_lflag |= ISIG; oldshell[0] = '\0'; /* set last command to blank */ if (setjmp(erret)) /* set error handler to exit */ exit(0); /* while parsing command line */ /*signal(SIGINT,catch);*/ /* catch break & quit signals/keys */ signal(SIGINT,SIG_IGN); signal(SIGQUIT,catch); #if RLINE rl_initialize();#endif default_bindings();#if XC_PLUS strcpy(rzcmd,"rz -y\0"); /* auto_zm */ while ((c = getopt(argc, argv, "s:l:tpw")) != -1)#else while ((c = getopt(argc, argv, "s:l:t")) != -1)#endif switch (c){ case 'l': /* set modem port name */ mport(optarg); break; case 's': /* Execute SCRIPT file */ script = optarg; break; case 't': /* jump into terminal mode */ reterm = TRUE; break;#if XC_PLUS case 'p': /* use pulse dialing */ tone = FALSE; break; case 'w': /* disable call waiting */ nowait = TRUE ; break; #endif default: /* Bad command .. print help */ usage(); exit(1); } setuid(geteuid()); setgid(getegid()); mopen(); /* opens and configures modem port, or exits */ setuid(getuid()); setgid(getgid()); getcwd(directory, SM_BUFF-2); do_script(STARTUP);#if DEBUG dbglog();#endif if (!script) status(); for (;;){ setjmp(erret); signal(SIGQUIT,s_exit); mode(SIGMODE); if (script) { do_script(script); script = NULL; reterm = TRUE; } if (reterm && isatty(2)){ s_term(); continue; } reset_crt();#if RLINE for(;;) {#endif fputc('\r',tfp); fputc('\n',tfp);#if !XC_PLUS if (menuflag){ fputc('\t',tfp); S1("[d]ial directory [t]erminal mode [q]uit [s]cript [?]help"); }#endif prompt_user(XCPROMPT); getline();#if RLINE if( *lptr == '\0' ) status(); else break ; } /* END for(;;) */#endif getword(); lc_word(word); if (word[0] == '\0') /* If blank line... reprompt */ continue; for (ptr = cmds; ptr->keyword; ptr++) if (!strcmp(word, ptr->keyword)) break; if (ptr->keyword) (*ptr->rtn)(); else sprintf(Msg,"Unrecognized command: %s",word), S; } return SUCCESS ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -