home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / xblckbst / patch03 < prev    next >
Encoding:
Text File  |  1993-05-31  |  15.7 KB  |  543 lines

  1. Newsgroups: comp.sources.x
  2. From: master@cats.UCSC.EDU (Mark Wedel)
  3. Subject: v20i006:  xblockbuster - a variation of the break-out type games, Patch03
  4. Message-ID: <1993Jun1.221025.3657@sparky.imd.sterling.com>
  5. X-Md4-Signature: 2f52277d0f9da3863a5f0ac38245acba
  6. Sender: chris@sparky.imd.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 1 Jun 1993 22:10:25 GMT
  9. Approved: chris@sparky.imd.sterling.com
  10.  
  11. Submitted-by: master@cats.UCSC.EDU (Mark Wedel)
  12. Posting-number: Volume 20, Issue 6
  13. Archive-name: xblockbuster/patch03
  14. Environment: X11
  15. Patch-To: xblockbuster: Volume 19, Issue 44-49,79
  16.  
  17.  
  18.  
  19. This is patch #3 for xblockbuster.  The changes are minor:
  20. Changes from v1.02 to v1.03
  21.  
  22.   file locking implemented for the scorefile.  By Gerald Vogt <vogt@isa.de>
  23.   this adds the files lock.c and lock.h
  24.  
  25.   added S_ISDIR macro to xblockbuster.c for Mips machines
  26.  
  27.  This is a shell archive.  It contains 3 files, the patch file
  28. (xbb.patch3) and two new files - lock.c and lock.h.  Unpack
  29. this file in the xblockbuster directory. 
  30.  
  31.  A completely patched version of XBlockBuster 1.03 should either be
  32. on or appear in the near future on export.lcs.mit.edu.  The
  33. compressed file is about 82k.
  34.  
  35.  Mark Wedel
  36. master@cats.ucsc.edu
  37.  
  38.  
  39. #! /bin/sh
  40. # This is a shell archive.  Remove anything before this line, then unpack
  41. # it by saving it into a file and typing "sh file".  To overwrite existing
  42. # files, type "sh file -c".  You can also feed this as standard input via
  43. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  44. # will see the following message at the end:
  45. #        "End of shell archive."
  46. # Contents:  xbb.patch3 lock.c lock.h
  47. # Wrapped by master@sleipner on Wed May 19 22:59:24 1993
  48. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  49. if test -f 'xbb.patch3' -a "${1}" != "-c" ; then 
  50.   echo shar: Will not clobber existing file \"'xbb.patch3'\"
  51. else
  52. echo shar: Extracting \"'xbb.patch3'\" \(7648 characters\)
  53. sed "s/^X//" >'xbb.patch3' <<'END_OF_FILE'
  54. Xdiff -c xblockbuster1.02/CHANGES xblockbuster1.03/CHANGES
  55. X*** xblockbuster1.02/CHANGES    Fri Apr  2 20:44:44 1993
  56. X--- xblockbuster1.03/CHANGES    Sat Apr 17 23:07:02 1993
  57. X***************
  58. X*** 1,3 ****
  59. X--- 1,10 ----
  60. X+ Changes from v1.02 to v1.03
  61. X+ 
  62. X+   file locking implemented for the scorefile.  By Gerald Vogt <vogt@isa.de>
  63. X+   this adds the files lock.c and lock.h
  64. X+ 
  65. X+   added S_ISDIR macro to xblockbuster.c for Mips machines
  66. X+ 
  67. X  Changes from v1.01 to v1.02
  68. X  
  69. X    rand and srand are now used as defaults on HP machines.
  70. Xdiff -c xblockbuster1.02/Imakefile xblockbuster1.03/Imakefile
  71. X*** xblockbuster1.02/Imakefile    Fri Apr  2 23:13:07 1993
  72. X--- xblockbuster1.03/Imakefile    Sat Apr 17 20:21:14 1993
  73. X***************
  74. X*** 17,22 ****
  75. X--- 17,23 ----
  76. X  #ifndef StageDir
  77. X  #define StageDir $(LIBDIR)/xblockbuster
  78. X  #endif
  79. X+ CFLAGS += -Wall
  80. X  
  81. X  STAGEDIR = StageDir
  82. X  
  83. X***************
  84. X*** 25,34 ****
  85. X          DEFINES = -DSTAGEDIR=\"$(STAGEDIR)\"
  86. X          DEPLIBS = $(DEPXLIB)
  87. X  LOCAL_LIBRARIES = $(XLIB)
  88. X!           SRCS1 = balls_pallet.c bricks.c deflection.c save.c score.c stage.c \
  89. X!                   xblockbuster.c
  90. X!           OBJS1 = balls_pallet.o bricks.o deflection.o save.o score.o stage.o \
  91. X!                   xblockbuster.o
  92. X            SRCS2 = stagemm.c
  93. X            OBJS2 = stagemm.o
  94. X         PROGRAMS = xblockbuster stagemm
  95. X--- 26,35 ----
  96. X          DEFINES = -DSTAGEDIR=\"$(STAGEDIR)\"
  97. X          DEPLIBS = $(DEPXLIB)
  98. X  LOCAL_LIBRARIES = $(XLIB)
  99. X!           SRCS1 = balls_pallet.c bricks.c deflection.c lock.c save.c score.c \
  100. X!                   stage.c xblockbuster.c
  101. X!           OBJS1 = balls_pallet.o bricks.o deflection.o lock.o save.o score.o \
  102. X!                   stage.o xblockbuster.o
  103. X            SRCS2 = stagemm.c
  104. X            OBJS2 = stagemm.o
  105. X         PROGRAMS = xblockbuster stagemm
  106. XOnly in xblockbuster1.03: Makefile
  107. Xdiff -c xblockbuster1.02/Makefile.noIm xblockbuster1.03/Makefile.noIm
  108. X*** xblockbuster1.02/Makefile.noIm    Sat Mar 20 03:11:41 1993
  109. X--- xblockbuster1.03/Makefile.noIm    Sat Apr 17 19:27:01 1993
  110. X***************
  111. X*** 1,10 ****
  112. X  #
  113. X  # Makefile for XBlockbuster
  114. X  #
  115. X! HDRS= xblockbuster.h patchlevel.h
  116. X! SRCS = balls_pallet.c bricks.c deflection.c save.c score.c stage.c \
  117. X      xblockbuster.c 
  118. X! OBJS = balls_pallet.o bricks.o deflection.o save.o score.o stage.o \
  119. X      xblockbuster.o 
  120. X  
  121. X  # Where you want the executable installed
  122. X--- 1,10 ----
  123. X  #
  124. X  # Makefile for XBlockbuster
  125. X  #
  126. X! HDRS= xblockbuster.h patchlevel.h lock.h
  127. X! SRCS = balls_pallet.c bricks.c deflection.c lock.c save.c score.c stage.c \
  128. X      xblockbuster.c 
  129. X! OBJS = balls_pallet.o bricks.o deflection.o lock.o save.o score.o stage.o \
  130. X      xblockbuster.o 
  131. X  
  132. X  # Where you want the executable installed
  133. Xdiff -c xblockbuster1.02/README xblockbuster1.03/README
  134. X*** xblockbuster1.02/README    Tue Mar 30 20:19:06 1993
  135. X--- xblockbuster1.03/README    Sat Apr 17 19:33:05 1993
  136. X***************
  137. X*** 97,110 ****
  138. X  
  139. X  BUGS/TODO:
  140. X  
  141. X-  I have gotten several reports of the pallette not appearing on the
  142. X- screen, yet the balls are appearing (both use the gc_xor structure, so
  143. X- I don't have any idea what the problem is, and can't reproduce it
  144. X- myself.)  This problem seems to be happening more on BW systems.  My
  145. X- only thought right now is perhaps the window wasn't made the proper size,
  146. X- so the bottom is cut off.  But even then, if the pointer is moved near
  147. X- the top of the window, the side crosshairs should still appear.
  148. X- 
  149. X   A nice opening screen, showing the bricks (with proper coloring, if 
  150. X  applicable), along with descriptions of what each brick does.
  151. X  
  152. X--- 97,102 ----
  153. XCommon subdirectories: xblockbuster1.02/SKELS and xblockbuster1.03/SKELS
  154. XCommon subdirectories: xblockbuster1.02/STAGES and xblockbuster1.03/STAGES
  155. XCommon subdirectories: xblockbuster1.02/STAGES.try and xblockbuster1.03/STAGES.try
  156. XCommon subdirectories: xblockbuster1.02/STAGES.wacko and xblockbuster1.03/STAGES.wacko
  157. XCommon subdirectories: xblockbuster1.02/icons and xblockbuster1.03/icons
  158. XOnly in xblockbuster1.03: lock.c
  159. XOnly in xblockbuster1.03: lock.h
  160. Xdiff -c xblockbuster1.02/patchlevel.h xblockbuster1.03/patchlevel.h
  161. X*** xblockbuster1.02/patchlevel.h    Fri Mar 26 01:21:39 1993
  162. X--- xblockbuster1.03/patchlevel.h    Sat Apr 17 19:39:55 1993
  163. X***************
  164. X*** 1 ****
  165. X! #define VERSION    "XBlockBuster 1.02"
  166. X--- 1 ----
  167. X! #define VERSION    "XBlockBuster 1.03"
  168. Xdiff -c xblockbuster1.02/score.c xblockbuster1.03/score.c
  169. X*** xblockbuster1.02/score.c    Wed Mar 24 18:46:51 1993
  170. X--- xblockbuster1.03/score.c    Sat Apr 17 20:30:49 1993
  171. X***************
  172. X*** 17,22 ****
  173. X--- 17,23 ----
  174. X   */
  175. X  
  176. X  #include "xblockbuster.h"
  177. X+ #include "lock.h"
  178. X  
  179. X  struct Score {
  180. X      int             score, balls_left;
  181. X***************
  182. X*** 52,61 ****
  183. X--- 53,74 ----
  184. X  
  185. X      /* read the score file into the array */
  186. X      sprintf( buf, SCOREFILE, playground );
  187. X+ 
  188. X+ #ifdef LOCK_FILE
  189. X+     if (LockScoreFile(buf) == -1)
  190. X+       exit(1);
  191. X+ #endif
  192. X+ 
  193. X      if ( !( fd = fopen(buf, "r+" ) ) ) {
  194. X          perror( "No score file" );
  195. X          exit( 1 );
  196. X      }
  197. X+ 
  198. X+ #ifdef LOCK_FCNTL
  199. X+     if (LockFile(fileno(fd)) == -1)
  200. X+       exit(1);
  201. X+ #endif
  202. X+ 
  203. X      for ( s = 0; s < NB_SCORES; s++ ) {
  204. X          fscanf( fd, "%d:%d:%s\n", &score_board[s].score,
  205. X              &score_board[s].balls_left,
  206. X***************
  207. X*** 109,115 ****
  208. X--- 122,137 ----
  209. X                   score_board[s].login );
  210. X          }
  211. X      }
  212. X+ 
  213. X+ #ifdef LOCK_FCNTL
  214. X+     UnlockFile(fileno(fd));
  215. X+ #endif
  216. X+ 
  217. X      fclose( fd );
  218. X+ 
  219. X+ #ifdef LOCK_FILE
  220. X+     UnlockScoreFile(buf);
  221. X+ #endif
  222. X  
  223. X      /* show score board */
  224. X      center_text( 0, "Top Scores" );
  225. XOnly in xblockbuster1.02: stagemm.o
  226. Xdiff -c xblockbuster1.02/xblockbuster.c xblockbuster1.03/xblockbuster.c
  227. X*** xblockbuster1.02/xblockbuster.c    Wed Mar 31 19:27:01 1993
  228. X--- xblockbuster1.03/xblockbuster.c    Sat Apr 17 23:06:10 1993
  229. X***************
  230. X*** 30,35 ****
  231. X--- 30,40 ----
  232. X  static char *disp=NULL, *play="default";
  233. X  static int winposx=0, winposy=0,geomask,no_pause=FALSE;
  234. X  
  235. X+ 
  236. X+ #ifdef Mips
  237. X+ #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
  238. X+ #endif
  239. X+ 
  240. X  void event_handler()
  241. X  {
  242. X      XEvent    e;
  243. Xdiff -c xblockbuster1.02/xblockbuster.h xblockbuster1.03/xblockbuster.h
  244. X*** xblockbuster1.02/xblockbuster.h    Tue Mar 30 20:11:59 1993
  245. X--- xblockbuster1.03/xblockbuster.h    Sat Apr 17 20:47:36 1993
  246. X***************
  247. X*** 20,25 ****
  248. X--- 20,36 ----
  249. X   * SYSTEM DEPENDENT OPTIONS
  250. X   */
  251. X  
  252. X+ /* NOTE: only one of LOCK_FCTNL or LOCK_FILE should be defined. */
  253. X+ /* If neither are defined, no file locking will be done */
  254. X+ 
  255. X+ /* Use fcntl to lock the scorefile */
  256. X+ #define LOCK_FCNTL
  257. X+ /* Use a different locking method for the score file.  Maybe try it
  258. X+   if fcntl does not work.  If you do use LOCK_FILE, the STAGES
  259. X+ directories themselves need to be publicly writable, as a lockfile
  260. X+ is written in them */
  261. X+ /*#define LOCK_FILE*/
  262. X+ 
  263. X  /* STAGEDIR should, in general, be defined in the (I)Makefile */
  264. X  #ifndef STAGEDIR
  265. X  #define STAGEDIR    "/usr/games/lib/blockbuster"
  266. Xdiff -c xblockbuster1.02/xblockbuster.man xblockbuster1.03/xblockbuster.man
  267. X*** xblockbuster1.02/xblockbuster.man    Wed Mar 31 19:43:21 1993
  268. X--- xblockbuster1.03/xblockbuster.man    Sat Apr 17 19:33:47 1993
  269. X***************
  270. X*** 283,287 ****
  271. X  the bricks it was unable to color.  If using alternate bricks, it can be
  272. X  difficult to differentiate bricks without the coloring.
  273. X  .LP
  274. X! None of the standard command line X arguements are interperted.  Likewise,
  275. X! none of the standard X defaults (in the .Xdefaults file) are used.
  276. X--- 283,288 ----
  277. X  the bricks it was unable to color.  If using alternate bricks, it can be
  278. X  difficult to differentiate bricks without the coloring.
  279. X  .LP
  280. X! Only a few of the standard command line X arguements are interperted.
  281. X! Likewise,
  282. X! only a few of the standard X defaults (in the .Xdefaults file) are used.
  283. END_OF_FILE
  284. if test 7648 -ne `wc -c <'xbb.patch3'`; then
  285.     echo shar: \"'xbb.patch3'\" unpacked with wrong size!
  286. fi
  287. # end of 'xbb.patch3'
  288. fi
  289. if test -f 'lock.c' -a "${1}" != "-c" ; then 
  290.   echo shar: Will not clobber existing file \"'lock.c'\"
  291. else
  292. echo shar: Extracting \"'lock.c'\" \(3733 characters\)
  293. sed "s/^X//" >'lock.c' <<'END_OF_FILE'
  294. X/*
  295. X** lock.c: this module provides a simple locking mechanism
  296. X**
  297. X**         LockScoreFile(filename) locks the given file. returns -1 on error.
  298. X**         UnlockScoreFile(filename) unlocks the given file.
  299. X**         LockFile(fd) locks the given file descriptor using fcntl.
  300. X**         UnlockFile(fd) unlocks the given file descriptor.
  301. X**
  302. X** the lockfilename is built from the given parameter by adding ".lock" at
  303. X** the end of it. the callers process id will be written in the file.
  304. X** when the file is unlocked again the pid will be read and checked
  305. X** before the file is unlinked.
  306. X**
  307. X** LockFile and UnlockFile use fcntl on an open file descriptor.
  308. X**
  309. X** Copyright (C) 1993, Gerald Vogt <vogt@isa.de>
  310. X** 
  311. X** This program is free software; you can redistribute it and/or modify
  312. X** it under the terms of the GNU General Public License as published by
  313. X** the Free Software Foundation; either version 1, or (at your option)
  314. X** any later version.
  315. X**
  316. X** This program is distributed in the hope that it will be useful,
  317. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  318. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  319. X** GNU General Public License for more details.
  320. X**
  321. X*/
  322. X
  323. X#include <stdio.h>
  324. X#include <fcntl.h>
  325. X#include <malloc.h>
  326. X#include "xblockbuster.h"
  327. X#include "lock.h"
  328. X
  329. X#define MAXTRY 30
  330. X
  331. X#ifdef LOCK_FILE
  332. Xchar    *CreateLockFileName(scorefile)
  333. Xchar    *scorefile;
  334. X{
  335. X    char    *buffer;
  336. X
  337. X    buffer = malloc(strlen(scorefile) + 6);
  338. X
  339. X    if (buffer != (char *) NULL) {
  340. X    strcpy(buffer, scorefile);
  341. X    strcat(buffer, ".lock");
  342. X    }
  343. X
  344. X    return(buffer);
  345. X}
  346. X
  347. Xint LockScoreFile(scorefile)
  348. Xchar    *scorefile;
  349. X{
  350. X    char    *filename;
  351. X    int        ret;
  352. X    char    string[10];
  353. X    int        tryCount;
  354. X    extern char *sys_errlist[];
  355. X    extern int errno;
  356. X
  357. X    filename = CreateLockFileName(scorefile);
  358. X   
  359. X    if (filename == (char *) NULL)
  360. X      return(-1);
  361. X
  362. X    tryCount = 0;
  363. X
  364. X    do {
  365. X    ret = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0664);
  366. X    tryCount++;
  367. X    
  368. X    if (ret == -1) {
  369. X        fprintf(stderr,"Could not open %s:%s\n",filename,sys_errlist[errno]);
  370. X
  371. X        if (tryCount == MAXTRY) {
  372. X        fprintf(stderr, "Giving up.\n");
  373. X        free(filename);
  374. X        return(-1);
  375. X        }
  376. X        sleep(1);
  377. X    }
  378. X    } while (ret == -1);
  379. X
  380. X    sprintf(string, "%d", getpid());
  381. X    write(ret, string, strlen(string) + 1);
  382. X
  383. X    close(ret);
  384. X    free(filename);
  385. X    return(0);
  386. X}
  387. X      
  388. Xvoid    UnlockScoreFile(scorefile)
  389. Xchar    *scorefile;
  390. X{
  391. X    char    *filename;
  392. X    int        ret, len;
  393. X    char    string[10];
  394. X    extern int atoi();
  395. X
  396. X    filename = CreateLockFileName(scorefile);
  397. X    
  398. X    if (filename == (char *) NULL)
  399. X      return;
  400. X
  401. X    ret = open(filename, O_RDONLY);
  402. X
  403. X    if (ret == -1) {
  404. X    perror("open score lock file");
  405. X    free(filename);
  406. X    return;
  407. X    }
  408. X
  409. X    len = read(ret, string, 10);
  410. X
  411. X    if (len == -1) {
  412. X    perror("reading score lock file");
  413. X    close(ret);
  414. X    free(filename);
  415. X    return;
  416. X    }
  417. X
  418. X    len = atoi(string);
  419. X
  420. X    close(ret);
  421. X
  422. X    if (len == getpid())
  423. X      unlink(filename);
  424. X    else
  425. X      fprintf(stderr, "Score lock pid does not match\n");
  426. X
  427. X    free(filename);
  428. X}
  429. X#endif
  430. X
  431. X#ifdef LOCK_FCNTL
  432. Xint LockFile(fd)
  433. Xint fd;
  434. X{
  435. X    int        ret;
  436. X    int        tryCount;
  437. X    struct flock fl;
  438. X
  439. X    tryCount = 0;
  440. X
  441. X    do {
  442. X    fl.l_type = F_WRLCK;
  443. X    fl.l_whence = 0;
  444. X    fl.l_start = 0L;
  445. X    fl.l_len = 0L;
  446. X    
  447. X    ret = fcntl(fd, F_SETLK, &fl);
  448. X
  449. X    tryCount++;
  450. X    
  451. X    if (ret == -1) {
  452. X        perror("fcntl");
  453. X
  454. X        if (tryCount == MAXTRY) {
  455. X        fprintf(stderr, "Giving up.\n");
  456. X        return(-1);
  457. X        }
  458. X        sleep(1);
  459. X    }
  460. X    } while (ret == -1);
  461. X
  462. X    return(0);
  463. X}
  464. X      
  465. Xvoid    UnlockFile(fd)
  466. Xint     fd;
  467. X{
  468. X    int        ret;
  469. X    struct flock fl;
  470. X
  471. X    fl.l_type = F_UNLCK;
  472. X    fl.l_whence = 0;
  473. X    fl.l_start = 0L;
  474. X    fl.l_len = 0L;
  475. X
  476. X    ret = fcntl(fd, F_SETLK, &fl);
  477. X
  478. X    if (ret == -1) {
  479. X    perror("fcntl");
  480. X    }
  481. X}
  482. X#endif
  483. END_OF_FILE
  484. if test 3733 -ne `wc -c <'lock.c'`; then
  485.     echo shar: \"'lock.c'\" unpacked with wrong size!
  486. fi
  487. # end of 'lock.c'
  488. fi
  489. if test -f 'lock.h' -a "${1}" != "-c" ; then 
  490.   echo shar: Will not clobber existing file \"'lock.h'\"
  491. else
  492. echo shar: Extracting \"'lock.h'\" \(1164 characters\)
  493. sed "s/^X//" >'lock.h' <<'END_OF_FILE'
  494. X/*
  495. X** lock.h: headerfile for lock.c
  496. X**
  497. X**         LockScoreFile(filename) locks the given file. returns -1 on error.
  498. X**         UnlockScoreFile(filename) unlocks the given file.
  499. X**
  500. X** the lockfilename is built from the given parameter by adding ".lock" at
  501. X** the end of it. the callers process id will be written in the file.
  502. X** when the file is unlocked again the pid will be read and checked
  503. X** before the file is unlinked.
  504. X**
  505. X** Copyright (C) 1993, Gerald Vogt <vogt@isa.de>
  506. X** 
  507. X** This program is free software; you can redistribute it and/or modify
  508. X** it under the terms of the GNU General Public License as published by
  509. X** the Free Software Foundation; either version 1, or (at your option)
  510. X** any later version.
  511. X**
  512. X** This program is distributed in the hope that it will be useful,
  513. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  514. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  515. X** GNU General Public License for more details.
  516. X**
  517. X*/
  518. X
  519. X#ifdef LOCK_FILE
  520. Xextern char *CreateLockFileName();
  521. Xextern int LockScoreFile();
  522. Xextern void UnlockScoreFile();
  523. X#endif
  524. X#ifdef LOCK_FCNTL
  525. Xextern int LockFile();
  526. Xextern void UnlockFile();
  527. X#endif
  528. END_OF_FILE
  529. if test 1164 -ne `wc -c <'lock.h'`; then
  530.     echo shar: \"'lock.h'\" unpacked with wrong size!
  531. fi
  532. # end of 'lock.h'
  533. fi
  534. echo shar: End of shell archive.
  535. exit 0
  536.  
  537. exit 0 # Just in case...
  538. -- 
  539.   // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
  540. \X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
  541.  "It's intuitively obvious to the |
  542.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  543.