home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / EasyTM_src.lha / EasyTM-src / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  2.1 KB  |  102 lines

  1. //************************************
  2. //
  3. // Name : Read.c
  4. //
  5. //************************************
  6.  
  7.  
  8. //**** Header files
  9.  
  10. //** OS Include files
  11. #include <dos/dos.h>
  12. #include <dos/rdargs.h>
  13.  
  14. //** OS function prototypes
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17.  
  18. //** OS function inline calls
  19. #include <pragmas/exec_pragmas.h>
  20. #include <pragmas/dos_pragmas.h>
  21.  
  22. //** ANSI C includes
  23. #include <string.h>
  24. //#include <stdio.h>
  25.  
  26. //** application include
  27. #include "Read.h"
  28. #include "Node.h"
  29.  
  30.  
  31. //**** non-local vars
  32.  
  33. extern struct Library *DOSBase;
  34.  
  35.  
  36. //**** Declarations
  37.  
  38. #define BUFSIZE        256
  39.  
  40. #define TEMPLATE  "MENUTEXT/A,FILENAME/A,DIR/A,LC/A/N,STACK/A/N,PRI/A/N"
  41. #define OPT_TEXT    0
  42. #define OPT_FILE    1
  43. #define OPT_DIR        2
  44. #define OPT_CODE    3
  45. #define OPT_STACK    4
  46. #define OPT_PRI        5
  47. #define OPT_COUNT    6
  48.  
  49.  
  50. //**** Read Tools file
  51.  
  52. int ReadFile(STRPTR FileName) {
  53.   char buffer[BUFSIZE];
  54.   BPTR fh;
  55.   struct ProgNode *pn;
  56.   BOOL reading;
  57.   struct RDArgs rdargs;
  58.   long opts[OPT_COUNT];
  59.  
  60.   if (0==FreeList(0)) {
  61.     return 0;
  62.   } // if FreeList
  63.  
  64.   if (NULL==(fh=Open(FileName,MODE_OLDFILE))) {
  65.     //intf("ReadPrefs ERROR : Could not open file %s\n",FileName);
  66.     return 0;
  67.   } // if open
  68.  
  69.   memset(&rdargs,0,sizeof(rdargs));
  70.   rdargs.RDA_Flags=RDAF_NOPROMPT;
  71.   rdargs.RDA_Source.CS_Buffer=buffer;
  72.   rdargs.RDA_Source.CS_Length=BUFSIZE;
  73.   for (reading=TRUE; TRUE==reading ; ) {
  74.     if (NULL==FGets(fh,buffer,BUFSIZE)) {
  75.       reading=FALSE;
  76.       break;
  77.     } // if
  78.     rdargs.RDA_Source.CS_CurChr=0;
  79.     if (ReadArgs(TEMPLATE,opts,&rdargs)) {
  80.       if (NULL==(pn=NewNode())) break;
  81.       pnSetItem(pn,(char *)opts[OPT_TEXT]);
  82.       pnSetFilename(pn,(char *)opts[OPT_FILE]);
  83.       pnSetDirectory(pn,(char *)opts[OPT_DIR]);
  84.       pn->pn_LaunchCode=(ULONG)*(ULONG *)opts[OPT_CODE];
  85.       pn->pn_Stack=(ULONG)*(ULONG *)opts[OPT_STACK];
  86.       pn->pn_Priority=(LONG)*(LONG *)opts[OPT_PRI];
  87.       pn->pn_appmenu=NULL;
  88.       AddTail( List, (struct Node *)pn );
  89.       FreeArgs(&rdargs);
  90.     } else {
  91.       //intf("bad rdargs\n");
  92. //      reading=FALSE;
  93. //      break;
  94.     }
  95.   } // for
  96.   Close(fh);
  97.  
  98.   return 1;
  99. } // ReadFile
  100.  
  101. //**** End of file
  102.