home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
INSTALL.CMM
< prev
next >
Wrap
Text File
|
1996-02-12
|
10KB
|
259 lines
/*************************************************************************
*** Install.cmm for OS/2 ver.1 ***
*** This is the installation program to set up CEnvi unregistered ***
*** shareware on your computer. Before running this program, CEnvi ***
*** must be copied to a hard disk directory. This Install.cmm ***
*** program should be run from CEnvi for OS/2 at the command line. ***
*************************************************************************/
if defined(_OS2_)
ExeName = "CEnvi2.exe"
else {
puts("This INSTALL.CMM is for the OS/2 version of CEnvi.");
puts("You are not running this version.\a");
exit(EXIT_FAILURE);
}
main(argc,argv)
{
// There should be no input args. If there are then the user needs help.
ScreenClear();
if ( argc != 1 )
GiveInstructionsAndExit();
// Get the current directory. The GetInstallDirectory() function assures
// that it is not a floppy.
InstallDirectory = GetInstallDirectory(argv[0]);
// Make the all directory based on the install directory
strcpy(allDirectory,InstallDirectory);
while((allDirectory[length = strlen(allDirectory) - 1]!='\\')&&(length!=0))
allDirectory[length] = '\0';
strcat(allDirectory,"ALL");
Install(InstallDirectory,allDirectory,"CONFIG.SYS","CONFIG.BAK");
puts("\nFinished installing CEnvi For OS/2!");
puts("\n<Press any key to continue>\n");
getch();
}
GiveInstructionsAndExit() // Show some info about using this program
{ // and then exit this program. Do not return.
printf("Install.cmm - CEnvi installation procedure. Execute with no parameters\n");
printf(" from the directory that contains %s and also contains\n",ExeName);
printf(" the *.cmm and other sample CEnvi files, including Install.cmm\n");
exit(EXIT_FAILURE);
}
GetInstallDirectory(Executable) // return current dir that is not on a floppy
{
// current source directory from the name of the executable
CurDir = SplitFileName(FullPath(Executable)).dir;
assert( CurDir != NULL && CurDir[0] != 0 );
// check that current directory is not floppy A: or B:
if ( CurDir[0] == 'A' || CurDir[0] == 'B' ) {
printf("\nCannot install CEnvi from a floppy.\n\a\n");
GiveInstructionsAndExit();
}
// Have found the directory Install.cmm is in, and so check that
// CEnvi.exe is also in the same directory.
if ( NULL == Directory(strcat(strcpy(temp,CurDir),ExeName)) ) {
printf("\nThis installation assumes that %s is in the same directory as\n",ExeName);
printf("Install.cmm. Could not find %s in the Install.cmm directory.\n\a\n",ExeName);
GiveInstructionsAndExit();
}
// remove extra backslash if at end of name (i.e., not root directory)
if ( strcmp(CurDir+1,":\\") )
CurDir[strlen(CurDir)-1] = 0;
// return the result
return(CurDir);
}
Fatal(Format) // like printf() but also beeps and exits program
{
va_start(parameters,Format);
printf("\a\n"); // beep
vprintf(Format,parameters);
exit(EXIT_FAILURE);
}
GetYesOrNo() // prompt for Yes or No, and return entered boolean TRUE
{ // if YES else FALSE if NO.
printf(" (Y/N) ");
while( TRUE ) { // forever
key = toupper(getch());
if ( key != 'Y' && key != 'N' )
printf("\a"); // beep
else
break;
}
printf("%c\n",key);
return( key == 'Y' );
}
CopyFile(Source,Destination) // copy file from source to destination
{
system("copy %s %s > NUL:",Source,Destination);
}
SkipWhitespace(str)
{
while( isspace(str[0]) )
str++;
}
AlreadyInPath(Dir,Path) // search through path for this Dir, return True if found, else False
{
len = strlen(Dir)
p = Path;
do {
if ( 0 == strnicmp(p,Dir,len) && (p[len]==0 || p[len]==';') )
return(True)
p = strchr(p,';')
} while( p++ != NULL )
return(False)
}
AlterEVarLine(text,EVar,Dir)
// If this text is a line setting the EVar environment variable, and if
// Dir is not already in it, then add Dir. Return TRUE if this is
// a line for EVar, and False if it is not.
{
FoundEVar = FALSE; // assume this is not the line
// determine if text is of the type "EVAR=" or "set EVAR="
SkipWhitespace(c = text);
// if the next statement is "SET" then skip it
if ( !strncmpi(c,"SET",3) ) {
// Skip beyond the SET statement
c += 3;
SkipWhitespace(c);
}
// test if this next part is the variable name
EVarLen = strlen(EVar);
if ( !strncmpi(c,EVar,EVarLen) ) {
c += EVarLen;
if ( isspace(c[0]) || c[0] == '=' ) {
// THIS IS IT. This line describes the EVar.
SkipWhitespace(c);
if ( c[0] == '=' ) {
c++;
SkipWhitespace(c);
}
FoundEVar = TRUE;
// If Dir is not already in this line then add Dir at the end.
// Check each dir as value between semicolons (;)
SkipWhitespace(c);
if ( !AlreadyInPath(Dir,c) ) {
// add this to the end of the existing path
if ( c[strlen(c)-1] != ';' )
strcat(c,";");
strcat(c,Dir);
}
}
}
return(FoundEVar);
}
Install(Dir,allDirectory,pFileName,pBackupFileName)
{
// set up the profile string
sprintf(profileString,"%s;%s",Dir,allDirectory);
// append the PATH statement so that it contains this directory, and
// also add the CMMPATH environment variable. But give user a choice
// of whether to do this first; if they choose not to then tell them
// what they must do by hand.
printf("\nIf you choose, install will add:\n\n");
printf(" \"%s\"\n\n",Dir);
printf("to the PATH environment variable in your %s file. Install will also\n",pFileName);
printf("add %s and %s to the CMMPATH environment variable in\n",Dir,allDirectory);
printf("that file. If you select to make these changes to %s, then\n",pFileName);
printf("install will backup the current version of %s to %s.\n",pFileName,pBackupFileName);
printf("\n\nShould these changes be made to %s?",pFileName);
if ( GetYesOrNo() ) {
do
{
printf("\nEnter drive letter for the booted %s file: ",pFileName);
DriveLetter = getche();
printf("\n");
if ( !isalpha(DriveLetter) )
{
printf("\aInvalid drive letter %c!\n",DriveLetter);
}
else
{
sprintf(lFileName,"%c:\\%s",DriveLetter,pFileName);
sprintf(lBackupFileName,"%c:\\%s",DriveLetter,pBackupFileName);
src = fopen(lFileName,"rt");
if ( src == NULL )
printf("Could not open source file \"%s\" for reading.\n",lFileName);
else
fclose(src);
}
} while(!isalpha(DriveLetter) || (src == NULL));
printf("Making changes to %s...",lFileName);
// user chose to make automatic changes. Do so now
CopyFile(lFileName,lBackupFileName);
// will now read the backup file, and if any PATH or CMMPATH line is
// encountered then will alter it, else just copy line exactly.
src = fopen(lBackupFileName,"rt");
if ( src == NULL )
Fatal("Could not open source file \"%s\" for reading.",lBackupFileName);
dest = fopen(lFileName,"wt");
if ( dest == NULL )
Fatal("Could not open source file \"%s\" for reading.",lBackupFileName);
SetPath = SetCmmPath = False;
while ( NULL != (line = fgets(src)) ) {
// remove the pesky newline if there is one
if ( PeskyNewLine = (line[strlen(line)-1] == '\n') )
line[strlen(line)-1] = 0;
if ( SetPath == FALSE && AlterEVarLine(line,"PATH",Dir) )
SetPath = True;
if ( AlterEVarLine(line,"CMMPATH",Dir) )
{
sprintf(line,"set CMMPATH=%s;%s",Dir,AllDirectory);
SetCmmPath = True;
}
fputs(line,dest);
if ( PeskyNewLine )
fputs("\n",dest);
}
fclose(src);
// if haven't already written PATH or CMMPATH, then do so now
if ( !SetPath )
fprintf(dest,"\nSET PATH=%s\n",Dir);
if ( !SetCmmPath )
fprintf(dest,"\nSET CMMPATH=%s\n",profileString);
fclose(dest);
printf("\n%s has been altered.\n",lFileName);
printf("Changes will take effect after you reboot.\n");
} else {
// user choose not to automatically install, so describe what the user
// needs to do by hand to make it work.
ScreenClear();
printf("\nThe PATH environment variable is used to find executable files, such as\n");
printf("%s, and batch files, such as those included in this CEnvi\n",ExeName);
printf("unregistered shareware release. The CMMPATH environment variable is\n");
printf("used by CEnvi to find common source code that may be included\n");
printf("in other CEnvi source files.\n\n");
printf("You chose not to have Install automatically alter %s.\n\n",pFileName);
printf("You may wish to try Install.cmm again, or to make these modifications\n");
printf("to %s by hand.\n",pFileName);
}
}