unzip-6.0-caseinsensitive.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. diff --git a/match.c b/match.c
  2. index 6cd656f..4e569f5 100644
  3. --- a/match.c
  4. +++ b/match.c
  5. @@ -190,10 +190,10 @@ char *___tmp_ptr;
  6. #endif
  7. -static int recmatch(p, s, cs)
  8. +static int recmatch(p, s, ci)
  9. ZCONST char *p; /* sh pattern to match */
  10. ZCONST char *s; /* string to match it to */
  11. -int cs; /* flag: force case-sensitive matching */
  12. +int ci; /* flag: force case-insensitive matching */
  13. /* Recursively compare the sh pattern p with the string s and return 1 if
  14. they match, and 0 or 2 if they don't or if there is a syntax error in the
  15. pattern. This routine recurses on itself no deeper than the number of
  16. @@ -214,7 +214,7 @@ int cs; /* flag: force case-sensitive matching */
  17. if (CLEN(p) == 2) {
  18. if (CLEN(s) == 2) {
  19. return (*p == *s && *(p+1) == *(s+1)) ?
  20. - recmatch(p + 2, s + 2, cs) : 0;
  21. + recmatch(p + 2, s + 2, ci) : 0;
  22. } else {
  23. return 0;
  24. }
  25. @@ -230,9 +230,9 @@ int cs; /* flag: force case-sensitive matching */
  26. /* '?' (or '%' or '#') matches any character (but not an empty string) */
  27. if (c == WILDCHR_SINGLE) {
  28. if (wild_stop_at_dir)
  29. - return (*s && *s != DIRSEP_CHR) ? recmatch(p, s + CLEN(s), cs) : 0;
  30. + return (*s && *s != DIRSEP_CHR) ? recmatch(p, s + CLEN(s), ci) : 0;
  31. else
  32. - return *s ? recmatch(p, s + CLEN(s), cs) : 0;
  33. + return *s ? recmatch(p, s + CLEN(s), ci) : 0;
  34. }
  35. /* WILDCHR_MULTI ('*') matches any number of characters, including zero */
  36. @@ -253,14 +253,14 @@ int cs; /* flag: force case-sensitive matching */
  37. # endif /* ?AMIGA */
  38. /* Single WILDCHR_MULTI ('*'): this doesn't match slashes */
  39. for (; *s && *s != DIRSEP_CHR; INCSTR(s))
  40. - if ((c = recmatch(p, s, cs)) != 0)
  41. + if ((c = recmatch(p, s, ci)) != 0)
  42. return c;
  43. /* end of pattern: matched if at end of string, else continue */
  44. if (*p == 0)
  45. return (*s == 0);
  46. /* continue to match if at DIRSEP_CHR in pattern, else give up */
  47. return (*p == DIRSEP_CHR || (*p == '\\' && p[1] == DIRSEP_CHR))
  48. - ? recmatch(p, s, cs) : 2;
  49. + ? recmatch(p, s, ci) : 2;
  50. }
  51. /* Two consecutive WILDCHR_MULTI ("**"): this matches DIRSEP_CHR ('/') */
  52. p++; /* move p past the second WILDCHR_MULTI */
  53. @@ -308,17 +308,17 @@ int cs; /* flag: force case-sensitive matching */
  54. */
  55. if (q != srest)
  56. return 0;
  57. - return ((cs ? strcmp(p, q) : namecmp(p, q)) == 0);
  58. + return ((!ci ? strcmp(p, q) : namecmp(p, q)) == 0);
  59. }
  60. #else /* !_MBCS */
  61. - return ((cs ? strcmp(p, srest) : namecmp(p, srest)) == 0);
  62. + return ((!ci ? strcmp(p, srest) : namecmp(p, srest)) == 0);
  63. #endif /* ?_MBCS */
  64. }
  65. else
  66. {
  67. /* pattern contains more wildcards, continue with recursion... */
  68. for (; *s; INCSTR(s))
  69. - if ((c = recmatch(p, s, cs)) != 0)
  70. + if ((c = recmatch(p, s, ci)) != 0)
  71. return c;
  72. return 2; /* 2 means give up--shmatch will return false */
  73. }
  74. @@ -353,17 +353,17 @@ int cs; /* flag: force case-sensitive matching */
  75. c = *(p-1);
  76. else
  77. {
  78. - uch cc = (cs ? (uch)*s : case_map((uch)*s));
  79. + uch cc = (!ci ? (uch)*s : to_up((uch)*s));
  80. uch uc = (uch) c;
  81. if (*(p+1) != '-')
  82. for (uc = uc ? uc : (uch)*p; uc <= (uch)*p; uc++)
  83. /* compare range */
  84. - if ((cs ? uc : case_map(uc)) == cc)
  85. - return r ? 0 : recmatch(q + CLEN(q), s + CLEN(s), cs);
  86. + if ((!ci ? uc : to_up(uc)) == cc)
  87. + return r ? 0 : recmatch(q + CLEN(q), s + CLEN(s), ci);
  88. c = e = 0; /* clear range, escape flags */
  89. }
  90. }
  91. - return r ? recmatch(q + CLEN(q), s + CLEN(s), cs) : 0;
  92. + return r ? recmatch(q + CLEN(q), s + CLEN(s), ci) : 0;
  93. /* bracket match failed */
  94. }
  95. #endif /* !VMS */
  96. @@ -382,18 +382,18 @@ int cs; /* flag: force case-sensitive matching */
  97. {
  98. /* Match "...]" with "]". Continue after "]" in both. */
  99. if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
  100. - return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
  101. + return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), ci);
  102. /* Else, look for a reduced match in s, until "]" in or end of s. */
  103. for (; *s && (*s != ']'); INCSTR(s))
  104. if (*s == '.')
  105. /* If reduced match, then continue after "..." in p, "." in s. */
  106. - if ((c = recmatch( (p+ CLEN( p)), s, cs)) != 0)
  107. + if ((c = recmatch( (p+ CLEN( p)), s, ci)) != 0)
  108. return (int)c;
  109. /* Match "...]" with "]". Continue after "]" in both. */
  110. if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
  111. - return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
  112. + return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), ci);
  113. /* No reduced match. Quit. */
  114. return 2;
  115. @@ -402,8 +402,8 @@ int cs; /* flag: force case-sensitive matching */
  116. #endif /* def VMS */
  117. /* Just a character--compare it */
  118. - return (cs ? c == *s : case_map((uch)c) == case_map((uch)*s)) ?
  119. - recmatch(p, s + CLEN(s), cs) : 0;
  120. + return (!ci ? c == *s : to_up((uch)c) == to_up((uch)*s)) ?
  121. + recmatch(p, s + CLEN(s), ci) : 0;
  122. }