/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        T E S T   D E S   F O N C T I O N S   D E   G E S T I O N   D E S                                                          */
/*        " E X P R E S S I O N S "   R E G U L I E R E S   ( A   L A   ' sed ' )                                                    */
/*        A V E C   U T I L I S A T I O N   D ' I N D E X                                                                            */
/*        E T   T E S T   D E S   M A J U S C U L E S / M I N U S C U L E S                                                          */
/*        E T   T E S T   D E S   S O U S - E X P R E S S I O N S   P O U R   ' SYSTEME_APC_LinuxRedHat_GCC '  :                     */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xtc/regul_exp.31$c' :                                                                                          */
/*                                                                                                                                   */
/*                    Jean-Francois Colonna (LACTAMME, AAAAMMJJhhmmss).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

extern    void      *malloc();

#include  <stdio.h>

#include  <regex.h>

#define   LONGUEUR                                                                                                                      \
                    10000

main()
          {
          char      *expression_reguliere="O";
                                        /* Avec "\n" il y a un "vrai new-line" mis dans la chaine et alors reconnu comme tel         */
                                        /* ensuite, alors que "\\n" qui devrait mettre les 2 caracteres "\" et "n" n'est pas         */
                                        /* reconnu ensuite comme un "new-line"...                                                    */
          char      *chaineA="NOUS partimes 500 mais par un prompt renfort,\nn\nous nous vimes 3000 en arrivant au PORT";
          char      *sous_chaineA;
          int       indexA;
          char      *chaineR;
          int       indexR;

          char      *chaineS="+";

          regex_t   expression_compilee;

          int       iterer=0;

          printf("\n expression reguliere=\n%s",expression_reguliere);

          chaineR=malloc(2*strlen(chaineA));

          if        (regcomp(&expression_compilee,expression_reguliere,REG_EXTENDED) != 0)
                    {
                    printf("\n probleme dans la compilation de l'expression reguliere");
                    }
          else
                    {
                    }

          printf("\n nombre de sous-expressions=%d",expression_compilee.re_nsub);

          sous_chaineA=chaineA;
          indexA=0;
          indexR=0;

          while     (iterer == 0)
                    {
#define   NMATCH    10
#define   DEB(n)    (sous_chaineA + (pmatch[n].rm_so))
#define   FIN(n)    (sous_chaineA + (pmatch[n].rm_eo))
#define   loc1      DEB(0)
#define   loc2      FIN(0)
                    int                 nmatch=NMATCH;
                    regmatch_t          pmatch[NMATCH];

                    if        (regexec(&expression_compilee,sous_chaineA,nmatch,pmatch,RE_SYNTAX_SED) == 0)
                              {
                              int       indexS=0;
                              int       NSousExp=0;

                              for       (NSousExp=1 ; NSousExp<=expression_compilee.re_nsub ; NSousExp++)
                                        {
                                        char      *SousExp;
                                        printf("\n sous-expression(%d)=",NSousExp);
                                        for       (SousExp=DEB(NSousExp) ; SousExp<FIN(NSousExp) ; SousExp++)
                                                  {
                                                  printf("%c",*SousExp);
                                                  }
                                        }

                              for       (indexA=indexA ; indexA<(loc1-chaineA) ; indexA++)
                                        {
                                        *(chaineR+indexR) = *(chaineA+indexA);
                                        indexR++;
                                        }

                              for       (indexS=indexS ; indexS<strlen(chaineS) ; indexS++)
                                        {
                                        *(chaineR+indexR) = *(chaineS+indexS);
                                        indexR++;
                                        }

                              sous_chaineA=loc2;

                              indexA=sous_chaineA-chaineA;
                              }
                    else
                              {
                              iterer++;
                              }
                    }

          regfree(&expression_compilee);

          for       (indexA=indexA ; indexA<strlen(chaineA) ; indexA++)
                    {
                    *(chaineR+indexR) = *(chaineA+indexA);
                    indexR++;
                    }

          *(chaineR+indexR) = 0;

          printf("\n chaineA=\n%s",chaineA);
          printf("\n chaineR=\n%s",chaineR);
          printf("\n");
          }



Copyright © Jean-François Colonna, 2021-2023.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / École polytechnique, Institut Polytechnique de Paris, 2021-2023.