home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / FileMover / HF-OM1.DMS / in.adf / OpusSDK.lha / SDK / source / modinit.c
Encoding:
C/C++ Source or Header  |  1996-11-05  |  3.8 KB  |  160 lines

  1. /****************************************************************************
  2.  
  3.  modinit.c - standard initialisation for Opus 5 modules
  4.  
  5.  ****************************************************************************/
  6.  
  7. #define _DOPUS_MODULE_DEF
  8. #include <dopus/modules.h>
  9.  
  10. #ifndef CLIB_EXEC_PROTOS_H
  11. #include <clib/exec_protos.h>
  12. #include <pragmas/exec_pragmas.h>
  13. #endif
  14.  
  15. #ifndef EXEC_MEMORY_H
  16. #include <exec/memory.h>
  17. #endif
  18.  
  19. #ifndef CLIB_LOCALE_PROTOS_H
  20. #include <clib/locale_protos.h>
  21. #include <pragmas/locale_pragmas.h>
  22. #endif
  23.  
  24. // SAS/C stuff
  25. int __saveds __UserLibInit(void);
  26. void __saveds __UserLibCleanup(void);
  27.  
  28. // The libraries we open
  29. struct Library *DOSBase;
  30. struct Library *DOpusBase;
  31. struct Library *IntuitionBase;
  32. struct Library *GfxBase;
  33. struct Library *IconBase;
  34. struct Library *LocaleBase;
  35. struct Library *UtilityBase;
  36. struct Library *LayersBase;
  37. struct Library *WorkbenchBase;
  38. struct Library *GadToolsBase;
  39. struct Library *AslBase;
  40. struct Library *DiskfontBase;
  41. struct Library *TimerBase;
  42. struct Library *RexxSysBase;
  43.  
  44. // Locale pointer
  45. struct DOpusLocale *locale;
  46.  
  47. // Library initialisation code
  48. __saveds __UserLibInit()
  49. {
  50.     // Initialise pointers
  51.     DOpusBase=0;
  52.     IntuitionBase=0;
  53.     GfxBase=0;
  54.     IconBase=0;
  55.     LocaleBase=0;
  56.     UtilityBase=0;
  57.     LayersBase=0;
  58.     WorkbenchBase=0;
  59.     GadToolsBase=0;
  60.     DiskfontBase=0;
  61.     AslBase=0;
  62.     RexxSysBase=0;
  63.     locale=0;
  64.  
  65.     // Get DOS library (can't really fail)
  66.     DOSBase=OpenLibrary("dos.library",0);
  67.  
  68.     // Open other libraries we need
  69.     if (!(DOpusBase=OpenLibrary("dopus5.library",55)) ||
  70.         !(IntuitionBase=OpenLibrary("intuition.library",37)) ||
  71.         !(GfxBase=OpenLibrary("graphics.library",37)) ||
  72.         !(IconBase=OpenLibrary("icon.library",37)) ||
  73.         !(LayersBase=OpenLibrary("layers.library",37)) ||
  74.         !(GadToolsBase=OpenLibrary("gadtools.library",37)) ||
  75.         !(AslBase=OpenLibrary("asl.library",37)) ||
  76.         !(DiskfontBase=OpenLibrary("diskfont.library",37)) ||
  77.         !(TimerBase=GetTimerBase()) ||
  78.         !(UtilityBase=OpenLibrary("utility.library",37))) return 1;
  79.  
  80.     // Libraries we don't need but want
  81.     WorkbenchBase=OpenLibrary("workbench.library",0);
  82.     RexxSysBase=OpenLibrary("rexxsyslib.library",0);
  83.  
  84.     // Allocate and open locale data
  85.     if (!(locale=AllocVec(sizeof(struct DOpusLocale),MEMF_CLEAR)))
  86.         return 1;
  87.     init_locale_data(locale);
  88.  
  89.     // Open locale library
  90.     if (LocaleBase=OpenLibrary("locale.library",38))
  91.     {
  92.         // Store library pointer
  93.         locale->li_LocaleBase=LocaleBase;
  94.  
  95.         // Open catalog if name supplied
  96.         if (module_info.locale_name)
  97.         {
  98.             struct TagItem tags[2];
  99.  
  100.             // If MODULEF_CATALOG_VERSION is set, we do version checking
  101.             tags[0].ti_Tag=(module_info.flags&MODULEF_CATALOG_VERSION)?OC_Version:TAG_IGNORE;
  102.             tags[0].ti_Data=module_info.ver;
  103.             tags[1].ti_Tag=TAG_END;
  104.  
  105.             // Open catalog
  106.             locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,tags);
  107.         }
  108.  
  109.         // Get default lolale
  110.         locale->li_Locale=OpenLocale(0);
  111.     }
  112.  
  113.     // Succeeded
  114.     return 0;
  115. }
  116.  
  117.  
  118. // Clean up
  119. void __saveds __UserLibCleanup()
  120. {
  121.     // Free locale stuff
  122.     if (locale)
  123.     {
  124.         if (LocaleBase)
  125.         {
  126.             CloseLocale(locale->li_Locale);
  127.             CloseCatalog(locale->li_Catalog);
  128.             CloseLibrary(LocaleBase);
  129.         }
  130.         FreeVec(locale);
  131.     }
  132.  
  133.     // Close libraries
  134.     CloseLibrary(DOpusBase);
  135.     CloseLibrary(IntuitionBase);
  136.     CloseLibrary(GfxBase);
  137.     CloseLibrary(IconBase);
  138.     CloseLibrary(LayersBase);
  139.     CloseLibrary(UtilityBase);
  140.     CloseLibrary(WorkbenchBase);
  141.     CloseLibrary(DiskfontBase);
  142.     CloseLibrary(RexxSysBase);
  143.     CloseLibrary(AslBase);
  144.     CloseLibrary(DOSBase);
  145. }
  146.  
  147.  
  148. // This routine is called by Opus to find out what the module does
  149. ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
  150. {
  151.     // Return module information
  152.     if (num==-1) return &module_info;
  153.  
  154.     // Valid function number?
  155.     if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
  156.  
  157.     // Return function description
  158.     return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
  159. }
  160.