Index: base/shell/cmd/config.h =================================================================== --- base/shell/cmd/config.h (revision 39998) +++ base/shell/cmd/config.h (working copy) @@ -50,6 +50,7 @@ #ifdef NT4_INTERNAL_COMMANDS #define INCLUDE_CMD_ACTIVATE #endif +#define INCLUDE_CMD_ASSOC #define INCLUDE_CMD_ATTRIB #define INCLUDE_CMD_CHCP #define INCLUDE_CMD_CHDIR Index: base/shell/cmd/lang/es-ES.rc =================================================================== --- base/shell/cmd/lang/es-ES.rc (revision 39998) +++ base/shell/cmd/lang/es-ES.rc (working copy) @@ -9,6 +9,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Muestra o cambia los atributos de los archivos.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -567,6 +575,7 @@ STRING_ALIAS_ERROR, "Linea de comandos demasiado larga tras la expansin del alias!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Error abriendo el archivo por lotes\n" STRING_CHCP_ERROR1, "Pgina de cdigos activa: %u\n" STRING_CHCP_ERROR4, "Cdigo de pgina invlido\n" Index: base/shell/cmd/lang/fr-FR.rc =================================================================== --- base/shell/cmd/lang/fr-FR.rc (revision 39998) +++ base/shell/cmd/lang/fr-FR.rc (working copy) @@ -10,6 +10,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Affiche ou change des attributs de fichiers.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -623,6 +631,7 @@ STRING_ALIAS_ERROR, "Ligne de commande trop longue aprs remplacement de l'alias!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Erreur l'ouverture du fichier batch\n" STRING_CHCP_ERROR1, "Page de codes actuelle : %u\n" STRING_CHCP_ERROR4, "Page de codes invalide \n" Index: base/shell/cmd/lang/de-DE.rc =================================================================== --- base/shell/cmd/lang/de-DE.rc (revision 39998) +++ base/shell/cmd/lang/de-DE.rc (working copy) @@ -9,6 +9,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Zeigt Dateiattribute an oder ndert sie.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] Dateiname ...\n\ [/S [/D]]\n\n\ @@ -600,6 +608,7 @@ STRING_COPY_OPTION, "JNA" STRING_ALIAS_ERROR, "Die Befehlszeile ist zu lange nach der Alias-Erweiterung!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Es trat ein Fehler auf, whrend die Batch-Datei geffnet wurde.\n" STRING_CHCP_ERROR1, "Aktive Code-Page: %u\n" STRING_CHCP_ERROR4, "Ungltige Code-Page\n" Index: base/shell/cmd/lang/ja-JP.rc =================================================================== --- base/shell/cmd/lang/ja-JP.rc (revision 39998) +++ base/shell/cmd/lang/ja-JP.rc (working copy) @@ -9,6 +9,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "t@C\\܂͕ύX܂B\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [t@C] ...\n\ [/S [/D]]\n\n\ @@ -574,6 +582,7 @@ STRING_ALIAS_ERROR, "GCAXWJ̃R}h C܂!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "ob` t@CJƂɃG[܂B\n" STRING_CHCP_ERROR1, "݂̃R[h y[W: %u\n" STRING_CHCP_ERROR4, "ȃR[h y[Wł\n" Index: base/shell/cmd/lang/uk-UA.rc =================================================================== --- base/shell/cmd/lang/uk-UA.rc (revision 39998) +++ base/shell/cmd/lang/uk-UA.rc (working copy) @@ -13,6 +13,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "³ .\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] ...\n\ [/S [/D]]\n\n\ @@ -613,6 +621,7 @@ STRING_ALIAS_ERROR, "Command line too long after alias expansion!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Error opening batch file\n" STRING_CHCP_ERROR1, "Active code page: %u\n" STRING_CHCP_ERROR4, "Invalid code page\n" Index: base/shell/cmd/lang/pl-PL.rc =================================================================== --- base/shell/cmd/lang/pl-PL.rc (revision 39998) +++ base/shell/cmd/lang/pl-PL.rc (working copy) @@ -10,6 +10,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Wywietla lub zmienia atrybuty plikw.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] nazwa_pliku ...\n\ [/S [/D]]\n\n\ @@ -565,6 +573,7 @@ STRING_ALIAS_ERROR, "Linia polece zbyt duga po rozszerzeniu aliasa!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Bd podczas otwierania pliku wsadowego\n" STRING_CHCP_ERROR1, "Aktywna strona kodowa nr: %u\n" STRING_CHCP_ERROR4, "Niewaciwy numer strony kodowej\n" Index: base/shell/cmd/lang/el-GR.rc =================================================================== --- base/shell/cmd/lang/el-GR.rc (revision 39998) +++ base/shell/cmd/lang/el-GR.rc (working copy) @@ -9,6 +9,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, " .\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -605,6 +613,7 @@ STRING_ALIAS_ERROR, "Command line too long after alias expansion!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Error opening batch file\n" STRING_CHCP_ERROR1, "Active code page: %u\n" STRING_CHCP_ERROR4, "Invalid code page\n" Index: base/shell/cmd/lang/hu-HU.rc =================================================================== --- base/shell/cmd/lang/hu-HU.rc (revision 39998) +++ base/shell/cmd/lang/hu-HU.rc (working copy) @@ -11,6 +11,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "llomnyok attribtumok megjelentse vagy belltsai.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] llomny ...\n\ [/S [/D]]\n\n\ @@ -547,6 +555,7 @@ STRING_ALIAS_ERROR, "A parancssor tl hossz az alias kibontsakor!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Hiba a batch llomny megnyitsakor\n" STRING_CHCP_ERROR1, "Aktv kdlap: %u\n" STRING_CHCP_ERROR4, "rvnytelen kdlap\n" Index: base/shell/cmd/lang/id-ID.rc =================================================================== --- base/shell/cmd/lang/id-ID.rc (revision 39998) +++ base/shell/cmd/lang/id-ID.rc (working copy) @@ -10,6 +10,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Menampilkan atau mengubah atribut file.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -567,6 +575,7 @@ STRING_ALIAS_ERROR, "Baris perintah terlalu panjang setelah ekspansi alias!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Kesalaham membuka file batch\n" STRING_CHCP_ERROR1, "Halaman kode aktif: %u\n" STRING_CHCP_ERROR4, "Halaman kode tidak benar\n" Index: base/shell/cmd/lang/it-IT.rc =================================================================== --- base/shell/cmd/lang/it-IT.rc (revision 39998) +++ base/shell/cmd/lang/it-IT.rc (working copy) @@ -5,6 +5,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Visualizza o modifica gli attributi dei file.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -613,6 +621,7 @@ STRING_ALIAS_ERROR, "Linea di comando troppo lunga dopo l'espansione degli alias!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Errore durante l'apertura di un batch\n" STRING_CHCP_ERROR1, "Tabella dei codici attiva: %u\n" STRING_CHCP_ERROR4, "Tabella dei codici non valida\n" Index: base/shell/cmd/lang/no-NO.rc =================================================================== --- base/shell/cmd/lang/no-NO.rc (revision 39998) +++ base/shell/cmd/lang/no-NO.rc (working copy) @@ -5,6 +5,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Viser eller endrer filattributtene.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] fil ...\n\ [/S [/D]]\n\n\ @@ -559,6 +567,7 @@ STRING_ALIAS_ERROR, "Kommando linje for lang etter alias utvidelse!\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, "Feil ved pning av satsvis fil\n" STRING_CHCP_ERROR1, "Aktiv tegntabell: %u\n" STRING_CHCP_ERROR4, "Ugyldig tegntabell\n" Index: base/shell/cmd/lang/en-US.rc =================================================================== --- base/shell/cmd/lang/en-US.rc (revision 39998) +++ base/shell/cmd/lang/en-US.rc (working copy) @@ -9,6 +9,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, "Displays or changes file attributes.\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] file ...\n\ [/S [/D]]\n\n\ @@ -608,7 +616,7 @@ STRING_CHOICE_OPTION, "YN" STRING_COPY_OPTION, "YNA" - +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_ALIAS_ERROR, "Command line too long after alias expansion!\n" STRING_BATCH_ERROR, "Error opening batch file\n" STRING_CHCP_ERROR1, "Active code page: %u\n" Index: base/shell/cmd/lang/ru-RU.rc =================================================================== --- base/shell/cmd/lang/ru-RU.rc (revision 39998) +++ base/shell/cmd/lang/ru-RU.rc (working copy) @@ -13,6 +13,14 @@ STRINGTABLE DISCARDABLE BEGIN +STRING_ASSOC_HELP, "Modify file extension associations.\n\n\ +assoc [.ext[=[FileType]]]\n\ +\n\ +assoc (print all associations)\n\ +assoc .ext (print specific association)\n\ +assoc .ext= (remove specific association)\n\ +assoc .ext=FileType (add new association)\n" + STRING_ATTRIB_HELP, " .\n\n\ ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] ...\n\ [/S [/D]]\n\n\ @@ -572,6 +580,7 @@ STRING_ALIAS_ERROR, " !\n" +STRING_ASSOC_ERROR, "File association not found for extension %s\n" STRING_BATCH_ERROR, " \n" STRING_CHCP_ERROR1, " : %u\n" STRING_CHCP_ERROR4, " \n" Index: base/shell/cmd/cmd.rbuild =================================================================== --- base/shell/cmd/cmd.rbuild (revision 39998) +++ base/shell/cmd/cmd.rbuild (working copy) @@ -16,6 +16,7 @@ precomp.h alias.c + assoc.c attrib.c batch.c beep.c Index: base/shell/cmd/cmdtable.c =================================================================== --- base/shell/cmd/cmdtable.c (revision 39998) +++ base/shell/cmd/cmdtable.c (working copy) @@ -37,6 +37,10 @@ {_T("alias"), 0, CommandAlias}, #endif +#ifdef INCLUDE_CMD_ASSOC + {_T("assoc"), 0, CommandAssoc}, +#endif + #ifdef INCLUDE_CMD_ATTRIB {_T("attrib"), 0, CommandAttrib}, #endif Index: base/shell/cmd/resource.h =================================================================== --- base/shell/cmd/resource.h (revision 39998) +++ base/shell/cmd/resource.h (working copy) @@ -70,6 +70,7 @@ #define STRING_REPLACE_ERROR5 355 #define STRING_REPLACE_ERROR6 356 #define STRING_REPLACE_ERROR7 357 +#define STRING_ASSOC_ERROR 358 #define STRING_ATTRIB_HELP 600 #define STRING_ALIAS_HELP 601 @@ -87,6 +88,7 @@ #define STRING_CMD_HELP6 613 #define STRING_CMD_HELP7 614 #define STRING_CMD_HELP8 615 +#define STRING_ASSOC_HELP 616 #define STRING_CMD_SHELLINFO 624 Index: base/shell/cmd/cmd.h =================================================================== --- base/shell/cmd/cmd.h (revision 39998) +++ base/shell/cmd/cmd.h (working copy) @@ -71,6 +71,9 @@ VOID ExpandAlias (LPTSTR, INT); INT CommandAlias (LPTSTR); +/* Prototypes for ASSOC.C */ +INT CommandAssoc (LPTSTR); + /* Prototypes for ATTRIB.C */ INT CommandAttrib (LPTSTR); Index: base/shell/cmd/assoc.c =================================================================== --- base/shell/cmd/assoc.c (revision 0) +++ base/shell/cmd/assoc.c (revision 0) @@ -0,0 +1,261 @@ +/* + * Assoc.C - assoc internal command. + * + * + * History: + * + * 14-Mar-2009 Lee C. Baker + * - initial implementation + * + * 15-Mar-2009 Lee C. Baker + * - Don't write to (or use) HKEY_CLASSES_ROOT directly + * - Make sure that non-administrator users can list associations + * - Externalize strings + * + * TODO: + * - PrintAllAssociations might could be optimized to not fetch all registry subkeys under 'Classes', just the ones that start with '.' + */ + +#include +#include + +#ifdef INCLUDE_CMD_ASSOC + +static INT +PrintAssociation(LPTSTR extension) +{ + DWORD return_val; + HKEY hKey = NULL, hInsideKey = NULL; + + DWORD fileTypeLength = 0; + LPTSTR fileType = NULL; + + return_val = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ , NULL, &hKey, NULL); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return -1; + } + + return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ , NULL, &hInsideKey, NULL); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + RegCloseKey(hInsideKey); + return -1; + } + + /* obtain string length */ + return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, NULL, &fileTypeLength); + + if(return_val == ERROR_FILE_NOT_FOUND) /* no default value, don't display */ + { + RegCloseKey(hInsideKey); + RegCloseKey(hKey); + return 0; + } + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hInsideKey); + RegCloseKey(hKey); + return -2; + } + + fileType = cmd_alloc(fileTypeLength * sizeof(TCHAR)); + + /* obtain actual file type */ + return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, (LPBYTE) fileType, &fileTypeLength); + + RegCloseKey(hInsideKey); + RegCloseKey(hKey); + + if(return_val != ERROR_SUCCESS) + { + cmd_free(fileType); + return -2; + } + + if(fileTypeLength != 0) /* if there is a default key, display relevant information */ + { + ConOutPrintf(_T("%s=%s\r\n"), extension, fileType); + } + + if(fileTypeLength) + cmd_free(fileType); + + return 1; +} + +static INT +PrintAllAssociations() +{ + DWORD return_val = 0; + HKEY hKey = NULL; + DWORD numKeys = 0; + + DWORD extLength = 0; + LPTSTR extName = NULL; + DWORD keyCtr = 0; + + return_val = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ , NULL, &hKey, NULL); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return -1; + } + + return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return -2; + } + + extName = cmd_alloc(extLength * sizeof(TCHAR)); + + for(keyCtr = 0; keyCtr < numKeys; keyCtr++) + { + DWORD buffer_size = extLength; + return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL); + + if(return_val == ERROR_SUCCESS || return_val == ERROR_MORE_DATA) + { + if(*extName == _T('.')) + PrintAssociation(extName); + } + else + { + cmd_free(extName); + RegCloseKey(hKey); + return -1; + } + } + + RegCloseKey(hKey); + + if(extName) + cmd_free(extName); + + return numKeys; +} + +static INT +AddAssociation(LPTSTR extension, LPTSTR type) +{ + DWORD return_val; + HKEY hKey = NULL, insideKey = NULL; + + return_val = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); + + if(return_val != ERROR_SUCCESS) + return -1; + + return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &insideKey, NULL); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return -1; + } + + return_val = RegSetValueEx(insideKey, NULL, 0, REG_SZ, (LPBYTE)type, (_tcslen(type) + 1) * sizeof(TCHAR)); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(insideKey); + RegCloseKey(hKey); + return -2; + } + + RegCloseKey(insideKey); + RegCloseKey(hKey); + return 0; +} + + +static int +RemoveAssociation(LPTSTR extension) +{ + DWORD return_val; + HKEY hKey; + + return_val = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); + + if(return_val != ERROR_SUCCESS) + return -1; + + return_val = RegDeleteKey(hKey, extension); + + if(return_val != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return -2; + } + + RegCloseKey(hKey); + return 0; +} + + + +INT CommandAssoc (LPTSTR param) +{ + + LPTSTR lpEqualSign = NULL; + + /* print help */ + if (!_tcsncmp (param, _T("/?"), 2)) + { + ConOutResPaging(TRUE,STRING_ASSOC_HELP); + return 0; + } + + nErrorLevel = 0; + + if(_tcslen(param) == 0) + PrintAllAssociations(); + else + { + lpEqualSign = _tcschr(param, _T('=')); + if(lpEqualSign != NULL) + { + LPTSTR fileType = lpEqualSign + 1; + LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR)); + + _tcsncpy(extension, param, lpEqualSign - param); + extension[lpEqualSign - param] = (TCHAR)0; + + if(_tcslen(fileType) == 0) + /* if the equal sign is the last character + in the string, then delete the key */ + { + RemoveAssociation(extension); + } + else + /* otherwise, add the key and print out the association*/ + { + AddAssociation( extension, fileType); + PrintAssociation(extension); + } + + cmd_free(extension); + } + else + { + /* no equal sign, print all associations */ + INT retval = PrintAssociation(param); + + if(retval == 0) /* if nothing printed out */ + ConOutResPrintf(STRING_ASSOC_ERROR, param); + } + } + + return 0; +} + +#endif /* INCLUDE_CMD_ASSOC */