Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

v47i144: cbreak - Single character input package, v1.0, Part01/02

11 views
Skip to first unread message

Rudi Vankemmel

unread,
Apr 16, 1995, 3:00:00 AM4/16/95
to
Submitted-by: vank...@imec.be (Rudi Vankemmel)
Posting-number: Volume 47, Issue 144
Archive-name: cbreak/part01
Environment: UNIX, VMS
Supersedes: cbreak: Volume 46 Issue 13-14

This is Release V1.0 patchlevel 0 of my cbreak package doing unbuffered
character input on UNIX and VMS based systems. Compared to the previous
released version V0.3 the following main changes were done:

1) included patchlevel.h file
2) some minor bugs solved
3) ported to IBM AIX, i386/i486 Linux.
4) gcc support on Solaris 2.3 (Sun).
5) inclusion of modifications for SGI under IRIX.
4) better fallback my_gets() routine.

Generally porting to other BSD and SYSV based UNIX flavors which are
not yet supported in V1.0, should be quite easy as the package supports
termio, sgtty and POSIX style tcgetattr terminal settings.

Furthermore extensions for MAC (using THINK C), Sony, MIPS and Amiga DOS
systems are provided but still not tested.

If you enhance the code, I'll be happy to receive your modifications in
order to include them (if appropriate) in further releases.

The archive is also available by anonymous ftp to imec.be in the
directory /pub/asp/tcad/rvk/ . The following files are there:

cbreak.sh : the sh archive (+- 78k, ascii)
cbreak.TZ : tarcompressed archive (+- 35k, binary mode)
cbreak.tar.gz : gzip'ped and tar'ed archive (+- 20k, binary)

Rudi Vankemmel.
vank...@imec.be
----
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# Contents: README INSTALL my_getch.1 my_getch.c mystrings.c sysdefs.h
# Wrapped by kent@ftp on Sun Apr 16 18:23:27 1995
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:
echo ' "shar: End of archive 1 (of 2)."'
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2870 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X This is a sh-archive !
X
X Name: my_getch.sh
X Version: 1.0
X Author: R. Vankemmel (vank...@imec.be)
X
X This archive provides some routines for doing
X unbuffered character input on UNIX systems.
X It has been tested on BSD and SYSV based UNIX systems
X (see the INSTALL file). VAX-VMS systems use System Service
X routines for handling the input.
X Furthermore extensions towards THINK-C on MAC,
X and Amiga DOS systems are provided but still not fully
X tested.
X See the file INSTALL for the currently supported platforms.
X If you enhance the code, I'll be happy to receive your
X modifications in order to include them (if appropriate) in
X further releases.
X
X The following files are in the archive:
X
X README : this file
X HISTORY : history of the package
X COPYRIGHT : the copyright notice
X INSTALL : how to install and port this software
X make-extern : a make file to be configured (only one line)
X make.com : DCL script for building the code on VAX-VMS.
X my_getch.c : source of unbuffered input routine
X my_gets.c : source of a fallback routine
X mystrings.c: some needed fallback routines
X test.c : a small test program
X my_getch.1 : manual page for my_getch()
X my_gets.1 : manual page for my_gets()
X mystrings.1: manual page for some miscellaneous routines
X sysdefs.h : system dependent settings
X vms_getkey.h: definitions for vms systems.
X vms_getkey.c: source code for unbuffered input on VAX-VMS systems.
X
X
X The archive is available from comp.sources.misc mirror sites or
X directly from our anonymous ftp server :
X
X imec.be /pub/asp/tcad/rvk/
X
X Files (you need only ONE of them):
X cbreak.TZ tarcompressed file, binary mode ftp
X cbreak.tar.gz tar'ed and gzipped file, binary mode ftp
X cbreak.sh sh archive, ascii mode ftp.
X
X
X COPYRIGHT:
X
XCopyright 1993 by R. Vankemmel
X
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X
X1 : Both the above copyright notice and this permission notice
X appear in all copies of both the software and the supporting
X documentation.
X2 : You don't make a profit out of it.
X3 : You properly credit the author of this software when it is
X included in any other package.
X
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.
X
XCopyright 1992 by Anthony C. McCracken for the VMS getkey() routine.
X
X
END_OF_FILE
if test 2870 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'INSTALL' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'INSTALL'\"
else
echo shar: Extracting \"'INSTALL'\" \(5205 characters\)
sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
X
X file: INSTALL
X purpose: help the user installing these the following routines:
X my_getch(), my_raw(), my_gets() + some small
X routines in mystrings.c
X
X author: R. Vankemmel
X date 10-1-1994
X
X -----------------------------------------------------------------
X
X 1) General Notes:
X
X These routines have been tested and installed on the following
X platforms:
X Apollo DN4500 Domain OS SR10.3 (BSD)
X HP-Apollo 425 Domain OS SR10.3 (BSD)
X HP 9000 735 HP-UX V9.0 (SYSV)
X Convex C2 ConvexOs (BSD)
X SUN Sparc SunOs (BSD)
X SUN Sparc Solaris 2.3 (Solaris)
X DECstation 5000/120 RISC Ultrix 4.X (BSD)
X DECstation 3500 Alpha OSF V1.3 (OSF)
X DECstation Alpha OpenVMS 6.1 (VMS)
X VAX 8X00 // VAX 6X00 OpenVMS 5.5 (VMS)
X VAX 780 Ultrix 4.X (BSD)
X SGI Indigo IRIX 4.0.5F (SYSV - POSIX)
X i386/i486 PC Linux (BSD - POSIX)
X IBM RS6000 AIX 2.3 (SYSV)
X
X The routines were already adapted towards the following platforms
X but are still untested:
X
X AMIGA using sgtty lib
X MAC using THINK-C lib
X
X 2) Compile:
X
X 2.1) For the above platforms no problem should occur in compiling them as
X the system dependent settings are already done in the sysdefs.h header
X file.
X
X 2.2) Edit the makefile "make-extern":
X change the compiler entry CC towards your platform.
X Remember to ask for the ANSI C compiler. As long as vendors do not
X provide the ANSI-C compiler as the default compiler, you will need
X to edit the makefile as it mostly needs some extra machine dependent
X command line options for invoking the ANSI C compiler.
X
X Note: for the supported platforms so far, the needed flags are
X commented in the makefile.
X
X Note 2: on VAX-VMS systems use the make.com file.
X
X 3) Platform port:
X
X If you decide to port the code to a not-yet-supported platform, then
X do the following:
X
X 3.1) Look on your system for a ANSI C compiler and edit the makefile
X towards the necessary command line options.
X
X 3.2) Edit the sysdefs.h header file.
X In this file the systems dependent settings are done. The most
X important things to set are the following:
X
X 1) look up which flags are set by the C-preprocessor at compile time
X which you can use to select the code to be included.
X Write these flags down in the top part of the sysdefs.h file.
X See this file for the settings on the predefined platforms.
X This/These flags can be used latter for switching between
X different platforms automatically.
X
X 2) look if your system is SYSV or BSD based.
X Add the appropriate define's in the sysdefs.h file.
X
X 3) see if your system has termio (typically SYSV), sgtty (BSD)
X or any other terminal control capabilities.
X Set in sysdefs.h the appropriate flags like HAS_TERMIOS or
X HAS_SGTTY in order to check on the the source code to compile.
X
X 4) if your system has such terminal control capabilities
X and ioctl() calls, then work is done here and you can compile
X the code.
X
X 5) If your system does not have such terminal capabilities (e.g.
X VAX-VMS, MAC) then you must provide a workaround based on your
X knowledge of your system. As an example I provided a (SYSV-)
X curses based workaround for VAX-VMS systems having the
X VMS_POSIX shell
X and a workaround on MAC using THINK-C library functions.
X However, on VMS systems you can use also the System Service
X routines.
X
X If you find and provide such a workaround for any other platform,
X i'll be happy to get informed about it so that I can enhance
X the code.
X
X 6) In case you use this code and you port your code with this
X routine to a platform missing any terminal control (does there
X exist one ?), a fallback routine my_gets() is provided which
X gets called by my_getch() automatically after setting the
X proper definitions in sysdefs.h
X
X 4) Note:
X In case you modify/change/enhance the code, I will be happy to
X hear about them and insert them into the released code.
X
X 5) Copyright:
X
XCopyright 1993 by R. Vankemmel
X
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X
X1 : Both the above copyright notice and this permission notice
X appear in all copies of both the software and the supporting
X documentation.
X2 : You don't make a profit out of it.
X3 : You properly credit the author of this software when it is
X included in any other package.
X
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.
X
XCopyright 1992 by Anthony C. McCracken for the VMS getkey() routine.
X
END_OF_FILE
if test 5205 -ne `wc -c <'INSTALL'`; then
echo shar: \"'INSTALL'\" unpacked with wrong size!
fi
# end of 'INSTALL'
fi
if test -f 'my_getch.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'my_getch.1'\"
else
echo shar: Extracting \"'my_getch.1'\" \(10094 characters\)
sed "s/^X//" >'my_getch.1' <<'END_OF_FILE'
X.TH MY_GETCH TCAD
X.\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
X.\" other parms are allowed: see man(7), man(1)
X.SH NAME
Xmy_getch \- unbuffered character input routine
X.SH SYNOPSIS
X.sp 1
X.nf
X
X #include "sysdefs.h"
X
X int my_getch()
X
X void my_raw(int set)
X
X.fi
X.SH "DESCRIPTION"
X.in +3n
X.ti -3n
Xmy_getch():
XThis routine reads one character from the keyboard
Xwhile being in raw mode. This enables to read a char
Xwithout needing a CR/LF.
X
XCurrently tested and working platforms include:
X.nf
X Apollo DN4500 Domain OS SR10.3 (BSD)
X HP-Apollo 425 Domain OS SR10.3 (BSD)
X HP 9000 735 HP-UX V9.0 (SYSV)
X Convex C2 ConvexOs (BSD)
X SUN Sparc SunOs (BSD)
X SUN Sparc Solaris 2.3 (Solaris)
X DECstation 5000/120 RISC Ultrix 4.X (BSD)
X DECstation 3500 Alpha OSF V1.3 (OSF)
X DECstation Alpha OpenVMS V6.1 (VMS)
X VAX 8X00 // VAX 6X00 OpenVMS 5.5 (VMS)
X VAX 780 Ultrix 4.X (BSD)
X SGI Indigo IRIX 4.0.5F (SYSV - POSIX)
X i386/i486 PC Linux (BSD - POSIX)
X IBM RS6000 AIX 2.3 (SYSV)
X
X.fi
X
XAn important difference with other known routines is that on UNIX
Xplatforms,
Xthis version catches the interrupt, quit, keyboard stop, termination
Xand continuation signals to the process and resets the previous
Xtty settings before exiting or suspending the proces. This
Xprevents that the controlling terminal is left in a weird
Xstate (which gets solved mostly by killing the shell and do a new login).
XNote that some smart shells are doing this (tcsh, some csh) but
Xas a lot don't, this functionality has been provided in my_getch().
XWhen the user sends a continuation signal (SIGCONT) to the proces,
Xthe process environment as before the stop signal occured, is reloaded
Xagain. Hence the program continues in the same mode again and the
Xuser is warned about the fact that he had to enter something there.
XWhen the raw mode is left again, the signal functions as loaded
Xby default or by the user program are set again to their original
Xvalues, hence users setting their own signal handling do not loose
Xthese when calling the my_getch() routine.
X
XThis does not apply on VAX systems running VMS using the System Services
Xroutines. There the library routines take care of this.
X.sp 1
X.ti -3n
Xmy_raw():
XThis routine does the actual setting of the terminal in raw mode.
XThe routine is isolated from my_getch() as it contains typical
Xsystem dependent settings. It is called by the my_getch() routine
Xbut it may be used within other routines.
X
XPlacing the terminal in raw mode happens by using ioctl() call's on
XUNIX (BSD and SYSV) platforms. Modern UNIX systems have POSIX compliant
Xterminal setting routines. Systems not having ioctl() but with
Xa good curses library can use this option. On systems using
Xthe THINK\-C compiler the code can be used through the csetmode() call.
XVAX systems running VMS or OpenVMS can use the System Service routines
Xfor
Xhandling unbuffered input. A separate routine vms_getkey() is provided.
XIn case no raw mode is available, the my_getch() routine calls the
Xmy_gets() routine performing buffered input with EOF detection.
X
XActually the necessary setting are done in the \fIsysdefs.h\fR file.
X.in -3n
X.SH "\fINOTES\fR"
X.in +3n
X.sp 1
X.ti -3n
XThe my_getch() and my_raw() routines need the \fIsysdefs.h\fR header file.
XIn this file system dependent settings are done. For most predefined systems
Xno problems should occur in installing the routines. If you port it to
Xa not\-yet\-supported platform, look in this file for the typical settings.
XMost important is the difference between BSD and SYSV based systems which is
Xset by detecting flags set by the compiler and the do the appropriate
Xdefinitions. The following flags are important: BSD, UNIX, SYSV.
XVAX systems under VMS use the VMS flag.
XSettings and definitions for PC's (IBM AT comp.), MAC and AMIGA
Xmachines have been done but not yet tested. However, platforms
Xusing the THINK\-C compiler or who have a good curses library should not
Ximpose much difficulties in get this code working.
X
XI refer to the sysdefs.h file for these systems dependent settings.
X.sp 1
X.ti -3n
XI experimented first with raw modes (hence the name my_raw() !)
Xwhich are not doing
Xsignal processing. So, we must do it by ourself. However,
Xraw() has the disadvantage that it also stops any i/o processing
Xhence any data in the output buffer (e.g.
Xthe question to
Xanswer with y/n) is being flushed
Xto /dev/null !! Therefore
XI switched to cbreak modes with signal catching with signal().
Xfor doing a controlled exit from these modes.
XSee the restrictions on the SIGKILL and SIGSTOP signals.
X.in -3n
X.SH "OPTIONS \- RETURN VALUE"
X.sp 1
X.nf
Xvoid my_raw(int set)
X Input: set = TRUE (1) : set terminal into raw state;
X set = FALSE (0): reset terminal into no raw state;
X Output: none
X
Xint my_getch()
X Input: none
X Output: int value of input character or EOF on error or ^D.
X.fi
X.SH "\fIUSAGE\fR"
XThe my_getch() routine reads only one character from the input.
XError processing and information (the question) must be provided by the
Xapplication writer. The following is a small illustrative test program.
X.br
X.bp \" next page
X.nf
X
X/* ============================================================== */
X#include <stdio.h>
X#include <string.h>
X#include <stdlib.h>
X#include <time.h>
X#include <errno.h>
X
Xextern int my_getch();
X
X#ifndef TRUE
X# define TRUE (1)
X#endif
X#ifndef FALSE
X# define FALSE (0)
X#endif
X
X/* =============================================================== */
Xmain(int argc, char **argv)
X{
X int input; /* entered character */
X int answer=FALSE,leave_loop;
X
X do
X {
X printf(" Please enter something <y,n>: ");
X putchar(\'n\'); /* show the default option */
X fflush(stdout);
X input = my_getch(); /* <====== here's the call */
X printf("\\b%c\\n",input); /* flush entered character */
X putchar(\'\\n\');
X switch(input) /* check the entered character */
X { /* and perform something */
X case \'y\': /* depending on the answer */
X case \'Y\':
X answer = TRUE;
X leave_loop = TRUE;
X break;
X case \'n\':
X case \'N\':
X case \'\r\':
X case \'\n\':
X answer = FALSE;
X leave_loop = TRUE;
X break;
X default:
X leave_loop = FALSE;
X break;
X }
X }
X while (! leave_loop);
X
X if (answer)
X printf(" You said yes \\n");
X else
X printf(" You said no \\n");
X
X}
X/* =============================================================== */
X.fi
X.sp 1
XOf course you can write a new routine using the my_getch() but including
Xthe do\-while construct and parsing the question string as a variable.
X.SH RESTRICTIONS
XSo far, only the SIGINT, SIGQUIT, SIGTERM, SIGTSTP and SIGCONT are
Xcatched and handled in the routine. All other signals call the
Xsignal handler loaded at that time (which is the default signal handler
Xroutine or any other handler provided by the programmer before the
Xcall to my_getch()).
X
XThe SIGKILL signal (kill \-9 <pid>) cannot be caught, blocked or ignored
Xhence the state of the terminal after killing the process, being in cbreak
Xmode, depends
Xon the shell's behaviour.
Xtcsh does save the original terminal settings and after killing it
Xre\-installs them. Some csh's do, other and sh don't. Those who don't
Xsave the tty settings will leave the terminal in cbreak mode or any other
Xweird state.
XThe same is true for SIGSTOP (kill -17 <pid>) which cannot be caught,
Xblocked or ignored.
X
XThese signals are NOT cathed on VAX systems running under VMS or OpenVMS.
X
X.SH "ERRORS and BUGS"
XWell, I guess there are many as it was only tested extensively on
XBSD and SYSV UNIX systems. The code for other platforms was provided
Xbut not yet fully tested.
X.SH FILES
X.br
X.nf
X.\" set tabstop to longest possible filename, plus a wee bit
X.ta \w'/usr/lib/perl/getopts.pl 'u
X\fImy_getch.c\fR The source file
X\fImy_getch.l\fR The manual page source file
X\fImy_gets.c\fR my_getch() needs it when no raw modes are available
X\fImy_gets.l\fR The my_gets() manual page source file
X\fImystrings.c\fR Some support routines.
X\fIsysdefs.h\fR System dependent settings
X\fItest.c\fR A small test program
X\fIvms_getkey.h\fR Definitions for VMS unbuffered input.
X\fIvms_getkey.c\fR Source for subroutine on VMS systems.
X\fImakefile\fR makefile to be modified.
X\fImake.com\fR DCL compile script for VAX-VMS systems.
X.SH ENHANCEMENTS
XFeel free to enhance the code and send
Ximprovements back to me so that I can include them in further releases.
X.SH COPYRIGHT
X.sp 1
XCopyright 1993 by R. Vankemmel
X.sp 1
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X.in +4n
X.ti -4n
X1 : Both the above copyright notice and this permission notice
Xappear in all copies of both the software and the supporting
Xdocumentation.
X.ti -4n
X2 : You don't make a profit out of it.
X.ti -4n
X3 : You properly credit the author of this software when it is
Xincluded in any other package.
X.sp 1
X.in -4n
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.
X.SH AUTHOR
XRudi Vankemmel (september 1993) [vank...@imec.be]: wrote the cbreak
Xroutines for most UNIX platforms.
XAnthony C. McCracken (april 1992) : wrote the getkey() routine for VMS.
XHe did not provide a particular copyright notice on this part. R. Vankemmel
Xported the VMS routine to DEC Alpha (OpenVMS 6.1).
END_OF_FILE
if test 10094 -ne `wc -c <'my_getch.1'`; then
echo shar: \"'my_getch.1'\" unpacked with wrong size!
fi
# end of 'my_getch.1'
fi
if test -f 'my_getch.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'my_getch.c'\"
else
echo shar: Extracting \"'my_getch.c'\" \(15435 characters\)
sed "s/^X//" >'my_getch.c' <<'END_OF_FILE'
X/*
X * Copyright 1993,94,95 by R. Vankemmel
X *
X * Permission to use, copy, modify and distribute this software and the
X * supporting documentation without fee is hereby granted, provided that :
X *
X * 1 : Both the above copyright notice and this permission notice
X * appear in all copies of both the software and the supporting
X * documentation.
X * 2 : You don't make a profit out of it.
X * 3 : You properly credit the author of this software when it is
X * included in any other package.
X *
X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
X * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
X * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
X * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
X * THIS SOFTWARE.
X */
X/* =========================RCS info================================== */
X/* $Author: rvklib $ */
X/* $Revision: 1.0 $ */
X/* $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/my_getch.c,v $ */
X/* $Date: 95/04/11 15:54:16 $ */
X/* $State: Exp $ */
X/* $Locker: $ */
X/* =================================================================== */
X/*
X * file: my_getch.c
X *
X * routine: my_raw()
X * purpose: the routine raw() allows to put a terminal into a
X * raw state so that we are able to do unbuffered input from the keyboard.
X * Hence we can read one char without the trailing CR/LF.
X *
X * routine: my_getch()
X * purpose: this routine reads one character from the
X * keyboard while being in raw mode. This enables to read a char without
X * needing a CR/LF. The routine performs detection of control characters
X * (especially EOF, [^D]) and prevents stdin to be closed. The returned
X * status is the same as for getc(). In case no raw mode is available, the
X * character is read by using the my_gets() routine needing however a CR !
X *
X *
X * author: R. Vankemmel date : 8/7/93
X *
X * Note : I experimented first with raw() modes which are not doing signal
X * processing. So, we must do it by ourself. However, raw() has the
X * disadvantage that it also stops any i/o processing hence any data in the
X * output buffer (e.g. the question to answer with y/n) is being flushed to
X * /dev/null !! Therefore I switched to cbreak modes with signal catching
X * with signal(). for doing a controlled exit from this modes.
X *
X * modifications:
X * 1) Larry Weissman (lar...@nsr.bioeng.washington.edu) 14 Dec 94:
X * reported bug in my_gets() call in my_getch routine:
X * parse &begin instead of begin. Reported my_getc() working on
X * SGI Indigo (IRIX 4.0.5F).
X * 2) Peter Andersen (peter.a...@mjolner.dk) 4 Jan 95: reported
X * cbreak pack to work under Linux by just adding the appropriate
X * entries into sysdefs.h.
X * 3) R. Vankemmel: 31/3/1995 IBM/RS6000 - AIX 3.2 port.
X * 4) R. Vankemmel: 11/4/1995 better fallback behaviour under my_gets()
X * usage: default values can be used now too by simply pressing <CR>.
X *
X *
X * syntax:
X * void my_raw(int set)
X * Input: set = TRUE (1) : set terminal into raw state;
X * set = FALSE (0): reset terminal into no raw state;
X * Output: ----
X *
X * int my_getch()
X * Input: -----
X * Output: -) int value of input character.
X * -) EOF on ^D or error.
X *
X */
X/* ===================================================================== */
X#include <stdio.h> /* IO functions */
X#include <string.h> /* strlen functions*/
X#include <errno.h> /* file errors */
X#include <signal.h> /* emulate signals */
X#include <setjmp.h> /* apply a jump after suspends */
X#include "sysdefs.h" /* general library header */
X
X#ifdef HAS_POSIX /* try first the POSIX style (easy) */
X# include <termios.h>
X#elif defined(HAS_IOCTL)
X# define FD_IN 0 /* file descriptor of stdin (see stdio.h) */
X# ifdef HAS_SGTTY /* BSD systems, AMIGA, MINIX */
X# include <sgtty.h> /* general terminal interface */
X# elif defined(HAS_TERMIOS) /* SYSV (and some BSD) systems */
X# include <sys/termio.h> /* terminal interface */
X# else /* generate an error */
X# include "PROBLEM: no termios.h nor sgtty.h file ?????"
X# endif
X#elif defined(HAS_CURSES) /* uses curses lib */
X# include <curses.h>
X#elif THINK_C /* Think-C 4 or -5 on MAC */
X# include <console.h>
X#elif defined(HAS_SSR) /* VAX-VMS SSR library */
X# include "vms_getkey.h"
X#else /* no ioctl() or curses lib */
X# define USE_MY_GETS /* use my_gets for reading */
Xextern char *my_gets();
X#endif
X
X/* this might be defined already */
X#ifndef TRUE
X#define TRUE (1)
X#endif
X#ifndef FALSE
X#define FALSE (0)
X#endif
X
X/* =================================================================== */
X#if !(defined(USE_MY_GETS) || defined(HAS_SSR))
X/* compile only when ioctl / curses available */
Xvoid set_signals();
Xvoid reset_signals();
Xvoid signal_handler();
X
Xstatic int is_in_noraw = TRUE; /* assumption at first call !!! */
Xjmp_buf return_env; /* jump environment for signals */
X
X/* ANSI C , CONVEX C-source or DEC ucode C compiler are more or less ANSI */
X#if(defined(__STDC__)||defined(CONVEX)||defined(DECRISC)||defined(DECALPHA)||defined(IBM6000))
X# define _ASSUME_STDC_
X#endif
X
X/* keep previous signals if called from */
X/* a program with other signal settings */
X/* Note: ANSI C (strict) does not allow for typedef signaltyp void
X * hence you cannot us signaltyp here. */
X#ifdef _ASSUME_STDC_
X void (*Intr) (), (*Quit) (), (*Term) (), (*Tstp) (), (*Cont) ();
X#else
X int (*Intr) (), (*Quit) (), (*Term) (), (*Tstp) (), (*Cont) ();
X#endif
X
X
X#ifdef HAS_POSIX
Xstruct termios old_term, new_term; /* struct's must be global: */
X#elif defined(HAS_IOCTL)
X# ifdef HAS_TERMIOS
Xstruct termio old_term, new_term; /* struct's must be global: */
X# elif defined(HAS_SGTTY) /* we must be able to pick up */
Xstruct sgttyb old_term, new_term; /* the settings after signal- */
X# ifdef CONVEX /* convex defines them as */
X# undef TCGETA /* TIOCGETA and TIOCSETAW */
X# undef TCSETAW /* therefore undef needed !!! */
X# endif
X# ifdef DECRISC /* DEC Risc ucode C comp. set both */
X# undef TCGETA /* SYSV and BSD definitions in ioctl.h */
X# undef TCSETAW /* so undef them too. */
X# endif
X# define TCGETA TIOCGETP /* handling (scope of struct's) */
X# define TCSETAW TIOCSETP /* define TC* to be BSD functions */
X# endif
X#endif
X
Xvoid
Xmy_raw(int set)
X{
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
X#ifdef HAS_POSIX /* try first with POSIX routines */
X if (set && is_in_noraw) {
X /* get the original settings and save them */
X tcgetattr(fileno(stdin), &old_term);
X new_term = old_term;
X
X /* change terminal settings */
X new_term.c_lflag &= ~(ICANON | ECHO); /* in raw mode */
X new_term.c_cc[VMIN] = '\01'; /* read one char a time */
X new_term.c_cc[VTIME] = '\00'; /* wait time for reading */
X
X /* set terminal in new state */
X tcsetattr(fileno(stdin), TCSANOW, &new_term);
X is_in_noraw = FALSE;
X } else if (!(set || is_in_noraw)) {
X /* restore old terminal setting again */
X tcsetattr(fileno(stdin), TCSANOW, &old_term);
X is_in_noraw = TRUE;
X }
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
X#elif defined(HAS_IOCTL)
X if (set && is_in_noraw) {
X /* get the original settings first, save */
X ioctl(FD_IN, TCGETA, &old_term); /* get old settings */
X ioctl(FD_IN, TCGETA, &new_term); /* again for changing */
X
X /* now change the new terminal settings */
X# ifdef HAS_SGTTY
X new_term.sg_flags &= ~(CRMOD | ECHO); /* switch of echo and */
X /* CR --> CR-LF mapping */
X new_term.sg_flags |= CBREAK; /* set in cbreak mode */
X# elif defined(HAS_TERMIOS)
X new_term.c_lflag &= ~(ICANON | ECHO); /* in raw mode */
X new_term.c_cc[VMIN] = '\01'; /* read one char a time */
X new_term.c_cc[VTIME] = '\00'; /* wait time for reading */
X# endif
X
X /* set the new terminal mode */
X ioctl(FD_IN, TCSETAW, &new_term);
X is_in_noraw = FALSE;
X } else if (!(set || is_in_noraw)) {
X /* restore old terminal setting again */
X ioctl(FD_IN, TCSETAW, &old_term);
X is_in_noraw = TRUE;
X }
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
X#elif defined(HAS_CURSES)
X if (set && is_in_noraw) {
X /* terminal to be putted in raw state */
X initscr(); /* curses needs this ; call's also
X * def_shell_mode() */
X savetty(); /* save current tty flags */
X cbreak();
X noecho();
X is_in_noraw = FALSE;
X } else if (!(set || is_in_noraw)) {
X /* terminal to be set in noraw state */
X nocbreak();
X echo();
X resetty(); /* restore old tty flags */
X#ifdef SYSV
X reset_shell_mode(); /* now here's a trick; endwin() does
X * a clear of the window which we
X * don't want therefore restore
X * shell mode terminal settings
X * without clearing. */
X#endif
X is_in_noraw = TRUE;
X }
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
X#elif defined(THINK_C) /* don't HAS_CURSES but has csetmode
X * (Think-C) */
X if (set && is_in_noraw) {
X csetmode(C_BREAK, stdin);
X is_in_noraw = FALSE;
X } else if (!(set || is_in_noraw)) {
X csetmode(C_ECHO, stdin);
X is_in_noraw = TRUE;
X }
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
X#endif /* HAS_IOCTL - THINK_C - HAS_CURSES */
X
X}
X#endif /* end if ! (USE_MY_GETS || HAS_SSR) */
X
X/* ================================================================ */
Xint
Xmy_getch()
X{
X /* read a char in raw mode */
X /* read one char from the screen, trap any eof entered ! */
X /* If the user enters EOF then reopen stdin */
X
X int input;
X
X#ifdef USE_MY_GETS /* no raw mode available */
X char buffer[256];
X char *bufptr;
X int begin;
X
X /* warn user about fallback routine: he must press
X * <CR> */
X printf("<CR>");
X bufptr = my_gets(buffer, &begin);
X if (bufptr != (char *) NULL) {
X /* take only one char */
X input = (int) buffer[begin];
X } else if (begin == -1)
X input = EOF;
X else
X input = (int) '\n'; /* on CR/LF */
X
X#elif defined(HAS_SSR) /* VAX_VMS SSR routines */
X char buffer[10];
X
X /* call the external routine form McCracken */
X input = (int) getkey();
X
X#else
X /* we have a raw mode available from ioctl() or curses */
X
X /* we cannot allow to exit while in raw mode: signal catching */
X set_signals();
X
X /* first get the char in the selected mode */
X if (setjmp(return_env)) {
X /* we return here after resuming a suspended session */
X printf("You had to enter something here: <y,n> ");
X fflush(stdout);
X my_raw(1);
X input = getchar();
X my_raw(0);
X } else {
X /* normal case */
X my_raw(1);
X input = getchar();
X my_raw(0);
X }
X
X /* reset signals */
X reset_signals();
X
X#endif
X
X#ifndef HAS_SSR /* System service routines do not know about stdin.. ; */
X /* it is sys level */
X
X /* NOTE !! : getc() return EOF (-1) on ^D */
X if (input == EOF) {
X /* 1) the user entered EOF (^D) in no_raw mode or */
X /* 2) an error on stdin occured */
X
X if (feof(stdin)) { /* reopen stdin on EOF input (stdin
X * closed) */
X freopen("/dev/tty", "r", stdin);
X } else if (ferror(stdin)) {
X clearerr(stdin);
X }
X }
X#endif
X
X return (input);
X}
X
X/* ================================================================ */
X#if !(defined(USE_MY_GETS) || defined(HAS_SSR))
X/* compile only when ioctl / curses available */
X
Xvoid
Xset_signals()
X{
X /* set local signal handler but keep previous settings */
X /* of the signal: important if called from another program */
X /* doing signal handling on its own */
X /* Note that a SIGKILL cannot be caught or blocked !!!! */
X /* Therefore terminal may be left into undefined state when */
X /* killing this proces, except when using csh who is */
X /* resetting the tty settings explicitely (tcsh) */
X /* Also SIGSTOP cannot be blocked so the same problem occurs */
X Intr = signal(SIGINT, signal_handler); /* ctrl-C */
X Quit = signal(SIGQUIT, signal_handler); /* ctrl-\ */
X Term = signal(SIGTERM, signal_handler); /* kill -15 */
X#ifdef SIGTSTP
X Tstp = signal(SIGTSTP, signal_handler); /* ctrl-Z, kill -18 */
X#endif
X#ifdef SIGCONT
X /*
X * now this is something special: if we load SIGCONT handling here
X * then it will be executed first when SIGTERM arives !!. In order to
X * circumvent this, I ignore the action here (set to default because
X * you can't ignore SIGCONT), keep the previous action and load
X * SIGCONT handling when a SIGTSTP arives.
X */
X Cont = signal(SIGCONT, SIG_DFL); /* fg after ^Z, kill -19 */
X#endif
X}
X
X/* ================================================================ */
Xvoid
Xsignal_handler(int sig)
X{
X int send_sig; /* signal to be sent */
X#ifdef _ASSUME_STDC_
X void (*Restore) (); /* default signals to be restored */
X#else
X int (*Restore) (); /* default signals to be restored */
X#endif
X
X switch (sig) {
X case SIGINT:
X case SIGQUIT:
X case SIGTERM:
X /* reset raw mode of terminal */
X my_raw(0);
X send_sig = SIGTERM; /* send a terminate signal */
X signal(sig, SIG_DFL); /* restore default setting */
X signal(send_sig, SIG_DFL); /* prevent again getting here */
X /* after sending send_sig ! */
X break;
X#ifdef SIGTSTP
X case SIGTSTP:
X /* reset raw mode of terminal */
X my_raw(0);
X send_sig = SIGSTOP; /* send a suspend signal */
X signal(sig, SIG_DFL); /* load default signal mode */
X /* now we will install the SIGCONT handler */
X signal(SIGCONT, signal_handler);
X
X break;
X#endif
X#ifdef SIGCONT
X case SIGCONT:
X /* this is resumed after a suspend: */
X printf(" Continuing ..... (my_raw.c)\n");
X fflush(stdout);
X signal(sig, signal_handler); /* keep same signal mode */
X longjmp(return_env, 1); /* return to question */
X break;
X#endif
X default:
X Restore = signal(sig, SIG_IGN);
X send_sig = sig;
X signal(sig, Restore); /* restore previous signal */
X /* note : restore with SIG_DFL could reset user */
X /* defined settings; therefore catch it in Restore() */
X break;
X }
X
X /* now generate the signals */
X#if (defined(sun) || defined(VMS)) /* no raise in lib on sun and VMS !! */
X kill(getpid(), send_sig); /* use UNIX sys library */
X#else
X raise(send_sig); /* this is ansi C */
X#endif
X
X#ifndef SIGCONT
X /* SIGCONT might not be defined: take
X * appropriate action when returning from kill() */
X /* if this is resumed after a suspend: */
X longjmp(return_env, 1);
X#endif
X
X}
X
X/* ================================================================= */
Xvoid
Xreset_signals()
X{
X /* now restore the old signals , previously was SIG_DFL */
X signal(SIGINT, Intr); /* ctrl-C */
X signal(SIGQUIT, Quit); /* ctrl-\ */
X signal(SIGTERM, Term); /* kill -15 */
X#ifdef SIGTSTP
X signal(SIGTSTP, Tstp); /* ctrl-Z */
X#endif
X#ifdef SIGCONT
X signal(SIGCONT, Cont); /* fg after ^Z */
X#endif
X}
X/* ================================================================= */
X#endif /* if ! (USE_MY_GETS || HAS_SSR) */
END_OF_FILE
if test 15435 -ne `wc -c <'my_getch.c'`; then
echo shar: \"'my_getch.c'\" unpacked with wrong size!
fi
# end of 'my_getch.c'
fi
if test -f 'mystrings.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mystrings.c'\"
else
echo shar: Extracting \"'mystrings.c'\" \(3443 characters\)
sed "s/^X//" >'mystrings.c' <<'END_OF_FILE'
X/*=========================RCS info==================================*/
X/* $Author: rvklib $ */
X/* $Revision: 1.0 $ */
X/* $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/mystrings.c,v $ */
X/* $Date: 95/04/11 15:54:18 $ */
X/* $State: Exp $ */
X/* $Locker: $ */
X/*===================================================================*/
X/* -------------------------------------------- */
X/* file: mystrings.c */
X/* purpose: some small, many needed strings */
X/* handling routines */
X/* author: R. Vankemmel */
X/* -------------------------------------------- */
X
X#include <string.h>
X#include <stdlib.h>
X#include <ctype.h>
X
X/* trim: remove trailing blanks, tabs, newlines */
X/* ref: K&R Ansi C p. 65 */
Xint trim(char s[])
X{
X int n;
X
X for (n=strlen(s)-1; n>=0; n--)
X if (s[n] != ' ' && s[n] != '\t' && s[n] != '\n')
X break;
X s[n+1] = '\0';
X return n;
X}
X
X/* skip: remove leading blanks, tabs */
X/* author: R. Vankemmel */
Xint skip(char s[])
X{
X int n;
X
X for (n=0; n < strlen(s); n++)
X if (s[n] != ' ' && s[n] != '\t') break;
X
X return n;
X}
X
X/* nextword: skip a text string up to the next word */
X/* author: R. Vankemmel */
Xint nextword(char s[])
X{
X int n;
X
X /* first skip non blank remaining chars */
X for (n=0; n<strlen(s); n++)
X if (isspace((int) s[n])) break;
X
X /* are we at end ? */
X if (n != (strlen(s)-1))
X {
X /* now skip extra blanks up to new word */
X n += skip(s+n);
X }
X
X return n;
X}
X
X/* reverse: reverse string s in place */
X/* ref: K&R p 62 (ANSI C sec. ed. */
Xvoid reverse(char s[])
X{
X int c,j,i;
X
X for (i=0, j=strlen(s)-1; i<j; i++, j--)
X c=s[i], s[i]=s[j], s[j]=c;
X}
X
X
X/* itoa: convert n to characters in s */
X/* ref: K&R p 64 (ANSI C, second ed.) */
Xvoid itoa(int n, char s[])
X{
X int i,sign;
X
X if ((sign = n) < 0) /* record sign */
X n = -n; /* make n positive */
X i = 0;
X do { /* generate digits in reverse order */
X s[i++] = n % 10 + '0'; /* get next digit */
X } while ((n /= 10) > 0); /* delete it */
X if (sign < 0)
X s[i++] = '-';
X s[i] = '\0';
X reverse(s);
X}
X
X/* matof: my atof() function ; same as atof() BUT
X * it converts also Fortran like numbers using D format as in
X * x.xxxxxD+yy or x.xxxxxd+yy which is not understood by scanf() or atof.
X * Also the E specifier can be
X * in lower or upper case.
X */
Xdouble matof(char *c)
X/* this routine converst a real number in string format into a double.
X * If the real numbers in the string are written as 0.xxxe+xx the you
X * can use simply atof(). However in PRISM the output format may be
X * 0.xxxd+xx which is not recognized in C. So, we must detect a d or
X * D and replace it by e or E. Note that the input string is NOT changed.
X *
X * author: R. Vankemmel 27/5/91 / based on a routine of Jan Ureel from the
X * PRISM postprocessor..
X * revision: RVK 23/8/1994: rewrote it.
X */
X{
X int j,index=0;
X char temp[128];
X
X for(j=skip(c); j < nextword(c) && j< strlen(c); j++) {
X if (isspace(c[j])) continue;
X else
X if ( isdigit(c[j]) || (c[j]=='.') || (c[j]=='-') ||
X (c[j]=='+') ) temp[index++]=c[j];
X else
X if ( (c[j]=='E') || (c[j]=='e') ||
X (c[j]=='D') || (c[j]=='d') )
X temp[index++]='e';
X }
X temp[index++] = '\0';
X return(atof(temp));
X}
X
END_OF_FILE
if test 3443 -ne `wc -c <'mystrings.c'`; then
echo shar: \"'mystrings.c'\" unpacked with wrong size!
fi
# end of 'mystrings.c'
fi
if test -f 'sysdefs.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sysdefs.h'\"
else
echo shar: Extracting \"'sysdefs.h'\" \(10817 characters\)
sed "s/^X//" >'sysdefs.h' <<'END_OF_FILE'
X/*
X * Copyright 1993,94,95 by R. Vankemmel
X *
X * Permission to use, copy, modify and distribute this software and the
X * supporting documentation without fee is hereby granted, provided that :
X *
X * 1 : Both the above copyright notice and this permission notice
X * appear in all copies of both the software and the supporting
X * documentation.
X * 2 : You don't make a profit out of it.
X * 3 : You properly credit the author of this software when it is
X * included in any other package.
X *
X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
X * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
X * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
X * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
X * THIS SOFTWARE.
X */
X/*=========================RCS info==================================*/
X/* $Author: rvklib $ */
X/* $Revision: 1.0 $ */
X/* $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/sysdefs.h,v $ */
X/* $Date: 95/04/11 15:54:55 $ */
X/* $State: Exp $ */
X/* $Locker: $ */
X/*===================================================================*/
X/*
X * file : sysdefs.h
X * purpose: header file in which typical machine dependent definitions
X * are done
X * author: R. Vankemmel (RVK) (vank...@imec.be)
X * date: 1/7/93
X * revisions:
X * 1) RVK: OSF 1.3 DEC Alpha support (14/9/1994)
X * 2) RVK: VMS 5.5 and OpenVMS 6.1 VAX / Dec Alpha support (8/11/1994)
X * 3) Larry Weissman (lar...@nsr.bioeng.washington.edu): reported
X * cbreak working on SGI Indigo (IRIX 4.0.5F). Provided SGI entry.
X * 4) Peter Andersen (peter.a...@mjolner.dk) jan 4 1995:
X * Linux port. Provided Linux entries.
X * Verified by RVK on our own Linux box now (april '95).
X * 5) RVK: port to IBM RS6000 / AIX 2.3 (4/2/1994).
X *
X */
X#ifndef SYSDEFS_H_SEEN
X#define SYSDEFS_H_SEEN
X
X/* list of predefined constants on the currently supported platforms */
X/*
X* APOLLO DNxx00 and HP4xx series:
X* apollo
X* aegis
X* unix
X* mc68000
X* MAC:
X* MC68000
X* mc68000
X* m68k
X* macintosh
X* mc68881 with the option -mc68881
X* applec on MPW-c: Apples own C
X* THINK_C for Think-C 4 or Think-C 5
X* HPUX: 1) in -Ac (Old K&R C) mode:
X* PWB
X* hpux and __hpux
X* unix and __unix
X* hp9000s200 on Series 200
X* hp9000s300 and __hp9000s300 on Series 300/400
X* hp9000s500 on Series 500
X* __hp9000s700 on Series 700
X* hp9000s800 , __hp9000s800 and __hppa on Series 800
X* 2) in -Aa mode (strict ANSI): all __* macros from above
X* (e.g. __hp9000s700, __hpux) plus the
X* ANSI-C def's as __STDC__.
X* 3) in -Ae mode (extended ANSI): as previous plus:
X* _HPUX_SOURCE
X* SUN3: SunOs
X* sun
X* mc68000
X* unix
X* SUN4: Sparc 2 or Sparc 10; SunOs 4.X
X* sun
X* sparc
X* unix
X* SUN5: Sparc 2 or Sparc 10; Solaris 2.3
X* sun sparc unix : not with -Xc mode
X* __sparc __unix __sun __BUILTIN_VA_ARG_INCR
X* __SUNPRO_C=0x300 __SVR4
X* The same but now using gcc:
X* __sparc, __svr4__, unix
X*
X* SONY:
X* sony
X* unix
X* IBMPC:
X* MSDOS on IBM compatibles under MS-DOS
X*
X* ultrix/DECstation: DECRisc
X* unix
X* ultrix
X* bsd4_2
X* mips : any RISC architecture
X* MIPSEL : little endian variant of MIPS architecture
X* host_mips : native compilation environment (as opposed to
X* cross- compiler)
X*
X*
X* ultrix/VAXstation:
X* VAX-Ultrix using VAX-C :
X* unix
X* ultrix
X* bsd4_2
X* vax, VAX, vaxc, VAXC, vax11c, VAX11C
X* VAX-Ultrix using gcc -ansi :
X* __unix__, __vax__
X* VAX-Ultrix using gcc :
X* unix, vax
X*
X* DEC Alpha OSF V1.3: using dec cc:
X* Flags always set independent of -std flag:
X* __LANGUAGE_C__
X* __unix__
X* __osf__
X* __alpha
X* _SYSTYPE_BSD
X*
X* VAX/VMS: VMS using VAX-C
X* vms
X* VMS
X* vax, VAX, vaxc, VAXC, vax11c, VAX11C
X*
X* IBM6000:
X* _IBMR2
X*
X* MIPS:
X* mips
X* mips_host
X* unix
X*
X* AMIGA PC:
X* AMIGA
X*
X* Convex:
X* __convex__ : in all compatibility modes.
X* convex : only in backward compatibility mode.
X* _CONVEX_SOURCE : only in extended mode.
X* __convexc__ : always defined.
X* __stdc__ : only in ANSI C mode.
X* __unix__ : in all compatibility modes.
X*
X*
X* i486 PC under Linux using gcc: see the linux.h file in ~gcc/config/
X* First reported by Peter Andersen (peter.a...@mjolner.dk).
X* unix : in all modes
X* BSD : yup , they say it is BSD !!
X* posix : they claim posix
X* _POSIX_SOURCE: in case posix is defined.
X* linux : OS system.
X* i386 , __i486__ : cpu type
X*
X* SGI Indigo (IRIX 4.0.5F); reported by Larry Weissman
X* sgi : even with -ansiposix flag
X*/
X/* --------------------------------------------------- */
X
X#ifdef apollo
X#define APOLLO /* system type = 2 */
X#define BSD
X#define UNIX
X
X#else /* else apollo */
X#if (defined(sun) || defined(__sun)) /* sun sparc machines SunOs 4.*
X * or Solaris 2.3 */
X#ifdef mc68000
X# define SUN3 /* system type = 8 */
X# define BSD
X# define UNIX
X#else /* else mc68000 */
X# if (defined(__sparc) && (defined(__SVR4)||defined(__svr4__)))
X /* sparc on Solaris */
X# define SUN5 /* system type = 15 */
X# define SYSV
X# define UNIX
X# else
X# ifdef sparc
X# define SUN4 /* system type = 1 */
X# define BSD
X# define UNIX
X# endif /* end sparc */
X# endif
X#endif /* end mc68000 */
X
X#else /* else sun's */
X#ifdef sony /* sony machine */
X#define SONY /* system type = 6 */
X#define BSD
X#define UNIX
X
X#else /* else sony */
X#if (defined(hpux) || defined(_HPUX_SOURCE))
X /* HP 9000/x00 machines */
X#define HPUX /* system type = 5 */
X#define SYSV
X#define UNIX
X#define POSIX
X
X#else /* else hpux */
X#ifdef _IBMR2 /* IBM Risc6000 machine under AIX */
X#define IBM6000 /* system type = 4 */
X#define SYSV
X#define UNIX
X
X#else /* else _ibmr2 */
X#if ( (defined(mips_host) || defined(mips) ) && ! defined(ultrix) )
X /* mips machine */
X#define MIPS /* system type = 7 */
X#define UNIX
X#ifdef SYSTYPE_BSD43
X#define BSD
X#else /* else SYSTYPE_BSD43 */
X#define SYSV
X#endif /* end if SYSTYPE_BSD43 */
X
X#else /* else mips_host */
X#ifdef MSDOS /* IBMPC under MSDOS */
X#define IBMPC /* system type = 12 */
X
X#else
X#if ( defined(ultrix) || (defined(__unix__) && defined(__vax__)) )
X# define BSD
X# define UNIX
X# if (defined(vax) || defined(__vax__))
X# define VAXstation /* system type = 10 */
X# else
X# define DECRISC /* system type = 3 */
X# endif
X
X#else /* else ultrix */
X#ifdef vms /* VAX-VMS machine */
X#ifndef VMS
X# define VMS /* system type = 9 */
X#endif
X#else /* else vms */
X#ifdef macintosh
X#define MAC /* system type = 11 */
X
X#else /* else macintosh */
X#ifdef AMIGA
X#define amiga /* system type = 13 */
X
X#else /* else amiga */
X#ifdef __convex__
X#define CONVEX /* system type = 14 */
X#define UNIX
X#define BSD
X#else /* else convex */
X#if (defined(__alpha) && defined(__osf__))
X#define DECALPHA /* system type = 16 */
X#define OSF
X#else /* else dec alpha/osf */
X#if defined(linux)
X# define LINUX /* system type = 17 */
X# define UNIX
X# define BSD
X# define POSIX
X#else /* else linux */
X#if defined(sgi)
X# define SGI /* system type = 18 */
X# define UNIX
X# define SYSV
X# define POSIX
X#else /* else sgi */
X >>> generate error, unknown porting platform <<<
X#endif /* 14 */
X#endif /* 13 */
X#endif /* 11 */
X#endif /* 9 */
X#endif /* 3 & 10 */
X#endif /* 12 */
X#endif /* 7 */
X#endif /* 4 */
X#endif /* 5 */
X#endif /* 6 */
X#endif /* 1 & 8 & 15 */
X#endif /* 2 */
X#endif /* 16 */
X#endif /* 17 */
X#endif /* 18 */
X
X
X#ifdef UNIX
X#define HAS_CTYPE /* <ctype.h>, iswhite( ), etc. */
X#define HAS_GETPID /* getpid( ) to identify processes */
X#define HAS_IOCTL /* has ioctl call's */
X#endif /* UNIX */
X
X#ifdef BSD
X#define HAS_BSDDIRS /* <sys/dir.h> */
X#define HAS_STRINGS
X#define HAS_CURSES /* has a bad curses lib */
X#define HAS_TERMCAP /* has a libtermcap.a */
X#define HAS_SGTTY /* has sgtty.h instead of termios.h */
X#endif /* BSD */
X
X#ifdef SYSV
X#define HAS_SYSVDIRS /* <dirent.h> */
X#define HAS_CURSES /* sysV has a good curses lib */
X#define HAS_TERMCAP /* has a libtermcap.a */
X#define HAS_TERMIOS /* has termios.h file */
X#endif /* SYSV */
X
X#ifdef OSF
X#define HAS_IOCTL /* has ioctl calls */
X#define HAS_CTYPE /* <ctype.h>, etc . */
X#define HAS_GETPID /* getpid( ) to identify processes */
X#define HAS_TERMIOS /* has termios.h file */
X#define HAS_SYSVDIRS /* has <dirent.h> */
X#define HAS_CURSES /* has a sysV based curses lib */
X#endif
X
X#ifdef POSIX /* a posix compliant system */
X#define HAS_POSIX
X#endif
X
X#ifdef IBMPC
X#define HAS_CTYPE /* <ctype.h>, iswhite( ), etc. */
X#define HAS_STDLIB
X#include <malloc.h>
X#define HAS_PERROR /* has own definition of perror in stdio
X not ansi's void */
X#ifndef __WATCOMC__
Xtypedef long time_t;
X#endif
X#endif /* IBMPC */
X
X#ifdef VMS
X#define HAS_SYSVTIME
X#define HAS_CTYPE /* <ctype.h>, iswhite( ), etc. */
X#define HAS_SSR /* VAX-C has a bad curses lib ; use the */
X#endif /* VMS */ /* system service routines (SSR) */
X
X#ifdef AMIGA
X#define HAS_SGTTY /* has sgtty.h, no termio.h */
X#endif
X/*----------------------------------------------------------------------*/
X#endif /* SYSDEFS_H_SEEN */
END_OF_FILE
if test 10817 -ne `wc -c <'sysdefs.h'`; then
echo shar: \"'sysdefs.h'\" unpacked with wrong size!
fi
# end of 'sysdefs.h'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked both archives.
rm -f ark[1-9]isdone
else
echo You still must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...

Rudi Vankemmel

unread,
Apr 16, 1995, 3:00:00 AM4/16/95
to
Submitted-by: vank...@imec.be (Rudi Vankemmel)
Posting-number: Volume 47, Issue 145
Archive-name: cbreak/part02

Environment: UNIX, VMS
Supersedes: cbreak: Volume 46 Issue 13-14

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: COPYRIGHT HISTORY make-extern make.com my_gets.1 my_gets.c
# mystrings.1 patchlevel.h test.c vms_getkey.c vms_getkey.h


# Wrapped by kent@ftp on Sun Apr 16 18:23:27 1995
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 2 (of 2)."'
if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'COPYRIGHT'\"
else
echo shar: Extracting \"'COPYRIGHT'\" \(976 characters\)
sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
X
XCopyright 1993-94-95 by R. Vankemmel


X
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X
X1 : Both the above copyright notice and this permission notice
X appear in all copies of both the software and the supporting
X documentation.
X2 : You don't make a profit out of it.
X3 : You properly credit the author of this software when it is
X included in any other package.
X
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.
X
X

XCopyright 1992 by Anthony C. McCracken (original vms getkey() routine):
END_OF_FILE
if test 976 -ne `wc -c <'COPYRIGHT'`; then
echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
fi
# end of 'COPYRIGHT'
fi
if test -f 'HISTORY' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'HISTORY'\"
else
echo shar: Extracting \"'HISTORY'\" \(1717 characters\)
sed "s/^X//" >'HISTORY' <<'END_OF_FILE'
X
X file: HISTORY


X author: R. Vankemmel
X

X
X archive: my_getch.sh
X
X
X 1) The package originated in a larger project which needed some
X basic on line menu system. As more people were interested in
X unbuffered input from the keyboard, the routines were
X isolated from the project and archived.
X R. Vankemmel wrote it.
X
X 2) V0.1 januari 12, 1994: R. Vankemmel : first PD release.
X 3) V0.2 september 14, 1994: R. Vankemmel: ported to DEC Alpha
X running OSF V1.3
X 4) V0.3 october 7, 1994: R. Vankemmel: included Anthony C. McCracken
X getkey() routine for VAX under VMS using the System Service
X routines. Tested also under OpenVMS. Works much better now
X than the previous version using curses. First version posted to
X comp.sources.misc.
X 5) V0.4 december 15, 1994: bug in my_getc() calling my_gets() in
X fallback mode (no raw mode available) solved. Bug reported
X by Larry Weissman (lar...@nsr.bioeng.washington.edu).
X Larry reported also cbreak working on SGI Indigo under IRIX.
X Modif's included in the package.
X 6) V0.5 january 4, 1995: Thanks to Peter Andersen
X (Peter.A...@mjolner.dk) cbreak works under Linux. Modif's
X included in sysdefs.h. He reported also modifications towards
X compiling on Sun Sparc under Solaris using gcc instead of cc.
X 7) V0.6 march 31, 1995: R. Vankemmel: IBM/RS6000 -AIX3.2 port.
X 8) V0.7 april 11, 1995: R. Vankemmel: better fallback behaviour when
X using my_gets() when no raw mode is available.
X 9) V1.0 april 12, 1995: R. Vankemmel: major release of the cbreak package
X Included a patchlevel.h file. Posted to comp.sources.misc.
END_OF_FILE
if test 1717 -ne `wc -c <'HISTORY'`; then
echo shar: \"'HISTORY'\" unpacked with wrong size!
fi
# end of 'HISTORY'
fi
if test -f 'make-extern' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'make-extern'\"
else
echo shar: Extracting \"'make-extern'\" \(1769 characters\)
sed "s/^X//" >'make-extern' <<'END_OF_FILE'
X# Makefile for the test program and the my_getch()
X# routine
X#
X# written by R. Vankemmel
X#
X# Note: depending on your machine you must select the
X# CC entry accordingly. Sorry for this kludge, but
X# I need the ANSI C compiler and most vendor supplied
X# C-compilers need flags for the ANSI mode.
X#
X#----------------------------------------------------
X# compiler flags:
X#CC = /bin/cc -ext -g # Convex systems (BSD)
X#CC = /bin/cc -Ae # HP7XX HPUX systems (SYSV)
X#CC = /usr/lang/acc # SUN4 Sparc systems (BSD)
X#CC = /bin/cc # Apollo DomainOS SR10 systems (BSD)
X#CC = /bin/cc # DECstation DECRisc systems (BSD)
X#CC = /bin/cc # DECstation Alpha (OSF), IBM,..........
XCC = gcc # Linux box.
X# targets:
XTEST = ./test_getch
X
XCCOBJ= test.o my_getch.o my_gets.o mystrings.o
X
X# headers
XHEADER= patchlevel.h sysdefs.h
X
X# files to pack:
XTOPACK= COPYRIGHT HISTORY INSTALL README make-extern make.com \
X my_getch.* my_gets.* mystrings.* patchlevel.h sysdefs.h test.c \
X vms_getkey.*
X
Xall: $(TEST)
X
X$(TEST): $(CCOBJ)
X @echo "Loading program $(TEST)"
X @$(CC) $(CCOBJ) -o $(TEST)
X @echo "Done...."
X
Xclean:
X @echo "Cleaning up this directory"
X @/bin/rm -f *.o $(TEST)
X @/bin/echo "Done......."
X
Xpacks:
X @echo "Creating cbreak archives:"
X @echo "Creating cbreak.TZ"
X tar cvf - $(TOPACK) | compress > cbreak.TZ
X @echo "Creating cbreak.tar.gz"
X tar cvf cbreak.tar $(TOPACK)
X gzip cbreak.tar
X @echo "Creating cbreak.sh"
X shar -b -c -C -e $(TOPACK) > cbreak.sh
X @echo "Done....."
X
X# header file dependencies:
X$(CCOBJ) : $(HEADER)
X
X# source file dependencies:
X.c.o:
X @echo "Compiling $*.c"
X @$(CC) $*.c -c
X
X# ---------------------------------------------------------------------------
END_OF_FILE
if test 1769 -ne `wc -c <'make-extern'`; then
echo shar: \"'make-extern'\" unpacked with wrong size!
fi
# end of 'make-extern'
fi
if test -f 'make.com' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'make.com'\"
else
echo shar: Extracting \"'make.com'\" \(539 characters\)
sed "s/^X//" >'make.com' <<'END_OF_FILE'
X!
X!
X$so:==write sys$output
X$so "Compiling MY_GETCH.C"
X$CC MY_GETCH.C
X$so "Compiling MY_GETS.C"
X$CC MY_GETS.C
X$so "Compiling MYSTRINGS.C"
X$CC MYSTRINGS.C
X$so "Compiling VMS_GETKEY.C"
X$CC VMS_GETKEY.C
X$so "Compiling TEST.C"
X$CC TEST.C
X$so "Defining link libraries"
X$DEFINE LNK$LIBRARY SYS$LIBRARY:VAXCRTL
X$so "Linking the TEST program"
XLINK/EXECUT=TEST.EXE TEST.OBJ,MY_GETCH.OBJ,VMS_GETKEY.OBJ
X$!
X$so "Creating the library MOC.OLB"
X$lib/create [.-]moc.olb
X$lib [.-]moc.olb my_getch.obj,my_gets.obj,mystrings.obj,vms_getkey.obj
X$so "Done"
X!
END_OF_FILE
if test 539 -ne `wc -c <'make.com'`; then
echo shar: \"'make.com'\" unpacked with wrong size!
fi
# end of 'make.com'
fi
if test -f 'my_gets.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'my_gets.1'\"
else
echo shar: Extracting \"'my_gets.1'\" \(2493 characters\)
sed "s/^X//" >'my_gets.1' <<'END_OF_FILE'
X.TH MY_GETS TCAD


X.\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
X.\" other parms are allowed: see man(7), man(1)
X.SH NAME

Xmy_gets \- get string routine with ^D detection


X.SH SYNOPSIS
X.sp 1
X.nf
X

X char *my_gets(char *buffer, int *begin)
X
X.fi
X.SH "DESCRIPTION"
Xmy_gets() has the same functionality as gets()
Xbut it checks when gets() returns a NULL pointer.
XThis is mainly because an EOF was read. In case
Xgets() is used in a loop, this may cause endless
Xloops because stdin is closed when a ^D at input
Xwas given. my_gets() then reopens stdin so that
Xinput reading may continue.
X
Xmy_gets() skips also leading blanks and tabs.
XIt returns the position in the buffer of the
Xfirst relevant char.
X.SH "\fIUSAGE\fR"
XThis routine does NOT allocate any memory for storing the strings.
XThe application programmer must provide them.
X.SH OPTIONS
XNone.
X.SH "PARAMETERS-RETURN VALUE"
X.sp 1
X.nf
Xinput: *buffer : any character string
X
Xoutput: *begin : index in buffer[] where first relevant character
X is or on EOF: -1
X *my_gets: on succes: pointer to first relevant char in
X buffer[]
X on CR/LF: NULL pointer;
X on EOF (^D): NULL pointer;
X.fi
X.SH ERRORS
XUnknown.


X.SH FILES
X.br
X.nf
X.\" set tabstop to longest possible filename, plus a wee bit
X.ta \w'/usr/lib/perl/getopts.pl 'u

X\fImy_gets.c\fR The my_gets() source.
X\fImy_gets.l\fR The my_gets() manual page.
X.SH AUTHORS
XRudi Vankemmel (june 1993)

END_OF_FILE
if test 2493 -ne `wc -c <'my_gets.1'`; then
echo shar: \"'my_gets.1'\" unpacked with wrong size!
fi
# end of 'my_gets.1'
fi
if test -f 'my_gets.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'my_gets.c'\"
else
echo shar: Extracting \"'my_gets.c'\" \(3120 characters\)
sed "s/^X//" >'my_gets.c' <<'END_OF_FILE'
X/*


XCopyright 1993 by R. Vankemmel
X
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X
X1 : Both the above copyright notice and this permission notice
X appear in all copies of both the software and the supporting
X documentation.
X2 : You don't make a profit out of it.
X3 : You properly credit the author of this software when it is
X included in any other package.
X
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.

X*/


X/*=========================RCS info==================================*/
X/* $Author: rvklib $ */
X/* $Revision: 1.0 $ */

X/* $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/my_gets.c,v $ */
X/* $Date: 95/04/11 15:54:17 $ */


X/* $State: Exp $ */
X/* $Locker: $ */
X/*===================================================================*/
X/*

X file: my_gets.c
X
X purpose: my_gets() has the same functionality as gets()
X but it checks when gets() returns a NULL pointer.
X This is mainly because an EOF was read. In case
X gets() is used in a loop, this may cause endless
X loops because stdin is closed when a ^D at input
X was given. my_gets() then reopens stdin so that
X input reading may continue.
X
X my_gets() skips also leading blanks and tabs.
X It returns the position in the buffer of the
X first relevant char.
X
X syntax: char *my_gets(char *buffer, int *begin)
X input: *buffer : any character string
X output: *begin : index in buffer[] where first relevant character
X is or on EOF: -1
X *my_gets: on succes: pointer to first relevant char in
X buffer[]
X on CR/LF: NULL pointer;
X on EOF (^D): NULL pointer;
X


X
X author: R. Vankemmel

X date: 7/7/93
X*/
X/*--------------------------------------------------------------*/
X#include <stdio.h>
X#include <errno.h>
Xextern int skip();
X
Xchar *my_gets(char *buffer,int *begin)
X{
X char *bufptr;
X
X bufptr = gets(buffer); /* read stdin */
X if (bufptr != (char *) NULL) /* check on EOF */
X {
X *begin = skip(buffer); /* where is first relevant char */
X if (buffer[*begin] == '\0') /* newline replaced by \0 in gets() */
X return(NULL);
X else
X return(buffer + *begin); /* return pointer to relevant string */
X }
X else
X {
X /* probably an EOF (^D) pressed : reopen stdin !!! */
X printf("\nmy_gets: Caught error at input\n");
X /* check if we need to reopen stdin */
X if (feof(stdin))
X {


X freopen("/dev/tty", "r", stdin);
X }
X else if (ferror(stdin))

X {
X clearerr(stdin);
X }
X *begin = -1;
X buffer[0] = '\0';
X return(NULL);
X }
X}
END_OF_FILE
if test 3120 -ne `wc -c <'my_gets.c'`; then
echo shar: \"'my_gets.c'\" unpacked with wrong size!
fi
# end of 'my_gets.c'
fi
if test -f 'mystrings.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mystrings.1'\"
else
echo shar: Extracting \"'mystrings.1'\" \(1768 characters\)
sed "s/^X//" >'mystrings.1' <<'END_OF_FILE'
X.TH MYSTRINGS TCAD


X.\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
X.\" other parms are allowed: see man(7), man(1)
X.SH NAME

Xmystrings \- some small string handling routines.


X.SH SYNOPSIS
X.sp 1
X.nf
X

X int trim(char s[])
X
X int skip(char s[])
X
X void reverse(char s[])
X
X void itoa(int n, char s[])
X
X.fi
X.SH "DESCRIPTION"
XThese routines provide simple string handling:
X.sp1
X.in +3n
X.ti -3n
Xtrim() takes a string and removes trailing blanks, tabs and
Xnewlines from the string. After processing, the string is delimited
Xby '\0'. The return value of trim() is the index in the character array
Xpointing to the last character after processing and equals the length
Xof the processed string.
X.sp 1
X.ti -3n
Xskip() : the same as trim() but now for leading blanks and tabs.
XThe return value of skip() points to the first non-blank or non-tab
Xcharacter in the string. Note that the string s[] is NOT modified.
X.sp 1
X.ti -3n
Xreverse() : reverse a string s in place.
X.sp 1
X.ti -3n
Xitoa() : convert a integer number to characters in the string s.
X.sp 1
X.in -3n
X.SH "\fINOTE\fR"
X.sp 1
XThe itoa() function is NOT ANSI C and only provided here as a
Xportability routine for foreign programs. For new routines use
Xthe standard ANSI C sprintf() functionality for converting integers
Xto strings.
X.SH "\fIUSAGE\fR"
XThis routine does NOT allocate any memory for storing the strings.
XThe application programmer must provide them.
X.SH OPTIONS
XNone.
X.SH "RETURN VALUE"
XSee the description of the routines.
X.SH ERRORS
XUnknown.


X.SH FILES
X.br
X.nf
X.\" set tabstop to longest possible filename, plus a wee bit
X.ta \w'/usr/lib/perl/getopts.pl 'u

X\fImystrings.c\fR source file.
X\fImystrings.l\fR manual page.
X.SH AUTHORS
XRudi Vankemmel (september 1993)
END_OF_FILE
if test 1768 -ne `wc -c <'mystrings.1'`; then
echo shar: \"'mystrings.1'\" unpacked with wrong size!
fi
# end of 'mystrings.1'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(1722 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X/*
X * patchlevel.h
X *
X * The cbreak package - Version 1.0 pl. 0.
X *
X * V0.1 januari 12, 1994: R. Vankemmel : first PD release.
X * V0.2 september 14, 1994: R. Vankemmel: ported to DEC Alpha
X * running OSF V1.3
X * V0.3 october 7, 1994: R. Vankemmel: included Anthony C. McCracken
X * getkey() routine for VAX under VMS using the System Service
X * routines. Tested also under OpenVMS. Works much better now
X * than the previous version using curses. First version posted to
X * comp.sources.misc.
X * V0.4 december 15, 1994: bug in my_getc() calling my_gets() in
X * fallback mode (no raw mode available) solved. Bug reported
X * by Larry Weissman (lar...@nsr.bioeng.washington.edu).
X * Larry reported also cbreak working on SGI Indigo under IRIX.
X * Modif's included in the package.
X * V0.5 january 4, 1995: Thanks to Peter Andersen
X * (Peter.A...@mjolner.dk) cbreak works under Linux. Modif's
X * included in sysdefs.h. He reported also modifications towards
X * compiling on Sun Sparc under Solaris using gcc instead of cc.
X * V0.6 march 31, 1995: R. Vankemmel: IBM/RS6000 -AIX3.2 port.
X * V0.7 april 11, 1995: R. Vankemmel: better fallback behaviour when
X * using my_gets() when no raw mode is available.
X * V1.0 april 12, 1995: R. Vankemmel: major release of the cbreak package
X * Included a patchlevel.h file. Posted to comp.sources.misc.
X *
X * RCS info:
X * $Author: rvklib $
X * $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/patchlevel.h,v $
X * $Revision: 1.0 $
X */
X
X#define VERSION 1.0
X#define PATCHLEVEL 0
END_OF_FILE
if test 1722 -ne `wc -c <'patchlevel.h'`; then
echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
if test -f 'test.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'test.c'\"
else
echo shar: Extracting \"'test.c'\" \(2910 characters\)
sed "s/^X//" >'test.c' <<'END_OF_FILE'
X/*


XCopyright 1993 by R. Vankemmel
X
XPermission to use, copy, modify and distribute this software and the
Xsupporting documentation without fee is hereby granted, provided that :
X
X1 : Both the above copyright notice and this permission notice
X appear in all copies of both the software and the supporting
X documentation.
X2 : You don't make a profit out of it.
X3 : You properly credit the author of this software when it is
X included in any other package.
X
XTHE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
XEVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
XDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
XPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
XACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
XTHIS SOFTWARE.

X*/


X/*=========================RCS info==================================*/
X/* $Author: rvklib $ */
X/* $Revision: 1.0 $ */

X/* $Source: /tmp_mnt/imec/software/rvklib/lib/moc/cbreak/RCS/test.c,v $ */
X/* $Date: 95/04/11 15:54:19 $ */


X/* $State: Exp $ */
X/* $Locker: $ */
X/*===================================================================*/
X/*
X

X file: test.c
X purpose: test program for the my_getch() routine.


X
X author: R. Vankemmel

X date: 11-5-93
X
X revisions:
X 1)
X
X
X*/


X/* ============================================================== */
X#include <stdio.h>
X#include <string.h>
X#include <stdlib.h>
X#include <time.h>
X#include <errno.h>
X
Xextern int my_getch();
X
X#ifndef TRUE
X# define TRUE (1)
X#endif
X#ifndef FALSE
X# define FALSE (0)
X#endif
X

X/* ---------------------------------------------------------------*/


Xmain(int argc, char **argv)
X{
X int input; /* entered character */
X int answer=FALSE,leave_loop;
X

X printf("\n Testing the my_getch() routine\n ");
X printf(" Author: R. Vankemmel\n");
X printf(" Date: 2/7/93\n");
X printf("\n");


X
X do
X {
X printf(" Please enter something <y,n>: ");
X putchar('n'); /* show the default option */
X fflush(stdout);
X input = my_getch();

X/* ---------------------------------------------------------------------- */
END_OF_FILE
if test 2910 -ne `wc -c <'test.c'`; then
echo shar: \"'test.c'\" unpacked with wrong size!
fi
# end of 'test.c'
fi
if test -f 'vms_getkey.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vms_getkey.c'\"
else
echo shar: Extracting \"'vms_getkey.c'\" \(2870 characters\)
sed "s/^X//" >'vms_getkey.c' <<'END_OF_FILE'
X/*
X * file: vms_getkey.c
X * purpose: unbuffered single character input on VAX VMS systems.
X * routines:
X * getkey() returns the next keystroke without echo or a carriage
X * return.
X *
X * putchar(char) works like the UNIX putchar, buffering the
X * characters until the buffer fills up (512 chars) or
X * a newline character is putchared.
X *
X * author: Anthony C. McCracken
X * date : 10-APR-92 Version 1.6
X *
X * modification: R. Vankemmel 28/10/1994
X * I had a routine which was handling single char input
X * on UNIX SYSV/BSD systems using the native ioctl calls,
X * curses or POSIX call's. Also Think C on MAC was supported.
X * Some users asked for a VMS version. However, Anthony C.
X * McCracken posted such a routine on the net which I
X * rearranged in order to include it transparantly in my
X * code i.e. the user can call the same routine my_getch()
X * on all platforms. For this purpose, Mr. McCracken's code
X * was split into a header file and a source file. This
X * allowed much easier inclusion.
X */
X
X#include <string.h> /* for the strlen() call */
X/* original source moved into header file up to here -----------------*/
X#include "vms_getkey.h"
X
X/* add system function prototyping: see help pages on system services */
Xextern int sys$assign(descr *, short int *, int, char *, ...);
Xextern int sys$qiow( int, int, int, iosb *, void (* fun)(), int, ... );
X
X/* continue with original source -------------------------------------*/
Xshort int __tty_chan = 0;
X
Xvoid build_descr(descr *p,char *s) /* Builds a fixed length string */
X /* descriptor */
X{
X
X p->length = strlen(s);
X p->dtype = 14;
X p->class = 1;
X p->ptr = s;
X}
X
Xchar getkey()
X{
X descr __tty_name;
X char __tty_buff;
X iosb __tty_iosb;
X int __i;
X
X if (__tty_chan == 0) {
X build_descr(&__tty_name,"TT:");
X if (sys$assign(&__tty_name,&__tty_chan,0,0) != SS$_NORMAL) return(0);
X }
X __i = sys$qiow(0,__tty_chan,IO$_READVBLK+IO$M_NOECHO,&__tty_iosb,0,0,
X &__tty_buff,1,0,0,0,0);
X if (__i != SS$_NORMAL) return(0);
X else return(__tty_buff);
X}
X
X#define __putcharbufsize 512
Xchar __putcbuff[__putcharbufsize];
Xint __pcp = 0;
X
X#define putchar(c) {if(c=='\n') __barfout(__putcbuff,&__pcp); \
X else __putcbuff[__pcp++]=c; \
X if (__pcp>__putcharbufsize-2) __barfout(__putcbuff,&__pcp);}
X
Xvoid __barfout(char *s, int *__i)
X{
X s[(*__i)++] = '\n';
X s[*__i] = 0;
X fputs(s,stdout);
X *__i = 0;
X}
X
X
X
X#ifdef _VMS_TEST_
X#include <stdio.h>
X#include "vms_getkey.h"
Xmain()
X{
X char c;
X
X printf("Press ANY key to continue\n");
X c = getkey();
X printf("You pressed the %c key\n",c);
X}
X#endif
X
X
END_OF_FILE
if test 2870 -ne `wc -c <'vms_getkey.c'`; then
echo shar: \"'vms_getkey.c'\" unpacked with wrong size!
fi
# end of 'vms_getkey.c'
fi
if test -f 'vms_getkey.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vms_getkey.h'\"
else
echo shar: Extracting \"'vms_getkey.h'\" \(1924 characters\)
sed "s/^X//" >'vms_getkey.h' <<'END_OF_FILE'
X/*
X * file: vms_getkey.h
X * purpose: header file for vms_getkey.c
X *
X * author: Anthony C. McCracken
X * modification: R. Vankemmel 28/10/1994
X * Split his original ode into a header and a source file.
X * Reason: see description in the vms_getkey.c file.
X * Added proper flags preventing multiple includes.
X *
X * His original comments:
X *================================================================
X *
X TERMIO.H fixes a few anomolies of the VAX C runtime library.
X
X Version 1.6 10-APR-92 Anthony C. McCracken
X
X getkey() returns the next keystroke without echo or a carriage
X return.
X
X putchar(char) works like the UNIX putchar, buffering the characters
X until the buffer fills up (512 chars) or a newline
X character is putchared.
X
X To use these routines, just include this header file after all the
X other #include statements.
X
X *================================================================
X *
X */
X#ifndef _VMS_GETKEY_H_SEEN_
X#define _VMS_GETKEY_H_SEEN_
X
X#include <stdio.h>
X#include <ssdef.h>
X#include <iodef.h>
X
Xtypedef struct {
X short int status; /* I/O completion status */
X short int bcount; /* byte transfer count */
X int dev_dep_data; /* device dependant data */
X } iosb; /* This is a QIO I/O Status Block */
X
Xtypedef struct {
X short int length; /* Length of string */
X char dtype; /* Type 14 is a string */
X char class; /* Class 1 is fixed length */
X char *ptr; /* Pointer to the string */
X } descr; /* once initialized, this is a fixed */
X /* length string descriptor */
X/* function prototyping */
Xextern char getkey();
X
X#endif
END_OF_FILE
if test 1924 -ne `wc -c <'vms_getkey.h'`; then
echo shar: \"'vms_getkey.h'\" unpacked with wrong size!
fi
# end of 'vms_getkey.h'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone

0 new messages