Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!comp-sources-3b1 From: tkacick@kyzyl.mi.org (Tom Tkacik) Newsgroups: comp.sources.3b1 Subject: v01i026: prewinit - a fix for the iswind problem, Part01/01 Message-ID: <1991Jun1.021822.20058@uunet.uu.net> Date: 1 Jun 91 02:18:22 GMT Sender: usenet@uunet.uu.net (UseNet News) Organization: UUNET Communications Services Lines: 106 Approved: dave@galaxia.newport.ri.us Originator: dhb@uunet.UU.NET Nntp-Posting-Host: uunet.uu.net X-Checksum-Snefru: 78f543c4 b8660408 ff09103d fe9b5a05 Submitted-by: tkacick@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 main() { prewinit(); winit(); /* rest of program */ wexit(0); } -- Tom Tkacik | tkacik@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@kyzyl.mi.org X */ X X#include X#include X#include 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@kyzyl.mi.org | To rent this space, call 1-800-555-QUIP. ..!rphroy!kyzyl!tkacik | -- David H. Brierley Home: dave@galaxia.newport.ri.us; Work: dhb@quahog.ssd.ray.com Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.newport.ri.us %% Can I be excused, my brain is full. **