1 /* 2 * PROJECT: ReactOS DiskPart 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: base/system/diskpart/help.c 5 * PURPOSE: Manages all the partitions of the OS in an interactive way. 6 * PROGRAMMERS: Lee Schroeder 7 */ 8 9 #include "diskpart.h" 10 11 /* 12 * HelpCommandList(): 13 * shows all the available commands and basic descriptions for diskpart 14 */ 15 VOID 16 HelpCommandList(VOID) 17 { 18 PCOMMAND cmdptr; 19 WCHAR szFormat[64]; 20 WCHAR szOutput[256]; 21 22 K32LoadStringW(GetModuleHandle(NULL), IDS_HELP_FORMAT_STRING, szFormat, ARRAYSIZE(szFormat)); 23 24 /* Print the header information */ 25 ConResPuts(StdOut, IDS_APP_HEADER); 26 ConPuts(StdOut, L"\n"); 27 28 /* List all the commands and the basic descriptions */ 29 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++) 30 { 31 if (cmdptr->cmd1 != NULL && cmdptr->cmd2 == NULL && cmdptr->cmd3 == NULL) 32 { 33 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput)); 34 ConPrintf(StdOut, szFormat, cmdptr->cmd1, szOutput); 35 } 36 } 37 38 ConPuts(StdOut, L"\n"); 39 } 40 41 42 BOOL 43 HelpCommand( 44 PCOMMAND pCommand) 45 { 46 PCOMMAND cmdptr; 47 BOOL bSubCommands = FALSE; 48 WCHAR szFormat[64]; 49 WCHAR szOutput[256]; 50 51 K32LoadStringW(GetModuleHandle(NULL), IDS_HELP_FORMAT_STRING, szFormat, ARRAYSIZE(szFormat)); 52 53 ConPuts(StdOut, L"\n"); 54 55 /* List all the commands and the basic descriptions */ 56 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++) 57 { 58 if (pCommand->cmd1 != NULL && pCommand->cmd2 == NULL && pCommand->cmd3 == NULL) 59 { 60 if (wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0 && cmdptr->cmd2 != NULL && cmdptr->cmd3 == NULL) 61 { 62 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput)); 63 ConPrintf(StdOut, szFormat, cmdptr->cmd2, szOutput); 64 bSubCommands = TRUE; 65 } 66 } 67 else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 == NULL) 68 { 69 if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) && 70 (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) && 71 (cmdptr->cmd3 != NULL)) 72 { 73 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput)); 74 ConPrintf(StdOut, szFormat, cmdptr->cmd3, szOutput); 75 bSubCommands = TRUE; 76 } 77 } 78 else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 != NULL) 79 { 80 if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) && 81 (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) && 82 (wcsicmp(pCommand->cmd3, cmdptr->cmd3) == 0) && 83 (cmdptr->help_detail != IDS_NONE)) 84 ConResPuts(StdOut, cmdptr->help_detail); 85 } 86 } 87 88 if ((bSubCommands == FALSE) && (pCommand->help_detail != IDS_NONE)) 89 { 90 ConResPuts(StdOut, pCommand->help_detail); 91 } 92 93 ConPuts(StdOut, L"\n"); 94 95 return TRUE; 96 } 97 98 99 /* help_main(char *arg): 100 * main entry point for the help command. Gives help to users who needs it. 101 */ 102 BOOL help_main(INT argc, LPWSTR *argv) 103 { 104 PCOMMAND cmdptr; 105 PCOMMAND cmdptr1 = NULL; 106 PCOMMAND cmdptr2 = NULL; 107 PCOMMAND cmdptr3 = NULL; 108 109 if (argc == 1) 110 { 111 HelpCommandList(); 112 return TRUE; 113 } 114 115 /* Scan internal command table */ 116 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++) 117 { 118 if ((cmdptr1 == NULL) && 119 (wcsicmp(argv[1], cmdptr->cmd1) == 0)) 120 cmdptr1 = cmdptr; 121 122 if ((cmdptr2 == NULL) && 123 (argc >= 3) && 124 (wcsicmp(argv[1], cmdptr->cmd1) == 0) && 125 (wcsicmp(argv[2], cmdptr->cmd2) == 0)) 126 cmdptr2 = cmdptr; 127 128 if ((cmdptr3 == NULL) && 129 (argc >= 4) && 130 (wcsicmp(argv[1], cmdptr->cmd1) == 0) && 131 (wcsicmp(argv[2], cmdptr->cmd2) == 0) && 132 (wcsicmp(argv[3], cmdptr->cmd3) == 0)) 133 cmdptr3 = cmdptr; 134 } 135 136 if (cmdptr3 != NULL) 137 { 138 return HelpCommand(cmdptr3); 139 } 140 else if (cmdptr2 != NULL) 141 { 142 return HelpCommand(cmdptr2); 143 } 144 else if (cmdptr1 != NULL) 145 { 146 return HelpCommand(cmdptr1); 147 } 148 149 HelpCommandList(); 150 151 return TRUE; 152 } 153