diff --git a/cmd_typist.c b/cmd_typist.c index a174a65..15a72be 100644 --- a/cmd_typist.c +++ b/cmd_typist.c @@ -14,6 +14,7 @@ Program Size: 2.8MB #include #include #include +#include //cmdtypist.c: Implementing the main #include"functions_for_cmd_typist.h"//function prototypes and global variables. @@ -26,6 +27,7 @@ Program Size: 2.8MB char argv[5][18]; int main(int argc, char **argv)//argc=command line counter, argv=pointer to pointer to character(command line arguments) { + redirect(); lmt_pg_size(); name_display(); read_message_conf();//welcome message for first time users. diff --git a/cmdtypist b/cmdtypist index 1427411..d6b345d 100755 Binary files a/cmdtypist and b/cmdtypist differ diff --git a/files.h b/files.h index 1ac20eb..f56a4f7 100755 --- a/files.h +++ b/files.h @@ -415,6 +415,48 @@ extern void lmt_pg_size()//limit page size rewind(fp); } } + if(fclose(fp)){ + fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n"); + exit(EXIT_FAILURE); + } +} + +/** + * @param void + * performs a test to make sure cmdtypist has been installed to home directory + * installed? true: it changes the current directory the the home/cmdTypist directory + * false: it gives a warning message with possible fixes and continues + */ +extern void redirect(void) +{ + char idir[62] = ""; + if(getenv("HOME") != NULL) + { + strncpy(idir,getenv("HOME"), 50); + strcat(idir, "/cmdTypist");//installation directory + printf("%s\n", idir); + } + // exit(0); + FILE *fp; + //call script that verifies if program is installed to $home/cmdTypist + char test_dir[60] = ""; + strncpy(test_dir, idir, 50); + strcat(test_dir, "/files.h"); + if((fp=fopen(test_dir,"r")) == NULL) + { + fprintf(stderr, "%s\n", "Program not installed to $HOME/cmdTypist directory\n"); + fprintf(stderr, "\t- %s\n", "Navigate to cmdtypist directory manually, before running it\n"); + fprintf(stderr, "\t- %s\n", "OR uninstall and reinstall a fresh copy\n"); + return; + }else{ + //system(idir); //navigate to installation directory + //change directory + if(chdir(idir) == -1){ + fprintf(stderr, "%s\n", "Error changing directory to $HOME/cmdTypist"); + exit(EXIT_FAILURE); + } + } + if(fclose(fp)){ fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n"); exit(EXIT_FAILURE); diff --git a/installation/install.sh b/installation/install.sh index 99d2895..a7505a8 100755 --- a/installation/install.sh +++ b/installation/install.sh @@ -1,10 +1,10 @@ #!/bin/bash #install cmdtypist -gcc ../cmd_typist.c -o ../cmd_typist && +gcc ../cmd_typist.c -o ../cmdtypist && +sudo cp ../cmdtypist /usr/bin/cmdtypist && +mkdir $HOME/cmdTypist && +cp -r ../ $HOME/cmdTypist/ && sudo cp ../cmdtypist /usr/bin/cmdtypist && -mkdir $HOME/cmdtypist && -cp -r ../ $HOME/cmdtypist/ && -sudo cp ../cmdtypist /usr/bin/ && sudo chmod +x /usr/bin/cmdtypist && (echo "CMDTYPIST successfully compiled and installed, learn how to use cmdtypist commands by running 'cmdtypist --help'"; exit 0) || (c=$?; echo "CMDTYPIST was unable to install: "; (exit $c)) diff --git a/uninstall/uninstall.sh b/uninstall/uninstall.sh index 0716995..342dbdb 100755 --- a/uninstall/uninstall.sh +++ b/uninstall/uninstall.sh @@ -1,6 +1,6 @@ #!/bin/bash #remove cmdtypist and associated files. sudo rm /usr/bin/cmdtypist && -sudo rm -r $HOME/cmdtypist && +sudo rm -r $HOME/cmdTypist && echo "cmdtypist uninstalled" || -echo "unable to install cmdtypist"; exit $? +echo "unable to uninstall cmdtypist"; exit $?