home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / advsys.zip / ADVCIO.C < prev    next >
Text File  |  1987-06-28  |  4KB  |  141 lines

  1. /* advcio.c - system dependant code for AdvCom */
  2. /*
  3.     Copyright (c) 1986, by David Michael Betz
  4.     All rights reserved
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <fcntl.h>
  9.  
  10. /* status values */
  11. #define ST_OK    1
  12. #define ST_ERR    0
  13.  
  14. /* external routines */
  15. extern long lseek();
  16.  
  17. /* advinit - initialize */
  18. /*
  19.     This function parses the argument list and returns the
  20.     input and output file names.
  21. */
  22. advinit(banner,argc,argv,ifile,ofile)
  23.   char *banner;    /* program banner text */
  24.   int argc;    /* argc passed to main() */
  25.   int *argv[];    /* argv passed to main() */
  26.   char *ifile;    /* input file name (output) */
  27.   char *ofile;    /* output file name (output) */
  28. {
  29.     /* print the banner text */
  30.     printf("%s\n",banner);
  31.  
  32.     /* check the argument count */
  33.     if (argc < 2)
  34.     advfatal("usage: advcom <file> [ <ofile> ]");
  35.     
  36.     /* get the input file name (adventure source file) */
  37.     strcpy(ifile,argv[1]); strcat(ifile,".adv");
  38.  
  39.     /* get the output file name (adventure data file) */
  40.     strcpy(ofile,(argc < 3 ? argv[1] : argv[2])); strcat(ofile,".dat");
  41. }
  42.  
  43. /* advcreate - create a binary data file */
  44. /*
  45.     This function *must* create the file in binary mode so that
  46.     subsequent writes will also be in binary mode.  No character
  47.     translations should be done during writes.  You probably
  48.     won't need to modify this function unless your runtime
  49.     library defaults to ASCII mode for files created with creat().
  50. */
  51. int advcreate(name,pfd)
  52.   char *name;    /* file name */
  53.   int *pfd;    /* file descriptor (output) */
  54. {
  55.     /* create the file in ***BINARY*** mode */
  56.     if ((*pfd = creat(name,0666)) < 0)
  57.     return (ST_ERR);
  58.  
  59.     /* return successfully */
  60.     return (ST_OK);
  61. }
  62.  
  63. /* advclose - close a binary data file */
  64. /*
  65.     You probably won't need to modify this routine.  It was
  66.     added as a hook to allow the use of non-UNIX style file
  67.     I/O routines.
  68. */
  69. int advclose(fd)
  70.   int fd;
  71. {
  72.     /* close the binary file */
  73.     if (close(fd) != 0)
  74.     return (ST_ERR);
  75.  
  76.     /* return successfully */
  77.     return (ST_OK);
  78. }
  79.  
  80. /* advseek - seek to a position in a binary data file */
  81. /*
  82.     You probably won't need to modify this routine.  It was
  83.     added as a hook to allow the use of non-UNIX style file
  84.     I/O routines.
  85. */
  86. int advseek(fd,pos)
  87.   int fd; long pos;
  88. {
  89.     /* seek to the position */
  90.     if (lseek(fd,pos,0) != pos)
  91.     return (ST_ERR);
  92.  
  93.     /* return successfully */
  94.     return (ST_OK);
  95. }
  96.  
  97. /* advwrite - write to a binary data file */
  98. /*
  99.     This function must write data in binary mode.  No character
  100.     translations should be done here.
  101. */
  102. int advwrite(fd,buf,len)
  103.   int fd; char *buf; int len;
  104. {
  105.     /* write the data */
  106.     if (write(fd,buf,len) != len)
  107.     return (ST_ERR);
  108.  
  109.     /* return successfully */
  110.     return (ST_OK);
  111. }
  112.  
  113. /* advfatal - print a fatal error message and exit */
  114. /*
  115.     You can probably leave this function as-is.  It was added
  116.     to the machine/compiler dependant module to provide a hook
  117.     for using alert boxes on machines like the Macintosh and
  118.     the Atari-ST.
  119. */
  120. advfatal(msg)
  121.   char *msg;
  122. {
  123.     fprintf(stderr,msg);
  124.     advpause();
  125.     exit(1);
  126. }
  127.  
  128. /* advpause - pause at the end of the adventure before returning to the OS */
  129. /*
  130.     This routine is provided as a hook for machines that clear the
  131.     screen before returning to the OS.  It is called after each
  132.     error message is printed.  It can also be used to prevent error
  133.     messages from scrolling off the screen before they have been
  134.     seen by the user.  This is especially useful on systems that
  135.     don't support XON/XOFF flow control.
  136. */
  137. advpause()
  138. {
  139. }
  140.  
  141.