comparison pwm.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 0b1bce8db371
children a07665727c19
comparison
equal deleted inserted replaced
12:8768fbd09bc5 13:cf81eb0c2d5a
1 /* 1 /*
2 * Copyright (C) 2016 Guido Berhoerster <guido+pwm@berhoerster.name> 2 * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name>
3 * 3 *
4 * Permission is hereby granted, free of charge, to any person obtaining 4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the 5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including 6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish, 7 * without limitation the rights to use, copy, modify, merge, publish,
67 char **argv = NULL; 67 char **argv = NULL;
68 struct cmd *cmd; 68 struct cmd *cmd;
69 int i; 69 int i;
70 70
71 for (;;) { 71 for (;;) {
72 cmd = NULL;
72 if (fgets(buf, (int)sizeof (buf), stdin) == NULL) { 73 if (fgets(buf, (int)sizeof (buf), stdin) == NULL) {
73 if (ferror(stdin)) { 74 if (ferror(stdin)) {
74 /* error */ 75 /* error */
75 warn("failed to read command"); 76 warn("failed to read command");
76 goto out; 77 goto out;
144 case CMD_QUIT: 145 case CMD_QUIT:
145 goto quit; 146 goto quit;
146 } 147 }
147 148
148 next: 149 next:
150 if (cmd != NULL) {
151 ctx->prev_cmd = cmd->full_cmd;
152 }
153
149 for (i = 0; i < argc; i++) { 154 for (i = 0; i < argc; i++) {
150 free(argv[i]); 155 free(argv[i]);
151 } 156 }
152 free(argv); 157 free(argv);
153 argc = 0; 158 argc = 0;