📄 ckuus4.c
字号:
int i, x; x = mdmtyp; if (x < 0) /* In case of network dialing */ x = mdmsav; if (x < 1) return("none"); else for (i = 0; i < nmdm; i++) if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0)) return(mdmtab[i].kwd);#endif /* NODIAL */ return("none");}#ifndef NOXMIT#ifndef NOLOCAL/* T R A N S M I T -- Raw upload *//* Obey current line, duplex, parity, flow, text/binary settings. *//* Returns 0 upon apparent success, 1 on obvious failure. *//*** Things to add: . Make both text and binary mode obey set file bytesize. . Maybe allow user to specify terminators other than CR? . Maybe allow user to specify prompts other than single characters?***//* T R A N S M I T -- Raw upload *//* s is the filename, t is the turnaround (prompt) character *//* Maximum number of characters to buffer. Must be less than LINBUFSIZ*/#define XMBUFS 120#ifdef NETCONN#ifndef IAC#define IAC 255#endif /* IAC */#endif /* NETCONN */int#ifdef CK_ANSICtransmit(char * s, char t)#elsetransmit(s,t) char *s; char t;#endif /* CK_ANSIC *//* transmit */ {#ifdef MAC extern char sstate; int count = 100;#else#ifdef OS2#ifdef NTSIGTYP (* oldsig)(int); /* For saving old interrupt trap. */#else /* NT */SIGTYP (* volatile oldsig)(int); /* For saving old interrupt trap. */#endif /* NT */#else /* OS2 */ SIGTYP (* oldsig)();#endif /* OS2 */#endif /* MAC */ long zz; int z = 1; /* Return code. 0=fail, 1=succeed. */ int x, c, i; /* Workers... */ int myflow; int mybinary;#ifdef COMMENT CHAR csave;#endif /* COMMENT */ char *p;#ifndef NOCSETS int tcs = TC_TRANSP; /* Intermediate (xfer) char set */ int langsv = L_USASCII; /* Save current language */#ifdef CKOUNI _PROTOTYP ( USHORT (*sxo), (CHAR) ) = NULL; /* Translation functions */ _PROTOTYP ( int (*rxo), (USHORT) ) = NULL; _PROTOTYP ( USHORT (*sxi), (CHAR) ) = NULL; _PROTOTYP ( int (*rxi), (USHORT) ) = NULL;#else /* CKOUNI */ _PROTOTYP ( CHAR (*sxo), (CHAR) ) = NULL; /* Translation functions */ _PROTOTYP ( CHAR (*rxo), (CHAR) ) = NULL; _PROTOTYP ( CHAR (*sxi), (CHAR) ) = NULL; _PROTOTYP ( CHAR (*rxi), (CHAR) ) = NULL;#endif /* CKOUNI */#endif /* NOCSETS *//* If a system-specific binary mode is set (MacBinary, Image, Labeled, etc), revert to "normal" binary mode for duration of TRANSMIT command.*/ mybinary = binary; if (binary) binary = XYFT_B; if (zopeni(ZIFILE,s) == 0) { /* Open the file to be transmitted */ printf("?Can't open file %s\n",s); binary = mybinary; return(0); } x = -1; /* Open the communication line */ if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) { /* (no harm if already open) */ printf("Can't open device %s\n",ttname); binary = mybinary; return(0); } zz = x ? speed : -1L; if (binary) { /* Binary file transmission */ myflow = (flow == FLO_XONX) ? FLO_NONE : flow; if (ttvt(zz,myflow) < 0) { /* So no Xon/Xoff! */ printf("Can't condition line\n"); binary = mybinary; return(0); } } else { if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */ printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */ binary = mybinary; return(0); } }#ifndef NOCSETS#ifdef CKOUNI/* Set up character set translations */ if (binary == 0) { if (tcsr == tcsl || binary) { /* Remote and local sets the same? */ sxo = NULL; /* Or file type is not text? */ rxo = NULL; sxi = NULL; rxi = NULL; } else { sxo = xl_u[tcsl]; rxo = xl_tx[tcsr]; rxi = xl_tx[tcsl]; sxi = xl_u[tcsr]; }/* This is to prevent use of zmstuff() and zdstuff() by translation functions. They only work with disk i/o, not with communication i/o. Luckily Russian translation functions don't do any stuffing...*/ langsv = language; language = L_USASCII; }#else /* CKOUNI */ tcs = gettcs(tcsr,tcsl); /* Get intermediate set. *//* Set up character set translations */ if (binary == 0) { if (tcsr == tcsl || binary) { /* Remote and local sets the same? */ sxo = rxo = NULL; /* Or file type is not text? */ sxi = rxi = NULL; } else { /* Otherwise, set up */ sxo = xls[tcs][tcsl]; /* translation function */ rxo = xlr[tcs][tcsr]; /* pointers for output functions */ sxi = xls[tcs][tcsr]; /* and for input functions. */ rxi = xlr[tcs][tcsl]; }/* This is to prevent use of zmstuff() and zdstuff() by translation functions. They only work with disk i/o, not with communication i/o. Luckily Russian translation functions don't do any stuffing...*/ langsv = language; language = L_USASCII; }#endif /* CKOUNI */#endif /* NOCSETS */ i = 0; /* Beginning of buffer. */#ifndef MAC#ifndef AMIGA oldsig = signal(SIGINT, trtrap); /* Save current interrupt trap. */#endif /* AMIGA */#endif /* MAC */ tr_int = 0; /* Have not been interrupted (yet). */ z = 1; /* Return code presumed good. */#ifdef VMS conres();#endif /* VMS */ c = 0; /* Initial condition */ while (c > -1) { /* Loop for all characters in file */#ifdef MAC /* * It is expensive to run the miniparser so don't do it for * every character. */ if (--count < 0) { count = 100; miniparser(1); if (sstate == 'a') { sstate = '\0'; z = 0; break; } }#else /* Not MAC */ if (tr_int) { /* Interrupted? */ printf("^C...\n"); /* Print message */ z = 0; break; }#endif /* MAC */ c = zminchar(); /* Get a file character */ debug(F101,"transmit char","",c); if (c == -1) /* Test for end-of-file */ break; if (c < 0) { z = 0; goto xmitexit; } c &= fmask; /* Apply SET FILE BYTESIZE mask */ if (binary) { /* If binary file, */ if (ttoc(dopar((char) c)) < 0) { /* else just send the char */ printf("?Can't transmit character\n"); z = 0; goto xmitexit; }#ifdef TNCODE if (c == IAC && network && ttnproto == NP_TELNET) ttoc((char)IAC);#endif /* TNCODE */ if (xmitw) msleep(xmitw); /* Pause if requested */ if (xmitx) { /* SET TRANSMIT ECHO ON? */ if (duplex) { /* Yes, for half duplex */ if (conoc((char)(c & cmdmsk)) < 0) { /* echo locally. */ z = 0; goto xmitexit; } } else { /* For full duplex, */ int i, n; /* display whatever is there. */ n = ttchk(); /* See how many chars are waiting */ if (n < 0) { /* Connection dropped? */ z = 0; goto xmitexit; } for (i = 0; i < n; i++) { /* Read and echo that many. */ x = ttinc(1); /* Timed read just in case. */ if (x > -1) { /* If no timeout */ if (parity) x &= 0x7f; /* display the char, */ if (conoc((char)(x & cmdmsk)) < 0) { z = 0; goto xmitexit; } } else break; /* otherwise stop reading. */ } } } else ttflui(); /* Not echoing, just flush input. */ } else { /* Text mode, line at a time. */ if (c == '\n') { /* Got a line */ int stuff = -1; if (i == 0) { /* Blank line? */ if (xmitf) /* Yes, insert fill if asked. */ line[i++] = dopar((char) xmitf); } if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR))) line[i++] = dopar(CR); /* Terminate it with CR */ if (xmitl) { stuff = LF;#ifdef TNCODE } else if (network && /* TELNET NEWLINE ON/OFF/RAW */ (ttnproto == NP_TELNET) && (tn_nlm != TNL_CR)) { stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;#endif /* TNCODE */ } if (stuff > -1) line[i++] = dopar((char)stuff); } else if (c != -1) { /* Not a newline, regular character */#ifdef COMMENT csave = c; /* Remember untranslated version */#endif /* COMMENT */#ifndef NOCSETS /* Translate character sets */#ifdef CKOUNI if (cs_is_nrc(tcsl) || c > 127) if (sxo) c = (*sxo)(c); /* From local to intermediate */ if (c >= 32) if (rxo) c = (*rxo)(c); /* From intermediate to remote */#else /* CKOUNI */ if (sxo) c = (*sxo)((CHAR)c); /* From local to intermediate */ if (rxo) c = (*rxo)((CHAR)c); /* From intermediate to remote */#endif /* CKOUNI */#endif /* NOCSETS */ if (xmits && parity && (c & 0200)) { /* If shifting */ line[i++] = dopar(SO); /* needs to be done, */ line[i++] = dopar((char)c); /* do it here, */ line[i++] = dopar(SI); /* crudely. */ } else { line[i++] = dopar((char)c); /* else, just char itself */#ifdef TNCODE if (c == IAC && network && ttnproto == NP_TELNET) line[i++] = IAC;#endif /* TNCODE */ } }/* Send characters if buffer full, or at end of line, or at end of file */ if (i >= XMBUFS || c == '\n' || c == -1) { p = line; line[i] = '\0'; debug(F111,"transmit buf",p,i); if (ttol((CHAR *)p,i) < 0) { /* try to send it. */ printf("Can't send buffer\n"); z = 0; break; } i = 0; /* Reset buffer pointer. *//* Worry about echoing here. "xmitx" is SET TRANSMIT ECHO flag. */ if (duplex && xmitx) { /* If local echo, echo it */ if (parity || cmdmsk == 0x7f) { /* Strip off high bits */ char *s = p; /* if necessary */ while (*s) { *s &= 0x7f; s++; } if (conoll(p) < 0) { z = 0; goto xmitexit; } } } if (xmitw) /* Give receiver time to digest. */ msleep(xmitw); if (t != 0 && c == '\n') { /* Want a turnaround character */ x = 0; /* Wait for it */ while (x != t) { if ((x = ttinc(1)) < 0) { z = 0; goto xmitexit; } if (xmitx && !duplex) { /* Echo any echoes */ if (parity) x &= 0x7f;#ifndef NOCSETS#ifdef CKOUNI if (cs_is_nrc(tcsr) || x > 127) if (sxi) x = (*sxi)(x); if (x >= 32) if (rxi) x = (*rxi)(x);#else /* CKOUNI */ if (sxi) x = (*sxi)((CHAR)x); /* But translate */ if (rxi) x = (*rxi)((CHAR)x); /* them first... */#endif /* CKOUNI */#endif /* NOCSETS */ if (conoc((char) x) < 0) { z = 0; goto xmitexit; } } } } else if (xmitx && !duplex) { /* Otherwise, */ int n; while ((n = ttchk()) > 0) { /* echo for as long as */ if ((x = ttinc(0)) < 0) break; /* anything is there. */ if (parity) x &= 0x7f;#ifndef NOCSETS#ifdef CKOUNI if (cs_is_nrc(tcsr) || x > 127) if (sxi) x = (*sxi)(x); if (x >= 32) if (rxi) x = (*rxi)(x);#else /* CKOUNI */ if (sxi) x = (*sxi)((CHAR)x); /* Translate first */ if (rxi) x = (*rxi)((CHAR)x);#endif /* CKOUNI */#endif /* NOCSETS */ if (conoc((char)x) < 0) { z = 0; goto xmitexit; } } if (n < 0) { /* Connection dropped? */ z = 0; goto xmitexit; } } else ttflui(); /* Otherwise just flush input buffer */ } /* End of buffer-dumping block */ } /* End of text mode */ } /* End of character-reading loop */xmitexit: if (z > 0) { if (*xmitbuf) { /* Anything to send at EOF? */ p = xmitbuf; /* Yes, point to string. */ while (*p) /* Send it. */ ttoc(dopar(*p++)); /* Don't worry about echo here. */ } }#ifndef AMIGA#ifndef MAC signal(SIGINT,oldsig); /* Put old signal action back. */#endif /* MAC */#endif /* AMIGA */#ifdef VMS concb(escape); /* Put terminal back, */#endif /* VMS */ zclose(ZIFILE); /* Close file, */#ifndef NOCSETS language = langsv; /* restore language, */#endif /* NOCSETS */ binary = mybinary; /* restore transfer mode, */ ttres(); /* and terminal modes, */ return(z); /* and return successfully. */}#endif /* NOLOCAL */#endif /* NOXMIT */#ifndef NOCSETS_PROTOTYP( CHAR (*sxx), (CHAR) ); /* Local translation function */_PROTOTYP( CHAR (*rxx), (CHAR) ); /* Local translation function */_PROTOTYP( CHAR zl1as, (CHAR) ); /* Latin-1 to ascii */_PROTOTYP( CHAR xl1as, (CHAR) ); /* ditto *//* X L A T E -- Translate a local file from one character set to another *//* Translates input file (fin) from character set csin to character set csout and puts the result in the output file (fout). The two character sets are file character sets from fcstab.*/intxlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {#ifndef MAC#ifdef OS2#ifdef NT SIGTYP (* oldsig)(int); /* For saving old interrupt trap. */#else /* NT */ SIGTYP (* volatile oldsig)(int); /* For saving old interrupt trap. */#endif /* NT */#else /* OS2 */ SIGTYP (* oldsig)(); /* For saving old interrupt trap. */#endif /* OS2 */#endif /* MAC */ int filecode; /* Code for output file */ int z = 1; /* Return code. */ int c, tcs; /* Workers */ if (zopeni(ZIFILE,fin) == 0) { /* Open the file to be translated */ printf("?Can't open input file %s\n",fin); return(0); }#ifdef MAC/* If user specified no output file, it goes to the screen. For the Mac, this must be done a special way (result goes to a new window); the Mac doesn't have a "controlling terminal" device name.*/ filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;#else#ifdef VMS filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;#else filecode = ZOFILE;#endif /* VMS */#endif /* MAC */ if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */ printf("?Can't open output file %s\n",fout); return(0); }#ifndef AMIGA#ifndef MAC oldsig = signal(SIGINT, trtrap); /* Save current interrupt trap. */#endif /* MAC */#endif /* AMIGA */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -