home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / parsepatternnocase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  5.1 KB  |  198 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: parsepatternnocase.c,v 1.4 1997/01/27 00:36:27 ldp Exp $
  4.     $Log: parsepatternnocase.c,v $
  5.     Revision 1.4  1997/01/27 00:36:27  ldp
  6.     Polish
  7.  
  8.     Revision 1.3  1996/12/09 13:53:37  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.2  1996/10/24 15:50:34  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.1  1996/09/11 12:54:46  digulla
  17.     A couple of new DOS functions from M. Fleischer
  18.  
  19.     Desc:
  20.     Lang: english
  21. */
  22. #include <proto/exec.h>
  23. #include <proto/utility.h>
  24. #include <dos/dos.h>
  25. #include <dos/dosasl.h>
  26. #include "dos_intern.h"
  27.  
  28. /*****************************************************************************
  29.  
  30.     NAME */
  31. #include <proto/dos.h>
  32.  
  33.     AROS_LH3(LONG, ParsePatternNoCase,
  34.  
  35. /*  SYNOPSIS */
  36.     AROS_LHA(STRPTR, Source,      D1),
  37.     AROS_LHA(STRPTR, Dest,        D2),
  38.     AROS_LHA(LONG,   DestLength,  D3),
  39.  
  40. /*  LOCATION */
  41.     struct DosLibrary *, DOSBase, 161, Dos)
  42.  
  43. /*  FUNCTION
  44.     Similar to ParsePattern(), only case insensitive (see there
  45.     for more information). For use with MatchPatternNoCase().
  46.  
  47.     INPUTS
  48.  
  49.     RESULT
  50.  
  51.     NOTES
  52.  
  53.     EXAMPLE
  54.  
  55.     BUGS
  56.  
  57.     SEE ALSO
  58.     ParsePattern(), MatchPatternNoCase().
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.     29-10-95    digulla automatically created from
  64.                 dos_lib.fd and clib/dos_protos.h
  65.  
  66. *****************************************************************************/
  67. {
  68.     AROS_LIBFUNC_INIT
  69.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  70.     STRPTR stack, end;
  71.     UBYTE a, b, t;
  72.     LONG iswild=0;
  73.  
  74.     LONG *result=&((struct Process *)FindTask(NULL))->pr_Result2;
  75. #define ERROR(a) { *result=a; return -1; }
  76.     stack=end=Dest+DestLength;
  77. #define PUT(a) { if(Dest>=stack) ERROR(ERROR_BUFFER_OVERFLOW); *Dest++=(a); }
  78.     
  79.     if(!*Source)
  80.     {
  81.         PUT(0);
  82.         return 0;
  83.     }else
  84.         PUT(MP_OR);
  85.  
  86.     while(*Source)
  87.     {
  88.         switch(*Source++)
  89.         {
  90.             case '#':
  91.                 iswild=1;
  92.                 if(*Source=='?')
  93.                 {
  94.                     Source++;
  95.                     PUT(MP_ALL);
  96.                 }else
  97.                 {
  98.                     PUT(MP_MULT);
  99.                     *--stack=MP_MULT_END;
  100.                     continue;
  101.                 }
  102.                 break;
  103.             case '~':
  104.                 iswild=1;
  105.                 PUT(MP_NOT);
  106.                 *--stack=MP_NOT_END;
  107.                 continue;
  108.             case '?':
  109.                 iswild=1;
  110.                 PUT(MP_SINGLE);
  111.                 break;
  112.             case '(':
  113.                 PUT(MP_OR);
  114.                 *--stack=MP_OR_END;
  115.                 continue;
  116.             case '|':
  117.                 iswild=1;
  118.                 if(stack!=end&&*stack!=MP_OR_END)
  119.                     ERROR(ERROR_BAD_TEMPLATE);
  120.                 PUT(MP_OR_NEXT);
  121.                 break;
  122.             case ')':
  123.                 if(stack==end||*stack!=MP_OR_END)
  124.                     ERROR(ERROR_BAD_TEMPLATE);
  125.                 PUT(*stack++);
  126.                 break;
  127.             case '[':
  128.                 if(*Source=='~')
  129.                 {
  130.                     Source++;
  131.                     PUT(MP_NOT_SET);
  132.                 }else
  133.                     PUT(MP_SET);
  134.                 a=*Source++;
  135.                 if(!a)
  136.                     ERROR(ERROR_BAD_TEMPLATE);
  137.                 do
  138.                 {
  139.                     if(Source[0]=='-'&&Source[1]!=']')
  140.                     {
  141.                         Source++;
  142.                         b=*Source++;
  143.                         if(!b)
  144.                             ERROR(ERROR_BAD_TEMPLATE);
  145.                         if(b>a)
  146.                             t=a, a=b, b=t;
  147.                         PUT(MP_DASH);
  148.                         if(b>=0x81&&b<=0x8e)
  149.                         {
  150.                             PUT(MP_ESCAPE);
  151.                             b-=0x80;
  152.                         }
  153.                         PUT(ToLower(b));
  154.                     }
  155.                     if(a>=0x81&&a<=0x8e)
  156.                     {
  157.                         PUT(MP_ESCAPE);
  158.                         a-=0x80;
  159.                     }
  160.                     PUT(ToLower(a));
  161.                     a=*Source++;
  162.                     if(!a)
  163.                         ERROR(ERROR_BAD_TEMPLATE);
  164.                 }while(a!=']');
  165.                 PUT(MP_SET_END);
  166.                 break;
  167.             case '*':
  168.                 if(DOSBase->dl_Flags&RNF_WILDSTAR)
  169.                 {
  170.                     PUT(MP_ALL);
  171.                 }else
  172.                     PUT('*');
  173.                 break;
  174.             case '\'':
  175.                 if(!*Source++)
  176.                     ERROR(ERROR_BAD_TEMPLATE);
  177.                 /* Fall through */
  178.             default:
  179.                 a=Source[-1];
  180.                 if(a>=0x81&&a<=0x8e)
  181.                 {
  182.                     PUT(MP_ESCAPE);
  183.                     a-=0x80;
  184.                 }
  185.                 PUT(ToLower(a));
  186.                 break;
  187.         }
  188.         while(stack!=end&&*stack!=MP_OR_END)
  189.             PUT(*stack++);
  190.     }
  191.     if(stack!=end)
  192.         ERROR(ERROR_BAD_TEMPLATE);
  193.     PUT(MP_OR_END);
  194.     PUT(0);
  195.     return iswild;
  196.     AROS_LIBFUNC_EXIT
  197. } /* ParsePatternNoCase */
  198.