Atlas - CLI.C

Home / systems / IBM-PC / DataWorks / src Lines: 3 | Size: 1159 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* C89 Standard only */ 2 3#include <stdio.h> 4#include <string.h> 5 6#include "DW.H" 7 8static int dw_interact(const char *path) 9{ 10 char line[DW_MAX_LINE]; 11 char *tokens[8]; 12 char *p; 13 int count; 14 15 printf("DataWorks interactive mode. Type HELP or EXIT.\n"); 16 for (;;) { 17 printf("%s> ", path); 18 if (fgets(line, sizeof(line), stdin) == NULL) { 19 return 1; 20 } 21 dw_trim(line); 22 if (line[0] == '\0') { 23 continue; 24 } 25 26 count = 0; 27 p = strtok(line, " \t"); 28 while (p != NULL && count < 8) { 29 tokens[count++] = p; 30 p = strtok(NULL, " \t"); 31 } 32 if (count == 0) { 33 continue; 34 } 35 36 if (dw_stricmp(tokens[0], "EXIT") == 0 || dw_stricmp(tokens[0], "QUIT") == 0) { 37 return 1; 38 } 39 if (dw_stricmp(tokens[0], "HELP") == 0) { 40 dw_print_help(); 41 continue; 42 } 43 44 if (!dw_run_command(path, count, tokens)) { 45 printf("Command failed.\n"); 46 } 47 } 48} 49 50int dw_cli_main(int argc, char **argv) 51{ 52 if (argc < 3) { 53 dw_print_help(); 54 return 1; 55 } 56 57 if (dw_stricmp(argv[2], "INTERACT") == 0) { 58 return dw_interact(argv[1]) ? 0 : 1; 59 } 60 61 return dw_run_command(argv[1], argc - 2, argv + 2) ? 0 : 1; 62} 63
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.