From d840e89e8ec180183d98e6a237b4d646c2e1207e Mon Sep 17 00:00:00 2001 From: Krush206 <37114863+Krush206@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:08:54 -0300 Subject: [PATCH] Create aliases for functions --- sh.func.c | 14 +++++++++++--- tcsh.man.in | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sh.func.c b/sh.func.c index 02503fd5..f1298b8c 100644 --- a/sh.func.c +++ b/sh.func.c @@ -2783,7 +2783,8 @@ dofunction(Char **v, struct command *c) stderror(ERR_FUNC, Sgoal); { Char funcexit[] = { 'r', 'e', 't', 'u', 'r', 'n', '\0' }, - *(*varvec)[2]; + alarg[] = { '!', '*', '\0' }, + *(*varvec)[4]; struct Strbuf aword = Strbuf_INIT, func = Strbuf_INIT; struct wordent *histent = NULL, @@ -2847,9 +2848,16 @@ dofunction(Char **v, struct command *c) if (!func.len) return; func.s[--func.len] = 0; - **(varvec = xmalloc(sizeof *varvec)) = func.s; - *varvec[1] = NULL; + **(varvec = xcalloc(1, sizeof *varvec - + (sizeof **varvec * 2))) = func.s; setq(Sgoal, *varvec, &functions, VAR_READONLY); + **(varvec = + xcalloc(1, sizeof *varvec)) = Strsave(str2short(bname)); + (*varvec)[1] = Strsave(Sgoal); + (*varvec)[2] = Strsave(alarg); + setq(Sgoal, *varvec, &aliases, VAR_READWRITE); + + tw_cmd_free(); } } } diff --git a/tcsh.man.in b/tcsh.man.in index 26ad35ff..fd8709f4 100644 --- a/tcsh.man.in +++ b/tcsh.man.in @@ -5530,6 +5530,9 @@ loop at the terminal you can rub it out. .It Ic function Ar name Xo .Op Ar arg No ... (+) +.It Ar name Xo +.Op Ar arg No ... +(+) .Xc The first form of the command prints the value of all shell functions. .Pp @@ -5552,6 +5555,10 @@ optionally, preceded by which is a list of arguments to be passed. Function calls may be nested or recursive, but too deep a nest or recursion will raise an error. +.Pp +The fourth form is an +.Ic alias +for the third form. . .El .Bl -tag -width 6n