2020 #######################################################################################
2121 Author: NerdOfCode
2222 License: Apache-2.0
23- Updated on: 10/28 /18
23+ Updated on: 11/1 /18
2424 #######################################################################################
2525
2626 #########################################################
@@ -186,7 +186,7 @@ int main ( int argc, char argv[64] ){
186186 parseCommand (input );
187187 }
188188 }
189- //Start the clean up b4 exit
189+ //Start the clean up before exit
190190 clean_up ();
191191
192192 //Start to free dynamically allocated memory
@@ -208,7 +208,7 @@ void change_to_home_dir( void ){
208208 short int ret = 0 ;
209209
210210 char current_user_home [64 ] = "/home/" ;
211- strncat (current_user_home ,logged_in_user ,sizeof (current_user_home ) + sizeof ( logged_in_user ) );
211+ strncat (current_user_home ,logged_in_user ,sizeof (current_user_home ));
212212
213213 //chdir() return -1 on error and 0 on success
214214 ret = chdir (current_user_home );
@@ -336,6 +336,7 @@ int check_empty_beginning(char input[64]){
336336
337337 //We'll hold off if it is only one space...
338338 if (input [0 ] == ' ' ){
339+ //If user puts two spaces before a command... GO ahead and let them know it's not found...
339340 if (input [1 ] == ' ' ){
340341 puts ("Command not found..." );
341342 return -2 ;
@@ -347,19 +348,19 @@ int check_empty_beginning(char input[64]){
347348
348349int parseCommand (char input [64 ]){
349350
350- char * filename_ptr ;
351- char * command_ptr ;
351+ char * pfilename ;
352+ char * pcommand ;
352353 bool command_args = FALSE;
353354 int command_status = 0 ;
354355
355- //The command_ptr is for the user input but without any arguments attached
356+ //The pcommand is for the user input but without any arguments attached
356357
357358 //Dynamic memory allocation
358- filename_ptr = malloc (64 * sizeof (char ));
359- command_ptr = malloc (64 * sizeof (char ));
359+ pfilename = malloc (64 * sizeof (char ));
360+ pcommand = malloc (64 * sizeof (char ));
360361
361362 //Check for any allocation errors before saving input
362- if (filename_ptr == NULL || command_ptr == NULL ){
363+ if (pfilename == NULL || pcommand == NULL ){
363364 fprintf (stderr , RED_TEXT "Failed to fork... Not enough memory...\n" RESET );
364365 return -1 ;
365366 }
@@ -383,7 +384,7 @@ int parseCommand(char input[64]){
383384 //Remove all arguments
384385 for (int i = 0 ; i <= strlen (input ); ++ i ){
385386 if (input [i ] != ' ' ){
386- command_ptr [i ] = input [i ];
387+ pcommand [i ] = input [i ];
387388 command_args = TRUE;
388389 }else {
389390 command_args = FALSE;
@@ -392,52 +393,52 @@ int parseCommand(char input[64]){
392393
393394 }
394395
395- //Obliterate filename_ptr
396+ //Obliterate pfilename
396397 //And check if command exists relative to its filename
397- memset (filename_ptr , 0 , sizeof (filename_ptr ));
398- strncat (filename_ptr ,CMD_BIN , sizeof (CMD_BIN ) + sizeof (filename_ptr ));
399- strncat (filename_ptr , command_ptr , sizeof (filename_ptr ) + sizeof (command_ptr ));
398+ memset (pfilename , 0 , sizeof (pfilename ));
399+ strncat (pfilename ,CMD_BIN , sizeof (CMD_BIN ) + sizeof (pfilename ));
400+ strncat (pfilename , pcommand , sizeof (pfilename ) + sizeof (pcommand ));
400401
401402 //Only remove newline if command has arguments
402403 if (command_args ){
403- filename_ptr [strlen (filename_ptr )- 1 ] = '\0' ;
404+ pfilename [strlen (pfilename )- 1 ] = '\0' ;
404405 }
405406
406- command_ptr [strlen (command_ptr )- 1 ] = '\0' ;
407+ pcommand [strlen (pcommand )- 1 ] = '\0' ;
407408 input [strlen (input )- 1 ] = '\0' ;
408409
409410 //TEMPORARY FIX!!! 4/20/18
410411 //SPECIAL CASE: If command is cd, give a heads up to update the cwd
411- if (strncmp (command_ptr ,"c" , sizeof (command_ptr )) == 0 ){
412+ if (strncmp (pcommand ,"c" , sizeof (pcommand )) == 0 ){
412413 update_new_cd (1 );
413414 }
414415
415416 //If command or rather file is found, proceed
416- if (access (filename_ptr , F_OK ) == 0 ){
417+ if (access (pfilename , F_OK ) == 0 ){
417418 //Since the command exists we can try running the arguments the user has provided
418419 //Check if args and no args are different
419- if (input != command_ptr ){
420+ if (input != pcommand ){
420421
421422 //Reset to default users args
422- memset (filename_ptr , 0 , 64 );
423- strncat (filename_ptr , CMD_BIN , sizeof (CMD_BIN ) + sizeof (filename_ptr ));
424- strncat (filename_ptr , input , sizeof (CMD_BIN ) + sizeof (filename_ptr ));
425- if (system (filename_ptr ) == -1 )
423+ memset (pfilename , 0 , 64 );
424+ strncat (pfilename , CMD_BIN , sizeof (CMD_BIN ) + sizeof (pfilename ));
425+ strncat (pfilename , input , sizeof (CMD_BIN ) + sizeof (pfilename ));
426+ if (system (pfilename ) == -1 )
426427 if (DEBUG )
427- printf ("Error executing: %s\n" ,filename_ptr );
428+ printf ("Error executing: %s\n" ,pfilename );
428429 }else {
429- if (system (filename_ptr ) == -1 )
430+ if (system (pfilename ) == -1 )
430431 if (DEBUG )
431- printf ("Error executing: %s\n" ,filename_ptr );
432+ printf ("Error executing: %s\n" ,pfilename );
432433 }
433434 }else {
434435 //TODO
435436
436437 //Check if command is an alias
437438
438- if (access (filename_ptr , F_OK ) == 0 ){
439+ if (access (pfilename , F_OK ) == 0 ){
439440
440- if (system (filename_ptr ) == -1 )
441+ if (system (pfilename ) == -1 )
441442 if (DEBUG )
442443 puts ("Error checking alias." );
443444
@@ -447,16 +448,16 @@ int parseCommand(char input[64]){
447448 if (DEBUG ){
448449 //Will show the pathway to file
449450 //We can safely ignore return value
450- int xyz = system (filename_ptr );
451+ int xyz = system (pfilename );
451452 }
452453 }
453454 }
454455
455456
456457 //Reset variables
457458 command_args = FALSE;
458- memset (filename_ptr , 0 , sizeof (filename_ptr ));
459- memset (command_ptr , 0 , sizeof (command_ptr ));
459+ memset (pfilename , 0 , sizeof (pfilename ));
460+ memset (pcommand , 0 , sizeof (pcommand ));
460461 memset (input , 0 , 64 );
461462
462463 return 0 ;
@@ -551,6 +552,7 @@ int log_command(char *command){
551552 fclose (fptr );
552553}
553554
555+
554556//Basically give the user a heads up that the admin is using logging tools and whatnot
555557//Also, since this function is most likely going to be run when the shell is activated,
556558//We will need to clear the screen
0 commit comments