home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / tools / pufferfish / source / pufferfish.c < prev    next >
C/C++ Source or Header  |  1994-03-30  |  12KB  |  488 lines

  1. /*
  2.  * PufferFish.c
  3.  *
  4.  * Generate Fish floppies from CD-ROM distribution
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <utility/tagitem.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/icclass.h>
  14. #include <libraries/amigaguide.h>
  15. #include <libraries/dos.h>
  16. #include <dos/dosextens.h>
  17. #include <dos/dostags.h>
  18. #include <resources/disk.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/amigaguide_protos.h>
  22. #include <clib/alib_protos.h>
  23. #include <clib/dos_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/icon_protos.h>
  26. #include <clib/intuition_protos.h>
  27.  
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31.  
  32. #include "WB2CLI/WB2CLI.h"
  33. #include "buttonclass/headers.h"
  34. #include "buttonclass/buttonclass.h"
  35. #include "PufferFish.h"
  36.  
  37. long __stack = 20000;
  38.  
  39. extern struct Library *SysBase;
  40. extern struct Library *IntuitionBase;
  41. extern struct Library *UtilityBase;
  42. extern struct Library *GfxBase;
  43. extern struct DosLibrary *DOSBase;
  44. struct Library *DiskBase = NULL;
  45. struct Library *AmigaGuideBase = NULL;
  46.  
  47. static const char versionstring[] = "\0$VER: PufferFish 1.0 (29.03.94)";
  48.  
  49. struct Screen *screen;
  50. struct DrawInfo *drawinfo;
  51. struct Window *win;
  52.  
  53. BPTR dirlock;
  54.  
  55. struct InfoData MyInfoData;
  56.  
  57. int start_disknum, end_disknum;
  58.  
  59. int dig[8] =
  60. {
  61.     0, 0, 0, 1,
  62.     0, 0, 0, 1
  63. };
  64.  
  65. char *dig_text[8] =
  66. {
  67.     "0", "0", "0", "1",
  68.     "0", "0", "0", "1",
  69. };
  70.  
  71. unsigned char avail_disks, drives_selected;
  72. struct MsgPort *myPort;
  73. struct Process *myProc[5];
  74.  
  75. int firstdisk, lastdisk;
  76. char *contentspath, *formatpath, *lhapath, *brikpath, *additional_device;
  77. BOOL verbose;
  78.  
  79. AMIGAGUIDECONTEXT agcontext = NULL;
  80. ULONG winbit;
  81.  
  82. Class *buttonclass;
  83.  
  84. void MakeBoxedStringClass(void);
  85. void FreeBoxedStringClass(void);
  86.  
  87. void handle_input(void);
  88.  
  89. // Change SAS/C's Ctrl-C checking (eventually abort accidental generation of wrong floppies?)
  90. void __regargs _CXBRK(void)
  91. {
  92. }
  93.  
  94. /*
  95.  * main()
  96.  *
  97.  * Handles library, window, image, gadget, help setup
  98.  * Handles input (should be separate)
  99.  *
  100.  */
  101. int main( int argc, char **argv )
  102. {
  103.     ULONG arrowwidth, arrowheight, checkwidth, winwidth, winheight;
  104.     struct NewAmigaGuide nag = {NULL};
  105.     STRPTR context[] =
  106.     {
  107.         "MAIN",
  108.         "DIGITS",
  109.         "DRIVES",
  110.         "START",
  111.         NULL
  112.     };
  113.     UBYTE **ttypes;
  114.     int i;
  115.     
  116.     WB2CLI((struct WBStartup *)argv,20000,DOSBase);
  117.     AmigaGuideBase = OpenLibrary( "amigaguide.library", 34 );
  118.     ttypes = ArgArrayInit( argc, argv );
  119.     firstdisk = ArgInt( ttypes, "FIRSTDISK", MIN_DISK_NUM );
  120.     lastdisk = ArgInt( ttypes, "LASTDISK", MAX_DISK_NUM );
  121.     contentspath = ArgString( ttypes, "CONTENTSPATH", CONTENTS_PATH );
  122.     formatpath = ArgString( ttypes, "FORMATPATH", FORMAT_PATH );
  123.     lhapath = ArgString( ttypes, "LHAPATH", LHA_PATH );
  124.     brikpath = ArgString( ttypes, "BRIKPATH", BRIK_PATH );
  125.     additional_device = ArgString( ttypes, "DEVICE", "" );
  126.     verbose = FindToolType( ttypes, "VERBOSE" ) ? TRUE : FALSE;
  127.     
  128.     if( firstdisk < MIN_DISK_NUM )
  129.     {
  130.         firstdisk = MIN_DISK_NUM;
  131.     }
  132.     if( lastdisk < firstdisk )
  133.     {
  134.         lastdisk = MAX_DISK_NUM;
  135.     }
  136.     start_disknum = end_disknum = firstdisk;
  137.     dig[0] = start_disknum / 1000;
  138.     dig[1] = (start_disknum - dig[0] * 1000) / 100;
  139.     dig[2] = (start_disknum - dig[0] * 1000 - dig[1] * 100) / 10;
  140.     dig[3] = (start_disknum - dig[0] * 1000 - dig[1] * 100 - dig[2] * 10);
  141.     dig[4] = end_disknum / 1000;
  142.     dig[5] = (end_disknum - dig[4] * 1000) / 100;
  143.     dig[6] = (end_disknum - dig[4] * 1000 - dig[5] * 100) / 10;
  144.     dig[7] = (end_disknum - dig[4] * 1000 - dig[5] * 100 - dig[6] * 10);
  145.     for( i = 0; i < 8; i += 1 )
  146.     {
  147.         dig_text[i][0] = '0' + dig[i];
  148.     }
  149.     
  150.     if( DiskBase = (struct Library *)OpenResource(DISKNAME) )
  151.     {
  152.         screen = LockPubScreen( NULL );
  153.         if( screen )
  154.         {
  155.             drawinfo = GetScreenDrawInfo( screen );
  156.             if( drawinfo )
  157.             {
  158.                 MakeBoxedStringClass();
  159.                 if( buttonclass = initButtonGadgetClass( IntuitionBase, UtilityBase, GfxBase ) )
  160.                 {
  161.                     if( make_systemimages() )
  162.                     {
  163.                         GetAttr( IA_Width, upimage, &arrowwidth );
  164.                         GetAttr( IA_Height, upimage, &arrowheight );
  165.                         GetAttr( IA_Width, checkimage, &checkwidth );
  166.                         
  167.                         // width of digits frame
  168.                         winwidth = ( arrowwidth * 11 / 2 + drawinfo->dri_Font->tf_XSize * 5 + 8);
  169.                         // width of drive frame
  170.                         drivenames_text[0].ITextFont = screen->Font;
  171.                         winwidth += drawinfo->dri_Font->tf_XSize
  172.                             + IntuiTextLength( &drivenames_text[0] )
  173.                             + checkwidth + 4
  174.                             + 2 * drawinfo->dri_Font->tf_XSize;
  175.                         
  176.                         // height of button frames
  177.                         winheight = 2 * ((arrowheight + 2)
  178.                             + (drawinfo->dri_Font->tf_YSize + 2 + 4)
  179.                             + (arrowheight + 2)
  180.                             + drawinfo->dri_Font->tf_YSize
  181.                                 + GF_TOPBORDER * 3 / 2) + drawinfo->dri_Font->tf_YSize;
  182.                         
  183.                         if( win = OpenWindowTags( NULL,
  184.                             WA_PubScreen,    screen,
  185.                             WA_Flags,    WFLG_DEPTHGADGET | WFLG_DRAGBAR | WFLG_CLOSEGADGET | WFLG_NEWLOOKMENUS,
  186.                                 WA_IDCMP,    GF_IDCMPFLAGS,
  187.                             WA_Width,    screen->WBorLeft + screen->WBorRight    // window borders
  188.                                 + GF_LEFTBORDER + GF_RIGHTBORDER                // margins from borders
  189.                                 + winwidth,
  190.                             WA_Height,    screen->WBorTop + screen->WBorBottom
  191.                                 + drawinfo->dri_Font->tf_YSize + 1
  192.                                 + GF_TOPBORDER + GF_BOTTOMBORDER
  193.                                 + winheight,
  194.                             WA_Activate,TRUE,
  195.                             WA_Title,    "PufferFish",
  196.                             TAG_END ))
  197.                         {
  198.                             if( GfxBase->lib_Version >= 39 )
  199.                             {
  200.                                 HelpControl( win, HC_GADGETHELP );
  201.                             }
  202.                             winbit = 1L << ((struct MsgPort *)win->UserPort)->mp_SigBit;
  203.                             avail_disks = which_disks();
  204.                             if( make_images() && make_digits() && make_drives() && make_gadgets() )
  205.                             {
  206.                                 draw_images();
  207.                                 
  208.                                 AddGList( win, uparrows[0], -1, -1, NULL );
  209.                                 RefreshGList( uparrows[0], win, NULL, -1 );
  210.                                 
  211.                                 if( AmigaGuideBase )
  212.                                 {
  213.                                     nag.nag_BaseName = "PUFFERFISH";
  214.                                     nag.nag_Name = "PufferFish.guide";
  215.                                     nag.nag_ClientPort = "PUFFERFISH_HELP";
  216.                                     nag.nag_Context = context;
  217.                                     nag.nag_Screen = screen;
  218.                                     if( agcontext = OpenAmigaGuideAsync( &nag, NULL ) )
  219.                                     {
  220.                                         SetAmigaGuideContext( agcontext, 0L, NULL );
  221.                                     }
  222.                                 }
  223.                                 handle_input();
  224.                                 if( AmigaGuideBase && agcontext )
  225.                                 {
  226.                                     CloseAmigaGuide( agcontext );
  227.                                 }
  228.                                 RemoveGList( win, uparrows[0], -1 );
  229.                                 free_gadgets();
  230.                                 free_drives();
  231.                                 free_digits();
  232.                                 free_images();
  233.                             }
  234.                             CloseWindow( win );
  235.                         }
  236.                         free_systemimages();
  237.                     }
  238.                     freeButtonGadgetClass( buttonclass );
  239.                 }
  240.                 FreeBoxedStringClass();
  241.                 FreeScreenDrawInfo( screen, drawinfo );
  242.             }
  243.             UnlockPubScreen( NULL, screen );
  244.         }
  245.         // NOTE: Don't close DiskBase...
  246.     }
  247.     ArgArrayDone();
  248.     if( AmigaGuideBase )
  249.     {
  250.         CloseLibrary( AmigaGuideBase );
  251.     }
  252. }
  253.  
  254. void handle_input(void)
  255. {
  256.     BOOL done = FALSE;
  257.     ULONG signal;
  258.     ULONG id, class, code;
  259.     void *ghelpid;
  260.     struct IntuiMessage *imsg;
  261.     struct EasyStruct easyStruct =
  262.     {
  263.         sizeof( struct EasyStruct ),
  264.         0,
  265.         NULL,
  266.         NULL,
  267.         NULL
  268.     };
  269.     struct Requester req;
  270.     LONG region, help_region;
  271.     
  272.     while( !done )
  273.     {
  274.         signal = Wait( winbit );
  275.         if( signal & winbit )
  276.         {
  277.             while( imsg = (struct IntuiMessage *)
  278.                 GetMsg( (struct MsgPort *)win->UserPort ) )
  279.             {
  280.                 class = imsg->Class;
  281.                 code = imsg->Code;
  282.                 if( class == IDCMP_GADGETUP )
  283.                 {
  284.                     id = ((struct Gadget *)imsg->IAddress)->GadgetID;
  285.                 }
  286.                 ghelpid = imsg->IAddress;
  287.                 ReplyMsg( (struct Message *)imsg );
  288.                 switch( class )
  289.                 {
  290.                     case IDCMP_CLOSEWINDOW:
  291.                         done = TRUE;
  292.                         break;
  293.                     case IDCMP_GADGETUP:
  294.                         if( id < GAD_START )
  295.                         {
  296.                             if( code == 0x5F )
  297.                             {
  298.                                 // Help for string/integer gadget requested
  299.                                 if( agcontext )
  300.                                 {
  301.                                     SetAmigaGuideContext( agcontext, GF_HELP_DIGITS, NULL );
  302.                                     SendAmigaGuideContext( agcontext, NULL );
  303.                                 }
  304.                                 else
  305.                                 {
  306.                                     /* amigaguide.library wasn't found, so help not available */
  307.                                     easyStruct.es_TextFormat = "Help not available\nYou need amigaguide.library V34";
  308.                                     easyStruct.es_GadgetFormat = "OK";
  309.                                     beginWait( win, &req );
  310.                                     EasyRequest( win, &easyStruct, NULL, NULL );
  311.                                     endWait( win, &req );
  312.                                 }
  313.                             }
  314.                             else
  315.                             {
  316.                                 update_gadge