Difference between revisions of "C version of DISPR"

From MidrangeWiki
Jump to: navigation, search
(the code)
m
Line 8: Line 8:
  
  
===CDISP C ===
+
===CDISPR C ===
  
 
<pre>
 
<pre>
Line 531: Line 531:
 
  }
 
  }
  
 +
</pre>
 +
===CDISPR needed files ===
  
 +
You need to create these file
  
 +
<pre>
 +
 +
To create files REL and SEL
  
 
DSPFD FILE(*libl/urfile*) TYPE(*ACCPTH) OUTPUT(*OUTFILE) OUTFILE(QTEMP/REL)
 
DSPFD FILE(*libl/urfile*) TYPE(*ACCPTH) OUTPUT(*OUTFILE) OUTFILE(QTEMP/REL)
DSPFD FILE(*libl/urfile*) TYPE(*select) OUTPUT(*OUTFILE) OUTFILE(QTEMP/sEL)  
+
DSPFD FILE(*libl/urfile*) TYPE(*select) OUTPUT(*OUTFILE) OUTFILE(QTEMP/SEL)  
 +
 
 +
DDS for  CDISPRF
  
     A*%%TS  SD  20101208  163705  KOLMANNF    REL-V5R4M0  5722-WDS
+
     A*%%TS  SD   
 
     A*
 
     A*
 
     A*%%EC
 
     A*%%EC
Line 546: Line 554:
 
     A                                      CF12(12)
 
     A                                      CF12(12)
 
     A          R S01                      SFL
 
     A          R S01                      SFL
     A*%%TS  SD  20101208  163705  KOLMANNF    REL-V5R4M0  5722-WDS
+
     A*%%TS  SD   
 
     A            S01FUNC        2A  B  4  3
 
     A            S01FUNC        2A  B  4  3
 
     A  55
 
     A  55
Line 562: Line 570:
 
     A            S01APKEYF R        O  4 61REFFLD(QWHFDACP/APKEYF QTEMP/REL)
 
     A            S01APKEYF R        O  4 61REFFLD(QWHFDACP/APKEYF QTEMP/REL)
 
     A          R C01                      SFLCTL(S01)
 
     A          R C01                      SFLCTL(S01)
     A*%%TS  SD  20101208  163705  KOLMANNF    REL-V5R4M0  5722-WDS
+
     A*%%TS  SD   
 
     A                                      SFLSIZ(0019)
 
     A                                      SFLSIZ(0019)
 
     A                                      SFLPAG(0018)
 
     A                                      SFLPAG(0018)

Revision as of 07:35, 1 April 2014


C Program

A C program that uses a subfile. I named the program CDISPR snd it is a conversion of the RPGLE program DISPR.


CDISPR C




/*                 */
#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
#include <string.h>
#include <ctype.h>
#include <decimal.h>
#include <xxcvt.h>

enum Panels
     {
     TOP , S01BLD, S01PRC, S01PRS, S02BLD, S02PRC
     };

#define NUM_RECS   9999

#define PFILENAME    "*LIBL/REL"
#define SOPFILE     "*LIBL/SEL"
#define SUBFILENAME  "*LIBL/CDISPRF"

#pragma mapinc("ddhpf","*libl/REL(*ALL)","input"," ",,"")
#include "ddhpf"

#pragma mapinc("ddspf","*libl/SEL(*ALL)","input"," ",,"")
#include "ddspf"

#pragma mapinc("ddhdf","*LIBL/CDISPRF(*ALL)","both indicators"," ",,"")
#include "ddhdf"



#define RECLENPF sizeof(QWHFDACP_i_t)
#define RECLENSEL sizeof(QWHFDSO_i_t)
#define RECLENS01i sizeof(S01_i_t)
#define RECLENS01o sizeof(S01_o_t)
#define RECLENC01i sizeof(C01_i_t)
#define RECLENC01o sizeof(C01_o_t)
#define RECLENS02i sizeof(S02_i_t)
#define RECLENS02o sizeof(S02_o_t)
#define RECLENC02i sizeof(C02_i_t)
#define RECLENC02o sizeof(C02_o_t)

#define IND_ON '1'
#define IND_OFF '0'
#define I03     02
#define I12     11
#define I51     50
#define I52     51
#define I53     52
#define I56     55
#define EQ      ==
#define SHARE   static
#define EXPORT
#define IMPORT  extern

void fS01BLD(_RFILE *, _RFILE *, int *, char *, char *);
void fS01PRC(_RFILE *, int *, char *, char *);
void fS01PRS(_RFILE *, int *, char *, char *);
void fS02BLD(_RFILE *, _RFILE *, int *,char *, char *);
void fS02PRC(_RFILE *, int *,char *, char *);



EXPORT    enum Panels Panel[99]  ;
EXPORT    int  pnl_lvl = 0;
EXPORT    _SYSindara       indicator_area;


int main(void)
{
    _RFILE           *pf;
    _RFILE           *subf;
    _RFILE           *sopf;


    int              i;
    int              n;
    int              *pn  = &n;
    int              n2;
    int              *pn2  = &n2;

    char C01FILE[10] = "          ";
    char C01LIB[10]  = "          ";
    char *p_c01file ;
    char *p_c01lib ;
    char C02FILE[10] = "          ";
    char C02LIB[10]  = "          ";
    char *p_c02file ;
    char *p_c02lib ;

    p_c01file =  C01FILE;
    p_c01lib  =  C01LIB;
    p_c02file =  C02FILE;
    p_c02lib  =  C02LIB;

    Panel[++pnl_lvl] = TOP ;
    Panel[++pnl_lvl] =  S01BLD ;

    for (i = 0; i <= 98; i++)
        { indicator_area[i] = IND_OFF;}


/* Open the Relations  file.                            */
    if ((pf = _Ropen(PFILENAME, "rr")) EQ NULL)
    {   printf("can't open file %s\n", PFILENAME);  exit(1); }

/* Open the subfile  file.                            */
    if ((subf = _Ropen(SUBFILENAME, "wr+ indicators=y")) EQ NULL)
    {   printf("can't open file %s\n", SUBFILENAME); exit(2); }
    _Rindara ( subf, indicator_area );

 /* Open the Select/Omit  file.                            */
    if ((sopf = _Ropen(SOPFILE, "rr")) EQ NULL)
    {   printf("can't open file %s\n", SOPFILE);  exit(1); }


for (;;) {


  switch (Panel[pnl_lvl])
  {
    case S01BLD:
       fS01BLD(pf, subf, pn, p_c01file, p_c01lib );
      break;

    case S01PRC:
       fS01PRC(subf, pn, p_c01file, p_c01lib );
      break;

    case  S01PRS:
       fS01PRS(subf, pn,  p_c02file, p_c02lib);
      break;

    case S02BLD:
       fS02BLD(sopf, subf, pn2, p_c02file, p_c02lib);
      break;

    case S02PRC:
       fS02PRC(subf, pn2,p_c02file, p_c02lib);
      break;

    case TOP:
  //  EXIT THE PROGRAM
      exit(0);
  }

  //  CF3 EXIT
    if (indicator_area[I03] EQ IND_ON)
    { exit(0); }
  //  CF12  PREVIOUS
    if (indicator_area[I12] EQ IND_ON)
    { indicator_area[I12] = IND_OFF,pnl_lvl--; }

}


/* Close the physical files and the subfile.                           */
     _Rclose(pf);
     _Rclose(sopf);
     _Rclose(subf);
}

//  ###################################



void fS01BLD(_RFILE *pf, _RFILE *subf, int *n, char *f, char *l)
 {
   _RIOFB_T      *fb;
    int           i;
    QWHFDACP_i_t  pfrcd;
    S01_o_t       sfrcd;
    S01_o_t       *p_sfrcd;
    char          wfile[10];
    char          wlib[10];

    p_sfrcd    =  &sfrcd;
    _Rindara(subf, indicator_area );

/* CLEAR the SUBFILE  */
     _Rformat(subf, "C01");
    indicator_area[I51] = IND_OFF;
    indicator_area[I52] = IND_OFF;
    indicator_area[I53] = IND_ON;
      fb = _Rwrite(subf, "" , 0);


/* Select the subfile record format.                                  */
        _Rformat(subf, "S01");
        *n = 0;
        for (i = 1; i <= NUM_RECS; i++)
        {
               fb = _Rreadn(pf, &pfrcd, RECLENPF, __DFT);
               if (fb->num_bytes != EOF)
               {


                memcpy (f , pfrcd.APFILE, 10);
                memcpy (l , pfrcd.APLIB , 10);
                if (( memcmp(pfrcd.APFILE, wfile, 10) EQ 0 ) &&
                    ( memcmp(pfrcd.APLIB, wlib, 10) EQ 0 ))
                {
                indicator_area[I56] = IND_ON;
                memcpy (sfrcd.S01FUNC  , "          ", 2  );
                memcpy (sfrcd.S01APFILE, "          ", 10 );
                memcpy (sfrcd.S01APLIB , "          ", 10 );
                memcpy (sfrcd.S01APACCP, "          ", 1  );
                memcpy (sfrcd.S01APUNIQ, "          ", 1  );
                memcpy (sfrcd.S01APSELO, "          ", 1  );
                memcpy (sfrcd.S01APFTYP, "          ", 1  );
                memcpy (sfrcd.S01APJOIN, "          ", 1  );
                memcpy (sfrcd.S01APKEYO, "          ", 1  );
                memcpy (sfrcd.S01APKSEQ, pfrcd.APKSEQ, 1  );
                memcpy (sfrcd.S01APKSIN, pfrcd.APKSIN, 1  );
                memcpy (sfrcd.S01APKEYF, pfrcd.APKEYF, 10 );
                }
                else
                {
                indicator_area[I56] = IND_OFF;
                memcpy (sfrcd.S01FUNC  , "          ", 2  );
                memcpy (wfile, pfrcd.APFILE, 10 );
                memcpy (wlib, pfrcd.APLIB, 10 );
                memcpy (sfrcd.S01APLIB , pfrcd.APLIB , 10 );
                memcpy (sfrcd.S01APFILE, pfrcd.APFILE, 10 );
                memcpy (sfrcd.S01APLIB , pfrcd.APLIB , 10 );
                memcpy (sfrcd.S01APACCP, pfrcd.APACCP, 1  );
                memcpy (sfrcd.S01APUNIQ, pfrcd.APUNIQ, 1  );
                memcpy (sfrcd.S01APSELO, pfrcd.APSELO, 1  );
                memcpy (sfrcd.S01APFTYP, pfrcd.APFTYP, 1  );
                memcpy (sfrcd.S01APJOIN, pfrcd.APJOIN, 1  );
                memcpy (sfrcd.S01APKEYO, pfrcd.APKEYO, 1  );
                memcpy (sfrcd.S01APKSEQ, pfrcd.APKSEQ, 1  );
                memcpy (sfrcd.S01APKSIN, pfrcd.APKSIN, 1  );
                memcpy (sfrcd.S01APKEYF, pfrcd.APKEYF, 10 );
                }

                 fb = _Rwrited(subf, p_sfrcd, RECLENS01o, i);

                 if (fb->num_bytes != RECLENS01o )
                 {
                   printf("error occurred during write\n");
                   exit(3);
                 }
                 else
                 {
                   *n = i;
                 }


               }
               else
               {
               break;
               }
        }
        Panel[++pnl_lvl] =  S01PRC ;

 }
//  ###################################

void fS01PRC(_RFILE *subf, int *n, char *f, char *l)
 {

 /*
 +Write the subfile to the display by writing a record to the
 +subfile control format.
 */
    int             i;
    _RIOFB_T      *fb;

    C01_o_t       cfrcd;
    C01_o_t       *p_cfrcd;

    p_cfrcd    = &cfrcd;

    _Rformat(subf, "R01");
    fb = _Rwrite(subf, "", 0);

    for (;;)
    {
     _Rformat(subf, "C01");
     _Rindara(subf, indicator_area );

      i = 1;
      QXXITOZ (cfrcd.SRS01 , 4 , 0, i);

      memcpy (cfrcd.C01APBOF, f , 10);
      memcpy (cfrcd.C01APBOL, l , 10);

    indicator_area[I51] = IND_OFF;
    indicator_area[I52] = IND_ON;
    indicator_area[I53] = IND_OFF;
    if (n != 0)
    { indicator_area[I51] = IND_ON; }

     fb = _Rwrite(subf, p_cfrcd, RECLENC01o);

     if (fb->num_bytes != RECLENC01o )
                 {
                   printf("error occurred during write\n");
                   exit(3);
                 }


     _Rreadn(subf, "", 0, __DFT);

      //  CF3 EXIT
    if (indicator_area[I03] EQ IND_ON) { break; }

     //  CF12 Previous
         if (indicator_area[I12] EQ IND_ON)
         {pnl_lvl--; break; }

    //  Process the subfile

    Panel[++pnl_lvl] =  S01PRS ;
    break;

    }
 }

 //  ###################################
void fS01PRS(_RFILE *subf, int *n,  char *f, char *l)
 {

  _RIOFB_T      *fb;
    S01_i_t       sfrcd;
    S01_i_t       *p_sfrcd;
    long        rrn;
    int         i;
    int         j;
    char        func[2];

   p_sfrcd    =  &sfrcd;
   _Rindara(subf, indicator_area );


/* Select the subfile record format.                                  */
        _Rformat(subf, "S01");


    for (i = 1; i <= *n ; i++)
    {
        rrn = i;
         fb = _Rreadd(subf, p_sfrcd, RECLENS01i, __DFT,rrn);
               if (fb->num_bytes EQ EOF)
               {
               {pnl_lvl--; break; }
               }
               else
               {
                memcpy (f, sfrcd.S01APFILE , 10 );
                memcpy (l, sfrcd.S01APLIB , 10 );
                memcpy (&func, sfrcd.S01FUNC, 2);

             //  convert to upper case radj blank fill
                for(j = 0; j EQ 1; j++) {func[j] = toupper(func[j]); }
                if (memcmp(&func[0], " ", 1) EQ 0 )
                  {
                  memmove(&func[0] , &func[1] ,1);
                  memcpy(&func[1] ," ", 1);
                  }

               if (memcmp(func, "X ", 2) EQ 0 )
               {
               indicator_area[I03] = IND_ON ;  break;
               }

               if (memcmp(func, "R ", 2) EQ 0 )
               {
                memcpy (sfrcd.S01FUNC  , "          ", 2  );
                fb  =  _Rupdate(subf,p_sfrcd, RECLENS01i);
                Panel[++pnl_lvl] =  S02BLD ; break;
               }
               if (fb->rrn  EQ *n)
               {  --pnl_lvl;   }

               }

    }


 }

//  ###################################

void fS02BLD(_RFILE *sopf, _RFILE *subf, int *n2, char *f, char *l)
 {

  _RIOFB_T      *fb;
    QWHFDSO_i_t  pfrcd;
    S02_o_t       sfrcd;
    S02_o_t       *p_sfrcd;
    long        rrn;
    int         i;
    int         j;
    char        wfile[10];
    char        wlib[10];

    p_sfrcd =  &sfrcd;
   _Rindara(subf, indicator_area );

    memcpy (wfile , f, 10);
    memcpy (wlib , l , 10);

    /* CLEAR the SUBFILE  */
     _Rformat(subf, "C02");
    indicator_area[I51] = IND_OFF;
    indicator_area[I52] = IND_OFF;
    indicator_area[I53] = IND_ON;
      fb = _Rwrite(subf, "" , 0);


/* Select the subfile record format.                                  */
    _Rformat(subf, "S02");
    *n2 = 0;
    j = 0;

    for (i = 1; i < NUM_RECS; i++)
    {
        rrn = i;
         fb = _Rreadd(sopf, &pfrcd, RECLENSEL, __NO_LOCK,rrn);
               if (fb->num_bytes EQ EOF)
               {
               break;
               }
               else
               {

               if (( memcmp(pfrcd.SOFILE, wfile, 10) EQ 0 ) &&
                    ( memcmp(pfrcd.SOLIB, wlib, 10) EQ 0 ))
               {
                memcpy (sfrcd.S02SOFLD, pfrcd.SOFLD, 10  );
                memcpy (sfrcd.S02SORULE, pfrcd.SORULE, 1  );
                memcpy (sfrcd.S02SOCOMP, pfrcd.SOCOMP, 2 );
                memcpy (sfrcd.S02SOVALU, pfrcd.SOVALU, 32 );

               fb = _Rwrited(subf, p_sfrcd, RECLENS02o, ++j);

                 if (fb->num_bytes != RECLENS02o )
                 {
                   printf("error occurred during write\n");
                   exit(3);
                 }
                 else
                 {
                   *n2 = j;
                 }
                }

               }

    }
             Panel[++pnl_lvl] =  S02PRC ;

   }

//  ###################################

void fS02PRC(_RFILE *subf, int *n, char *f, char *l)
 {

 /*
 +Write the subfile to the display by writing a record to the
 +subfile control format.
 */
    int             i;
    _RIOFB_T      *fb;

    C02_o_t       cfrcd;
    C02_o_t       *p_cfrcd;

    p_cfrcd    = &cfrcd;

    _Rformat(subf, "R02");
    fb = _Rwrite(subf, "", 0);

    for (;;)
    {
     _Rformat(subf, "C02");
     _Rindara(subf, indicator_area );

      i = 1;
      QXXITOZ (cfrcd.SRS02 , 4 , 0, i);

      memcpy (cfrcd.C02APFILE, f , 10);
      memcpy (cfrcd.C02APLIB, l , 10);

    indicator_area[I51] = IND_OFF;
    indicator_area[I52] = IND_ON;
    indicator_area[I53] = IND_OFF;
    if (n != 0)
    { indicator_area[I51] = IND_ON; }

     fb = _Rwrite(subf, p_cfrcd, RECLENC02o);

     if (fb->num_bytes != RECLENC02o )
                 {
                   printf("error occurred during write\n");
                   exit(3);
                 }


     _Rreadn(subf, "", 0, __DFT);

      //  CF3 EXIT
    if (indicator_area[I03] EQ IND_ON) { break; }

     //  CF12 Previous
    if (indicator_area[I12] EQ IND_ON)
            { indicator_area[I12] = IND_OFF; }

     //  ENTER  and F12
        pnl_lvl--;pnl_lvl--;break;
    }
 }

CDISPR needed files

You need to create these file


To create files REL and SEL

DSPFD FILE(*libl/urfile*) TYPE(*ACCPTH) OUTPUT(*OUTFILE) OUTFILE(QTEMP/REL)
DSPFD FILE(*libl/urfile*) TYPE(*select) OUTPUT(*OUTFILE) OUTFILE(QTEMP/SEL) 

DDS for  CDISPRF

     A*%%TS  SD  
     A*
     A*%%EC
     A                                      INDARA
     A                                      DSPSIZ(24 80 *DS3)
     A                                      PRINT
     A                                      CF03(03)
     A                                      CF12(12)
     A          R S01                       SFL
     A*%%TS  SD  
     A            S01FUNC        2A  B  4  3
     A  55
     AO 56                                  DSPATR(PR ND)
     A            S01APFILE R        O  4  6REFFLD(QWHFDACP/APFILE QTEMP/REL)
     A            S01APLIB  R        O  4 17REFFLD(QWHFDACP/APLIB QTEMP/REL)
     A            S01APACCP R        O  4 29REFFLD(QWHFDACP/APACCP QTEMP/REL)
     A            S01APUNIQ R        O  4 33REFFLD(QWHFDACP/APUNIQ QTEMP/REL)
     A            S01APSELO R        O  4 37REFFLD(QWHFDACP/APSELO QTEMP/REL)
     A            S01APFTYP R        O  4 41REFFLD(QWHFDACP/APFTYP QTEMP/REL)
     A            S01APJOIN R        O  4 45REFFLD(QWHFDACP/APJOIN QTEMP/REL)
     A            S01APKEYO R        O  4 48REFFLD(QWHFDACP/APKEYO QTEMP/REL)
     A            S01APKSEQ R        O  4 53REFFLD(QWHFDACP/APKSEQ QTEMP/REL)
     A            S01APKSIN R        O  4 57REFFLD(QWHFDACP/APKSIN QTEMP/REL)
     A            S01APKEYF R        O  4 61REFFLD(QWHFDACP/APKEYF QTEMP/REL)
     A          R C01                       SFLCTL(S01)
     A*%%TS  SD  
     A                                      SFLSIZ(0019)
     A                                      SFLPAG(0018)
     A                                      OVERLAY
     A  50                                  SFLEND
     A  51                                  SFLDSP
     A  52                                  SFLDSPCTL
     A  53                                  SFLCLR
     A            SRS01          4S 0H      SFLRCDNBR(CURSOR)
     A*
     A                                  1 18'FILE RELATIONS for '
     A            C01APBOF  R        O  1 39REFFLD(QWHFDACP/APBOF QTEMP/REL)
     A                                  1 51'Lib.'
     A            C01APBOL  R        O  1 56REFFLD(QWHFDACP/APBOL QTEMP/REL)
     A                                  2 32'Uni SEL         LIFO ASC Key'
     A                                  3  6'File       Library    Acc Key OMT -
     A                                      TYP  J  FIFO DSC Sgn Key'
     A          R R01
     A                                 24  3'F3-Exit'
     A                                 22  3'R - Display Select/Omit rules'
     A                                 23  3'X - Select for display'
      *
     A          R R02
     A                                 24  3'F3-Exit'
     A          R S02                       SFL
     A                                      SFLNXTCHG
     A            S02SOFLD  R        O  4  4REFFLD(QWHFDSO/SOFLD QTEMP/SEL)
     A            S02SORULE R        O  4 17REFFLD(QWHFDSO/SORULE QTEMP/SEL)
     A            S02SOCOMP R        O  4 22REFFLD(QWHFDSO/SOCOMP QTEMP/SEL)
     A            S02SOVALU R        O  4 28REFFLD(QWHFDSO/SOVALU QTEMP/SEL)

     A          R C02                       SFLCTL(S02 )
     A                                      OVERLAY
     A  50                                  SFLEND
     A  51                                  SFLDSP
     A  52                                  SFLDSPCTL
     A  53                                  SFLCLR
     A                                      SFLSIZ(0019)
     A                                      SFLPAG(0018)
     A            SRS02          4S 0H      SFLRCDNBR(CURSOR)
     A*
     A                                  1  6'FILE SELECTS   for '
     A            C02APFILE R        O  2  7REFFLD(QWHFDSO/SOFILE QTEMP/SEL)
     A                                  2 20'Lib.'
     A            C02APLIB  R        O  2 25REFFLD(QWHFDSO/SOLIB QTEMP/SEL)
     A                                  3  4'Field'
     A                                  3 28'Select/Omit Value'
     A                                  3 16'S/O'
     A                                  3 21'COMP'






#top