home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / pufferfish / source / generate.c < prev    next >
C/C++ Source or Header  |  1994-03-21  |  5KB  |  206 lines

  1. /*
  2.  * generate.c
  3.  *
  4.  * Do the actual floppy generation
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <utility/tagitem.h>
  10. #include <dos/dostags.h>
  11.  
  12. #include <clib/dos_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #include "PufferFish.h"
  20.  
  21. /*
  22.  * generate_disk()
  23.  *
  24.  * Actually does the disk creation (format, uncompress, verify)
  25.  *
  26.  * Several of these will be started as tasks
  27.  *
  28.  */
  29. __saveds void generate_disk( void )
  30. {
  31.     struct GFMessage msg, *reply;
  32.     struct MsgPort *port;
  33.     BPTR console_window;
  34.     ULONG error;
  35.     BOOL done = FALSE;
  36.     char echo_command[255], system_command[255], diskname[255], diskpath[255];
  37.     ULONG disknum;
  38.     
  39.     if( port = CreateMsgPort() )
  40.     {
  41.         msg.gf_Msg.mn_Length = sizeof( struct GFMessage );
  42.         msg.gf_Msg.mn_ReplyPort = port;
  43.         msg.gf_DriveNum = -1;
  44.         
  45.         PutMsg( myPort, (struct Message *)&msg );
  46.         
  47.         WaitPort( port );
  48.         if( reply = (struct GFMessage *)GetMsg( port ) )
  49.         {
  50.             // Find out which drive we're going to use
  51.             msg.gf_DriveNum = reply->gf_DriveNum;
  52.         }
  53.         
  54.         if( msg.gf_DriveNum < 4 )
  55.         {
  56.             sprintf( echo_command, "CON:0/%ld/640/50/PufferFish Output DF%ld:/CLOSE/WAIT/SCREEN %s",
  57.                 100 + (msg.gf_DriveNum * 50),
  58.                 msg.gf_DriveNum,
  59.                 screen->Title );
  60.         }
  61.         else
  62.         {
  63.             sprintf( echo_command, "CON:0/%ld/640/50/PufferFish Output %s/CLOSE/WAIT/SCREEN %s",
  64.                 100 + (msg.gf_DriveNum * 50),
  65.                 additional_device,
  66.                 screen->Title );
  67.         }
  68.         if( console_window = Open( echo_command, MODE_NEWFILE ) )
  69.         {
  70.             PutMsg( port, (struct Message *)&msg );
  71.             while( !done )
  72.             {
  73.                 WaitPort( port );
  74.                 if( reply = (struct GFMessage *)GetMsg( port ) )
  75.                 {
  76.                     disknum = reply->gf_DiskNumber;
  77.                     if( disknum > lastdisk )
  78.                     {
  79.                         // Received 'quit' message
  80.                         done = TRUE;
  81.                     }
  82.                     else
  83.                     {
  84.                         if( disknum > 0 )
  85.                         {
  86.                             strcpy( diskname, reply->gf_DiskName );
  87.                             strcpy( diskpath, reply->gf_DiskPath );
  88.                             
  89.                             sprintf( echo_command,
  90.                                 "\033[1;2mCreating AmigaLibDisk %03d\033[0m\n",
  91.                                 disknum );
  92.                             Write( console_window, echo_command, strlen( echo_command ) );
  93.                             if( msg.gf_DriveNum < 4 )
  94.                             {
  95.                                 sprintf( system_command,
  96.                                     "%s DRIVE DF%ld: NAME %s\n",
  97.                                     formatpath,
  98.                                     msg.gf_DriveNum,
  99.                                     diskname );
  100.                             }
  101.                             else
  102.                             {
  103.                                 sprintf( system_command,
  104.                                     "%s DRIVE %s NAME %s\n",
  105.                                     formatpath,
  106.                                     additional_device,
  107.                                     diskname );
  108.                             }
  109.                             if( verbose )
  110.                             {
  111.                                 Write( console_window, system_command, strlen( system_command ) );
  112.                             }
  113.                             if( !( error = SystemTags( system_command,
  114.                                 SYS_Asynch, FALSE,
  115.                                 SYS_Input, console_window,
  116.                                 SYS_Output, NULL,
  117.                                 TAG_END ) ) )
  118.                             {
  119.                                 int i = 0;
  120.                                 
  121.                                 // Add : to disk name
  122.                                 for( i = 0; i < strlen( diskname ) - 1; i += 1 );
  123.                                 if( diskname[0] == '\"')
  124.                                 {
  125.                                     diskname[i] = ':';
  126.                                     diskname[i+1] = '\"';
  127.                                 }
  128.                                 else
  129.                                 {
  130.                                     diskname[i+1] = ':';
  131.                                 }
  132.                                 diskname[i+2] = '\0';
  133.                                 
  134.                                 sprintf( system_command,
  135.                                     "%s %s/#?.lha %s\n",
  136.                                     lhapath,
  137.                                     diskpath,
  138.                                     diskname );
  139.                                 if( verbose )
  140.                                 {
  141.                                     Write( console_window, system_command, strlen( system_command ) );
  142.                                 }
  143.                                 if( !( error = SystemTags( system_command,
  144.                                     SYS_Asynch, FALSE,
  145.                                     SYS_Input, console_window,
  146.                                     SYS_Output, NULL,
  147.                                     TAG_END ) ) )
  148.                                 {
  149.                                     sprintf( system_command,
  150.                                         "CD %s\n%s %s/Disk%03d.crc\n",
  151.                                         diskname,
  152.                                         brikpath,
  153.                                         diskpath,
  154.                                         disknum );
  155.                                     if( verbose )
  156.                                     {
  157.                                         Write( console_window, system_command, strlen( system_command ) );
  158.                                     }
  159.                                     if( !( error = SystemTags( system_command,
  160.                                         SYS_Asynch, FALSE,
  161.                                         SYS_Input, console_window,
  162.                                         SYS_Output, NULL,
  163.                                         NP_StackSize, 20000,
  164.                                         TAG_END ) ) )
  165.                                     {
  166.                                         sprintf( echo_command,
  167.                                             "\033[1;2mAmigaLibDisk %03d successfully generated!\033[0m\n",
  168.                                             disknum );
  169.                                     }
  170.                                     else
  171.                                     {
  172.                                         DisplayBeep( screen );
  173.                                         sprintf( echo_command,
  174.                                             "\033[1mBrik failed to verify disk\033[0m\n" );
  175.                                     }
  176.                                 }
  177.                                 else
  178.                                 {
  179.                                     DisplayBeep( screen );
  180.                                     sprintf( echo_command,
  181.                                         "\033[1mLhA failed to extract disk contents\033[0m\n" );
  182.                                 }
  183.                             }
  184.                             else
  185.                             {
  186.                                 DisplayBeep( screen );
  187.                                 sprintf( echo_command,
  188.                                     "\033[1mFormat failed to initialize disk\033[0m\n" );
  189.                             }
  190.                             Write( console_window, echo_command, strlen( echo_command ) );
  191.                         }
  192.                         PutMsg( myPort, (struct Message *)&msg );
  193.                     }
  194.                 }
  195.             }
  196.             // Close console_window handle
  197.             Close( console_window );
  198.         }
  199.         DeleteMsgPort( port );
  200.     }
  201.     else
  202.     {
  203.         // Couldn't create message port: should report error (else calling task will wait forever)
  204.     }
  205. }
  206.