OpenCoverage

alias.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/alias.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is alias.def, from which is created alias.c-
2It implements the builtins "alias" and "unalias" in Bash.-
3-
4Copyright (C) 1987-2015 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$BUILTIN alias-
22$FUNCTION alias_builtin-
23$DEPENDS_ON ALIAS-
24$PRODUCES alias.c-
25$SHORT_DOC alias [-p] [name[=value] ... ]-
26Define or display aliases.-
27-
28Without arguments, `alias' prints the list of aliases in the reusable-
29form `alias NAME=VALUE' on standard output.-
30-
31Otherwise, an alias is defined for each NAME whose VALUE is given.-
32A trailing space in VALUE causes the next word to be checked for-
33alias substitution when the alias is expanded.-
34-
35Options:-
36 -p print all defined aliases in a reusable format-
37-
38Exit Status:-
39alias returns true unless a NAME is supplied for which no alias has been-
40defined.-
41$END-
42-
43#include <config.h>-
44-
45#if defined (ALIAS)-
46-
47#if defined (HAVE_UNISTD_H)-
48# ifdef _MINIX-
49# include <sys/types.h>-
50# endif-
51# include <unistd.h>-
52#endif-
53-
54# include "../bashansi.h"-
55# include "../bashintl.h"-
56-
57# include <stdio.h>-
58# include "../shell.h"-
59# include "../alias.h"-
60# include "common.h"-
61# include "bashgetopt.h"-
62-
63/* Flags for print_alias */-
64#define AL_REUSABLE 0x01-
65-
66static void print_alias __P((alias_t *, int));-
67-
68/* Hack the alias command in a Korn shell way. */-
69int-
70alias_builtin (list)-
71 WORD_LIST *list;-
72{-
73 int any_failed, offset, pflag, dflags;-
74 alias_t **alias_list, *t;-
75 char *name, *value;-
76-
77 dflags = posixly_correct ? 0 : AL_REUSABLE;
posixly_correctDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 115 times by 1 test
Evaluated by:
  • Self test
2-115
78 pflag = 0;-
79 reset_internal_getopt ();-
80 while ((offset = internal_getopt (list, "p")) != -1)
(offset = inte...t, "p")) != -1Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 112 times by 1 test
Evaluated by:
  • Self test
10-112
81 {-
82 switch (offset)-
83 {-
84 case 'p':
executed 5 times by 1 test: case 'p':
Executed by:
  • Self test
5
85 pflag = 1;-
86 dflags |= AL_REUSABLE;-
87 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
88 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
89 default:
executed 5 times by 1 test: default:
Executed by:
  • Self test
5
90 builtin_usage ();-
91 return (EX_USAGE);
executed 5 times by 1 test: return (258);
Executed by:
  • Self test
5
92 }-
93 }-
94-
95 list = loptend;-
96-
97 if (list == 0 || pflag)
list == 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
pflagDescription
TRUEnever evaluated
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
0-102
98 {-
99 if (aliases == 0)
aliases == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
3-7
100 return (EXECUTION_SUCCESS);
executed 3 times by 1 test: return (0);
Executed by:
  • Self test
3
101-
102 alias_list = all_aliases ();-
103-
104 if (alias_list == 0)
alias_list == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
2-5
105 return (EXECUTION_SUCCESS);
executed 2 times by 1 test: return (0);
Executed by:
  • Self test
2
106-
107 for (offset = 0; alias_list[offset]; offset++)
alias_list[offset]Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-8
108 print_alias (alias_list[offset], dflags);
executed 8 times by 1 test: print_alias (alias_list[offset], dflags);
Executed by:
  • Self test
8
109-
110 free (alias_list); /* XXX - Do not free the strings. */-
111-
112 if (list == 0)
list == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
113 return (sh_chkwrite (EXECUTION_SUCCESS));
executed 5 times by 1 test: return (sh_chkwrite (0));
Executed by:
  • Self test
5
114 }
never executed: end of block
0
115-
116 any_failed = 0;-
117 while (list)
listDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
102
118 {-
119 name = list->word->word;-
120-
121 for (offset = 0; name[offset] && name[offset] != '='; offset++)
name[offset]Description
TRUEevaluated 470 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
name[offset] != '='Description
TRUEevaluated 377 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
9-470
122 ;
executed 377 times by 1 test: ;
Executed by:
  • Self test
377
123-
124 if (offset && name[offset] == '=')
offsetDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
name[offset] == '='Description
TRUEevaluated 93 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-102
125 {-
126 name[offset] = '\0';-
127 value = name + offset + 1;-
128-
129 if (legal_alias_name (name, 0) == 0)
legal_alias_na...(name, 0) == 0Description
TRUEnever evaluated
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
0-93
130 {-
131 builtin_error (_("`%s': invalid alias name"), name);-
132 any_failed++;-
133 }
never executed: end of block
0
134 else-
135 add_alias (name, value);
executed 93 times by 1 test: add_alias (name, value);
Executed by:
  • Self test
93
136 }-
137 else-
138 {-
139 t = find_alias (name);-
140 if (t)
tDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
4-5
141 print_alias (t, dflags);
executed 4 times by 1 test: print_alias (t, dflags);
Executed by:
  • Self test
4
142 else-
143 {-
144 sh_notfound (name);-
145 any_failed++;-
146 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
147 }-
148 list = list->next;-
149 }
executed 102 times by 1 test: end of block
Executed by:
  • Self test
102
150-
151 return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
executed 102 times by 1 test: return (any_failed ? 1 : 0);
Executed by:
  • Self test
102
152}-
153#endif /* ALIAS */-
154-
155$BUILTIN unalias-
156$FUNCTION unalias_builtin-
157$DEPENDS_ON ALIAS-
158$SHORT_DOC unalias [-a] name [name ...]-
159Remove each NAME from the list of defined aliases.-
160-
161Options:-
162 -a remove all alias definitions-
163-
164Return success unless a NAME is not an existing alias.-
165$END-
166-
167#if defined (ALIAS)-
168/* Remove aliases named in LIST from the aliases database. */-
169int-
170unalias_builtin (list)-
171 register WORD_LIST *list;-
172{-
173 register alias_t *alias;-
174 int opt, aflag;-
175-
176 aflag = 0;-
177 reset_internal_getopt ();-
178 while ((opt = internal_getopt (list, "a")) != -1)
(opt = interna...t, "a")) != -1Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 36 times by 1 test
Evaluated by:
  • Self test
23-36
179 {-
180 switch (opt)-
181 {-
182 case 'a':
executed 18 times by 1 test: case 'a':
Executed by:
  • Self test
18
183 aflag = 1;-
184 break;
executed 18 times by 1 test: break;
Executed by:
  • Self test
18
185 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
186 default:
executed 5 times by 1 test: default:
Executed by:
  • Self test
5
187 builtin_usage ();-
188 return (EX_USAGE);
executed 5 times by 1 test: return (258);
Executed by:
  • Self test
5
189 }-
190 }-
191-
192 list = loptend;-
193-
194 if (aflag)
aflagDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18
195 {-
196 delete_all_aliases ();-
197 return (EXECUTION_SUCCESS);
executed 18 times by 1 test: return (0);
Executed by:
  • Self test
18
198 }-
199-
200 if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
201 {-
202 builtin_usage ();-
203 return (EX_USAGE);
never executed: return (258);
0
204 }-
205-
206 aflag = 0;-
207 while (list)
listDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18-29
208 {-
209 alias = find_alias (list->word->word);-
210-
211 if (alias)
aliasDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
14-15
212 remove_alias (alias->name);
executed 15 times by 1 test: remove_alias (alias->name);
Executed by:
  • Self test
15
213 else-
214 {-
215 sh_notfound (list->word->word);-
216 aflag++;-
217 }
executed 14 times by 1 test: end of block
Executed by:
  • Self test
14
218-
219 list = list->next;-
220 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
221-
222 return (aflag ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
executed 18 times by 1 test: return (aflag ? 1 : 0);
Executed by:
  • Self test
18
223}-
224-
225/* Output ALIAS in such a way as to allow it to be read back in. */-
226static void-
227print_alias (alias, flags)-
228 alias_t *alias;-
229 int flags;-
230{-
231 char *value;-
232-
233 value = sh_single_quote (alias->value);-
234 if (flags & AL_REUSABLE)
flags & 0x01Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-12
235 printf ("alias %s", (alias->name && alias->name[0] == '-') ? "-- " : "");
executed 12 times by 1 test: printf ("alias %s", (alias->name && alias->name[0] == '-') ? "-- " : "");
Executed by:
  • Self test
12
236 printf ("%s=%s\n", alias->name, value);-
237 free (value);-
238-
239 fflush (stdout);-
240}
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
241#endif /* ALIAS */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2