-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor b_unset(), b_unalias, and unall()
With this change all special builtins are now in their own source module. More importantly this eliminates a lot of cleverness that obfuscates the actual behavior.
- Loading branch information
1 parent
9ba9355
commit d5277d3
Showing
8 changed files
with
172 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*********************************************************************** | ||
* * | ||
* This software is part of the ast package * | ||
* Copyright (c) 1982-2014 AT&T Intellectual Property * | ||
* and is licensed under the * | ||
* Eclipse Public License, Version 1.0 * | ||
* by AT&T Intellectual Property * | ||
* * | ||
* A copy of the License is available at * | ||
* http://www.eclipse.org/org/documents/epl-v10.html * | ||
* (with md5 checksum b35adb5213ca9657e911e9befb180842) * | ||
* * | ||
* Information and Software Systems Research * | ||
* AT&T Research * | ||
* Florham Park NJ * | ||
* * | ||
* David Korn <[email protected]> * | ||
* * | ||
***********************************************************************/ | ||
#include "config_ast.h" // IWYU pragma: keep | ||
|
||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#include "builtins.h" | ||
#include "cdt.h" | ||
#include "defs.h" | ||
#include "error.h" | ||
#include "name.h" | ||
#include "option.h" | ||
#include "shcmd.h" | ||
|
||
// The `unalias` builtin. | ||
int b_unalias(int argc, char *argv[], Shbltin_t *context) { | ||
UNUSED(argc); | ||
Shell_t *shp = context->shp; | ||
Dt_t *troot = shp->alias_tree; | ||
nvflag_t nvflags = NV_NOSCOPE; | ||
bool all = false; | ||
int n; | ||
|
||
if (shp->subshell) troot = sh_subaliastree(shp, 0); | ||
while ((n = optget(argv, sh_optunalias))) { | ||
switch (n) { //!OCLINT(MissingDefaultStatement) | ||
case 'a': { | ||
all = true; | ||
break; | ||
} | ||
case ':': { | ||
errormsg(SH_DICT, 2, "%s", opt_info.arg); | ||
break; | ||
} | ||
case '?': { | ||
errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg); | ||
return 2; | ||
} | ||
} | ||
} | ||
argv += opt_info.index; | ||
if (error_info.errors || (!*argv && !all)) { | ||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL)); | ||
__builtin_unreachable(); | ||
} | ||
|
||
if (!troot) return 1; | ||
if (all) { | ||
dtclear(troot); | ||
return 0; | ||
} | ||
return nv_unall(argv, true, nvflags, troot, shp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters