New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Alias.c
blob5f8a2a4edb27a5e39c2d1439fc2006488eb0f36f
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
20 Workbench:c
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 IPTR OutArgs[3];
93 int Return_Value = RETURN_OK;
94 BOOL Success;
95 LONG VarLength;
96 char Buffer1[BUFFER_SIZE];
97 char Buffer2[BUFFER_SIZE];
100 if (SHArg(NAME) != NULL || SHArg(STRING) != NULL)
102 /* Make sure we get to here is either arguments are
103 * provided on the command line.
105 if (SHArg(NAME) != NULL && SHArg(STRING) == NULL)
107 Success = GetVar(SHArg(NAME), &Buffer[0],
108 BUFFER_SIZE, GVF_LOCAL_ONLY | LV_ALIAS);
110 if (Success == FALSE)
112 Return_Value = RETURN_WARN;
113 PrintFault(IoErr(), "Alias");
115 else
117 OutArgs[0] = (IPTR)&Buffer[0];
118 OutArgs[1] = (IPTR)NULL;
119 VPrintf("%s\n", &OutArgs[0]);
122 else
124 /* Add the new local variable to the list. */
125 Success = SetVar(SHArg(NAME), SHArg(STRING),
126 -1, GVF_LOCAL_ONLY | LV_ALIAS);
128 if (Success == FALSE)
130 PrintFault(IoErr(), "Alias");
131 Return_Value = RETURN_ERROR;
135 else
137 /* Display a list of aliases. */
138 AliasProc = (struct Process *)FindTask(NULL);
140 ForeachNode(&(AliasProc->pr_LocalVars), AliasNode)
142 if (AliasNode->lv_Node.ln_Type == LV_ALIAS)
144 /* Get a clean variable with no excess
145 * characters.
147 VarLength = GetVar(AliasNode->lv_Node.ln_Name,
148 &Buffer1[0],
149 BUFFER_SIZE,
150 GVF_LOCAL_ONLY | LV_ALIAS);
151 if (VarLength != -1)
153 GetNewString(&Buffer1[0], &Buffer2[0], VarLength);
155 Buffer2[VarLength] = NULL;
157 OutArgs[0] = (IPTR)AliasNode->lv_Node.ln_Name;
158 OutArgs[1] = (IPTR)&Buffer2[0];
159 OutArgs[2] = (IPTR)NULL;
160 VPrintf("%-20s\t%-20s\n", &OutArgs[0]);
166 return Return_Value;
168 AROS_SHCOMMAND_EXIT
169 } /* main */
172 void GetNewString(STRPTR s, STRPTR d, LONG l)
174 int i;
175 int j;
177 i = j = 0;
179 while (i < l)
181 if (s[i] == '*' || s[i] == '\e')
183 d[j] = '*';
185 i++;
186 j++;
188 else
190 d[j] = s[i];
192 i++;
193 j++;
196 } /* GetNewString */