home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / filestack < prev    next >
Encoding:
Text File  |  1991-02-04  |  5.0 KB  |  145 lines

  1. /* > $.CLIB.C.filestack
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      routines to control the stacking of file load/save/auto-load routines
  21.  */
  22. #include "includes.h"
  23.  
  24. typedef struct filestore {
  25.         int     (*code)(char *, buffer *);
  26.         char    name[256];
  27.         char    type[8];
  28. } filestore;
  29.  
  30. typedef struct autostore {
  31.         int     (*code)(char *, buffer *);
  32.         char    type[8];
  33. } autostore;
  34.  
  35. #define HASWIN_MAXFILES         8
  36. static filestore haswin_savefilestack[HASWIN_MAXFILES];
  37. static int       haswin_savefilestackptr = 0;
  38. static filestore haswin_loadfilestack[HASWIN_MAXFILES];
  39. static int       haswin_loadfilestackptr = 0;
  40. static autostore haswin_autoloadstack[HASWIN_MAXFILES];
  41. static int       haswin_autoloadstackptr = 0;
  42.  
  43. /*
  44.  *      push the current autoloadroutine onto the autoloadroutine stack and
  45.  *      set a new one if we can.
  46.  */
  47. int haswin_pushautoloadroutine(int (*user)(char *, buffer *), char *type) {
  48.  
  49.         if (haswin_autoloadstackptr == HASWIN_MAXFILES)
  50.                 return(HASWIN_FALSE);
  51.         haswin_autoloadstack[haswin_autoloadstackptr].code =
  52.                 haswin_autoloadroutine;
  53.         haswin_decodefiletype(haswin_autoloadtype, haswin_autoloadstack[haswin_autoloadstackptr].type);
  54.         haswin_autoloadstackptr++;
  55.         haswin_setautoloadroutine(user, type);
  56.         return(HASWIN_TRUE);
  57. }
  58.  
  59. /*
  60.  *      push the current loadfileroutine onto the loadfileroutine stack and
  61.  *      set a new one if we can.
  62.  */
  63. int haswin_pushloadfileroutine(int (*user)(char *, buffer *), char *name, char *type) {
  64.  
  65.         if (haswin_loadfilestackptr == HASWIN_MAXFILES)
  66.                 return(HASWIN_FALSE);
  67.         haswin_loadfilestack[haswin_loadfilestackptr].code =
  68.                 haswin_loadfileroutine;
  69.         strcpy(haswin_loadfilestack[haswin_loadfilestackptr].name,
  70.                 haswin_defaultloadfile);
  71.         haswin_decodefiletype(haswin_loadfiletype, haswin_loadfilestack[haswin_loadfilestackptr].type);
  72.         haswin_loadfilestackptr++;
  73.         haswin_setloadfileroutine(user, name, type);
  74.         return(HASWIN_TRUE);
  75. }
  76.  
  77. /*
  78.  *      push the current savefileroutine onto the savefileroutine stack and
  79.  *      set a new one if we can.
  80.  */
  81. int haswin_pushsavefileroutine(int (*user)(char *, buffer *), char *name, char *type) {
  82.  
  83.         if (haswin_savefilestackptr == HASWIN_MAXFILES)
  84.                 return(HASWIN_FALSE);
  85.         haswin_savefilestack[haswin_savefilestackptr].code =
  86.                 haswin_savefileroutine;
  87.         strcpy(haswin_savefilestack[haswin_savefilestackptr].name,
  88.                 haswin_defaultsavefile);
  89.         haswin_decodefiletype(haswin_savefiletype, haswin_savefilestack[haswin_savefilestackptr].type);
  90.         haswin_savefilestackptr++;
  91.         haswin_setsavefileroutine(user, name, type);
  92.         return(HASWIN_TRUE);
  93. }
  94.  
  95. /*
  96.  *      pull an autoloadroutine from the autoload stack if we can
  97.  */
  98. int haswin_popautoloadroutine(void) {
  99.  
  100.         if (haswin_autoloadstackptr <= 0) {
  101.                 haswin_setautoloadroutine(0, "");
  102.                 return(HASWIN_FALSE);
  103.         }
  104.         haswin_autoloadstackptr--;
  105.         haswin_setautoloadroutine(
  106.                 haswin_autoloadstack[haswin_autoloadstackptr].code,
  107.                 haswin_autoloadstack[haswin_autoloadstackptr].type);
  108.         return(HASWIN_TRUE);
  109. }
  110.  
  111. /*
  112.  *      pull a loadfileroutine from the loadfile stack if we can
  113.  */
  114. int haswin_poploadfileroutine(void) {
  115.  
  116.         if (haswin_loadfilestackptr <= 0) {
  117.                 haswin_setloadfileroutine(0, "", "");
  118.                 return(HASWIN_FALSE);
  119.         }
  120.         haswin_loadfilestackptr--;
  121.         haswin_setloadfileroutine(
  122.                 haswin_loadfilestack[haswin_loadfilestackptr].code,
  123.                 haswin_loadfilestack[haswin_loadfilestackptr].name,
  124.                 haswin_loadfilestack[haswin_loadfilestackptr].type);
  125.         return(HASWIN_TRUE);
  126. }
  127.  
  128. /*
  129.  *      pull a savefileroutine from the savefile stack if we can
  130.  */
  131. int haswin_popsavefileroutine(void) {
  132.  
  133.         if (haswin_savefilestackptr <= 0) {
  134.                 haswin_setsavefileroutine(0, "", "");
  135.                 return(HASWIN_FALSE);
  136.         }
  137.         haswin_savefilestackptr--;
  138.         haswin_setsavefileroutine(
  139.                 haswin_savefilestack[haswin_savefilestackptr].code,
  140.                 haswin_savefilestack[haswin_savefilestackptr].name,
  141.                 haswin_savefilestack[haswin_savefilestackptr].type);
  142.         return(HASWIN_TRUE);
  143. }
  144.  
  145.