v01i026: prewinit - a fix for the iswind problem, Part01/01

Tom Tkacik tkacick at kyzyl.mi.org
Sat Jun 1 12:18:22 AEST 1991


Submitted-by: tkacick at kyzyl.mi.org (Tom Tkacik)
Posting-number: Volume 1, Issue 26
Archive-name: prewinit/part01


Here is my solution to the problem that the TAM routine iswind() does
not always do its job.  This routine should be used in any program that
uses the TAM library, before winit() is called.
These is no need to call iswind() anymore.

It simply checks that the program is run from the console, and then opens
a fresh window for use by the program.

This code is put into the public domain.
Not only are you allowed to use this code, I hope that any new graphics
programs will use it.

Its use in a program is simple:

#include <tam.h>
main()
{
	prewinit();
	winit();

	/* rest of program */

	wexit(0);
}

--
Tom Tkacik                |
tkacik at kyzyl.mi.org       |     To rent this space, call 1-800-555-QUIP.
..!rphroy!kyzyl!tkacik   |
#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
#
echo 'x - prewinit.c'
if test -f prewinit.c; then echo 'shar: not overwriting prewinit.c'; else
sed 's/^X//' << '________This_Is_The_END________' > prewinit.c
X/*
X * This routine should be executed before running the tam routine winit()
X * It will check if the program is being run from the console, and will
X * get a fresh window for the program to use.
X *
X * Iswind() is not needed.  This routine does the job.
X *
X * This routine is in the public domain.
X * Not only are you allowed to use this code, I wish you would.
X *
X * Thomas Tkacik    tkacik at kyzyl.mi.org
X */
X
X#include <fcntl.h>
X#include <stdio.h>
X#include <sys/window.h>
X
Xvoid prewinit()
X{
X
X	struct uwdata win_data;
X	int wn;
X
X	/* will fail if not a window */
X	if(ioctl(1, WIOCGETD, &win_data) == -1) {
X		(void)fprintf(stderr, "must use the bitmapped display\n");
X		exit(1);
X	}
X	
X	/* everything is fine, running from the console */
X
X	/* detach from stdin, stout and stderr, and get a fresh window */
X	(void)close(0);
X	if((wn = open("/dev/window", O_RDWR )) == -1) {
X		(void)fprintf(stderr, "cannot open window\n");
X		exit(1);
X	}
X	(void)close(1);
X	(void)close(2);
X	(void)dup(wn);
X	(void)dup(wn);
X}
X
________This_Is_The_END________
if test `wc -c < prewinit.c` -ne 997; then
	echo 'shar: prewinit.c was damaged during transit (should have been 997 bytes)'
fi
fi		; : end of overwriting check
exit 0
-- 
Tom Tkacik                |
tkacik at kyzyl.mi.org       |     To rent this space, call 1-800-555-QUIP.
..!rphroy!kyzyl!tkacik   |

-- 
David H. Brierley
Home: dave at galaxia.newport.ri.us; Work: dhb at quahog.ssd.ray.com
Send comp.sources.3b1 submissions to comp-sources-3b1 at galaxia.newport.ri.us
%% Can I be excused, my brain is full. **



More information about the Comp.sources.3b1 mailing list