comparison cmd.c @ 13:cf81eb0c2d5a

Warn before quitting if there are unsaved changes If there are unsaved changes emit a warning when the quit command is used. Only quit if the quit command is used twice with no other command in between. Add a new Quit command which immediatly quits pwm without a warning.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon, 07 Aug 2017 16:59:47 +0200
parents 8768fbd09bc5
children a01899a6e4bb
comparison
equal deleted inserted replaced
12:8768fbd09bc5 13:cf81eb0c2d5a
170 { "ch", "changepassword", "changepassword", "Change password", 170 { "ch", "changepassword", "changepassword", "Change password",
171 cmd_changepassword }, 171 cmd_changepassword },
172 { "h", "help", "help", "Show help text", cmd_help }, 172 { "h", "help", "help", "Show help text", cmd_help },
173 { "w", "write", "write", "Write the database", cmd_write }, 173 { "w", "write", "write", "Write the database", cmd_write },
174 { "q", "quit", "quit", "Quit", cmd_quit }, 174 { "q", "quit", "quit", "Quit", cmd_quit },
175 { "Q", "Quit", "Quit", "Quit without checking", cmd_quit },
175 { 0 } 176 { 0 }
176 }; 177 };
177 178
178 static int 179 static int
179 parse_arg(char *arg, const char *namev[], int sep, char **valuep) 180 parse_arg(char *arg, const char *namev[], int sep, char **valuep)
909 { 910 {
910 if (argc != 1) { 911 if (argc != 1) {
911 return (CMD_USAGE); 912 return (CMD_USAGE);
912 } 913 }
913 914
915 if ((argv[0][0] == 'q') && ctx->unsaved_changes &&
916 (ctx->prev_cmd != NULL) && (strcmp(ctx->prev_cmd, "quit") != 0)) {
917 printf("Warning: There are unsaved changes\n");
918 return (CMD_OK);
919 }
920
914 return (CMD_QUIT); 921 return (CMD_QUIT);
915 } 922 }
916 923
917 struct cmd * 924 struct cmd *
918 cmd_match(const char *cmd_name) 925 cmd_match(const char *cmd_name)