home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / leadtool.zip / LEADECOM.C < prev    next >
Text File  |  1992-07-20  |  14KB  |  393 lines

  1. /****************************************************************************/
  2. /* FILE NAME: LEADECOM.C SOFTWARE DECOMPRESS FILE TO FILE                   */
  3. /* PROGRAMER: MOHAMMAD DAHER                                                */
  4. /* DATE:      03/12/1992                                                    */
  5. /*                                                                          */
  6. /*     COPYRIGHT (c) LEAD Technologies Inc. ALL RIGHTS RESEVED              */
  7. /****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include"v:\leadview\toolkit\L_Bitmap.h"
  12. #include"v:\leadview\toolkit\L_error.h"
  13. #include"v:\leadview\toolkit\toolapp.h"  
  14.  
  15. #define OK 1
  16. #define BAD_COMMAND -2
  17. #define TARGAOLD 1
  18. #define VGA   2
  19.  
  20. #if __BORLANDC__
  21.     extern unsigned _stklen = 13000U;
  22. #endif
  23.  
  24. int format = TGA24;
  25.  
  26. main(int argc, char *argv[])
  27. {
  28.   FILEINFO FileInformation;
  29.   struct find_t file;
  30.   int result;
  31.   int i;
  32.   char string[256];
  33.   int mode,page;
  34.   int error;
  35.   char outfile[128], infile[128], pathname[128];
  36.   int wild_flag = 0;
  37.  
  38.   if(argc<=2)
  39.   {
  40.      printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  41.      printf("              8701 Mallard Creek Rd.\n");
  42.      printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  43. printf("LEADTOOLS DEMO is for Evaluation purposes only. Your license to use this\n");
  44.      printf("software will expire after 3 weeks from the date you receive it.\n");
  45.      printf("You are free to distribute this demo copy of LEADTOOLS as long as all files\n");
  46.      printf("listed (DEMO.C DEMO36.EXE LEADSHOW.C LEADSHOW.EXE LEADCOMP.C\n");
  47.      printf("LEADCOMP.EXE LEADECOM.C LEADECOM.EXE) are all included. You may not distribute\n");
  48.      printf("any of the files separately.\n");
  49.      printf("If you do not have the above list of files please contact LEAD Technologies Inc.\n");
  50.      printf("for the complete list.\n");
  51.      printf("All .EXE programs are not designed as end user products.  They all are a quick\n");
  52.      printf("collection of calls to LEADTOOLS functions.  Menus were not included to avoid\n");
  53.      printf("confusion when evaluating the code as to the processing calls verses the\n");
  54.      printf("menuing code..........................PRESS ANY KEY TO CONTINUE.\n");
  55.       L_SleepKey(20);
  56.       printf("\nDOS - File to file software decompresion utility Version 3.6\n");
  57.       printf("USEAGE: LEADECOM <source file> <target file> [/option1]\n");
  58.       printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  59.       printf("<target file> is any DOS file name\n");
  60.       printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  61.       printf("          /TGA16 decompress to 16bits TGA image file format\n");
  62.       printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  63.       printf("          /TGA32 decompress to 32bits TGA image file format\n");
  64.       printf("          /TIF24 decompress to 24bits TIF image file format\n");
  65.       printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  66.       printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  67.       printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  68.       printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  69.       printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  70.       printf("          /PCX decompress to 8bits color mapped PCX image file format\n");
  71.       printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  72.       printf("DOS wildcards are also supported for <source file> and <target file>\n");
  73.       printf("EXAMPLE LEADECOM *.cmp *.TGA /TGA24\n");
  74.       printf("  will decompress all cmp files to 24bits TGA files.\n");
  75.       if(argc==1)
  76.          printf("ERROR NO <source file> and <target file> specified");
  77.       else
  78.          printf("ERROR NO <target file> specified");
  79.       exit(0);
  80.   }
  81.  else
  82.     if(argv[1][0]=='/')
  83.      {
  84.         printf("Error Bad source file %s",argv[1]);
  85.         exit(0);
  86.      }
  87.     else if(argv[2][0]=='/')
  88.      {
  89.         printf("Error Bad source file %s",argv[1]);
  90.         exit(0);
  91.      }
  92.   
  93.   
  94.   strupr(argv[1]);
  95.   strupr(argv[2]);
  96.   
  97.   if ( find_wildletter(argv[1]) == 1)
  98.      {
  99.        if (find_wildletter(argv[2]) == 1)
  100.           wild_flag = 1;
  101.      }
  102.   
  103.   for (i = 3; i<=argc; i++)
  104.     {
  105.        strupr(argv[i]);
  106.        if(argv[i][0]=='/')
  107.           if(get_value(argv[i]+1)==BAD_COMMAND)
  108.            {
  109.              printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  110.              printf("              8701 Mallard Creek Rd.\n");
  111.              printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  112.              L_SleepKey(1);
  113.              printf("\nDOS - File to file software decompresion utility Version 3.6\n");
  114.              printf("USEAGE: LEADECOM <source file> <target file> [/option1]\n");
  115.              printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  116.              printf("<target file> is any DOS file name\n");
  117.              printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  118.              printf("          /TGA16 decompress to 16bits TGA image file format\n");
  119.              printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  120.              printf("          /TGA32 decompress to 32bits TGA image file format\n");
  121.              printf("          /TIF24 decompress to 24bits TIF image file format\n");
  122.              printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  123.              printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  124.              printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  125.              printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  126.              printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  127.              printf("          /PCX decompress to 8bits color mapped PCX image file format\n");
  128.              printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  129.              printf("DOS wildcards are also supported for <source file> and <target file>\n");
  130.              printf("EXAMPLE LEADECOM *.cmp *.TGA /TGA24\n");
  131.              printf("  will decompress all cmp files to 24bits TGA files.\n");
  132.              if(argc==1)
  133.                 printf("ERROR NO <source file> and <target file> specified");
  134.              else
  135.                 printf("ERROR NO <target file> specified");
  136.   
  137.              printf("\nInvalid option %s",argv[i]);
  138.              exit(0);
  139.            }
  140.     }
  141.     
  142.     
  143.     get_pathname(argv[1], pathname);
  144.     result = _dos_findfirst(argv[1], 0 , &file);
  145.               /* _dosfindfirst will return a 0 if succesfull */
  146.               /*   and any other value if not       */
  147.   
  148.     if (result)   /* if result has any value rather that 0 then  */
  149.                   /* False = 0    True= any other value */
  150.                   /* and when the function is succesful it return a 0 */
  151.         printf("leadcomp: no such file %s\n",argv[1]);
  152.     else
  153.        while(!result)  /* Stop when _dos_findnext returns */
  154.                        /*   a value other than a 0        */
  155.                        /* becuse False =0 and when the
  156.                        /* function is succesful it returns a 0) */
  157.        {
  158.         strcpy(infile, pathname);
  159.         strcat(infile, file.name);
  160.         if (L_FileInfo(infile,&FileInformation)==SUCCESS)
  161.            {
  162.                if (wild_flag == 1)
  163.                   get_outfilename(file.name, argv[2], outfile);
  164.   
  165.                else
  166.                   strcpy(outfile, argv[2]);
  167.               printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  168.               printf("              8701 Mallard Creek Rd.\n");
  169.               printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  170.               printf("\nDOS - File to file software decompresion utility Version 3.6\n");
  171.               printf("\nDecompressing image file %s to %s", infile, outfile);
  172.               if( (FileInformation.Format == FILE_CMP) ||
  173.                 ( FileInformation.Format == FILE_JFIF) ||
  174.                 ( FileInformation.Format == FILE_JTIF) )
  175.                 {
  176.                    if((format==TGA8) || (format==TGA16) || (format==TGA24) ||
  177.                       (format==TGA32) )
  178.                         error=L_DecompressTGA(infile,outfile,format);
  179.                    else if( (format==TIF8) || (format==TIF24) )
  180.                         error=L_DecompressTIF(infile,outfile,format);
  181.                    else if( (format==BMP8) || (format==BMP24) || (format==PM8) ||
  182.                          (format==PM24) )
  183.                         error=L_DecompressBMP(infile,outfile,format);
  184.                    else if( (format==PCX8))
  185.                         error=L_DecompressPCX(infile,outfile,format);
  186.                    else if( (format==GIF8))
  187.                          error=L_DecompressGIF(infile,outfile,format);
  188.   
  189.                 }
  190.  
  191.                if(error!=SUCCESS)
  192.                 {
  193.                    printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  194.                    printf("              8701 Mallard Creek Rd.\n");
  195.                    printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  196.                    printf("\nDOS - File to file software decompresion utility Version 3.6\n");
  197.                    printf("\nERROR %d DECOMPRESSING IMAGE FILE %s\n",error,file.name);
  198.                 }
  199.            }
  200.           else
  201.            {
  202.               printf("\nleadcomp: error opening file %s\n",file.name);
  203.               putch(7);
  204.            }
  205.         result = _dos_findnext(&file);
  206.        }
  207. }
  208.   
  209.   
  210.   
  211.   
  212. get_value(string)
  213. char *string;
  214. {
  215.   int ret=OK;
  216.   if     ( string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  217.         && string[3] == '8' )
  218.       {
  219.          format=TGA8;
  220.       }
  221.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  222.             && string[3] == '1' && string[4] == '6')
  223.    {
  224.       format=TGA16;
  225.    }
  226.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  227.            && string[3] == '2' && string[4] == '4')
  228.    {
  229.       format=TGA24;
  230.    }
  231.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  232.            && string[3] == '3' && string[4] == '2')
  233.    {
  234.       format=TGA32;
  235.    }
  236.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  237.            && string[3] == '8')
  238.    {
  239.       format=TIF8;
  240.    }
  241.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  242.            && string[3] == '2' && string[4] == '4')
  243.    {
  244.       format=TIF24;
  245.    }
  246.   else if (   string[0] == 'B' && string[1] == 'M' && string[2] == 'P'
  247.            && string[3] == '8')
  248.    {
  249.       format=BMP8;
  250.    }
  251.   else if (   string[0] == 'B' && string[1] == 'B' && string[2] == 'P'
  252.            && string[3] == '2' && string[4] == '4')
  253.    {
  254.       format=BMP24;
  255.    }
  256.   else if (   string[0] == 'P' && string[1] == 'M'
  257.            && string[3] == '8' )
  258.    {
  259.       format=PM8;
  260.    }
  261.   else if (   string[0] == 'P' && string[1] == 'M' 
  262.            && string[3] == '2' && string[4] == '4')
  263.    {
  264.       format=PM24;
  265.    }
  266.   else if (   string[0] == 'P' && string[1] == 'C' && string[2] == 'X')
  267.    {
  268.       format=PCX8;
  269.    }
  270.   else if (   string[0] == 'G' && string[1] == 'I' && string[2] == 'F' )
  271.    {
  272.       format=GIF8;
  273.    }
  274.   else
  275.       return(ret);
  276.  
  277. return(ret);
  278. }
  279.  
  280.  
  281.  
  282. get_outfilename(from_file, as_file, to_file)
  283. char from_file[], as_file[], to_file[];
  284. {
  285.   char ext1[20], name1[128], ext2[20], name2[128];
  286.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  287.   int x, x1;
  288.   
  289.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  290.   for (i = strlen(from_file)-1; i >= 0; i--)
  291.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  292.      {
  293.          ext1_flag = 1;
  294.          break;
  295.       }
  296.   
  297.   strcpy(name1, from_file);
  298.   name1[i] = 0;
  299.   if (ext1_flag == 1)
  300.     strcpy(ext1, from_file+i+1);
  301.   for (i = strlen(as_file)-1; i >= 0; i--)
  302.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  303.      {
  304.         ext2_flag = 1;
  305.         break;
  306.      }
  307.   
  308.   strcpy(name2, as_file);
  309.   name2[i] = 0;
  310.   if (ext2_flag == 1)
  311.      strcpy(ext2, as_file+i+1);
  312.   
  313.   for (i = 0, q = 0; i < strlen(name2); i++)
  314.       {
  315.        if (name2[i] == '*')
  316.            {
  317.            to_file[i] = 0;
  318.            strcat(to_file+i, name1);
  319.            i = i + strlen(name1+q);
  320.            goto exit0;
  321.            }
  322.        if (name2[i] == '?')
  323.           {
  324.           to_file[i] = name1[i];
  325.           q++;
  326.           } 
  327.        else
  328.           to_file[i] = name2[i];
  329.       }
  330.   
  331.    to_file[i] = 0;
  332.    exit0:
  333.   
  334.    to_file[i] = '.';
  335.    i++;
  336.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  337.     {
  338.        if (ext2[j] == '*')
  339.         {
  340.            to_file[i] = 0;
  341.            strcat(to_file, ext1+q);
  342.            return(0);
  343.         }
  344.        if (name2[i] == '?')
  345.           {
  346.           to_file[i] = ext1[j];
  347.           q++;
  348.           } 
  349.        else
  350.           to_file[i] = ext2[j];
  351.     }
  352.     to_file[i] = 0;
  353.     if(to_file[i-1] == '.')
  354.        to_file[i-1] = 0;
  355.   
  356.   return(0);
  357. }
  358.   
  359.  
  360. find_wildletter(string)
  361. char string[];
  362. {
  363. int i;
  364.  
  365. for (i = 0; i < strlen(string); i++)
  366.     if (string[i] == '*')
  367.        return(1);
  368.  
  369. return(0);
  370. }
  371.  
  372. get_pathname(in, pathname)
  373. char in[], pathname[];
  374. {
  375. int i;
  376.  
  377. strcpy(pathname, in);
  378.  
  379. for (i = strlen(in)-1; i >= 0; i--)
  380.     {
  381.     if (in[i] == '\\' || in[i] == ':')
  382.        break;
  383.     }
  384.  
  385. if (i == 0)
  386.    pathname[0] = 0;
  387. else
  388.    pathname[i+1] = 0;
  389. }
  390.  
  391.  
  392.  
  393.