force CC/CXX to the passed in compiler to use.
[AROS.git] / workbench / c / shellcommands / Alias.c
blob7ce525f54502e646dfeee229d145606ef3d93b71
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Alias CLI command.
6 */
8 /*****************************************************************************
10 NAME
12 Alias
14 SYNOPSIS
16 NAME,STRING/F
18 LOCATION
22 FUNCTION
24 Alias allows you to create an alternate name for other DOS commands.
25 If Alias is used with no parameters, it will display the current
26 list of Aliases defined within the current shell.
28 Using a pair of square brackets within an alias allows you to
29 provide the 'new' dos command with parameters.
31 If no parameters are specified, the current list of aliases are
32 displayed.
34 INPUTS
36 NAME - The name of the alias to set.
38 STRING - The value of the alias NAME.
40 RESULT
42 Standard DOS error codes.
44 NOTES
46 EXAMPLE
48 Alias DF "Type [] number"
50 By typing "DF S:Shell-Startup" in the shell, you are actually
51 executing the command "Type S:Shell-Startup number". This will
52 display the contents of the S:Shell-Startup file in the shell
53 with line numbers on the left hand side.
55 BUGS
57 SEE ALSO
59 Unalias
61 INTERNALS
63 ******************************************************************************/
66 #include <proto/dos.h>
67 #include <proto/exec.h>
69 #include <dos/dos.h>
70 #include <dos/dosextens.h>
71 #include <dos/rdargs.h>
72 #include <dos/var.h>
73 #include <exec/lists.h>
74 #include <exec/nodes.h>
75 #include <exec/types.h>
77 #include <aros/shcommands.h>
79 #define BUFFER_SIZE 160
81 void GetNewString(STRPTR, STRPTR, LONG);
83 AROS_SH2(Alias, 41.0,
84 AROS_SHA(STRPTR, ,NAME, ,NULL),
85 AROS_SHA(STRPTR, ,STRING,/F,NULL))
87 AROS_SHCOMMAND_INIT
89 struct Process *AliasProc;
90 struct LocalVar *AliasNode;
91 char Buffer[BUFFER_SIZE];
92 int Return_Value = RETURN_OK;
93 BOOL Success;
94 LONG VarLength;
95 char Buffer1[BUFFER_SIZE];
96 char Buffer2[BUFFER_SIZE];
99 if (SHArg(NAME) != NULL || SHArg(STRING) != NULL)
101 /* Make sure we get to here is either arguments are
102 * provided on the command line.
104 if (SHArg(NAME) != NULL && SHArg(STRING) == NULL)
106 Success = GetVar(SHArg(NAME), &Buffer[0],
107 BUFFER_SIZE, GVF_LOCAL_ONLY | LV_ALIAS);
109 if (Success == FALSE)
111 Return_Value = RETURN_WARN;
112 PrintFault(IoErr(), "Alias");
114 else
116 Printf("%s\n", Buffer);
119 else
121 /* Add the new local variable to the list. */
122 Success = SetVar(SHArg(NAME), SHArg(STRING),
123 -1, GVF_LOCAL_ONLY | LV_ALIAS);
125 if (Success == FALSE)
127 PrintFault(IoErr(), "Alias");
128 Return_Value = RETURN_ERROR;
132 else
134 /* Display a list of aliases. */
135 AliasProc = (struct Process *)FindTask(NULL);
137 ForeachNode(&(AliasProc->pr_LocalVars), AliasNode)
139 if (AliasNode->lv_Node.ln_Type == LV_ALIAS)
141 /* Get a clean variable with no excess
142 * characters.
144 VarLength = GetVar(AliasNode->lv_Node.ln_Name,
145 &Buffer1[0],
146 BUFFER_SIZE,
147 GVF_LOCAL_ONLY | LV_ALIAS);
148 if (VarLength != -1)
150 GetNewString(&Buffer1[0], &Buffer2[0], VarLength);
152 Buffer2[VarLength] = 0;
154 Printf("%-20s\t%-20s\n", AliasNode->lv_Node.ln_Name, Buffer2);
160 return Return_Value;
162 AROS_SHCOMMAND_EXIT
163 } /* main */
166 void GetNewString(STRPTR s, STRPTR d, LONG l)
168 int i;
169 int j;
171 i = j = 0;
173 while (i < l)
175 if (s[i] == '*' || s[i] == '\e')
177 d[j] = '*';
179 i++;
180 j++;
182 else
184 d[j] = s[i];
186 i++;
187 j++;
190 } /* GetNewString */