Made restoration files optional

This commit is contained in:
rexy712
2018-12-06 13:37:01 -08:00
parent 8244ebb50b
commit dbfa9b9d12
7 changed files with 73 additions and 32 deletions
+10 -3
View File
@@ -16,12 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h> //fprintf
#include <string.h> //strcmp
#include <stdlib.h> //malloc, free, strtol, atof
#include "cmd.h"
#include "common.h"
#include "config.h"
#define NO_OPT NULL
#define GET_LONG_OPT "--get"
@@ -94,7 +95,9 @@ struct cmd_arg rexbacklight_args[] = {
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_XBACK_OPT, STEPS_DESC},
{GET_LONG_OPT, GET_SHORT_OPT, GET_XBACK_OPT, GET_DESC},
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_XBACK_OPT, LIST_DESC},
#ifdef ENABLE_RESTORE_FILE
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_XBACK_OPT, RESTORE_DESC},
#endif
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_XBACK_OPT, HELP_DESC},
{VERSION_LONG_OPT, NO_OPT, VERSION_XBACK_OPT, VERSION_DESC}
};
@@ -108,7 +111,9 @@ struct cmd_arg rexbacklight_args[] = {
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_DESC},
{GET_LONG_OPT, GET_SHORT_OPT, GET_DESC},
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_DESC},
#ifdef ENABLE_RESTORE_FILE
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_DESC},
#endif
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_DESC},
{VERSION_LONG_OPT, NO_OPT, VERSION_DESC}
};
@@ -202,9 +207,11 @@ struct arg_values process_cmd_args(int argc, char** argv){
ret.next = NULL;
return ret;
}
#ifdef ENABLE_RESTORE_FILE
else if(CHECK_OPTION(RESTORE, argv[i])){
ret.operation = OP_RESTORE;
}
#endif
else if(!strcmp(argv[i], "max")){
curr->operation = OP_SET;
curr->delta = 100;
+1
View File
@@ -22,6 +22,7 @@
#include "globals.h"
#include <stdio.h> //printf
#include <stdlib.h> //exit
int return_value = RETVAL_SUCCESS;
+4 -3
View File
@@ -16,12 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h> //strcmp
#include <stdio.h> //printf
#include <string.h> //strcmp, strlen
#include <rjp.h>
#include <sys/types.h> //struct passwd
#include <sys/types.h> //getpwnam
#include <pwd.h> //getpwnam
#include <unistd.h> //chdir
#include <stdlib.h> //malloc, free
#include "restore.h"
#include "common.h"
+33 -12
View File
@@ -16,22 +16,24 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//Needed for usleep to work
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/time.h>
#include <time.h>
#include <rjp.h>
#include <stdio.h> //fprintf
#include <stdlib.h> //malloc, free
#include <string.h> //strlen, strcpy
#include <unistd.h> //chdir
#include <sys/types.h> //opendir
#include <dirent.h> //opendir
#include <sys/time.h> //gettimeofday
#include <time.h> //nanosleep
#include "common.h"
#include "cmd.h"
#include "restore.h"
#include "globals.h"
#include "config.h"
#ifdef ENABLE_RESTORE_FILE
#include <rjp.h>
#include "restore.h"
#endif
//name of the program being run so that we print the correct name in the usage
@@ -240,6 +242,7 @@ int individual_device_op(struct arg_values* curr){
return return_value;
}
#ifdef ENABLE_RESTORE_FILE
//If devices were specified, this function will run
void individual_device_loop(struct arg_values* a){
struct arg_values* curr;
@@ -258,6 +261,18 @@ void individual_device_loop(struct arg_values* a){
}
rjp_free_value(root);
}
#else
//If devices were specified, this function will run
void individual_device_loop(struct arg_values* a){
struct arg_values* curr;
int try_restore = 1;
for(curr = a->next;curr;curr = curr->next){
return_value = individual_device_op(curr);
if(return_value == RETVAL_INTERNAL_ERROR)
return;
}
}
#endif
//If no devices were specified, this function will run
@@ -280,7 +295,9 @@ void all_device_loop(struct string_array* device_names, struct arg_values* args)
return;
}
}
#ifdef ENABLE_RESTORE_FILE
save_restore_file(device_names);
#endif
break;
case OP_LIST:
do_list(device_names);
@@ -300,9 +317,11 @@ void all_device_loop(struct string_array* device_names, struct arg_values* args)
}
}
break;
#ifdef ENABLE_RESTORE_FILE
case OP_RESTORE:;
all_restore();
break;
#endif
default:
fprintf(stderr, "Internal processing error!\n");
break;
@@ -365,7 +384,9 @@ int main(int argc, char** argv){
//Run selected operation
if(args.next){
individual_device_loop(&args);
#ifdef ENABLE_RESTORE_FILE
save_restore_file(&device_names);
#endif
}else{
all_device_loop(&device_names, &args);
}