home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- *** Install.cmm for DOS 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 DOS at the command line. ***
- *************************************************************************/
-
- if defined(_DOS_)
- ExeName = "CEnviD.exe"
- else if defined(_DOS32_)
- ExeName = "CEnviD32.exe"
- else {
- puts("This INSTALL.CMM is for the DOS and 32-bit DOS versions")
- puts("of CEnvi. You are not running one of those versions.\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]);
-
- Install(InstallDirectory,"AUTOEXEC.BAT","AUTOEXEC.BAK");
-
- puts("\nFinished installing CEnvi For DOS!");
- 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, assume
- // CEnvi.exe is also in the same directory.
-
- // 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,pFileName,pBackupFileName)
- {
- // append the PATH statement so that it contains this directory.
- // Add the CMMPATH environment variable if the user decides to.
- // If they choose not to, tell them what they must do by hand.
- printf("\nIf you choose, install will add the directory:\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 to the CMMPATH environment variable.\n",Dir);
- printf("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.",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)
- if ( AlterEVarLine(line,"PATH",Dir) )
- SetPath = True;
- if ( AlterEVarLine(line,"CMMPATH",Dir) )
- {
- sprintf(line,"set CMMPATH=%s",Dir);
- 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",Dir);
- fclose(dest);
-
- // Now, alter the environment variable so there is no need to
- // reboot the system
- if(!defined(PATH))
- strcpy(PATH,"\0");
- // always clean out CMMPATH
- strcpy(CMMPATH,"\0");
-
- strcat(PATH,";");
- strcat(PATH,Dir);
- strcat(CMMPATH,Dir);
-
-
- 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\n",ExeName);
- printf("this CEnvi 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);
- }
- }
-
-