/**
 * @file   SCFCUGZP.c
 * @brief  Sample program in C to run FLUC-CONV
 * @author limes datentechnik gmbh
 ******************************************************************************/

/* defines code page for literals for IBM mainframes to German */
#ifdef __ZOS__
#  pragma convert(1141)
#endif

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include"FLUCUP.h"

/**
 * This test program takes one or two parameters to compress files via
 * the FLUC subprogram.
 *
 * @param argc must be 2 or 3
 * @param argv input and optional output filename
 * @return flucup error
 */
int main(int argc, char * argv[])
{
   unsigned int   i;
   char           acCmdStr[65536];
   char*          h;
   char*          a[5]={"","","","",""};

/* defines environment variable LANG to German EBCDIC for IBM mainframes */
#ifdef __ZOS__
   __setenv("LANG","de_DE.IBM-1141",1);
#endif

   if (argc==2) { /* parse HOST parameter string */
      i=2; a[0]=argv[0]; a[1]=argv[1];
      h=strchr(a[1],',');
      if (h!=NULL) { h[0]=0x00; a[2]=h+1; i++; }
      argc=i; argv=a;
   }

   switch (argc) {
   case 2: snprintf(acCmdStr,sizeof(acCmdStr),"read.binary(file='%s' deco) write.binary(comp.gzip())"          ,argv[1]);         break;
   case 3: snprintf(acCmdStr,sizeof(acCmdStr),"read.binary(file='%s' deco) write.binary(comp.gzip() file='%s')",argv[1],argv[2]); break;
   default:
      fprintf(stderr,"Parameter count (%d) not correct (2/3) to run this sample program\n",argc);
      fprintf(stderr,"Given parameter:\n");
      for (i=0;i<argc;i++) fprintf(stderr,"--> P%2.2u(%s)\n",i,argv[i]);
      fprintf(stderr,"Required parameter:\n");
      fprintf(stderr,"   :> %s inputfilename [outputfilename]\n",argv[0]);
      exit(20);
   }

   return(flucconv(acCmdStr,NULL,":STDERR",NULL));
}

/**********************************************************************/
