home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume37 / magiccube / part04 < prev    next >
Text File  |  1993-05-15  |  62KB  |  2,160 lines

  1. Newsgroups: comp.sources.misc
  2. From: fleurant@hri.com (P.Fleurant)
  3. Subject: v37i041:  magiccube - a cube simulator for X11/Motif, Part04/05
  4. Message-ID: <1993May10.213408.29831@sparky.imd.sterling.com>
  5. X-Md4-Signature: 97015015268469c6268a0794fb9fcf4d
  6. Date: Mon, 10 May 1993 21:34:08 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: fleurant@hri.com (P.Fleurant)
  10. Posting-number: Volume 37, Issue 41
  11. Archive-name: magiccube/part04
  12. Environment: X11, Motif, ANSI-C
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  cube/init_cubik.c cube/layer1c_txx.c cube/layer1edge_tb.c
  19. #   cube/layer1edge_tf.c cube/layer1edge_tl.c cube/layer1edge_tr.c
  20. #   cube/layer3flip.c cube/layer3twirl.c cube/lib/help_dialog.c
  21. #   cube/lib/quit.c cube/lib/talkto.c cube/lib/wprintf.c
  22. #   cube/lib/xmstr_to_str.c cube/taylor.c
  23. # Wrapped by kent@sparky on Mon May 10 16:15:41 1993
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 4 (of 5)."'
  27. if test -f 'cube/init_cubik.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'cube/init_cubik.c'\"
  29. else
  30.   echo shar: Extracting \"'cube/init_cubik.c'\" \(5166 characters\)
  31.   sed "s/^X//" >'cube/init_cubik.c' <<'END_OF_FILE'
  32. X/*The following references were used:
  33. X   "The X Window System Programming And Applications with Xt
  34. X   OSF/MOTIF EDITION"
  35. X   by Douglas A Young 
  36. X   Prentice-Hall, 1990.
  37. X   ISBN 0-13-642786-3
  38. X
  39. X   "Mastering Rubik's Cube"
  40. X   by Don Taylor
  41. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  42. X   ISBN 0-03-059941-5
  43. X
  44. X-------------------------------------------------------------------
  45. XCopyright (C) 1993 by Pierre A. Fleurant
  46. XPermission is granted to copy and distribute this program
  47. Xwithout charge, provided this copyright notice is included
  48. Xin the copy.
  49. XThis Software is distributed on an as-is basis. There will be
  50. XABSOLUTELY NO WARRANTY for any part of this software to work
  51. Xcorrect. In no case will the author be liable to you for damages
  52. Xcaused by the usage of this software.
  53. X-------------------------------------------------------------------
  54. X
  55. X  init_cubik
  56. X  This is a callback that creates a message box.
  57. X  The message box contains a pallette of colors 
  58. X  and 6 buttons (front, back, ...etc.) for each 
  59. X  side of the cube. 
  60. X   The user chooses a side which causes the main window's
  61. X  canvas to display the side. Then the user picks a color
  62. X  from the pallette. After this the uses clicks on the 
  63. X  canvas' cube subplane to init to this color.
  64. X   
  65. X  `OK' ends the operation.
  66. X  This is used with cube.c
  67. X                       popup(transientShell)
  68. X                        |
  69. X                       framework
  70. X                        |
  71. X               ---------|
  72. X               |        |
  73. X            message  command
  74. X                        |---------|
  75. X                        |         |
  76. X                      tiles      panel
  77. X              
  78. X */
  79. X#include "init_cubik.h"
  80. X#include "common.h"
  81. X
  82. Xvoid xcube_init_cubik(w, wdata, call_data) 
  83. X     Widget          w; 
  84. X     widget_data     *wdata;
  85. X     caddr_t         call_data;
  86. X{
  87. X  int        i,n;
  88. X  Widget     framework,message,command,tiles,panel;
  89. X  Arg        wargs[10];
  90. X  XmString   xmstr;
  91. X
  92. X  /*
  93. X   * Create the dialog 
  94. X   */
  95. X  wdata->popup = XtCreatePopupShell("Init_Cube",transientShellWidgetClass,
  96. X                 w,NULL,0);
  97. X
  98. X
  99. X  framework = XtCreateManagedWidget("popframework", 
  100. X                                    xmFormWidgetClass, 
  101. X                                    wdata->popup, NULL, 0);
  102. X
  103. X  /*
  104. X   * Count the text up to the first NULL string.
  105. X   */
  106. X  for(i=0; popup_str[i][0] != '\0'; i++)
  107. X    ;
  108. X  /*
  109. X   * Convert the string array to an XmString array and 
  110. X   * set it as the label text.
  111. X   */
  112. X  xmstr  = xs_str_array_to_xmstr(popup_str, i);
  113. X
  114. X  n = 0;
  115. X  XtSetArg(wargs[n],  XmNmessageString, xmstr);n++;
  116. X  /* add a message */
  117. X
  118. X  message = XtCreateManagedWidget("popmessage",
  119. X                  xmMessageBoxWidgetClass,
  120. X                  framework,wargs,n);
  121. X  /* Make the button say 'Done' instead of 'Ok' */
  122. X  xmstr = XmStringCreate("Done", XmSTRING_DEFAULT_CHARSET);
  123. X  n = 0;
  124. X  XtSetArg(wargs[n], XmNokLabelString, xmstr);     n++;
  125. X  XtSetValues(message, wargs, n);
  126. X  
  127. X  /* Add OK (Done) callback to pop down the dialog. */
  128. X  XtAddCallback(message, XmNokCallback, xcic_done_callback, wdata);
  129. X  
  130. X  /*
  131. X   * We won't be using the help and cancel widgets. Unmanage 'em.
  132. X   */
  133. X  XtUnmanageChild(XmMessageBoxGetChild (message,
  134. X                    XmDIALOG_HELP_BUTTON));
  135. X  XtUnmanageChild(XmMessageBoxGetChild (message,
  136. X                    XmDIALOG_CANCEL_BUTTON));
  137. X  
  138. X  /*
  139. X   * Create the column to hold pallette and side buttons (panel).
  140. X   */
  141. X  command = XtCreateManagedWidget("popcommand", 
  142. X                                  xmRowColumnWidgetClass, 
  143. X                                  framework, NULL, 0);
  144. X  
  145. X  /* add pallette */
  146. X  tiles = xss_create_pixmap_browser(command, 
  147. X                    seed_color,
  148. X                    6, /* sides */
  149. X                    set_fill_pattern, wdata->graph_pointer);
  150. X  /* add side buttons */
  151. X  panel = xss_create_label_wbutton(command, 
  152. X                   side_names,
  153. X                   6, /* sides */
  154. X                   set_cube_side, wdata);
  155. X  
  156. X  XtManageChild(tiles);
  157. X  XtManageChild(panel);
  158. X
  159. X  /* fix pallette orientation */
  160. X  n = 0;
  161. X  XtSetArg(wargs[n], XmNorientation,    XmHORIZONTAL);     n++;
  162. X  XtSetValues(tiles, wargs, n);
  163. X
  164. X  /* fix side names orientation */
  165. X  n = 0;
  166. X  XtSetArg(wargs[n], XmNorientation,    XmHORIZONTAL);     n++;
  167. X  XtSetValues(panel, wargs, n);
  168. X
  169. X  /* specifiy attachments */
  170. X  /* message */
  171. X  n = 0;
  172. X  XtSetArg(wargs[n], XmNtopAttachment,    XmATTACH_FORM);     n++;
  173. X  XtSetArg(wargs[n], XmNleftAttachment,   XmATTACH_FORM);     n++;
  174. X  XtSetValues(message, wargs, n);
  175. X
  176. X  /* command */
  177. X  n = 0;
  178. X  XtSetArg(wargs[n], XmNtopAttachment,    XmATTACH_WIDGET);   n++;
  179. X  XtSetArg(wargs[n], XmNtopWidget,        message);           n++;
  180. X  XtSetArg(wargs[n], XmNleftAttachment,   XmATTACH_FORM);     n++;
  181. X  XtSetValues(command, wargs, n);
  182. X
  183. X  /* 
  184. X     Cube must be inited because we can't orient back from
  185. X     an arbitrary r-s-f angle.
  186. X   */
  187. X  init_cube(wdata->canvas, wdata, NULL);
  188. X
  189. X  XtPopup(wdata->popup,XtGrabNone);
  190. X  
  191. X}
  192. X
  193. Xvoid xcic_done_callback(w, wdata, call_data) 
  194. X     Widget               w; 
  195. X     widget_data     *wdata;
  196. X     XmAnyCallbackStruct *call_data; 
  197. X{
  198. X  align_subfaces(w,wdata,call_data); /* update front[], left[],... */
  199. X  XtUnmanageChild(wdata->popup);
  200. X  XtDestroyWidget(wdata->popup);   
  201. X  /* reset */
  202. X  Fill_Pattern_Chosen = FALSE;
  203. X  Cube_Side_Chosen = FALSE;
  204. X}
  205. END_OF_FILE
  206.   if test 5166 -ne `wc -c <'cube/init_cubik.c'`; then
  207.     echo shar: \"'cube/init_cubik.c'\" unpacked with wrong size!
  208.   fi
  209.   # end of 'cube/init_cubik.c'
  210. fi
  211. if test -f 'cube/layer1c_txx.c' -a "${1}" != "-c" ; then 
  212.   echo shar: Will not clobber existing file \"'cube/layer1c_txx.c'\"
  213. else
  214.   echo shar: Extracting \"'cube/layer1c_txx.c'\" \(3422 characters\)
  215.   sed "s/^X//" >'cube/layer1c_txx.c' <<'END_OF_FILE'
  216. X/* layer1c_txx.c
  217. X   This incorporates Don Taylor's solution to the 
  218. X   Buvos Kocka (Hungarian Magic Cube). 
  219. X
  220. X   First Layer Corner Cube top/front/right
  221. X----------------------------------------------------------
  222. X   The following references were used:
  223. X   "The X Window System Programming And Applications with Xt
  224. X   OSF/MOTIF EDITION"
  225. X   by Douglas A Young 
  226. X   Prentice-Hall, 1990.
  227. X   ISBN 0-13-642786-3
  228. X
  229. X   "Mastering Rubik's Cube"
  230. X   by Don Taylor
  231. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  232. X   ISBN 0-03-059941-5
  233. X
  234. X-------------------------------------------------------------------
  235. XCopyright (C) 1993 by Pierre A. Fleurant
  236. XPermission is granted to copy and distribute this program
  237. Xwithout charge, provided this copyright notice is included
  238. Xin the copy.
  239. XThis Software is distributed on an as-is basis. There will be
  240. XABSOLUTELY NO WARRANTY for any part of this software to work
  241. Xcorrect. In no case will the author be liable to you for damages
  242. Xcaused by the usage of this software.
  243. X-------------------------------------------------------------------    
  244. X*/   
  245. X
  246. X#include "taylor.h"
  247. X
  248. Xextern void F(); /*  front  */
  249. Xextern void L(); /*  left   */
  250. Xextern void R(); /*  right  */
  251. Xextern void B(); /*  back   */
  252. Xextern void U(); /*  up     */
  253. Xextern void D(); /*  down   */
  254. X
  255. Xvoid first_layer_corner_tfr(w,wdata,call_data) /* These parameters needed for macros */
  256. X     Widget   w;
  257. X     widget_data *wdata;
  258. X     caddr_t  call_data;
  259. X{
  260. X  /* Top/Front/Right
  261. X   * The src cube in bottom layer is directly below
  262. X   * the destination cube in the top layer.
  263. X   * Operation depends where the TOP face is in the src cube.
  264. X   */
  265. X  
  266. X  if(Front(8) == TOP){
  267. X    F(1);D(1);F(-1);
  268. X    return;
  269. X  }
  270. X  else if(Right(6) == TOP){
  271. X    R(-1);D(-1);R(1);
  272. X    return;
  273. X  }
  274. X  else if(Bottom(2) == TOP){
  275. X    R(-1);D(1);R(1);D(2);
  276. X    R(-1);D(-1);R(1);
  277. X    return;
  278. X  }
  279. X}
  280. X
  281. Xvoid first_layer_corner_trb(w,wdata,call_data)
  282. X     Widget   w;
  283. X     widget_data *wdata;
  284. X     caddr_t  call_data;
  285. X{
  286. X  /* Top/Right/Back
  287. X   * The src cube in bottom layer is directly below
  288. X   * the destination cube in the top layer.
  289. X   * Operation depends where the TOP face is in the src cube.
  290. X   */
  291. X  
  292. X  if(Right(8) == TOP){
  293. X    R(1);D(1);R(-1);
  294. X    return;
  295. X  }
  296. X  else if(Back(8) == TOP){
  297. X    B(-1);D(-1);B(1);
  298. X    return;
  299. X  }
  300. X  else if(Bottom(8) == TOP){
  301. X    B(-1);D(1);B(1);D(2);
  302. X    B(-1);D(-1);B(1);
  303. X    return;
  304. X  }
  305. X}
  306. X
  307. Xvoid first_layer_corner_tbl(w,wdata,call_data)
  308. X     Widget   w;
  309. X     widget_data *wdata;
  310. X     caddr_t  call_data;
  311. X{
  312. X  /* Top/Back/Left
  313. X   * The src cube in bottom layer is directly below
  314. X   * the destination cube in the top layer.
  315. X   * Operation depends where the TOP face is in the src cube.
  316. X   */
  317. X  
  318. X  if(Back(6) == TOP){
  319. X    B(1);D(1);B(-1);
  320. X    return;
  321. X  }
  322. X  else if(Left(8) == TOP){
  323. X    L(-1);D(-1);L(1);
  324. X    return;
  325. X  }
  326. X  else if(Bottom(6) == TOP){
  327. X    L(-1);D(1);L(1);D(2);
  328. X    L(-1);D(-1);L(1);
  329. X    return;
  330. X  }
  331. X}
  332. X
  333. Xvoid first_layer_corner_tlf(w,wdata,call_data)
  334. X     Widget   w;
  335. X     widget_data *wdata;
  336. X     caddr_t  call_data;
  337. X{
  338. X  /* Top/Left/Front
  339. X   * The src cube in bottom layer is directly below
  340. X   * the destination cube in the top layer.
  341. X   * Operation depends where the TOP face is in the src cube.
  342. X   */
  343. X  
  344. X  if(Left(6) == TOP){
  345. X    L(1);D(1);L(-1);
  346. X    return;
  347. X  }
  348. X  else if(Front(6) == TOP){
  349. X    F(-1);D(-1);F(1);
  350. X    return;
  351. X  }
  352. X  else if(Bottom(0) == TOP){
  353. X    F(-1);D(1);F(1);D(2);
  354. X    F(-1);D(-1);F(1);
  355. X    return;
  356. X  }
  357. X}
  358. X
  359. X
  360. X
  361. X
  362. END_OF_FILE
  363.   if test 3422 -ne `wc -c <'cube/layer1c_txx.c'`; then
  364.     echo shar: \"'cube/layer1c_txx.c'\" unpacked with wrong size!
  365.   fi
  366.   # end of 'cube/layer1c_txx.c'
  367. fi
  368. if test -f 'cube/layer1edge_tb.c' -a "${1}" != "-c" ; then 
  369.   echo shar: Will not clobber existing file \"'cube/layer1edge_tb.c'\"
  370. else
  371.   echo shar: Extracting \"'cube/layer1edge_tb.c'\" \(3460 characters\)
  372.   sed "s/^X//" >'cube/layer1edge_tb.c' <<'END_OF_FILE'
  373. X/* layer1edge_tb.c
  374. X   This incorporates Don Taylor's solution to the 
  375. X   Buvos Kocka (Hungarian Magic Cube). 
  376. X
  377. X   First Layer Edge Cube top/back
  378. X
  379. X
  380. X   The following references were used:
  381. X   "The X Window System Programming And Applications with Xt
  382. X   OSF/MOTIF EDITION"
  383. X   by Douglas A Young 
  384. X   Prentice-Hall, 1990.
  385. X   ISBN 0-13-642786-3
  386. X
  387. X   "Mastering Rubik's Cube"
  388. X   by Don Taylor
  389. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  390. X   ISBN 0-03-059941-5
  391. X
  392. X-------------------------------------------------------------------
  393. XCopyright (C) 1993 by Pierre A. Fleurant
  394. XPermission is granted to copy and distribute this program
  395. Xwithout charge, provided this copyright notice is included
  396. Xin the copy.
  397. XThis Software is distributed on an as-is basis. There will be
  398. XABSOLUTELY NO WARRANTY for any part of this software to work
  399. Xcorrect. In no case will the author be liable to you for damages
  400. Xcaused by the usage of this software.
  401. X-------------------------------------------------------------------    
  402. X*/   
  403. X
  404. X#include "taylor.h"
  405. X
  406. Xextern void F(); /*  front  */
  407. Xextern void L(); /*  left   */
  408. Xextern void R(); /*  right  */
  409. Xextern void B(); /*  back   */
  410. Xextern void U(); /*  up     */
  411. Xextern void D(); /*  down   */
  412. X
  413. Xvoid first_layer_edge_cube_tb(w,wdata,call_data) /* These parameters needed for macros */
  414. X     Widget   w;
  415. X     widget_data *wdata;
  416. X     caddr_t  call_data;
  417. X{
  418. X  /* Top/Right */
  419. X  /* Search for the Top/Back edge cube.
  420. X     There are 12 edge cubes in all,
  421. X     with 2 possible configurations: Top/Back
  422. X     or Back/Top.
  423. X     */
  424. X  
  425. X  /* Top edge cubes */
  426. X  if(Top(1) == BACK && Front(1) == TOP){
  427. X    F(2);D(-1);L(1);B(-1);L(-1);
  428. X  }
  429. X  
  430. X  else if(Top(5) == BACK && Right(1) == TOP){
  431. X    R(1);B(1);
  432. X  }
  433. X  
  434. X  else if(Top(7) == BACK && Back(1) == TOP){
  435. X    B(2);D(1);L(1);B(-1);L(-1);
  436. X  } 
  437. X  
  438. X  else if(Top(3) == BACK && Left(1) == TOP){
  439. X    L(-1);B(-1);
  440. X  }
  441. X
  442. X
  443. X
  444. X  
  445. X  else if(Top(1) == TOP && Front(1) == BACK){
  446. X    F(2);D(2);B(2);
  447. X  }
  448. X  
  449. X  else if(Top(5) == TOP && Right(1) == BACK){
  450. X    R(2);D(1);B(2);
  451. X  }
  452. X  
  453. X  else if(Top(7) == TOP && Back(1) == BACK){
  454. X    /* the correct one */ 
  455. X    ;
  456. X  } 
  457. X  
  458. X  else if(Top(3) == TOP && Left(1) == BACK){
  459. X    L(2);D(-1);B(2);
  460. X  }
  461. X
  462. X
  463. X
  464. X  /* middle edge cubes */ 
  465. X  else if(Front(5) == BACK && Right(3) == TOP){
  466. X    F(1);D(2);F(-1);B(2);
  467. X  }
  468. X  
  469. X  else if(Right(5) == BACK && Back(5) == TOP){
  470. X    R(1);D(1);R(-1);B(2);
  471. X  }
  472. X  
  473. X  else if(Back(3) == BACK && Left(5) == TOP){
  474. X    B(-1);
  475. X  } 
  476. X
  477. X  else if(Left(3) == BACK && Front(3) == TOP){
  478. X    F(-1);D(-1);F(1);L(1);B(-1);L(-1);
  479. X  }
  480. X
  481. X
  482. X
  483. X  else if(Front(5) == TOP && Right(3) == BACK){
  484. X    F(1);D(-1);F(-1);L(1);B(-1);L(-1);
  485. X  }
  486. X
  487. X  else if(Right(5) == TOP && Back(5) == BACK){
  488. X    B(1);
  489. X  }
  490. X
  491. X  else if(Back(3) == TOP && Left(5) == BACK){
  492. X    B(1);D(1);L(1);B(-1);L(-1);
  493. X  } 
  494. X
  495. X  else if(Left(3) == TOP && Front(3) == BACK){
  496. X    L(2);B(-1);L(-2);
  497. X  }
  498. X
  499. X
  500. X  /* Bottom edge cubes */
  501. X  else if(Bottom(1) == BACK && Front(7) == TOP){
  502. X    D(-1);L(1);B(-1);L(-1);
  503. X  }
  504. X  
  505. X  else if(Bottom(5) == BACK && Right(7) == TOP){
  506. X    R(-1);B(1);R(1);
  507. X  }
  508. X  
  509. X  else if(Bottom(7) == BACK && Back(7) == TOP){
  510. X    D(1);L(1);B(-1);L(-1);
  511. X  } 
  512. X  
  513. X  else if(Bottom(3) == BACK && Left(7) == TOP){
  514. X    L(1);B(-1);L(-1);
  515. X  }
  516. X
  517. X
  518. X  else if(Bottom(1) == TOP && Front(7) == BACK){
  519. X    D(2);B(2);
  520. X  }
  521. X
  522. X  else if(Bottom(5) == TOP && Right(7) == BACK){
  523. X    D(1);B(2);
  524. X  }
  525. X
  526. X  else if(Bottom(7) == TOP && Back(7) == BACK){
  527. X    B(2);
  528. X  } 
  529. X
  530. X  else if(Bottom(3) == TOP && Left(7) == BACK){
  531. X    D(-1);B(2);
  532. X  }
  533. X}
  534. X
  535. X
  536. X
  537. X
  538. END_OF_FILE
  539.   if test 3460 -ne `wc -c <'cube/layer1edge_tb.c'`; then
  540.     echo shar: \"'cube/layer1edge_tb.c'\" unpacked with wrong size!
  541.   fi
  542.   # end of 'cube/layer1edge_tb.c'
  543. fi
  544. if test -f 'cube/layer1edge_tf.c' -a "${1}" != "-c" ; then 
  545.   echo shar: Will not clobber existing file \"'cube/layer1edge_tf.c'\"
  546. else
  547.   echo shar: Extracting \"'cube/layer1edge_tf.c'\" \(3480 characters\)
  548.   sed "s/^X//" >'cube/layer1edge_tf.c' <<'END_OF_FILE'
  549. X/* layer1edge_tf.c
  550. X   This incorporates Don Taylor's solution to the 
  551. X   Buvos Kocka (Hungarian Magic Cube). 
  552. X
  553. X   First Layer Edge Cube top/front
  554. X   
  555. XThe following references were used:
  556. X   "The X Window System Programming And Applications with Xt
  557. X   OSF/MOTIF EDITION"
  558. X   by Douglas A Young 
  559. X   Prentice-Hall, 1990.
  560. X   ISBN 0-13-642786-3
  561. X
  562. X   "Mastering Rubik's Cube"
  563. X   by Don Taylor
  564. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  565. X   ISBN 0-03-059941-5
  566. X
  567. X-------------------------------------------------------------------
  568. XCopyright (C) 1993 by Pierre A. Fleurant
  569. XPermission is granted to copy and distribute this program
  570. Xwithout charge, provided this copyright notice is included
  571. Xin the copy.
  572. XThis Software is distributed on an as-is basis. There will be
  573. XABSOLUTELY NO WARRANTY for any part of this software to work
  574. Xcorrect. In no case will the author be liable to you for damages
  575. Xcaused by the usage of this software.
  576. X-------------------------------------------------------------------    
  577. X*/   
  578. X
  579. X#include "taylor.h"
  580. X
  581. Xextern void F(); /*  front  */
  582. Xextern void L(); /*  left   */
  583. Xextern void R(); /*  right  */
  584. Xextern void B(); /*  back   */
  585. Xextern void U(); /*  up     */
  586. Xextern void D(); /*  down   */
  587. X
  588. Xvoid first_layer_edge_cube_tf(w,wdata,call_data) /* These parameters needed for macros */
  589. X     Widget   w;
  590. X     widget_data *wdata;
  591. X     caddr_t  call_data;
  592. X{
  593. X  /* Top/Front */
  594. X  /* Search for the Top/Front edge cube.
  595. X     There are 12 edge cubes in all,
  596. X     with 2 possible configurations: Top/Front
  597. X     or Front/Top.
  598. X     */
  599. X  
  600. X  /* Top edge cubes */
  601. X  if(Top(1) == FRONT && Front(1) == TOP){
  602. X    F(2);D(1);R(1);F(-1);R(-1);
  603. X  }
  604. X  
  605. X  else if(Top(5) == FRONT && Right(1) == TOP){
  606. X    R(-1);F(-1);
  607. X  }
  608. X  
  609. X  else if(Top(7) == FRONT && Back(1) == TOP){
  610. X    B(2);D(-1);R(1);F(-1);R(-1);
  611. X  } 
  612. X  
  613. X  else if(Top(3) == FRONT && Left(1) == TOP){
  614. X    L(1);F(1);
  615. X  }
  616. X
  617. X
  618. X  
  619. X  else if(Top(1) == TOP && Front(1) == FRONT){
  620. X    /* the correct one */ 
  621. X    ;
  622. X  }
  623. X  
  624. X  else if(Top(5) == TOP && Right(1) == FRONT){
  625. X    R(2);D(-1);F(2);
  626. X  }
  627. X  
  628. X  else if(Top(7) == TOP && Back(1) == FRONT){
  629. X    B(2);D(2);F(2);
  630. X  } 
  631. X  
  632. X  else if(Top(3) == TOP && Left(1) == FRONT){
  633. X    L(2);D(1);F(2);
  634. X  }
  635. X
  636. X  /* middle edge cubes */ 
  637. X  else if(Front(5) == FRONT && Right(3) == TOP){
  638. X    F(-1);
  639. X  }
  640. X  
  641. X  else if(Right(5) == FRONT && Back(5) == TOP){
  642. X    B(-1);D(-1);B(1);R(1);F(-1);R(-1);
  643. X  }
  644. X  
  645. X  else if(Back(3) == FRONT && Left(5) == TOP){
  646. X    B(1);D(2);B(-1);F(2);
  647. X  } 
  648. X
  649. X  else if(Left(3) == FRONT && Front(3) == TOP){
  650. X    L(1);D(1);L(-1);F(2);
  651. X  }
  652. X
  653. X
  654. X
  655. X  else if(Front(5) == TOP && Right(3) == FRONT){
  656. X    F(1);D(1);R(1);F(-1);R(-1);
  657. X  }
  658. X
  659. X  else if(Right(5) == TOP && Back(5) == FRONT){
  660. X    R(2);F(-1);R(-2);
  661. X  }
  662. X
  663. X  else if(Back(3) == TOP && Left(5) == FRONT){
  664. X    B(1);D(-1);B(-1);R(1);F(-1);R(-1);
  665. X  } 
  666. X
  667. X  else if(Left(3) == TOP && Front(3) == FRONT){
  668. X    F(1);
  669. X  }
  670. X
  671. X
  672. X  /* Bottom edge cubes */
  673. X  else if(Bottom(1) == FRONT && Front(7) == TOP){
  674. X    D(1);R(1);F(-1);R(-1);
  675. X  }
  676. X  
  677. X  else if(Bottom(5) == FRONT && Right(7) == TOP){
  678. X    R(1);F(-1);R(-1);
  679. X  }
  680. X
  681. X  else if(Bottom(7) == FRONT && Back(7) == TOP){
  682. X    D(-1);R(1);F(-1);R(-1);
  683. X  } 
  684. X
  685. X  else if(Bottom(3) == FRONT && Left(7) == TOP){
  686. X    L(-1);F(1);L(1);
  687. X  }
  688. X
  689. X
  690. X  else if(Bottom(1) == TOP && Front(7) == FRONT){
  691. X    F(2);
  692. X  }
  693. X
  694. X  else if(Bottom(5) == TOP && Right(7) == FRONT){
  695. X    D(-1);F(2);
  696. X  }
  697. X
  698. X  else if(Bottom(7) == TOP && Back(7) == FRONT){
  699. X    D(2);F(2);
  700. X  } 
  701. X
  702. X  else if(Bottom(3) == TOP && Left(7) == FRONT){
  703. X    D(1);F(2);
  704. X  }
  705. X}
  706. X
  707. X
  708. X
  709. X
  710. END_OF_FILE
  711.   if test 3480 -ne `wc -c <'cube/layer1edge_tf.c'`; then
  712.     echo shar: \"'cube/layer1edge_tf.c'\" unpacked with wrong size!
  713.   fi
  714.   # end of 'cube/layer1edge_tf.c'
  715. fi
  716. if test -f 'cube/layer1edge_tl.c' -a "${1}" != "-c" ; then 
  717.   echo shar: Will not clobber existing file \"'cube/layer1edge_tl.c'\"
  718. else
  719.   echo shar: Extracting \"'cube/layer1edge_tl.c'\" \(3461 characters\)
  720.   sed "s/^X//" >'cube/layer1edge_tl.c' <<'END_OF_FILE'
  721. X/* layer1edge_tl.c
  722. X   This incorporates Don Taylor's solution to the 
  723. X   Buvos Kocka (Hungarian Magic Cube). 
  724. X
  725. X   First Layer Edge Cube top/back
  726. X   
  727. X
  728. XThe following references were used:
  729. X   "The X Window System Programming And Applications with Xt
  730. X   OSF/MOTIF EDITION"
  731. X   by Douglas A Young 
  732. X   Prentice-Hall, 1990.
  733. X   ISBN 0-13-642786-3
  734. X
  735. X   "Mastering Rubik's Cube"
  736. X   by Don Taylor
  737. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  738. X   ISBN 0-03-059941-5
  739. X
  740. X-------------------------------------------------------------------
  741. XCopyright (C) 1993 by Pierre A. Fleurant
  742. XPermission is granted to copy and distribute this program
  743. Xwithout charge, provided this copyright notice is included
  744. Xin the copy.
  745. XThis Software is distributed on an as-is basis. There will be
  746. XABSOLUTELY NO WARRANTY for any part of this software to work
  747. Xcorrect. In no case will the author be liable to you for damages
  748. Xcaused by the usage of this software.
  749. X------------------------------------------------------------------- 
  750. X*/   
  751. X
  752. X#include "taylor.h"
  753. X
  754. Xextern void F(); /*  front  */
  755. Xextern void L(); /*  left   */
  756. Xextern void R(); /*  right  */
  757. Xextern void B(); /*  back   */
  758. Xextern void U(); /*  up     */
  759. Xextern void D(); /*  down   */
  760. X
  761. Xvoid first_layer_edge_cube_tl(w,wdata,call_data) /* These parameters needed for macros */
  762. X     Widget   w;
  763. X     widget_data *wdata;
  764. X     caddr_t  call_data;
  765. X{
  766. X  /* Top/Right */
  767. X  /* Search for the Top/Left edge cube.
  768. X     There are 12 edge cubes in all,
  769. X     with 2 possible configurations: Top/Left
  770. X     or Left/Top.
  771. X     */
  772. X  
  773. X  /* Top edge cubes */
  774. X  if(Top(1) == LEFT && Front(1) == TOP){
  775. X    F(-1);L(-1);
  776. X  }
  777. X  
  778. X  else if(Top(5) == LEFT && Right(1) == TOP){
  779. X    R(2);D(-1);F(1);L(-1);F(-1);
  780. X  }
  781. X  
  782. X  else if(Top(7) == LEFT && Back(1) == TOP){
  783. X    B(1);L(1);
  784. X  } 
  785. X  
  786. X  else if(Top(3) == LEFT && Left(1) == TOP){
  787. X    L(2);D(1);F(1);L(-1);F(-1);
  788. X  }
  789. X
  790. X  
  791. X
  792. X
  793. X  else if(Top(1) == TOP && Front(1) == LEFT){
  794. X    F(2);D(-1);L(2);
  795. X  }
  796. X  
  797. X  else if(Top(5) == TOP && Right(1) == LEFT){
  798. X    R(2);D(2);L(2);
  799. X  }
  800. X  
  801. X  else if(Top(7) == TOP && Back(1) == LEFT){
  802. X    B(2);D(1);L(2);
  803. X  } 
  804. X  
  805. X  else if(Top(3) == TOP && Left(1) == LEFT){
  806. X    /* the correct one */ 
  807. X    ;
  808. X  }
  809. X
  810. X
  811. X
  812. X  /* middle edge cubes */ 
  813. X  else if(Front(5) == LEFT && Right(3) == TOP){
  814. X    R(-1);D(-1);R(1);F(1);L(-1);F(-1);
  815. X  }
  816. X  
  817. X  else if(Right(5) == LEFT && Back(5) == TOP){
  818. X    R(1);D(2);R(-1);L(2);
  819. X  }
  820. X  
  821. X  else if(Back(3) == LEFT && Left(5) == TOP){
  822. X    B(1);D(1);B(-1);L(2);
  823. X  } 
  824. X
  825. X  else if(Left(3) == LEFT && Front(3) == TOP){
  826. X    L(-1);
  827. X  }
  828. X
  829. X
  830. X
  831. X
  832. X  else if(Front(5) == TOP && Right(3) == LEFT){
  833. X    F(2);L(-1);F(-2);
  834. X  }
  835. X
  836. X  else if(Right(5) == TOP && Back(5) == LEFT){
  837. X    R(1);D(-1);R(-1);F(1);L(-1);F(-1);
  838. X  }
  839. X
  840. X  else if(Back(3) == TOP && Left(5) == LEFT){
  841. X    L(1);
  842. X  } 
  843. X
  844. X  else if(Left(3) == TOP && Front(3) == LEFT){
  845. X    L(1);D(1);F(1);L(-1);F(-1);
  846. X  }
  847. X
  848. X
  849. X
  850. X  /* Bottom edge cubes */
  851. X  else if(Bottom(1) == LEFT && Front(7) == TOP){
  852. X    F(1);L(-1);F(-1);
  853. X  }
  854. X  
  855. X  else if(Bottom(5) == LEFT && Right(7) == TOP){
  856. X    D(-1);F(1);L(-1);F(-1);
  857. X  }
  858. X  
  859. X  else if(Bottom(7) == LEFT && Back(7) == TOP){
  860. X    B(-1);L(1);B(1);
  861. X  } 
  862. X  
  863. X  else if(Bottom(3) == LEFT && Left(7) == TOP){
  864. X    D(1);F(1);L(-1);F(-1);
  865. X  }
  866. X
  867. X
  868. X
  869. X
  870. X  else if(Bottom(1) == TOP && Front(7) == LEFT){
  871. X    D(-1);L(2);
  872. X  }
  873. X
  874. X  else if(Bottom(5) == TOP && Right(7) == LEFT){
  875. X    D(2);L(2);
  876. X  }
  877. X
  878. X  else if(Bottom(7) == TOP && Back(7) == LEFT){
  879. X    D(1);L(2);
  880. X  } 
  881. X
  882. X  else if(Bottom(3) == TOP && Left(7) == LEFT){
  883. X    L(2);
  884. X  }
  885. X}
  886. X
  887. X
  888. X
  889. X
  890. END_OF_FILE
  891.   if test 3461 -ne `wc -c <'cube/layer1edge_tl.c'`; then
  892.     echo shar: \"'cube/layer1edge_tl.c'\" unpacked with wrong size!
  893.   fi
  894.   # end of 'cube/layer1edge_tl.c'
  895. fi
  896. if test -f 'cube/layer1edge_tr.c' -a "${1}" != "-c" ; then 
  897.   echo shar: Will not clobber existing file \"'cube/layer1edge_tr.c'\"
  898. else
  899.   echo shar: Extracting \"'cube/layer1edge_tr.c'\" \(3483 characters\)
  900.   sed "s/^X//" >'cube/layer1edge_tr.c' <<'END_OF_FILE'
  901. X/* layer1edge_tr.c
  902. X   This incorporates Don Taylor's solution to the 
  903. X   Buvos Kocka (Hungarian Magic Cube). 
  904. X
  905. X   First Layer Edge Cube top/front
  906. X
  907. X
  908. X   The following references were used:
  909. X   "The X Window System Programming And Applications with Xt
  910. X   OSF/MOTIF EDITION"
  911. X   by Douglas A Young 
  912. X   Prentice-Hall, 1990.
  913. X   ISBN 0-13-642786-3
  914. X
  915. X   "Mastering Rubik's Cube"
  916. X   by Don Taylor
  917. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  918. X   ISBN 0-03-059941-5
  919. X
  920. X-------------------------------------------------------------------
  921. XCopyright (C) 1993 by Pierre A. Fleurant
  922. XPermission is granted to copy and distribute this program
  923. Xwithout charge, provided this copyright notice is included
  924. Xin the copy.
  925. XThis Software is distributed on an as-is basis. There will be
  926. XABSOLUTELY NO WARRANTY for any part of this software to work
  927. Xcorrect. In no case will the author be liable to you for damages
  928. Xcaused by the usage of this software.
  929. X-------------------------------------------------------------------    
  930. X*/   
  931. X
  932. X#include "taylor.h"
  933. X
  934. Xextern void F(); /*  front  */
  935. Xextern void L(); /*  left   */
  936. Xextern void R(); /*  right  */
  937. Xextern void B(); /*  back   */
  938. Xextern void U(); /*  up     */
  939. Xextern void D(); /*  down   */
  940. X
  941. Xvoid first_layer_edge_cube_tr(w,wdata,call_data) /* These parameters needed for macros */
  942. X     Widget   w;
  943. X     widget_data *wdata;
  944. X     caddr_t  call_data;
  945. X{
  946. X  /* Top/Right */
  947. X  /* Search for the Top/Right edge cube.
  948. X     There are 12 edge cubes in all,
  949. X     with 2 possible configurations: Top/Right
  950. X     or Right/Top.
  951. X     */
  952. X  
  953. X  /* Top edge cubes */
  954. X  if(Top(1) == RIGHT && Front(1) == TOP){
  955. X    F(1);R(1);
  956. X  }
  957. X  
  958. X  else if(Top(5) == RIGHT && Right(1) == TOP){
  959. X    R(2);D(1);B(1);R(-1);B(-1);
  960. X  }
  961. X  
  962. X  else if(Top(7) == RIGHT && Back(1) == TOP){
  963. X    B(-1);R(-1);
  964. X  } 
  965. X  
  966. X  else if(Top(3) == RIGHT && Left(1) == TOP){
  967. X    L(2);D(-1);B(1);R(-1);B(-1);
  968. X  }
  969. X  
  970. X
  971. X  
  972. X  else if(Top(1) == TOP && Front(1) == RIGHT){
  973. X    F(2);D(1);R(2);
  974. X  }
  975. X  
  976. X  else if(Top(5) == TOP && Right(1) == RIGHT){
  977. X    /* the correct one */ 
  978. X    ;
  979. X  }
  980. X  
  981. X  else if(Top(7) == TOP && Back(1) == RIGHT){
  982. X    B(2);D(-1);R(2);
  983. X  } 
  984. X  
  985. X  else if(Top(3) == TOP && Left(1) == RIGHT){
  986. X    L(2);D(2);R(2);
  987. X  }
  988. X
  989. X  /* middle edge cubes */ 
  990. X  else if(Front(5) == RIGHT && Right(3) == TOP){
  991. X    F(1);D(1);F(-1);R(2);
  992. X  }
  993. X  
  994. X  else if(Right(5) == RIGHT && Back(5) == TOP){
  995. X    R(-1);
  996. X  }
  997. X  
  998. X  else if(Back(3) == RIGHT && Left(5) == TOP){
  999. X    L(-1);D(-1);L(1);B(1);R(-1);B(-1);
  1000. X  } 
  1001. X
  1002. X  else if(Left(3) == RIGHT && Front(3) == TOP){
  1003. X    L(1);D(2);L(-1);R(2);
  1004. X  }
  1005. X
  1006. X
  1007. X
  1008. X  else if(Front(5) == TOP && Right(3) == RIGHT){
  1009. X    R(1);
  1010. X  }
  1011. X
  1012. X  else if(Right(5) == TOP && Back(5) == RIGHT){
  1013. X    R(1);D(1);B(1);R(-1);B(-1);
  1014. X  }
  1015. X
  1016. X  else if(Back(3) == TOP && Left(5) == RIGHT){
  1017. X    B(2);R(-1);B(-2);
  1018. X  } 
  1019. X
  1020. X  else if(Left(3) == TOP && Front(3) == RIGHT){
  1021. X    L(1);D(-1);L(-1);B(1);R(-1);B(-1);
  1022. X  }
  1023. X
  1024. X
  1025. X  /* Bottom edge cubes */
  1026. X  else if(Bottom(1) == RIGHT && Front(7) == TOP){
  1027. X    F(-1);R(1);F(1);
  1028. X  }
  1029. X  
  1030. X  else if(Bottom(5) == RIGHT && Right(7) == TOP){
  1031. X    D(1);B(1);R(-1);B(-1);
  1032. X  }
  1033. X
  1034. X  else if(Bottom(7) == RIGHT && Back(7) == TOP){
  1035. X    B(1);R(-1);B(-1);
  1036. X  } 
  1037. X
  1038. X  else if(Bottom(3) == RIGHT && Left(7) == TOP){
  1039. X    D(-1);B(1);R(-1);B(-1);
  1040. X  }
  1041. X
  1042. X
  1043. X  else if(Bottom(1) == TOP && Front(7) == RIGHT){
  1044. X    D(1);R(2);
  1045. X  }
  1046. X
  1047. X  else if(Bottom(5) == TOP && Right(7) == RIGHT){
  1048. X    R(2);
  1049. X  }
  1050. X
  1051. X  else if(Bottom(7) == TOP && Back(7) == RIGHT){
  1052. X    D(-1);R(2);
  1053. X  } 
  1054. X
  1055. X  else if(Bottom(3) == TOP && Left(7) == RIGHT){
  1056. X    D(2);R(2);
  1057. X  }
  1058. X}
  1059. X
  1060. X
  1061. X
  1062. X
  1063. END_OF_FILE
  1064.   if test 3483 -ne `wc -c <'cube/layer1edge_tr.c'`; then
  1065.     echo shar: \"'cube/layer1edge_tr.c'\" unpacked with wrong size!
  1066.   fi
  1067.   # end of 'cube/layer1edge_tr.c'
  1068. fi
  1069. if test -f 'cube/layer3flip.c' -a "${1}" != "-c" ; then 
  1070.   echo shar: Will not clobber existing file \"'cube/layer3flip.c'\"
  1071. else
  1072.   echo shar: Extracting \"'cube/layer3flip.c'\" \(3595 characters\)
  1073.   sed "s/^X//" >'cube/layer3flip.c' <<'END_OF_FILE'
  1074. X/* layer3flip.c
  1075. X   This incorporates Don Taylor's solution to the 
  1076. X   Buvos Kocka (Hungarian Magic Cube). 
  1077. X
  1078. X   Last Layer Cubes
  1079. X
  1080. X   Flip edge cubes.
  1081. X
  1082. XThe following references were used:
  1083. X   "The X Window System Programming And Applications with Xt
  1084. X   OSF/MOTIF EDITION"
  1085. X   by Douglas A Young 
  1086. X   Prentice-Hall, 1990.
  1087. X   ISBN 0-13-642786-3
  1088. X
  1089. X   "Mastering Rubik's Cube"
  1090. X   by Don Taylor
  1091. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  1092. X   ISBN 0-03-059941-5
  1093. X
  1094. X-------------------------------------------------------------------
  1095. XCopyright (C) 1993 by Pierre A. Fleurant
  1096. XPermission is granted to copy and distribute this program
  1097. Xwithout charge, provided this copyright notice is included
  1098. Xin the copy.
  1099. XThis Software is distributed on an as-is basis. There will be
  1100. XABSOLUTELY NO WARRANTY for any part of this software to work
  1101. Xcorrect. In no case will the author be liable to you for damages
  1102. Xcaused by the usage of this software.
  1103. X-------------------------------------------------------------------
  1104. X*/   
  1105. X
  1106. X#include "taylor.h"
  1107. X
  1108. Xextern void F(); /*  front  */
  1109. Xextern void L(); /*  left   */
  1110. Xextern void R(); /*  right  */
  1111. Xextern void B(); /*  back   */
  1112. Xextern void U(); /*  up     */
  1113. Xextern void D(); /*  down   */
  1114. X
  1115. XBoolean flip(w,wdata,call_data) /* These parameters needed for macros */
  1116. X     Widget   w;
  1117. X     widget_data *wdata;
  1118. X     caddr_t  call_data;
  1119. X{
  1120. X  /* Test if ok */
  1121. X  if(Front(7) == FRONT &&
  1122. X     Right(7) == RIGHT &&
  1123. X     Back(7)  == BACK  &&
  1124. X     Left(7)  == LEFT)
  1125. X    return(True);
  1126. X
  1127. X  /* Here if not ok 
  1128. X   * Flip corners   
  1129. X   * There are always an even number of cubes that nedd to be flipped.
  1130. X   *
  1131. X   * Look for an edge that needs to be flipped.
  1132. X   */
  1133. X  if(Front(7) == BOTTOM){
  1134. X    F(1);D(1);U(-1);R(2);D(2);U(2);L(1);
  1135. X    if(Left(7) == BOTTOM){
  1136. X      L(-1);U(2);D(2);R(2);U(1);D(-1);F(-1);
  1137. X    }
  1138. X    else if(Back(7) == BOTTOM){
  1139. X      D(1);
  1140. X      L(-1);U(2);D(2);R(2);U(1);D(-1);F(-1);
  1141. X      D(-1);
  1142. X    }
  1143. X    else if(Right(7) == BOTTOM){
  1144. X      D(2);
  1145. X      L(-1);U(2);D(2);R(2);U(1);D(-1);F(-1);
  1146. X      D(2);
  1147. X    }
  1148. X    else if(Front(7) == BOTTOM){
  1149. X      D(-1);
  1150. X      L(-1);U(2);D(2);R(2);U(1);D(-1);F(-1);
  1151. X      D(1);
  1152. X    }
  1153. X  }
  1154. X  else if(Right(7) == BOTTOM){
  1155. X    R(1);D(1);U(-1);B(2);D(2);U(2);F(1);
  1156. X    if(Front(7) == BOTTOM){
  1157. X      F(-1);U(2);D(2);B(2);U(1);D(-1);R(-1);
  1158. X    }
  1159. X    else if(Left(7) == BOTTOM){
  1160. X      D(1);
  1161. X      F(-1);U(2);D(2);B(2);U(1);D(-1);R(-1);
  1162. X      D(-1);
  1163. X    }
  1164. X    else if(Back(7) == BOTTOM){
  1165. X      D(2);
  1166. X      F(-1);U(2);D(2);B(2);U(1);D(-1);R(-1);
  1167. X      D(2);
  1168. X    }
  1169. X    else if(Right(7) == BOTTOM){
  1170. X      D(-1);
  1171. X      F(-1);U(2);D(2);B(2);U(1);D(-1);R(-1);
  1172. X      D(1);
  1173. X    }
  1174. X  }
  1175. X  else if(Back(7) == BOTTOM){
  1176. X    B(1);D(1);U(-1);L(2);D(2);U(2);R(1);
  1177. X    if(Right(7) == BOTTOM){
  1178. X      R(-1);U(2);D(2);L(2);U(1);D(-1);B(-1);
  1179. X    }
  1180. X    else if(Front(7) == BOTTOM){
  1181. X      D(1);
  1182. X      R(-1);U(2);D(2);L(2);U(1);D(-1);B(-1);
  1183. X      D(-1);
  1184. X    }
  1185. X    else if(Left(7) == BOTTOM){
  1186. X      D(2);
  1187. X      R(-1);U(2);D(2);L(2);U(1);D(-1);B(-1);
  1188. X      D(2);
  1189. X    }
  1190. X    else if(Back(7) == BOTTOM){
  1191. X      D(-1);
  1192. X      R(-1);U(2);D(2);L(2);U(1);D(-1);B(-1);
  1193. X      D(1);
  1194. X    }
  1195. X  }
  1196. X  else if(Left(7) == BOTTOM){
  1197. X    L(1);D(1);U(-1);F(2);D(2);U(2);B(1);
  1198. X    if(Back(7) == BOTTOM){
  1199. X      B(-1);U(2);D(2);F(2);U(1);D(-1);L(-1);
  1200. X    }
  1201. X    else if(Right(7) == BOTTOM){
  1202. X      D(1);
  1203. X      B(-1);U(2);D(2);F(2);U(1);D(-1);L(-1);
  1204. X      D(-1);
  1205. X    }
  1206. X    else if(Front(7) == BOTTOM){
  1207. X      D(2);
  1208. X      B(-1);U(2);D(2);F(2);U(1);D(-1);L(-1);
  1209. X      D(2);
  1210. X    }
  1211. X    else if(Left(7) == BOTTOM){
  1212. X      D(-1);
  1213. X      B(-1);U(2);D(2);F(2);U(1);D(-1);L(-1);
  1214. X      D(1);
  1215. X    }
  1216. X  }
  1217. X  return(False);
  1218. X}
  1219. END_OF_FILE
  1220.   if test 3595 -ne `wc -c <'cube/layer3flip.c'`; then
  1221.     echo shar: \"'cube/layer3flip.c'\" unpacked with wrong size!
  1222.   fi
  1223.   # end of 'cube/layer3flip.c'
  1224. fi
  1225. if test -f 'cube/layer3twirl.c' -a "${1}" != "-c" ; then 
  1226.   echo shar: Will not clobber existing file \"'cube/layer3twirl.c'\"
  1227. else
  1228.   echo shar: Extracting \"'cube/layer3twirl.c'\" \(4294 characters\)
  1229.   sed "s/^X//" >'cube/layer3twirl.c' <<'END_OF_FILE'
  1230. X/* layer3twirl.c
  1231. X   This incorporates Don Taylor's solution to the 
  1232. X   Buvos Kocka (Hungarian Magic Cube). 
  1233. X
  1234. X   Last Layer Cubes
  1235. X
  1236. X   Twirl corner cubes.
  1237. X
  1238. X
  1239. XThe following references were used:
  1240. X   "The X Window System Programming And Applications with Xt
  1241. X   OSF/MOTIF EDITION"
  1242. X   by Douglas A Young 
  1243. X   Prentice-Hall, 1990.
  1244. X   ISBN 0-13-642786-3
  1245. X
  1246. X   "Mastering Rubik's Cube"
  1247. X   by Don Taylor
  1248. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  1249. X   ISBN 0-03-059941-5
  1250. X
  1251. X-------------------------------------------------------------------
  1252. XCopyright (C) 1993 by Pierre A. Fleurant
  1253. XPermission is granted to copy and distribute this program
  1254. Xwithout charge, provided this copyright notice is included
  1255. Xin the copy.
  1256. XThis Software is distributed on an as-is basis. There will be
  1257. XABSOLUTELY NO WARRANTY for any part of this software to work
  1258. Xcorrect. In no case will the author be liable to you for damages
  1259. Xcaused by the usage of this software.
  1260. X-------------------------------------------------------------------
  1261. X*/   
  1262. X
  1263. X#include "taylor.h"
  1264. X
  1265. Xextern void F(); /*  front  */
  1266. Xextern void L(); /*  left   */
  1267. Xextern void R(); /*  right  */
  1268. Xextern void B(); /*  back   */
  1269. Xextern void U(); /*  up     */
  1270. Xextern void D(); /*  down   */
  1271. X
  1272. XBoolean twirl(w,wdata,call_data) /* These parameters needed for macros */
  1273. X     Widget   w;
  1274. X     widget_data *wdata;
  1275. X     caddr_t  call_data;
  1276. X{
  1277. X  /* Test if ok */
  1278. X  if(Front(6) == FRONT &&
  1279. X     Right(6) == RIGHT &&
  1280. X     Back(8)  == BACK  &&
  1281. X     Left(8)  == LEFT)
  1282. X    return(True);
  1283. X
  1284. X  /* Here if not ok */
  1285. X  /* Twirl corners */
  1286. X  /* 3 possibilities:
  1287. X   * 1: one corner needs twirl clockwise and another needs twirl anti-clockwise
  1288. X   * 2: two corners need twirl clockwise and other two need twirl anti-clockwise
  1289. X   * 3: three corners need to be twirled the same way
  1290. X   * 
  1291. X   * The twirl algorithm twirls one corner clockwise, and another anti-clockwise.
  1292. X   * This is repeated until all 4 corners are correct.
  1293. X   */
  1294. X
  1295. X  /* Find a corner that needs a clockwise twirl.
  1296. X   * (Note: all corners are in correct position.
  1297. X   * A corner needs a clockwise twirl if the front matches the top with
  1298. X   * said cube oriented in a top right-hand position.
  1299. X   * A corner needs an anti-clockwise twirl if the right-hand face matches the top.)
  1300. X   */
  1301. X
  1302. X  if(Front(6) == BOTTOM){
  1303. X    L(-1);U(1);L(1);F(1);U(1);F(-1);
  1304. X    /* Now search for cube that needs an anti-clockwise turn. */
  1305. X    if(Back(6) == BOTTOM){
  1306. X      D(1);
  1307. X      F(1);U(-1);F(-1);L(-1);U(-1);L(1);
  1308. X      D(-1);
  1309. X    }
  1310. X    else if(Right(8) == BOTTOM){
  1311. X      D(2);
  1312. X      F(1);U(-1);F(-1);L(-1);U(-1);L(1);
  1313. X      D(2);
  1314. X    }
  1315. X    else if(Front(8) == BOTTOM){
  1316. X      D(-1);
  1317. X      F(1);U(-1);F(-1);L(-1);U(-1);L(1);
  1318. X      D(1);
  1319. X    }
  1320. X  }
  1321. X  else if(Right(6) == BOTTOM){
  1322. X    F(-1);U(1);F(1);R(1);U(1);R(-1);
  1323. X    if(Left(6) == BOTTOM){
  1324. X      D(1);
  1325. X      R(1);U(-1);R(-1);F(-1);U(-1);F(1);
  1326. X      D(-1);
  1327. X    }
  1328. X    else if(Back(6) == BOTTOM){
  1329. X      D(2);
  1330. X      R(1);U(-1);R(-1);F(-1);U(-1);F(1);
  1331. X      D(2);
  1332. X    }
  1333. X    else if(Right(8) == BOTTOM){
  1334. X      D(-1);
  1335. X      R(1);U(-1);R(-1);F(-1);U(-1);F(1);
  1336. X      D(1);
  1337. X    }
  1338. X  }
  1339. X  else if(Back(8) == BOTTOM){
  1340. X    R(-1);U(1);R(1);B(1);U(1);B(-1);
  1341. X    if(Front(8) == BOTTOM){
  1342. X      D(1);
  1343. X      B(1);U(-1);B(-1);R(-1);U(-1);R(1);
  1344. X      D(-1);
  1345. X    }
  1346. X    else if(Left(6) == BOTTOM){
  1347. X      D(2);
  1348. X      B(1);U(-1);B(-1);R(-1);U(-1);R(1);
  1349. X      D(2);
  1350. X    }
  1351. X    else if(Back(6) == BOTTOM){
  1352. X      D(-1);
  1353. X      B(1);U(-1);B(-1);R(-1);U(-1);R(1);
  1354. X      D(1);
  1355. X    }
  1356. X  }
  1357. X  else if(Left(8) == BOTTOM){
  1358. X    B(-1);U(1);B(1);L(1);U(1);L(-1);
  1359. X    if(Right(8) == BOTTOM){
  1360. X      D(1);
  1361. X      L(1);U(-1);L(-1);B(-1);U(-1);B(1);
  1362. X      D(-1);
  1363. X    }
  1364. X    else if(Front(8) == BOTTOM){
  1365. X      D(2);
  1366. X      L(1);U(-1);L(-1);B(-1);U(-1);B(1);
  1367. X      D(2);
  1368. X    }
  1369. X    else if(Left(6) == BOTTOM){
  1370. X      D(-1);
  1371. X      L(1);U(-1);L(-1);B(-1);U(-1);B(1);
  1372. X      D(1);
  1373. X    }
  1374. X  }
  1375. X  else{
  1376. X    /* Here if not ok and no corners need clockwise twirl.
  1377. X     * So this is case 3 with three corners needing an
  1378. X     * anti-clockwise twirl.
  1379. X     * 
  1380. X     * So we perform operations to create atleast 1 corner
  1381. X     * needing a clockwise twirl, then return false.
  1382. X     * Operation is from "Front(6) == BOTTOM/Back(6) == BOTTOM" case.
  1383. X     */
  1384. X    L(-1);U(1);L(1);F(1);U(1);F(-1);
  1385. X    D(1);
  1386. X    F(1);U(-1);F(-1);L(-1);U(-1);L(1);
  1387. X    D(-1);
  1388. X  }
  1389. X  return(False);
  1390. X}
  1391. END_OF_FILE
  1392.   if test 4294 -ne `wc -c <'cube/layer3twirl.c'`; then
  1393.     echo shar: \"'cube/layer3twirl.c'\" unpacked with wrong size!
  1394.   fi
  1395.   # end of 'cube/layer3twirl.c'
  1396. fi
  1397. if test -f 'cube/lib/help_dialog.c' -a "${1}" != "-c" ; then 
  1398.   echo shar: Will not clobber existing file \"'cube/lib/help_dialog.c'\"
  1399. else
  1400.   echo shar: Extracting \"'cube/lib/help_dialog.c'\" \(4205 characters\)
  1401.   sed "s/^X//" >'cube/lib/help_dialog.c' <<'END_OF_FILE'
  1402. X/**********************************************************
  1403. X * A help callback.
  1404. X  *         From:
  1405. X  *                   The X Window System, 
  1406. X  *            Programming and Applications with Xt
  1407. X  *                   OSF/Motif Edition
  1408. X  *         by
  1409. X  *                Douglas Young
  1410. X  *              Prentice Hall, 1990
  1411. X  *
  1412. X  *                 Example described on pages:  119-121
  1413. X  *
  1414. X  *
  1415. X  *  Copyright 1989 by Prentice Hall
  1416. X  *  All Rights Reserved
  1417. X  *
  1418. X  * This code is based on the OSF/Motif widget set and the X Window System
  1419. X  *
  1420. X  * Permission to use, copy, modify, and distribute this software for 
  1421. X  * any purpose and without fee is hereby granted, provided that the above
  1422. X  * copyright notice appear in all copies and that both the copyright notice
  1423. X  * and this permission notice appear in supporting documentation.
  1424. X  *
  1425. X  * Prentice Hall and the author disclaim all warranties with regard to 
  1426. X  * this software, including all implied warranties of merchantability and fitness.
  1427. X  * In no event shall Prentice Hall or the author be liable for any special,
  1428. X  * indirect or cosequential damages or any damages whatsoever resulting from 
  1429. X  * loss of use, data or profits, whether in an action of contract, negligence 
  1430. X  * or other tortious action, arising out of or in connection with the use 
  1431. X  * or performance of this software.
  1432. X  *
  1433. X  * Open Software Foundation is a trademark of The Open Software Foundation, Inc.
  1434. X  * OSF is a trademark of Open Software Foundation, Inc.
  1435. X  * OSF/Motif is a trademark of Open Software Foundation, Inc.
  1436. X  * Motif is a trademark of Open Software Foundation, Inc.
  1437. X  * DEC is a registered trademark of Digital Equipment Corporation
  1438. X  * HP is a registered trademark of the Hewlett Packard Company
  1439. X  * DIGITAL is a registered trademark of Digital Equipment Corporation
  1440. X  * X Window System is a trademark of the Massachusetts Institute of Technology
  1441. X  **********************************************************************************/
  1442. X#include <X11/StringDefs.h>
  1443. X#include <X11/Intrinsic.h> 
  1444. X#include <Xm/Xm.h>
  1445. X#include <Xm/MessageB.h>
  1446. X#include "libXs.h"
  1447. X
  1448. Xstatic void xs_ok_callback();
  1449. X
  1450. Xvoid xs_help_callback(w, str, call_data) 
  1451. X     Widget    w; 
  1452. X     char     *str[];
  1453. X     caddr_t   call_data;
  1454. X{
  1455. X  int        i, n;
  1456. X  Widget     dialog;
  1457. X  Widget     label;
  1458. X  XmString   xmstr;
  1459. X  Arg        wargs[5];
  1460. X  /*
  1461. X   * Create the message dialog to display the help.
  1462. X   */
  1463. X   n = 0;
  1464. X   XtSetArg(wargs[n], XmNautoUnmanage, FALSE); n++;
  1465. X   dialog = XmCreateMessageDialog(w, "Help", wargs, n);
  1466. X   /*
  1467. X    * We won't be using the cancel widget. Unmanage it.
  1468. X    */
  1469. X   XtUnmanageChild(XmMessageBoxGetChild (dialog,
  1470. X                   XmDIALOG_CANCEL_BUTTON));
  1471. X   /*
  1472. X    * Retrieve the label widget and make the 
  1473. X    * text left justified
  1474. X    */
  1475. X   label = XmMessageBoxGetChild (dialog,
  1476. X                                 XmDIALOG_MESSAGE_LABEL);
  1477. X   n = 0;
  1478. X   XtSetArg(wargs[n],XmNalignment,XmALIGNMENT_BEGINNING);n++;
  1479. X   XtSetValues(label, wargs, n);
  1480. X   /*
  1481. X    * Add an OK callback to pop down the dialog.
  1482. X    */
  1483. X   XtAddCallback(dialog, XmNokCallback, 
  1484. X                 xs_ok_callback, NULL);
  1485. X  /*
  1486. X   * Count the text up to the first NULL string.
  1487. X   */
  1488. X  for(i=0; str[i][0] != '\0'; i++)
  1489. X    ;
  1490. X  /*
  1491. X   * Convert the string array to an XmString array and 
  1492. X   * set it as the label text.
  1493. X   */
  1494. X  xmstr  = xs_str_array_to_xmstr(str, i);
  1495. X  n = 0;
  1496. X  XtSetArg(wargs[n],  XmNmessageString, xmstr);n++;
  1497. X  XtSetValues(dialog, wargs, n);
  1498. X  /*
  1499. X   * If the next entry in the help string array is also NULL,
  1500. X   * then this is the last message. Unmanage the help button.
  1501. X   */
  1502. X  if(str[++i][0] == '\0')
  1503. X    XtUnmanageChild(XmMessageBoxGetChild (dialog,
  1504. X                    XmDIALOG_HELP_BUTTON));
  1505. X  /*
  1506. X   * Otherwise, add a help callback function with the address of 
  1507. X   * the next entry  in the help string as client_data.
  1508. X   */
  1509. X  else{
  1510. X    XtAddCallback(dialog, XmNhelpCallback, 
  1511. X                  xs_help_callback, &str[i]);
  1512. X  }
  1513. X  /*
  1514. X   * Display the dialog.
  1515. X   */
  1516. X  XtManageChild(dialog);
  1517. X}
  1518. X
  1519. Xstatic void xs_ok_callback(w, client_data, call_data) 
  1520. X   Widget               w; 
  1521. X   caddr_t              client_data;
  1522. X   XmAnyCallbackStruct *call_data; 
  1523. X{
  1524. X   XtUnmanageChild(w);
  1525. X   XtDestroyWidget(w);   
  1526. X}
  1527. END_OF_FILE
  1528.   if test 4205 -ne `wc -c <'cube/lib/help_dialog.c'`; then
  1529.     echo shar: \"'cube/lib/help_dialog.c'\" unpacked with wrong size!
  1530.   fi
  1531.   # end of 'cube/lib/help_dialog.c'
  1532. fi
  1533. if test -f 'cube/lib/quit.c' -a "${1}" != "-c" ; then 
  1534.   echo shar: Will not clobber existing file \"'cube/lib/quit.c'\"
  1535. else
  1536.   echo shar: Extracting \"'cube/lib/quit.c'\" \(3250 characters\)
  1537.   sed "s/^X//" >'cube/lib/quit.c' <<'END_OF_FILE'
  1538. X/*******************************************************
  1539. X * quit.c: A utility function that adds a quit button 
  1540. X  *         From:
  1541. X  *                   The X Window System, 
  1542. X  *            Programming and Applications with Xt
  1543. X  *                   OSF/Motif Edition
  1544. X  *         by
  1545. X  *                Douglas Young
  1546. X  *              Prentice Hall, 1990
  1547. X  *
  1548. X  *                 Example described on pages:  77-78
  1549. X  *
  1550. X  *
  1551. X  *  Copyright 1989 by Prentice Hall
  1552. X  *  All Rights Reserved
  1553. X  *
  1554. X  * This code is based on the OSF/Motif widget set and the X Window System
  1555. X  *
  1556. X  * Permission to use, copy, modify, and distribute this software for 
  1557. X  * any purpose and without fee is hereby granted, provided that the above
  1558. X  * copyright notice appear in all copies and that both the copyright notice
  1559. X  * and this permission notice appear in supporting documentation.
  1560. X  *
  1561. X  * Prentice Hall and the author disclaim all warranties with regard to 
  1562. X  * this software, including all implied warranties of merchantability and fitness.
  1563. X  * In no event shall Prentice Hall or the author be liable for any special,
  1564. X  * indirect or cosequential damages or any damages whatsoever resulting from 
  1565. X  * loss of use, data or profits, whether in an action of contract, negligence 
  1566. X  * or other tortious action, arising out of or in connection with the use 
  1567. X  * or performance of this software.
  1568. X  *
  1569. X  * Open Software Foundation is a trademark of The Open Software Foundation, Inc.
  1570. X  * OSF is a trademark of Open Software Foundation, Inc.
  1571. X  * OSF/Motif is a trademark of Open Software Foundation, Inc.
  1572. X  * Motif is a trademark of Open Software Foundation, Inc.
  1573. X  * DEC is a registered trademark of Digital Equipment Corporation
  1574. X  * HP is a registered trademark of the Hewlett Packard Company
  1575. X  * DIGITAL is a registered trademark of Digital Equipment Corporation
  1576. X  * X Window System is a trademark of the Massachusetts Institute of Technology
  1577. X  **********************************************************************************/
  1578. X
  1579. X#include <X11/Intrinsic.h>
  1580. X#include <X11/StringDefs.h>
  1581. X#include <Xm/Xm.h>
  1582. X#include <Xm/PushB.h>
  1583. X
  1584. X/* 
  1585. X * Define three callbacks. Make them static - no need 
  1586. X * to make them known outside this file.
  1587. X */
  1588. Xstatic void arm_callback(w, flag, call_data)
  1589. X     Widget     w;
  1590. X     int       *flag;
  1591. X     XmAnyCallbackStruct *call_data; 
  1592. X{
  1593. X *flag = FALSE;
  1594. X}
  1595. Xstatic void activate_callback(w, flag, call_data)
  1596. X     Widget     w;
  1597. X     int       *flag;
  1598. X     XmAnyCallbackStruct *call_data; 
  1599. X{
  1600. X  *flag = TRUE;
  1601. X}
  1602. Xstatic void disarm_callback(w, flag, call_data)
  1603. X     Widget     w;
  1604. X     int       *flag;
  1605. X     XmAnyCallbackStruct *call_data; 
  1606. X{
  1607. X  if(*flag){
  1608. X    XtCloseDisplay(XtDisplay(w));
  1609. X    exit(0);
  1610. X  }
  1611. X}
  1612. X/* 
  1613. X * Function to add a quit button as a child of any widget.
  1614. X */
  1615. XWidget xs_create_quit_button(parent)
  1616. X   Widget  parent;
  1617. X{
  1618. X   Widget     w;
  1619. X   static int really_quit;
  1620. X   w = XtCreateManagedWidget("quit", xmPushButtonWidgetClass,
  1621. X                            parent, NULL, 0);
  1622. X   XtAddCallback(w, XmNarmCallback, 
  1623. X                 arm_callback, &really_quit);
  1624. X   XtAddCallback(w, XmNdisarmCallback, 
  1625. X                 disarm_callback, &really_quit);
  1626. X   XtAddCallback(w, XmNactivateCallback, 
  1627. X                 activate_callback, &really_quit);     
  1628. X   return (w);
  1629. X}
  1630. END_OF_FILE
  1631.   if test 3250 -ne `wc -c <'cube/lib/quit.c'`; then
  1632.     echo shar: \"'cube/lib/quit.c'\" unpacked with wrong size!
  1633.   fi
  1634.   # end of 'cube/lib/quit.c'
  1635. fi
  1636. if test -f 'cube/lib/talkto.c' -a "${1}" != "-c" ; then 
  1637.   echo shar: Will not clobber existing file \"'cube/lib/talkto.c'\"
  1638. else
  1639.   echo shar: Extracting \"'cube/lib/talkto.c'\" \(3249 characters\)
  1640.   sed "s/^X//" >'cube/lib/talkto.c' <<'END_OF_FILE'
  1641. X/********************************************************************************
  1642. X *  xs_talkto(): connect two processes suchj that stdin of each reads from 
  1643. X *  stdout of the other
  1644. X  *         From:
  1645. X  *                   The X Window System, 
  1646. X  *            Programming and Applications with Xt
  1647. X  *                   OSF/Motif Edition
  1648. X  *         by
  1649. X  *                Douglas Young
  1650. X  *              Prentice Hall, 1990
  1651. X  *
  1652. X  *                 Example described on pages:  ??
  1653. X  *
  1654. X  *
  1655. X  *  Copyright 1989 by Prentice Hall
  1656. X  *  All Rights Reserved
  1657. X  *
  1658. X  * This code is based on the OSF/Motif widget set and the X Window System
  1659. X  *
  1660. X  * Permission to use, copy, modify, and distribute this software for 
  1661. X  * any purpose and without fee is hereby granted, provided that the above
  1662. X  * copyright notice appear in all copies and that both the copyright notice
  1663. X  * and this permission notice appear in supporting documentation.
  1664. X  *
  1665. X  * Prentice Hall and the author disclaim all warranties with regard to 
  1666. X  * this software, including all implied warranties of merchantability and fitness.
  1667. X  * In no event shall Prentice Hall or the author be liable for any special,
  1668. X  * indirect or cosequential damages or any damages whatsoever resulting from 
  1669. X  * loss of use, data or profits, whether in an action of contract, negligence 
  1670. X  * or other tortious action, arising out of or in connection with the use 
  1671. X  * or performance of this software.
  1672. X  *
  1673. X  * Open Software Foundation is a trademark of The Open Software Foundation, Inc.
  1674. X  * OSF is a trademark of Open Software Foundation, Inc.
  1675. X  * OSF/Motif is a trademark of Open Software Foundation, Inc.
  1676. X  * Motif is a trademark of Open Software Foundation, Inc.
  1677. X  * DEC is a registered trademark of Digital Equipment Corporation
  1678. X  * HP is a registered trademark of the Hewlett Packard Company
  1679. X  * DIGITAL is a registered trademark of Digital Equipment Corporation
  1680. X  * X Window System is a trademark of the Massachusetts Institute of Technology
  1681. X  **********************************************************************************/
  1682. X#include     <stdio.h>
  1683. Xvoid xs_talkto(cmd)
  1684. X   char   *cmd;
  1685. X{
  1686. X  int   to_child[2], /* pipe descriptors from parent->child */
  1687. X        to_parent[2];/* pipe descriptors from child->parent */
  1688. X  int   pid;
  1689. X  pipe(to_child);
  1690. X  pipe(to_parent);
  1691. X  if (pid = fork(), pid == 0){    /* in the child   */
  1692. X     close(0);                    /* redirect stdin */
  1693. X     dup(to_child[0]);
  1694. X     close(1);                    /* redirect stdout*/
  1695. X     dup(to_parent[1]);
  1696. X     close(to_child[0]);          /* close pipes    */
  1697. X     close(to_child[1]);
  1698. X     close(to_parent[0]);
  1699. X     close(to_parent[1]);
  1700. X     execlp(cmd, cmd, NULL);      /* exec the new cmd */
  1701. X   }
  1702. X   else if (pid > 0){             /* in the parent  */
  1703. X      close(0);                   /* redirect stdin */
  1704. X      dup(to_parent[0]);
  1705. X      close(1);                   /* redirect stdout  */
  1706. X      dup(to_child[1]);
  1707. X      setbuf(stdout, NULL);       /* no buffered output */
  1708. X      close(to_child[0]);         /* close pipes */
  1709. X      close(to_child[1]);
  1710. X      close(to_parent[0]);
  1711. X      close(to_parent[1]);
  1712. X    }
  1713. X    else {                        /* error!       */
  1714. X      fprintf(stderr,"Couldn't fork process %s\n", cmd);
  1715. X      exit(1);
  1716. X    }
  1717. X}
  1718. END_OF_FILE
  1719.   if test 3249 -ne `wc -c <'cube/lib/talkto.c'`; then
  1720.     echo shar: \"'cube/lib/talkto.c'\" unpacked with wrong size!
  1721.   fi
  1722.   # end of 'cube/lib/talkto.c'
  1723. fi
  1724. if test -f 'cube/lib/wprintf.c' -a "${1}" != "-c" ; then 
  1725.   echo shar: Will not clobber existing file \"'cube/lib/wprintf.c'\"
  1726. else
  1727.   echo shar: Extracting \"'cube/lib/wprintf.c'\" \(3012 characters\)
  1728.   sed "s/^X//" >'cube/lib/wprintf.c' <<'END_OF_FILE'
  1729. X/*********************************************************
  1730. X * xs_wprintf: fprintf-like function for XmLabel widgets
  1731. X  *         From:
  1732. X  *                   The X Window System, 
  1733. X  *            Programming and Applications with Xt
  1734. X  *                   OSF/Motif Edition
  1735. X  *         by
  1736. X  *                Douglas Young
  1737. X  *              Prentice Hall, 1990
  1738. X  *
  1739. X  *                 Example described on pages: ??
  1740. X  *
  1741. X  *
  1742. X  *  Copyright 1989 by Prentice Hall
  1743. X  *  All Rights Reserved
  1744. X  *
  1745. X  * This code is based on the OSF/Motif widget set and the X Window System
  1746. X  *
  1747. X  * Permission to use, copy, modify, and distribute this software for 
  1748. X  * any purpose and without fee is hereby granted, provided that the above
  1749. X  * copyright notice appear in all copies and that both the copyright notice
  1750. X  * and this permission notice appear in supporting documentation.
  1751. X  *
  1752. X  * Prentice Hall and the author disclaim all warranties with regard to 
  1753. X  * this software, including all implied warranties of merchantability and fitness.
  1754. X  * In no event shall Prentice Hall or the author be liable for any special,
  1755. X  * indirect or cosequential damages or any damages whatsoever resulting from 
  1756. X  * loss of use, data or profits, whether in an action of contract, negligence 
  1757. X  * or other tortious action, arising out of or in connection with the use 
  1758. X  * or performance of this software.
  1759. X  *
  1760. X  * Open Software Foundation is a trademark of The Open Software Foundation, Inc.
  1761. X  * OSF is a trademark of Open Software Foundation, Inc.
  1762. X  * OSF/Motif is a trademark of Open Software Foundation, Inc.
  1763. X  * Motif is a trademark of Open Software Foundation, Inc.
  1764. X  * DEC is a registered trademark of Digital Equipment Corporation
  1765. X  * HP is a registered trademark of the Hewlett Packard Company
  1766. X  * DIGITAL is a registered trademark of Digital Equipment Corporation
  1767. X  * X Window System is a trademark of the Massachusetts Institute of Technology
  1768. X  **********************************************************************************/
  1769. X#include <varargs.h>
  1770. X#include <stdio.h>
  1771. X#include <X11/Intrinsic.h>
  1772. X#include <X11/StringDefs.h>
  1773. X#include <Xm/Xm.h>
  1774. X#include <Xm/Label.h>
  1775. X
  1776. Xvoid xs_wprintf(va_alist)
  1777. X     va_dcl
  1778. X{
  1779. X  Widget    w;
  1780. X  char     *format;
  1781. X  va_list   args;
  1782. X  char      str[1000];  /* DANGER: Fixed buffer size */
  1783. X  Arg       wargs[1];
  1784. X  XmString  xmstr;
  1785. X  /*
  1786. X   * Init the variable length args list.
  1787. X   */
  1788. X  va_start(args);
  1789. X  /*
  1790. X   * Extract the destination widget.
  1791. X   * Make sure it is a subclass of XmLabel.
  1792. X   */
  1793. X  w = va_arg(args, Widget);
  1794. X  if(!XtIsSubclass(w, xmLabelWidgetClass))
  1795. X     XtError("xs_wprintf() requires a Label Widget");
  1796. X  /*
  1797. X   * Extract the format to be used.
  1798. X   */
  1799. X  format = va_arg(args, char *);
  1800. X  /*
  1801. X   * Use vsprintf to format the string to be displayed in the
  1802. X   * XmLabel widget, then convert it to a compound string
  1803. X   */
  1804. X  vsprintf(str, format, args);
  1805. X  xmstr =  XmStringLtoRCreate(str, XmSTRING_DEFAULT_CHARSET);
  1806. X
  1807. X  XtSetArg(wargs[0], XmNlabelString, xmstr);
  1808. X  XtSetValues(w, wargs, 1);     
  1809. X
  1810. X  va_end(args);
  1811. X}
  1812. END_OF_FILE
  1813.   if test 3012 -ne `wc -c <'cube/lib/wprintf.c'`; then
  1814.     echo shar: \"'cube/lib/wprintf.c'\" unpacked with wrong size!
  1815.   fi
  1816.   # end of 'cube/lib/wprintf.c'
  1817. fi
  1818. if test -f 'cube/lib/xmstr_to_str.c' -a "${1}" != "-c" ; then 
  1819.   echo shar: Will not clobber existing file \"'cube/lib/xmstr_to_str.c'\"
  1820. else
  1821.   echo shar: Extracting \"'cube/lib/xmstr_to_str.c'\" \(2966 characters\)
  1822.   sed "s/^X//" >'cube/lib/xmstr_to_str.c' <<'END_OF_FILE'
  1823. X/***********************************************************************
  1824. X * Retrieve the character string from a possibly composite compound string, such as
  1825. X * created by xs_concat_words()
  1826. X*         From:
  1827. X  *                   The X Window System, 
  1828. X  *            Programming and Applications with Xt
  1829. X  *                   OSF/Motif Edition
  1830. X  *         by
  1831. X  *                Douglas Young
  1832. X  *              Prentice Hall, 1990
  1833. X  *
  1834. X  *                 Example described on pages:  ??
  1835. X  *
  1836. X  *
  1837. X  *  Copyright 1989 by Prentice Hall
  1838. X  *  All Rights Reserved
  1839. X  *
  1840. X  * This code is based on the OSF/Motif widget set and the X Window System
  1841. X  *
  1842. X  * Permission to use, copy, modify, and distribute this software for 
  1843. X  * any purpose and without fee is hereby granted, provided that the above
  1844. X  * copyright notice appear in all copies and that both the copyright notice
  1845. X  * and this permission notice appear in supporting documentation.
  1846. X  *
  1847. X  * Prentice Hall and the author disclaim all warranties with regard to 
  1848. X  * this software, including all implied warranties of merchantability and fitness.
  1849. X  * In no event shall Prentice Hall or the author be liable for any special,
  1850. X  * indirect or cosequential damages or any damages whatsoever resulting from 
  1851. X  * loss of use, data or profits, whether in an action of contract, negligence 
  1852. X  * or other tortious action, arising out of or in connection with the use 
  1853. X  * or performance of this software.
  1854. X  *
  1855. X  * Open Software Foundation is a trademark of The Open Software Foundation, Inc.
  1856. X  * OSF is a trademark of Open Software Foundation, Inc.
  1857. X  * OSF/Motif is a trademark of Open Software Foundation, Inc.
  1858. X  * Motif is a trademark of Open Software Foundation, Inc.
  1859. X  * DEC is a registered trademark of Digital Equipment Corporation
  1860. X  * HP is a registered trademark of the Hewlett Packard Company
  1861. X  * DIGITAL is a registered trademark of Digital Equipment Corporation
  1862. X  * X Window System is a trademark of the Massachusetts Institute of Technology
  1863. X  **********************************************************************************/
  1864. X#include <X11/Intrinsic.h> 
  1865. X#include <Xm/Xm.h>
  1866. X
  1867. Xchar * xs_get_string_from_xmstring (string) 
  1868. X    XmString string; 
  1869. X{ 
  1870. X   caddr_t           context; 
  1871. X   char             *text; 
  1872. X   XmStringCharSet   charset; 
  1873. X   XmStringDirection dir; 
  1874. X   Boolean           separator; 
  1875. X   char             *buf = NULL; 
  1876. X
  1877. X int               done = FALSE;
  1878. X  XmStringInitContext (&context, string);
  1879. X  while (!done)
  1880. X   if(XmStringGetNextSegment (context, &text, &charset,
  1881. X                              &dir, &separator)){ 
  1882. X     if(separator) /* Stop when next segment is a separator */
  1883. X        done = TRUE;
  1884. X
  1885. X     if(buf){
  1886. X        buf = XtRealloc(buf, strlen(buf) + strlen(text) + 2);
  1887. X        strcat(buf, text);            
  1888. X     }
  1889. X     else {
  1890. X        buf = (char *) XtMalloc(strlen(text) +1);
  1891. X        strcpy(buf, text);
  1892. X      }
  1893. X     XtFree(text);
  1894. X   }
  1895. X     else
  1896. X     done = TRUE;
  1897. X
  1898. X  XmStringFreeContext (context);
  1899. X  return buf;
  1900. X}
  1901. END_OF_FILE
  1902.   if test 2966 -ne `wc -c <'cube/lib/xmstr_to_str.c'`; then
  1903.     echo shar: \"'cube/lib/xmstr_to_str.c'\" unpacked with wrong size!
  1904.   fi
  1905.   # end of 'cube/lib/xmstr_to_str.c'
  1906. fi
  1907. if test -f 'cube/taylor.c' -a "${1}" != "-c" ; then 
  1908.   echo shar: Will not clobber existing file \"'cube/taylor.c'\"
  1909. else
  1910.   echo shar: Extracting \"'cube/taylor.c'\" \(5569 characters\)
  1911.   sed "s/^X//" >'cube/taylor.c' <<'END_OF_FILE'
  1912. X/* taylor.c
  1913. X   This incorporates Don Taylor's solution to the 
  1914. X   Buvos Kocka (Hungarian Magic Cube). 
  1915. X
  1916. X   Steps to Solution:
  1917. X    1) First Layer Edge Cubes (top)
  1918. X       top/front
  1919. X       top/right
  1920. X       top/back
  1921. X       top/left
  1922. X    2) First layer Corner Cubes (top)
  1923. X       top/front/right
  1924. X       top/right/back
  1925. X       top/back/left
  1926. X       top/left/front
  1927. X    3) Middle layer (edge cubes)
  1928. X    4) Last Layer
  1929. X       Getting corner cubes in correct position
  1930. X       Getting edge cubes in correct position
  1931. X       Edge Flips/Corner Cubes
  1932. X      
  1933. XThe following references were used:
  1934. X   "The X Window System Programming And Applications with Xt
  1935. X   OSF/MOTIF EDITION"
  1936. X   by Douglas A Young 
  1937. X   Prentice-Hall, 1990.
  1938. X   ISBN 0-13-642786-3
  1939. X
  1940. X   "Mastering Rubik's Cube"
  1941. X   by Don Taylor
  1942. X   An Owl Book; Holt, Rinehart and Winston, New York, 1980
  1943. X   ISBN 0-03-059941-5
  1944. X
  1945. X-------------------------------------------------------------------
  1946. XCopyright (C) 1993 by Pierre A. Fleurant
  1947. XPermission is granted to copy and distribute this program
  1948. Xwithout charge, provided this copyright notice is included
  1949. Xin the copy.
  1950. XThis Software is distributed on an as-is basis. There will be
  1951. XABSOLUTELY NO WARRANTY for any part of this software to work
  1952. Xcorrect. In no case will the author be liable to you for damages
  1953. Xcaused by the usage of this software.
  1954. X-------------------------------------------------------------------
  1955. X*/   
  1956. X
  1957. X#include "taylor.h"
  1958. X
  1959. XWidget         saved_w;
  1960. Xwidget_data    *saved_wdata;
  1961. Xcaddr_t        saved_call_data;
  1962. Xint            number_moves;
  1963. X
  1964. Xvoid F(); /*  front  */
  1965. Xvoid L(); /*  left   */
  1966. Xvoid R(); /*  right  */
  1967. Xvoid B(); /*  back   */
  1968. Xvoid U(); /*  up     */
  1969. Xvoid D(); /*  down   */
  1970. X
  1971. Xextern void first_layer_edge_cube_tf(); /* layer1edge_tf */
  1972. Xextern void first_layer_edge_cube_tr(); /* layer1edge_tr */
  1973. Xextern void first_layer_edge_cube_tb(); /* layer1edge_tb */
  1974. Xextern void first_layer_edge_cube_tl(); /* layer1edge_tl */
  1975. X
  1976. Xextern Boolean first_layer_corner();    /* layer1corner */
  1977. X
  1978. Xextern Boolean middle_layer();          /* layer2 */ 
  1979. X
  1980. Xextern void last_layer();               /* layer3 */
  1981. X
  1982. Xextern Boolean twirl();                 /* layer3twirl */
  1983. Xextern Boolean flip();                  /* layer3flip */
  1984. X
  1985. Xvoid taylor(w,wdata,call_data)
  1986. X     Widget   w;
  1987. X     widget_data *wdata;
  1988. X     caddr_t  call_data;
  1989. X{
  1990. X  /* Save 'em in a global so we don't have to pass 'em 
  1991. X   * around all the time.
  1992. X   */
  1993. X  saved_w = w;
  1994. X  saved_wdata = wdata;
  1995. X  saved_call_data = call_data;
  1996. X  number_moves = 1;
  1997. X  printf("\nSolution:\n");
  1998. X
  1999. X  /* major parts of solution */
  2000. X  first_layer_edge_cube_tf(w,wdata,call_data); /* top/front */
  2001. X  first_layer_edge_cube_tr(w,wdata,call_data); /* top/right */
  2002. X  first_layer_edge_cube_tb(w,wdata,call_data); /* top/back  */
  2003. X  first_layer_edge_cube_tl(w,wdata,call_data); /* top/left  */
  2004. X
  2005. X  /* This is repeated until top layer is completed */
  2006. X  while(!first_layer_corner(w,wdata,call_data));
  2007. X  printf("TOP LAYER COMPLETED\n");
  2008. X
  2009. X  /* This is repeated until middle layer is completed */
  2010. X  while(!middle_layer(w,wdata,call_data));
  2011. X  printf("MIDDLE LAYER COMPLETED\n");
  2012. X
  2013. X  /* put last layer's corners and edges in correct position */
  2014. X  last_layer(w,wdata,call_data);
  2015. X
  2016. X  /* twirl last layer's corners */
  2017. X  while(!twirl(w,wdata,call_data));
  2018. X  printf("CORNERS TWIRLED\n");
  2019. X
  2020. X  /* flip last layer's edges */
  2021. X  while(!flip(w,wdata,call_data));
  2022. X
  2023. X  printf("End Of Solution\n");
  2024. X
  2025. X}
  2026. X
  2027. X
  2028. Xvoid F(nturns)
  2029. X     int nturns;
  2030. X{
  2031. X  int i, normturns;
  2032. X
  2033. X  printf("%d. Front(%d)\n", number_moves++,nturns);
  2034. X
  2035. X  /* get rid of extra turns...just in case */
  2036. X  normturns = nturns % 4;
  2037. X
  2038. X  /* our cubik_front goes the wrong way */
  2039. X  /* normturns ranges from -3 to +3, 
  2040. X     change this range to a 3, 2, 1, -3, -2, -1
  2041. X   */
  2042. X  if(normturns > 0)
  2043. X    normturns -= 4;
  2044. X  for(i=normturns; i<0; i++)
  2045. X    cubik_front(saved_w,saved_wdata,saved_call_data);
  2046. X}
  2047. X  
  2048. Xvoid L(nturns)
  2049. X     int nturns;
  2050. X{
  2051. X  int i, normturns;
  2052. X
  2053. X  printf("%d. Left(%d)\n", number_moves++,nturns);
  2054. X
  2055. X  /* get rid of extra turns...just in case */
  2056. X  normturns = nturns % 4;
  2057. X
  2058. X  /* our cubik_left goes the wrong way */
  2059. X  if(normturns > 0)
  2060. X    normturns -= 4;
  2061. X  for(i=normturns; i<0; i++)
  2062. X    cubik_left(saved_w,saved_wdata,saved_call_data);
  2063. X}
  2064. X  
  2065. Xvoid R(nturns)
  2066. X     int nturns;
  2067. X{
  2068. X  int i, normturns;
  2069. X
  2070. X  printf("%d. Right(%d)\n", number_moves++,nturns);
  2071. X
  2072. X  /* get rid of extra turns...just in case */
  2073. X  normturns = nturns % 4;
  2074. X
  2075. X  /* our cubik_right goes the correct way */
  2076. X  if(normturns < 0)
  2077. X    normturns += 4;
  2078. X  for(i=normturns; i>0; i--)
  2079. X    cubik_right(saved_w,saved_wdata,saved_call_data);
  2080. X}
  2081. X  
  2082. Xvoid B(nturns)
  2083. X     int nturns;
  2084. X{
  2085. X  int i, normturns;
  2086. X
  2087. X  printf("%d. Back(%d)\n", number_moves++,nturns);
  2088. X
  2089. X  /* get rid of extra turns...just in case */
  2090. X  normturns = nturns % 4;
  2091. X
  2092. X  /* our cubik_back goes the right way */
  2093. X  if(normturns < 0)
  2094. X    normturns += 4;
  2095. X  for(i=normturns; i>0; i--)
  2096. X    cubik_back(saved_w,saved_wdata,saved_call_data);
  2097. X}
  2098. X  
  2099. Xvoid U(nturns)
  2100. X     int nturns;
  2101. X{
  2102. X  int i, normturns;
  2103. X
  2104. X  printf("%d. Up(%d)\n", number_moves++,nturns);
  2105. X
  2106. X  /* get rid of extra turns...just in case */
  2107. X  normturns = nturns % 4;
  2108. X
  2109. X  /* our cubik_top goes the right way */
  2110. X  if(normturns < 0)
  2111. X    normturns += 4;
  2112. X  for(i=normturns; i>0; i--)
  2113. X    cubik_top(saved_w,saved_wdata,saved_call_data);
  2114. X}
  2115. X  
  2116. Xvoid D(nturns)
  2117. X     int nturns;
  2118. X{
  2119. X  int i, normturns;
  2120. X
  2121. X  printf("%d. Down(%d)\n", number_moves++,nturns);
  2122. X
  2123. X  /* get rid of extra turns...just in case */
  2124. X  normturns = nturns % 4;
  2125. X
  2126. X  /* our cubik_bottom goes the wrong way */
  2127. X  if(normturns > 0)
  2128. X    normturns -= 4;
  2129. X  for(i=normturns; i<0; i++)
  2130. X    cubik_bottom(saved_w,saved_wdata,saved_call_data);
  2131. X}
  2132. X  
  2133. X
  2134. END_OF_FILE
  2135.   if test 5569 -ne `wc -c <'cube/taylor.c'`; then
  2136.     echo shar: \"'cube/taylor.c'\" unpacked with wrong size!
  2137.   fi
  2138.   # end of 'cube/taylor.c'
  2139. fi
  2140. echo shar: End of archive 4 \(of 5\).
  2141. cp /dev/null ark4isdone
  2142. MISSING=""
  2143. for I in 1 2 3 4 5 ; do
  2144.     if test ! -f ark${I}isdone ; then
  2145.     MISSING="${MISSING} ${I}"
  2146.     fi
  2147. done
  2148. if test "${MISSING}" = "" ; then
  2149.     echo You have unpacked all 5 archives.
  2150.     rm -f ark[1-9]isdone
  2151. else
  2152.     echo You still must unpack the following archives:
  2153.     echo "        " ${MISSING}
  2154. fi
  2155. exit 0
  2156. exit 0 # Just in case...
  2157.