home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Tools / ReActor / Examples / EuroCalc / EuroCalc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  27.9 KB  |  836 lines

  1. /* Michael Christoph Software */
  2. /* EuroCalc - Euro-Währungsrechner */
  3. /* EuroCalc.c: Main-Routinen */ 
  4. /* V1.00: 17.07.-18.08.1999, created */
  5. /* V1.01: 25.10.1999, updated + localized */
  6.  
  7. /* !!!!! Published with the Amiga NDK are welcome !!!!! */
  8.  
  9. /******************************* ERKLÄRUNG *************************************
  10. **
  11. ** Ländernamen / Fahnendateien / Hymnendateien:
  12. ** 
  13. ** Europa       europe.iff       -
  14. ** Deutschland  germany.iff      germany.mid
  15. ** Belgien      belgium.iff      belgium.mid
  16. ** Finnland     finland.iff      finland.mid
  17. ** Frankreich   france.iff       france.mid
  18. ** Irland       ireland.iff      ireland.mid
  19. ** Italien      italy.iff        italy.mid
  20. ** Luxemburg    luxemburg.iff    luxemburg.mid
  21. ** Niederlande  netherland.iff   netherland.mid
  22. ** Österreich   austria.iff      austria.mid
  23. ** Portugal     portugal.iff     portugal.mid
  24. ** Spanien      spain.iff        spain.mid
  25. ** 
  26. ** --------------------------------------------------------------------------------
  27. ** 
  28. ** Alle Kommentare sind deutsch und darunter englisch angegeben.
  29. ** Im Programm werden nur englische Bezeichnungen und Variablennamen verwendet.
  30. ** Hier die Übersetzungstabelle:
  31. **   Total        = Betrag
  32. **   Currency     = Währung
  33. **   Currencymark = Währungskennzeichen
  34. **   Exchange     = Wechselkurs
  35. ** Übersetzung der Oberflächenelemente als Catalogdatei.
  36. ** 
  37. ** All comments are first in german an then in english given.
  38. ** Only english names and variablenames will used.
  39. ** Translation from the gui to other countries with catalog-files.
  40. ** 
  41. ** --------------------------------------------------------------------------------
  42. **
  43. ** Das Programm ist nicht vollständig !
  44. ** Beliebige Änderungen und Erweiterungen des Sources sind erwünscht.
  45. **
  46. ** The program is not complete !
  47. ** Any changes and extensions of the source are welcome.
  48. ** - graphic print of the complete window
  49. ** - printing texttable (1,5,10,...) of one currency
  50. ** - arexxport (easy with ReActor)
  51. ** - ... our own ideas ...
  52. **
  53. *******************************************************************************/
  54.  
  55. /*
  56. ** Result for the shell:
  57. **  0 - RETURN_OK     arguments ok or gui was used
  58. **  5 - RETURN_WARN   unused
  59. **  8 - RETURN_BREAK  gui was closed with CTRL-C
  60. ** 10 - RETURN_ERROR  error in arguments (e.g. unknown currency)
  61. ** 20 - RETURN_FAIL   no AmigaOS 3.5, open failed from library, window, ect.
  62. */
  63.  
  64. /************************** PROGRAMM-PARAMETER ********************************/
  65.  
  66. #define PROGNAME "EuroCalc"
  67. #define VERSIONR "1.01"
  68. #define PROGDATE "25.10.1999"
  69. #define COPYRIGT "Copyright © Jul.1999 by Meicky-Soft"
  70.  
  71. const char *version = "\0$VER: " PROGNAME " " VERSIONR " (" PROGDATE ") - " COPYRIGT "\n";
  72.  
  73. /******************************* INCLUDES *************************************/
  74.  
  75. #include "EuroCalcFrame.h"
  76.  
  77. #include <exec/types.h>
  78. #include <exec/alerts.h>
  79. #include <dos/dos.h>
  80. #define RETURN_BREAK 8    /* Ergänzung zu den Defines in dos.h */
  81.                           /* Additional to the defines in dos.h */
  82. #include <intuition/intuition.h>
  83. #include <intuition/gadgetclass.h>
  84. #include <intuition/classusr.h>
  85. #include <libraries/gadtools.h>
  86. #include <classes/window.h>
  87. //#include <classes/arexx.h>
  88. #include <workbench/startup.h>
  89. #include <workbench/icon.h>
  90. #include <reaction/reaction.h>
  91. #include <reaction/reaction_macros.h>
  92.  
  93. #include <clib/alib_protos.h>
  94. #include <clib/exec_protos.h>
  95. #include <clib/dos_protos.h>
  96. #include <clib/intuition_protos.h>
  97. #include <clib/gadtools_protos.h>
  98. #include <clib/locale_protos.h>
  99. #include <clib/icon_protos.h>
  100. #include <clib/resource_protos.h>
  101.  
  102. #include <stdio.h>
  103. #include <stdlib.h>
  104. #include <string.h>
  105.  
  106. /************************ VARIABLEN DEKLARATIONEN *****************************/
  107.  
  108. UBYTE gb_ArgTemplate[]="TOTAL,CURRENCY,TO/K/M,PUBSCREEN/K";
  109. enum { ARG_total, ARG_currency, ARG_to, ARG_pubscreen, ARG_MAX };
  110. LONG gb_Args[ARG_MAX]={ 0,0,0,NULL };
  111.  
  112. /************************ VARIABLEN DEKLARATIONEN *****************************/
  113.  
  114. struct Library       *ResourceBase;
  115. struct IntuitionBase *IntuitionBase;
  116. struct Library       *GadToolsBase;
  117. struct Library       *LocaleBase;
  118. struct Library       *IconBase;
  119.  
  120. struct Screen        *gb_Screen;
  121. struct Window        *gb_Window;
  122. struct Gadget       **gb_Gadgets;
  123. struct Menu          *gb_Menus;
  124. struct Catalog       *gb_Catalog;
  125. struct MsgPort       *gb_IDCMPort;
  126. struct MsgPort       *gb_AppPort;
  127. RESOURCEFILE          gb_Resource;
  128. Object               *gb_WindowObj;
  129. UBYTE                 gb_ProgName[30];
  130.  
  131. /************************ VARIABLEN DEKLARATIONEN *****************************/
  132.  
  133. struct CountryList
  134. {
  135.   UWORD  ll_GadID;       /* GadgetID */
  136.   UBYTE  ll_Currency[5]; /* Währungskennzeichen / Currencymark */
  137.   DOUBLE ll_Exchange;    /* Wechselkurs / rate of exchange */
  138.   UBYTE  ll_Country[20]; /* Ländername / Name of the country */
  139. };
  140.  
  141. struct CountryList gb_Countries[] =
  142. {
  143.   0,"",0,"",                                    /* unused */
  144.   0,"",0,"",                                    /* unused */
  145.   GAD_ID_EUR, "EURO",   1.0     , "Europe"    , /*"Europa"     */
  146.   GAD_ID_DM , "DM"  ,   1.95583 , "Germany"   , /*"Deutschland"*/
  147.   GAD_ID_BFR, "BFR" ,  40.3399  , "Belgium"   , /*"Belgien"    */
  148.   GAD_ID_FMK, "FMK" ,   5.94573 , "Finland"   , /*"Finnland"   */
  149.   GAD_ID_FF , "FF"  ,   6.55957 , "France"    , /*"Frankreich" */
  150.   GAD_ID_IRF, "IRF" ,   0.787564, "Ireland"   , /*"Irland"     */
  151.   GAD_ID_LIT, "LIT" ,1936.27    , "Italy"     , /*"Italien"    */
  152.   GAD_ID_LFR, "LFR" ,  40.3399  , "Luxemburg" , /*"Luxemburg"  */
  153.   GAD_ID_HFL, "HFL" ,   2.20371 , "Netherland", /*"Niederlande"*/
  154.   GAD_ID_OES, "OES" ,  13.7603  , "Austria"   , /*"Österreich" */
  155.   GAD_ID_ESC, "ESC" , 200.482   , "Portugal"  , /*"Portugal"   */
  156.   GAD_ID_PTA, "PTA" , 166.386   , "Spain"     , /*"Spanien"    */
  157. };
  158.  
  159. /*
  160. ** der derzeitige Arrayaufbau und die Gadget-IDs ermöglichen es, daß
  161. ** z.B. per gb_Countries[GAD_ID_EUR] auf die Werte zugegriffen werden kann.
  162. */
  163. /*
  164. ** the actual arraysort and gadgetids can simple use to get the values
  165. ** from the structure with e.g. gb_Countries[GAD_ID_EUR].
  166. */
  167.  
  168. /* niedriegste benutze Länder-ID und Anzahl Array-Einträge */
  169. /* first used country-id and numbers of array-elements */
  170. #define COUNTRY_FIRST GAD_ID_EUR
  171. #define COUNTRY_MAX   (GAD_ID_PTA + 1)
  172.  
  173. /* Ergebniswerte; Array 0 und 1 unbenutzt, wie bei gb_Countires */
  174. /* resultvalues; array 0 and 1 unused, as gb_Countries */
  175. DOUBLE gb_Total[COUNTRY_MAX];
  176.  
  177. /* Ausgabeformat für die Ergebniswerte */
  178. /* Outputstring to format the resultvalues */
  179. #define FMT_CurrencyOutput "%0.2f"
  180.  
  181. /************************ VARIABLEN DEKLARATIONEN *****************************/
  182.  
  183. /* Localisierung der programmeigenen Elemente/Texte */
  184. /* localized of the internal elements and texts */
  185.  
  186. const STRPTR STR_TX_Ok            = "Ok";
  187. const STRPTR STR_TX_SureToQuit    = "\nSure to quit program ?";
  188. const STRPTR STR_TX_QuitYesNo     = "Yes|No";
  189. const STRPTR STR_TX_From          = "from";
  190.  
  191. const STRPTR STR_TX_MENU_Project  = "Project";
  192. const STRPTR STR_TX_MENU_Manual   = "M\0Manual...";
  193. const STRPTR STR_TX_MENU_Print    = "P\0Print";
  194. const STRPTR STR_TX_MENU_Info     = "I\0Info...";
  195. const STRPTR STR_TX_MENU_Quit     = "Q\0Quit...";
  196.  
  197. const STRPTR STR_TX_MENU_Edit     = "Edit";
  198. const STRPTR STR_TX_MENU_ClearAll = "X\0Clear all fields";
  199. const STRPTR STR_TX_MENU_Exchange = "E\0Change exchange...";
  200.  
  201. enum LocaleIDs
  202. {
  203.   TX_Ok                = 1001,
  204.   TX_SureToQuit,
  205.   TX_QuitYesNo,
  206.   TX_From,
  207.  
  208.   TX_MENU_Project      = 1011,
  209.   TX_MENU_Manual,
  210.   TX_MENU_Print,
  211.   TX_MENU_Info,
  212.   TX_MENU_Quit,
  213.   TX_MENU_Edit,
  214.   TX_MENU_ClearAll,
  215.   TX_MENU_Exchange,
  216. };
  217.  
  218. #define CATSTR(id)        GetCatalogStr(gb_Catalog,id,(STRPTR)STR_ ## id)
  219. #define CATSTRSTR(id,str) GetCatalogStr(gb_Catalog,id,(STRPTR)str)
  220.  
  221. /************************ VARIABLEN DEKLARATIONEN *****************************/
  222.  
  223. static struct NewMenu gb_MenuDescribe[] =
  224. {
  225.   NM_TITLE, (STRPTR)STR_TX_MENU_Project,  NULL, 0, 0, (APTR)TX_MENU_Project,  /* "Project" */
  226.   NM_ITEM,  (STRPTR)STR_TX_MENU_Manual,   NULL, 0, 0, (APTR)TX_MENU_Manual,   /* "M\0Manual..." */
  227.   NM_ITEM,  (STRPTR)STR_TX_MENU_Print,    NULL, 0, 0, (APTR)TX_MENU_Print,    /* "P\0Print" */
  228.   NM_ITEM,  (STRPTR)STR_TX_MENU_Info,     NULL, 0, 0, (APTR)TX_MENU_Info,     /* "I\0Info..." */
  229.   NM_ITEM,  NM_BARLABEL,                  NULL, 0, 0, (APTR)0,
  230.   NM_ITEM,  (STRPTR)STR_TX_MENU_Quit,     NULL, 0, 0, (APTR)TX_MENU_Quit,     /* "Q\0Quit..." */
  231.  
  232.   NM_TITLE, (STRPTR)STR_TX_MENU_Edit,     NULL, 0, 0, (APTR)TX_MENU_Edit,     /* "Edit" */
  233.   NM_ITEM,  (STRPTR)STR_TX_MENU_ClearAll, NULL, 0, 0, (APTR)TX_MENU_ClearAll, /* "X\0Clear all field" */
  234.   NM_ITEM,  (STRPTR)STR_TX_MENU_Exchange, NULL, 0, 0, (APTR)TX_MENU_Exchange, /* "E\0Change exchange..." */
  235.  
  236.   NM_END, NULL, NULL, 0, 0, NULL
  237. };
  238.  
  239. /* Menüdefines zur einfacheren Benutzung */
  240. /* Menuedefines for easier used */
  241. #define MENU_ID_Manual    FULLMENUNUM(0,0,NOSUB)
  242. #define MENU_ID_Print     FULLMENUNUM(0,1,NOSUB)
  243. #define MENU_ID_Info      FULLMENUNUM(0,2,NOSUB)
  244. #define MENU_ID_Quit      FULLMENUNUM(0,4,NOSUB)
  245. #define MENU_ID_ClearAll  FULLMENUNUM(1,0,NOSUB)
  246. #define MENU_ID_Exchange  FULLMENUNUM(1,1,NOSUB)
  247.  
  248. /******************************************************************************/
  249.  
  250. const STRPTR FormatCurrency(DOUBLE total)
  251. {
  252.   /* ACHTUNG:
  253.   ** Funktion ist nicht reentrant !
  254.   ** und darf daher nicht mehrfach gleichzeitig aufgerufen werden
  255.   */
  256.   /* Functions in not reentrant ! */
  257.  
  258.   static UBYTE totalstr[10];
  259.   sprintf(totalstr,FMT_CurrencyOutput,total);
  260.   return( totalstr );
  261. }
  262.  
  263. /******************************************************************************/
  264.  
  265. void UpdateGadgets()
  266. {
  267.   /* in allen Gadgets den aktuellen Wert anzeigen */
  268.   /* display in all gadgets the actual values */
  269.  
  270.   ULONG i;
  271.   for(i=COUNTRY_FIRST; i<COUNTRY_MAX; i++)
  272.   {
  273.     SetGadgetAttrs(gb_Gadgets[gb_Countries[i].ll_GadID],gb_Window,NULL,
  274.                    STRINGA_TextVal,FormatCurrency(gb_Total[i]),
  275.                    TAG_DONE);
  276.   }
  277. }
  278.  
  279. /******************************************************************************/
  280.  
  281. void ClearAllGadgets()
  282. {
  283.   /* alle Eingabefelder löschen */
  284.   /* empty all inputgadgets */
  285.  
  286.   ULONG i;
  287.   for(i=COUNTRY_FIRST; i<COUNTRY_MAX; i++)
  288.   {
  289.     gb_Total[i] = 0.0;
  290.  
  291.     SetGadgetAttrs(gb_Gadgets[gb_Countries[i].ll_GadID],gb_Window,NULL,
  292.                    STRINGA_TextVal,"",
  293.                    TAG_DONE);
  294.   }
  295. }
  296.  
  297. /******************************************************************************/
  298.  
  299. DOUBLE Calculate(UWORD currency, DOUBLE input)
  300.   /* Währungs-Umrechnung vornehmen */
  301.   /* 'input' enthält den Zahlenwert und 'currency' die zugehörige Basiswährung */
  302.   /* zurückgeliefert wird der berechnete Eurokurs */
  303.  
  304.   ULONG i;
  305.  
  306.   /* calculate given value to euro */
  307.   const DOUBLE ineuro = input / gb_Countries[currency].ll_Exchange;
  308.  
  309.   /* then calculate from euro to all other currencies */
  310.   for(i=COUNTRY_FIRST; i<COUNTRY_MAX; i++)
  311.     gb_Total[i] = ineuro * gb_Countries[i].ll_Exchange;
  312.  
  313.   return( ineuro );
  314. }
  315.  
  316. /******************************************************************************/
  317.  
  318. struct Menu *CreateMenu(struct NewMenu *newmenu)
  319. {
  320.   /* menu => Menübeschreibung */
  321.   /* <= übergebene Menübeschreibung aber mit den neuen Texten */
  322.  
  323.   struct Menu *menu=NULL;
  324.   APTR visualinfo;
  325.  
  326.   struct NewMenu *item;
  327.   for(item = newmenu; item->nm_Type != NM_END; item++)
  328.   {
  329.     if(item->nm_UserData)
  330.     {
  331.       /*
  332.       ** falls der String nicht aus dem Catalog ermittelt werden kann,
  333.       ** wird der interne String zurückgegeben.
  334.       */
  335.       const STRPTR str = CATSTRSTR((ULONG)item->nm_UserData,item->nm_Label);
  336.  
  337.       if(item->nm_Type == NM_TITLE)
  338.       {
  339.         item->nm_Label = (STRPTR)str;   /* Title-Strings werden ohne Shortcut angegeben */
  340.       }
  341.       else
  342.       {
  343.         item->nm_Label = (STRPTR)&str[2];
  344.         if(str[0] != ' ') item->nm_CommKey = (STRPTR)str;  /* im ersten Byte steht der Shortcut */
  345.       }
  346.     }
  347.   }
  348.  
  349.   if((visualinfo = GetVisualInfoA(gb_Screen,NULL)))
  350.   {
  351.     if((menu = CreateMenusA(newmenu,NULL)))
  352.     {
  353.       if((LayoutMenus(menu,visualinfo,GTMN_NewLookMenus,TRUE,TAG_DONE)))
  354.       {
  355.       }
  356.       else { fprintf(stderr,"ERROR: can't layout menu.\n"); FreeMenus(menu); menu=NULL; }
  357.     }
  358.     else { fprintf(stderr,"ERROR: can't create menu.\n"); }
  359.  
  360.     FreeVisualInfo(visualinfo); 
  361.   }
  362.   else printf("ERROR: can't get visualinfo from screen.\n");
  363.  
  364.   return( menu );
  365. }
  366.  
  367. /******************************************************************************/
  368.  
  369. void DeleteMenu(struct Menu *menu)
  370. {
  371.   if(menu) FreeMenus(menu);
  372. }
  373.  
  374. /******************************************************************************/
  375.  
  376. LONG EasyRequester(const STRPTR text, const STRPTR button, ...)
  377. {
  378.   struct EasyStruct easyreq = { sizeof(struct EasyStruct),0,NULL,NULL,NULL };
  379.  
  380.   easyreq.es_Title        = (UBYTE *)PROGNAME;
  381.   easyreq.es_TextFormat   = (UBYTE *)text;
  382.   easyreq.es_GadgetFormat = (UBYTE *)button;
  383.  
  384.   return( EasyRequestArgs(gb_Window,&easyreq,NULL,(ULONG*)((&button)+1)) );
  385. }
  386.  
  387. /******************************************************************************/
  388.  
  389. ULONG messageloop(void)
  390. {
  391.   /* Nachrichtenschleife */
  392.  
  393.   ULONG res=RETURN_FAIL;
  394.  
  395.   ULONG windowsignal, signals;
  396.  
  397.   /* Signalbit für das Fenster besorgen */
  398.   /* get the signalbit for the windowmessages */
  399.   GetAttr(WINDOW_SigMask,gb_WindowObj,&windowsignal);
  400.  
  401.   while(res == RETURN_FAIL)
  402.   {
  403.     /* auf das Eintreffen von Nachrichten warten oder CTRL-C für Abbruch */
  404.     /* wait for a message or CTRL-C for user break */
  405.     signals = Wait(windowsignal | SIGBREAKF_CTRL_C);
  406.  
  407.     /* Fenster-Nachrichten behandeln */
  408.     /* handle the window-messages */
  409.     if(signals & windowsignal) 
  410.     {
  411.       ULONG result, code;
  412.  
  413.       /* nächste Nachricht auslesen */
  414.       /* get next message */
  415.  
  416.       /* result: oberes Word enthält die Classe, unteres Word die Event-Beschreibung */
  417.       /* result: high word is the class, in low word is the event-describe */
  418.  
  419.       while((result = RA_HandleInput(gb_WindowObj,&code)) != WMHI_LASTMSG)  
  420.       {
  421.         switch(result & WMHI_CLASSMASK)
  422.         {
  423.           case WMHI_CLOSEWINDOW:
  424.                res = RETURN_OK;
  425.                break;
  426.  
  427.           case WMHI_GADGETUP:
  428.                {
  429.                  /* Gruppen-ID ermitteln, wir haben nur eine Gruppe, daher brauchen wir sie nicht weiter */
  430.                  /* build group-id, we have only one group, so we need it */
  431.                  const UWORD groupid = RL_GROUPID(result);
  432.  
  433.                  /* Gadget-ID ermitteln */
  434.                  /* build gadget-id */
  435.                  const UWORD gadid = RL_GADGETID(result);
  436.  
  437.                  if(gadid >= COUNTRY_FIRST && gadid < COUNTRY_MAX)
  438.                  {
  439.                    /* 
  440.                    ** Es wurde eine Eingabe vorgenommen.
  441.                    ** Den Wert auslesen (in eine Flieskommazhal umwandeln),
  442.                    ** in die anderen Währungen umrechnen und anzeigen.
  443.                    */
  444.                    /*
  445.                    ** The user has given a new input.
  446.                    ** Read the value (convert to floatingpoint),
  447.                    ** calculate to the other currencies and display it.
  448.                    */
  449.                    UBYTE *val;
  450.                    if(GetAttr(STRINGA_TextVal,gb_Gadgets[gadid],(ULONG*)&val))
  451.                      gb_Total[gadid] = atof(val);
  452.  
  453.                    Calculate(gadid,gb_Total[gadid]);
  454.                    UpdateGadgets();
  455.                  }
  456.  
  457.                  /* andere Gadgets behandeln */
  458.                  /* handle the other gadgets */
  459.                  switch(gadid)
  460.                  {
  461.                    default:
  462.                      break;
  463.                  }
  464.                }
  465.                break;
  466.  
  467.           case WMHI_ICONIFY:
  468.                /* Fenster iconifizieren und Window-Pointer löschen */
  469.                /* iconify window and clear window-pointer */
  470.                RA_Iconify(gb_WindowObj); gb_Window = NULL;
  471.                break;
  472.  
  473.           case WMHI_UNICONIFY:
  474.                /* Fenster wieder vollständig anzeigen, Window-Pointer ermitteln */
  475.                /* uniconify window and get the actual window-pointer */
  476.                gb_Window = RA_OpenWindow(gb_WindowObj);
  477.                break;
  478.  
  479.           case WMHI_MENUPICK:
  480.                switch(result & WMHI_MENUMASK)
  481.                {
  482.                  case MENU_ID_Manual:
  483.                       Execute("RUN >NIL: MultiView EuroCalc.guide",NULL,NULL);
  484.                       break;
  485.  
  486.                  case MENU_ID_Print:
  487.                       /* not jet implemented */
  488.                       break;
  489.  
  490.                  case MENU_ID_Info:
  491.                       EasyRequester("%s V%s %s %s\n\n"
  492.                                     "%s\n\n"
  493.                                     "Michael Christoph\n"
  494.                                     "Irring 3\n"
  495.                                     "94113 Tiefenbach\n"
  496.                                     "<michael@meicky-soft.de>"
  497.                                     ,CATSTR(TX_Ok)
  498.                                     ,PROGNAME,VERSIONR,CATSTR(TX_From),PROGDATE,COPYRIGT 
  499.                                    );
  500.                       break;
  501.  
  502.                  case MENU_ID_Quit:
  503.                       /* "\nSure to quit program ?","Yes|No" */
  504.                       if(EasyRequester(CATSTR(TX_SureToQuit),CATSTR(TX_QuitYesNo)))
  505.                         res = RETURN_OK;
  506.                       break;
  507.  
  508.                  case MENU_ID_ClearAll:
  509.                       /* Berechnung von 0 Euros löscht alle Felder */
  510.                       /* calculation with 0 euros clear all fields */
  511.                       ClearAllGadgets();
  512.                       break;
  513.  
  514.                  case MENU_ID_Exchange:
  515.                       /* not jet implemented */
  516.                       break;
  517.                }
  518.                break;
  519.  
  520.           case WMHI_RAWKEY:
  521.                /* RawKey Nachricht, unteres Byte enthält den Tastencode, Qualifier nur in der Hook-Routine */
  522.                /* raw key event, lower byte are the keycode, qualifiers only in hook-routine */
  523.                break;
  524.  
  525.           case WMHI_VANILLAKEY:
  526.                /* ASCII-Tastencode im unteren Byte (siehe RawKey) */
  527.                /* ASCII-code in the lower byte (see RawKey) */
  528.                break;
  529.         }
  530.       }
  531.     }
  532.  
  533.     /* CTRL-C behandeln */
  534.     /* handle CTRL-C signal */
  535.     if(signals & SIGBREAKF_CTRL_C)
  536.       res = RETURN_BREAK;
  537.   }
  538.  
  539.   return( res );
  540. }
  541.  
  542. /******************************************************************************/
  543.  
  544. ULONG rungui(void)
  545. {
  546.   ULONG res = RETURN_FAIL;
  547.  
  548.   /* Zur Prüfung, ob AmigaOS 3.5 vorhanden ist, überprüfen wir die resource.library */
  549.   /* as indicator if AmigaOS 3.5 is here, we will check the resource.library */
  550.  
  551.   if((ResourceBase = OpenLibrary("resource.library",44)))
  552.   {
  553.     /* alle benötigten Libraries öffnen */
  554.     /* open all needed libraries */
  555.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",39);
  556.     GadToolsBase = OpenLibrary("gadtools.library",38);
  557.     LocaleBase = OpenLibrary("locale.library",38);
  558.     IconBase = OpenLibrary("icon.library",39);
  559.  
  560.     if(IntuitionBase && GadToolsBase && LocaleBase && IconBase)
  561.     {
  562.       /* Catalog muß nicht zwingend vorhanden sein */
  563.       /* catalog is not must and can be null */
  564.       gb_Catalog = OpenCatalogA(NULL,PROGNAME ".catalog",NULL);
  565.  
  566.       /* Default-Public-Screen locken, normalerweise die Workbench */
  567.       /* lock default-public-screen, normal the workbench */
  568.       if((gb_Screen = LockPubScreen((UBYTE *) gb_Args[ARG_pubscreen])))
  569.       {
  570.         /* zwei Nachrichtenports für die (interne) Kommunikation anlegen */
  571.         /* create two messageports for the (internal) communication */
  572.         if((gb_IDCMPort = CreateMsgPort()))
  573.         {
  574.           if((gb_AppPort = CreateMsgPort()))
  575.           {
  576.             /* Resource-Verwaltung anlegen */
  577.             /* create resource-manager */
  578.             if((gb_Resource = RL_OpenResource(RCTResource,gb_Screen,gb_Catalog)))
  579.             {
  580.               /* Localisiertes menü erzeugen */
  581.               /* create localized menu */
  582.               if((gb_Menus = CreateMenu(gb_MenuDescribe)))
  583.               {
  584.                 /* Neues Objekt erzeugen: das Hauptfenster */
  585.                 /* create new object: the mainwindow */
  586.                 if((gb_WindowObj = RL_NewObject(gb_Resource,WIN_ID_Main,
  587.                                                 WINDOW_SharedPort,   gb_IDCMPort,
  588.                                                 WINDOW_AppPort,      gb_AppPort,
  589.                                                 WINDOW_MenuStrip,    gb_Menus,
  590.                                                 WINDOW_MenuUserData, WGUD_IGNORE,
  591.                                                 /* Icon wird automatisch freigegeben */
  592.                                                 /* Icon will free qutomaticly */
  593.                                                 WINDOW_Icon,         GetDiskObject(gb_ProgName),
  594.                                                 TAG_DONE)))
  595.                 {
  596.                   /* Array der Gadget-Zeiger für die Oberflächenelemente ermitteln */
  597.                   /* get the array with the gadget-pointer to the guielementes */
  598.                   gb_Gadgets = (struct Gadget **) RL_GetObjectArray(gb_Resource,gb_WindowObj,GROUP_ID_Main);
  599.  
  600.                   /* das Fenster öffnen und den Window-Pointer ermitteln */
  601.                   /* open the window and get the window-pointer */
  602.                   if((gb_Window = RA_OpenWindow(gb_WindowObj)))
  603.                   {
  604.                     /* nicht nutzbare Menüeinträge sperren */
  605.                     /* disable unusable menuentries */
  606.                     OffMenu(gb_Window,MENU_ID_Print);
  607.                     OffMenu(gb_Window,MENU_ID_Exchange);
  608.  
  609.                     /* 1 Euro als Vorgabe ausgeben */
  610.                     /* set 1 Euro as default */
  611.                     gb_Total[GAD_ID_EUR] = 1.0;
  612.                     Calculate(GAD_ID_EUR,gb_Total[GAD_ID_EUR]);
  613.                     UpdateGadgets();
  614.  
  615.                     /* Programmschleife - Nachrichtenbehandlung */
  616.                     /* programmloop - messagehandling */
  617.                     res = messageloop();
  618.  
  619.                     /* Fenster schließen */
  620.                     /* close window */
  621.                     DoMethod(gb_WindowObj,WM_CLOSE);
  622.                   }
  623.                   else fprintf(stderr,"ERROR: can't open window.\n");
  624.                 }
  625.                 else fprintf(stderr,"ERROR: can't generate window object.\n");
  626.  
  627.                 DeleteMenu(gb_Menus);
  628.               }
  629.               /* error was printed from CreateMenu() */
  630.  
  631.               /* Resource-Verwaltung schließen, gibt alle anderen Objekte frei */
  632.               /* close resourcemanager, freed all other objects */
  633.               RL_CloseResource(gb_Resource);
  634.             }
  635.             else fprintf(stderr,"ERROR: can't open resources.\n");
  636.  
  637.             /* Nachrichtenports freigeben */
  638.             /* freed messageports */
  639.             DeleteMsgPort(gb_AppPort);
  640.           }
  641.           else fprintf(stderr,"ERROR: can't create msgport.\n");
  642.  
  643.           DeleteMsgPort(gb_IDCMPort);
  644.         }
  645.         else fprintf(stderr,"ERROR: can't create msgport.\n");
  646.  
  647.         /* Bildschirmlock freigeben */
  648.         /* freed screenlock */
  649.         UnlockPubScreen(NULL,gb_Screen);
  650.       }
  651.       else if(gb_Args[ARG_pubscreen]) fprintf(stderr,"ERROR: can't look default public screen.\n");
  652.            else                       fprintf(stderr,"ERROR: can't look public screen \"%s\".\n",gb_Args[ARG_pubscreen]);
  653.  
  654.       if(gb_Catalog) CloseCatalog(gb_Catalog);
  655.     }
  656.     else fprintf(stderr,"ERROR: can't open intuition/gadtools/locale/icon.library.\n");
  657.  
  658.     /* geöffnete Libraries schließen */
  659.     /* closed all open libraries */
  660.     if(IconBase)      CloseLibrary(IconBase);
  661.     if(LocaleBase)    CloseLibrary(LocaleBase);
  662.     if(GadToolsBase)  CloseLibrary(GadToolsBase);
  663.     if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  664.  
  665.     CloseLibrary(ResourceBase);
  666.   }
  667.   else fprintf(stderr,"Program required AmigaOS 3.5 !!\nERROR: can't open resource.library V44.\n");
  668.  
  669.   return( res );
  670. }
  671.  
  672. /******************************************************************************/
  673.  
  674. UWORD Currency2GadID(const STRPTR currency)
  675. {
  676.   /* wandelt die Währungsbezeichnung in die korespondierende GadgetID um */
  677.   /* get the gadgetid for the koresponding currency */
  678.   UWORD res=0;
  679.   ULONG i;
  680.  
  681.   for(i=1; i<COUNTRY_MAX; i++)
  682.   {
  683.     if(stricmp(currency,gb_Countries[i].ll_Currency) == 0)
  684.       { res = gb_Countries[i].ll_GadID; break; }
  685.   }
  686.  
  687.   return( res );
  688. }
  689.  
  690. /******************************************************************************/
  691.  
  692. /***** StormC/MaxonC Workbench start *****/
  693.  
  694. #ifdef __cplusplus
  695. extern "C"
  696. #endif
  697. void wbmain(struct WBStartup *WBenchMsg)
  698. {
  699.   BPTR olddir;
  700.  
  701.   /* eine Ausgabeconsole für die Fehlermeldungen öffnen */
  702.   /* open an outputconsole for errormessages */
  703.  
  704.   if(!freopen("CON:10/25/500/188/EuroCalc Output/AUTO/CLOSE", "w+", stdout))
  705.   {
  706.     /* Ein/Ausgabekanal konnte nicht neu eingerichtet werden */
  707.     /* in/outputchannel can't reopen */
  708.     Alert(AT_Recovery | AG_IOError | AO_DOSLib);  /* Alert 0006 8007 */
  709.     return;
  710.   }
  711.  
  712.  
  713.   /* ins Programmverzeichnis wechseln */
  714.   /* change directory to the program dir */
  715.   olddir = CurrentDir(WBenchMsg->sm_ArgList->wa_Lock) ;
  716.   strcpy(gb_ProgName,WBenchMsg->sm_ArgList->wa_Name);
  717.  
  718.   /* Tooltypes auswerten */
  719.   /* extract tooltypes */
  720.   if((IconBase = OpenLibrary("icon.library",37)))
  721.   {
  722.     struct DiskObject *dobj;
  723.  
  724.     if((dobj = GetDiskObject(WBenchMsg->sm_ArgList->wa_Name)))  /* Wir haben ein Icon! */
  725.     {                                                           /* We have an icon */
  726.       gb_Args[ARG_pubscreen] = (ULONG) FindToolType((STRPTR *) dobj->do_ToolTypes,"PUBSCREEN");
  727.     }
  728.  
  729.     CloseLibrary(IconBase); IconBase = NULL;
  730.   }
  731.   else Alert(AT_Recovery | AG_OpenLib | AO_IconLib);  /* 0003 8009 */
  732.  
  733.   rungui();
  734.  
  735.   /* zurück ins Aufrufverzeichnis */
  736.   /* back to the startdir */
  737.   CurrentDir(olddir);
  738. }
  739.  
  740. /***** Shell start *****/
  741.  
  742. void main(void)
  743. {
  744.   ULONG res = RETURN_FAIL;
  745.   BPTR olddir;
  746.   UBYTE progname[100];
  747.  
  748.   DOUBLE eurores = 0.0;
  749.   DOUBLE total = 0.0;
  750.   const UBYTE *currency = "";
  751.   struct RDArgs *rda = NULL;
  752.  
  753.   /* ins Programmverzeichnis wechseln und Programmnamen ermitteln */
  754.   /* change directory to the program dir and get programname */
  755.   olddir = CurrentDir(GetProgramDir());
  756.   GetProgramName(progname,100);
  757.   strcpy(gb_ProgName,FilePart(progname));  /* evtl. Pfadangabe entfernen */
  758.                                            /* skip path when available */
  759.  
  760.   if((rda=ReadArgs(gb_ArgTemplate,gb_Args,NULL)))
  761.   {
  762.     if(gb_Args[ARG_total])
  763.     {
  764.       res = RETURN_OK;
  765.  
  766.       /*
  767.       ** es wurde eine Betrag übergeben:
  768.       ** dieser wird sofort in die angegebenen Zielwährungen
  769.       ** umgerechnet und die Ergebnisse ausgegeben.
  770.       */
  771.       /*
  772.       ** user will give arguments:
  773.       ** calculate it to the zielcurrency and print it out
  774.       */
  775.       if(gb_Args[ARG_total])    total    = atof((UBYTE*)gb_Args[ARG_total]);
  776.       if(gb_Args[ARG_currency]) currency = (UBYTE*) gb_Args[ARG_currency];
  777.  
  778. //      eurores = Calculate(currency,total);
  779.  
  780.       if(gb_Args[ARG_to])
  781.       {
  782.         /* alle Währungskennzeichen; für Argument "ALL" */
  783.         /* all -Währungskennzeichen-; for argument "ALL" */
  784.         const STRPTR gb_AllCurrencies[] =
  785.         {
  786.           "EURO", "DM", "BFR", "FMK", "FF", "IRF", "LIT", "LFR", "HFL", "OES", "ESC", "PTA", NULL
  787.         };
  788.  
  789.         /* Zielwährung wurde angegeben */
  790.         /* zielcurrency will given */
  791.         UBYTE **toarg = (stricmp(((UBYTE**)gb_Args[ARG_to])[0],"ALL")==0 ?
  792.                                 (UBYTE**)gb_AllCurrencies :
  793.                                 (UBYTE**)gb_Args[ARG_to]);
  794.         for(; *toarg; toarg++)
  795.         {
  796.           UWORD currencyid;
  797.           if((currencyid = Currency2GadID(*toarg)))
  798.           {
  799.             Calculate(currencyid,total);
  800.             printf(FMT_CurrencyOutput " %s\n",*toarg);
  801.           }
  802.           else
  803.           {
  804.             fprintf(stderr,"unknown currency '%s'.\n",*toarg);
  805.             res = RETURN_ERROR;
  806.           }
  807.         }
  808.       }
  809.       else printf(FMT_CurrencyOutput " EURO\n",eurores);
  810.     }
  811.     else
  812.     {
  813.       /* ohne Parameter die Oberfläche darstellen */
  814.       /* without arguments the gui will opend */
  815.       res = rungui();
  816.     }
  817.  
  818.     FreeArgs(rda);
  819.   }
  820.   else
  821.   {
  822.     PrintFault(IoErr(),gb_ProgName);
  823.     res = RETURN_ERROR;
  824.   }
  825.  
  826.   /* zurück ins Aufrufverzeichnis */
  827.   /* back to the startdir */
  828.   CurrentDir(olddir);
  829.  
  830.   exit( res );
  831. }
  832.  
  833. /******************************************************************************/
  834.  
  835.