home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / ygrep403.zip / DOS.C < prev    next >
C/C++ Source or Header  |  1995-08-09  |  8KB  |  212 lines

  1. #if    !defined( lint )
  2. static    char *sccsid =
  3.     "$Id: DOS.C 1.5 1995/04/24 05:12:36 Y.Roumazeilles Exp $";
  4. #endif
  5. #pragma    warning(disable:4001)
  6.  
  7. /*
  8. //   Test program for DOS libs
  9. //
  10. //   Just compile it with the appropriate model (corresponding to the one
  11. //   used by the library you selected:
  12. //    SYGREP.LIB (Microsoft) and SYGREPB.LIB (Borland) are Small model;
  13. //    CYGREP.LIB (Microsoft) and CYGREPB.LIB (Borland) are Compact model;
  14. //    MYGREP.LIB (Microsoft) and MYGREPB.LIB (Borland) are Medium model;
  15. //    LYGREP.LIB (Microsoft) and LYGREPB.LIB (Borland) are Large model;
  16. //    HYGREP.LIB (Microsoft) is Huge model.
  17. //
  18. //   (C) 1992-93-94-95 Yves Roumazeilles
  19. */
  20.  
  21. #define    STRICT    
  22. #include    <windows2.h>
  23. #include    <stdio.h>
  24. #include    <malloc.h>
  25. #include    "ygrep.h"
  26.  
  27.  
  28. #define    CHECK(a,b,s)    if((a)!=(b)) {fprintf(stderr,"\n---"s"->(%d)\n",(a));return(-1);} else{fprintf(stderr,".");}
  29.  
  30.  
  31.  
  32. LPCSTR    test[] = {
  33.     /*0*/    "include",
  34.     /*1*/    "includi",
  35.     /*2*/    "includeINCLUDE",
  36.     /*3*/    "toto",
  37.     /*4*/    "tototo",
  38.     /*5*/    "totototo",
  39.     /* */    "" };
  40.  
  41.  
  42. main()
  43. {
  44.     int        iVal;
  45. /*    AGREPINFO    aGI;    */
  46.     LPAGREPINFO    pGI;
  47.     LPRGREPINFO    pRGI;
  48.     char*        pTemp;
  49.     char*        pSubs = "012345678901234567890123456789";
  50.     char*        pDest = "012345678901234567890123456789";
  51.  
  52.     printf("*** YGrep Search Engine diags level 1/2/3 ***\n\n");
  53.     printf("YGrepVersion: 0x%04x\n", YGrepVersion());
  54.     printf("Starting!\n");
  55.  
  56.     pGI = (LPAGREPINFO)calloc(1, sizeof(AGREPINFO));
  57. /*    pGI = &aGI;    */
  58.  
  59.     /* Level 1 */
  60.     /***********/
  61.     CHECK( AGrepInit(pGI), TRUE, "init" );
  62.     
  63.     // k=0 mismatch...
  64.     CHECK( CompileAGrep((LPCSTR)test[1], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp0" );
  65.     // ...0 matche(s)
  66.     CHECK( AGrep((LPCSTR)test[2], pGI), 0, "ag0" );
  67.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  68.  
  69.     // k=1 mismatch...
  70.     CHECK( CompileAGrep((LPCSTR)test[1], 1, TRUE,  pGI), AGERR_NO_ERROR, "cmp1" );
  71.     // ...1 matche(s)
  72.     CHECK( AGrep((LPCSTR)test[2], pGI), 1, "ag1" );
  73.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  74.  
  75.     // k=1 mismatch, but no case...
  76.     CHECK( CompileAGrep((LPCSTR)test[1], 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  77.     // ...2 matche(s)
  78.     CHECK( AGrep((LPCSTR)test[2], pGI), 2, "ag2" );
  79.     CHECK( AGrepSubsBuild("-&-", pSubs, 30, pGI), AGERR_NO_ERROR, "su0" );
  80.     CHECK( strcmp(pSubs,"-include-"), 0, "su1" );
  81.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  82.  
  83.     // ElectUnltd bug?
  84.     CHECK( CompileAGrep((LPCSTR)"Bob", 5, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  85.     //fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben", pGI) );
  86.     //fprintf( stderr, "%3d", AGrep((LPCSTR)test[2], pGI) );
  87.     //fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben τa alors, tiens !", pGI) );
  88.     CHECK( AGrep((LPCSTR)"Ben", pGI), 3, "eu1" );
  89.     CHECK( AGrep((LPCSTR)test[2], pGI), 14, "eu2" );
  90.     CHECK( AGrep((LPCSTR)"Ben τa alors, tiens !", pGI), 21, "eu3" );
  91. #define    LONGUEUR    2300
  92.     pTemp = (char*)calloc(LONGUEUR,sizeof(char));
  93.     if( pTemp==NULL )
  94.         fprintf(stderr, "!");
  95.     else {
  96.         for( iVal=0; iVal<LONGUEUR-1; iVal++ )
  97.             pTemp[iVal] = '!';
  98.         pTemp[LONGUEUR-1]='\0';
  99.         /*fprintf(stderr,"*");*/
  100.         CHECK( AGrep((LPCSTR)pTemp, pGI), (int)strlen(pTemp), "eu4" );
  101.     }
  102.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  103.  
  104.     CHECK( CompileAGrep((LPCSTR)"Bob", 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  105.     CHECK( AGrep((LPCSTR)pTemp, pGI), 0, "eu5" );
  106.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  107.     free(pTemp);
  108.  
  109.     // January bug check
  110.     CHECK( CompileAGrep((LPCSTR)test[3], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp3" );
  111.     CHECK( AGrep((LPCSTR)test[4], pGI), 2, "to1" );
  112.     CHECK( AGrep((LPCSTR)test[5], pGI), 3, "to2" );
  113.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  114.     CHECK( CompileAGrep((LPCSTR)test[4], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp4" );
  115.     CHECK( AGrep((LPCSTR)test[5], pGI), 2, "to3" );
  116.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  117.  
  118.     // Feb AEK.XL bug check
  119.     CHECK( CompileAGrep((LPCSTR)test[0], 0, FALSE, pGI), AGERR_NO_ERROR, "cmp5" );
  120.     CHECK( AGrep((LPCSTR)test[2], pGI), 2, "axl1" );
  121.  
  122.     free(pGI);
  123.  
  124.     /* Level 2 */
  125.     /***********/
  126.     CHECK( SAGrepInit(), TRUE, "s1" );
  127.     CHECK( SCompileAGrep((LPCSTR)test[1], 0, TRUE), AGERR_NO_ERROR, "s2" );
  128.     CHECK( SAGrep((LPCSTR)test[2]), 0, "s3" );
  129.     CHECK( SAGrepEmpty(), TRUE, "s4" );
  130.     CHECK( SCompileAGrep((LPCSTR)test[1], 1, TRUE), AGERR_NO_ERROR, "s5" );
  131.     CHECK( SAGrep((LPCSTR)test[2]), 1, "s6" );
  132.     CHECK( SAGrepEmpty(), TRUE, "s7" );
  133.     CHECK( SCompileAGrep((LPCSTR)test[1], 1, FALSE), AGERR_NO_ERROR, "s8" );
  134.     CHECK( SAGrep((LPCSTR)test[2]), 2, "s9" );
  135.     CHECK( SAGrepSubsBuild("-&-", pSubs, 30), AGERR_NO_ERROR, "s10" );
  136.     CHECK( strcmp(pSubs,"-include-"), 0, "s11" );
  137.     CHECK( SAGrepEmpty(), TRUE, "s12" );
  138.     CHECK( SCompileAGrep((LPCSTR)"Bob", 5, FALSE), AGERR_NO_ERROR, "s13" );
  139.     CHECK( SAGrep((LPCSTR)"Ben"), 3, "s14" );
  140.     CHECK( SAGrep((LPCSTR)test[2]), 14, "s15" );
  141.     CHECK( SAGrep((LPCSTR)"Ben τa alors, tiens !"), 21, "s16" );
  142. #define    LONGUEUR    2300
  143.     pTemp = (char*)calloc(LONGUEUR,sizeof(char));
  144.     if( pTemp==NULL )
  145.         fprintf(stderr, "!");
  146.     else {
  147.         for( iVal=0; iVal<LONGUEUR-1; iVal++ )
  148.             pTemp[iVal] = '!';
  149.         pTemp[LONGUEUR-1]='\0';
  150.         /*fprintf(stderr,"*");*/
  151.         CHECK( SAGrep((LPCSTR)pTemp), (int)strlen(pTemp), "s17" );
  152.     }
  153.     CHECK( SAGrepEmpty(), TRUE, "s18" );
  154.     CHECK( SCompileAGrep((LPCSTR)"Bob", 1, FALSE), AGERR_NO_ERROR, "s19" );
  155.     CHECK( SAGrep((LPCSTR)pTemp), 0, "s20" );
  156.     CHECK( SAGrepEmpty(), TRUE, "s21" );
  157.     free(pTemp);
  158.     CHECK( SCompileAGrep((LPCSTR)test[3], 0, TRUE), AGERR_NO_ERROR, "s22" );
  159.     CHECK( SAGrep((LPCSTR)test[4]), 2, "s23" );
  160.     CHECK( SAGrep((LPCSTR)test[5]), 3, "s24" );
  161.     CHECK( SAGrepEmpty(), TRUE, "s25" );
  162.     CHECK( SCompileAGrep((LPCSTR)test[4], 0, TRUE), AGERR_NO_ERROR, "s26" );
  163.     CHECK( SAGrep((LPCSTR)test[5]), 2, "s27" );
  164.     CHECK( SAGrepEmpty(), TRUE, "s28" );
  165.  
  166.     /* Level 3 */
  167.     /***********/
  168.     pRGI = (LPRGREPINFO)calloc(1, sizeof(RGREPINFO));
  169.     CHECK( CompileRGrep((LPCSTR)"i\\(n[Cc][Ll]+\\)u", TRUE, pRGI), AGERR_NO_ERROR, "rcp0" );
  170.     CHECK( RGrep((LPCSTR)test[1], pRGI), 1, "rg0" );
  171.     CHECK( CompileRGrep((LPCSTR)"inclu", FALSE, pRGI), AGERR_NO_ERROR, "rcp1" );
  172.     CHECK( RGrep((LPCSTR)test[2], pRGI), 1, "rg1" );
  173.     CHECK( CompileRGrep((LPCSTR)test[4], FALSE, pRGI), AGERR_NO_ERROR, "rcp2" );
  174.     CHECK( RGrep((LPCSTR)test[2], pRGI), 0, "rg2" );
  175.     free(pRGI);
  176.  
  177.     
  178.     printf("\nEnding!\n");
  179.     return 0;
  180. }
  181.  
  182.  
  183. /*
  184. //    Some comments. Without any order...
  185. */
  186.  
  187. /*
  188. //    Nobody ever reads what is in the sample source code. However, you
  189. //    will be able to know why there is no AGREPINFO variable built in
  190. //    an automatic variable inside main(). It would have been nice and
  191. //    simpler than allocating it from the heap with calloc(). Well...
  192. //    Yes but there is quite a problem with large data structures like
  193. //    this one when they are built from the stack. E.g. with Borland C++
  194. //    v4.0, you would have to increase manually the stack for the simplest
  195. //    program - like this one - to operate smoothly.
  196. //    In the original version, I was building an AGREPINFO aGI variable
  197. //    as an automatic variable (it may still be present as a code comment),
  198. //    but this had a too large impact on code and data size for some of the
  199. //    memory models. See below.
  200. */
  201.  
  202. /*
  203. //    You must also remember that the YGrep Search Engine is a rather large
  204. //    set of routines and data. For real world applications it is highly
  205. //    improbable that you will be able to use the Small or Compact memory
  206. //    models. The data segment is too small for that.
  207. //    This size limitation can also appear when compiling applications with
  208. //    full debug information. E.g. Borland C++ 4.0 insisted on producing a
  209. //    stack overflow on entering main() [before reaching the first C code
  210. //    line.]
  211. */
  212.