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
];
92 int Return_Value
= RETURN_OK
;
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");
116 Printf("%s\n", Buffer
);
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
;
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
144 VarLength
= GetVar(AliasNode
->lv_Node
.ln_Name
,
147 GVF_LOCAL_ONLY
| LV_ALIAS
);
150 GetNewString(&Buffer1
[0], &Buffer2
[0], VarLength
);
152 Buffer2
[VarLength
] = 0;
154 Printf("%-20s\t%-20s\n", AliasNode
->lv_Node
.ln_Name
, Buffer2
);
166 void GetNewString(STRPTR s
, STRPTR d
, LONG l
)
175 if (s
[i
] == '*' || s
[i
] == '\e')