home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / barfly / utilities / makebarflyfd.lha / MakeBarflyFD.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  8KB  |  193 lines

  1.  
  2. /************************************************************************/
  3. /*                                                                      */
  4. /* MakeBarflyFD.c       ---     creates the file ram:BARFLY.FD          */
  5. /*                                                                      */
  6. /* V1.01 - KS 2.04 required                                             */
  7. /*                                                                      */
  8. /*----------------------------------------------------------------------*/
  9. /*                                                                      */
  10. /* 07/24/91     "Small C-Hack" (V1.00) by Ralph Schmidt                 */
  11. /*                                                                      */
  12. /* 11/28/91     Rewrite (call it V1.01) by Michael Böhnisch (billy)     */
  13. /*              Executable shrinks to less than 1/2 of original size    */
  14. /* 3/2/94       Update some paths(V1.02)                                */
  15. /*                                                                      */
  16. /************************************************************************/
  17.  
  18. #include <exec/exec.h>
  19.  
  20. #include <dos/dos.h>
  21. #include <dos/dostags.h>
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25.  
  26. #include <stdlib.h>     /* ANSI includes. DO NOT INCLUDE STDIO.H !      */
  27. #include <stdarg.h>
  28. #include <stddef.h>
  29. #include <string.h>
  30. #include <ctype.h>
  31.  
  32. const UBYTE Version[] = "$VER: MakeBarflyFD 1.02 ("__DATE__")";
  33.  
  34. #define BUFFERSIZE      256
  35.  
  36. /*extern struct Library *DOSBase;*/
  37.  
  38. /*----------------------------------------------------------------------*/
  39. /* I/O filehandles & filenames                                          */
  40. /*----------------------------------------------------------------------*/
  41.  
  42. BPTR    Source, Dest, stdout;
  43.  
  44. UBYTE   *SourceName = "T:BARFLY.FD_bak",
  45.         *DestName   = "ram:BARFLY.FD",
  46.         *stdoutName = "CON:0/0/640/200/MakeBarFlyFD/AUTO/NOCLOSE";
  47.  
  48. /*----------------------------------------------------------------------*/
  49. /* Close anything opened at runtime                                     */
  50. /*----------------------------------------------------------------------*/
  51.  
  52. void CloseAll(void)
  53. {
  54.         if ( Source )   Close(Source);
  55.         if ( Dest   )   Close(Dest  );
  56.  
  57.         DeleteFile(SourceName);
  58.  
  59.         if ( stdout )   {
  60.                 Delay(500);
  61.                 Close(stdout);
  62.         }
  63. }
  64.  
  65. /*----------------------------------------------------------------------*/
  66. /* fake main program (lc will replace this by tinymain)                 */
  67. /*----------------------------------------------------------------------*/
  68.  
  69. void main(int argc, char **argv)
  70. {
  71.         UBYTE   Buffer[BUFFERSIZE];
  72.         int     i;
  73.  
  74.         /*--------------------------------------------------------------*/
  75.         /* assign I/O file handles                                      */
  76.         /*--------------------------------------------------------------*/
  77.  
  78.         stdout  = Open(stdoutName, MODE_NEWFILE);
  79.         if ( ! stdout  ) {
  80.                 exit(20);
  81.         }
  82.  
  83.         /*--------------------------------------------------------------*/
  84.         /* introductory messages                                        */
  85.         /*--------------------------------------------------------------*/
  86.  
  87.         FPuts(stdout,
  88.                 "\033[0;0H\033[J"       /* Clear window                 */
  89.                 "This program creates the file 'ram:Barfly.FD'.\n\n"
  90.  
  91.                 "Please check the following files:\n"
  92.                 "exec_lib.fd\t\t1. line: \"* exec.library\"\n"
  93.                 "misc_lib.fd\t\t1. line: \"* misc.resource\"\n"
  94.                 "expansion_lib.fd\t1. line: \"* expansion.library\"\n"
  95.                 "Better check all library definition files and add it\n"
  96.                 "where necessary!\n\n"
  97.  
  98.                 "Joining #?.FD files...\n\n"
  99.         );
  100.                 
  101.         /*--------------------------------------------------------------*/
  102.         /* Join fd files to temporary. SystemTagList() is the preferred */
  103.         /* method for calling external programs since the actual progam */
  104.         /* return code is returned, -1 for not executable.              */
  105.         /* Additonally SystemTagList()  does  not  read  commands  from */
  106.         /* Input() filehandle.                                          */
  107.         /*--------------------------------------------------------------*/
  108.  
  109.         if ( SystemTagList("Join >NIL: FD:#?.fd AS T:BARFLY.FD_bak", NULL) ) {
  110.                 FPuts(stdout,
  111.                         "Join failed.\n"
  112.                         "Make sure that \"FD:\" is assigned to the directory"
  113.                         "containing\n"
  114.                         "the #?.fd files.\n"
  115.                 );
  116.                 CloseAll();
  117.                 exit(10);
  118.         }
  119.  
  120.         /*--------------------------------------------------------------*/
  121.         /* Open temporary file as input                                 */
  122.         /*--------------------------------------------------------------*/
  123.  
  124.         if ( ! ( Source = Open(SourceName, MODE_OLDFILE) ) ) {
  125.                 FPuts(stdout, "Can't open T:BARFLY.FD_bak\n");
  126.                 CloseAll();
  127.                 exit(10);
  128.         }
  129.  
  130.         /*--------------------------------------------------------------*/
  131.         /* Create new library description file for Barfly               */
  132.         /*--------------------------------------------------------------*/
  133.  
  134.         if ( ! ( Dest = Open(DestName, MODE_NEWFILE) ) ) {
  135.                 FPuts(stdout, "Can't create new file ram:BARFLY.FD\n");
  136.                 CloseAll();
  137.                 exit(10);
  138.         }
  139.  
  140.         FPuts(stdout, "Creating ram:BARFLY.FD...\n\n");
  141.  
  142.         /*--------------------------------------------------------------*/
  143.         /* Main step: filter comments and argument strings              */
  144.         /*--------------------------------------------------------------*/
  145.  
  146.         while ( FGets(Source, Buffer, BUFFERSIZE) ) {
  147.                 switch ( Buffer[0] ) {
  148.  
  149.                     /*--------------------------------------------------*/
  150.                     /* filter comments (except lib/resource/... names)  */
  151.                     /*--------------------------------------------------*/
  152.  
  153.                     case '*':
  154.                         if ( ( Buffer[1] == ' ' ) && (Buffer[2] == '\"') ) {
  155.                                 FPuts(Dest, Buffer);
  156.                         }
  157.                         break;
  158.                         
  159.                     /*--------------------------------------------------*/
  160.                     /* filter fd commands (except ##bias)               */
  161.                     /*--------------------------------------------------*/
  162.  
  163.                     case '#':
  164.                         if ( (        Buffer[1]  == '#') &&
  165.                              (tolower(Buffer[2]) == 'b') &&
  166.                              (tolower(Buffer[3]) == 'i')    ) {
  167.                                 FPuts(Dest, Buffer);
  168.                         }
  169.                         break;
  170.  
  171.                     /*--------------------------------------------------*/
  172.                     /* filter argument strings                          */
  173.                     /*--------------------------------------------------*/
  174.  
  175.                     default:
  176.                         if ( isalpha(Buffer[0]) ) {
  177.                                 for ( i = 0; Buffer[i] != '('; i++ ) { ; }
  178.                                 Buffer[i]   = '\n';
  179.                                 Buffer[i+1] = '\0';
  180.                                 FPuts(Dest, Buffer);
  181.                         }
  182.                         break;
  183.                 }
  184.         }
  185.  
  186.         /*--------------------------------------------------------------*/
  187.         /* Cleanup: Close anything opened at runtime                    */
  188.         /*--------------------------------------------------------------*/
  189.  
  190.         FPuts(stdout, "All done!!!\n");
  191.         CloseAll();
  192. }
  193.