|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 5842 (0x16d2) Types: TextFile Names: »utilities.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit └─⟦639290824⟧ »EurOpenD3/misc/tn3270.4.1.1.tar.Z« └─⟦cd3e6b3a4⟧ └─⟦this⟧ »disttn3270/telnet/Source/utilities.c«
/* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint static char sccsid[] = "@(#)utilities.c 1.11 (Berkeley) 2/6/89"; #endif /* not lint */ #define TELOPTS #include <arpa/telnet.h> #include <sys/types.h> #include <ctype.h> #include "general.h" #include "fdset.h" #include "ring.h" #include "defines.h" #include "externs.h" FILE *NetTrace = 0; /* Not in bss, since needs to stay */ /* * upcase() * * Upcase (in place) the argument. */ void upcase(argument) register char *argument; { register int c; while ((c = *argument) != 0) { if (islower(c)) { *argument = toupper(c); } argument++; } } /* * SetSockOpt() * * Compensate for differences in 4.2 and 4.3 systems. */ int SetSockOpt(fd, level, option, yesno) int fd, level, option, yesno; { #ifndef NOT43 return setsockopt(fd, level, option, (char *)&yesno, sizeof yesno); #else /* NOT43 */ if (yesno == 0) { /* Can't do that in 4.2! */ fprintf(stderr, "Error: attempt to turn off an option 0x%x.\n", option); return -1; } return setsockopt(fd, level, option, 0, 0); #endif /* NOT43 */ } \f /* * The following are routines used to print out debugging information. */ void Dump(direction, buffer, length) char direction; char *buffer; int length; { # define BYTES_PER_LINE 32 # define min(x,y) ((x<y)? x:y) char *pThis; int offset; offset = 0; while (length) { /* print one line */ fprintf(NetTrace, "%c 0x%x\t", direction, offset); pThis = buffer; buffer = buffer+min(length, BYTES_PER_LINE); while (pThis < buffer) { fprintf(NetTrace, "%.2x", (*pThis)&0xff); pThis++; } fprintf(NetTrace, "\n"); length -= BYTES_PER_LINE; offset += BYTES_PER_LINE; if (length < 0) { fflush(NetTrace); return; } /* find next unique line */ } fflush(NetTrace); } /*VARARGS*/ void printoption(direction, fmt, option, what) char *direction, *fmt; int option, what; { if (!showoptions) return; fprintf(NetTrace, "%s ", direction+1); if (fmt == doopt) fmt = "do"; else if (fmt == dont) fmt = "dont"; else if (fmt == will) fmt = "will"; else if (fmt == wont) fmt = "wont"; else fmt = "???"; if (option < (sizeof telopts/sizeof telopts[0])) fprintf(NetTrace, "%s %s", fmt, telopts[option]); else fprintf(NetTrace, "%s %d", fmt, option); if (*direction == '<') { fprintf(NetTrace, "\r\n"); return; } fprintf(NetTrace, " (%s)\r\n", what ? "reply" : "don't reply"); } void printsub(direction, pointer, length) char *direction, /* "<" or ">" */ *pointer; /* where suboption data sits */ int length; /* length of suboption data */ { if (showoptions) { fprintf(NetTrace, "%s suboption ", (direction[0] == '<')? "Received":"Sent"); switch (pointer[0]) { case TELOPT_TTYPE: fprintf(NetTrace, "Terminal type "); switch (pointer[1]) { case TELQUAL_IS: { char tmpbuf[SUBBUFSIZE]; int minlen = min(length, sizeof tmpbuf); memcpy(tmpbuf, pointer+2, minlen); tmpbuf[minlen-1] = 0; fprintf(NetTrace, "is %s.\n", tmpbuf); } break; case TELQUAL_SEND: fprintf(NetTrace, "- request to send.\n"); break; default: fprintf(NetTrace, "- unknown qualifier %d (0x%x).\n", pointer[1], pointer[1]); } break; default: fprintf(NetTrace, "Unknown option %d (0x%x)\n", pointer[0], pointer[0]); } } } /* EmptyTerminal - called to make sure that the terminal buffer is empty. * Note that we consider the buffer to run all the * way to the kernel (thus the select). */ void EmptyTerminal() { #if defined(unix) fd_set o; FD_ZERO(&o); #endif /* defined(unix) */ if (TTYBYTES() == 0) { #if defined(unix) FD_SET(tout, &o); (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0, (struct timeval *) 0); /* wait for TTLOWAT */ #endif /* defined(unix) */ } else { while (TTYBYTES()) { ttyflush(0); #if defined(unix) FD_SET(tout, &o); (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0, (struct timeval *) 0); /* wait for TTLOWAT */ #endif /* defined(unix) */ } } } void SetForExit() { setconnmode(); #if defined(TN3270) if (In3270) { Finish3270(); } #else /* defined(TN3270) */ do { telrcv(); /* Process any incoming data */ EmptyTerminal(); } while (ring_full_count(&netiring)); /* While there is any */ #endif /* defined(TN3270) */ setcommandmode(); fflush(stdout); fflush(stderr); #if defined(TN3270) if (In3270) { StopScreen(1); } #endif /* defined(TN3270) */ setconnmode(); EmptyTerminal(); /* Flush the path to the tty */ setcommandmode(); } void Exit(returnCode) int returnCode; { SetForExit(); exit(returnCode); } void ExitString(string, returnCode) char *string; int returnCode; { SetForExit(); fwrite(string, 1, strlen(string), stderr); exit(returnCode); } #if defined(MSDOS) void ExitPerror(string, returnCode) char *string; int returnCode; { SetForExit(); perror(string); exit(returnCode); } #endif /* defined(MSDOS) */