home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / compress / filearchivers / all2lha / source.lha / source / all2lha.c < prev    next >
C/C++ Source or Header  |  1993-01-14  |  4KB  |  189 lines

  1. /* All2LHA v1.0 de Christian Warren */
  2. #include <stdio.h>
  3. #include "exec/types.h"
  4. #include "libraries/dos.h"
  5. #include "exec/memory.h"
  6. #include "fcntl.h"
  7.  
  8. #include "Prototypes.h"
  9. #include "All2Lha.h"
  10.  
  11. struct DosBase *DOSBase;
  12.  
  13. VOID ecrit(string)
  14. register UBYTE *string;
  15. {
  16.     Write(Output(), "\n", 10);
  17.     Write(Output(), string, strlen(string));
  18.     Write(Output(), "\n", 5);
  19. }
  20.  
  21. VOID ecritsansansi(string)
  22. register UBYTE *string;
  23. {
  24.     Write(Output(), string, strlen(string));
  25. }
  26.  
  27. VOID efface_fichier(file)
  28. register UBYTE *file;
  29. {
  30.     ecrit("deleting the original file!!");
  31.     DeleteFile(file);
  32. }
  33.  
  34. VOID sortie(erreur)
  35. register ULONG erreur;
  36. {
  37.     CloseLibrary((struct Library *) DOSBase);
  38.     exit(erreur);
  39. }
  40.  
  41. int main(argc, argv)
  42. int argc;
  43. char *argv[];
  44. {
  45.     register UWORD i, j, EFFACE = APRES_CREER_LHA;
  46.     UBYTE sourcefile[120], filelha[120], a_exec[200], current_dir[120], comment[80];
  47.     struct FileLock *lock;
  48.     struct FileInfoBlock *info;
  49.     int fichier;
  50.  
  51.     if (!(DOSBase = (struct DosBase *) OpenLibrary("dos.library", 0)))
  52.         exit(1);
  53.  
  54.     ecritsansansi("\nALL2LHA v1.0  FreeWare\n");
  55.     getcwd(current_dir, 120);
  56.  
  57.     if (argc < 2)
  58.     {
  59.         ecritsansansi("Usage: all2lha [-options] file.lzh file.arc file.zoo file.zip file.arj...\n");
  60.         ecritsansansi("       you'll need arc, zoo, unzip, unarj and LHA in a C: directory...\n");
  61.         ecritsansansi("       Options\n");
  62.         ecritsansansi("              -n Dont Delete the original archive.\n");
  63.         ecritsansansi("              -a Delete the original archive before\n");
  64.         ecritsansansi("                 the creation of the '.lha'.\n");
  65.         ecritsansansi("              -n Delete the original archive after\n");
  66.         ecritsansansi("                 the creation of the '.lha'. (Default).\n");
  67.         sortie(0);
  68.     }
  69.  
  70.     if (!getfa("t:all2lha_rep_temp") && (mkdir("t:all2lha_rep_temp")))
  71.     {
  72.         ecrit("Can not create temp directory!");
  73.         sortie(2);
  74.     }
  75.  
  76.     chdir("t:all2lha_rep_temp");
  77.     i = 1;
  78.     do
  79.     {
  80.         if (argv[i][0] == '-')
  81.         {
  82.             switch (argv[i][1])
  83.             {
  84.                 case 'a':
  85.                     EFFACE = AVANT_CREER_LHA;
  86.                     break;
  87.                 case 'p':
  88.                     EFFACE = APRES_CREER_LHA;
  89.                     break;
  90.                 case 'n':
  91.                     EFFACE = N_EFFACE_PAS;
  92.                     break;
  93.             }
  94.             i++;
  95.         }
  96.         else
  97.             break;
  98.     } while (TRUE);
  99.  
  100.     while (i < argc)
  101.     {
  102.         strcpy(sourcefile, argv[i]);
  103.         strmfe(filelha, argv[i], "lha");
  104.         i++;
  105.  
  106.         strcpy(a_exec, "File -> ");
  107.         strcat(a_exec, sourcefile);
  108.         ecrit(a_exec);
  109.  
  110.         if (fichier = open(sourcefile, O_RDONLY, 0))
  111.         {
  112.             read(fichier, a_exec, 7);
  113.             close(fichier);
  114.             if (!strnicmp(&a_exec[2], "-lh5-", 5))
  115.             {
  116.                 ecrit("The file is already in .lha!");
  117.                 ecrit("Renaming to .lha...");
  118.                 Rename(sourcefile, filelha);
  119.                 continue;
  120.             }
  121.         }
  122.  
  123.         if (getfa(sourcefile) == -1)
  124.         {
  125.             for (j = 0; j < NB_D_ARCHIVEUR; j++)
  126.             {
  127.                 strcpy(a_exec, "Archiver -> ");
  128.                 strcat(a_exec, archiveur[j].Extension);
  129.                 ecrit(a_exec);
  130.  
  131.                 if (!stricmp(&sourcefile[strlen(sourcefile) - strlen(archiveur[j].Extension)], archiveur[j].Extension))
  132.                 {
  133.                     strcpy(a_exec, archiveur[j].Desarchive);
  134.                     strcat(a_exec, " \"");
  135.                     strcat(a_exec, sourcefile);
  136.                     strcat(a_exec, "\"");
  137.                     ecrit("Un-archiving...");
  138.  
  139.                     if (!system(a_exec))
  140.                     {
  141.                         if ((info = (struct FileInfoBlock *)
  142.                               AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC | MEMF_CLEAR)))
  143.                         {
  144.                             if (lock = (struct FileLock *) Lock(sourcefile, SHARED_LOCK))
  145.                             {
  146.                                 if (Examine((BPTR) lock, info))
  147.                                     strcpy(comment, info->fib_Comment);
  148.                                 UnLock((BPTR) lock);
  149.                             }
  150.                             FreeMem(info, sizeof(struct FileInfoBlock));
  151.                         }
  152.  
  153.                         strcpy(a_exec, "lha -x -a -m -r -2 a \"");
  154.                         strcat(a_exec, filelha);
  155.                         strcat(a_exec, "\" #?");
  156.  
  157.                         ecrit("Un-Protecting files...");
  158.                         system("Protect t:all2lha_rep_temp/#? +d ALL QUIET");
  159.  
  160.                         if (EFFACE == AVANT_CREER_LHA)
  161.                             efface_fichier(sourcefile);
  162.  
  163.                         ecrit("Archiving...");
  164.                         if (!system(a_exec))
  165.                         {
  166.                             SetComment(filelha, comment);
  167.                             if (EFFACE == APRES_CREER_LHA)
  168.                                 efface_fichier(sourcefile);
  169.                             break;
  170.                         }
  171.                         else
  172.                             ecrit("Files where not archived correctly!");
  173.                     }
  174.                     else
  175.                         ecrit("File could not be un-Arc properly!");
  176.                 }
  177.                 else
  178.                     ecrit("File dont have the right extension!");
  179.             }
  180.             system("Delete t:all2lha_rep_temp/#? ALL QUIET");
  181.         }
  182.     }
  183.  
  184.     chdir(current_dir);
  185.     system("Delete t:all2lha_rep_temp ALL QUIET");
  186.  
  187.     sortie(0);
  188. }
  189.