home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / filesppt.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  3KB  |  124 lines

  1. // file, error, etc support
  2. // Dave Stampe, 4/1/94
  3.  
  4.  
  5. /*
  6.  This code is part of the VR-386 project, created by Dave Stampe.
  7.  VR-386 is a desendent of REND386, created by Dave Stampe and
  8.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  9.  Stampre for VR-386.
  10.  
  11.  Copyright (c) 1994 by Dave Stampe:
  12.  May be freely used to write software for release into the public domain
  13.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  14.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  15.  this software or source code into their products!  Usually there is no
  16.  charge for under 50-100 items for low-cost or shareware products, and terms
  17.  are reasonable.  Any royalties are used for development, so equipment is
  18.  often acceptable payment.
  19.  
  20.  ATTRIBUTION:  If you use any part of this source code or the libraries
  21.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  22.  and any other authors in your documentation, source code, and at startup
  23.  of your program.  Let's keep the freeware ball rolling!
  24.  
  25.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  26.  REND386, improving programmer access by rewriting the code and supplying
  27.  a standard API.  If you write improvements, add new functions rather
  28.  than rewriting current functions.  This will make it possible to
  29.  include you improved code in the next API release.  YOU can help advance
  30.  VR-386.  Comments on the API are welcome.
  31.  
  32.  CONTACT: dstampe@psych.toronto.edu
  33. */
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. #include <ctype.h>
  39. #include <dos.h>
  40. #include <conio.h>     /* kbhit() */
  41. #include <bios.h>      /* bioskey() */
  42. #include <string.h>    /* strlen() */
  43.  
  44. #include "vr_api.h"
  45.  
  46.  
  47. extern FILE *logfile;
  48.  
  49. WORD errprintf(char *fmt, ...)
  50. {
  51.    char buffer[180];
  52.    va_list argptr;
  53.    int cnt;
  54.  
  55.    va_start(argptr, fmt);
  56.    cnt = vsprintf(buffer, fmt, argptr);
  57.    va_end(argptr);
  58.  
  59.    if(log_file) fprintf(log_file,"%s\n",buffer);
  60.    if(!in_graphics)
  61.        fprintf(stderr,"%s\n",buffer);
  62.    if(in_graphics)
  63.      {
  64.        buffer[35] = 0;
  65.        save_screen();
  66.        popmsg(buffer);
  67.        get_response(1);
  68.        restore_screen();
  69.      }
  70.  
  71.    return(cnt);
  72. }
  73.  
  74.  
  75.     // prints to "popmsg" box
  76.     // useful for debugging
  77.     // prints to stderr if not in graphics mode
  78. WORD popprintf(char *fmt, ...)
  79. {
  80.   char buffer[180];
  81.   va_list argptr;
  82.   int cnt;
  83.  
  84.   va_start(argptr, fmt);
  85.   cnt = vsprintf(buffer, fmt, argptr);
  86.   va_end(argptr);
  87.  
  88.    if(!in_graphics)
  89.        fprintf(stderr,"%s\n",buffer);
  90.    if(in_graphics)
  91.      {
  92.        buffer[35] = 0;
  93.        popmsg(buffer);
  94.      }
  95.  
  96.    return(cnt);
  97. }
  98.  
  99.  
  100. void add_ext(char *name, char *ext)    // add extension to filename
  101. {
  102.   char *c;
  103.   if(strchr(name, '.')) return;
  104.   c = strchr(name, 0);
  105.   *c++ = '.';
  106.   *c++ = *ext++;
  107.   *c++ = *ext++;
  108.   *c++ = *ext++;
  109.   *c = 0;
  110. }
  111.  
  112. static char tempname[100];
  113. char loadpath[100] = "";
  114.  
  115. char *fix_fname(char *name)
  116. {
  117.   if (loadpath[0] && !strchr(name, '\\') && !strchr(name, '/'))
  118.     sprintf(tempname, "%s\\%s", loadpath, name);
  119.   else
  120.     strcpy(tempname, name);
  121.   return tempname;
  122. }
  123.  
  124.