ReactOS 0.4.16-dev-1946-g52006dd
alias.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for alias.c:

Go to the source code of this file.

Classes

struct  _ALIAS_ENTRY
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _ALIAS_ENTRY ALIAS_ENTRY
 
typedef struct _ALIAS_ENTRYPALIAS_ENTRY
 

Functions

static VOID ShowAliases (VOID)
 
static VOID ShowAlias (PWSTR pszAliasName)
 
static PALIAS_ENTRY GetAliasEntry (PWSTR pszAliasName)
 
VOID InitAliases (VOID)
 
VOID DestroyAliases (VOID)
 
DWORD WINAPI AliasCommand (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
DWORD WINAPI ShowAliasCommand (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
DWORD WINAPI UnaliasCommand (LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 

Variables

PALIAS_ENTRY AliasListHead = NULL
 
PALIAS_ENTRY AliasListTail = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file alias.c.

Typedef Documentation

◆ ALIAS_ENTRY

◆ PALIAS_ENTRY

Function Documentation

◆ AliasCommand()

DWORD WINAPI AliasCommand ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 123 of file alias.c.

131{
132 PALIAS_ENTRY pAliasEntry = NULL;
133 PWSTR pszAlias;
134
135 DPRINT("AliasCommand(dwCurrentIndex %lu dwArgCount %lu)\n",
137
138 /* Show aliases */
139 if (dwArgCount - dwCurrentIndex == 0)
140 {
141 ShowAliases();
142 return ERROR_SUCCESS;
143 }
144
145 if (dwArgCount - dwCurrentIndex == 1)
146 {
148 return ERROR_SUCCESS;
149 }
150
151
152 /* TODO: Check builtin commands */
153
154
155 pAliasEntry = GetAliasEntry(argv[dwCurrentIndex]);
156 if (pAliasEntry)
157 {
159 DPRINT("Alias: %S\n", pszAlias);
160 if (pszAlias == NULL)
162
163 if (pAliasEntry->pszAlias)
164 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAlias);
165
166 pAliasEntry->pszAlias = pszAlias;
167 }
168 else
169 {
170 pAliasEntry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ALIAS_ENTRY));
171 if (pAliasEntry == NULL)
173
174 pAliasEntry->pszAliasName = HeapAlloc(GetProcessHeap(), 0,
175 (wcslen(argv[dwCurrentIndex]) + 1) * sizeof(WCHAR));
176 if (pAliasEntry->pszAliasName == NULL)
177 {
178 HeapFree(GetProcessHeap(), 0, pAliasEntry);
180 }
181
182 wcscpy(pAliasEntry->pszAliasName, argv[dwCurrentIndex]);
183 DPRINT("AliasName: %S\n", pAliasEntry->pszAliasName);
184
186 DPRINT("Alias: %S\n", pAliasEntry->pszAlias);
187 if (pAliasEntry->pszAlias == NULL)
188 {
189 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAliasName);
190 HeapFree(GetProcessHeap(), 0, pAliasEntry);
192 }
193
194 if (AliasListHead == NULL)
195 {
196 AliasListHead = pAliasEntry;
197 AliasListTail = pAliasEntry;
198 }
199 else
200 {
201 pAliasEntry->pPrev = AliasListTail;
202 AliasListTail->pNext = pAliasEntry;
203 AliasListTail = pAliasEntry;
204 }
205 }
206
207 DPRINT("Done\n");
208
209 return ERROR_OKAY;
210}
static PALIAS_ENTRY GetAliasEntry(PWSTR pszAliasName)
Definition: alias.c:76
PALIAS_ENTRY AliasListHead
Definition: alias.c:26
PALIAS_ENTRY AliasListTail
Definition: alias.c:27
static VOID ShowAliases(VOID)
Definition: alias.c:34
static VOID ShowAlias(PWSTR pszAliasName)
Definition: alias.c:51
wcscpy
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define argv
Definition: mplay32.c:18
LPWSTR MergeStrings(_In_ LPWSTR pszStringArray[], _In_ INT nCount)
Definition: netsh.c:53
#define ERROR_OKAY
Definition: netsh.h:24
_In_ LPWSTR _In_ DWORD dwArgCount
Definition: netsh.h:115
_In_ LPWSTR _In_ DWORD dwCurrentIndex
Definition: netsh.h:139
#define DPRINT
Definition: sndvol32.h:73
Definition: alias.c:18
PWSTR pszAliasName
Definition: alias.c:22
struct _ALIAS_ENTRY * pNext
Definition: alias.c:20
struct _ALIAS_ENTRY * pPrev
Definition: alias.c:19
PWSTR pszAlias
Definition: alias.c:23
uint16_t * PWSTR
Definition: typedefs.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CreateRootContext().

◆ DestroyAliases()

VOID DestroyAliases ( VOID  )

Definition at line 103 of file alias.c.

104{
105 PALIAS_ENTRY pAliasEntry;
106
107 while (AliasListHead != NULL)
108 {
109 pAliasEntry = AliasListHead;
111
112 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAliasName);
113 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAlias);
114 HeapFree(GetProcessHeap(), 0, pAliasEntry);
115 }
116
118}

Referenced by wmain().

◆ GetAliasEntry()

static PALIAS_ENTRY GetAliasEntry ( PWSTR  pszAliasName)
static

Definition at line 76 of file alias.c.

78{
79 PALIAS_ENTRY pAliasEntry = NULL;
80
81 pAliasEntry = AliasListHead;
82 while (pAliasEntry)
83 {
84 if (wcscmp(pAliasEntry->pszAliasName, pszAliasName) == 0)
85 return pAliasEntry;
86
87 pAliasEntry = pAliasEntry->pNext;
88 }
89
90 return NULL;
91}
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by AliasCommand().

◆ InitAliases()

VOID InitAliases ( VOID  )

Definition at line 95 of file alias.c.

96{
99}

Referenced by wmain().

◆ ShowAlias()

static VOID ShowAlias ( PWSTR  pszAliasName)
static

Definition at line 51 of file alias.c.

53{
54 PALIAS_ENTRY pAliasEntry = NULL;
55
56 DPRINT1("ShowAlias(%S)\n", pszAliasName);
57
58 pAliasEntry = AliasListHead;
59 while (pAliasEntry)
60 {
61 if (wcscmp(pAliasEntry->pszAliasName, pszAliasName) == 0)
62 {
63 ConPrintf(StdOut, L"%s\n", pAliasEntry->pszAlias);
64 return;
65 }
66
67 pAliasEntry = pAliasEntry->pNext;
68 }
69
71}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define IDS_ALIAS_NOT_FOUND
Definition: resource.h:17
#define DPRINT1
Definition: precomp.h:8
#define L(x)
Definition: resources.c:13

Referenced by AliasCommand().

◆ ShowAliasCommand()

DWORD WINAPI ShowAliasCommand ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 215 of file alias.c.

223{
224 DPRINT("ShowAliasCommand()\n");
225
226 ShowAliases();
227
228 return ERROR_SUCCESS;
229}

Referenced by CreateRootContext().

◆ ShowAliases()

static VOID ShowAliases ( VOID  )
static

Definition at line 34 of file alias.c.

35{
36 PALIAS_ENTRY pAliasEntry = NULL;
37
38 DPRINT1("ShowAliases()\n");
39
40 pAliasEntry = AliasListHead;
41 while (pAliasEntry)
42 {
43 ConPrintf(StdOut, L"%s : %s\n", pAliasEntry->pszAliasName, pAliasEntry->pszAlias);
44 pAliasEntry = pAliasEntry->pNext;
45 }
46}

Referenced by AliasCommand(), and ShowAliasCommand().

◆ UnaliasCommand()

DWORD WINAPI UnaliasCommand ( LPCWSTR  pwszMachine,
LPWSTR argv,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 234 of file alias.c.

242{
243 PALIAS_ENTRY pAliasEntry = NULL;
244
245 DPRINT("UnaliasCommand()\n");
246
247 if (dwArgCount - dwCurrentIndex != 1)
249
250 DPRINT("Alias %S\n", argv[dwCurrentIndex]);
251
252 pAliasEntry = AliasListHead;
253 while (pAliasEntry)
254 {
255 if (wcscmp(pAliasEntry->pszAliasName, argv[dwCurrentIndex]) == 0)
256 {
257 DPRINT("Alias found %S\n", argv[dwCurrentIndex]);
258
259 if (pAliasEntry->pNext != NULL)
260 pAliasEntry->pNext->pPrev = pAliasEntry->pPrev;
261 else
262 AliasListTail = pAliasEntry->pPrev;
263
264 if (pAliasEntry->pPrev != NULL)
265 pAliasEntry->pPrev->pNext = pAliasEntry->pNext;
266 else
267 AliasListHead = pAliasEntry->pNext;
268
269 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAliasName);
270 HeapFree(GetProcessHeap(), 0, pAliasEntry->pszAlias);
271 HeapFree(GetProcessHeap(), 0, pAliasEntry);
272
273 return ERROR_SUCCESS;
274 }
275
276 pAliasEntry = pAliasEntry->pNext;
277 }
278
280
281 return ERROR_SUCCESS;
282}
#define ERROR_INVALID_SYNTAX
Definition: netsh.h:10

Referenced by CreateRootContext().

Variable Documentation

◆ AliasListHead

◆ AliasListTail

PALIAS_ENTRY AliasListTail = NULL

Definition at line 27 of file alias.c.

Referenced by AliasCommand(), DestroyAliases(), InitAliases(), and UnaliasCommand().