home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / fish / 831-840 / ff833 / zip / zip-1.00.lha / osdepend.c < prev    next >
C/C++ Source or Header  |  1992-10-09  |  4KB  |  198 lines

  1. /*
  2.  * osdepend.c
  3.  *
  4.  * All non screen specific operating system dependent routines.
  5.  *
  6.  * Olaf Barthel 28-Jul-1992 V1.0
  7.  *
  8.  */
  9.  
  10. #ifdef MAC
  11. #include <console.h>
  12. #endif
  13. #include "ztypes.h"
  14.  
  15. /* File names will be O/S dependent */
  16.  
  17. #if defined(amiga)
  18. #define SAVE_NAME "Story.Save"  /* Default save name */
  19. #define SCRIPT_NAME "PRT:"      /* Default script name */
  20. #else /* !defined(amiga) */
  21. #define SAVE_NAME "story.sav"   /* Default save name */
  22. #define SCRIPT_NAME "story.lis" /* Default script name */
  23. #endif /* defined(amiga) */
  24.  
  25. /*
  26.  * process_arguments
  27.  *
  28.  * Do any argument preprocessing necessary before the game is
  29.  * started. This may include selecting a specific game file or
  30.  * setting interface-specific options.
  31.  *
  32.  */
  33.  
  34. #ifdef __STDC__
  35. void process_arguments (int argc, char *argv[])
  36. #else
  37. void process_arguments (argc, argv)
  38. int argc;
  39. char *argv[];
  40. #endif
  41. {
  42.  
  43. #ifdef MAC
  44.     argc = ccommand (&argv);
  45. #endif
  46.  
  47.     if (argc < 2) {
  48.         fprintf (stderr, "Usage: %s story-file-name [restore-file_name]", argv[0]);
  49.         exit (EXIT_FAILURE);
  50.     }
  51.  
  52.     open_story (argv[1]);
  53.  
  54.     if (argc > 2)
  55.         restore_name = argv[2];
  56.  
  57. }/* process_arguments */
  58.  
  59. /*
  60.  * file_cleanup
  61.  *
  62.  * Perform actions when a file is successfully closed. Flag can be one of:
  63.  * GAME_SAVE, GAME_RESTORE, GAME_SCRIPT.
  64.  *
  65.  */
  66.  
  67. #ifdef __STDC__
  68. void file_cleanup (const char *file_name, int flag)
  69. #else
  70. void file_cleanup (file_name, flag)
  71. const char *file_name;
  72. int flag;
  73. #endif
  74. {
  75.  
  76. }/* file_cleanup */
  77.  
  78. /*
  79.  * sound
  80.  *
  81.  * Play a sound file or a note.
  82.  *
  83.  * argc = 1: argv[0] = note# (range 1 - 3)
  84.  *
  85.  *           Play note.
  86.  *
  87.  * argc = 2: argv[0] = 0
  88.  *           argv[1] = 3
  89.  *
  90.  *           Stop playing current sound.
  91.  *
  92.  * argc = 2: argv[0] = 0
  93.  *           argv[1] = 4
  94.  *
  95.  *           Free allocated resources.
  96.  *
  97.  * argc = 3: argv[0] = ID# of sound file to replay.
  98.  *           argv[1] = 2
  99.  *           argv[2] = Volume to replay sound with, this value
  100.  *                     can range between 1 and 8.
  101.  *
  102.  *           Play sound file.
  103.  *
  104.  */
  105.  
  106. #ifdef __STDC__
  107. void sound (int argc, zword_t *argv)
  108. #else
  109. void sound (argc, argv)
  110. int argc;
  111. zword_t *argv;
  112. #endif
  113. {
  114.  
  115.     /* Generic bell sounder */
  116.  
  117.     if (argc == 1 || (argc >= 2 && argv[1] == 2))
  118.         display_char ('\007');
  119.  
  120. }/* sound */
  121.  
  122. /*
  123.  * get_file_name
  124.  *
  125.  * Return the name of a file. Flag can be one of: GAME_SAVE, GAME_RESTORE or
  126.  * GAME_SCRIPT.
  127.  *
  128.  */
  129.  
  130. #ifdef __STDC__
  131. int get_file_name (char *file_name, char *default_name, int flag)
  132. #else
  133. int get_file_name (file_name, default_name, flag)
  134. char *file_name;
  135. char *default_name;
  136. int flag;
  137. #endif
  138. {
  139.     int status, saved_scripting_disable;
  140.  
  141.     if (default_name[0] == '\0')
  142.         if (flag == GAME_SCRIPT)
  143.             strcpy (default_name, SCRIPT_NAME);
  144.         else
  145.             strcpy (default_name, SAVE_NAME);
  146.  
  147.     saved_scripting_disable = scripting_disable;
  148.     scripting_disable = ON;
  149.  
  150.     status = TRUE;
  151.  
  152.     output_stringnl ("Enter a file name.");
  153.     output_string ("(Default is \"");
  154.     output_string (default_name);
  155.     output_string ("\"): ");
  156.  
  157.     input[0] = (char) (screen_cols - RIGHT_MARGIN - 1 -
  158.         sizeof ("(Default is \"") - strlen (default_name) - sizeof ("\"): "));
  159.  
  160.     input_line ();
  161.  
  162.     if (input[1]) {
  163.         input[input[1] + 2] = '\0';
  164.         strcpy (file_name, &input[2]);
  165.     } else
  166.         strcpy (file_name, default_name);
  167.  
  168. #if !defined(VMS) /* VMS has file version numbers, so cannot overwrite */
  169.     if (flag == GAME_SAVE || flag == GAME_SCRIPT) {
  170.         FILE *tfp;
  171.         char c;
  172.  
  173.         tfp = fopen (file_name, "r");
  174.         if (tfp != NULL) {
  175.             fclose (tfp);
  176.  
  177.             output_stringnl ("You are about to write over an existing file.");
  178.             output_string ("Proceed? (Y/N) ");
  179.  
  180.             do
  181.                 c = toupper (input_character ());
  182.             while (c != 'Y' && c != 'N');
  183.  
  184.             display_char (c);
  185.             scroll_line ();
  186.  
  187.             if (c == 'N')
  188.                 status = FALSE;
  189.         }
  190.     }
  191. #endif /* !defined(VMS) */
  192.  
  193.     scripting_disable = saved_scripting_disable;
  194.  
  195.     return (status);
  196.  
  197. }/* get_file_name */
  198.