home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / misc / edu / WhirlDisc.lha / WhirlDisc / Source / viewer.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-15  |  5.1 KB  |  235 lines

  1. /*
  2.  
  3. File: viewer.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2000 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24. #include <exec/types.h>
  25. #include <workbench/workbench.h>
  26. #include "viewer.h"
  27.  
  28. #include "general_protos.h"
  29. #include "paedia_protos.h"
  30. #include "article_protos.h"
  31. #include "search_protos.h"
  32. #include "index_protos.h"
  33. #include <proto/exec.h>
  34. #include <proto/dos.h>
  35. #include <proto/icon.h>
  36.  
  37.  
  38. const TEXT *version_string="$VER: WhirlDisc 0.1 (9.8.2000)";
  39. const TEXT *prog_name="WhirlDisc";
  40.  
  41. const TEXT *intuition_name="intuition.library";
  42. const TEXT *dos_name="dos.library";
  43. const TEXT *graphics_name="graphics.library";
  44. const TEXT *gadtools_name="gadtools.library";
  45. const TEXT *icon_name="icon.library";
  46.  
  47.  
  48. const TEXT *datadrawer_tt_name="DATADRAWER";
  49. const TEXT *default_paedia_path="WBISS600:";
  50.  
  51.  
  52. #define EXEC_VERSION 39
  53. #define INTUITION_VERSION 39
  54. #define DOS_VERSION 39
  55. #define GRAPHICS_VERSION 39
  56. #define GADTOOLS_VERSION 39
  57. #define ICON_VERSION 39
  58.  
  59.  
  60. static BOOL OpenLibs();
  61. static VOID CloseLibs();
  62.  
  63.  
  64. ULONG main()
  65. {
  66.    Paedia paedia;
  67.    Search search;
  68.    Article article;
  69.    BOOL quit=FALSE;
  70.    struct IntuiMessage *msg;
  71.    struct MsgPort *msg_port;
  72.    struct MinList object_list;
  73.    BPTR prog_dir,old_dir;
  74.    struct DiskObject *disk_object;
  75.    STRPTR *tooltypes,paedia_path=default_paedia_path;
  76.  
  77.    if(OpenLibs())
  78.    {
  79.  
  80.       /* Initialise object list and shared message port */
  81.  
  82.       NewList(&object_list);
  83.       msg_port=CreateMsgPort();
  84.  
  85.       /* Get paedia's directory name from tooltypes */
  86.  
  87.       prog_dir=GetProgramDir();
  88.       old_dir=CurrentDir(prog_dir);
  89.       disk_object=GetDiskObject(prog_name);
  90.  
  91.       if(disk_object)
  92.       {
  93.          tooltypes=disk_object->do_ToolTypes;
  94.          paedia_path=FindToolType(tooltypes,datadrawer_tt_name);
  95.       }
  96.  
  97.       /* Initialise paedia */
  98.  
  99.       paedia=CreatePaedia("links",paedia_path);
  100.  
  101.       if((paedia!=NULL)&&(msg_port!=NULL))
  102.       {
  103.  
  104.          search=CreateSearch(msg_port,paedia,&object_list,50,50);
  105.          if(search!=NULL)
  106.          {
  107.  
  108.             AddHead((struct List *)&object_list,&search->node);
  109.  
  110.             while(quit!=TRUE)
  111.             {
  112.                WaitPort(msg_port);
  113.                while((msg=(struct IntuiMessage *)GetMsg(
  114.                   msg_port))!=NULL)
  115.                {
  116.                   if(((Article)msg->IDCMPWindow->UserData)->node.ln_Type==
  117.                      NT_ARTICLE)
  118.                   {
  119.                      article=(Article)msg->IDCMPWindow->UserData;
  120.                      HandleArticleInput(article,msg);
  121.                   }
  122.                   else
  123.                   {
  124.                      search=(Search)msg->IDCMPWindow->UserData;
  125.                      HandleSearchInput(search,msg);
  126.                   }
  127.  
  128.                }
  129.  
  130.                /* Check if list is empty */
  131.  
  132.                if(IsListEmpty((struct List *)&object_list))
  133.                   quit=TRUE;
  134.             }
  135.  
  136.          }
  137.       }
  138.  
  139.       if(paedia!=NULL)
  140.          KillPaedia(paedia);
  141.  
  142.       if(disk_object!=NULL)
  143.          FreeDiskObject(disk_object);
  144.       CurrentDir(old_dir);
  145.  
  146.       DeleteMsgPort(msg_port);
  147.    }
  148.  
  149.    CloseLibs();
  150.  
  151.    return RETURN_OK;
  152. }
  153.  
  154.  
  155.  
  156. int wbmain(struct Msg *wbmsg)
  157. {
  158.    main();
  159. }
  160.  
  161.  
  162.  
  163. /* Function: OpenLibs
  164.  * ==================
  165.  */
  166.  
  167. static BOOL OpenLibs()
  168. {
  169.    BOOL success=TRUE;
  170.  
  171.    if(!(IntuitionBase=OpenLibrary(intuition_name,INTUITION_VERSION)))
  172.    {
  173.       success=FALSE;
  174.    }
  175.  
  176.    if(success)
  177.       if(!(DOSBase=(struct DosLibrary *)OpenLibrary(dos_name,DOS_VERSION)))
  178.       {
  179.          ReportError(NULL,ERROR_REPORT_LIB,dos_name,DOS_VERSION);
  180.          success=FALSE;
  181.       }
  182.  
  183.    if(success)
  184.       if(!(GfxBase=OpenLibrary(graphics_name,GRAPHICS_VERSION)))
  185.       {
  186.          ReportError(NULL,ERROR_REPORT_LIB,graphics_name,GRAPHICS_VERSION);
  187.          success=FALSE;
  188.       }
  189.  
  190.    if(success)
  191.       if(!(GadToolsBase=OpenLibrary(gadtools_name,GADTOOLS_VERSION)))
  192.       {
  193.          ReportError(NULL,ERROR_REPORT_LIB,gadtools_name,GADTOOLS_VERSION);
  194.          success=FALSE;
  195.       }
  196.  
  197.    if(success)
  198.       if(!(IconBase=OpenLibrary(icon_name,ICON_VERSION)))
  199.       {
  200.          ReportError(NULL,ERROR_REPORT_LIB,icon_name,ICON_VERSION);
  201.          success=FALSE;
  202.       }
  203.  
  204.    return success;
  205. }
  206.  
  207.  
  208.  
  209. /* Function: CloseLibs
  210.  * ===================
  211.  */
  212.  
  213. static VOID CloseLibs()
  214. {
  215.    if(IconBase)
  216.       CloseLibrary(IconBase);
  217.  
  218.    if(GadToolsBase)
  219.       CloseLibrary(GadToolsBase);
  220.  
  221.    if(GfxBase)
  222.       CloseLibrary(GfxBase);
  223.  
  224.    if(DOSBase)
  225.       CloseLibrary((struct Library *)DOSBase);
  226.  
  227.    if(IntuitionBase)
  228.       CloseLibrary(IntuitionBase);
  229.  
  230.    return;
  231. }
  232.  
  233.  
  234.  
  235.