home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d913 / stickit.lha / StickIt / Source / Source.lha / main.c < prev    next >
C/C++ Source or Header  |  1993-08-02  |  8KB  |  338 lines

  1. /************************************************
  2.  **************    StickIt.c   ******************
  3.  ************************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/classes.h>
  10. #include <intuition/classusr.h>
  11. #include <intuition/imageclass.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/gadtools.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/gfxbase.h>
  16. #include <workbench/startup.h>
  17. #include <workbench/workbench.h>
  18. #include <dos/dos.h>
  19.  
  20. #include <clib/alib_protos.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/gadtools_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/diskfont_protos.h>
  26. #include <clib/utility_protos.h>
  27. #include <clib/icon_protos.h>
  28. #include <clib/dos_protos.h>
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33.  
  34. #include "stickit.h"
  35.  
  36. #include "consts.h"
  37. #include "structs.h"
  38. #include "prototype.h"
  39.  
  40. struct IntuitionBase  *IntuitionBase = NULL;
  41. struct Library *GfxBase = NULL;
  42. struct Library *GadToolsBase = NULL;
  43. struct Library *UtilityBase = NULL;
  44. struct Library *DiskfontBase = NULL;
  45. struct Library *IconBase = NULL;
  46.  
  47. extern struct Gadget *editGadgets[];
  48.  
  49. extern struct WBStartup *WBenchMsg;
  50.  
  51. prjptr prj = NULL;
  52.  
  53. /***   Version string   ***/
  54.  
  55. char *version = "$VER: StickIt V1.02 2nd August '93 ©1993 Andy Dean";
  56.  
  57. int main(int argc, char **argv)
  58.    {
  59.    /***   Open Libraries   ***/
  60.  
  61.    if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary
  62.                   ("intuition.library",OS_VER)))
  63.       cleanup();
  64.  
  65.    if (!(GfxBase = OpenLibrary("graphics.library",OS_VER)))
  66.       cleanup();
  67.  
  68.    if (!(GadToolsBase = OpenLibrary("gadtools.library",OS_VER)))
  69.       cleanup();
  70.  
  71.    if (!(UtilityBase = OpenLibrary("utility.library",OS_VER)))
  72.       cleanup();
  73.  
  74.    if (!(DiskfontBase = OpenLibrary("diskfont.library",OS_VER)))
  75.       cleanup();
  76.  
  77.    if (!(IconBase = OpenLibrary("icon.library",OS_VER)))
  78.       cleanup();
  79.  
  80.    /***   Main program    ***********************************************/
  81.  
  82.    init(argc);
  83.  
  84.    /***   Get lock on screen   ***/
  85.  
  86.    if (SetupScreen())
  87.       cleanup();
  88.  
  89.    /***   How do we look when we open up ?   ***/
  90.  
  91.    while (!prj->quit)
  92.       {
  93.       if ((prj->editnotes) || (prj->startedit) || (prj->no_notes == 0))
  94.          {
  95.          prj->startedit = FALSE;
  96.          openedit();
  97.          }
  98.       else
  99.          shownotes();
  100.       }
  101.  
  102.    /*********************************************************************/
  103.  
  104.    cleanup();
  105.    }
  106.  
  107. void init(int argc)
  108.    {
  109.    prj = (prjptr)malloc(sizeof(struct project));
  110.  
  111.    if (!prj)
  112.       error("Could not allocate prj",ERR_MALLOC);
  113.       
  114.    prj->no_notes = 0;
  115.    prj->no_notes_visable = 0;
  116.  
  117.    prj->notes_start = prj->notes_end = NULL;
  118.  
  119.    prj->editnotes = FALSE;
  120.    prj->showedit = TRUE;
  121.    prj->startedit = FALSE;
  122.    prj->abouttoclose = FALSE;
  123.    prj->quit = FALSE;
  124.  
  125.    prj->filechanged = prj->titlechanged = prj->notechanged = FALSE;
  126.  
  127.    prj->delay = 0;
  128.  
  129.    strncpy(prj->notefile,"StickIt.notes",STRLEN_FNAME);
  130.    prj->backcolour = 0;
  131.    prj->textcolour = 1;
  132.  
  133.    prj->notefont.ta_Name = prj->fontname;
  134.    strncpy(prj->fontname,"Helvetica.font",STRLEN_FONTNAME);
  135.  
  136.    prj->notefont.ta_YSize = 12;
  137.    prj->notefont.ta_Style = NULL;
  138.    prj->notefont.ta_Flags = NULL;
  139.  
  140.    prj->msgport = NULL;
  141.    prj->notefontptr = NULL;
  142.  
  143.    prj->currnode = NULL;
  144.    prj->copybuffernode = NULL;
  145.  
  146.    prj->noteheight = 70;
  147.    prj->notewidth = 150;
  148.  
  149.    prj->nextx = 40;
  150.    prj->nexty = 20;
  151.  
  152.    if (!argc)
  153.       readtooltypes();
  154.  
  155.    /***   Startup delay to stop disk thrashing   ***/
  156.  
  157.    Delay(prj->delay * 50);
  158.  
  159.    initlists();
  160.    readnotefile();
  161.  
  162.    /***   If no notes, don't show edit window if user doesn't want it   ***/
  163.  
  164.    if ((prj->no_notes == 0) && (!prj->startedit))
  165.       cleanup();
  166.  
  167.    /***   Open font   ***/
  168.  
  169.    prj->notefontptr = OpenDiskFont(&prj->notefont);
  170.  
  171.    if (!prj->notefontptr)
  172.       prj->notefontptr = ((struct GfxBase *)GfxBase)->DefaultFont;
  173.               
  174.    }
  175.  
  176. void cleanup()
  177.    {
  178.    /***   Remove any notes that may be on the screen   ***/
  179.  
  180.    removenotes();
  181.  
  182.    /***   Call GadToolsBox routines to shut everything down   ***/
  183.  
  184.    CloseaboutWindow();
  185.    CloseeditWindow();
  186.    CloseDownScreen();
  187.  
  188.    /***   Close font   ***/
  189.  
  190.    if ((prj->notefontptr) && 
  191.                (prj->notefontptr != ((struct GfxBase *)GfxBase)->DefaultFont))
  192.       CloseFont(prj->notefontptr);
  193.  
  194.    prj->notefontptr = NULL;
  195.  
  196.    /***   Remove linked list   ***/
  197.  
  198.    if (prj->notes_start)
  199.       llfree(prj->notes_start);
  200.  
  201.    /**   Remove copy buffer   ***/
  202.  
  203.    if (prj->copybuffernode)
  204.       {
  205.       if (prj->copybuffernode->data)
  206.          free((void *)prj->copybuffernode->data);
  207.  
  208.       free((void *)prj->copybuffernode);
  209.       }
  210.  
  211.    /***   Remove message port   ***/
  212.  
  213.    if (prj->msgport)
  214.       DeleteMsgPort(prj->msgport);
  215.  
  216.    /***   Finally, remove prj   ***/
  217.  
  218.    if(prj)
  219.       free((void *)prj);
  220.  
  221.    /***   Close libraries   ***/
  222.  
  223.    if (IconBase)
  224.       CloseLibrary(IconBase);
  225.  
  226.    if (DiskfontBase)
  227.       CloseLibrary(DiskfontBase);
  228.  
  229.    if (UtilityBase)
  230.       CloseLibrary(UtilityBase);
  231.  
  232.    if (GadToolsBase)
  233.       CloseLibrary(GadToolsBase);
  234.  
  235.    if (GfxBase)
  236.       CloseLibrary(GfxBase);
  237.  
  238.    if (IntuitionBase)
  239.       CloseLibrary((struct Library *)IntuitionBase);
  240.  
  241.    exit(20);
  242.    }
  243.  
  244. void readtooltypes()
  245.    {
  246.    struct DiskObject *diskobj;
  247.  
  248.    char *toolstring;
  249.  
  250.    LONG value;
  251.  
  252.    if (WBenchMsg)
  253.       {
  254.       diskobj = GetDiskObject(WBenchMsg->sm_ArgList[0].wa_Name);
  255.  
  256.       if (diskobj)
  257.          {
  258.          /***   Our notefile   ***/
  259.  
  260.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEFILE");
  261.  
  262.          if (toolstring)
  263.             strncpy(prj->notefile,toolstring,STRLEN_FNAME);
  264.  
  265.          /***   Font   ***/
  266.  
  267.          toolstring = FindToolType(diskobj->do_ToolTypes,"FONTNAME");
  268.  
  269.          if (toolstring)
  270.             strncpy(prj->fontname,toolstring,STRLEN_FONTNAME);
  271.  
  272.          toolstring = FindToolType(diskobj->do_ToolTypes,"FONTSIZE");
  273.  
  274.          if (toolstring)
  275.             {
  276.             StrToLong(toolstring,&value);
  277.             prj->notefont.ta_YSize = (UWORD)value;
  278.             }
  279.  
  280.          /***   Start with edit window if no notes in file ?   ***/
  281.  
  282.          toolstring = FindToolType(diskobj->do_ToolTypes,"STARTEDIT");
  283.  
  284.          if (toolstring)
  285.             prj->startedit = (Stricmp(toolstring,"YES")?FALSE:TRUE);
  286.  
  287.          /***   Colours   ***/
  288.  
  289.          toolstring = FindToolType(diskobj->do_ToolTypes,"BACKCOLOUR");
  290.  
  291.          if (toolstring)
  292.             {
  293.             StrToLong(toolstring,&value);
  294.             prj->backcolour = (int)value;
  295.             }
  296.  
  297.          toolstring = FindToolType(diskobj->do_ToolTypes,"TEXTCOLOUR");
  298.  
  299.          if (toolstring)
  300.             {
  301.             StrToLong(toolstring,&value);
  302.             prj->textcolour = (int)value;
  303.             }
  304.  
  305.          /***   Opening delay to stop disk thrashing   ***/
  306.  
  307.          toolstring = FindToolType(diskobj->do_ToolTypes,"DELAY");
  308.  
  309.          if (toolstring)
  310.             {
  311.             StrToLong(toolstring,&value);
  312.             prj->delay = (ULONG)value;
  313.             }
  314.  
  315.          /***   Note sizes   ***/
  316.  
  317.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEHEIGHT");
  318.  
  319.          if (toolstring)
  320.             {
  321.             StrToLong(toolstring,&value);
  322.             prj->noteheight = (UWORD)value;
  323.             }
  324.  
  325.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEWIDTH");
  326.  
  327.          if (toolstring)
  328.             {
  329.             StrToLong(toolstring,&value);
  330.             prj->notewidth = (UWORD)value;
  331.             }
  332.  
  333.  
  334.          FreeDiskObject(diskobj);
  335.          }
  336.       }
  337.    }
  338.