home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / parsepatternnocase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  4.9 KB  |  190 lines

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