-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.c
More file actions
69 lines (58 loc) · 1.67 KB
/
Main.c
File metadata and controls
69 lines (58 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "pch.h"
typedef struct _EXAMPLE_PROC
{
wchar_t* Name;
FN_EXAMPLE_PROC* Proc;
} EXAMPLE_PROC;
#define DECL_EXAMPLE_PROC(x) { L###x, &x }
/* Append new example here in alphabetical order */
extern FN_EXAMPLE_PROC DataStructure_LinkedList_Merge;
extern FN_EXAMPLE_PROC DataStructure_LinkedList_Reverse;
extern FN_EXAMPLE_PROC Print_MultiplicationTable;
static const EXAMPLE_PROC ExampleList[] = {
DECL_EXAMPLE_PROC(DataStructure_LinkedList_Merge),
DECL_EXAMPLE_PROC(DataStructure_LinkedList_Reverse),
DECL_EXAMPLE_PROC(Print_MultiplicationTable),
};
static
bool
RunExample(
_In_ const EXAMPLE_PROC* Example)
{
bool bRet;
wprintf(L"======== Running example: %ls ========\n", Example->Name);
bRet = Example->Proc();
wprintf(L"======== %ls ========\n\n", bRet ? L"Succeeded" : L"Failed");
return bRet;
}
int wmain(
_In_ int argc,
_In_reads_(argc) _Pre_z_ wchar_t** argv)
{
_wsetlocale(LC_ALL, L".ACP");
if (argc == 1)
{
/* No argument, run all examples */
for (int i = 0; i < __crt_countof(ExampleList); i++)
{
if (!RunExample(&ExampleList[i]))
{
return EFAULT;
}
}
return 0;
} else if (argc == 2)
{
/* One argument, run specified example */
for (int i = 0; i < __crt_countof(ExampleList); i++)
{
if (_wcsicmp(argv[1], ExampleList[i].Name) == 0)
{
return RunExample(&ExampleList[i]) ? 0 : EFAULT;
}
}
return ENOENT;
}
/* Invalid parameter */
return EINVAL;
}