2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
8 /*****************************************************************************
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
36 NAME - The name of the alias to set.
38 STRING - The value of the alias NAME.
42 Standard DOS error codes.
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.
63 ******************************************************************************/
66 #include <proto/dos.h>
67 #include <proto/exec.h>
70 #include <dos/dosextens.h>
71 #include <dos/rdargs.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
);
84 AROS_SHA(STRPTR
, ,NAME
, ,NULL
),
85 AROS_SHA(STRPTR
, ,STRING
,/F
,NULL
))
89 struct Process
*AliasProc
;
90 struct LocalVar
*AliasNode
;
91 char Buffer
[BUFFER_SIZE
];
93 int Return_Value
= RETURN_OK
;
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");
117 OutArgs
[0] = (IPTR
)&Buffer
[0];
118 OutArgs
[1] = (IPTR
)NULL
;
119 VPrintf("%s\n", &OutArgs
[0]);
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
;
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
147 VarLength
= GetVar(AliasNode
->lv_Node
.ln_Name
,
150 GVF_LOCAL_ONLY
| LV_ALIAS
);
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]);
172 void GetNewString(STRPTR s
, STRPTR d
, LONG l
)
181 if (s
[i
] == '*' || s
[i
] == '\e')