home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / os20 / util / recall / source / converter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  5.6 KB  |  240 lines

  1. /*
  2.  *    File:                    Converter.c
  3.  *    Description:    Program to convert a Recall project to different formats.
  4.  *    Version:            1.0
  5.  *    Author:                Ketil Hunn
  6.  *    Mail:                    hunn@dhmolde.no
  7.  *                                ketil@lyr.dhmolde.no
  8.  *
  9.  *    Copyright © 1993 Ketil Hunn.  Please read the document for further
  10.  *    information and copyrights.
  11.  *
  12.  *    In order to list the source-files included in this package properly,
  13.  *    the TAB size should be set at 2.
  14.  *
  15.  */
  16.  
  17. #include <MUI.h>
  18. #include "Escapes.h"
  19. #include "Version.h"
  20.  
  21. #include "GUI_Converter.h"
  22. #include <exec/memory.h>
  23. #include "GlobalConfig.h"
  24. #include "MyRequest().h"
  25.  
  26. short reqType=MUI_TYPE;
  27.  
  28. #include "Config14.h"
  29. #include "Config20.h"
  30. #include "ASCII.h"
  31. #include "GetFile().h"
  32.  
  33. /* PROTOTYPES */
  34. BOOL Exists(char name[256]);
  35. void CheckReady(char source[256], char destination[256]);
  36. BOOL Convert(long intype, char *source, long outtype, char *destination);
  37.  
  38. struct FileRequester *aslreq=NULL;
  39.  
  40. #define TEMPLATE "INTYPE/A,FILE1/A,OUTTYPE/A,FILE2/A"
  41. BOOL noargs=TRUE;
  42.  
  43. main()
  44. {
  45.     ULONG    signals;
  46.     BOOL    running=TRUE, getfileflag=FALSE;
  47.     char *source, *destination;
  48.     struct RDArgs        *args=NULL;
  49.     LONG                        arg[5];
  50.  
  51.     // Using standar AmigaDOS parsing routines
  52.     if(args=ReadArgs(TEMPLATE, arg, NULL))
  53.     {
  54.         char *dummy;
  55.         long intype =strtol((UBYTE *)arg[0], &dummy, 10);
  56.         long outtype=strtol((UBYTE *)arg[2], &dummy, 10);
  57.         noargs=FALSE;
  58.  
  59.         Convert(intype, (UBYTE *)arg[1], outtype, (UBYTE *)arg[3]);
  60.         FreeArgs(args);
  61.         exit(0);
  62.     }
  63.  
  64.     if(app=SetupGUI())
  65.     {
  66.         if(aslreq=MUI_AllocAslRequestTags(ASL_FileRequest,TAG_DONE))
  67.         {
  68.             if((source=malloc(FNSIZE)) && (destination=malloc(FNSIZE)))
  69.             {
  70.                 strcpy(source, DEFSOURCE);
  71.                 strcpy(destination, DEFDESTINATION);
  72.                 set(sourceString, MUIA_String_Contents, source);
  73.                 set(destinationString, MUIA_String_Contents, destination);
  74.  
  75.                 CheckReady(source,destination);
  76.                 set(window, MUIA_Window_Open, TRUE);
  77.                 set(window, MUIA_Window_ActiveObject, sourceString);
  78.  
  79.                 while(running)
  80.                 {
  81.                     switch(DoMethod(app, MUIM_Application_Input, &signals))
  82.                     {
  83.                         case MUIV_Application_ReturnID_Quit:
  84.                             running=FALSE;
  85.                             break;
  86.  
  87.                         case ID_ABOUT:
  88.                             MUI_Request(app, window, 0, NULL, "*OK",
  89.                                                     aCENTRE aLIGHT
  90.                                                     CONVERTERNAME " " VERSION2 " " COPYRIGHT ".\n\n"
  91.                                                     aNORMAL aDARK
  92.                                                     "Program for converting a " PROGNAME " project\n"
  93.                                                     "to different formats.\n\n"
  94.                                                     "Placing the pointer over a gadget and pressing\n"
  95.                                                     "HELP will pop up help on that function.\n\n"
  96.                                                     "This program is Public Domain.\n"
  97.                                                     "Compiled on " CURRENT_DAY ", " CURRENT_DATE);
  98.                             break;
  99.  
  100.                         case ID_GETSOURCE:
  101.                             getfileflag=TRUE;
  102.  
  103.                         case ID_SOURCESTRING:
  104.                             if(getfileflag)
  105.                             {
  106.                                 if(GetFile(GetWinPtr(window),
  107.                                                 aslreq,
  108.                                                 "Select Source File...",
  109.                                                 source,
  110.                                                 ""))
  111.                                     set(window, MUIA_Window_ActiveObject, sourceString);
  112.                             }
  113.                             else
  114.                                 get(sourceString, MUIA_String_Contents, &source);
  115.                             set(sourceString, MUIA_String_Contents, source);
  116.                             set(window, MUIA_Window_ActiveObject, destinationString);
  117.                             CheckReady(source,destination);
  118.                             getfileflag=FALSE;
  119.                             break;
  120.  
  121.                         case ID_GETDESTINATION:
  122.                             getfileflag=TRUE;
  123.  
  124.                         case ID_DESTINATIONSTRING:
  125.                             if(getfileflag)
  126.                             {
  127.                                 if(GetFile(GetWinPtr(window),
  128.                                                 aslreq,
  129.                                                 "Select Destination File...",
  130.                                                 destination,
  131.                                                 ""))
  132.                                     set(window, MUIA_Window_ActiveObject, destinationString);
  133.                             }
  134.                             else
  135.                                 get(destinationString, MUIA_String_Contents, &destination);
  136.                             set(destinationString, MUIA_String_Contents, destination);
  137.                             set(window, MUIA_Window_ActiveObject, sourceString);
  138.                             CheckReady(source,destination);
  139.                             getfileflag=FALSE;
  140.                             break;
  141.  
  142.                         case ID_CONVERT:
  143.                             set(window, MUIA_Window_Sleep, TRUE);
  144.                             if(!Convert(Active(sourceListView), source,
  145.                                                     Active(destinationListView),destination))
  146.                                 MUI_Request(app, window, 0, NULL, "*OK",
  147.                                                         "Not the correct loadmodule!");
  148.                             set(window, MUIA_Window_Sleep, FALSE);
  149.                             break;
  150.                     }
  151.  
  152.                     if (running && signals)
  153.                         Wait(signals);
  154.                 }
  155.                 set(window,MUIA_Window_Open,FALSE);
  156.                 free(source);
  157.                 free(destination);
  158.             }
  159.             MUI_FreeAslRequest(aslreq);
  160.         }
  161.         fail(app,NULL);
  162.     }
  163. }
  164.  
  165. BOOL Exists(char name[256])
  166. {
  167.     FILE    *fp=NULL;
  168.     BOOL    exists=FALSE;
  169.  
  170.     if(fp=fopen(name,"r"))
  171.         exists=TRUE;
  172.     fclose(fp);
  173.     return exists;
  174. }
  175.  
  176. void CheckReady(char source[256], char destination[256])
  177. {
  178.     if(Exists(source) && strlen(destination)>0 &&
  179.                                                 strcmp(destination, DEFDESTINATION))
  180.         set(convert, MUIA_Disabled, FALSE);
  181.     else
  182.         set(convert, MUIA_Disabled, TRUE);
  183. }
  184.  
  185. BOOL Convert(long intype, char *source,
  186.                                                                 long outtype, char *destination)
  187. {
  188.     struct List        *list=NULL;
  189.     BOOL success=FALSE;
  190.  
  191.     if(list=AllocMem(sizeof(struct List), MEMF_CLEAR))
  192.     {
  193.         NewList(list);
  194.  
  195.         switch(intype)
  196.         {
  197.             case LOAD_ASCII:
  198.                 success=ReadASCII(list, source);
  199.                 break;
  200.  
  201.             case LOAD_V1X:
  202.                 success=ReadPrefs14(list, source);
  203.                 break;
  204.  
  205.             case LOAD_V20:
  206.                 success=ReadIFF(list, source);
  207.                 break;
  208. /*
  209.             default:
  210.                 printf("Wrong source type: %d\n", intype);
  211.                 break;
  212. */
  213.         }
  214.  
  215.         if(success)
  216.         {
  217.             switch(outtype)
  218.             {
  219.                 case SAVE_ASCII:
  220.                     WriteASCII(list, destination);
  221.                     break;
  222.  
  223.                 case SAVE_V20:
  224.                     WriteIFF(list, destination);
  225.                     break;
  226. /*
  227.                 default:
  228.                     printf("Wrong destination type: %d\n", outtype);
  229.                     break;
  230. */
  231.             }
  232.         }
  233.         FreeEventList(list);
  234.         FreeMem(list, sizeof(struct List));
  235.     }
  236.     if(success && noargs)
  237.         MyRequest("Conversion was successfull!", "OK", "");
  238.     return success;
  239. }
  240.