ckuus4.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:380k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- case TN_NG_RF: printf( "u, refused; " ); break;
- case TN_NG_RQ: printf( "u, requested; "); break;
- case TN_NG_MU: printf( "u, required; "); break;
- }
- switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
- case TN_NG_AC: printf( "me, accepted; " ); break ;
- case TN_NG_RF: printf( "me, refused; " ); break;
- case TN_NG_RQ: printf( "me, requested; "); break;
- case TN_NG_MU: printf( "me, required; "); break;
- }
- printf("u, %s; me, %sn",
- TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
- TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
- );
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" binary-transfer-mode: %sn",showoff(tn_b_xfer));
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" bug binary-me-means-u-too: %sn",showoff(tn_b_meu));
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" bug binary-u-means-me-too: %sn",showoff(tn_b_ume));
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" bug sb-implies-will-do: %sn",showoff(tn_sb_bug));
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" terminal-type: ");
- if (tn_term) {
- printf("%sn",tn_term);
- } else {
- char *p;
- #ifdef OS2
- p = (tt_type >= 0 && tt_type <= max_tt) ?
- tt_info[tt_type].x_name :
- "UNKNOWN";
- #else
- p = getenv("TERM");
- #endif /* OS2 */
- if (p)
- printf("none (%s will be used)n",p);
- else printf("nonen");
- }
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- #ifdef CK_ENVIRONMENT
- printf(" environment: %sn", showoff(tn_env_flg));
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" account: %sn",tn_env_acct);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" display: %sn",tn_env_disp);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" job : %sn",tn_env_job);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" printer: %sn",tn_env_prnt);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- #ifndef NOSPL
- printf(" user : %sn",uidbuf);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- #endif /* NOSPL */
- printf(" system : %sn",tn_env_sys);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- #endif /* CK_ENVIRONMENT */
- #ifdef CK_SNDLOC
- printf(" location: %sn", tn_loc ? tn_loc : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- #endif /* CK_SNDLOC */
- return(n);
- }
- #endif /* TNCODE */
- #ifdef CK_NETBIOS
- static int
- shonb(n) int n; {
- printf("NETBIOS parameters:n");
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" API : %sn",
- NetbeuiAPI ?
- "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
- : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" Local Name: [%s]n", NetBiosName);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- printf(" Adapter : %dn", NetBiosAdapter);
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- if (NetBiosLSN > 0xFF) {
- printf(" Session : %dn", NetBiosLSN);
- } else {
- printf(" Session : none activen");
- }
- if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
- return(n);
- }
- #endif /* CK_NETBIOS */
- #ifndef NONET
- int
- shonet() {
- #ifndef NETCONN
- printf("nNo networks are supported in this version of C-Kermitn");
- #else
- #ifdef NOLOCAL
- printf("nNo networks are supported in this version of C-Kermitn");
- #else /* rest of this routine */
- int i, n = 4;
- #ifndef NODIAL
- if (nnetdir <= 1) {
- printf("nNetwork directory: %sn",netdir[0] ? netdir[0] : "(none)");
- n++;
- } else {
- int i;
- printf("nNetwork directories:n");
- for (i = 0; i < nnetdir; i++) {
- printf("%2d. %sn",i,netdir[i]);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- }
- #endif /* NODIAL */
- #ifdef OS2
- printf("nNetwork availability:n");
- #else
- printf("nSupported networks:n");
- #endif /* OS2 */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #ifdef VMS
- #ifdef TCPWARE
- printf(" Process Software Corporation TCPware for OpenVMS");
- #else
- #ifdef MULTINET
- printf(" TGV MultiNet TCP/IP");
- #else
- #ifdef WINTCP
- printf(" WOLLONGONG WIN/TCP");
- #else
- #ifdef DEC_TCPIP
- {
- static $DESCRIPTOR(tcp_desc,"_TCP0:");
- int status;
- long devclass;
- static int itmcod = DVI$_DEVCLASS;
- #ifdef COMMENT
- status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
- #else
- /* Martin Zinser 9/96 */
- status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
- #endif /* COMMENT */
- if ((status & 1) && (devclass == DC$_SCOM))
- printf(" Process Software Corporation TCPware for OpenVMS");
- else
- #ifdef UCX50
- printf(" DEC TCP/IP Services for (Open)VMS 5.0");
- #else
- printf(" DEC TCP/IP Services for (Open)VMS");
- #endif /* UCX50 */
- }
- #else
- #ifdef CMU_TCPIP
- printf(" CMU-OpenVMS/IP");
- #else
- printf(" None");
- #endif /* CMU_TCPIP */
- #endif /* DEC_TCPIP */
- #endif /* WINTCP */
- #endif /* MULTINET */
- #endif /* TCPWARE */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #ifdef TNCODE
- printf(", TELNET protocolnn");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- n = shotel(n);
- if (n < 0) return(0);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* TNCODE */
- printf("n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #else /* Not VMS */
- #ifdef SUNX25
- printf(" SunLink X.25n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SUNX25 */
- #ifdef STRATUSX25
- printf(" Stratus VOS X.25n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* STRATUSX25 */
- #ifdef IBMX25
- printf(" IBM AIX X.25n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* IBMX25 */
- #ifdef HPX25
- printf(" HP-UX X.25n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* HPX25 */
- #ifdef DECNET
- #ifdef OS2
- #ifdef NT
- if (dnet_avail)
- printf(" DECnet, LAT and CTERM protocolsn");
- else
- printf(" DECnet, LAT and CTERM protocols - not availablen");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #else /* NT */
- if (dnet_avail)
- printf(" DECnet, LAT protocoln");
- else
- printf(" DECnet, LAT protocol - not availablen");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* NT */
- #else
- printf(" DECnetn");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* OS2 */
- #endif /* DECNET */
- #ifdef NPIPE
- printf(" Named Pipesn");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* NPIPE */
- #ifdef CK_NETBIOS
- if (netbiosAvail)
- printf(" NETBIOSn");
- else
- printf(" NETBIOS - not availablen");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* CK_NETBIOS */
- #ifdef SUPERLAT
- if (slat_avail)
- printf(" SuperLATn");
- else
- printf(" SuperLAT - not availablen") ;
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SUPERLAT */
- #ifdef TCPSOCKET
- if (
- #ifdef OS2
- tcp_avail
- #else
- 1
- #endif /* OS2 */
- ) {
- char ipaddr[16];
- if (getlocalipaddrs(ipaddr,16,0) < 0) {
- #ifdef OS2ONLY
- printf(" TCP/IP via %sn", tcpname);
- #else
- printf(" TCP/IPn");
- #endif /* OS2ONLY */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- } else {
- int i = 1;
- #ifdef OS2ONLY
- printf(" TCP/IP [%16s] via %sn", ipaddr, tcpname);
- #else
- printf(" TCP/IP [%16s]n",ipaddr);
- #endif /* OS2ONLY */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
- printf(" [%16s]n",ipaddr);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- }
- #ifdef TNCODE
- if (nettype == NET_TCPB) {
- printf("n");
- n = shotel(++n);
- if (n < 0) return(0);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #endif /* TNCODE */
- #ifdef OS2
- } else {
- printf(" TCP/IP - not available%sn",tcpname[0] ? tcpname : "" );
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* OS2 */
- }
- #endif /* TCPSOCKET */
- #ifdef CK_NETBIOS
- if (netbiosAvail && nettype == NET_BIOS) {
- printf("n") ;
- if ((n = shonb(++n)) < 0) return(0);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #endif /* CK_NETBIOS */
- #endif /* VMS */
- printf("nActive network connection:n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- if (network) {
- printf(" Host: %s",ttname);
- if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
- printf(" [%s]",ipaddr);
- } else
- printf(" Host: none");
- printf(", via: ");
- if (nettype == NET_TCPA || nettype == NET_TCPB)
- printf("tcp/ipn");
- else if (nettype == NET_SX25)
- printf("SunLink X.25n");
- else if (nettype == NET_VX25)
- printf("Stratus VOS X.25n");
- else if (nettype == NET_IX25)
- printf("IBM AIX X.25n");
- else if (nettype == NET_HX25)
- printf("HP-UX X.25n");
- else if (nettype == NET_DEC) {
- if ( ttnproto == NP_LAT )
- printf("DECnet LATn");
- else if ( ttnproto == NP_CTERM )
- printf("DECnet CTERMn");
- else
- printf("DECnetn");
- } else if (nettype == NET_PIPE)
- printf("Named Pipesn");
- else if (nettype == NET_BIOS)
- printf("NetBIOSn");
- else if (nettype == NET_SLAT)
- printf("SuperLATn");
- #ifdef NETFILE
- else if ( nettype == NET_FILE )
- printf("local filen");
- #endif /* NETFILE */
- #ifdef NETCMD
- else if ( nettype == NET_CMD )
- printf("pipen");
- #endif /* NETCMD */
- #ifdef NETPTY
- else if ( nettype == NET_PTY )
- printf("psuedoterminaln");
- #endif /* NETPTY */
- #ifdef NETDLL
- else if ( nettype == NET_DLL )
- printf("dynamic link libraryn");
- #endif /* NETDLL */
- #ifdef SSH
- else if ( nettype == NET_SSH )
- printf("Secure Shelln");
- #endif /* SSH */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #ifdef ANYX25
- if ((nettype == NET_SX25) ||
- (nettype == NET_VX25) ||
- (nettype == NET_IX25))
- if ((n = shox25(n)) < 0) return(0);
- #endif /* ANYX25 */
- #ifdef TCPSOCKET
- if (nettype == NET_TCPA || nettype == NET_TCPB) {
- printf(" Reverse DNS lookup: %sn", showooa(tcp_rdns));
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #ifdef CK_DNS_SRV
- printf(" DNS Service Records lookup: %sn", showooa(tcp_dns_srv));
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* CK_DNS_SRV */
- #ifndef NOTCPOPTS
- #ifdef SOL_SOCKET
- #ifdef SO_KEEPALIVE
- printf(" Keepalive: %sn", showoff(tcp_keepalive));
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SO_KEEPALIVE */
- #ifdef SO_LINGER
- printf(" Linger: %s", tcp_linger ? "on, " : "offn" );
- if (tcp_linger) {
- if (tcp_linger_tmo)
- printf("%d x 10 millisecondsn",tcp_linger_tmo);
- else
- printf("no timeoutn");
- }
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SO_LINGER */
- #ifdef SO_DONTROUTE
- printf(" DontRoute: %sn", tcp_dontroute ? "on" : "off" );
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SO_DONTROUTE */
- #ifdef TCP_NODELAY
- printf(" Nodelay: %sn", showoff(tcp_nodelay));
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* TCP_NODELAY */
- #ifdef SO_SNDBUF
- if (tcp_sendbuf <= 0)
- printf(" Send buffer: (default size)n");
- else
- printf(" Send buffer: %d bytesn", tcp_sendbuf);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SO_SNDBUF */
- #ifdef SO_RCVBUF
- if (tcp_recvbuf <= 0)
- printf(" Receive buffer: (default size)n");
- else
- printf(" Receive buffer: %d bytesn", tcp_recvbuf);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- #endif /* SO_RCVBUF */
- #endif /* SOL_SOCKET */
- #endif /* NOTCPOPTS */
- }
- #ifdef RLOGCODE
- if (ttnproto == NP_RLOGIN) {
- printf(" LOGIN (rlogin) protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #ifdef CK_KERBEROS
- else if (ttnproto == NP_K4LOGIN) {
- printf(" Kerberos 4 LOGIN (klogin) protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- else if (ttnproto == NP_EK4LOGIN) {
- printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- else if (ttnproto == NP_K5LOGIN) {
- printf(" Kerberos 5 LOGIN (klogin) protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- else if (ttnproto == NP_EK5LOGIN) {
- printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #endif /* CK_KERBEROS */
- #endif /* RLOGCODE */
- #ifdef TNCODE
- if (ttnproto == NP_TELNET) {
- printf(" TELNET protocoln");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Echoing is currently %sn",duplex ? "local" : "remote");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #endif /* TNCODE */
- if (ttnproto == NP_TCPRAW) {
- printf(" Raw TCP socketn");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- }
- #endif /* TCPSOCKET */
- printf("n");
- #endif /* NOLOCAL */
- #endif /* NETCONN */
- return(0);
- }
- #endif /* NONET */
- #ifndef NODIAL
- VOID
- shodial() {
- if (mdmtyp >= 0 || local != 0) doshodial();
- }
- VOID
- shods(s) char *s; { /* Show a dial-related string */
- char c;
- if (s == NULL || !(*s)) { /* Empty? */
- printf("(none)n");
- } else { /* Not empty. */
- while (c = *s++) /* Can contain controls */
- if (c == '\') /* a backslash */
- printf("\\");
- else if (c > 31 && c < 127) {
- putchar(c);
- } else
- printf("\{%d}",c);
- printf("n");
- }
- }
- int
- doshodial() {
- int i, n = 2;
- printf(" Dial status: %d", dialsta);
- #ifdef BIGBUFOK
- if (dialsta > 90)
- printf(" = Unknown error");
- else if (dialsta < 0)
- printf(" = (none)");
- else if (dialsta < 30 && dialmsg[dialsta])
- printf(" = %s", dialmsg[dialsta]);
- #endif /* BIGBUFOK */
- n++;
- if (ndialdir <= 1) {
- printf("n Dial directory: %sn",dialdir[0] ? dialdir[0] : "(none)");
- } else {
- int i;
- printf("n Dial directories:n");
- for (i = 0; i < ndialdir; i++)
- printf("%2d. %sn",i+1,dialdir[i]);
- n += ndialdir;
- }
- printf(" Dial method: ");
- if (dialmauto) printf("auto ");
- else if (dialmth == XYDM_D) printf("default");
- else if (dialmth == XYDM_P) printf("pulse ");
- else if (dialmth == XYDM_T) printf("tone ");
- printf(" Dial sort: %sn",dialsrt ? "on" : "off");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Dial hangup: %s Dial display: %sn",
- dialhng ? "on " : "off", dialdpy ? "on" : "off");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- if (dialrtr > 0) {
- printf(" Dial retries: %-6d Dial interval: %dn",
- dialrtr, dialint);
- } else {
- printf(" Dial retries: (auto) Dial interval: %dn", dialint);
- }
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Dial timeout: ");
- #ifdef CK_TAPI
- if (tttapi && !tapipass)
- printf("(tapi)");
- else
- #endif /* CK_TAPI */
- if (dialtmo > 0)
- printf("%4d sec", dialtmo);
- else
- printf("0 (auto)");
- printf(" Redial number: %sn",dialnum ? dialnum : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Dial confirmation: %s Dial convert-directory: %sn",
- dialcnf ? "on " : "off",
- dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
- printf(" Dial pacing: %dn",dialpace);
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial prefix: %sn", dialnpr ? dialnpr : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial suffix: %sn", dialsfx ? dialsfx : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial country-code: %-12s", diallcc ? diallcc : "(none)");
- printf("Dial connect: %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
- : "off");
- if (dialcon != CAR_OFF)
- printf(" %s", dialcq ? "quiet" : "verbose");
- printf(
- "n Dial area-code: %-12s", diallac ? diallac : "(none)");
- n++;
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf("Dial restrict: ");
- if (dialrstr == 5) printf("internationaln");
- else if (dialrstr == 4) printf("long-distancen");
- else if (dialrstr == 2) printf("localn");
- else if (dialrstr == 6) printf("nonen");
- else printf("?n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(" Dial lc-area-codes: ");
- if (nlocalac == 0)
- printf("(none)");
- else
- for (i = 0; i < nlocalac; i++)
- printf("%s ", diallcac[i]);
- printf(
- "n Dial lc-prefix: %sn", diallcp ? diallcp : "(none)");
- n++;
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial lc-suffix: %sn", diallcs ? diallcs : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial ld-prefix: %sn", dialldp ? dialldp : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial ld-suffix: %sn", diallds ? diallds : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial force-long-distance %sn", showoff(dialfld));
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial intl-prefix: %sn", dialixp ? dialixp : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial intl-suffix: %sn", dialixs ? dialixs : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial toll-free-area-code: ");
- if (ntollfree == 0)
- printf("(none)");
- else
- for (i = 0; i < ntollfree; i++)
- printf("%s ", dialtfc[i]);
- printf("n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial pulse-countries: ");
- if (ndialpucc == 0)
- printf("(none)");
- else
- for (i = 0; i < ndialpucc; i++)
- printf("%s ", dialpucc[i]);
- printf("n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial tone-countries: ");
- if (ndialtocc == 0)
- printf("(none)");
- else
- for (i = 0; i < ndialtocc; i++)
- printf("%s ", dialtocc[i]);
- printf("n");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial toll-free-prefix: %sn",
- dialtfp ? dialtfp :
- (dialldp ? dialldp : "(none)")
- );
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- #ifdef COMMENT
- " Dial pbx-exchange: %sn", dialpxx ? dialpxx : "(none)");
- #else
- " Dial pbx-exchange: ");
- if (ndialpxx == 0)
- printf("(none)");
- else
- for (i = 0; i < ndialpxx; i++)
- printf("%s ", dialpxx[i]);
- printf("n");
- #endif /* COMMENT */
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial pbx-inside-prefix: %sn", dialpxi ? dialpxi : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial pbx-outside-prefix: %sn", dialpxo ? dialpxo : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
- printf(
- " Dial macro: %sn", dialmac ? dialmac : "(none)");
- return(0);
- }
- #endif /* NODIAL */
- #endif /* NOLOCAL */
- /* Show File Parameters */
- static char *
- pathval(x) int x; {
- switch (x) {
- case PATH_OFF: return("off");
- case PATH_ABS: return("absolute");
- case PATH_REL: return("relative");
- case PATH_AUTO: return("auto");
- default: return("unknown");
- }
- }
- VOID
- shofil() {
- char *s; int i = 0, n = 1;
- extern char * ifdnam[];
- #ifdef UNIX
- extern int wildxpand;
- #endif /* UNIX */
- extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
- #ifdef PATTERNS
- extern int patterns;
- #endif /* PATTERNS */
- extern char * rfspec, * sfspec;
- #ifdef UNIX
- extern int zobufsize, zofbuffer, zofblock;
- #endif /* UNIX */
- #ifdef CK_CTRLZ
- extern int eofmethod;
- #endif /* CK_CTRLZ */
- printf("n");
- #ifdef VMS
- printf(" File record-Length: %5dn",frecl);
- n++;
- #endif /* VMS */
- #ifndef NOXFER
- printf(" Transfer mode: %sn",
- xfermode == XMODE_A ?
- "automatic" :
- "manual"
- );
- n++;
- #ifdef PATTERNS
- printf(" File patterns: %s", showooa(patterns));
- if (xfermode == XMODE_M && patterns)
- printf(" (but disabled by TRANSFER-MODE MANUAL)");
- else if (patterns)
- printf(" (SHOW PATTERNS for list)");
- printf("n");
- n++;
- #endif /* PATTERNS */
- if (xfermode == XMODE_A)
- printf(" Default file type: %sn",shoxm());
- else
- printf(" File type: %sn",shoxm());
- n++;
- if (fncnv == XYFN_L)
- s = "literal";
- else if (fncnv == XYFN_C)
- s = "converted";
- else
- s = "(unknown)";
- printf(" File names: %sn",s);
- n++;
- printf(" Send pathnames: %sn", pathval(fnspath));
- n++;
- printf(" Receive pathnames: %sn", pathval(fnrpath));
- n++;
- #ifdef UNIXOROSK
- printf(" Match dot files: %sn", matchdot ? "yes" : "no");
- n++;
- #ifdef UNIX
- printf(" Wildcard-expansion: %sn", wildxpand ? "shell" : "kermit");
- n++;
- #endif /* UNIX */
- #endif /* UNIXOROSK */
- printf(" File collision: ");
- for (i = 0; i < ncolx; i++)
- if (colxtab[i].kwval == fncact) break;
- printf("%sn", (i == ncolx) ? "unknown" : colxtab[i].kwd);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" File destination: %sn",
- (dest == DEST_D) ? "disk" :
- ((dest == DEST_S) ? "screen" :
- ((dest == DEST_N) ? "nowhere" :
- "printer"))
- );
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
- printf(" File incomplete: %sn",s);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" File bytesize: %dn",(fmask == 0177) ? 7 : 8);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #ifndef NOCSETS
- printf(" File character-set: %sn",fcsinfo[fcharset].keyword);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #ifdef UNICODE
- printf(" File UCS bom: %sn",showoff(ucsbom));
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" File UCS byte-order: %s-endiann",
- ucsorder ? "little" : "big");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Computer byteorder: %s-endiann",
- byteorder ? "little" : "big");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* UNICODE */
- #endif /* NOCSETS */
- printf(" File end-of-line: ");
- i = feol;
- switch (feol) {
- case XYFA_C: printf("%sn","cr"); break;
- case XYFA_L: printf("%sn","lf"); break;
- case XYFA_2: printf("%sn","crlf"); break;
- default: printf("%dn",i);
- }
- #endif /* NOXFER */
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #ifdef CK_CTRLZ
- printf(" File eof: %sn", eofmethod ? "ctrl-z" : "length");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* CK_CTRLZ */
- #ifndef NOXFER
- #ifdef CK_TMPDIR
- printf(" File download-directory: %sn", dldir ? dldir : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #ifdef COMMENT
- i = 256;
- s = line;
- zzstring("\v(tmpdir)",&s,&i);
- printf(" Temporary directory: %sn", line);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* COMMENT */
- #endif /* CK_TMPDIR */
- #ifdef VMS
- {
- extern int vmssversions, vmsrversions;
- printf(" Send version-numbers: %sn",showoff(vmssversions));
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Receive version-numbers: %sn",showoff(vmsrversions));
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- }
- #endif /* VMS */
- printf(" Send move-to: %sn",
- snd_move ? snd_move : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Send rename-to: %sn",
- snd_rename ? snd_rename : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Receive move-to: %sn",
- rcv_move ? rcv_move : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Receive rename-to: %sn",
- rcv_rename ? rcv_rename : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* NOXFER */
- #ifdef KERMRC
- printf(" Initialization file: %sn", noinit ? "(none)" :
- #ifdef CK_SYSINI
- CK_SYSINI
- #else
- kermrc
- #endif /* CK_SYSINI */
- );
- #endif /* KERMRC */
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- if (k_info_dir) {
- printf(" Kermit doc files: %sn", k_info_dir);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- }
- #ifdef UNIX
- printf(" Disk output buffer: %d (writes are %s, %s)n",
- zobufsize,
- zofbuffer ? "buffered" : "unbuffered",
- zofblock ? "blocking" : "nonblocking"
- );
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* UNIX */
- #ifdef OS2ORUNIX
- printf(" Longest filename: %dn", maxnam);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Longest pathname: %dn", maxpath);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- #endif /* OS2ORUNIX */
- printf(" Last file sent: %sn", sfspec ? sfspec : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" Last file received: %sn", rfspec ? rfspec : "(none)");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf("n Also see:n");
- n++;
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf(" SHOW PROTOCOL, SHOW XFER");
- #ifdef CK_LABELED
- printf(", SHOW LABELED");
- #endif /* CK_LABELED */
- #ifdef PATTERNS
- printf(", SHOW PATTERNS");
- #endif /* PATTERNS */
- #ifdef STREAMING
- printf(", SHOW STREAMING");
- #endif /* STREAMING */
- #ifndef NOCSETS
- printf(", SHOW CHARACTER-SETS");
- #endif /* NOCSETS */
- printf("nn");
- }
- #ifndef NOXFER
- VOID
- shoparp() { /* Protocol */
- extern int docrc, skipbup;
- char *s;
- #ifdef CK_TIMERS
- extern int rttflg;
- #endif /* CK_TIMERS */
- printf("Protocol: %sn",ptab[protocol].p_name);
- if (protocol == PROTO_K) {
- printf("nProtocol Parameters: Send Receive");
- if (timef)
- printf("n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
- else
- printf("n Timeout (used=%2d):%7d%9d ", timint, rtimo, pkttim);
- #ifdef XFRCAN
- printf(" Cancellation: %s",showoff(xfrcan));
- if (xfrcan)
- printf(" %d %d", xfrchr, xfrnum);
- #endif /* XFRCAN */
- printf("n Padding: %11d%9d", npad, mypadn);
- if (bctr == 4)
- printf(" Block Check: blank-free-2n");
- else
- printf(" Block Check: %6dn",bctr);
- printf( " Pad Character:%11d%9d", padch, mypadc);
- printf(" Delay: %6dn",ckdelay);
- printf( " Pause: %11d%9d", pktpaus, pktpaus);
- printf(" Attributes: %sn",showoff(atcapr));
- printf( " Packet Start: %11d%9d", mystch, stchr);
- printf(" Max Retries: %6dn",maxtry);
- printf( " Packet End: %11d%9d", seol, eol);
- if (ebqflg)
- printf(" 8th-Bit Prefix: '%c'",ebq);
- else
- printf(" 8th-Bit Prefix: ('%c' but not used)",ebq);
- printf( "n Packet Length:%11d ", spmax);
- printf("%8d ", urpsiz);
- if (rptflg)
- printf(" Repeat Prefix: '%c'",rptq);
- else
- printf(" Repeat Prefix: ('%c' but not used)",rptq);
- printf( "n Maximum Length: %9d%9d", maxsps, maxrps);
- printf(" Window Size:%7d set, %d usedn",wslotr,wmax);
- printf( " Buffer Size: %11d%9d", bigsbsiz, bigrbsiz);
- printf(" Locking-Shift: ");
- if (lscapu == 2) {
- printf("forced");
- } else {
- printf("%s", (lscapr ? "enabled" : "disabled"));
- if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
- }
- printf("nn");
- if (!(s = ptab[protocol].h_b_init)) s = "";
- printf(" Auto-upload command (binary): %sn", *s ? s : "(none)");
- if (!(s = ptab[protocol].h_t_init)) s = "";
- printf(" Auto-upload command (text): %sn", *s ? s : "(none)");
- if (!(s = ptab[protocol].h_x_init)) s = "";
- printf(" Auto-server command: %sn", *s ? s : "(none)");
- tmpbuf[0] = NUL;
- #ifdef CK_TIMERS
- if (rttflg) {
- extern int mintime, maxtime;
- sprintf(tmpbuf," Packet timeouts: dynamic %d:%d",
- mintime,
- maxtime);
- } else {
- sprintf(tmpbuf," Packet timeouts: fixed");
- }
- #endif /* CK_TIMERS */
- if (tmpbuf[0])
- printf("%-31s",tmpbuf);
- printf("Send backup: %sn",showoff(!skipbup));
- printf(" Transfer mode: %s", xfermode == XMODE_A ?
- "automatic " :
- "manual "
- );
- printf(" Transfer slow-start: %s, crc: %sn",
- showoff(slostart),
- showoff(docrc)
- );
- #ifdef PIPESEND
- {
- extern int usepipes;
- printf(" Transfer pipes: %s ",usepipes ? "on " : "off");
- }
- #endif /* PIPESEND */
- #ifndef NOCSETS
- printf(" Transfer character-set: ");
- if (tcharset == TC_TRANSP)
- printf("transparentn");
- else
- printf("%sn", tcsinfo[tcharset].keyword );
- #endif /* NOCSETS */
- #ifdef PIPESEND
- {
- extern char * sndfilter, * rcvfilter;
- printf(" Send filter: %sn", sndfilter ? sndfilter : "(none)");
- printf(" Receive filter: %sn", rcvfilter ? rcvfilter : "(none)");
- }
- #endif /* PIPESEND */
- printf("nAlso see:n");
- printf(" SHOW FILE, SHOW XFER");
- #ifdef CK_LABELED
- printf(", SHOW LABELED");
- #endif /* CK_LABELED */
- #ifdef PATTERNS
- printf(", SHOW PATTERNS");
- #endif /* PATTERNS */
- #ifdef STREAMING
- printf(", SHOW STREAMING");
- #endif /* STREAMING */
- #ifndef NOCSETS
- printf(", SHOW CHARACTER-SETS");
- #endif /* NOCSETS */
- }
- #ifdef CK_XYZ
- #ifdef XYZ_INTERNAL
- if (protocol != PROTO_K) {
- int i;
- int x;
- printf(" File type: %sn", binary ? "binary" : "text");
- if (protocol == PROTO_Z) { /* Zmodem */
- printf(" Window size: ");
- if (ptab[protocol].winsize < 1)
- printf("nonen");
- else
- printf("%dn",wslotr);
- #ifdef COMMENT
- printf(" Packet (frame) length: ");
- if (ptab[protocol].spktlen < 0)
- printf("nonen");
- else
- printf("%dn",spmax);
- #endif /* COMMENT */
- } else {
- if (ptab[protocol].spktlen >= 1000)
- printf(" 1K packetsn");
- else
- printf(" 128-byte packetsn");
- }
- printf(" Pathname stripping when sending: %sn",
- showoff(ptab[protocol].fnsp)
- );
- printf(" Pathname stripping when receiving: %sn",
- showoff(ptab[protocol].fnrp)
- );
- printf(" Filename collision action: ");
- for (i = 0; i < ncolx; i++)
- if (colxtab[i].kwval == fncact) break;
- printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
- printf("n Escape control characters: ");
- x = ptab[protocol].prefix;
- if (x == PX_ALL)
- printf("alln");
- else if (x == PX_CAU || x==PX_WIL)
- printf("minimaln");
- else
- printf("nonen");
- if (!(s = ptab[protocol].h_b_init))
- s = "";
- printf(" Autoreceive command (binary): %sn", *s ? s : "(none)");
- if (!(s = ptab[protocol].h_t_init))
- s = "";
- printf(" Autoreceive command (text): %sn", *s ? s : "(none)");
- }
- #else
- if (protocol != PROTO_K) {
- printf("nExecuted by external commands:nn");
- s = ptab[protocol].p_b_scmd;
- if (!s) s = "";
- printf(" SEND command (binary): %sn", *s ? s : "(none)");
- s = ptab[protocol].p_t_scmd;
- if (!s) s = "";
- printf(" SEND command (text): %sn", *s ? s : "(none)");
- s = ptab[protocol].p_b_rcmd;
- if (!s) s = "";
- printf(" RECEIVE command (binary): %sn", *s ? s : "(none)");
- s = ptab[protocol].p_t_rcmd;
- if (!s) s = "";
- printf(" RECEIVE command (text): %sn", *s ? s : "(none)");
- s = ptab[protocol].h_b_init;
- if (!s) s = "";
- printf(" Autoreceive command (binary): %sn", *s ? s : "(none)");
- s = ptab[protocol].h_t_init;
- if (!s) s = "";
- printf(" Autoreceive command (text): %sn", *s ? s : "(none)");
- }
- #endif /* XYZ_INTERNAL */
- #endif /* CK_XYZ */
- }
- #endif /* NOXFER */
- #ifndef NOCSETS
- /* Character-set items */
- extern int s_cset, r_cset, axcset[], afcset[];
- extern struct keytab xfrmtab[];
- VOID
- shoparl() {
- #ifdef COMMENT
- int i;
- /* Misleading... */
- printf("nAvailable Languages:n");
- for (i = 0; i < MAXLANG; i++) {
- printf(" %sn",langs[i].description);
- }
- #else
- printf("nLanguage-specific translation rules: %sn",
- language == L_USASCII ? "none" : langs[language].description);
- shocharset();
- printf("nn");
- #endif /* COMMENT */
- }
- VOID
- shocharset() {
- int x;
- char * s = "Unknown";
- extern int xlatype;
- debug(F101,"SHOW FILE CHAR","",fcharset);
- printf("n File Character-Set: %s (%s), ",
- fcsinfo[fcharset].keyword,
- fcsinfo[fcharset].name
- );
- if ((x = fcsinfo[fcharset].size) == 128)
- printf("7-bit");
- else if (x == 256)
- printf("8-bit");
- else
- printf("multibyte");
- printf("n Transfer Character-Set");
- #ifdef COMMENT
- if (tslevel == TS_L2)
- printf(": (international)");
- else
- #endif /* COMMENT */
- if (tcharset == TC_TRANSP)
- printf(": Transparent");
- else
- printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
- printf("n");
- #ifdef COMMENT
- switch (xlatype) {
- case XLA_NONE: s = "None"; break;
- case XLA_BYTE: s = "Byte"; break;
- case XLA_JAPAN: s = "Japanese"; break;
- case XLA_UNICODE: s = "Unicode"; break;
- }
- printf("n Translation type: %sn",s);
- #endif /* COMMENT */
- printf(" SEND character-set-selection: %sn",xfrmtab[s_cset].kwd);
- printf(" RECEIVE character-set-selection: %sn",xfrmtab[r_cset].kwd);
- if (s_cset == XMODE_A || r_cset == XMODE_A)
- printf(
- " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)n"
- );
- }
- VOID
- showassoc() {
- int i, k, n = 4;
- char * s;
- printf("nFor incoming files:nn");
- printf("Transfer Character-Set File Character-Setn");
- for (i = 1; i <= MAXTCSETS; i++) {
- k = axcset[i];
- if (k < 0 || k > MAXFCSETS)
- s = "(none)";
- else
- s = fcsinfo[k].keyword;
- if (!s) s = "";
- if (!*s) s = "(none)";
- printf(" %-25s%sn",tcsinfo[i].keyword,s);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- }
- printf("nFor outbound files:nn");
- n += 2;
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- printf("File Character-Set Transfer Character-Setn");
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- for (i = 0; i <= MAXFCSETS; i++) {
- k = afcset[i];
- if (k < 0 || k > MAXTCSETS)
- s = "(none)";
- else
- s = tcsinfo[k].keyword;
- if (!s) s = "";
- if (!*s) s = "(none)";
- printf(" %-25s%sn",fcsinfo[i].keyword,s);
- if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
- }
- }
- #endif /* NOCSETS */
- VOID
- shopar() {
- printf("Show what? (Type "show ?" for a list of possiblities.)n");
- }
- #endif /* NOSHOW */
- #ifndef NOXFER
- /* D O S T A T -- Display file transfer statistics. */
- int
- dostat(brief) int brief; {
- extern long filrej, peakcps;
- extern int lastspmax, streamed, cleared, streamok;
- extern char whoareu[];
- int n = 0;
- extern int docrc, interrupted, fatalio;
- #ifdef CK_TTGWSIZ
- #ifdef OS2
- if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
- ttgwsiz();
- #else /* OS2 */
- if (ttgwsiz() > 0) {
- if (tt_rows > 0 && tt_cols > 0) {
- cmd_rows = tt_rows;
- cmd_cols = tt_cols;
- }
- }
- #endif /* OS2 */
- #endif /* CK_TTGWSIZ */
- debug(F101,"dostat xferstat","",xferstat);
- if (xferstat < 0) {
- printf(" No file transfers yet.n");
- return(1);
- }
- if (brief) printf("n");
- n = 1;
- printf(" status : ");
- if (xferstat) printf("SUCCESSn");
- else if (interrupted) printf("FAILURE (interrupted)n");
- else if (fatalio) printf("FAILURE (i/o error)n");
- else printf("FAILUREn");
- n++;
- if (xferstat > 0) {
- if (docrc)
- printf(" crc-16 of file(s) : %ldn", crc16);
- else
- printf(" crc-16 of file(s) : (disabled)n");
- n++;
- }
- if (!xferstat && *epktmsg) {
- printf(" reason : %sn", epktmsg);
- n++;
- }
- if (!brief) {
- if (whoareu[0]) {
- printf(" remote system type : %sn",
- getsysid((char *)whoareu));
- n++;
- }
- printf(" files transferred : %ldn",filcnt - filrej);
- printf(" files not transferred : %ldn",filrej);
- printf(" characters last file : %ldn",ffc);
- printf(" total file characters : %ldn",tfc);
- printf(" communication line in : %ldn",tlci);
- printf(" communication line out : %ldn",tlco);
- printf(" packets sent : %dn", spackets);
- printf(" packets received : %dn", rpackets);
- n += 8;
- }
- printf(" damaged packets rec'd : %dn", crunched);
- printf(" timeouts : %dn", timeouts);
- printf(" retransmissions : %dn", retrans);
- n += 3;
- if (!brief) {
- if (filcnt > 0) {
- printf(" parity : %s",parnam((char)parity));
- n++;
- if (autopar) { printf(" (detected automatically)"); n++; }
- printf(
- "n control characters : %ld prefixed, %ld unprefixedn",
- ccp, ccu);
- n++;
- printf(" 8th bit prefixing : ");
- n++;
- if (ebqflg) printf("yes [%c]n",ebq); else printf("non");
- n++;
- printf(" locking shifts : %sn", lscapu ? "yes" : "no");
- n++;
- }
- }
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- if (streamed > 0)
- printf(" window slots used : (streaming)n");
- else
- printf(" window slots used : %d of %dn", wmax, wslotr);
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- printf(" reliable: : %s%sn",
- streamok ? "" : "not ", "negotiated");
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- printf(" clearchannel: : %s%sn",
- cleared ? "" : "not ", "negotiated");
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- if (!brief) {
- printf(" packet length : %d (send), %d (receive)n",
- lastspmax, urpsiz);
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- printf(" compression : ");
- if (rptflg)
- printf("yes [%c] (%ld)n",(char) rptq,rptn);
- else
- printf("non");
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- if (bctu == 4)
- printf(" block check type used : blank-free-2n");
- else
- printf(" block check type used : %dn",bctu);
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- }
- #ifdef GFTIMER
- #ifdef COMMENT
- printf(" elapsed time : %0.3f sec, %sn", fptsecs,hhmmss(tsecs));
- #endif /* COMMENT */
- printf(" elapsed time : %s (%0.3f sec)n",
- hhmmss((long)(fptsecs + 0.5)),fptsecs);
- #else
- #ifdef COMMENT
- printf(" elapsed time : %s (%d sec)n",hhmmss(tsecs),tsecs);
- #endif /* COMMENT */
- printf(" elapsed time : %d sec, %sn",tsecs,hhmmss(tsecs));
- #endif /* GFTIMER */
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- if (local && !network && !brief) {
- if (speed <= 0L) speed = ttgspd();
- if (speed > 0L) {
- if (speed == 8880)
- printf(" transmission rate : 75/1200 bpsn");
- else
- printf(" transmission rate : %ld bpsn",speed);
- if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
- }
- }
- if (local && !network && /* Only makes sense for */
- mdmtyp == 0 && /* direct serial connections */
- speed > 99L && /* when we really know the speed */
- speed != 8880L
- ) {
- int eff;
- eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
- printf(" effective data rate : %ld cps (%d%%)n",tfcps,eff);
- } else
- printf(" effective data rate : %ld cpsn", tfcps);
- if (peakcps > 0L && peakcps > tfcps)
- printf(" peak data rate : %ld cpsn", peakcps);
- if (brief)
- printf("nUse STATISTICS /VERBOSE for greater detail.nn");
- return(1);
- }
- #endif /* NOXFER */
- #ifndef NOSPL
- /* The INPUT command */
- /*
- NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
- material that has already arrived and is waiting to be read, and perform
- matches against it, without doing any further reads. It should succeed
- or fail instantaneously.
- */
- /* Output buffering for "doinput" */
- #ifdef pdp11
- #define MAXBURST 16 /* Maximum size of input burst */
- #else
- #define MAXBURST 1024
- #endif /* pdp11 */
- #ifdef OSK
- static CHAR *conbuf; /* Buffer to hold output for console */
- #else
- static CHAR conbuf[MAXBURST]; /* Buffer to hold output for console */
- #endif /* OSK */
- static int concnt = 0; /* Number of characters buffered */
- #ifdef OSK
- static CHAR *sesbuf; /* Buffer to hold output for session log */
- #else
- static CHAR sesbuf[MAXBURST]; /* Buffer to hold output for session log */
- #endif /* OSK */
- static int sescnt = 0; /* Number of characters buffered */
- static VOID /* Flush INPUT echoing */
- myflsh() { /* and session log output. */
- if (concnt > 0) {
- conxo(concnt, (char *) conbuf);
- concnt = 0;
- }
- if (sescnt > 0) {
- logstr((char *) sesbuf, sescnt);
- sescnt = 0;
- }
- }
- /* Execute the INPUT and MINPUT commands */
- int instatus = -1;
- long inetime = -1L;
- int inwait = 0;
- /* For returning the input sequence that matched */
- #ifdef BIGBUFOK
- #define MATCHBUFSIZ 8191
- #else
- #define MATCHBUFSIZ 1023
- #endif /* BIGBUFOK */
- static char * matchbuf = NULL;
- static int matchindex = 0;
- /*
- timo = How long to wait:
- < 0 = Wait forever
- 0 = Don't wait
- > 0 = Wait this many seconds
- ms = Array of strings to wait for.
- mp = Array of flags.
- If mp[i] == 0, ms[i] is literal, else it's a pattern.
- */
- int
- doinput(timo,ms,mp) int timo; char *ms[]; int mp[]; {
- extern int inintr;
- #ifdef CK_AUTODL
- extern int inautodl;
- #endif /* CK_AUTODL */
- int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
- #ifdef GFTIMER
- CKFLOAT fpt = 0.0;
- #endif /* GFTIMER */
- int lastchar = 0;
- int waiting = 0;
- char ch, *xp, *s;
- CHAR c;
- #ifdef OS2
- extern int term_io;
- int term_io_save;
- #endif /* OS2 */
- #ifdef TNCODE
- static int cr = 0;
- #endif /* TNCODE */
- int is_tn = 0;
- int wrapped = 0;
- #define CK_BURST
- /*
- This enables the INPUT speedup code, which depends on ttchk() returning
- accurate information. If INPUT fails with this code enabled, change the
- above "#define" to "#undef".
- */
- #ifdef CK_BURST
- int burst = 0; /* Chars remaining in input burst */
- #endif /* CK_BURST */
- inwait = timo; /* For v(inwait) */
- makestr(&inpmatch,NULL);
- if (!matchbuf)
- matchbuf = malloc(MATCHBUFSIZ+1);
- matchindex = 0;
- is_tn =
- #ifdef TNCODE
- (local && network && ttnproto == NP_TELNET) || (!local && sstelnet)
- #else
- 0
- #endif /* TNCODE */
- ;
- instatus = INP_IE; /* 3 = internal error */
- kbchar = 0;
- #ifdef OSK
- if (conbuf == NULL) {
- if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
- return(0);
- }
- sesbuf = conbuf + MAXBURST;
- }
- #endif /* OSK */
- #ifndef NOLOCAL
- if (local) { /* In local mode... */
- if ((waiting = ttchk()) < 0) { /* check that connection is open */
- printf("?Connection %s %s is not open.n",
- network ? "to" : "on",
- ttname
- );
- instatus = INP_IO;
- return(0);
- }
- debug(F101,"doinput waiting","",waiting);
- y = ttvt(speed,flow); /* Put line in "ttvt" mode */
- if (y < 0) {
- printf("?INPUT initialization errorn");
- instatus = INP_IO;
- return(0); /* Watch out for failure. */
- }
- }
- #endif /* NOLOCAL */
- if (!ms[0]) { /* If we were passed a NULL pointer */
- anychar = 1; /* ... */
- } else {
- y = (int)strlen(ms[0]); /* Or if search string is empty */
- anychar = (y < 1); /* any input character will do. */
- }
- if (!anychar && waiting == 0 && timo == 0)
- return(0);
- #ifndef NODEBUG
- if (deblog) {
- char xbuf[24];
- debug(F101,"doinput anychar","",anychar);
- debug(F101,"doinput timo","",timo);
- debug(F101,"doinput echo","",inecho);
- debug(F101,"doinput burst","",burst);
- y = -1;
- while (ms[++y]) {
- sprintf(xbuf,"doinput string %2d",y);
- debug(F111,xbuf,ms[y],mp[y]);
- }
- }
- #endif /* NODEBUG */
- #ifdef IKS_OPTION
- if (is_tn) {
- /* If the remote side is in a state of IKS START-SERVER */
- /* we request that the state be changed. We will detect */
- /* a failure to adhere to the request when we call ttinc() */
- if (TELOPT_U(TELOPT_KERMIT) &&
- TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
- iks_wait(KERMIT_REQ_STOP,0); /* Send Request-Stop */
- #ifdef CK_AUTODL
- /* If we are processing packets during INPUT and we have not */
- /* sent a START message, do so now. */
- if (inautodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
- tn_siks(KERMIT_START); /* Send Kermit-Server Start */
- }
- #endif /* CK_AUTODL */
- }
- #endif /* IKS_OPTION */
- x = 0; /* Return code, assume failure */
- instatus = INP_TO; /* Status, assume timeout */
- for (y = 0; y < MINPMAX; y++)
- mi[y] = 0; /* String pattern match position */
- if (!inpcas[cmdlvl]) { /* INPUT CASE = IGNORE? */
- y = -1;
- while(xp = ms[++y]) {
- while (*xp) { /* Convert to lowercase */
- if (isupper(*xp)) *xp = (char) tolower(*xp);
- xp++;
- }
- }
- }
- rtimer(); /* Reset timer. */
- #ifdef GFTIMER
- rftimer(); /* Floating-point timer too. */
- #endif /* GFTIMER */
- inetime = -1L; /* Initialize elapsed time. */
- t = 0; /* Time now is 0. */
- m_found = 0; /* Default to timed-out */
- incount = 0; /* Character counter */
- rt = (timo == 0) ? 0 : 1; /* Character-read timeout interval */
- #ifdef OS2
- term_io_save = term_io; /* Disable I/O by emulator */
- term_io = 0;
- #endif /* OS2 */
- while (1) { /* Character-getting loop */
- #ifdef CK_APC
- /* Check to see if there is an Autodown or other APC command */
- if (apcactive == APC_LOCAL ||
- (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
- if (mlook(mactab,"_apc_commands",nmac) == -1) {
- debug(F110,"doinput about to execute APC",apcbuf,0);
- domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
- delmac("_apc_commands");
- apcactive = APC_INACTIVE;
- #ifdef DEBUG
- } else {
- debug(F100,"doinput APC in progress","",0);
- #endif /* DEBUG */
- }
- }
- #endif /* CK_APC */
- if (timo == 0 && waiting < 1) { /* Special exit criterion */
- instatus = INP_TO; /* for timeout == 0 */
- break;
- }
- if (local) { /* One case for local */
- y = ttinc(rt); /* Get character from comm device */
- debug(F101,"input ttinc(rt) returns","",y);
- if (y < -1) { /* Connection failed. */
- instatus = INP_IO; /* Status = i/o error */
- #ifdef OS2
- term_io = term_io_save;
- #endif /* OS2 */
- switch (y) {
- case -2: /* Connection lost */
- if (local && !network && carrier != CAR_OFF) {
- #ifdef CKLOGDIAL
- dologend();
- #endif /* CKLOGDIAL */
- printf("Connection closed.n");
- ttclos(1);
- }
- break;
- case -3:
- #ifdef CKLOGDIAL
- dologend();
- #endif /* CKLOGDIAL */
- printf("Session Limit exceeded - closing connection.n");
- ttclos(1);
- default:
- break;
- }
- return(0);
- }
- if (inintr) {
- if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
- kbchar = coninc(0);
- debug(F101,"input interrupted from keyboard","",icn);
- while (--icn > 0) {
- debug(F110,"doinput","absorbing",0);
- coninc(0); /* Yes, absorb what was typed. */
- }
- instatus = INP_UI; /* Fail and remember why. */
- break;
- }
- }
- } else { /* Another for remote */
- y = coninc(rt);
- debug(F101,"input coninc(rt) returns","",y);
- }
- if (y > -1) { /* A character arrived */
- if (timo == 0)
- waiting--;
- #ifndef OS2
- #ifdef TNCODE
- /* Check for telnet protocol negotiation */
- if (is_tn) {
- switch (y & 0xff) {
- case IAC:
- cr = 0;
- myflsh(); /* Break from input burst for tn_doop() */
- #ifdef CK_BURST
- burst = 0;
- #endif /* CK_BURST */
- waiting -= 2; /* (not necessarily...) */
- switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
- case 2: duplex = 0; continue;
- case 1: duplex = 1; continue;
- #ifdef IKS_OPTION
- case 4:
- if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
- !tcp_incoming) {
- instatus = INP_IKS;
- printf(
- " Internet Kermit Service in SERVER mode.n Please use REMOTE commands.n"
- );
- break;
- }
- continue;
- #endif /* IKS_OPTION */
- case 6: /* TELNET DO LOGOUT received */
- default: continue;
- }
- case CR:
- cr = 1;
- break;
- case NUL:
- if (!TELOPT_U(TELOPT_BINARY) && cr) {
- cr = 0;
- continue;
- }
- cr = 0;
- break;
- default:
- cr = 0;
- }
- /* I'm echoing remote chars */
- if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
- ttoc((char)y);
- }
- #endif /* TNCODE */
- #ifdef CK_AUTODL
- /* Check for file transfer packets */
- if (inautodl) autodown(y);
- #endif /* CK_AUTODL */
- #else /* OS2 */
- #ifdef TNCODE
- /* Check for telnet protocol negotiation */
- if (is_tn) {
- int tx;
- switch (y & 0xff) {
- case IAC:
- myflsh(); /* Break from input burst for tn_doop() */
- #ifdef CK_BURST
- burst = 0;
- #endif /* CK_BURST */
- #ifdef IKS_OPTION
- tx = scriptwrtbuf((USHORT)y);
- if (tx == 4) {
- if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
- !tcp_incoming
- ) {
- instatus = INP_IKS;
- printf(
- " Internet Kermit Service in SERVER mode.n Please use REMOTE commands.n"
- );
- break;
- }
- } else if (tx == 6) {
- /* TELNET DO LOGOUT received */
- }
- #else /* IKS_OPTION */
- /* Handles Telnet negotiations */
- tx = scriptwrtbuf((USHORT)y);
- if (tx == 6) {
- /* TELNET DO LOGOUT received */
- }
- #endif /* IKS_OPTION */
- waiting -= 2; /* (not necessarily...) */
- cr = 0;
- continue; /* and autodownload check */
- case CR:
- cr = 1;
- tx = scriptwrtbuf((USHORT)y);
- if (tx == 6) {
- /* TELNET DO LOGOUT received */
- }
- break;
- case NUL:
- cr = 0;
- if (!TELOPT_U(TELOPT_BINARY) && cr)
- continue;
- tx = scriptwrtbuf((USHORT)y);
- if (tx == 6) {
- /* TELNET DO LOGOUT received */
- }
- break;
- default:
- cr = 0;
- tx = scriptwrtbuf((USHORT)y);
- if (tx == 6) {
- /* TELNET DO LOGOUT received */
- }
- }
- /* I'm echoing remote chars */
- if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
- ttoc((CHAR)y);
- } else
- #endif /* TNCODE */
- /* Handles terminal emulation responses */
- scriptwrtbuf((USHORT)y);
- #endif /* OS2 */
- /* Real input character to be checked */
- #ifdef CK_BURST
- burst--; /* One less character waiting */
- debug(F101,"doinput burst","",burst);
- #endif /* CK_BURST */
- c = (CHAR) (cmask & (CHAR) y); /* Mask off parity */
- inchar[0] = c; /* Remember character for v(inchar) */
- #ifdef COMMENT
- #ifdef CK_BURST
- /* Update "lastchar" time only once during input burst */
- if (burst <= 0)
- #endif /* CK_BURST */
- #endif /* COMMENT */
- lastchar = gtimer(); /* Remember when it came */
- if (c == ' ') { /* NUL, we can't use it */
- if (anychar) { /* Except if any character will do? */
- x = 1; /* Yes, done. */
- incount = 1; /* This must be the first and only. */
- break;
- } else goto refill; /* Otherwise continue INPUTting */
- }
- *inpbp++ = c; /* Store char in circular buffer */
- incount++; /* Count it for v(incount) */
- /* Don't NUL-terminate here - it's a circular buffer. */
- if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
- wrapped++;
- *inpbp = NUL ; /* Make it null-terminated */
- inpbp = inpbuf; /* Yes. */
- }
- if (matchbuf) {
- if (matchindex < MATCHBUFSIZ) {
- matchbuf[matchindex++] = c;
- matchbuf[matchindex] = NUL;
- }
- }
- #ifdef MAC
- {
- extern char *ttermw; /* fake pointer cast */
- if (inecho) {
- outchar(ttermw, c); /* echo to terminal window */
- /* this might be too much overhead to do here ? */
- updatecommand(ttermw);
- }
- }
- #else /* Not MAC */
- if (inecho) conbuf[concnt++] = c; /* Buffer console output */
- #endif /* MAC */
- #ifndef OS2
- if (seslog) {
- #ifdef UNIX
- if (sessft != 0 || c != 'r')
- #else
- #ifdef OSK
- if (sessft != 0 || c != ' 12')
- #endif /* OSK */
- #endif /* UNIX */
- sesbuf[sescnt++] = c; /* Buffer session log output */
- }
- #endif /* OS2 */
- if (anychar) { /* Any character will do? */
- x = 1;
- break;
- }
- if (!inpcas[cmdlvl]) { /* Ignore alphabetic case? */
- if (isupper(c)) /* Yes, convert input char to lower */
- c = (CHAR) tolower(c);
- }
- debug(F000,"doinput char","",c);
- /* Here is the matching section */
- y = -1; /* Loop thru search strings */
- while (s = ms[++y]) { /* ...as many as we have. */
- if (mp[y]) { /* Pattern match? */
- int j;
- /* This is gross but it works... */
- /* We could just as easily have prepended '*' to the */
- /* pattern and skipped the loop, except then we would */
- /* not have any way to identify the matching string. */
- for (j = 0; j < matchindex; j++) {
- if (ckmatch(s,&matchbuf[j],1,0)) {
- matchindex = j;
- x = 1;
- break;
- }
- }
- if (x > 0)
- break;
- continue;
- } /* Literal match. */
- i = mi[y]; /* Match-position in search string. */
- debug(F000,"compare char","",(CHAR)s[i]);
- if (c == (CHAR) s[i]) { /* Check for match */
- i++; /* Got one, go to next character */
- } else { /* Don't have a match */
- int j;
- for (j = i; i > 0; ) { /* Back up in search string */
- i--; /* (Do this here to prevent compiler foulup) */
- /* j is the length of the substring that matched */
- if (c == (CHAR) s[i]) {
- if (!strncmp(s,&s[j-i],i)) {
- i++; /* c actually matches -- cfk */
- break;
- }
- }
- }
- }
- if ((CHAR) s[i] == (CHAR) ' ') { /* Matched to end? */
- ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
- matchindex = 0;
- x = 1; /* Yes, */
- break; /* done. */
- }
- mi[y] = i; /* No, remember match-position */
- }
- if (x == 1) { /* Set v(minput) result */
- m_found = y + 1;
- break;
- }
- }
- #ifdef CK_BURST
- else if (y <= -1 && burst > 0) {
- debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
- /* a timo occurred so there can't */
- burst = 0; /* be data waiting; must check timo */
- }
- refill:
- if (burst <= 0) { /* No buffered chars remaining... */
- myflsh(); /* Flush buffered output */
- if (local) { /* Get size of next input burst */
- burst = ttchk();
- if (burst < 0) { /* ttchk() says connection is closed */
- instatus = INP_IO; /* Status = i/o error */
- #ifdef OS2
- term_io = term_io_save;
- #endif /* OS2 */
- printf("Fatal error - disconnected.n");
- ttclos(1);
- break;
- }
- if (inintr) {
- if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
- kbchar = coninc(0);
- debug(F101,"input interrupted from keyboard","",icn);
- while (--icn > 0) coninc(0); /* Yes, absorb chars. */
- break; /* And fail. */
- }
- }
- } else {
- burst = conchk();
- }
- debug(F101,"doinput burst","",burst);
- /* Prevent overflow of "conbuf" and "sesbuf" */
- if (burst > MAXBURST)
- burst = MAXBURST;
- /* Did not match, timer exceeded? */
- t = gtimer();
- debug(F111,"doinput gtimer","burst",t);
- debug(F101,"doinput timo","",timo);
- if ((t >= timo) && (timo > 0))
- break;
- else if (insilence > 0 && (t - lastchar) > insilence)
- break;
- } else {
- debug(F111,"doinput (burst > 0)","burst",burst);
- }
- #else
- myflsh(); /* Flush buffered output */
- /* Did not match, timer exceeded? */
- t = gtimer();
- debug(F111,"doinput gtimer","no burst",t);
- debug(F101,"doinput timo","",timo);
- if ((t >= timo) && (timo > -1))
- break;
- else if (insilence > 0 && (t - lastchar) > insilence)
- break;
- #endif /* CK_BURST */
- } /* Still have time left, continue. */
- myflsh(); /* Flush buffered output. */
- if (x > 0)
- instatus = 0;
- #ifdef OS2
- term_io = term_io_save;
- #endif /* OS2 */
- #ifdef COMMENT
- #ifdef IKS_OPTION
- #ifdef CK_AUTODL
- if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
- tn_siks(KERMIT_STOP); /* Send Kermit-Server Stop */
- }
- #endif /* CK_AUTODL */
- #endif /* IKS_OPTION */
- #endif /* COMMENT */
- #ifdef GFTIMER
- fpt = gftimer(); /* Get elapsed time */
- /* If a long is 32 bits, it would take about 50 days for this to overflow. */
- inetime = (int)(fpt * (CKFLOAT)1000.0);
- #else
- inetime = (int)(gtimer() * 1000);
- #endif /* GFTIMER */
- makestr(&inpmatch,&matchbuf[matchindex]); /* v(inmatch) */
- return(x); /* Return the return code. */
- }
- #endif /* NOSPL */
- #ifndef NOSPL
- /* REINPUT Command */
- /*
- Note, the timeout parameter is required, but ignored. Syntax is compatible
- with MS-DOS Kermit except timeout can't be omitted. This function only
- looks at the characters already received and does not read any new
- characters from the connection.
- */
- int
- doreinp(timo,s,pat) int timo; char *s; int pat; {
- int x, y, i;
- char *xx, *xp, *xq = (char *)0;
- CHAR c;
- if (!s) s = "";
- debug(F101,"doreinput pat","",pat);
- y = (int)strlen(s);
- debug(F111,"doreinput search",s,y);
- if (y > inbufsize) { /* If search string longer than */
- debug(F101,"doreinput inbufsize","",inbufsize);
- return(0); /* input buffer, fail. */
- }
- makestr(&inpmatch,NULL);
- if (!matchbuf)
- matchbuf = malloc(MATCHBUFSIZ+1);
- matchindex = 0;
- x = 0; /* Return code, assume failure */
- i = 0; /* String pattern match position */
- if (!inpcas[cmdlvl]) { /* INPUT CASE = IGNORE? */
- xp = malloc(y+2); /* Make a separate copy of the */
- if (!xp) { /* search string. */
- printf("?malloc error 6n");
- return(x);
- } else xq = xp; /* Keep pointer to beginning. */
- while (*s) { /* Yes, convert to lowercase */
- *xp = *s;
- if (isupper(*xp)) *xp = (char) tolower(*xp);
- xp++; s++;
- }
- *xp = NUL; /* Terminate it! */
- s = xq; /* Move search pointer to it. */
- }
- xx = *inpbp ? inpbp : inpbuf; /* Current INPUT buffer pointer */
- do {
- c = *xx++; /* Get next character */
- debug(F000,"XXX","",c);
- if (!c) break;
- if (xx >= inpbuf + inbufsize) /* Wrap around if necessary */
- xx = inpbuf;
- if (!inpcas[cmdlvl]) { /* Ignore alphabetic case? */
- if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
- }
- if (pat) {
- int j;
- if (matchbuf) {
- if (matchindex < MATCHBUFSIZ) {
- matchbuf[matchindex++] = c;
- matchbuf[matchindex] = NUL;
- debug(F111,"XXX",matchbuf,matchindex);
- }
- for (j = 0; j < matchindex; j++) { /* Gross but effective */
- if (ckmatch(s,&matchbuf[j],1,0)) {
- debug(F101,"GOT IT","",j);
- matchindex = j;
- x = 1;
- break;
- }
- }
- }
- if (x > 0)
- break;
- continue;
- }
- debug(F000,"doreinp char","",c);
- debug(F000,"compare char","",(CHAR) s[i]);
- if (((char) c) == ((char) s[i])) { /* Check for match */
- i++; /* Got one, go to next character */
- } else { /* Don't have a match */
- int j;
- for (j = i; i > 0; ) { /* [jrs] search backwards for it */
- i--;
- if (((char) c) == ((char) s[i])) {
- if (!strncmp(s,&s[j-i],i)) {
- i++;
- break;
- }
- }
- }
- } /* [jrs] or return to zero from -1 */
- if (s[i] == ' ') { /* Matched all the way to end? */
- ckstrncpy(matchbuf,s,MATCHBUFSIZ);
- matchindex = 0;
- x = 1; /* Yes, */
- break; /* done. */
- }
- } while (xx != inpbp && x < 1); /* Until back where we started. */
- if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
- makestr(&inpmatch,&matchbuf[matchindex]); /* v(inmatch) */
- return(x); /* Return search result. */
- }
- /* X X S T R I N G -- Interpret strings containing backslash escapes */
- /* Z Z S T R I N G -- (new name...) */
- /*
- Copies result to new string.
- strips enclosing braces or doublequotes.
- interprets backslash escapes.
- returns 0 on success, nonzero on failure.
- tries to be compatible with MS-DOS Kermit.
- Syntax of input string:
- string = chars | "chars" | {chars}
- chars = (c*e*)*
- where c = any printable character, ascii 32-126
- and e = a backslash escape
- and * means 0 or more repetitions of preceding quantity
- backslash escape = operand
- operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
- number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
- radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
- */
- #ifndef NOFRILLS
- int
- yystring(s,s2) char *s; char **s2; { /* Reverse a string */
- int x;
- static char *new;
- new = *s2;
- if (!s || !new) return(-1); /* Watch out for null pointers. */
- if ((x = (int)strlen(s)) == 0) { /* Recursion done. */
- *new = ' ';
- return(0);
- }
- x--; /* Otherwise, call self */
- *new++ = s[x]; /* to reverse rest of string. */
- s[x] = 0;
- return(yystring(s,&new));
- }
- #endif /* NOFRILLS */
- static char ipabuf[16] = { NUL }; /* IP address buffer */
- static char *
- getip(s) char *s; {
- char c=NUL; /* Workers... */
- int i=0, p=0, d=0;
- int state = 0; /* State of 2-state FSA */
- while (c = *s++) {
- switch(state) {
- case 0: /* Find first digit */
- i = 0; /* Output buffer index */
- ipabuf[i] = NUL; /* Initialize output buffer */
- p = 0; /* Period counter */
- d = 0; /* Digit counter */
- if (isdigit(c)) { /* Have first digit */
- d = 1; /* Count it */
- ipabuf[i++] = c; /* Copy it */
- state = 1; /* Change state */
- }
- break;
- case 1: /* In numeric field */
- if (isdigit(c)) { /* Have digit */
- if (++d > 3) /* Too many */
- state = 0; /* Start over */
- else /* Not too many */
- ipabuf[i++] = c; /* Keep it */
- } else if (c == '.' && p < 3) { /* Have a period */
- p++; /* Count it */
- if (d == 0) /* Not preceded by a digit */
- state = 0; /* Start over */
- else /* OK */
- ipabuf[i++] = c; /* Keep it */
- d = 0; /* Reset digit counter */
- } else if (p == 3 && d > 0) { /* Not part of address */
- ipabuf[i] = NUL; /* If we have full IP address */
- return((char *)ipabuf); /* Return it */
- } else { /* Otherwise */
- state = 0; /* Start over */
- ipabuf[0] = NUL; /* (in case no more chars left) */
- }
- }
- } /* Fall thru at end of string */
- ipabuf[i] = NUL; /* Maybe we have one */
- return((p == 3 && d > 0) ? (char *)ipabuf : "");
- }
- #endif /* NOSPL */
- /* Date Routines */
- /* Z J D A T E -- Convert yyyymmdd date to Day of Year */
- static int jdays[12] = { 0,31,59,90,120,151,181,212,243,273,304,334 };
- static int ldays[12] = { 0,31,60,91,121,152,182,213,244,274,305,335 };
- static char zjdbuf[12] = { NUL, NUL };
- /*
- Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
- statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
- praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
- fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
- consequentur centesimi non omnes bissextiles sint, sed in quadringentis
- quibusque annis primi quique tres centesimi sine bissexto transigantur,
- quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
- MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
- intercaletur, februario dies XXIX continente, idemque ordo intermittendi
- intercalandique bissextum diem in quadringentis quibusque annis perpetuo
- conservetur. - Gregorius XIII, Anno Domini MDLXXXII.
- */
- char *
- zjdate(date) char * date; { /* date = yyyymmdd */
- char year[5];
- char month[3];
- char day[3];
- int d, m, x, y;
- int leapday, j;
- char * time = NULL;
- if (!date) date = ""; /* Validate arg */
- x = strlen(date);
- if (x < 1) return("0");
- if (x < 8) return("-1");
- for (x = 0; x < 8; x++)
- if (!isdigit(date[x]))
- return("-1");
- if (date[8] && date[9])
- time = date + 9;
- year[0] = date[0]; /* Isolate year */
- year[1] = date[1];
- year[2] = date[2];
- year[3] = date[3];
- year[4] = ' ';
- month[0] = date[4]; /* Month */
- month[1] = date[5];
- month[2] = ' ';;
- day[0] = date[6]; /* And day */
- day[1] = date[7];
- day[2] = ' ';
- leapday = 0; /* Assume no leap day */
- y = atoi(year);
- m = atoi(month);
- d = atoi(day);
- if (m > 2) { /* No Leap day before March */
- if (y % 4 == 0) { /* If year is divisible by 4 */
- leapday = 1; /* It's a Leap year */
- if (y % 100 == 0) { /* Except if divisible by 100 */
- if (y % 400 != 0) /* but not by 400 */
- leapday = 0;
- }
- }
- }
- j = jdays[m - 1] + d + leapday; /* Day of year */
- if (time)
- sprintf(zjdbuf,"%04d%03d %s",y,j,time);
- else
- sprintf(zjdbuf,"%04d%03d",y,j);
- return((char *)zjdbuf);
- }
- static char jzdbuf[32];
- /* J Z D A T E -- Convert Day of Year to yyyyddmm date */
- char *
- jzdate(date) char * date; { /* date = yyyyddd */
- char year[5]; /* with optional time */
- char day[4];
- char * time = NULL, * p;
- int d, m, x, y;
- int leapday, j;
- int * zz;
- if (!date) date = ""; /* Validate arg */
- x = strlen(date);
- debug(F111,"jzdate len",date,x);
- if (x < 1) return("0");
- if (x < 7) return("-1");
- if (x > 8) time = date + 8;
- for (x = 0; x < 7; x++)
- if (!isdigit(date[x]))
- return("-1");
- year[0] = date[0]; /* Isolate year */
- year[1] = date[1];
- year[2] = date[2];
- year[3] = date[3];
- year[4] = ' ';
- debug(F110,"jzdate year",year,0);
- day[0] = date[4]; /* And day */
- day[1] = date[5];
- day[2] = date[6];
- day[3] = ' ';
- debug(F110,"jzdate day",day,0);
- j = atoi(day);
- if (j > 366)
- return("-1");
- leapday = 0; /* Assume no leap day */
- y = atoi(year);
- if (y % 4 == 0) { /* If year is divisible by 4 */
- leapday = 1; /* It's a Leap year */
- if (y % 100 == 0) { /* Except if divisible by 100 */
- if (y % 400 != 0) /* but not by 400 */
- leapday = 0;
- }
- }
- debug(F101,"jzdate leapday","",leapday);
- zz = leapday ? ldays : jdays;
- for (x = 0; x < 11; x++)
- if (j > zz[x] && j <= zz[x+1])
- break;
- m = x + 1;
- debug(F101,"jzdate m","",m);
- d = j - zz[x];
- debug(F101,"jzdate d","",d);
- if (time)
- sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time);
- else
- sprintf(jzdbuf,"%04d%02d%02d",y,m,d);
- debug(F101,"jzdate jzdbuf",jzdbuf,0);
- p = ckcvtdate((char *)jzdbuf, 0); /* Convert to standard form */
- ckstrncpy(jzdbuf,p,32);
- if (!time) jzdbuf[8] = NUL; /* Remove time if not wanted */
- return((char *)jzdbuf);
- }
- /* M J D -- Modified Julian Date */
- /*
- Call with:
- Standard-format date-time string: yyyymmdd[ hh:mm:ss].
- The time, if any, is ignored.
- Returns:
- -1L on error, otherwise:
- The number of days since 17 Nov 1858 (as a whole number)
- The Modified Julian Date is defined by the International Astronomical
- Union as the true Julian date minus 2400000.5 days. The true Julian
- date is the number days since since noon of 1 January 4713 BCE of the
- Julian proleptic calendar.
- */
- long
- mjd(date) char * date; {
- char year[5];
- char month[3];
- char day[3];
- int x, d, m, y;
- if (!date) date = ""; /* Validate arg */
- x = strlen(date);
- if (x < 1) return(0L);
- if (x < 8) return(-1L);
- for (x = 0; x < 8; x++)
- if (!isdigit(date[x]))
- return(-1L);
- year[0] = date[0]; /* Isolate year */
- year[1] = date[1];
- year[2] = date[2];
- year[3] = date[3];
- year[4] = ' ';
- y = atoi(year) - 1900;
- month[0] = date[4]; /* Month */
- month[1] = date[5];
- month[2] = ' ';;
- m = atoi(month);
- day[0] = date[6]; /* And day */
- day[1] = date[7];
- day[2] = ' ';
- d = atoi(day);
- if (m - 2 < 1) { /* Arithmetic */
- m += 9;
- y--;
- } else {
- m -= 3;
- }
- return(15078 + (1461 * y) / 4 + (153 * m + 2) / 5 + d);
- }
- static char mjd2dbuf[12];
- /* M J D 2 D A T E -- Converts MJD to yyyymmdd */
- char *
- #ifdef CK_ANSIC
- mjd2date(long mjd)
- #else
- mjd2date(mjd) long mjd;
- #endif /* CK_ANSIC */
- /* mjd2date */ {
- long jd, l, n;
- int d, m, y;
- jd = (long)(mjd + 2400001L);
- l = jd + 68569;
- n = 4 * l / 146097L;
- l = l - (146097 * n + 3) / 4;
- y = 4000 * (l + 1) / 1461001L;
- l = l - 1461 * y / 4 + 31;
- m = 80 * l / 2447;
- d = l - 2447 * m / 80;
- l = m / 11;
- m = m + 2 - 12 * l;
- y = 100 * (n - 49) + y + l;
- sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d);
- return((char *)mjd2dbuf);
- }
- #ifndef NOSPL
- static char ** flist = (char **) NULL; /* File list for fnextfile() */
- static int flistn = 0; /* Number of items in file list */
- /*
- The function return-value buffer must be global, since fneval() returns a
- pointer to it. fneval() is called only by zzstring(), which always copies
- the result out of this buffer to somewhere else, so it's OK to have only
- one buffer for this in most cases. However, since function calls can be
- nested -- e.g. functions whose arguments are functions, or recursive
- functions, at some point we should convert this to an array of buffers,
- indexed by function depth (which might or might not be the same as the
- "depth" variable). Also, since function results are potentially quite big,
- we'd need to allocate and deallocate dynamically as we descend and ascend
- function depth. Left for a future release...
- */
- char fnval[FNVALL+2]; /* Function return value */
- static int fndepth = 0; /* (we don't actually use this yet) */
- int fnsuccess = 1;
- extern int fnerror;
- static char * /* Evaluate builtin functions */
- fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
- int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
- int failed = 0; /* Return code, 0 = ok */
- long z = 0L;
- char *bp[FNARGS + 1]; /* Pointers to malloc'd strings */
- char c = NUL;
- char *p = NULL, *s = NULL;
- char *val1 = NULL, *val2 = NULL; /* Pointers to numeric string values */
- #ifdef RECURSIVE
- int rsave = recursive;
- #endif /* RECURSIVE */
- #ifdef OS2
- int zsave = zxpn;
- #endif /* OS2 */
- for (i = 0; i < FNARGS; i++) /* Initialize argument pointers */
- bp[i] = NULL;
- /*
- IMPORTANT: Note that argn is not an accurate count of the number of
- arguments. We can't really tell if an argument is null until after we
- execute the code below. So argn is really the maximum number of arguments
- we might have. In particular note that argn is always at least 1, even
- if the function is called with empty parentheses (but don't count on it).
- */
- if (!fn) fn = ""; /* Protect against null pointers */
- debug(F111,"fneval",fn,argn);
- debug(F110,"fneval",argp[0],0);
- if (argn > FNARGS) /* Discard excess arguments */
- argn = FNARGS;
- fndepth++;
- debug(F101,"fneval fndepth","",fndepth);
- p = fnval;
- fnval[0] = NUL;
- y = lookup(fnctab,fn,nfuncs,&x); /* Look up the function name */
- if (y < 0) { /* Not found */
- failed = 1;
- if (fndiags) { /* FUNCTION DIAGNOSTIC ON */
- int x;
- x = strlen(fn);
- switch (y) {
- case -1:
- if (x + 32 < FNVALL)
- sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\f%s()>",fn);
- else
- sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
- break;
- case -2:
- if (x + 26 < FNVALL)
- sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\f%s()>",fn);
- else
- sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
- break;
- case -3:
- sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\f()>");
- break;
- default:
- if (x + 26 < FNVALL)
- sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\f%s()>",fn);
- else
- sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
- break;
- }
- }
- goto fnend; /* Always leave via common exit */
- }
- #ifdef DEBUG
- if (deblog) {
- int j;
- for (j = 0; j < argn; j++)
- debug(F111,"fneval arg",argp[j],j);
- }
- #endif /* DEBUG */
- for (j = argn-1; j >= 0; j--) { /* Uncount empty trailing args */
- if (!argp[j])
- argn--;
- else if (!*(argp[j]))
- argn--;
- else break;
- }
- debug(F101,"fneval argn","",argn);
- /*
- fliteral() and fcontents() are special functions that do not evaluate
- their arguments, and are treated specially here. After these come the
- functions whose arguments are evaluated in the normal way.
- */
- if (y == FN_LIT) { /* literal(arg1) */
- debug(F110,"flit",xp,0);
- p = xp ? xp : ""; /* Return a pointer to arg itself */
- goto fnend;
- }
- if (y == FN_CON) { /* Contents of variable, unexpanded. */
- char c;
- if (!(p = argp[0]) || !*p) {
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:MISSING_ARG:\fcontents()>");
- goto fnend;
- }
- p = brstrip(p);
- if (*p == CMDQ) p++;
- if ((c = *p) == '%') { /* Scalar variable. */
- c = *++p; /* Get ID character. */
- p = ""; /* Assume definition is empty */
- if (!c) { /* Double paranoia */
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\fcontents()>");
- goto fnend;
- }
- if (c >= '0' && c <= '9') { /* Digit for macro arg */
- if (maclvl < 0) /* Digit variables are global */
- p = g_var[c]; /* if no macro is active */
- else /* otherwise */
- p = m_arg[maclvl][c - '0']; /* they're on the stack */
- } else if (c == '*' && maclvl >= 0) {
- p = m_line[maclvl];
- if (!p) p = "";
- } else {
- if (isupper(c)) c -= ('a'-'A');
- p = g_var[c]; /* Letter for global variable */
- }
- if (!p) p = "";
- goto fnend;
- } else if (c == '&') { /* Array reference. */
- int vbi, d;
- if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\fcontents()>");
- goto fnend;
- }
- if (chkarray(vbi,d) > 0) { /* Array is declared? */
- vbi -= ARRAYBASE; /* Convert name to index */
- if (a_dim[vbi] >= d) { /* If subscript in range */
- char **ap;
- ap = a_ptr[vbi]; /* get data pointer */
- if (ap) { /* and if there is one */
- p = ap[d];
- goto fnend;
- }
- }
- } else {
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\fcontents()>");
- goto fnend;
- }
- } else {
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\fcontents()>");
- goto fnend;
- }
- }
- p = fnval; /* Default result pointer */
- fnval[0] = NUL; /* Default result = empty string */
- for (i = 0; i < argn; i++) { /* Loop to expand each argument */
- n = MAXARGLEN; /* Allow plenty of space */
- bp[i] = s = malloc(n+1); /* Allocate space for this argument */
- if (bp[i] == NULL) { /* Handle failure to get space */
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:MALLOC_FAILURE:\f%s()>",fn);
- goto fnend;
- }
- p = argp[i] ? argp[i] : ""; /* Point to this argument */
- /*
- Trim leading and trailing spaces from the original argument, before
- evaluation. This code new to edit 184.
- */
- {
- int x, j;
- x = strlen(p);
- if (*p == '{' && *(p+x-1) == '}') {
- p[x-1] = NUL;
- p++;
- x -= 2;
- } else {
- j = x - 1; /* Trim trailing whitespace */
- while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
- *(p + j--) = NUL;
- while (*p == SP || *p == HT) /* Strip leading whitespace */
- p++;
- }
- }
- /* Now evaluate the argument */
- debug(F111,"fneval calling zzstring",p,n);
- t = zzstring(p,&s,&n); /* Expand arg into new space */
- debug(F101,"fneval zzstring","",t);
- debug(F101,"fneval zzstring","",n);
- if (t < 0) {
- debug(F101,"fneval zzstring fails, arg","",i);
- failed = 1;
- if (fndiags) {
- if (n == 0)
- sprintf(fnval,"<ERROR:ARG_TOO_LONG:\f%s()>",fn);
- else
- sprintf(fnval,"<ERROR:ARG_EVAL_FAILURE:\f%s()>",fn);
- }
- goto fnend;
- }
- debug(F111,"fneval arg",bp[i],i);
- }
- #ifdef DEBUG
- if (deblog) {
- int j;
- for (j = 0; j < argn; j++) {
- debug(F111,"fneval arg post eval",argp[j],j);
- debug(F111,"fneval evaluated arg",bp[j],j);
- }
- }
- #endif /* DEBUG */
- /*
- From this point on, bp[0..argn-1] are not NULL and all must be freed
- before returning.
- */
- if (argn < 1) { /* Catch required args missing */
- switch (y) {
- case FN_DEF:
- case FN_EVA:
- case FN_EXE:
- case FN_CHR:
- case FN_COD:
- case FN_MAX:
- case FN_MIN:
- case FN_MOD:
- case FN_FD:
- case FN_FS:
- case FN_TOD:
- case FN_FFN:
- case FN_BSN:
- case FN_RAW:
- case FN_CMD:
- case FN_2HEX:
- case FN_2OCT:
- case FN_DNAM:
- #ifdef FN_ERRMSG
- case FN_ERRMSG:
- #endif /* FN_ERRMSG */
- #ifdef CK_KERBEROS
- case FN_KRB_TK:
- case FN_KRB_NX:
- case FN_KRB_IV:
- case FN_KRB_TT:
- case FN_KRB_FG:
- #endif /* CK_KERBEROS */
- case FN_MJD2:
- case FN_N2TIM:
- case FN_DIM:
- case FN_DATEJ:
- case FN_PNCVT:
- case FN_PERM:
- case FN_ALOOK:
- case FN_TLOOK:
- case FN_ABS:
- case FN_FPABS:
- case FN_FPEXP:
- case FN_FPLOG:
- case FN_FPLN:
- case FN_FPMOD:
- case FN_FPSQR:
- case FN_FPADD:
- case FN_FPDIV:
- case FN_FPMUL:
- case FN_FPPOW:
- case FN_FPSUB:
- case FN_FPINT:
- case FN_FPROU:
- case FN_FPSIN:
- case FN_FPCOS:
- case FN_FPTAN:
- case FN_AADUMP:
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:MISSING_ARG:\f%s()>",fn);
- goto fnend;
- }
- }
- p = fnval; /* Reset these again. */
- fnval[0] = NUL;
- switch (y) { /* Do function on expanded args. */
- case FN_DEF: /* fdefinition(arg1) */
- k = mlook(mactab,bp[0],nmac);
- p = (k > -1) ? mactab[k].mval : "";
- goto fnend;
- case FN_EVA: /* fevaluate(arg1) */
- p = *(bp[0]) ? evalx(bp[0]) : "";
- if (!*p && fndiags) {
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- }
- goto fnend;
- case FN_EXE: /* fexecute(arg1) */
- j = (int)strlen(s = bp[0]); /* Length of macro invocation */
- p = ""; /* Initialize return value to null */
- if (j) { /* If there is a macro to execute */
- while (*s == SP) s++,j--; /* strip leading spaces */
- p = s; /* remember beginning of macro name */
- for (i = 0; i < j; i++) { /* find end of macro name */
- if (*s == SP)
- break;
- s++;
- }
- if (*s == SP) { /* if there was a space after */
- *s++ = NUL; /* terminate the macro name */
- while (*s == SP) s++; /* skip past any extra spaces */
- } else s = ""; /* maybe there are no arguments */
- if (p && *p)
- k = mlook(mactab,p,nmac); /* Look up the macro name */
- else
- k = -1;
- if (k < 0) {
- failed = 1;
- p = fnval;
- if (fndiags)
- sprintf(fnval,"<ERROR:NO_SUCH_MACRO:\f%s()>",fn);
- goto fnend;
- }
- /*
- This is just a WEE bit dangerous because we are copying up to 9 arguments
- into the space reserved for one. It won't overrun the buffer, but if there
- are lots of long arguments we might lose some. The other problem is that if
- the macro has more than 3 arguments, the 4th through last are all
- concatenated onto the third. (The workaround is to use spaces rather than
- commas to separate them.) Leaving it like this to avoid having to allocate
- tons more buffers.
- */
- if (argn > 1) { /* Commas used instead of spaces */
- int i;
- char *p = bp[0]; /* Reuse this space */
- *p = NUL; /* Make into dodo() arg list */
- for (i = 1; i < argn; i++) {
- strncat(p,bp[i],MAXARGLEN);
- strncat(p," ",MAXARGLEN);
- }
- s = bp[0]; /* Point to new list */
- }
- p = ""; /* Initialize return value */
- if (k >= 0) { /* If macro found in table */
- /* Go set it up (like DO cmd) */
- if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
- if (cmpush() > -1) { /* Push command parser state */
- extern int ifc;
- int ifcsav = ifc; /* Push IF condition on stack */
- k = parser(1); /* Call parser to execute the macro */
- cmpop(); /* Pop command parser */
- ifc = ifcsav; /* Restore IF condition */
- if (k == 0) { /* No errors, ignore action cmds. */
- p = mrval[maclvl+1]; /* If OK, set return value. */
- if (p == NULL) p = "";
- }
- } else { /* Can't push any more */
- debug(F100,"fexec pushed too deep","",0);
- printf("n?\fexec() too deeply nestedn");
- while (cmpop() > -1) ;
- p = "";
- }
- }
- }
- }
- goto fnend;
- #ifdef RECURSIVE
- case FN_RDIR: /* frdir..() - Recursive dir count */
- case FN_RFIL: /* frfiles() - Recursive file count */
- /* recursive = 2; */ /* fall thru... */
- #endif /* RECURSIVE */
- case FN_FC: /* ffiles() - File count. */
- case FN_DIR: { /* ffdir.() - Directory count. */
- char abuf[16], *s;
- char ** ap = NULL;
- int x, xflags = 0;
- if (matchdot)
- xflags |= ZX_MATCHDOT;
- if (y == FN_RDIR || y == FN_RFIL)
- xflags |= ZX_RECURSE;
- failed = 0;
- if (argn < 1) {
- p = "0";
- goto fnend;
- }
- if (y == FN_DIR || y == FN_RDIR) { /* Only list directories */
- xflags |= ZX_DIRONLY;
- #ifdef OS2
- zxpn = 1; /* Use the alternate list */
- #endif /* OS2 */
- } else { /* List only files */
- xflags |= ZX_FILONLY;
- #ifdef OS2
- zxpn = 1; /* Use the alternate list */
- #endif /* OS2 */
- }
- if (*(bp[0])) {
- k = nzxpand(bp[0],xflags);
- if (k < 0) k = 0;
- sprintf(fnval,"%d",k);
- p = fnval;
- } else
- p = "0";
- if (argn > 1) { /* Assign list to array */
- fnval[0] = NUL; /* Initial return value */
- ckstrncpy(abuf,bp[1],16); /* Get array reference */
- s = abuf;
- if (*s == CMDQ) s++;
- failed = 1; /* Assume it's bad */
- p = fnval; /* Point to result */
- if (fndiags) /* Default is this error message */
- sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\f%s()>",fn);
- if (s[0] != '&') /* "Address" of array */
- goto fnend;
- if (s[2])
- if (s[2] != '[' || s[3] != ']')
- goto fnend;
- if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
- s[1] += 32;
- if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
- goto fnend;
- failed = 0; /* Unset failure flag */
- ap = a_ptr[x]; /* Point to array we just declared */
- sprintf(fnval,"%d",k);
- }
- #ifdef OS2
- if (ap) { /* We are making an array */
- int i;
- char tmp[16];
- ap[0] = NULL; /* Containing number of files */
- makestr(&(ap[0]),ckitoa(k));
- ckstrncpy(tmp,fnval,16); /* Save return value */
- for (i = 1; i <= k; i++) { /* Fill it */
- ap[i] = NULL;
- znext(fnval); /* Next filename */
- if (!*fnval) /* No more, done */
- break; /* In case a premature end */
- makestr(&(ap[i]),fnval);
- }
- #ifdef ZXREWIND
- k = zxrewind(); /* Reset the file expansion */
- #else
- k = nzxpand(bp[0],xflags);
- #endif /* ZXREWIND */
- ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
- }
- #else /* OS2 */
- { /* Make copies of the list */
- int i; char tmp[16];
- if (flist) { /* Free old file list, if any */
- for (i = 0; flist[i]; i++) { /* and each string */
- free(flist[i]);
- flist[i] = NULL;
- }
- free(flist);
- }
- ckstrncpy(tmp,fnval,16); /* Save our return value */
- flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
- if (flist) {
- for (i = 0; i <= k; i++) { /* Fill it */
- flist[i] = NULL;
- znext(fnval); /* Next filename */
- if (!*fnval) /* No more, done */
- break;
- makestr(&(flist[i]),fnval);
- }
- if (ap) { /* If array pointer given */
- ap[0] = NULL;
- makestr(&(ap[0]),ckitoa(k));
- for (i = 0; i < k; i++) { /* Copy file list to array */
- ap[i+1] = NULL;
- makestr(&(ap[i+1]),flist[i]);
- }
- }
- }
- ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
- flistn = 0; /* Reset global list pointer */
- }
- #endif /* OS2 */
- #ifdef RECURSIVE
- recursive = rsave;
- #endif /* RECURSIVE */
- #ifdef OS2
- zxpn = zsave;
- #endif /* OS2 */
- }
- goto fnend;
- case FN_FIL: /* fnextfile() - Next file in list. */
- p = fnval; /* (no args) */
- *p = NUL;
- #ifdef OS2
- zxpn = 1; /* OS/2 - use the alternate list */
- znext(p); /* Call system-dependent function */
- zxpn = zsave; /* Restore original list */
- #else
- if (flist) /* Others, use our own list. */
- if (flist[flistn])
- p = flist[flistn++];
- #endif /* OS2 */
- goto fnend;
- } /* Break up big switch... */
- switch (y) {
- case FN_IND: /* findex(s1,s2,start) */
- case FN_RIX: /* frindex(s1,s2,start) */
- case FN_SEARCH: /* fsearch(pat,string,start) */
- case FN_RSEARCH: { /* frsearch(pat,string,start) */
- int i = 0, right = 0, search = 0;
- right = (y == FN_RIX || y == FN_RSEARCH);
- search = (y == FN_SEARCH || y == FN_RSEARCH);
- p = "0";
- if (argn > 1) { /* Only works if we have 2 or 3 args */
- int start = 0;
- int mflag = 0;
- char * pat = NULL;
- len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
- len2 = (int)strlen(s = bp[1]); /* length of string to look in */
- if (search) { /* If pattern */
- if (len1 == 0) /* append "*" if not already there.. */
- mflag++;
- else if (pat[len1-1] != '*')
- mflag++;
- if (mflag) {
- char * tmp;
- tmp = malloc(len1+2);
- if (tmp) {
- sprintf(tmp,"%s*",pat);
- pat = tmp;
- } else
- mflag = 0;
- }
- len1++;
- }
- if (len1 < 1 || len2 < 1) /* Watch out for empty strings */
- goto fnend;
- start = right ? -1 : 0; /* Default starting position */
- if (argn > 2) {
- val1 = *(bp[2]) ? evalx(bp[2]) : "1";
- if (chknum(val1)) {
- int t;
- t = atoi(val1);
- if (!search) { /* Index or Rindex */
- j = len2 - len1; /* Length difference */
- t--; /* Convert position to 0-based */
- if (t < 0) t = 0;
- start = t;
- if (!right && start < 0) start = 0;
- } else { /* Search or Rsearch */
- int x;
- if (t < 0) t = 0;
- if (right) { /* Right to left */
- if (t > len2) t = len2;
- start = len2 - t - 1;
- if (start < 0) {
- if (mflag) if (pat) free(pat);
- goto fnend;
- }
- x = len2 - t;
- s[x] = NUL;
- } else { /* Left to right */
- start = t - 1;
- if (start < 0) start = 0;
- if (start >= len2) {
- if (mflag) if (pat) free(pat);
- goto fnend;
- }
- }
- }
- } else {
- failed = 1;
- if (fndiags) {
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- p = fnval;
- }
- if (mflag) if (pat) free(pat);
- goto fnend;
- }
- }
- if (search) { /* fsearch() or frsearch() */
- if (right) {
- if (start < 0) start = len2 - 1;
- for (i = start;
- i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1);
- i--) ;
- if (i < 0) i = 0; else i++;
- } else {
- for (i = start;
- i < len2 && !ckmatch(pat,s+i,inpcas[cmdlvl],1);
- i++) ;
- if (i == len2) i = 0; else i++;
- }
- } else {
- i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
- }
- if (mflag) if (pat) free(pat);
- sprintf(fnval,"%d",i);
- p = fnval;
- }
- goto fnend;
- }
- case FN_RPL: /* freplace(s1,s2,s3) */
- /*
- s = bp[0] = source string
- bp[1] = match string
- bp[2] = replacement string
- p = fnval = destination (result) string
- */
- if (argn < 1) /* Nothing */
- goto fnend;
- if (argn < 2) { /* Only works if we have 2 or 3 args */
- ckstrncpy(p,bp[0],FNVALL);
- } else {
- len1 = (int)strlen(bp[0]); /* length of string to look in */
- len2 = (int)strlen(bp[1]); /* length of string to look for */
- len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
- j = len1 - len2 + 1;
- if (j < 1 || len1 == 0 || len2 == 0) { /* Args out of whack */
- ckstrncpy(p,bp[0],FNVALL); /* so just return original string */
- p[FNVALL] = NUL;
- } else {
- s = bp[0]; /* Point to beginning of string */
- while (j--) { /* For each character */
- if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl])) {
- if (len3) {
- strcpy(p,bp[2]);
- p += len3;
- }
- s += len2; /* and skip past it. */
- } else { /* No, */
- *p++ = *s++; /* just copy this character */
- }
- }
- *p = NUL;
- while (*p++ = *s++);
- }
- }
- p = fnval;
- goto fnend;
- case FN_CHR: /* fcharacter(arg1) */
- val1 = *(bp[0]) ? evalx(bp[0]) : "";
- if (chknum(val1)) { /* Must be numeric */
- i = atoi(val1);
- if (i >= 0 && i < 256) { /* Must be an 8-bit value */
- p = fnval;
- *p++ = (char) i;
- *p = NUL;
- p = fnval;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_OUT_OF_RANGE:\f%s()>",fn);
- }
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- }
- goto fnend;
- case FN_COD: /* fcode(char) */
- if ((int)strlen(bp[0]) > 0) {
- p = fnval;
- i = *bp[0];
- sprintf(p,"%d",(i & 0xff));
- } else p = ""; /* Can't happen */
- goto fnend;
- case FN_LEN: /* flength(arg1) */
- if (argn > 0) {
- p = fnval;
- sprintf(p,"%d",(int)strlen(bp[0]));
- } else p = "0";
- goto fnend;
- case FN_LOW: /* flower(arg1) */
- s = bp[0] ? bp[0] : "";
- p = fnval;
- while (*s) {
- if (isupper(*s))
- *p = (char) tolower(*s);
- else
- *p = *s;
- p++; s++;
- }
- *p = NUL;
- p = fnval;
- goto fnend;
- case FN_MAX: /* fmax(arg1,arg2) */
- case FN_MIN: /* fmin(arg1,arg2) */
- case FN_MOD: /* fmod(arg1,arg2) */
- val1 = *(bp[0]) ? evalx(bp[0]) : "";
- free(bp[0]); /* Copy this because evalx() returns */
- bp[0] = NULL; /* Set it to NULL in case argn == 1 */
- if (argn > 1) { /* pointer to same */
- bp[0] = malloc((int)strlen(val1)+1); /* buffer next time. */
- strcpy(bp[0],val1);
- val1 = bp[0];
- val2 = *(bp[1]) ? evalx(bp[1]) : "";
- if (chknum(val1) && chknum(val2)) {
- i = atoi(val1);
- j = atoi(val2);
- switch (y) {
- case FN_MAX:
- if (j < i) j = i;
- break;
- case FN_MIN:
- if (j > i) j = i;
- break;
- case FN_MOD:
- if (j == 0) {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:DIVIDE_BY_ZERO:\f%s()>",fn);
- else
- fnval[0] = NUL;
- goto fnend;
- } else
- j = i % j;
- }
- p = fnval;
- sprintf(p,"%d",j);
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- }
- } else p = val1;
- goto fnend;
- } /* Break up big switch... */
- switch (y) {
- case FN_SUB: /* fsubstr(arg1,arg2,arg3) */
- case FN_RIG: /* fright(arg1,arg2) */
- case FN_LEF: /* fleft(arg1,arg2) */
- if (argn < 1)
- goto fnend;
- val1 = "";
- if (argn > 1)
- if (*(bp[1]))
- val1 = evalx(bp[1]);
- if (bp[1]) free(bp[1]); /* Have to copy this */
- bp[1] = malloc((int)strlen(val1)+1);
- if (!bp[1]) {
- failed = 1;
- if (fndiags)
- sprintf((p = fnval),"<ERROR:MALLOC:\f%s()>",fn);
- goto fnend;
- }
- strcpy(bp[1],val1);
- val1 = bp[1];
- val2 = "";
- if (argn > 2)
- if (*(bp[2]))
- val2 = evalx(bp[2]);
- if (
- ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
- ((y == FN_SUB) &&
- ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
- ) {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- } else {
- int lx;
- p = fnval; /* pointer to result */
- lx = strlen(bp[0]); /* length of arg1 */
- if (y == FN_SUB) { /* substring */
- k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
- j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
- } else if (y == FN_LEF) { /* left */
- k = (argn > 1) ? atoi(val1) : lx;
- j = 1;
- } else { /* right */
- k = (argn > 1) ? atoi(val1) : lx; /* length */
- j = lx - k + 1; /* start pos for right */
- if (j < 1) j = 1;
- }
- if (k > 0 && j <= lx) { /* if start pos in range */
- s = bp[0]+j-1; /* point to source string */
- for (i = 0; (i < k) && (*p++ = *s++); i++) ; /* copy */
- }
- *p = NUL; /* terminate the result */
- p = fnval; /* and point to it. */
- }
- goto fnend;
- case FN_UPP: /* fupper(arg1) */
- s = bp[0] ? bp[0] : "";
- p = fnval;
- while (*s) {
- if (islower(*s))
- *p = (char) toupper(*s);
- else
- *p = *s;
- p++; s++;
- }
- *p = NUL;
- p = fnval;
- goto fnend;
- case FN_REP: /* frepeat(text,number) */
- if (argn < 1)
- goto fnend;
- val1 = "1";
- if (argn > 1)
- if (*(bp[1]))
- val1 = evalx(bp[1]);
- if (chknum(val1)) { /* Repeat count */
- n = atoi(val1);
- debug(F111,"SUNDAY frepeat n",val1,n);
- if (n > 0) { /* Make n copies */
- p = fnval;
- *p = ' ';
- k = (int)strlen(bp[0]); /* Make sure string has some length */
- debug(F111,"SUNDAY frepeat k","",k);
- debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
- if (k * n >= FNVALL) { /* But not too much... */
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:RESULT_TOO_LONG:\f%s()>",fn);
- else
- fnval[0] = NUL;
- p = fnval;
- goto fnend;
- }
- if (k > 0) { /* If there is something to copy */
- for (i = 0; i < n; i++) { /* Copy loop */
- s = bp[0];
- for (j = 0; j < k; j++) {
- if ((p - fnval) >= FNVALL)
- break; /* shouldn't happen... */
- else
- *p++ = *s++;
- }
- }
- *p = NUL;
- }
- }
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- }
- p = fnval;
- goto fnend;
- #ifndef NOFRILLS
- case FN_REV: /* freverse() */
- if (argn < 1)
- goto fnend;
- yystring(bp[0],&p);
- goto fnend;
- #endif /* NOFRILLS */
- case FN_RPA: /* frpad() and flpad() */
- case FN_LPA:
- if (argn < 1)
- goto fnend;
- val1 = "";
- if (argn > 1)
- if (*(bp[1]))
- val1 = evalx(bp[1]);
- if (argn == 1 || !*val1) { /* If a number wasn't given */
- p = fnval; /* just return the original string */
- ckstrncpy(p,bp[0],FNVALL);
- } else if (chknum(val1)) { /* Repeat count */
- char pc;
- n = atoi(val1);
- if (n >= 0) {
- p = fnval;
- k = (int)strlen(bp[0]); /* Length of string to be padded */
- if (k >= n) { /* It's already long enough */
- ckstrncpy(p,bp[0],FNVALL);
- } else {
- if (n + k <= FNVALL) {
- pc = (char) ((argn < 3) ? SP : *bp[2]);
- if (!pc) pc = SP;
- if (y == FN_RPA) { /* RPAD */
- strncpy(p,bp[0],k); /* (leave it like this) */
- p[k] = NUL;
- p += k;
- for (i = k; i < n; i++)
- *p++ = pc;
- } else { /* LPAD */
- n -= k;
- for (i = 0; i < n; i++)
- *p++ = pc;
- strncpy(p,bp[0],k); /* (leave it like this) */
- p[k] = NUL;
- p += k;
- }
- }
- *p = NUL;
- }
- }
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- }
- p = fnval;
- goto fnend;
- #ifdef ZFCDAT
- case FN_FD: /* fdate(filename) */
- p = fnval;
- s = zfcdat(bp[0]);
- if (!s) s = "";
- if (!*s) {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:FILE_NOT_FOUND:\f%s()>",fn);
- goto fnend;
- }
- ckstrncpy(fnval,s,FNVALL);
- #endif /* ZFCDAT */
- goto fnend;
- } /* Break up big switch... */
- switch (y) {
- case FN_FS: /* fsize(filename) */
- p = fnval;
- z = zchki(bp[0]);
- if (z < 0) {
- failed = 1;
- if (fndiags) {
- if (z == -1)
- sprintf(fnval,"<ERROR:FILE_NOT_FOUND:\f%s()>",fn);
- else if (z == -2)
- sprintf(fnval,"<ERROR:FILE_NOT_READABLE:\f%s()>",fn);
- else if (z == -3)
- sprintf(fnval,"<ERROR:FILE_NOT_ACCESSIBLE:\f%s()>",fn);
- else
- sprintf(fnval,"<ERROR:FILE_ERROR:\f%s()>",fn);
- }
- goto fnend;
- }
- sprintf(fnval,"%ld",z);
- goto fnend;
- case FN_VER: /* fverify() */
- p = "0";
- if (argn > 1) { /* Only works if we have 2 or 3 args */
- int start;
- char *s2, ch1, ch2;
- start = 0;
- if (argn > 2) { /* Starting position specified */
- val1 = *(bp[2]) ? evalx(bp[2]) : "0";
- if (chknum(val1)) {
- start = atoi(val1) /* - 1 */;
- if (start < 0) start = 0;
- if (start > (int)strlen(bp[1]))
- goto verfin;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- i = start;
- p = "0";
- for (s = bp[1] + start; *s; s++,i++) {
- ch1 = *s;
- if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
- j = 0;
- for (s2 = bp[0]; *s2; s2++) {
- ch2 = *s2;
- if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
- if (ch1 == ch2) {
- j = 1;
- break;
- }
- }
- if (j == 0) {
- sprintf(fnval,"%d",i+1);
- p = fnval;
- break;
- }
- }
- }
- verfin:
- goto fnend;
- case FN_IPA: /* Find and return IP address */
- if (argn > 0) { /* in argument string. */
- int start;
- char *s2;
- start = 0;
- if (argn > 1) { /* Starting position specified */
- if (chknum(bp[1])) {
- start = atoi(bp[1]) - 1;
- if (start < 0) start = 0;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- p = getip(bp[0]+start);
- } else p = "";
- goto fnend;
- #ifdef OS2
- case FN_CRY:
- p = "";
- if (argn > 0) {
- p = fnval;
- ckstrncpy(p,bp[0],FNVALL);
- ck_encrypt(p);
- }
- goto fnend;
- case FN_OOX:
- p = "";
- if (argn > 0)
- p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
- goto fnend;
- #endif /* OS2 */
- case FN_HEX: /* fhexify(arg1) */
- if (argn < 1)
- goto fnend;
- if ((int)strlen(bp[0]) < (FNVALL / 2)) {
- s = bp[0];
- p = fnval;
- while (*s) {
- x = (*s >> 4) & 0x0f;
- *p++ = hexdigits[x];
- x = *s++ & 0x0f;
- *p++ = hexdigits[x];
- }
- *p = NUL;
- p = fnval;
- }
- goto fnend;
- case FN_UNH: { /* funhex(arg1) */
- int c[2], i;
- if (argn < 1)
- goto fnend;
- if ((int)strlen(bp[0]) < (FNVALL * 2)) {
- s = bp[0];
- p = fnval;
- while (*s) {
- for (i = 0; i < 2; i++) {
- c[i] = *s++;
- if (!c[i]) { p = ""; goto unhexfin; }
- if (islower(c[i])) c[i] = toupper(c[i]);
- if (c[i] >= '0' && c[i] <= '9') {
- c[i] -= 0x30;
- } else if (c[i] >= 'A' && c[i] <= 'F') {
- c[i] -= 0x37;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,
- "<ERROR:ARG_OUT_OF_RANGE:\f%s()>",
- fn
- );
- goto fnend;
- }
- }
- *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
- }
- *p = NUL;
- p = fnval;
- }
- unhexfin:
- goto fnend;
- }
- case FN_BRK: { /* fbreak() */
- char * c; /* Characters to break on */
- char c2, s2;
- int start = 0;
- int done = 0;
- if (argn < 1)
- goto fnend;
- if (argn > 2) {
- s = bp[2] ? bp[2] : "0";
- if (chknum(s)) {
- start = atoi(s);
- if (start < 0) start = 0;
- if (start > (int)strlen(bp[0]))
- goto brkfin;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- s = bp[0] + start; /* Source pointer */
- while (*s && !done) {
- s2 = *s;
- if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
- c = bp[1] ? bp[1] : ""; /* Character to break on */
- while (*c) {
- c2 = *c;
- if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
- if (c2 == s2) {
- done = 1;
- break;
- }
- c++;
- }
- if (done) break;
- *p++ = *s++;
- }
- *p = NUL; /* terminate the result */
- p = fnval; /* and point to it. */
- brkfin:
- goto fnend;
- }
- case FN_SPN: { /* fspan() */
- char *q;
- char c1, c2;
- int start = 0;
- if (argn < 1)
- goto fnend;
- if (argn > 2) { /* Starting position */
- s = bp[2] ? bp[2] : "0";
- if (chknum(s)) {
- start = atoi(s);
- if (start < 0) start = 0;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- s = bp[0] + start; /* Source pointer */
- if (argn > 1 &&
- (int)strlen(bp[1]) > 0 &&
- start <= (int)strlen(bp[0])) {
- while (*s) { /* Loop thru source string */
- q = bp[1]; /* Span string */
- c1 = *s;
- if (!inpcas[cmdlvl])
- if (islower(c1)) c1 = toupper(c1);
- x = 0;
- while (c2 = *q++) {
- if (!inpcas[cmdlvl])
- if (islower(c2)) c2 = toupper(c2);
- if (c1 == c2) { x = 1; break; }
- }
- if (!x) break;
- *p++ = *s++;
- }
- *p = NUL; /* Terminate and return the result */
- p = fnval;
- }
- goto fnend;
- }
- } /* Break up big switch... */
- switch (y) {
- case FN_TRM: /* ftrim(s1[,s2]) */
- case FN_LTR: /* fltrim(s1[,s2]) */
- if (argn < 1)
- goto fnend;
- if ((len1 = (int)strlen(bp[0])) > 0) {
- if (len1 > FNVALL)
- len1 = FNVALL;
- s = " t";
- if (argn > 1) /* Trim list given */
- s = bp[1];
- len2 = (int)strlen(s);
- if (len2 < 1) { /* or not... */
- s = " t"; /* Default is to trim whitespace */
- len2 = 2;
- }
- if (y == FN_TRM) { /* Trim from right */
- char * q, p2, q2;
- ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
- p = fnval + len1 - 1; /* Point to last character */
- while (p >= (char *)fnval) { /* Go backwards */
- q = s; /* Point to trim list */
- p2 = *p;
- if (!inpcas[cmdlvl])
- if (islower(p2)) p2 = toupper(p2);
- while (*q) { /* Is this char in trim list? */
- q2 = *q;
- if (!inpcas[cmdlvl])
- if (islower(q2)) q2 = toupper(q2);
- if (p2 == q2) { /* Yes, null it out */
- *p = NUL;
- break;
- }
- q++;
- }
- if (!*q) /* Trim list exhausted */
- break; /* So we're done. */
- p--; /* Else keep trimming */
- }
- } else { /* Trim from left */
- char * q, p2, q2;
- p = bp[0]; /* Source */
- while (*p) {
- p2 = *p;
- if (!inpcas[cmdlvl])
- if (islower(p2)) p2 = toupper(p2);
- q = s;
- while (*q) { /* Is this char in trim list? */
- q2 = *q;
- if (!inpcas[cmdlvl])
- if (islower(q2)) q2 = toupper(q2);
- if (p2 == q2) { /* Yes, point past it */
- p++; /* and try next source character */
- break;
- }
- q++; /* No, try next trim character */
- }
- if (!*q) /* Trim list exhausted */
- break; /* So we're done. */
- }
- ckstrncpy(fnval,p,FNVALL);
- }
- p = fnval;
- } else p = "";
- goto fnend;
- case FN_CAP: /* fcapitalize(arg1) */
- if (argn < 1)
- goto fnend;
- s = bp[0];
- p = fnval;
- x = 0;
- while (c = *s++) {
- if (isalpha(c)) {
- if (x == 0) {
- x = 1;
- if (islower(c))
- c = toupper(c);
- } else if (isupper(c))
- c = tolower(c);
- }
- *p++ = c;
- }
- *p = NUL;
- p = fnval;
- goto fnend;
- #ifdef COMMENT
- case FN_TOD: /* Time of day to secs since midnite */
- sprintf(fnval,"%ld",tod2sec(bp[0]));
- goto fnend;
- #endif /* COMMENT */
- case FN_FFN: /* Full pathname of file */
- zfnqfp(bp[0],FNVALL,p);
- if (!p) p = "";
- goto fnend;
- case FN_CHK: { /* fchecksum() */
- long chk = 0;
- p = (argn > 0) ? bp[0] : "";
- while (*p) chk += *p++;
- sprintf(fnval,"%lu",chk);
- p = fnval;
- goto fnend;
- }
- #ifndef NOXFER
- case FN_CRC: /* fcrc16() */
- if (argn > 0)
- sprintf(fnval,"%u",chk3((CHAR *)bp[0],(int)strlen(bp[0])));
- else
- p = "0";
- goto fnend;
- #endif /* NOXFER */
- case FN_BSN: /* fbasename() */
- zstrip(bp[0],&p);
- goto fnend;
- #ifdef OS2
- case FN_SCRN_CX: /* fscrncurx() */
- p = fnval;
- sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x);
- goto fnend;
- case FN_SCRN_CY: /* fscrncury() */
- p = fnval;
- sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y);
- goto fnend;
- case FN_SCRN_STR: { /* fscrnstr() */
- videoline * line = NULL;
- viocell * cells = NULL;
- int row = 0, col = 0, len = 0;
- /* NOTE: On Unicode systems, the screen contents are stored in */
- /* in Unicode. Therefore, we should really be performing a */
- /* conversion to the local character set. */
- if (bp[0] == NULL || bp[0][0] == ' ') {
- row = 0;
- } else {
- if (chknum(bp[0])) {
- row = atoi(bp[0]);
- if (row < 0)
- row = 0;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- line = VscrnGetLineFromTop( VTERM, (USHORT) row );
- if (line != NULL) {
- if (bp[1] == NULL || bp[1][0] == ' ')
- col = 0;
- else {
- if (chknum(bp[0])) {
- col = atoi(bp[1]);
- if (col < 0 || col >= line->width)
- col = 0;
- } else {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- }
- if (bp[2] == NULL || bp[2][0] == ' ') {
- len = line->width - (col+1);
- } else {
- if (!chknum(bp[2])) {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:ARG_NOT_NUMERIC:\f%s()>",fn);
- goto fnend;
- }
- len = atoi(bp[2]);
- if (len < 0 || len > line->width)
- len = line->width;
- }
- cells = line->cells;
- for (i = 0; i < len; i++) {
- int pos = i + col;
- if (pos < line->width) {
- fnval[i] = (CHAR) (cells[pos].c & 0xFF);
- if (fnval[i] == 0)
- fnval[i] = SP;
- } else
- fnval[i] = SP;
- }
- fnval[i] = ' ';
- } else {
- fnval[0] = ' ';
- }
- p = fnval;
- goto fnend;
- }
- #endif /* OS2 */
- #ifndef NOPUSH
- case FN_RAW: /* frawcommand() */
- case FN_CMD: { /* fcommand() */
- int x, c, n = FNVALL;
- x = 0; /* Completion flag */
- /*
- ZIFILE can be safely used because we can't possibly be transferring a file
- while executing this function.
- */
- if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
- while (n-- > -1) { /* Read from it */
- if ((c = zminchar()) < 0) {
- x = 1; /* EOF - set completion flag */
- if (y == FN_CMD) { /* If not "rawcommand" */
- p--; /* remove trailing newlines */
- while (*p == CR || *p == LF)
- p--;
- p++;
- }
- *p = NUL; /* Terminate the string */
- break;
- } else /* Command still running */
- *p++ = c; /* Copy the bytes */
- }
- zclose(ZIFILE); /* Close the command */
- }
- /* Return null string if command's output was too long. */
- p = fnval;
- if (!x) {
- failed = 1;
- if (fndiags)
- sprintf(fnval,"<ERROR:RESULT_TOO_LONG:\f%s()>",fn);
- }
- goto fnend;
- }
- #endif /* NOPUSH */
- } /* Break up big switch... */
- switch (y) {
- case FN_STX: /* fstripx(string,c) */
- if (!(s = bp[0])) /* Make sure there is a string */
- goto fnend;
- c = '.'; /* Character to strip from */
- if (argn > 1) if (*bp[1]) c = *bp[1];