home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / v-23 / engine.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  171 lines

  1. ;/* Engine.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 Engine.c
  3. quit ;*/
  4.  
  5. /* (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.       */
  6. /* The information contained herein is subject to change without notice,  */
  7. /* and is provided "as is" without warranty of any kind, either expressed */
  8. /* or implied.  The entire risk as to the use of this information is      */
  9. /* assumed by the user.                                                   */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <dos/dostags.h>
  14. #include <dos/dos.h>
  15. #include <diskfont/diskfonttag.h>
  16. #include <diskfont/diskfont.h>
  17. #include <diskfont/glyph.h>
  18. #include <diskfont/oterrors.h>
  19. #include <utility/tagitem.h>
  20. #include <string.h>
  21.  
  22. #include <clib/dos_protos.h>
  23. #include <clib/exec_protos.h>
  24. #include <clib/utility_protos.h>
  25. #include <clib/bullet_protos.h>
  26.  
  27. #define OTAG_ID 0x0f03   /* this really belongs in <diskfont/diskfont.h>, */
  28.                          /* but it's not there, yet.                      */
  29.  
  30. extern UBYTE   *librarystring; /* ".library", defined in BulletMain.c. */
  31.  
  32. struct TagItem *AllocOtag(STRPTR);
  33. void            FreeOtag(void *);
  34. struct Library *OpenScalingLibrary(struct TagItem *);
  35. void            CloseScalingLibrary(struct Library *);
  36. struct GlyphEngine *GetGlyphEngine(struct TagItem *, STRPTR);
  37. void            ReleaseGlyphEngine(struct GlyphEngine *);
  38.  
  39. #define BUFSIZE     256
  40.  
  41. extern struct Library *BulletBase, *UtilityBase;
  42.  
  43. /*************************************************************************************/
  44. /* open the otag file, allocate a buffer, read the file into the buffer, verify that */
  45. /* the file is OK, relocate all of the address relocation tags, close the otag file. */
  46. /*************************************************************************************/
  47. struct TagItem *
  48. AllocOtag(STRPTR otagname)
  49. {
  50.   BPTR            otfile;
  51.   struct TagItem *ti, *tip, *returnti;
  52.   struct FileInfoBlock *fib;
  53.  
  54.   ti = NULL;
  55.  
  56.   if (fib = AllocDosObject(DOS_FIB, NULL))    /* The FileInfoBlock of the OTAG file */
  57.   {                                           /* contains the file's size.          */
  58.     if (otfile = Open(otagname, MODE_OLDFILE))
  59.     {
  60.       if (ExamineFH(otfile, fib))
  61.       {
  62.         if (returnti = (struct TagItem *) AllocVec(fib->fib_Size, MEMF_CLEAR))
  63.         {
  64.           if (Read(otfile, (UBYTE *) returnti, fib->fib_Size))
  65.           {
  66.             if ((returnti->ti_Tag == OT_FileIdent)               /* Test to see if */
  67.                 && (returnti->ti_Data == (ULONG) fib->fib_Size)) /* the OTAG file  */
  68.             {                                                    /* is valid.      */
  69.               tip = returnti;
  70.               while (ti = NextTagItem(&tip))     /* Step through and relocate tags */
  71.               {
  72.                 if (ti->ti_Tag & OT_Indirect)
  73.                 {
  74.                   ti->ti_Data = (ULONG) returnti + ti->ti_Data;
  75.                 }
  76.               }
  77.             }
  78.           }
  79.         }
  80.       }
  81.       Close(otfile);
  82.     }
  83.     FreeDosObject(DOS_FIB, fib);
  84.   }
  85.   return (returnti);
  86. }
  87.  
  88. /**************************************************************************/
  89. /*********** Deallocates resources allocated by AllocOtag(). **************/
  90. /**************************************************************************/
  91. void
  92. FreeOtag(void *vector)
  93. {
  94.   FreeVec(vector);
  95. }
  96.  
  97.  
  98. /*****************************************************************************/
  99. /******* Scans through a TagList looking for an scaling engine name. *********/
  100. /*******           If it finds one, it opens that library.           *********/
  101. /*****************************************************************************/
  102. struct Library *
  103. OpenScalingLibrary(struct TagItem * ti)
  104. {
  105.   STRPTR          enginename;
  106.   UBYTE           libnamebuffer[BUFSIZE];
  107.  
  108.   if (enginename = (STRPTR) GetTagData(OT_Engine, NULL, ti))
  109.   {
  110.     strcpy(libnamebuffer, enginename);
  111.     strcat(libnamebuffer, librarystring);
  112.  
  113.     return (OpenLibrary(libnamebuffer, 0L));
  114.   }
  115.   return(NULL);  /*   <----- BUG!:--  This line was missing in the original */
  116. }                /*                        publication of this code module. */
  117.  
  118. /**************************************************************************/
  119. /******* Deallocates resources allocated by OpenScalingLibrary(). *********/
  120. /**************************************************************************/
  121. void
  122. CloseScalingLibrary(struct Library * bbase)
  123. {
  124.   CloseLibrary(bbase);
  125. }
  126.  
  127.  
  128. /**************************************************************************/
  129. /* Open the glyph engine, give it the tags from the otag file, and set up */
  130. /* a default device dpi so it doesn't crash if someone forgets to set it. */
  131. /**************************************************************************/
  132. struct GlyphEngine *
  133. GetGlyphEngine(struct TagItem * ti, STRPTR otagpath)
  134. {
  135.   struct GlyphEngine *ge = NULL;
  136.   BOOL            ok = TRUE;
  137.  
  138.   if (ge = OpenEngine())
  139.   {
  140.     ok = FALSE;
  141.     if (SetInfo(ge,
  142.                 OT_OTagList, ti,
  143.                 OT_OTagPath, otagpath,
  144.                 TAG_END) == OTERR_Success)
  145.     {
  146.       if (SetInfo(ge,
  147.                   OT_DeviceDPI, ((ULONG) 77) << 16 | 75,
  148.                   TAG_END) == OTERR_Success)
  149.       {
  150.         ok = TRUE;
  151.       }
  152.     }
  153.   }
  154.  
  155.   if (!ok)
  156.   {
  157.     CloseEngine(ge);
  158.     ge = NULL;
  159.   }
  160.   return (ge);
  161. }
  162.  
  163. /**************************************************************************/
  164. /********* Deallocates resources allocated by GetGlyphEngine(). ***********/
  165. /**************************************************************************/
  166. void
  167. ReleaseGlyphEngine(struct GlyphEngine * ge)
  168. {
  169.   CloseEngine(ge);
  170. }
  171.