~peter-pearse/ubuntu/natty/dash/prop001

« back to all changes in this revision

Viewing changes to debian/diff/0018--PARSER-Fix-parsing-of-1.diff

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-04-29 10:45:09 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090429104509-awtb7757j3orktqr
Tags: 0.5.5.1-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Make the package both "required" and "Essential" since this is our
    default system shell.
  - Add dependency on debianutils so /etc/shells exists before
    we are configured
  - If the dash/sh question has not been seen by the user, reset it to
    the default which is now true.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From ab72e0678b0febde521c9b828af6b227b4cca3a8 Mon Sep 17 00:00:00 2001
2
 
From: Herbert Xu <herbert@gondor.apana.org.au>
3
 
Date: Thu, 4 Oct 2007 22:15:10 +0800
4
 
Subject: [PATCH] [PARSER] Fix parsing of ${##1}
5
 
 
6
 
Previously dash treated ${##1} as a length operation.  This patch fixes that.
7
 
 
8
 
Test case:
9
 
 
10
 
        set -- a
11
 
        echo ${##1}OK
12
 
 
13
 
Old result:
14
 
 
15
 
        1OK
16
 
 
17
 
New result:
18
 
 
19
 
        OK
20
 
---
21
 
 ChangeLog    |    4 ++++
22
 
 src/parser.c |   31 ++++++++++++++++++++++---------
23
 
 2 files changed, 26 insertions(+), 9 deletions(-)
24
 
 
25
 
diff --git a/ChangeLog b/ChangeLog
26
 
index ac717c5..3352429 100644
27
 
--- a/ChangeLog
28
 
+++ b/ChangeLog
29
 
@@ -1,3 +1,7 @@
30
 
+2007-10-04  Herbert Xu <herbert@gondor.apana.org.au>
31
 
+
32
 
+       * Fix parsing of ${##1}.
33
 
+
34
 
 2007-10-04  Alexey Gladkov <legion@altlinux.org>
35
 
 
36
 
        * Add --enable-static option to configure.
37
 
diff --git a/src/parser.c b/src/parser.c
38
 
index cac0aa5..9edb824 100644
39
 
--- a/src/parser.c
40
 
+++ b/src/parser.c
41
 
@@ -1167,15 +1167,9 @@ parsesub: {
42
 
                subtype = VSNORMAL;
43
 
                if (c == '{') {
44
 
                        c = pgetc();
45
 
-                       if (c == '#') {
46
 
-                               if ((c = pgetc()) == '}')
47
 
-                                       c = '#';
48
 
-                               else
49
 
-                                       subtype = VSLENGTH;
50
 
-                       }
51
 
-                       else
52
 
-                               subtype = 0;
53
 
+                       subtype = 0;
54
 
                }
55
 
+varname:
56
 
                if (c > PEOA && is_name(c)) {
57
 
                        do {
58
 
                                STPUTC(c, out);
59
 
@@ -1188,8 +1182,27 @@ parsesub: {
60
 
                        } while (is_digit(c));
61
 
                }
62
 
                else if (is_special(c)) {
63
 
-                       USTPUTC(c, out);
64
 
+                       int cc = c;
65
 
+
66
 
                        c = pgetc();
67
 
+
68
 
+                       if (!subtype && cc == '#') {
69
 
+                               subtype = VSLENGTH;
70
 
+
71
 
+                               if (c == '_' || isalnum(c))
72
 
+                                       goto varname;
73
 
+
74
 
+                               cc = c;
75
 
+                               c = pgetc();
76
 
+                               if (cc == '}' || c != '}') {
77
 
+                                       pungetc();
78
 
+                                       subtype = 0;
79
 
+                                       c = cc;
80
 
+                                       cc = '#';
81
 
+                               }
82
 
+                       }
83
 
+
84
 
+                       USTPUTC(cc, out);
85
 
                }
86
 
                else
87
 
 badsub:                        synerror("Bad substitution");
88
 
1.5.6.3
89