diff options
author | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-08 01:40:05 +0100 |
---|---|---|
committer | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-08 01:40:05 +0100 |
commit | ff9b3f3c50c67bfd4a9c9789f4cfee160431d703 (patch) | |
tree | 67c2bef189790bc395fea2da3bb6ae57867768ba | |
parent | cc6a18ae9748eccfc6dc6df404b2f69a99418937 (diff) |
Fix style; Fix minor bugs
-rw-r--r-- | COPYING.txt | 10 | ||||
-rw-r--r-- | modules/menu/src/menu_clui.c | 43 | ||||
-rw-r--r-- | modules/menu/src/menu_tui.c | 4 | ||||
-rw-r--r-- | modules/menu/src/parser.c | 2 | ||||
-rw-r--r-- | modules/save/tmp/Makefile | 2 | ||||
-rw-r--r-- | modules/user/src/user_clui.c | 32 | ||||
-rw-r--r-- | share/LICENSE.txt | 10 |
7 files changed, 57 insertions, 46 deletions
diff --git a/COPYING.txt b/COPYING.txt index 9e98b13..0776f74 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -237,7 +237,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index f5bb045..b5dc619 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -38,28 +38,32 @@ static void menu_clui_start (void); void menu_clui (void) { char buff [BUFF_SIZE]; - char ch; + char c; - ch = 'n'; + c = 'n'; printf("Read 'Disclaimer of warranty'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { return; } - if (ch == 'y' || ch == 'Y') { + if (sscanf(buff, " %c", &c) != 1) { + return; + } + if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_DISCLAIMER); } else { printf(" >NO\n"); } - ch = 'n'; + c = 'n'; printf("Read 'License'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { + return; + } + if (sscanf(buff, " %c", &c) != 1) { return; } - if (ch == 'y' || ch == 'Y') { + if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_LICENSE); } else { @@ -67,10 +71,13 @@ void menu_clui (void) } #if 0 printf("Game interface? (NCURSES/text): "); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { return; } - if (ch == 't' || ch == 'T') { + if (sscanf(buff, " %c", &c) != 1) { + return; + } + if (c == 't' || c == 'T') { printf(" >text\n"); // FIXME } else { @@ -100,18 +107,20 @@ static void menu_clui_start (void) start_switch(); char buff [BUFF_SIZE]; - char ch; + char c; - ch = 'm'; + c = 'm'; printf("Load again? (MENU/load/exit): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { + return; + } + if (sscanf(buff, " %c", &c) != 1) { return; } - if (ch == 'p' || ch == 'P') { + if (c == 'p' || c == 'P') { printf(" >load\n"); menu_clui_start(); - } else if (ch == 'e' || ch == 'E') { + } else if (c == 'e' || c == 'E') { printf(" >exit!\n"); } else { printf(" >MENU\n"); diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 5654b40..8850e7f 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -134,7 +134,7 @@ static void menu_tui_continue (void) /* Input box */ w2 = w - 8; r2 = r + h - 5; - static const char *txt[] = {"File name:"}; + static const char *const txt[] = {"File name:"}; /* Menu */ wh = true; @@ -292,7 +292,7 @@ static void menu_tui_devel (void) /* Input box */ w2 = w - 8; r2 = r + h - 5; - static const char *txt[] = { + static const char *const txt[] = { "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", "Modes: 0=Results; 1=Operations; 2=All", "Modes: 1=CLUI; 2=TUI" diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index a7ed4a8..d751182 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -50,7 +50,7 @@ void parser (int argc, char *argv[]) int opt = 0; int opt_index = 0; - struct option long_options[] = { + const struct option long_options[] = { /* Standard */ {"help", no_argument, 0, 'h'}, {"license", no_argument, 0, 'L'}, diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile index 2003a10..4f2abf9 100644 --- a/modules/save/tmp/Makefile +++ b/modules/save/tmp/Makefile @@ -31,7 +31,7 @@ all: $(ALL) save_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - + save.s: $(SAVE_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(SAVE_INC_DIRS) -S $< -o $@ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 11e7db1..9a61d7e 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -54,6 +54,7 @@ static void show_help (void); ******************************************************************************/ void user_clui_init (void) { + log_pos = 0; } @@ -71,6 +72,7 @@ int user_clui (const char *title, const char *subtitle) void user_clui_fname (const char *filepath, char *filename) { + printf("File name:\n"); printf("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff\n"); fgets(filename, FILENAME_MAX, stdin); @@ -79,14 +81,13 @@ void user_clui_fname (const char *filepath, char *filename) void user_clui_show_log (const char *title, const char *subtitle) { - printf("________________________________________________________________________________\n"); - /* Board */ + printf("________________________________________" + "________________________________________\n"); log_loop(); - - /* Subtitle & title */ printf("%s - %s\n", subtitle, title); - printf("--------------------------------------------------------------------------------\n"); + printf("----------------------------------------" + "----------------------------------------\n"); } @@ -115,24 +116,23 @@ static void log_loop (void) static int usr_input (void) { int action; - char buff [BUFF_SIZE]; char ch [10]; - int i; + for (i = 0; i < 10; i++) { ch[i] = '\0'; } buff[0] = '\0'; + action = USER_IFACE_ACT_FOO; - /* Wait for input */ - fgets(buff, BUFF_SIZE, stdin); - - /* Interpret input */ - if (sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { - ch[0] = '\0'; + if (!fgets(buff, BUFF_SIZE, stdin)) { + goto err_fgets; } - action = USER_IFACE_ACT_FOO; + if (!sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { + goto err_sscanf; + } + switch (ch[0]) { case '+': action = USER_IFACE_ACT_APPLY; @@ -560,6 +560,8 @@ static int usr_input (void) break; } +err_fgets: +err_sscanf: return action; } @@ -568,7 +570,7 @@ static int usr_input (void) * * * * * * * * * */ static void show_help (void) { - // FIXME + printf("Apply: %s\n", "Space"); printf("Discard: %s\n", "Backspace"); printf("Save to mem: %c\n", 'm'); diff --git a/share/LICENSE.txt b/share/LICENSE.txt index 9e98b13..0776f74 100644 --- a/share/LICENSE.txt +++ b/share/LICENSE.txt @@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -237,7 +237,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest |