home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / sfs / part19 < prev    next >
Encoding:
Text File  |  1991-12-27  |  55.2 KB  |  2,137 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i019:  sfs - Space Flight Simulator, Part19/21
  4. Message-ID: <1991Dec24.191956.21203@sparky.imd.sterling.com>
  5. X-Md4-Signature: b6dbc23978d5721f228d9db7acd15d58
  6. Date: Tue, 24 Dec 1991 19:19:56 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  10. Posting-number: Volume 27, Issue 19
  11. Archive-name: sfs/part19
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file sfs/sfs/sfs_pr.c continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 19; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping sfs/sfs/sfs_pr.c'
  32. else
  33. echo 'x - continuing file sfs/sfs/sfs_pr.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfs_pr.c' &&
  35. X     }
  36. X      }
  37. X
  38. X   fclose( data );
  39. X
  40. X   /* Initialize all orbits utilizing data entered */
  41. X
  42. X   for ( orbit = 0; orbit < ORBITS; ++orbit )
  43. X      {
  44. X      if ( sorbit_array[ orbit ] != NULL )
  45. X     {
  46. X
  47. #ifdef  OLD_DEBUG
  48. X     sprintf( bw_ebuf, "[pr:] sfs_pr(): reinitializing orbit %d",
  49. X        orbit );
  50. X     bw_debug( bw_ebuf );
  51. #endif
  52. X
  53. X     or_init( sorbit_array[ orbit ]->aorbit,
  54. X        sorbit_array[ orbit ]->aorbit->periapsis,
  55. X        sorbit_array[ orbit ]->aorbit->apoapsis );
  56. X     }
  57. X      }
  58. X
  59. X   return TRUE;
  60. X   }
  61. X
  62. pr_parse( buffer, fdfile, sorbit_array, n_orbits )
  63. X   char *buffer;
  64. X   char *fdfile;
  65. X   struct sfs_orbit **sorbit_array;
  66. X   int n_orbits;
  67. X   {
  68. X   int n;        /* number of arguments  */
  69. X   int i;
  70. X   long l;
  71. X   double d;
  72. X   static char x_name[] = "";
  73. X
  74. X   n = pr_getargs( buffer );       /* get arguments   */
  75. X   if ( n == FALSE )
  76. X      {
  77. X      return;
  78. X      }
  79. X
  80. X   if ( strcmp( arguments[ 0 ], "FOCUS" ) == 0 )
  81. X      {
  82. #ifdef  OLD_DEBUG
  83. X      bw_message( "reading focus" );
  84. #endif
  85. X      i = atoi( arguments[ 1 ] );
  86. X      strncpy( fdfile, fntolc( arguments[ 2 ] ), (size_t) FDFILESIZE );
  87. X      if ( sorbit_array[ i - 1 ] == NULL )
  88. X     {
  89. X     pr_default( sorbit_array, i - 1, n_orbits, fdfile );
  90. X     }
  91. X      else
  92. X     {
  93. X     sorbit_array[ i - 1 ]->aorbit->focus
  94. X        = pr_getfd( sorbit_array, i - 1, n_orbits, fdfile );
  95. X     }
  96. X      }
  97. X
  98. X   else if ( strcmp( arguments[ 0 ], "ORB" ) == 0 )
  99. X      {
  100. #ifdef  OLD_DEBUG
  101. X      bw_message( "reading orb" );
  102. #endif
  103. X      i = atoi( arguments[ 1 ] );
  104. X      if ( sorbit_array[ i - 1 ] == NULL )
  105. X     {
  106. X     pr_default( sorbit_array, i - 1, n_orbits, fdfile );
  107. X     }
  108. X      strncpy( sorbit_array[ i - 1 ]->orbfile,
  109. X     fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
  110. X      }
  111. X
  112. X   else if ( strcmp( arguments[ 0 ], "GRID" ) == 0 )
  113. X      {
  114. #ifdef  OLD_DEBUG
  115. X      bw_message( "reading grid" );
  116. #endif
  117. X      i = atoi( arguments[ 1 ] );
  118. X      if ( sorbit_array[ i - 1 ] == NULL )
  119. X     {
  120. X     pr_default( sorbit_array, i - 1, n_orbits, fdfile );
  121. X     }
  122. X      strncpy( sorbit_array[ i - 1 ]->gridfile,
  123. X     fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
  124. X      }
  125. X
  126. X   else if ( strcmp( arguments[ 0 ], "SURFACE" ) == 0 )
  127. X      {
  128. #ifdef  OLD_DEBUG
  129. X      bw_message( "reading surface" );
  130. #endif
  131. X      i = atoi( arguments[ 1 ] );
  132. X      if ( sorbit_array[ i - 1 ] == NULL )
  133. X     {
  134. X     pr_default( sorbit_array, i - 1, n_orbits, fdfile );
  135. X     }
  136. X      strncpy( sorbit_array[ i - 1 ]->surfile,
  137. X     fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
  138. X      }
  139. X
  140. X   else if ( strcmp( arguments[ 0 ], "PERIAPSIS" ) == 0 )
  141. X      {
  142. #ifdef  OLD_DEBUG
  143. X      bw_message( "reading periapsis" );
  144. #endif
  145. X      i = atoi( arguments[ 1 ] );
  146. X      d = atof( arguments[ 2 ] );
  147. X      if ( sorbit_array[ i - 1 ] == NULL )
  148. X     {
  149. X     pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  150. X     }
  151. X      if ( d < 0 )
  152. X     {
  153. X     bw_error( PRERR_PRI );
  154. X     }
  155. X      else
  156. X    {
  157. X    sorbit_array[ i - 1 ]->aorbit->periapsis = d;
  158. X    }
  159. X      }
  160. X
  161. X   else if ( strcmp( arguments[ 0 ], "APOAPSIS" ) == 0 )
  162. X      {
  163. #ifdef  OLD_DEBUG
  164. X      bw_message( "reading apoapsis" );
  165. #endif
  166. X      i = atoi( arguments[ 1 ] );
  167. X      d = atof( arguments[ 2 ] );
  168. X
  169. X      if ( sorbit_array[ i - 1 ] == NULL )
  170. X    {
  171. X    pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  172. X    }
  173. X      if ( ( d < 0 ) || ( d < sorbit_array[ i - 1 ]->aorbit->periapsis ))
  174. X    {
  175. X    bw_error( PRERR_APO );
  176. X    }
  177. X      else
  178. X    {
  179. X    sorbit_array[ i - 1 ]->aorbit->apoapsis = d;
  180. X    }
  181. X      }
  182. X
  183. X   else if ( strcmp( arguments[ 0 ], "INCLINATION" ) == 0 )
  184. X      {
  185. #ifdef  OLD_DEBUG
  186. X      bw_message( "reading inclination" );
  187. #endif
  188. X      i = atoi( arguments[ 1 ] );
  189. X      d = atof( arguments[ 2 ] );
  190. X      if ( sorbit_array[ i - 1 ] == NULL )
  191. X    {
  192. X    pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  193. X    }
  194. X      if ( ( d < OR_INC_MIN ) || ( d > OR_INC_MAX ) )
  195. X    {
  196. X    sprintf( bw_ebuf, PRERR_INC, OR_INC_MIN, OR_INC_MAX );
  197. X    bw_error( bw_ebuf );
  198. X    }
  199. X      else
  200. X    {
  201. X    sorbit_array[ i - 1 ]->aorbit->inclination = d;
  202. X    }
  203. X      }
  204. X
  205. X   else if ( strcmp( arguments[ 0 ], "LONAN" ) == 0 )
  206. X      {
  207. #ifdef  OLD_DEBUG
  208. X      bw_message( "reading lon asc. node" );
  209. #endif
  210. X      i = atoi( arguments[ 1 ] );
  211. X      d = atof( arguments[ 2 ] );
  212. X      if ( sorbit_array[ i - 1 ] == NULL )
  213. X    {
  214. X    pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  215. X    }
  216. X      if ( ( d < OR_LAN_MIN ) || ( d > OR_LAN_MAX ) )
  217. X    {
  218. X    sprintf( bw_ebuf, PRERR_LAN, OR_LAN_MIN, OR_LAN_MAX );
  219. X    bw_error( bw_ebuf );
  220. X    }
  221. X      else
  222. X    {
  223. X    sorbit_array[ i - 1 ]->aorbit->lon_an = d;
  224. X    }
  225. X      }
  226. X
  227. X   else if ( strcmp( arguments[ 0 ], "ARGPER" ) == 0 )
  228. X      {
  229. #ifdef  OLD_DEBUG
  230. X      bw_message( "reading arg. perigee" );
  231. #endif
  232. X      i = atoi( arguments[ 1 ] );
  233. X      d = atof( arguments[ 2 ] );
  234. X      if ( sorbit_array[ i - 1 ] == NULL )
  235. X    {
  236. X    pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  237. X    }
  238. X      if ( ( d < OR_ARP_MIN ) || ( d > OR_ARP_MAX ) )
  239. X    {
  240. X    sprintf( bw_ebuf, PRERR_ARP, OR_ARP_MIN, OR_ARP_MAX );
  241. X    bw_error( bw_ebuf );
  242. X    }
  243. X      else
  244. X    {
  245. X    sorbit_array[ i - 1 ]->aorbit->arg_per = d;
  246. X    }
  247. X      }
  248. X
  249. X   else if ( strcmp( arguments[ 0 ], "NAME" ) == 0 )
  250. X      {
  251. #ifdef  OLD_DEBUG
  252. X      bw_message( "reading name" );
  253. #endif
  254. X      i = atoi( arguments[ 1 ] );
  255. X      if ( sorbit_array[ i - 1 ] == NULL )
  256. X     {
  257. X     pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
  258. X     }
  259. X      if ( ( sorbit_array[ i - 1 ]->name
  260. X     = malloc( (size_t) strlen( arguments[ 2 ] ) + 2 )) == NULL )
  261. X     {
  262. X     bw_error( PRMEMERR_NAME );
  263. X     sfs_exit();
  264. X     exit(1);
  265. X     }
  266. X
  267. X      pr_stripcr( arguments[ 2 ] );
  268. X      strcpy( sorbit_array[ i - 1 ]->name, arguments[ 2 ] );
  269. X      }
  270. X
  271. X   else if ( strcmp( arguments[ 0 ], "TFACTOR" ) == 0 )
  272. X      {
  273. #ifdef  OLD_DEBUG
  274. X      bw_message( "reading tfactor" );
  275. #endif
  276. X      l = atol( arguments[ 1 ] );
  277. X      if ( l < 1 )
  278. X    {
  279. X    bw_error( PRERR_TF );
  280. X    }
  281. X      else
  282. X    {
  283. X    sfs_tfactor = l;
  284. X    }
  285. X      }
  286. X
  287. X   else if ( strcmp( arguments[ 0 ], "UPDATE" ) == 0 )
  288. X      {
  289. #ifdef  OLD_DEBUG
  290. X      bw_message( "reading update time" );
  291. #endif
  292. X      l = atol( arguments[ 1 ] );
  293. X      if ( l < 1 )
  294. X    {
  295. X    bw_error( PRERR_UI );
  296. X    }
  297. X      else
  298. X    {
  299. X    sfs_inc = l;
  300. X    }
  301. X      }
  302. X
  303. X   else if ( strcmp( arguments[ 0 ], "TRIG" ) == 0 )
  304. X      {
  305. #ifdef  OLD_DEBUG
  306. X      bw_message( "reading trig level" );
  307. #endif
  308. X      l = atol( arguments[ 1 ] );
  309. X      if ( ( l < 1 ) || ( l > 2 ) )
  310. X    {
  311. X    bw_error( PRERR_TL );
  312. X    }
  313. X      else
  314. X    {
  315. X    vpt_level = l;
  316. X    }
  317. X      }
  318. X
  319. X   else if ( strcmp( arguments[ 0 ], "INSERTION" ) == 0 )
  320. X      {
  321. #ifdef  OLD_DEBUG
  322. X      bw_message( "reading insertion" );
  323. #endif
  324. X      l = atol( arguments[ 1 ] );
  325. X      if ( l < 0 )
  326. X    {
  327. X    sprintf( bw_ebuf, PRERR_INS );
  328. X    bw_error( bw_ebuf );
  329. X    }
  330. X      else
  331. X    {
  332. X    sfs_insertion = l;
  333. X    }
  334. X      }
  335. X
  336. #ifdef  USEGO
  337. X   else if ( strcmp( arguments[ 0 ], "GO" ) == 0 )
  338. X      {
  339. X      sfs_go = 1;
  340. X      }
  341. #endif
  342. X
  343. X   else
  344. X      {
  345. X      sprintf( bw_ebuf, PRERR_UNKNOWN, arguments[ 0 ] );
  346. X      bw_error( bw_ebuf );
  347. X      }
  348. X   }
  349. X
  350. pr_getargs( buffer )
  351. X   char *buffer;
  352. X   {
  353. X   int     y;            /* yes continue to loop    */
  354. X   int     n;            /* number of agument       */
  355. X   int     p;            /* position in argument string  */
  356. X   register char *c;          /* character position in buffer */
  357. X
  358. X   c = buffer;
  359. X   y = TRUE;
  360. X   n = 0;
  361. X
  362. X   /* check for null line */
  363. X
  364. X   if ( ( ( *c & 255 ) == 0xa ) || ( ( *c & 255 ) == 0xc ) )
  365. X      {
  366. X      return 0;
  367. X      }
  368. X
  369. X   /* loop to get each argument */
  370. X
  371. X   while( y == TRUE )
  372. X      {
  373. X      p = 0;
  374. X      arguments[ n ][ p ] = 0;
  375. X      while( ( isspace( *c ) == 0 ) && ( *c != 0 ))
  376. X    {
  377. X    if ( n == 0 )
  378. X       {
  379. X       arguments[ n ][ p ] = toupper( *c );
  380. X       }
  381. X    else
  382. X       {
  383. X       arguments[ n ][ p ] = *c;
  384. X       }
  385. X    arguments[ n ][ p + 1 ] = 0;
  386. X    ++c;
  387. X    ++p;
  388. X    }
  389. X
  390. X      /* Eat up any remaining whitespace before next argument */
  391. X
  392. X      while( isspace( *c ) != 0 )
  393. X    {
  394. X    ++c;
  395. X    }
  396. X
  397. X      /* if *c == 0, then end of line has been reached */
  398. X
  399. X      if ( *c == 0 )
  400. X    {
  401. X    y = FALSE;
  402. X    }
  403. X      else
  404. X    {
  405. X    ++n;
  406. X    }
  407. X      if ( ( n + 1 ) == MAXARGS )
  408. X    {
  409. X    y = FALSE;
  410. X    }
  411. X
  412. X      }
  413. X   return n + 1;
  414. X   }
  415. X
  416. pr_default( sorbit_array, orbit, n_orbits, fdfile )
  417. X   struct sfs_orbit **sorbit_array;
  418. X   int orbit, n_orbits;
  419. X   char *fdfile;
  420. X   {
  421. X   static char x_name[] = "";
  422. X
  423. X   /* Allocate memory for orbit structure */
  424. X
  425. X   if ( ( sorbit_array[ orbit ] = (struct sfs_orbit *) malloc( sizeof( struct sfs_orbit ) )) == NULL )
  426. X      {
  427. X      bw_error( PRMEMERR_SORBIT );
  428. X      sfs_exit();
  429. X      exit(1);
  430. X      }
  431. X
  432. X   if ( ( sorbit_array[ orbit ]->aorbit = (struct as_orbit *)
  433. X      malloc( sizeof( struct as_orbit ) )) == NULL )
  434. X      {
  435. X      bw_error( PRMEMERR_AORBIT );
  436. X      sfs_exit();
  437. X      exit(1);
  438. X      }
  439. X
  440. X   sorbit_array[ orbit ]->aorbit->focus
  441. X      = pr_getfd( sorbit_array, orbit, n_orbits, fdfile );
  442. X
  443. X   /* Now fill in defaults */
  444. X
  445. X   sorbit_array[ orbit ]->name                 = x_name;
  446. X   sorbit_array[ orbit ]->aorbit->lon_an       = 0.0;
  447. X   sorbit_array[ orbit ]->aorbit->arg_per      = 0.0;
  448. X   sorbit_array[ orbit ]->aorbit->inclination  = 0.0;
  449. X   sorbit_array[ orbit ]->aorbit->periapsis    = sorbit_array[ orbit ]->aorbit->focus->radius * 0.1;
  450. X   sorbit_array[ orbit ]->aorbit->apoapsis     = sorbit_array[ orbit ]->aorbit->focus->radius * 4;
  451. X
  452. X   strncpy ( sorbit_array[ orbit ]->orbfile, DEFAULTORB, SFS_FILESIZE - 1 );
  453. X   strncpy ( sorbit_array[ orbit ]->gridfile, DEFAULTGRID, SFS_FILESIZE - 1 );
  454. X   strncpy ( sorbit_array[ orbit ]->surfile, DEFAULTSD, SFS_FILESIZE - 1 );
  455. #ifdef  USEPOINTS
  456. X   strncpy ( sorbit_array[ orbit ]->pdfile, DEFAULTPT, SFS_FILESIZE - 1 );
  457. #endif
  458. X
  459. X   or_init( sorbit_array[ orbit ]->aorbit,
  460. X      sorbit_array[ orbit ]->aorbit->periapsis,
  461. X      sorbit_array[ orbit ]->aorbit->apoapsis );
  462. X
  463. #ifdef  OLD_DEBUG
  464. X   sprintf( bw_ebuf, "[pr:] pr_default(): orbit %d, focus %s, mass %le",
  465. X      orbit, sorbit_array[ orbit ]->aorbit->focus->name,
  466. X      sorbit_array[ orbit ]->aorbit->focus->mass );
  467. X   bw_debug( bw_ebuf );
  468. #endif
  469. X
  470. X   }
  471. X
  472. pr_save( filename, sorbit_array, n_orbits, pr_name )
  473. X   char *filename;
  474. X   struct sfs_orbit **sorbit_array;
  475. X   int n_orbits;
  476. X   char *pr_name;
  477. X   {
  478. X   FILE *data;
  479. X   register int orbit;
  480. X   static time_t ticks;
  481. X   static struct tm *tp;
  482. X
  483. X   /* get the date and time */
  484. X
  485. X   ticks = time( NULL );
  486. X   tp = localtime( &ticks );
  487. X
  488. X   /* Open the program file */
  489. X
  490. X   if ( ( data = fopen( filename, "w" )) == NULL )
  491. X      {
  492. X      sprintf( bw_ebuf, PRERR_WRITE,
  493. X         filename );
  494. X      bw_error( bw_ebuf );
  495. X      return BW_ERROR;
  496. X      }
  497. X
  498. X   pr_stripcr( pr_name );
  499. X   fprintf( data, FILE_DELIMITER );
  500. X   fprintf( data, ";\t%s \n", filename );
  501. X   fprintf( data, ";\t%s %s", PR_CREATED, asctime( tp ) );
  502. X   fprintf( data, FILE_DELIMITER );
  503. X   fprintf( data, "%s \n", pr_name );
  504. X   fprintf( data, "tfactor\t\t%ld\n", sfs_tfactor );
  505. X   fprintf( data, "update\t\t%ld\n", sfs_inc );
  506. X   fprintf( data, "trig\t\t%d\n", vpt_level );
  507. X   fprintf( data, "insertion\t%ld\n", sfs_insertion );
  508. X
  509. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  510. X      {
  511. X      if ( sorbit_array[ orbit ] != NULL )
  512. X         {
  513. X     fprintf( data, FILE_DELIMITER );
  514. X     fprintf( data, ";\t%s %d\n", PR_PARAMS, orbit + 1 );
  515. X     fprintf( data, FILE_DELIMITER );
  516. X         fprintf( data, "name\t\t%d\t%s\n", orbit + 1,
  517. X            sorbit_array[ orbit ]->name );
  518. X         fprintf( data, "focus\t\t%d\t%s\n", orbit + 1,
  519. X        sorbit_array[ orbit ]->aorbit->focus->fdfile );
  520. X         fprintf( data, "periapsis\t%d\t%lf\n", orbit + 1,
  521. X            sorbit_array[ orbit ]->aorbit->periapsis );
  522. X         fprintf( data, "apoapsis\t%d\t%lf\n", orbit + 1,
  523. X            sorbit_array[ orbit ]->aorbit->apoapsis );
  524. X         fprintf( data, "inclination\t%d\t%lf\n", orbit + 1,
  525. X        sorbit_array[ orbit ]->aorbit->inclination );
  526. X         fprintf( data, "argper\t\t%d\t%lf\n", orbit + 1,
  527. X        sorbit_array[ orbit ]->aorbit->arg_per );
  528. X         fprintf( data, "lonan\t\t%d\t%lf\n", orbit + 1,
  529. X        sorbit_array[ orbit ]->aorbit->lon_an );
  530. X     fprintf( data, "orb\t\t%d\t%s\n", orbit + 1,
  531. X        sorbit_array[ orbit ]->orbfile );
  532. X     fprintf( data, "grid\t\t%d\t%s\n", orbit + 1,
  533. X        sorbit_array[ orbit ]->gridfile );
  534. X     fprintf( data, "surface\t\t%d\t%s\n", orbit + 1,
  535. X        sorbit_array[ orbit ]->surfile );
  536. X         }
  537. X      }
  538. X
  539. X   fprintf( data, FILE_DELIMITER );
  540. X   fprintf( data, ";\t%s %s \n", PR_ENDOF, filename );
  541. X   fprintf( data, FILE_DELIMITER );
  542. X   fclose( data );
  543. X   }
  544. X
  545. pr_stripcr( s )
  546. X   char *s;
  547. X   {
  548. X   char *p;
  549. X
  550. X   p = s;
  551. X   while ( *p != 0 )
  552. X      {
  553. X      switch( *p )
  554. X     {
  555. X     case 0x0d:
  556. X     case 0x0a:
  557. X        *p = 0;
  558. X        break;
  559. X     }
  560. X      ++p;
  561. X      }
  562. X   *p = 0;
  563. X   }
  564. X
  565. struct as_focus *
  566. pr_getfd( sorbit_array, orbit_n, n_orbits, fdfile )
  567. X   struct sfs_orbit **sorbit_array;
  568. X   int orbit_n, n_orbits;
  569. X   char *fdfile;
  570. X   {
  571. X   register int orbit;
  572. X   struct as_focus *newfocus;
  573. X
  574. X   /* first cycle through orbits to see if this focus has already
  575. X      been initialized */
  576. X
  577. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  578. X      {
  579. X      if ( ( orbit != orbit_n ) && ( sorbit_array[ orbit ] != NULL ))
  580. X     {
  581. X     if ( strcmp( sorbit_array[ orbit ]->aorbit->focus->fdfile,
  582. X        fdfile ) == 0 )
  583. X        {
  584. #ifdef  OLD_DEBUG
  585. X        sprintf( bw_ebuf, "Reinit %s for orbit %d from orbit %d", 
  586. X               fdfile, orbit_n, orbit );
  587. X        bw_debug( bw_ebuf );
  588. #endif
  589. X        return sorbit_array[ orbit ]->aorbit->focus;
  590. X        }
  591. X     }
  592. X      }
  593. X
  594. X   /* the focus has not been initialized; initialize it now */
  595. X
  596. #ifdef  OLD_DEBUG
  597. X   sprintf( bw_ebuf, "Init %s for orbit %d", fdfile, orbit_n );
  598. X   bw_debug( bw_ebuf );
  599. #endif
  600. X   if ( ( newfocus = (struct as_focus *)
  601. X      malloc( sizeof( struct as_focus ) )) == NULL )
  602. X      {
  603. X      bw_error( PRMEMERR_FOCUS );
  604. X      sfs_exit();
  605. X      exit(1);
  606. X      }
  607. X
  608. X   /* read in focal data */
  609. X
  610. X   as_readfd( fdfile, newfocus );
  611. X   return newfocus;
  612. X
  613. X   }
  614. X
  615. char *
  616. fntolc( s )
  617. X   char *s;
  618. X   {
  619. X   char *p;
  620. X
  621. X   p = s;
  622. X   while( *p != 0 )
  623. X      {
  624. X      *p = tolower( *p );
  625. X      ++p;
  626. X      }
  627. X   return s;
  628. X   }
  629. SHAR_EOF
  630. echo 'File sfs/sfs/sfs_pr.c is complete' &&
  631. chmod 0644 sfs/sfs/sfs_pr.c ||
  632. echo 'restore of sfs/sfs/sfs_pr.c failed'
  633. Wc_c="`wc -c < 'sfs/sfs/sfs_pr.c'`"
  634. test 17557 -eq "$Wc_c" ||
  635.     echo 'sfs/sfs/sfs_pr.c: original size 17557, current size' "$Wc_c"
  636. rm -f _shar_wnt_.tmp
  637. fi
  638. # ============= sfs/sfs/sfs_vi.c ==============
  639. if test -f 'sfs/sfs/sfs_vi.c' -a X"$1" != X"-c"; then
  640.     echo 'x - skipping sfs/sfs/sfs_vi.c (File already exists)'
  641.     rm -f _shar_wnt_.tmp
  642. else
  643. > _shar_wnt_.tmp
  644. echo 'x - extracting sfs/sfs/sfs_vi.c (Text)'
  645. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_vi.c' &&
  646. /***************************************************************
  647. X
  648. X    sfs_vi.c        Visual Simulation Routines for SFS
  649. X
  650. X            Copyright (c) 1991, Ted A. Campbell
  651. X
  652. X            Bywater Software
  653. X            P. O. Box 4023 
  654. X            Duke Station 
  655. X            Durham, NC  27706
  656. X
  657. X            email: tcamp@hercules.acpub.duke.edu
  658. X
  659. X    Copyright and Permissions Information:
  660. X
  661. X    All U.S. and international copyrights are claimed by the
  662. X    author. The author grants permission to use this code
  663. X    and software based on it under the following conditions:
  664. X    (a) in general, the code and software based upon it may be 
  665. X    used by individuals and by non-profit organizations; (b) it
  666. X    may also be utilized by governmental agencies in any country,
  667. X    with the exception of military agencies; (c) the code and/or
  668. X    software based upon it may not be sold for a profit without
  669. X    an explicit and specific permission from the author, except
  670. X    that a minimal fee may be charged for media on which it is
  671. X    copied, and for copying and handling; (d) the code must be 
  672. X    distributed in the form in which it has been released by the
  673. X    author; and (e) the code and software based upon it may not 
  674. X    be used for illegal activities. 
  675. X
  676. ***************************************************************/
  677. X
  678. #include "stdio.h"
  679. #include "ctype.h"
  680. #include "math.h"
  681. #include "bw.h"
  682. #include "gr.h"
  683. #include "kb.h"
  684. #include "ui.h"
  685. #include "as.h"
  686. #include "sfs.h"
  687. X
  688. /* #define NOT_HIDDEN */
  689. X
  690. /***************************************************************
  691. X
  692. X    vi_draw()       Draw visual simulation screen
  693. X
  694. ***************************************************************/
  695. X
  696. vi_draw( uiwind, focus, elements, g_start, g_end, s_start, s_end,
  697. X      o_start, o_end, radius, distance, sorbit_array, orbit_n )
  698. X   struct uiwindow *uiwind;     /* ui window to draw in */
  699. X   struct as_focus *focus;      /* orbital focus to display */
  700. X   unsigned int elements;       /* elements to draw */
  701. X   struct spj_pt *g_start;      /* start array of points for grid */
  702. X   struct spj_pt *g_end;        /* end array of points for grid */
  703. X   struct spj_pt *s_start;      /* start array of points for surface */
  704. X   struct spj_pt *s_end;        /* end array of points for surface */
  705. X   struct spj_pt *o_start;      /* start array for orb data */
  706. X   struct spj_pt *o_end;        /* end array for orb data */
  707. X   double radius;               /* radius for size/horizon calculation */
  708. X   double distance;             /* distance for size/horizon calculation */
  709. X   struct sfs_orbit **sorbit_array;
  710. X   int orbit_n;
  711. X   {
  712. X   int l, c;                            /* line, column for title display */
  713. X   int x, y;                            /* coordinates to locate orb */
  714. X   static int clip_status = FALSE;      /* is clipping allowed? */
  715. X   int x_screen;
  716. X
  717. #ifdef  DEBUG
  718. X   if ( distance == 0.0 )
  719. X      {
  720. X      sprintf( bw_ebuf, "[pr: vi_draw() received distance = %.2lf",
  721. X     distance );
  722. X      bw_error( bw_ebuf );
  723. X      return;
  724. X      }
  725. X   if ( radius == 0.0 )
  726. X      {
  727. X      sprintf( bw_ebuf, "[pr: vi_draw() received radius = %.2lf",
  728. X     radius );
  729. X      bw_error( bw_ebuf );
  730. X      return;
  731. X      }
  732. #endif
  733. X
  734. X   /***  inform the viewer */
  735. X
  736. X   bw_message( VI_DRAW );
  737. X
  738. X   /***  initial screen setup */
  739. X
  740. #ifdef  NOT_HIDDEN
  741. X   x_screen = GR_PRIMARY;
  742. #else
  743. X   if ( gr_screens > 1 )
  744. X      {
  745. X      x_screen = GR_HIDDEN;
  746. X      }
  747. X   else
  748. X      {
  749. X      x_screen = GR_PRIMARY;
  750. X      }
  751. X   ui_setscreen( x_screen );
  752. #endif
  753. X
  754. #ifdef  OLD_DEBUG
  755. X   bw_message( "DEBUG: Blank window..." );
  756. #endif
  757. X
  758. X   /***  Blank the user area of the window */
  759. X
  760. X   ui_fbox( uiwind->u_x1, uiwind->u_y1,
  761. X       uiwind->u_x2, uiwind->u_y2, BLACK, SOLID );
  762. X
  763. #ifdef  OLD_DEBUG
  764. X   bw_message( "DEBUG: Set font..." );
  765. #endif
  766. X
  767. X   /***  Set appropriate font */
  768. X
  769. X   gr_font( x_screen, F_DEFAULT, ui_grwind->ymax / 40 );
  770. X
  771. X   /***  Element 1: Blank the orb */
  772. X
  773. X   /***  Element 2: Draw the orb */
  774. X
  775. X   if ( ( elements & VI_ORBOUTLINE ) > 0 )
  776. X      {
  777. #ifdef  OLD_DEBUG
  778. X      bw_debug( "ready to draw orb..." );
  779. #endif
  780. X      vi_showseq( o_start, o_end, uiwind, HORDEGS, radius, distance,
  781. X     cl_grid, SOLID, AL_HORIZON, SPJ_ALLSIDES, x_screen );
  782. X      }
  783. X
  784. X   /***  Element 3: Draw front of the grid */
  785. X
  786. X   if ( ( elements & VI_GRIDFRONT ) > 0 )
  787. X      {
  788. X      vi_showseq( g_start, g_end, uiwind, HORDEGS, radius, distance,
  789. X     cl_grid, GRID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
  790. X      }
  791. X
  792. X   /***  Element 4: Draw reverse of the grid */
  793. X
  794. X   if ( ( elements & VI_GRIDBACK ) > 0 )
  795. X      {
  796. X      vi_showseq( g_start, g_end, uiwind, HORDEGS, radius, distance,
  797. X     cl_grid, GRID, AL_HORIZON, SPJ_FARSIDE, x_screen );
  798. X      }
  799. X
  800. X   /***  Element 5: Draw reverse of the surface features */
  801. X
  802. X   if ( ( elements & VI_SURBACK ) > 0 )
  803. X      {
  804. X      vi_showseq( s_start, s_end, uiwind, HORDEGS, radius, distance,
  805. X     cl_surface, GRID, AL_HORIZON, SPJ_FARSIDE, x_screen );
  806. X      }
  807. X
  808. X   /***  Element 6: Draw front of the surface features */
  809. X
  810. X   if ( ( elements & VI_SURFRONT ) > 0 )
  811. X      {
  812. X      vi_showseq( s_start, s_end, uiwind, HORDEGS, radius, distance,
  813. X     cl_surface, SOLID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
  814. X      }
  815. X
  816. X   /***  Element 7: Show the points */
  817. X
  818. #ifdef  USEPOINTS
  819. X   if ( ( elements & VI_POINTS ) > 0 )
  820. X      {
  821. X      vi_showseq( p_start, p_end, uiwind, HORDEGS, radius, distance,
  822. X     cl_marker, GRID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
  823. X      }
  824. #endif
  825. X
  826. X   /***  Element 8: Show titles for point data */
  827. X
  828. #ifdef  USEPOINTS
  829. X   if ( ( elements & VI_PTITLES ) > 0 )
  830. X      {
  831. X      vi_titles( p_start, p_end, uiwind, HORDEGS, radius, distance,
  832. X     cl_mback, cl_mfore, AL_HORIZON, SPJ_NEARSIDE, x_screen );
  833. X      }
  834. #endif
  835. X
  836. X   /***  Element 9: Show crosshairs */
  837. X
  838. X   if ( ( elements & VI_CROSSH ) > 0 )
  839. X      {
  840. X      pe_crosshair( uiwind, HORDEGS, x_screen );
  841. X      }
  842. X
  843. X   /***  Element 10: Show screen title */
  844. X
  845. X   if ( ( elements & VI_STITLE ) > 0 )
  846. X      {
  847. X      sprintf( bw_ebuf, "%s:   %s %ld   %s %.2lf   %s %.2lf   %s %.0lf km",
  848. X     VI_POS, VI_ORBIT, sorbit_array[ orbit_n ]->ssp_n,
  849. X     VI_LAT, sorbit_array[ orbit_n ]->ssp_lat,
  850. X     VI_LON, sorbit_array[ orbit_n ]->ssp_lon,
  851. X     VI_ALT, sorbit_array[ orbit_n ]->ssp_r - focus->radius );
  852. X      gr_rectangle( x_screen, uiwind->u_x1 + 1, uiwind->u_y1 + 1,
  853. X     uiwind->u_x2 - 1, uiwind->u_y1 + 1 + ui_grwind->fysize + 1,
  854. X     cl_marker, SOLID );
  855. X      gr_text( x_screen, uiwind->u_x1 + 1, uiwind->u_y1 + 1,
  856. X     bw_ebuf, cl_mfore, cl_marker );
  857. X      }
  858. X
  859. X   /***  Restore font */
  860. X
  861. X   sfsx_font( 0 );
  862. X
  863. X   /* Show toggle status */
  864. X
  865. X   el_show( x_screen, uiwind, elements );
  866. X
  867. X   /***  blit and return screen to original state */
  868. X
  869. #ifndef NOT_HIDDEN
  870. X   if ( gr_screens > 1 )
  871. X      {
  872. X      gr_blit( GR_HIDDEN, GR_PRIMARY, uiwind->u_x1, uiwind->u_y1,
  873. X     uiwind->u_x2, uiwind->u_y2 );
  874. X      }
  875. X   ui_setscreen( GR_PRIMARY );
  876. #endif
  877. X
  878. X   /* Title the screen */
  879. X
  880. X   sprintf( bw_ebuf, VI_WTITLE,
  881. X      focus->name,
  882. X      sorbit_array[ orbit_n ]->name );
  883. X   ui_wtitle( uiwind, bw_ebuf );
  884. X
  885. X   }
  886. X
  887. /***************************************************************
  888. X
  889. X    vi_titles()     Show point titles on visual display
  890. X
  891. ***************************************************************/
  892. X
  893. #ifdef  USEPOINTS
  894. X
  895. vi_titles( start, end, uiwind, hor_deg, radius, distance,
  896. X   background, foreground, alignment, spjmode, screen )
  897. X   struct spj_pt *start, *end;
  898. X   struct uiwindow *uiwind;
  899. X   double hor_deg, radius, distance;
  900. X   int background, foreground;
  901. X   int alignment, spjmode, screen;
  902. X   {
  903. X   struct spj_pt *current;
  904. X   static struct uiwindow *oldwind;     /* save window pointer to avoid recalculation */
  905. X   static int x_midx, x_midy;           /* x, y mid points of window */
  906. X   static double x_xfactor, x_yfactor;  /* factors for x, y expansion in window */
  907. X   static double old_hdeg;              /* save horizontal degrees to avoid recalculation */
  908. X   static double vert_degrees;          /* calculate vertical degrees */
  909. X   static int old_align;                /* save alignment to avoid recalculation */
  910. X   int v;                               /* is the point visible? */
  911. X
  912. X   if ( ( uiwind != oldwind ) || ( alignment != old_align )
  913. X                  || ( hor_deg != old_hdeg ))
  914. X      {
  915. X      x_xfactor = ( uiwind->u_x2 - uiwind->u_x1 ) / hor_deg;
  916. X      vert_degrees = hor_deg * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
  917. X     * ( gr_pysize / (double) gr_pxsize ) )
  918. X     / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
  919. X      x_yfactor = ( uiwind->u_y2 - uiwind->u_y1 ) / vert_degrees;
  920. X      old_hdeg = hor_deg;
  921. X      x_midx = uiwind->u_x1 + (( uiwind->u_x2 - uiwind->u_x1 ) / 2 );
  922. X      if ( alignment == AL_HORIZON )
  923. X     {
  924. X     x_midy = ( ( ( uiwind->u_y2 - uiwind->u_y1 ) / 3 ) * 2 )
  925. X        - ( x_yfactor * spj_angrad( distance, radius ));
  926. X     }
  927. X      else
  928. X     {
  929. X     x_midy = uiwind->u_y1 + (( uiwind->u_y2 - uiwind->u_y1 ) / 2 );
  930. X     }
  931. X      old_align = alignment;
  932. X      oldwind = uiwind;
  933. X      }
  934. X
  935. X   current = start;
  936. X   while( current != end )
  937. X      {
  938. X
  939. X      /* Check to see if the coordinates are within the bounds
  940. X     of the whole screen */
  941. X
  942. X      v = TRUE;
  943. X      if ( current->name == NULL )
  944. X     {
  945. X     v = FALSE;
  946. X     }
  947. X      else if ( ( current->x < 0 ) || ( current->x > ui_grwind->xmax ) )
  948. X     {
  949. X     v = FALSE;
  950. X     }
  951. X      else if ( ( current->y < 0 ) || ( current->y > ui_grwind->ymax ) )
  952. X     {
  953. X     v = FALSE;
  954. X     }
  955. X      else if ( current->side != spjmode )
  956. X     {
  957. X     v = FALSE;
  958. X     }
  959. X
  960. X      if ( v == TRUE )
  961. X     {
  962. X     gr_text( screen,
  963. X        (int) ( current->x * x_xfactor ) + 3 + x_midx,
  964. X        (int) ( current->y * x_yfactor ) - ( ui_grwind->fysize / 2 )
  965. X           + x_midy,
  966. X        current->name, foreground, background );
  967. X     }
  968. X
  969. X      current = current->next;
  970. X      }
  971. X   }
  972. X
  973. #endif
  974. X
  975. /***************************************************************
  976. X
  977. X    vi_showseq()    Show a linked sequence of spherical
  978. X            projection data points in a ui window
  979. X
  980. ***************************************************************/
  981. X
  982. vi_showseq( start, end, uiwind, hor_deg, radius, distance,
  983. X   color, linestyle, alignment, spjmode, screen )
  984. X   struct spj_pt *start, *end;          /* start, end structures for
  985. X                       spherical projection data */
  986. X   struct uiwindow *uiwind;             /* ui window for display */
  987. X   double hor_deg;                      /* degrees of horizontal axis */
  988. X   double radius;                       /* radius for horizon position calculation */
  989. X   double distance;                     /* distance for horizon position calculation */
  990. X   int color;                           /* gr color for lines, points */
  991. X   int linestyle;                       /* gr line style for lines */
  992. X   int alignment;                       /* horizon or centered alignment */
  993. X   int spjmode;                         /* spj mode (sides) for display */
  994. X   int screen;                          /* screen for display */
  995. X   {
  996. X   struct spj_pt *current;              /* current point structure */
  997. X   static struct uiwindow *oldwind;     /* save window pointer to avoid recalculation */
  998. X   static int x_midx, x_midy;           /* x, y mid points of window */
  999. X   int x, y, side;                      /* current x, y, side values */
  1000. X   int prevcode, prevx, prevy, prevside;   /* save previous values */
  1001. X   static double x_xfactor, x_yfactor;  /* factors for x, y expansion in window */
  1002. X   static double old_hdeg;              /* save horizontal degrees to avoid recalculation */
  1003. X   static double vert_degrees;          /* calculate vertical degrees */
  1004. X   static double old_distance;        /* save distance to avoid recalc */
  1005. X   static int old_align;                /* save alignment to avoid recalculation */
  1006. #ifdef    DEBUG
  1007. X   int Dc;
  1008. #endif
  1009. X
  1010. #ifdef  DEBUG
  1011. X   if ( distance == 0.0 )
  1012. X      {
  1013. X      sprintf( bw_ebuf, "[pr: vi_showseq() received distance = %.2lf",
  1014. X     distance );
  1015. X      bw_error( bw_ebuf );
  1016. X      return;
  1017. X      }
  1018. X   if ( radius == 0.0 )
  1019. X      {
  1020. X      sprintf( bw_ebuf, "[pr: vi_showseq() received radius = %.2lf",
  1021. X     radius );
  1022. X      bw_error( bw_ebuf );
  1023. X      return;
  1024. X      }
  1025. #endif
  1026. X
  1027. X   if ( ( uiwind != oldwind ) || ( alignment != old_align )
  1028. X        || ( distance != old_distance )  || ( hor_deg != old_hdeg ))
  1029. X      {
  1030. X
  1031. #ifdef  DEBUG
  1032. X      bw_message( "DEBUG: recalculating for showseq()..." );
  1033. #endif
  1034. X
  1035. X      x_xfactor = ( uiwind->u_x2 - (double) uiwind->u_x1 ) / hor_deg;
  1036. X      vert_degrees = hor_deg * (double)
  1037. X     ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
  1038. X     * ( gr_pysize / (double) gr_pxsize ) )
  1039. X     / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
  1040. X      x_yfactor = ( uiwind->u_y2 - (double) uiwind->u_y1 ) / vert_degrees;
  1041. X      old_hdeg = hor_deg;
  1042. X      x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
  1043. X      if ( alignment == AL_HORIZON )
  1044. X     {
  1045. X     x_midy = uiwind->y1 +
  1046. X        ( ( (double) uiwind->u_y2 - (double) uiwind->u_y1 ) * 0.7 )
  1047. X        - ( x_yfactor * spj_angrad( distance, radius ));
  1048. X     }
  1049. X      else
  1050. X     {
  1051. X     x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2 );
  1052. X     }
  1053. X      old_align = alignment;
  1054. X      oldwind = uiwind;
  1055. X      old_distance = distance;
  1056. #ifdef  OLD_DEBUG
  1057. X      sprintf( bw_ebuf, "vert_degrees = %.2lf  xfactor = %.2lf, yfactor = %.2lf",
  1058. X         vert_degrees, x_xfactor, x_yfactor );
  1059. X      bw_debug( bw_ebuf );
  1060. #endif
  1061. X
  1062. X      }
  1063. X
  1064. #ifdef  OLD_DEBUG
  1065. X   Dc = 0;
  1066. X   sprintf( bw_ebuf, "ready to draw points, mode %d", spjmode );
  1067. X   bw_debug( bw_ebuf );
  1068. #endif
  1069. X
  1070. X   current = start->next;
  1071. X   prevside = 255;
  1072. X
  1073. X   while( current != end )
  1074. X      {
  1075. X      x = current->x * x_xfactor;
  1076. X      y = current->y * x_yfactor;
  1077. X      side = current->side;
  1078. #ifdef    DEBUG
  1079. X      ++Dc;
  1080. #endif
  1081. X
  1082. X      switch ( spjmode )
  1083. X     {
  1084. X     case SPJ_ALLSIDES:
  1085. #ifdef  OLD_DEBUG
  1086. X            sprintf( bw_ebuf, "DEBUG: allsides point %d: x %d y %d", Dc, x, y );
  1087. X            bw_message( bw_ebuf );
  1088. #endif
  1089. X        if ( current->code < 1000 )
  1090. X           {
  1091. X           sfs_line( screen,
  1092. X          x_midx + x,
  1093. X          x_midy + y,
  1094. X          x_midx + prevx,
  1095. X          x_midy + prevy, color, linestyle );
  1096. X           }
  1097. X        else
  1098. X           {
  1099. X           sfs_pixel( screen, x_midx + x,
  1100. X          x_midy + y, color );
  1101. X           }
  1102. X        break;
  1103. X     case SPJ_FARSIDE:
  1104. #ifdef  OLD_DEBUG
  1105. X            sprintf( bw_ebuf, "DEBUG: farside point %d: x %d y %d", Dc, x, y );
  1106. X            bw_message( bw_ebuf );
  1107. #endif
  1108. X        if ( ( prevside == SPJ_FARSIDE ) && ( side == SPJ_FARSIDE ))
  1109. X           {
  1110. X           if ( current->code < 1000 )
  1111. X          {
  1112. X          sfs_line( screen,
  1113. X             x_midx + x,
  1114. X             x_midy + y,
  1115. X             x_midx + prevx,
  1116. X             x_midy + prevy, color, linestyle );
  1117. X          }
  1118. X           else
  1119. X          {
  1120. X          sfs_pixel( screen, x_midx + x,
  1121. X          x_midy + y, color );
  1122. X          }
  1123. X           }
  1124. X        break;
  1125. X     default:
  1126. #ifdef  OLD_DEBUG
  1127. X            sprintf( bw_ebuf, "DEBUG: nearside point %d: x %d y %d", Dc, x, y );
  1128. X            bw_message( bw_ebuf );
  1129. #endif
  1130. X        if ( ( prevside == SPJ_NEARSIDE ) && ( side == SPJ_NEARSIDE ))
  1131. X           {
  1132. X           if ( current->code < 1000 )
  1133. X          {
  1134. X          sfs_line( screen,
  1135. X             x_midx + x,
  1136. X             x_midy + y,
  1137. X             x_midx + prevx,
  1138. X             x_midy + prevy, color, linestyle );
  1139. X          }
  1140. X           else
  1141. X          {
  1142. X          sfs_pixel( screen, x_midx + x,
  1143. X             x_midy + y, color );
  1144. X          }
  1145. X           }
  1146. X        break;
  1147. X     }
  1148. X
  1149. X      prevx = x;
  1150. X      prevy = y;
  1151. X      prevside = side;
  1152. X      prevcode = current->code;
  1153. X      current = current->next;
  1154. X      }
  1155. X   }
  1156. X
  1157. /***************************************************************
  1158. X
  1159. X    vi_rotate()     Calculate rotation based on 2 positions
  1160. X
  1161. ***************************************************************/
  1162. X
  1163. double
  1164. vi_rotate( current_x, current_y, next_x, next_y )
  1165. X   double current_x;           /* current x coordinate */
  1166. X   double current_y;           /* current y coordinate */
  1167. X   double next_x;              /* next x coordinate */
  1168. X   double next_y;              /* next y coordinate */
  1169. X   {
  1170. X   double x, y, r;
  1171. X
  1172. X   x = next_x - current_x;
  1173. X   y = next_y - current_y;
  1174. X
  1175. X   if ( x == 0.0 )
  1176. X      {
  1177. X      if ( y == 0.0 )
  1178. X     {
  1179. X     return 270.0;
  1180. X     }
  1181. X      else if ( y > 0.0 )
  1182. X     {
  1183. X     return 0.0;
  1184. X     }
  1185. X      else if ( y < 0.0 )
  1186. X     {
  1187. X     return 180.0;
  1188. X     }
  1189. X      }
  1190. X
  1191. X   if ( y == 0.0 )
  1192. X      {
  1193. X      if ( x > 0.0 )
  1194. X     {
  1195. X     return 270.0;
  1196. X     }
  1197. X      else if ( x < 0.0 )
  1198. X     {
  1199. X     return 90.0;
  1200. X     }
  1201. X      }
  1202. X
  1203. X   r = atan2( y, x ) * RAD_DEG;
  1204. X
  1205. #ifdef  OLD_DEBUG
  1206. X   sprintf( bw_ebuf, "exit vi_rotate(), current_x %.2lf  next_x %.2lf x %.2lf  y %.2lf  r %.2lf",
  1207. X      current_x, next_x, x, y, r );
  1208. X   bw_debug( bw_ebuf );
  1209. #endif
  1210. X
  1211. X   return spj_degfix( 270.0 + r );
  1212. X   }
  1213. X
  1214. sfs_line( screen, x1, y1, x2, y2, color, style )
  1215. X   int screen, x1, y1, x2, y2, color, style;
  1216. X   {
  1217. X
  1218. X   if ( ( x1 < 0 ) || ( x1 > ui_grwind->xmax ))
  1219. X      {
  1220. X      return FALSE;
  1221. X      }
  1222. X   if ( ( x2 < 0 ) || ( x2 > ui_grwind->xmax ))
  1223. X      {
  1224. X      return FALSE;
  1225. X      }
  1226. X   if ( ( y1 < 0 ) || ( y1 > ui_grwind->ymax ))
  1227. X      {
  1228. X      return FALSE;
  1229. X      }
  1230. X   if ( ( y2 < 0 ) || ( y2 > ui_grwind->ymax ))
  1231. X      {
  1232. X      return FALSE;
  1233. X      }
  1234. X
  1235. X   gr_line( screen, x1, y1, x2, y2, color, style );
  1236. X
  1237. X   }
  1238. X
  1239. sfs_pixel( screen, x, y, color )
  1240. X   int screen, x, y, color;
  1241. X   {
  1242. X
  1243. X   if ( ( x < 0 ) || ( x > ui_grwind->xmax ))
  1244. X      {
  1245. X      return FALSE;
  1246. X      }
  1247. X   if ( ( y < 0 ) || ( y > ui_grwind->ymax ))
  1248. X      {
  1249. X      return FALSE;
  1250. X      }
  1251. X
  1252. X   gr_pixel( screen, x, y, color );
  1253. X
  1254. X   }
  1255. X
  1256. SHAR_EOF
  1257. chmod 0644 sfs/sfs/sfs_vi.c ||
  1258. echo 'restore of sfs/sfs/sfs_vi.c failed'
  1259. Wc_c="`wc -c < 'sfs/sfs/sfs_vi.c'`"
  1260. test 16784 -eq "$Wc_c" ||
  1261.     echo 'sfs/sfs/sfs_vi.c: original size 16784, current size' "$Wc_c"
  1262. rm -f _shar_wnt_.tmp
  1263. fi
  1264. # ============= sfs/sfs/sfsm.c ==============
  1265. if test -f 'sfs/sfs/sfsm.c' -a X"$1" != X"-c"; then
  1266.     echo 'x - skipping sfs/sfs/sfsm.c (File already exists)'
  1267.     rm -f _shar_wnt_.tmp
  1268. else
  1269. > _shar_wnt_.tmp
  1270. echo 'x - extracting sfs/sfs/sfsm.c (Text)'
  1271. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.c' &&
  1272. /***************************************************************
  1273. X
  1274. X    sfsm.c        Space Flight Simulator
  1275. X            Main Menu and Orbital Modeling Module
  1276. X
  1277. X            Copyright (c) 1991, Ted A. Campbell
  1278. X
  1279. X            Bywater Software
  1280. X            P. O. Box 4023 
  1281. X            Duke Station 
  1282. X            Durham, NC  27706
  1283. X
  1284. X            email: tcamp@hercules.acpub.duke.edu
  1285. X
  1286. X    Copyright and Permissions Information:
  1287. X
  1288. X    All U.S. and international copyrights are claimed by the
  1289. X    author. The author grants permission to use this code
  1290. X    and software based on it under the following conditions:
  1291. X    (a) in general, the code and software based upon it may be 
  1292. X    used by individuals and by non-profit organizations; (b) it
  1293. X    may also be utilized by governmental agencies in any country,
  1294. X    with the exception of military agencies; (c) the code and/or
  1295. X    software based upon it may not be sold for a profit without
  1296. X    an explicit and specific permission from the author, except
  1297. X    that a minimal fee may be charged for media on which it is
  1298. X    copied, and for copying and handling; (d) the code must be 
  1299. X    distributed in the form in which it has been released by the
  1300. X    author; and (e) the code and software based upon it may not 
  1301. X    be used for illegal activities. 
  1302. X
  1303. ***************************************************************/
  1304. X
  1305. #include "stdio.h"
  1306. #include "time.h"
  1307. #include "signal.h"
  1308. #include "ctype.h"
  1309. #include "math.h"
  1310. X
  1311. #ifdef __STDC__
  1312. #include "malloc.h"
  1313. #else
  1314. extern char * malloc();
  1315. #endif
  1316. X
  1317. #include "sfsm.h"
  1318. X
  1319. #ifndef   __STDC__
  1320. #define   time_t    long
  1321. #define   size_t   int
  1322. #endif
  1323. X
  1324. extern  int sfs_sigint();
  1325. X
  1326. #define MM_TITLES       4
  1327. /* #define SMALL_DEBUG */
  1328. #define MAXYSIZE    375
  1329. X
  1330. struct dir_ent *d_entries[ MAX_ENTRIES ];
  1331. char *d_titles[ MAX_ENTRIES ];
  1332. X
  1333. char *mm_titles[ MM_TITLES ] = {
  1334. X     MM_SETPROGFILE,
  1335. X     MM_OM,
  1336. X     MM_OS,
  1337. X     MM_EXIT };
  1338. X
  1339. /***    Colors */
  1340. X
  1341. int   cl_mback;      /* Main background color   */
  1342. int   cl_mfore;      /* Main foreground color   */
  1343. int   cl_marker;      /* Color for prompt markers   */
  1344. int   cl_grid;      /* Color for planetary grid   */
  1345. int   cl_surface;      /* Color for planetary surface   */
  1346. int   cl_orbits[ OR_COLORS ];      /* Colors for different orbits   */
  1347. X
  1348. char    sfs_program[ 36 ];
  1349. char    sfs_tbuf[ 512 ];
  1350. int     sfs_curorbit = 0;
  1351. long    sfs_insertion;
  1352. long    sfs_inc;         
  1353. long    sfs_tfactor;      /* time factor         */
  1354. X
  1355. #define LOGOPAUSE       5
  1356. X
  1357. struct  uiwindow *main_window;          /* structure for main window    */
  1358. struct  menu_box w1, w2, w3, w4;    /* structures quad windows      */
  1359. X
  1360. int   stat_y1;         /* line for status display   */
  1361. int   stat_y2;         /* top of status display   */
  1362. int   stat_x1;         /* column for status display   */
  1363. int   stat_x2;         /* max col for status display   */
  1364. X
  1365. char sfs_prname[ 128 ];
  1366. char bw_ebuf[ BW_EBUFSIZE ];
  1367. X
  1368. static    int midx, midy;
  1369. static   FILE *data;
  1370. X
  1371. main( argc, argv )
  1372. X   int argc;
  1373. X   char **argv;
  1374. X   {
  1375. X   int x1, y1, x2, y2, incr, sfs_resume;
  1376. X   register int c, goodbye;
  1377. X   static char tbuf[ 64 ];
  1378. X   static struct sfs_orbit *sorbit_array[ ORBITS ];
  1379. X
  1380. X   /***    First some precautionary measures               */
  1381. X   /***    Load "chain" so that the loader (sfs) will exit */
  1382. X   /***    in the case of any unexpected exit              */
  1383. X
  1384. X   if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
  1385. X      {
  1386. X      fprintf( data, "%s \n", SFSCH_EXIT );
  1387. X      fclose( data );
  1388. X      }
  1389. X
  1390. X   /***    Now set a signal handler so that a SIGINT       */
  1391. X   /***    (control-C under DOS, DEL under Unix) will      */
  1392. X   /***    exit gracefully                                 */
  1393. X
  1394. X   signal( SIGINT, sfs_sigint );
  1395. X
  1396. X   /* Process arguments */
  1397. X
  1398. X   strcpy( sfs_program, SFS_DEFAULTPROG );
  1399. X   if ( argc > 1 )
  1400. X      {
  1401. X      if ( ( data = fopen( argv[ 1 ], "r" ) ) != 0 )
  1402. X         {
  1403. X         fclose( data );
  1404. X         strcpy( sfs_program, argv[ 1 ] );
  1405. X         }
  1406. #ifdef  DEBUG
  1407. X      else
  1408. X     {
  1409. X     fprintf( stderr, "Failed to open file %s\n", argv[ 1 ] );
  1410. X     exit( 0 );
  1411. X     }
  1412. #endif
  1413. X      }
  1414. X
  1415. X   sfs_resume = 0;
  1416. X   if ( argc > 2 )
  1417. X      {
  1418. X      if ( strncmp( argv[ 2 ], SFS_CONTARG, (size_t) 4 ) == 0 )
  1419. X         {
  1420. X         sfs_resume = TRUE;
  1421. X         }
  1422. X      }
  1423. X
  1424. X   /* Initialize the toolkit */
  1425. X
  1426. X   ui_init();
  1427. X
  1428. X   /* Return if initialization failed */
  1429. X
  1430. X   if ( ui_grwind->initialized == FALSE )
  1431. X      {
  1432. X      fprintf( stderr, "Graphics system is not initialized.\n" );
  1433. X      return -1;
  1434. X      }
  1435. X
  1436. X   /* assign colors */
  1437. X
  1438. X   sfs_colors();         /* Set colors       */
  1439. X
  1440. X
  1441. X   /* reset icon colors */
  1442. X
  1443. X   if ( gr_colors > 2 )
  1444. X      {
  1445. X      ui_seticons( cl_mback, cl_marker );
  1446. X      }
  1447. X
  1448. X   /* Initialize variable-precision trig */
  1449. X
  1450. X   vpt_init();
  1451. X   sfs_font( 0 );
  1452. X
  1453. X   /* get memory for directory/menu arrays */
  1454. X
  1455. X   for ( c = 0; c < MAX_ENTRIES; ++c )
  1456. X      {
  1457. X      if ( ( d_entries[ c ] =
  1458. X     (struct dir_ent *) malloc( sizeof( struct dir_ent ))) == NULL )
  1459. X     {
  1460. X     gr_deinit();
  1461. X     kb_deinit();
  1462. X     fprintf( stderr, MEMERR_DS, c );
  1463. X     exit( 1 );
  1464. X     }
  1465. X      if ( ( d_titles[ c ] = malloc( TITLE_SIZE )) == NULL )
  1466. X     {
  1467. X     gr_deinit();
  1468. X     kb_deinit();
  1469. X     fprintf( stderr, MEMERR_TA, c );
  1470. X     exit( 1 );
  1471. X     }
  1472. X      }
  1473. X
  1474. X   /* Clear the screen */
  1475. X
  1476. X   gr_cls( GR_PRIMARY );
  1477. X
  1478. X   sfs_font( 0 );
  1479. X
  1480. X   /* Draw the main screen */
  1481. X
  1482. X   sfs_ms();
  1483. X
  1484. #ifdef    OLD_DEBUG
  1485. X   kb_rx();
  1486. #endif
  1487. X
  1488. X   if ( sfs_resume == FALSE )
  1489. X      {
  1490. X
  1491. X      /* Show the program logo */
  1492. X
  1493. X      sfs_logo();
  1494. X      sfs_wait( LOGOPAUSE );
  1495. X
  1496. X      }
  1497. X
  1498. #ifdef  OLD_DEBUG
  1499. X   bw_error( "Test error message" );
  1500. #endif
  1501. X
  1502. X   /* Set default values */
  1503. X
  1504. X   sfs_curorbit = 0;
  1505. X   strcpy( sfs_prname, UNTPROG );
  1506. X   sfs_tfactor = 1;
  1507. X   sfs_inc = 30;
  1508. X   sfs_insertion = 0;
  1509. X
  1510. X   /* Read the initial program file */
  1511. X
  1512. X   sfs_pr( sfs_program, sfs_prname, sorbit_array, ORBITS );
  1513. X   bw_message( " " );
  1514. X
  1515. X   /* Cycle through the main menu */
  1516. X
  1517. X   goodbye = 0;
  1518. X   while( goodbye == 0 )
  1519. X      {
  1520. X
  1521. X      c = sfs_mm();
  1522. X
  1523. X      switch( c )
  1524. X         {
  1525. X         case 0:
  1526. X        sfs_setpr( sorbit_array, ORBITS );
  1527. X        bw_message( " " );
  1528. X        sfs_curorbit = 0;
  1529. X            break;
  1530. X         case 1:
  1531. X        sfs_om( sorbit_array, ORBITS );
  1532. X            break;
  1533. X         case 2:
  1534. X        if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
  1535. X               {
  1536. #ifdef OLD_DEBUG
  1537. X               bw_debug( "Setting up chain file" );
  1538. #endif
  1539. X           fprintf( data, "%s %s %s\n", SFSCH_SIMUL, sfs_program,
  1540. X          SFS_CONTARG );
  1541. X               fclose( data );
  1542. X               }
  1543. X            sfs_exit();
  1544. X            exit( 1 );
  1545. X            break;
  1546. #ifdef  BLOCKEDOUT
  1547. X     case 3:
  1548. X        if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
  1549. X               {
  1550. X           fprintf( data, "%s %s %s %s\n", SFSCH_ATLAS, sfs_fdfile,
  1551. X          SFS_CONTARG, sfs_program );
  1552. X               fclose( data );
  1553. X               }
  1554. X            sfs_exit();
  1555. X        exit( 1 );
  1556. X            break;
  1557. #endif
  1558. X     case TK_EXIT:
  1559. X     case 3:
  1560. X        if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
  1561. X               {
  1562. X           fprintf( data, "%s \n", SFS_EXITARG );
  1563. X               fclose( data );
  1564. X               }
  1565. X            sfs_exit();
  1566. X            exit( 1 );
  1567. X            goodbye = 1;
  1568. X            break;
  1569. X         }
  1570. X      }
  1571. X
  1572. X   sfs_exit();
  1573. X
  1574. X   }
  1575. X
  1576. sfs_colors()
  1577. X   {
  1578. X   register int c;
  1579. X   int n;
  1580. X
  1581. X   if ( gr_colors > 8 )
  1582. X      {
  1583. X      cl_mback = WHITE;
  1584. X      cl_mfore = BLACK;
  1585. X      cl_marker = DARK_CYAN;
  1586. X      cl_grid = DARK_BLUE;
  1587. X      cl_surface = DARK_GREEN;
  1588. X      n = LIGHT_RED;
  1589. X      for ( c = 0; c < OR_COLORS; ++c )
  1590. X         {
  1591. X         cl_orbits[ c ] = n;
  1592. X         ++n;
  1593. X         }
  1594. X      }
  1595. X   else if ( gr_colors > 2 )
  1596. X      {
  1597. X      cl_mback = WHITE;
  1598. X      cl_mfore = BLACK;
  1599. X      cl_marker = BLACK;
  1600. X      cl_grid = WHITE;
  1601. X      cl_surface = WHITE;
  1602. X      for ( c = 0; c < OR_COLORS; ++c )
  1603. X         {
  1604. X         cl_orbits[ c ] = WHITE;
  1605. X         }
  1606. X      }
  1607. X   else
  1608. X      {
  1609. X      cl_mback = WHITE;
  1610. X      cl_mfore = BLACK;
  1611. X      cl_marker = WHITE;
  1612. X      cl_grid = WHITE;
  1613. X      cl_surface = WHITE;
  1614. X      for ( c = 0; c < OR_COLORS; ++c )
  1615. X         {
  1616. X         cl_orbits[ c ] = WHITE;
  1617. X         }
  1618. X      }
  1619. X
  1620. X   }
  1621. X
  1622. /***  Main SFS Screen      */
  1623. X
  1624. sfs_ms()
  1625. X   {
  1626. X
  1627. X   /* Draw the window itself */
  1628. X
  1629. X   sprintf( sfs_tbuf, "%s, %s %s", SFS_TITLE, VERABB, VERSION );
  1630. X   main_window = ui_window( 0, 0, ui_grwind->xmax, ui_grwind->ymax,
  1631. X      TRUE, cl_marker, cl_mfore,
  1632. X      sfs_tbuf, FALSE, cl_mback,
  1633. X      FALSE, BLACK, cl_mback, GRID, BUT_CLOSE );
  1634. X   ui_fbox( main_window->u_x1, main_window->u_y1,
  1635. X      main_window->u_x2, main_window->u_y2, cl_mback, GRID );
  1636. X
  1637. X   /* Draw two lines demarcating Status area */
  1638. X
  1639. X   gr_line( GR_PRIMARY, ui_grwind->xmax / 2, main_window->tbar_y1,
  1640. X      ui_grwind->xmax / 2, main_window->y2, cl_mfore, SOLID );
  1641. X   gr_line( GR_PRIMARY, ( ui_grwind->xmax / 2 ) + 2,
  1642. X      main_window->tbar_y1,
  1643. X      ( ui_grwind->xmax / 2 ) + 2,
  1644. X      main_window->y2, cl_mfore, SOLID );
  1645. X
  1646. X   /* Record the status area */
  1647. X
  1648. X   stat_y1 = main_window->tbar_y1;
  1649. X   stat_y2 = main_window->y2 + ( ( ui_grwind->fysize ) * 0.3 );
  1650. X   stat_x1 = ( main_window->x2 / 2 ) + 5;
  1651. X   stat_x2 = main_window->tbar_x2;
  1652. X
  1653. X   }
  1654. X
  1655. /*** Display Program Logo */
  1656. X
  1657. sfs_logo()
  1658. X   {
  1659. X   struct uiwindow *logo_window;
  1660. X   int x1, x2, y1, y2, height, length, midx, midy;
  1661. X
  1662. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1663. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1664. X
  1665. X   length = ( main_window->u_x2 * 7 ) / 10;
  1666. X   x1 = midx - length / 2;
  1667. X   x2 = midx + length / 2;
  1668. X   height = main_window->u_y2 / 2;
  1669. X   y1 = midy - height / 2;
  1670. X   y2 = midy + height / 2;
  1671. X
  1672. X   logo_window = ui_window( x1, y1, x2, y2, FALSE, cl_marker, cl_mfore,
  1673. X      "", TRUE, cl_mfore, TRUE, cl_mfore, cl_mback, SOLID, FALSE );
  1674. X
  1675. X   sfs_font( 2 ); 
  1676. X   y1 = midy + ui_grwind->fysize;
  1677. X   gr_text( GR_PRIMARY, midx - ( gr_strlen( SFS_TITLE ) / 2 ),
  1678. X      y1, SFS_TITLE, cl_mfore, cl_mback );
  1679. X   sfs_font( 0 );
  1680. X   y1 -= ui_grwind->fysize * 2;
  1681. X   gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_PAX ) / 2 ),
  1682. X      y1, SFSM_PAX, cl_mfore, cl_mback );
  1683. X   y1 -= ui_grwind->fysize * 2;
  1684. X   gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_CPRT ) / 2 ),
  1685. X      y1, SFSM_CPRT, cl_mfore, cl_mback );
  1686. X   y1 -= ( ui_grwind->fysize * 4 ) / 3;
  1687. X   gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_BWS ) / 2 ),
  1688. X      y1, SFSM_BWS, cl_mfore, cl_mback );
  1689. X
  1690. X   }
  1691. X
  1692. /***  Main Menu */
  1693. X
  1694. sfs_mm()
  1695. X   {
  1696. X   static struct uiwindow *pr_box;
  1697. X   static struct menu_box m_box;
  1698. X
  1699. X   /* Clear the entire area */
  1700. X
  1701. X   ui_fbox( main_window->u_x1, main_window->u_y1,
  1702. X      main_window->u_x2, main_window->u_y2,
  1703. X      BLACK, SOLID );
  1704. X   ui_fbox( main_window->u_x1, main_window->u_y1,
  1705. X      main_window->u_x2, main_window->u_y2, 
  1706. X      cl_mback, GRID );
  1707. X
  1708. X   bw_message( MES_MM );
  1709. X
  1710. X   /* Display the program box */
  1711. X
  1712. X   if ( pr_box == NULL )
  1713. X      {
  1714. X      pr_box = ui_window( main_window->u_x1 + 2 +
  1715. X        (( main_window->u_x2 - main_window->u_x1 )/2),
  1716. X     main_window->u_y2 -
  1717. X        ( ui_grwind->fysize * ( MM_TITLES + 3 )),
  1718. X     main_window->u_x2, main_window->u_y2,
  1719. X     TRUE, cl_marker, cl_mfore, SFSM_CPFX,
  1720. X     TRUE, cl_mfore, FALSE, BLACK, cl_mback, SOLID, FALSE );
  1721. X      }
  1722. X   else
  1723. X      {
  1724. X      ui_rewindow( pr_box, SFSM_CPFX );
  1725. X      }
  1726. X   sprintf( sfs_tbuf, SFSM_CPFI,
  1727. X      sfs_program, sfs_prname );
  1728. X   ui_text( pr_box->u_x1, pr_box->u_y1, pr_box->u_x2, pr_box->u_y2,
  1729. X      64, cl_mback, cl_mfore, sfs_tbuf );
  1730. X
  1731. X   /* get the main menu item and return it */
  1732. X
  1733. X   m_box.is_drawn = FALSE;
  1734. X   return ui_list( MENU_SLIDERS, main_window->u_x1,
  1735. X      main_window->u_y2 -
  1736. X     ( ui_grwind->fysize * ( MM_TITLES + 3 )),
  1737. X      main_window->u_x2 -
  1738. X         (( main_window->u_x2 - main_window->u_x1 )/2),
  1739. X      main_window->u_y2,
  1740. X      MM_TTL, MM_TITLES, mm_titles,
  1741. X      cl_mfore, cl_mback, cl_marker, &m_box );
  1742. X
  1743. X   }
  1744. X
  1745. sfs_setpr( sorbit_array, n_orbits )
  1746. X   struct sfs_orbit **sorbit_array;
  1747. X   int n_orbits;
  1748. X   {
  1749. X   static struct menu_box setp_box;
  1750. X   int x1, x2, y1, y2, height, length, midx, midy;
  1751. X   int item;
  1752. X
  1753. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1754. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1755. X
  1756. X   length = ( main_window->u_x2 * 7 ) / 10;
  1757. X   x1 = midx - length / 2;
  1758. X   x2 = midx + length / 2;
  1759. X   height = main_window->u_y2 / 2;
  1760. X   y1 = midy - height / 2;
  1761. X   y2 = midy + height / 2;
  1762. X
  1763. X   setp_box.is_drawn = FALSE;
  1764. X   item = ui_ftext( x1, y1, x2, y2, "*.sfs", SFSM_SPF,
  1765. X      &setp_box, d_titles, d_entries, MAX_ENTRIES,
  1766. X      cl_mback, cl_mfore, cl_marker );
  1767. X
  1768. X   fntolc( d_entries[ item ] );
  1769. X   strcpy( sfs_program, d_entries[ item ] );
  1770. X   sfs_pr( sfs_program, sfs_prname, sorbit_array, n_orbits );
  1771. X
  1772. X   }
  1773. X
  1774. sfs_font( size )
  1775. X   int size;
  1776. X   {
  1777. X   static oldsize = 159;
  1778. X   int rq_height, calcy;
  1779. X
  1780. X   if ( size == oldsize )
  1781. X      {
  1782. X      return;
  1783. X      }
  1784. X
  1785. X   if ( ui_grwind->ymax > MAXYSIZE )
  1786. X      {
  1787. X      calcy = MAXYSIZE;
  1788. X      }
  1789. X   else
  1790. X      {
  1791. X      calcy = ui_grwind->ymax;
  1792. X      }
  1793. X
  1794. X   switch( size )
  1795. X      {
  1796. X      case 1:
  1797. X     rq_height = calcy / 25;
  1798. X         break;
  1799. X      case 2:
  1800. X     rq_height = calcy / 15;
  1801. X         break;
  1802. X      default:
  1803. X     rq_height = calcy / 30;
  1804. X         break;
  1805. X      }
  1806. X
  1807. X   gr_font( GR_PRIMARY, F_DEFAULT, rq_height );
  1808. X   }
  1809. X
  1810. bw_error( mes )
  1811. X   char *mes;
  1812. X   {
  1813. X   static char buffer[ BW_EBUFSIZE ];
  1814. X   static int x_mem;
  1815. X   static size_t x_size;
  1816. X   static int x1, x2, y1, y2, height, length, midx, midy, c;
  1817. X   static struct uiwindow *err_window;
  1818. X
  1819. X   if ( x_mem == NULL )
  1820. X      {
  1821. X
  1822. X      midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1823. X      midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1824. X
  1825. X      length = main_window->u_x2 / 2;
  1826. X      x1 = midx - length / 2;
  1827. X      x2 = midx + length / 2;
  1828. X      height = main_window->u_y2 / 2;
  1829. X      y1 = midy - height / 2;
  1830. X      y2 = midy + height / 2;
  1831. X
  1832. X      }
  1833. X
  1834. X   gr_imsave( GR_PRIMARY, TRUE, x1, y1, x2, y2, &x_mem );
  1835. X   buffer[ 0 ] = 0;
  1836. X   sprintf( buffer, ERR_PROMPT, mes );
  1837. X   c = ui_yn( x1, y1, x2, y2, cl_mback, cl_mfore, cl_marker, TRUE,
  1838. X      buffer, ERRP_NO, ERRP_YES, &err_window );
  1839. X   gr_imsave( GR_PRIMARY, FALSE, x1, y1, x2, y2, &x_mem );
  1840. X   gr_imfree( x_mem );
  1841. X
  1842. X   if ( c == FALSE )
  1843. X      {
  1844. X      sfs_exit();
  1845. X      exit( 1 );
  1846. X      }
  1847. X   }
  1848. X
  1849. #ifdef  DEBUG
  1850. bw_debug( mes )
  1851. X   char *mes;
  1852. X   {
  1853. X   static char buffer[ 256 ];
  1854. X   static int x_mem;
  1855. X   static size_t x_size;
  1856. X   static int x1, x2, y1, y2, height, length, midx, midy, c;
  1857. X   static struct uiwindow *deb_window;
  1858. X
  1859. #ifdef  SMALL_DEBUG
  1860. X   sprintf( buffer, "DEBUG: %s     ", mes );
  1861. X   gr_text( GR_PRIMARY, 5, 5, buffer, BLACK, WHITE );
  1862. X   ui_wait();
  1863. #else
  1864. X   if ( x_mem == NULL )
  1865. X      {
  1866. X
  1867. X      midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1868. X      midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1869. X
  1870. X      length = main_window->u_x2 / 2;
  1871. X      x1 = midx - length / 2;
  1872. X      x2 = midx + length / 2;
  1873. X      height = main_window->u_y2 / 2;
  1874. X      y1 = midy - height / 2;
  1875. X      y2 = midy + height / 2;
  1876. X
  1877. X      }
  1878. X
  1879. X   gr_imsave( GR_PRIMARY, TRUE, x1, y1, x2, y2, &x_mem );
  1880. X   buffer[ 0 ] = 0;
  1881. X   sprintf( buffer, "DEBUG:  %s ", mes );
  1882. X   c = ui_alarm( x1, y1, x2, y2, cl_mback, cl_mfore, cl_marker, TRUE,
  1883. X      buffer, "Press Any Key to Continue", &deb_window );
  1884. X   gr_imsave( GR_PRIMARY, FALSE, x1, y1, x2, y2, &x_mem );
  1885. X   gr_imfree( x_mem );
  1886. X
  1887. #endif
  1888. X
  1889. X   }
  1890. #endif
  1891. X
  1892. sfs_exit()
  1893. X   {
  1894. X   gr_cls( GR_PRIMARY );
  1895. X   gr_deinit();
  1896. X   }
  1897. X
  1898. sfs_wait( seconds )
  1899. X   int seconds;
  1900. X   {
  1901. X   static time_t start, current;
  1902. X   time( &start );
  1903. X   current = start;
  1904. X   while ( current < ( start + seconds ) )
  1905. X      {
  1906. X      time( ¤t );
  1907. X      }
  1908. X   }
  1909. X
  1910. tl_window( title )
  1911. X   char *title;
  1912. X   {
  1913. X
  1914. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1915. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1916. X
  1917. X   if ( w1.window == NULL )
  1918. X      {
  1919. X      w1.window = ui_window( main_window->u_x1 + 1, midy + 1,
  1920. X     midx - 1, main_window->u_y2 - 1, TRUE, cl_marker, BLACK,
  1921. X     title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
  1922. X      }
  1923. X   else
  1924. X      {
  1925. X      ui_rewindow( w1.window, title );
  1926. X      }
  1927. X   }
  1928. X
  1929. tr_window( title )
  1930. X   char *title;
  1931. X   {
  1932. X
  1933. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1934. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1935. X
  1936. X   if ( w2.window == NULL )
  1937. X      {
  1938. X      w2.window = ui_window( midx + 1, midy + 1,
  1939. X     main_window->u_x2 - 1, main_window->u_y2 - 1, TRUE, cl_marker, cl_mfore,
  1940. X     title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
  1941. X      }
  1942. X   else
  1943. X      {
  1944. X      ui_rewindow( w2.window, title );
  1945. X      }
  1946. X   }
  1947. X
  1948. bl_window( title )
  1949. X   char *title;
  1950. X   {
  1951. X
  1952. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1953. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1954. X
  1955. X   if ( w3.window == NULL )
  1956. X      {
  1957. X      w3.window = ui_window( main_window->u_x1 + 1, main_window->u_y1 + 1,
  1958. X     midx - 1, midy - 1, TRUE, cl_marker, BLACK,
  1959. X     title, TRUE, BLACK, FALSE, BLACK, WHITE, GRID, BUT_CLOSE );
  1960. X      }
  1961. X   else
  1962. X      {
  1963. X      ui_rewindow( w3.window, title );
  1964. X      }
  1965. X   sfsm_clpe();
  1966. X   }
  1967. X
  1968. br_window( title )
  1969. X   char *title;
  1970. X   {
  1971. X
  1972. X   midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
  1973. X   midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
  1974. X
  1975. X   if ( w4.window == NULL )
  1976. X      {
  1977. X      w4.window = ui_window( midx + 1, main_window->u_y1 + 1,
  1978. X     main_window->u_x2 - 1, midy - 1, TRUE, cl_marker, cl_mfore,
  1979. X     title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
  1980. X      }
  1981. X   else
  1982. X      {
  1983. X      ui_rewindow( w4.window, title );
  1984. X      }
  1985. X   }
  1986. X
  1987. sfs_sigint()
  1988. X   {
  1989. X   if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
  1990. X      {
  1991. X      fprintf( data, "%s \n", SFS_EXITARG );
  1992. X      fclose( data );
  1993. X      }
  1994. X   sfs_exit();
  1995. X   exit( 1 );
  1996. X   }
  1997. X
  1998. ui_poll()
  1999. X   {
  2000. X   ;
  2001. X   }
  2002. X
  2003. bw_message( m )
  2004. X   char *m;
  2005. X   {
  2006. X   ui_fbox( stat_x1, main_window->tbar_y1 + 1,
  2007. X      main_window->tbar_x2, main_window->y2 - 1,
  2008. X      main_window->t_bcolor, SOLID );
  2009. X
  2010. X   ui_str( stat_x1, stat_y1, stat_x2, cl_marker, cl_mfore, m );
  2011. X
  2012. X   }
  2013. X
  2014. matherr( xstruct )
  2015. X   struct exception *xstruct;
  2016. X   {
  2017. X   sprintf( bw_ebuf, ERR_MATH, xstruct->name );
  2018. X   bw_error( bw_ebuf );
  2019. X   }
  2020. X
  2021. X
  2022. SHAR_EOF
  2023. chmod 0644 sfs/sfs/sfsm.c ||
  2024. echo 'restore of sfs/sfs/sfsm.c failed'
  2025. Wc_c="`wc -c < 'sfs/sfs/sfsm.c'`"
  2026. test 17785 -eq "$Wc_c" ||
  2027.     echo 'sfs/sfs/sfsm.c: original size 17785, current size' "$Wc_c"
  2028. rm -f _shar_wnt_.tmp
  2029. fi
  2030. # ============= sfs/sfs/sfsm.h ==============
  2031. if test -f 'sfs/sfs/sfsm.h' -a X"$1" != X"-c"; then
  2032.     echo 'x - skipping sfs/sfs/sfsm.h (File already exists)'
  2033.     rm -f _shar_wnt_.tmp
  2034. else
  2035. > _shar_wnt_.tmp
  2036. echo 'x - extracting sfs/sfs/sfsm.h (Text)'
  2037. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.h' &&
  2038. /***************************************************************
  2039. X
  2040. X    sfsm.h          General Header File for
  2041. X            Space Flight Simulator, 
  2042. X            Main Menu and Orbital Modeling Module
  2043. X
  2044. X            Copyright (c) 1991, Ted A. Campbell
  2045. X
  2046. X            Bywater Software
  2047. X            P. O. Box 4023 
  2048. X            Duke Station 
  2049. X            Durham, NC  27706
  2050. X
  2051. X            email: tcamp@hercules.acpub.duke.edu
  2052. X
  2053. X    Copyright and Permissions Information:
  2054. X
  2055. X    All U.S. and international copyrights are claimed by the
  2056. X    author. The author grants permission to use this code
  2057. X    and software based on it under the following conditions:
  2058. X    (a) in general, the code and software based upon it may be 
  2059. X    used by individuals and by non-profit organizations; (b) it
  2060. X    may also be utilized by governmental agencies in any country,
  2061. X    with the exception of military agencies; (c) the code and/or
  2062. X    software based upon it may not be sold for a profit without
  2063. X    an explicit and specific permission from the author, except
  2064. X    that a minimal fee may be charged for media on which it is
  2065. X    copied, and for copying and handling; (d) the code must be 
  2066. X    distributed in the form in which it has been released by the
  2067. X    author; and (e) the code and software based upon it may not 
  2068. X    be used for illegal activities. 
  2069. X
  2070. ***************************************************************/
  2071. X
  2072. /***    Include Files */
  2073. X
  2074. #include "bw.h"         /* header for generic Bywater handlers */
  2075. #include "as.h"         /* header for astronomy routines */
  2076. #include "gr.h"         /* header for graphics routines */
  2077. #include "dr.h"         /* header for directory routines */
  2078. #include "ui.h"         /* header for user interface routines */
  2079. #include "sfs.h"        /* header for sfs specific information */
  2080. X
  2081. /***    Program-specific definitions */
  2082. X
  2083. #define MAX_ENTRIES     64
  2084. #define TITLE_SIZE      64
  2085. X
  2086. /***************************************************************
  2087. X
  2088. X    language-specific definitions
  2089. X
  2090. X    English is taken as a default, and if SFSMNAME
  2091. X    has not been defined, the English definitions will be
  2092. X    utilized. To translate into other languages, we suggest
  2093. X    that the following section be copied, a language name
  2094. X    defined as one, and then each of the definitions rendered
  2095. X    into the language. Example:
  2096. X
  2097. X    ;#define        LATIN   1
  2098. X    ;
  2099. X    ;
  2100. X    ;#if    LATIN
  2101. X    ;#define        SFSMNAME        " Pars Prima "
  2102. X    ;......etc.
  2103. X    ;#endif
  2104. X
  2105. X    SFSMNAME will then be defined, and the English language
  2106. X    tags will not be called.
  2107. X
  2108. ***************************************************************/
  2109. X
  2110. #ifndef SFSMNAME
  2111. #define SFSMNAME        " Main Module "
  2112. #define SFSM_PAX        "VENIMVS IN PACE PRO OMNIBVS"
  2113. #define SFSM_CPRT       "Copyright (c) 1991, Ted A. Campbell"
  2114. #define SFSM_BWS        "Bywater Software"
  2115. #define SFSM_PEBL       "[Perspective Window Blocked]"
  2116. #define MM_SETPROGFILE  " Set SFS Program File"
  2117. #define MM_OM           " Orbital Modeling "
  2118. #define MM_OS           " Orbital Simulation "
  2119. #define MM_EXIT         " Exit from SFS "
  2120. #define SFSERR_GRINIT   "ERROR: Failed to initialize graphics system.\n"
  2121. #define MEMERR_DS       "Cannot allocate memory for directory structure %d \n"
  2122. #define MEMERR_TA       "Cannot allocate memory for title array %d \n"
  2123. #define UNTPROG         "(As yet untitled)"
  2124. SHAR_EOF
  2125. true || echo 'restore of sfs/sfs/sfsm.h failed'
  2126. fi
  2127. echo 'End of  part 19'
  2128. echo 'File sfs/sfs/sfsm.h is continued in part 20'
  2129. echo 20 > _shar_seq_.tmp
  2130. exit 0
  2131. exit 0 # Just in case...
  2132. -- 
  2133. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2134. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2135. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2136. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2137.