v01i027: iswind() patches for mahjongg, Part01/01

Tom Tkacik tkacik at kyzyl.mi.org
Sat Jun 8 12:56:49 AEST 1991


Submitted-by: tkacik at kyzyl.mi.org (Tom Tkacik)
Posting-number: Volume 1, Issue 27
Archive-name: mahjongg/patch2
Patch-To: mahjongg: Volume 1, Issue 15-16,21


Because several of you noticed that iswind() does not always seem
to work properly, I have here a set of patches for mahjongg to
take care of that problem.  This uses the new prewinit() routine I
posted a few days ago.

Unless you allow logins other than through the console,
you should not notice a difference.

--
Tom Tkacik                |
tkacik at kyzyl.mi.org       |     To rent this space, call 1-800-555-QUIP.
tkacik at hobbes.cs.gmr.com  |
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Makefile~	Tue Mar 12 07:32:41 1991
--- Makefile	Wed Jun  5 17:57:52 1991
***************
*** 14,21 ****
  
  # program source and object files
  HDR = mahjongg.h
! SRC = mahjongg.c window.c tiles.c event.c bamboo.c character.c dot.c other.c
! OBJ = mahjongg.o window.o tiles.o event.o bamboo.o character.o dot.o other.o
  
  # Uncomment the next two lines if you want to use GCC
  CC = gcc
--- 14,23 ----
  
  # program source and object files
  HDR = mahjongg.h
! SRC = mahjongg.c window.c tiles.c event.c prewinit.c\
! 	bamboo.c character.c dot.c other.c
! OBJ = mahjongg.o window.o tiles.o event.o prewinit.o\
! 	bamboo.o character.o dot.o other.o
  
  # Uncomment the next two lines if you want to use GCC
  CC = gcc
*** window.c~	Mon Mar 11 18:27:26 1991
--- window.c	Wed Jun  5 18:02:52 1991
***************
*** 6,12 ****
   */
  
  #include <stdio.h>
- #include <fcntl.h>
  #include <termio.h>
  #include <sys/signal.h>
  #include <tam.h>
--- 6,11 ----
***************
*** 34,39 ****
--- 33,39 ----
  struct umdata mouse = { MSDOWN, SIDEBORDER, TOPBORDER, 0, 0, &stick };
  
  int reborder(), leave();
+ void prewinit();
  
  /*  window routines */
  
***************
*** 43,66 ****
  
  initwindow()
  {
!      /* start with a clean window */
!      /*  this needs to be done because winit() uses the */
!      /*  current window first, so we open a new one     */
! 	(void)close(0);
! 	(void)close(1);
! 	(void)close(2);
! 	wn = open("/dev/window", O_RDWR );
! 	(void)dup(wn);
! 	(void)dup(wn);
  
       /* initialize the tam routines */
  	winit();
- 
-      /* can only be run on the unixpc screen */
- 	if(iswind()==0) {
- 		(void)fprintf(stderr, "must use bitmapped screen\n");
- 		wexit(1);
- 	}
  
       /* open the mahjongg window */
  	if((wn = wcreate(WINDOW_Y, WINDOW_X, ROWS, COLS, NBORDER)) == -1) {
--- 43,53 ----
  
  initwindow()
  {
!      /* pre-check if things are ok --- no need to call iswind() */
! 	prewinit();
  
       /* initialize the tam routines */
  	winit();
  
       /* open the mahjongg window */
  	if((wn = wcreate(WINDOW_Y, WINDOW_X, ROWS, COLS, NBORDER)) == -1) {
*** prewinit.c~	Wed Jun  5 17:56:42 1991
--- prewinit.c	Wed Jun  5 17:56:28 1991
***************
*** 0 ****
--- 1,43 ----
+ /*
+  * This routine should be executed before running the tam routine winit()
+  * It will check if the program is being run from the console, and will
+  * get a fresh window for the program to use.
+  *
+  * Iswind() is not needed.  This routine does the job.
+  *
+  * This routine is in the public domain.
+  * Not only are you allowed to use this code, I wish you would.
+  *
+  * Thomas Tkacik    tkacik at kyzyl.mi.org
+  */
+ 
+ #include <fcntl.h>
+ #include <stdio.h>
+ #include <sys/window.h>
+ 
+ void prewinit()
+ {
+ 
+ 	struct uwdata win_data;
+ 	int wn;
+ 
+ 	/* will fail if not a window */
+ 	if(ioctl(1, WIOCGETD, &win_data) == -1) {
+ 		(void)fprintf(stderr, "must use the bitmapped display\n");
+ 		exit(1);
+ 	}
+ 	
+ 	/* everything is fine, running from the console */
+ 
+ 	/* detach from stdin, stout and stderr, and get a fresh window */
+ 	(void)close(0);
+ 	if((wn = open("/dev/window", O_RDWR )) == -1) {
+ 		(void)fprintf(stderr, "cannot open window\n");
+ 		exit(1);
+ 	}
+ 	(void)close(1);
+ 	(void)close(2);
+ 	(void)dup(wn);
+ 	(void)dup(wn);
+ }
+ 
-- 
Tom Tkacik                |
tkacik at kyzyl.mi.org       |     To rent this space, call 1-800-555-QUIP.
tkacik at hobbes.cs.gmr.com  |

-- 
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