/*------------------------------------------------------------------*/
/*    Programmers Group & Management Resource    Copyright  1997    */
/*                                                                  */
/*                             \\\\\\\                              */
/*                            ( o   o )                             */
/*------------------------oOO----(_)----OOo-------------------------*/
/*                                                                  */
/*  System name  . . . :   PGMR Tool                                */
/*  Program name . . . :   UPDRPGVCP                                */
/*  Text . . . . . . . :   Validity checking program for UPDRPGSRC  */
/*                                                                  */
/*  Author . . . . . . :   Alexander Nubla                          */
/*  Creation date. . . :   11/25/97                                 */
/*  Description. . . . :   This program validates the source file   */
/*                         and member requested by the user.        */
/*                                                                  */
/*                         Do the following first:                  */
/*                                                                  */
/*                         Crtmsgf   Yourlib/PGMRMSG                */
/*                                                                  */
/*                         Addmsgd   msgid(PGM9898) +               */
/*                                   msgf(Yourlib/PGMRMSG) +        */
/*                                   msg('&2') +                    */
/*                                   seclvl('&3') +                 */
/*                                   sev(40) +                      */
/*                                   fmt((*char 4) (*char 100) +    */
/*                                       (*char 512))               */
/*                                                                  */
/*                     ooooO              Ooooo                     */
/*                     (    )             (    )                    */
/*----------------------(   )-------------(   )---------------------*/
/*                       (_)               (_)                      */
/*                                                                  */
/*  Modification Log:                                               */
/*                                                                  */
/*  Date     Task  Programmer/Description                           */
/*  -------- ----- ------------------------------------------------ */
/*  11/25/97       Alex Nubla                                       */
/*                 Created                                          */
/*                                                                  */
/*------------------------------------------------------------------*/
             pgm        (&FullSrc      /* Source file & Library */   +
                         &SrcMbr       /* Source Member         */   +
                         &SrcSeq       /* Source Seq Option     */   +
                         &IncSeq)      /* Increment Seq Number  */

/*--------------------------------------------------------*/
/*  declaration                                           */
/*--------------------------------------------------------*/
             dcl        &FullSrc   *char   20
             dcl        &SrcMbr    *char   10
             dcl        &SrcSeq    *char    7
             dcl        &IncSeq    *dec   ( 3 2)

             dcl        &Src       *char   10
             dcl        &SrcLib    *char   10
             dcl        &SrcTyp    *char   10
             dcl        &lib       *char   10
             dcl        &Msg1      *char  100
             dcl        &Msg2      *char  512

             dcl        &Err1      *char  100  +
                        value('The UPDRPGSRC utility can only be used +
                        for ILE RPG/400 source code')
             dcl        &Err2      *char  512  +
                        value('The UPDRPGSRC utility can only be used +
                        for ILE RPG/400 source code. The valid source +
                        member types of source members to be +
                        converted are RPGLE and SQLRPGLE. The +
                        Update RPG ILE Source command does not +
                        support source member types RPG, RPG36, RPG38 +
                        and other non-RPG source member types (for +
                        example, CLP and TXT)')

             dcl        &error     *lgl                   /* std err */
             dcl        &msgid     *char    7             /* std err */
             dcl        &msgkey    *char    4             /* std err */
             dcl        &msgdta    *char  100             /* std err */
             dcl        &msgf      *char   10             /* std err */
             dcl        &msgflib   *char   10             /* std err */
             dcl        &msgtyp    *char   10  '*DIAG'    /* std err */
             dcl        &msgtypctr *char    4 X'00000001' /* std err */
             dcl        &pgmmsgq   *char   10  '*'        /* std err */
             dcl        &stkctr    *char    4 X'00000001' /* std err */
             dcl        &errbytes  *char    4 X'00000000' /* std err */

             monmsg     msgid(cpf0000) exec(goto error)

/*--------------------------------------------------------*/
/*  Check for the message file                            */
/*--------------------------------------------------------*/
             rtvobjd    obj(*libl/UPDRPGSRC) +
                        objtype(*cmd)       +
                        rtnlib(&lib)
 chkmsgf:
             chkobj     obj(&lib/PGMRMSG)   +
                        objtype(*msgf)
             monmsg     cpf9801    exec(do)
               Crtmsgf   &lib/PGMRMSG       +
                         text('Message File from PGMR, Inc.')
               Addmsgd   msgid(PGM9898)     +
                         msgf(&lib/PGMRMSG) +
                         msg('&2')          +
                         seclvl('&3')       +
                         sev(40)            +
                         fmt((*char 4) (*char 100) +
                             (*char 512))
             enddo

/*--------------------------------------------------------*/
/*  Validate source file                                  */
/*--------------------------------------------------------*/
chksrcfile:
             chgvar     &Src       %sst(&FullSrc   1  10)
             chgvar     &SrcLib    %sst(&FullSrc  11  10)
             chkobj     obj(&SrcLib/&Src)   +
                        objtype(*file)
          /*----------------------------------------------*/
          /*  Source file not found                       */
          /*----------------------------------------------*/
             monmsg   cpf9801      exec(do)
               RcvMsg     msgtype(*last)    +
                          msg(&msg1)        +
                          seclvl(&msg2)
               sndpgmmsg  msgid(PGM9898)    +
                          msgf(PGMRMSG)     +
                          msgdta('0000'     +
                              |< &msg1      +
                              || &msg2)     +
                          msgtype(*diag)
               sndpgmmsg  msgid(cpf0002)    +
                          msgf(qcpfmsg)     +
                          msgtype(*escape)
             enddo

/*--------------------------------------------------------*/
/*  Validate source type                                  */
/*--------------------------------------------------------*/
             If         (&SrcMbr = '*ALL')  then(goto End)
 chksrctype:
             rtvmbrd    file(&SrcLib/&Src)  +
                        mbr(&SrcMbr)        +
                        srctype(&SrcTyp)
             If         (&SrcTyp *ne 'SQLRPGLE'  *and +
                         &SrcTyp *ne 'RPGLE')    then(do)
               sndpgmmsg  msgid(PGM9898)         +
                          msgf(PGMRMSG)          +
                          msgdta('0000'          +
                              |< &err1           +
                              || &err2)          +
                          msgtype(*diag)
               sndpgmmsg  msgid(cpf0002)         +
                          msgf(qcpfmsg)          +
                          msgtype(*escape)
             enddo

             Goto       End

/*--------------------------------------------------------*/
/*  error routine:                                        */
/*--------------------------------------------------------*/
 error:
             if         &error     (goto errordone)
               else      chgvar       &error  '1'
          /*----------------------------------------------*/
          /*  move all *DIAG message to *PRV program queue*/
          /*----------------------------------------------*/
             call       QMHMOVPM   (&msgkey      +
                                    &msgtyp      +
                                    &msgtypctr   +
                                    &pgmmsgq     +
                                    &stkctr      +
                                    &errbytes)
          /*----------------------------------------------*/
          /*  resend the last *ESCAPE message             */
          /*----------------------------------------------*/
 errordone:
             call       QMHRSNEM   (&msgkey      +
                                    &errbytes)
             monmsg     cpf0000    exec(do)
               sndpgmmsg  msgid(cpf3cf2) msgf(QCFPMSG) +
                            msgdta('QMHRSNEM') msgtype(*escape)
               monmsg     cpf0000
             enddo
 end:        endpgm
