Gentoo Archives: gentoo-commits

From: Sven Eden <sven.eden@×××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/ufed:master commit in: /
Date: Mon, 25 Nov 2013 21:43:30
Message-Id: 1385366639.49b8c6c96781d7d70662231b1a699701b3e4be15.yamakuzure@gentoo
1 commit: 49b8c6c96781d7d70662231b1a699701b3e4be15
2 Author: Sven Eden <yamakuzure <AT> gmx <DOT> net>
3 AuthorDate: Mon Nov 25 08:03:59 2013 +0000
4 Commit: Sven Eden <sven.eden <AT> gmx <DOT> de>
5 CommitDate: Mon Nov 25 08:03:59 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=49b8c6c9
7
8 Added error messages and reporting of those if the file parsing failes.
9
10 ---
11 Portage.pm | 13 +++++++------
12 ufed.pl.in | 43 ++++++++++++++++++++++++++++++-------------
13 2 files changed, 37 insertions(+), 19 deletions(-)
14
15 diff --git a/Portage.pm b/Portage.pm
16 index dc7b964..e9edaab 100644
17 --- a/Portage.pm
18 +++ b/Portage.pm
19 @@ -953,14 +953,14 @@ sub _read_sh {
20 for(;;) {
21 /\G$BLANK/gc;
22 last if ((pos || 0) == (length || 0));
23 - /\G$IDENT/gc or die;
24 + /\G$IDENT/gc or die "Empty file detected, no identifier found.";
25 my $name = $1;
26 /\G$BLANK/gc;
27 if($name ne 'source') {
28 - /\G$ASSIG/gc or die;
29 + /\G$ASSIG/gc or die "Bare keyword $name detected.";
30 /\G$BLANK/gc;
31 }
32 - die if pos == length;
33 + pos == length and die "Bumped into unexpected EOF after $name.";
34 my $value = '';
35 for(;;) {
36 if(/\G$UQVAL/gc || /\G$DQVAL/gc) {
37 @@ -989,17 +989,18 @@ sub _read_sh {
38 substr($_, pos, 0) = do {
39 local $/;
40 my $text = <$f>;
41 - die if not defined $text;
42 + defined $text or die "Error parsing $value";
43 $text;
44 };
45 pos = $pos;
46 - close $f or die "Unable to open $value\n$!\n";
47 + close $f or die "Unable to close $value\n$!\n";
48 } else {
49 $env{$name} = $value;
50 }
51 }
52 };
53 - die "Parse error in $fname\n" if $@;
54 + defined($@) and length($@) and
55 + die "Parse error in $fname\n - Error: \"$@\"\n";
56 }
57 _merge_env(\%env);
58 return %env if wantarray;
59
60 diff --git a/ufed.pl.in b/ufed.pl.in
61 index be20b02..37f7957 100644
62 --- a/ufed.pl.in
63 +++ b/ufed.pl.in
64 @@ -213,31 +213,36 @@ sub save_flags {
65 my $line = substr($_, $linestart, pos()-$linestart);
66 $line !~ /[^ \t]/;
67 };
68 - /\G$IDENT/gc or die;
69 + /\G$IDENT/gc or die "No identifier found to start with.";
70 my $name = $1;
71 /\G$BLANK/gc;
72 if($name ne 'source') {
73 - /\G$ASSIG/gc or die;
74 - /\G$BLANK/gc;
75 + /\G$ASSIG/gc or die "Identifier $name without assignement detected.";
76 + /\G$BLANK/gc;
77 } else {
78 $sourcing = 1;
79 }
80 - die if pos == length;
81 + pos == length and die "Bumped into early EOF.";
82 if($name ne 'USE') {
83 - /\G(?:$UQVAL|$SQVAL|$DQVAL)+/gc or die;
84 + /\G(?:$UQVAL|$SQVAL|$DQVAL)+/gc or die "Blank assignement for $name detected.";
85 } else {
86 my $start = pos;
87 - /\G(?:$BNUQV|$SQVAL|$BNDQV)+/gc or die;
88 + m/\G(?:$BNUQV|$SQVAL|$BNDQV)+/gc or die "Empty USE assignement detected.";
89 my $end = pos;
90 +
91 # save whether user uses backslash-newline
92 my $bsnl = defined $1 || defined $2;
93 +
94 # start of the line is one past the last newline; also handles first line
95 my $linestart = 1+rindex $_, "\n", $start-1;
96 +
97 # everything on the current line before the USE flags, plus one for the "
98 my $line = substr($_, $linestart, $start-$linestart).' ';
99 +
100 # only indent if USE starts a line
101 my $blank = $flagatstartofline ? $line : "";
102 $blank =~ s/[^ \t]/ /g;
103 +
104 # word wrap
105 if(@flags != 0) {
106 my $length = 0;
107 @@ -251,10 +256,12 @@ sub save_flags {
108 }
109 }
110 my $blanklength = $blank ne '' ? $length : 0;
111 +
112 # new line, using backslash-newline if the user did that
113 my $nl = ($bsnl ? " \\\n" : "\n").$blank;
114 my $linelength = $bsnl ? 76 : 78;
115 my $flag = $flags[0];
116 +
117 if($blanklength != 0 || length $flag <= $linelength) {
118 $flags = $flag;
119 $length += length $flag;
120 @@ -272,16 +279,22 @@ sub save_flags {
121 }
122 }
123 }
124 +
125 # replace the current USE flags with the modified ones
126 substr($_, $start, $end-$start) = "\"$flags\"";
127 +
128 # and have the next search start after our new flags
129 pos = $start + 2 + length $flags;
130 +
131 # and end this
132 undef $flags;
133 last;
134 }
135 }
136 - if(defined $flags) { # if we didn't replace the flags, tack them after the last #USE= or at the end
137 +
138 + if(defined $flags) {
139 +
140 + # if we didn't replace the flags, tack them after the last #USE= or at the end
141 $flags = '';
142 if(@flags != 0) {
143 $flags = $flags[0];
144 @@ -297,21 +310,23 @@ sub save_flags {
145 }
146 }
147 substr($_, $ucs, $uce-$ucs) = "\nUSE=\"$flags\"\n";
148 - } else { # if we replaced the flags, delete any further overrides
149 + } else {
150 +
151 + # if we replaced the flags, delete any further overrides
152 for(;;) {
153 my $start = pos;
154 /\G$BLANK/gc;
155 last if pos == length;
156 - /\G$IDENT/gc or die;
157 + /\G$IDENT/gc or die "Identifier detection failed.";
158 my $name = $1;
159 /\G$BLANK/gc;
160 if($name ne 'source') {
161 - /\G$ASSIG/gc or die;
162 - /\G$BLANK/gc;
163 + /\G$ASSIG/gc or die "Identifier $name without assignement detected.";
164 + /\G$BLANK/gc;
165 } else {
166 $sourcing = 1;
167 }
168 - /\G(?:$UQVAL|$SQVAL|$DQVAL)+/gc or die;
169 + m/\G(?:$UQVAL|$SQVAL|$DQVAL)+/gc or die "Empty assignement for $name detected.";
170 my $end = pos;
171 if($name eq 'USE') {
172 substr($_, $start, $end-$start) = '';
173 @@ -320,7 +335,9 @@ sub save_flags {
174 }
175 }
176 };
177 - die "Parse error when writing make.conf - did you modify it while ufed was running?\n" if $@;
178 + defined($@) and length($@) and die "\nParse error when writing make.conf"
179 + . " - did you modify it while ufed was running?\n"
180 + . " - Error: \"$@\"\n";
181
182 print STDERR <<EOF if $sourcing;
183 Warning: source command found in $makeconf_name. Flags may