summaryrefslogtreecommitdiffstats
path: root/private/sdktools/alias
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/sdktools/alias
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/sdktools/alias')
-rw-r--r--private/sdktools/alias/alias.c509
-rw-r--r--private/sdktools/alias/alias.rc11
-rw-r--r--private/sdktools/alias/makefile6
-rw-r--r--private/sdktools/alias/sources42
4 files changed, 568 insertions, 0 deletions
diff --git a/private/sdktools/alias/alias.c b/private/sdktools/alias/alias.c
new file mode 100644
index 000000000..14b9aa045
--- /dev/null
+++ b/private/sdktools/alias/alias.c
@@ -0,0 +1,509 @@
+/*++
+
+Copyright (c) 1990 Microsoft Corporation
+
+Module Name:
+
+ alias.c
+
+Abstract:
+
+ alias utility
+
+Author:
+
+ Therese Stowell (thereses) 22-Mar-1990
+
+Revision History:
+
+--*/
+
+#include <windows.h>
+#include "..\..\windows\inc\conapi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <cvtoem.h>
+
+BOOL fVerbose;
+
+DWORD
+DisplayAliases(
+ char *ExeName
+ );
+
+DWORD
+DisplayAlias(
+ LPSTR AliasName,
+ LPSTR ExeName
+ );
+
+DWORD
+DoAliasFile(
+ char * FileName,
+ char * ExeName,
+ BOOL fDelete
+ );
+
+DWORD
+DoAlias(
+ char *Source,
+ char *Target,
+ char *ExeName
+ );
+
+void
+usage( void )
+{
+ fprintf( stderr, "Usage: ALIAS [-v] [-p programName] [-f filespec] [<source> <target>]\n" );
+ fprintf( stderr, " [-v] means verbose output.\n" );
+ fprintf( stderr, " [-d] means delete aliases.\n" );
+ fprintf( stderr, " [-p programName] specifies which image file name these alias\n" );
+ fprintf( stderr, " definitions are for. Default is CMD.EXE\n" );
+ fprintf( stderr, " [-f filespec] specifies a file which contains the alises.\n" );
+ exit( 1 );
+}
+
+DWORD
+DoAlias(
+ char *Source,
+ char *Target,
+ char *ExeName
+ )
+{
+ if (!AddConsoleAlias( Source, Target, ExeName )) {
+ if (!Target) {
+ fprintf( stderr,
+ "ALIAS: Unable to delete alias - %s\n",
+ Source,
+ Target
+ );
+ }
+ else {
+ fprintf( stderr,
+ "ALIAS: Unable to add alias - %s = %s\n",
+ Source,
+ Target
+ );
+ }
+
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
+ else
+ if (fVerbose) {
+ if (!Target) {
+ fprintf( stderr, "Deleted alias - %s\n", Source );
+ }
+ else {
+ fprintf( stderr, "Added alias - %s = %s\n", Source, Target );
+ }
+ }
+
+ return NO_ERROR;
+}
+
+
+DWORD
+DoAliasFile(
+ char * FileName,
+ char * ExeName,
+ BOOL fDelete
+ )
+{
+ DWORD rc;
+ FILE *fh;
+ char LineBuffer[ 256 ], *Source, *Target, *s;
+
+ if (!(fh = fopen( FileName, "rt" ))) {
+ fprintf( stderr, "ALIAS: Unable to open file - %s\n", FileName );
+ return ERROR_FILE_NOT_FOUND;
+ }
+
+ if (fVerbose) {
+ fprintf( stderr,
+ "ALIAS: %s aliases defined in %s\n",
+ fDelete ? "Deleting" : "Loading",
+ FileName
+ );
+ }
+ while (s = fgets( LineBuffer, sizeof( LineBuffer ), fh )) {
+ while (*s <= ' ') {
+ if (!*s) {
+ break;
+ }
+ s++;
+ }
+
+ if (!*s || (*s == '/' && s[1] == '/')) {
+ continue;
+ }
+
+ Source = s;
+ while (*s > ' ') {
+ s++;
+ }
+ *s++ = '\0';
+
+ while (*s <= ' ') {
+ if (!*s) {
+ break;
+ }
+ s++;
+ }
+
+ Target = s;
+ s += strlen( s );
+ while (*s <= ' ') {
+ *s-- = '\0';
+ if (s < Target) {
+ break;
+ }
+ }
+
+ rc = DoAlias( Source, fDelete ? NULL : Target, ExeName );
+ if (rc != NO_ERROR) {
+ break;
+ }
+ }
+
+ return rc;
+}
+
+DWORD
+DisplayAlias(
+ LPSTR AliasName,
+ LPSTR ExeName
+ )
+{
+ DWORD cb;
+ CHAR AliasBuffer[512];
+
+ if (cb = GetConsoleAlias( AliasName, AliasBuffer, sizeof( AliasBuffer ), ExeName )) {
+ printf( "%-16s=%s\n", AliasName, AliasBuffer );
+ return NO_ERROR;
+ }
+ else {
+ printf( "%-16s *** Unable to read value of alias ***\n",
+ AliasName
+ );
+ return ERROR_ENVVAR_NOT_FOUND;
+ }
+}
+
+int _CRTAPI1
+CmpNamesRoutine(
+ const VOID *Element1,
+ const VOID *Element2
+ )
+{
+ return( strcmp( *(LPSTR *)Element1, *(LPSTR *)Element2 ) );
+}
+
+DWORD
+DisplayAliases(
+ char *ExeName
+ )
+{
+ DWORD cb, rc, nExeNames, nAliases, iExeName, iAlias;
+ LPSTR FreeMem1, FreeMem2, AliasName, AliasValue, s, *SortedExeNames, *SortedAliasNames;
+
+ if (ExeName == NULL) {
+ cb = GetConsoleAliasExesLength();
+ if (cb == 0) {
+ return ERROR_ENVVAR_NOT_FOUND;
+ }
+
+ if (!(FreeMem1 = malloc( cb+2 ))) {
+ fprintf( stderr, "ALIAS: Not enough memory for EXE names.\n" );
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
+
+ ExeName = FreeMem1;
+ if (!GetConsoleAliasExes( ExeName, cb )) {
+ fprintf( stderr, "ALIAS: Unable to read alias EXE names.\n" );
+ return ERROR_ENVVAR_NOT_FOUND;
+ }
+
+ ExeName[ cb ] = '\0';
+ ExeName[ cb+1 ] = '\0';
+
+ nExeNames = 0;
+ s = ExeName;
+ while (*s) {
+ _strupr( s );
+ nExeNames++;
+ while (*s++) {
+ }
+ }
+
+ SortedExeNames = malloc( nExeNames * sizeof( LPSTR ) );
+ if (SortedExeNames == NULL) {
+ fprintf( stderr, "ALIAS: Not enough memory to sort .EXE names.\n" );
+ }
+ else {
+ iExeName = 0;
+ s = ExeName;
+ while (*s) {
+ SortedExeNames[ iExeName++ ] = s;
+ while (*s++) {
+ }
+ }
+
+ qsort( SortedExeNames,
+ nExeNames,
+ sizeof( LPSTR ),
+ CmpNamesRoutine
+ );
+
+ iExeName = 0;
+ }
+
+ }
+ else {
+ SortedExeNames = NULL;
+ FreeMem1 = NULL;
+ }
+
+ rc = NO_ERROR;
+ while (rc == NO_ERROR && *ExeName) {
+ if (SortedExeNames != NULL) {
+ ExeName = SortedExeNames[ iExeName++ ];
+ }
+
+ cb = GetConsoleAliasesLength(ExeName);
+ if (cb == 0) {
+ printf( "No aliases defined for %s in current console.\n", ExeName );
+ }
+ else {
+ if (!(FreeMem2 = malloc( cb+2 ))) {
+ fprintf( stderr, "ALIAS: Not enough memory for alias names.\n" );
+ rc = ERROR_NOT_ENOUGH_MEMORY;
+ break;
+ }
+
+ SortedAliasNames = NULL;
+ AliasName = FreeMem2;
+ if (GetConsoleAliases( AliasName, cb, ExeName )) {
+ AliasName[ cb ] = '\0';
+ AliasName[ cb+1 ] = '\0';
+ nAliases = 0;
+ s = AliasName;
+ while (*s) {
+ nAliases++;
+ while (*s++) {
+ }
+ }
+
+ SortedAliasNames = malloc( nAliases * sizeof( LPSTR ) );
+ if (SortedAliasNames == NULL) {
+ fprintf( stderr, "ALIAS: Not enough memory to sort alias names.\n" );
+ }
+ else {
+ iAlias = 0;
+ s = AliasName;
+ while (*s) {
+ SortedAliasNames[ iAlias++ ] = s;
+ while (*s++) {
+ }
+ }
+
+ qsort( SortedAliasNames,
+ nAliases,
+ sizeof( LPSTR ),
+ CmpNamesRoutine
+ );
+
+ iAlias = 0;
+ }
+
+ printf( "Dumping all defined aliases for %s.\n", ExeName );
+ while (*AliasName) {
+ if (SortedAliasNames != NULL) {
+ AliasName = SortedAliasNames[ iAlias++ ];
+ }
+ AliasValue = AliasName;
+
+ while (*AliasValue) {
+ if (*AliasValue == '=') {
+ *AliasValue++ = '\0';
+ break;
+ }
+ else {
+ AliasValue++;
+ }
+ }
+
+ printf( " %-16s=%s\n", AliasName, AliasValue );
+ if (SortedAliasNames != NULL) {
+ if (iAlias < nAliases) {
+ AliasName = " ";
+ }
+ else {
+ AliasName = "";
+ }
+ }
+ else {
+ AliasName = AliasValue;
+ while (*AliasName++) {
+ ;
+ }
+ }
+ }
+ }
+ else {
+ fprintf( stderr, "ALIAS: unable to read aliases for %s.\n", ExeName );
+ rc = ERROR_ENVVAR_NOT_FOUND;
+ }
+
+ free( FreeMem2 );
+ if (SortedAliasNames != NULL) {
+ free( SortedAliasNames );
+ }
+ }
+
+ if (SortedExeNames != NULL) {
+ if (iExeName < nExeNames) {
+ ExeName = " ";
+ }
+ else {
+ ExeName = "";
+ }
+ }
+ else {
+ while (*ExeName++) {
+ ;
+ }
+ }
+ }
+
+ if (SortedExeNames != NULL) {
+ free( SortedExeNames );
+ }
+
+ if (FreeMem1) {
+ free( FreeMem1 );
+ }
+
+ return rc;
+}
+
+DWORD _CRTAPI1
+main(
+ int argc,
+ char *argv[]
+ )
+{
+ DWORD rc;
+ char *s, *s1, *AliasName;
+ char *ExeName;
+ BOOL fDelete;
+ BOOL DisplayAllAliases;
+
+ ConvertAppToOem( argc,argv );
+ AliasName = NULL;
+ ExeName = NULL;
+ fVerbose = FALSE;
+ fDelete = FALSE;
+ DisplayAllAliases = TRUE;
+ rc = NO_ERROR;
+ while (rc == NO_ERROR && --argc) {
+ s = *++argv;
+ if (*s == '-' || *s == '/') {
+ while (*++s) {
+ switch( *s ) {
+ case '?':
+ case 'h':
+ case 'H':
+ usage();
+ break;
+
+ case 'd':
+ case 'D':
+ fDelete = TRUE;
+ break;
+
+ case 'v':
+ case 'V':
+ fVerbose = TRUE;
+ break;
+
+ case 'p':
+ case 'P':
+ if (!--argc) {
+ fprintf( stderr, "ALIAS: Argument to -p switch missing.\n" );
+ usage();
+ }
+
+ if (ExeName != NULL) {
+ free( ExeName );
+ ExeName = NULL;
+ }
+ s1 = *++argv;
+ ExeName = calloc( 1, strlen( s1 )+2 );
+ strcpy( ExeName, s1 );
+ break;
+
+ case 'f':
+ case 'F':
+ if (!--argc) {
+ fprintf( stderr, "ALIAS: Argument to -f switch missing.\n" );
+ usage();
+ }
+
+ DisplayAllAliases = FALSE;
+ rc = DoAliasFile( *++argv, ExeName ? ExeName : "CMD.EXE", fDelete );
+ break;
+
+ default:
+ fprintf( stderr, "ALIAS: invalid switch /%c\n", *s );
+ usage();
+ break;
+ }
+ }
+ }
+ else {
+ DisplayAllAliases = FALSE;
+ if (AliasName == NULL) {
+ if (fDelete) {
+ rc = DoAlias( s, NULL, ExeName ? ExeName : "CMD.EXE" );
+ }
+ else {
+ AliasName = s;
+ }
+ }
+ else {
+ if (fDelete) {
+ rc = DoAlias( AliasName, NULL, ExeName ? ExeName : "CMD.EXE" );
+ AliasName = s;
+ }
+ else {
+ rc = DoAlias( AliasName, s, ExeName ? ExeName : "CMD.EXE" );
+ AliasName = NULL;
+ }
+ }
+ }
+ }
+
+ if (rc == NO_ERROR) {
+ if (AliasName != NULL) {
+ if (fDelete) {
+ rc = DoAlias( AliasName, NULL, ExeName ? ExeName : "CMD.EXE" );
+ }
+ else {
+ rc = DisplayAlias( AliasName, ExeName ? ExeName : "CMD.EXE" );
+ }
+ }
+ else
+ if (DisplayAllAliases) {
+ rc = DisplayAliases( ExeName );
+ }
+ }
+
+ if (ExeName != NULL) {
+ free( ExeName );
+ ExeName = NULL;
+ }
+
+ exit( rc );
+ return rc;
+}
diff --git a/private/sdktools/alias/alias.rc b/private/sdktools/alias/alias.rc
new file mode 100644
index 000000000..b5d35381c
--- /dev/null
+++ b/private/sdktools/alias/alias.rc
@@ -0,0 +1,11 @@
+#include <windows.h>
+#include <ntverp.h>
+
+#define VER_FILETYPE VFT_APP
+#define VER_FILESUBTYPE VFT2_UNKNOWN
+#define VER_FILEDESCRIPTION_STR "Microsoft\256 Cmd Line Alias Utility"
+
+#define VER_INTERNALNAME_STR "ALIAS.EXE"
+#define VER_ORIGINALFILENAME_STR "ALIAS.EXE"
+
+#include <common.ver>
diff --git a/private/sdktools/alias/makefile b/private/sdktools/alias/makefile
new file mode 100644
index 000000000..6ee4f43fa
--- /dev/null
+++ b/private/sdktools/alias/makefile
@@ -0,0 +1,6 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/sdktools/alias/sources b/private/sdktools/alias/sources
new file mode 100644
index 000000000..772800fe8
--- /dev/null
+++ b/private/sdktools/alias/sources
@@ -0,0 +1,42 @@
+!IF 0
+
+Copyright (c) 1989 Microsoft Corporation
+
+Module Name:
+
+ sources.
+
+Abstract:
+
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+
+Author:
+
+ Steve Wood (stevewo) 12-Apr-1990
+
+NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
+
+!ENDIF
+
+MAJORCOMP=sdktools
+MINORCOMP=alias
+
+TARGETNAME=alias
+TARGETPATH=obj
+TARGETTYPE=PROGRAM
+
+INCLUDES=..\ztools\inc
+
+SOURCES=alias.c alias.rc
+
+MSC_WARNING_LEVEL=/W3 /WX
+
+C_DEFINES=-D_OS2_20_=0 -Dnear= -Dfar= -Dpascal=
+
+UMTYPE=console
+UMLIBS=..\ztools\src\obj\*\ztools.lib \
+ $(BASEDIR)\public\sdk\lib\*\user32.lib