Atlas - COMMAND.C
Home / systems / IBM-PC / DataWorks / src Lines: 19 | Size: 2492 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* C89 Standard only */ 2 3#include <stdio.h> 4#include <stdlib.h> 5 6#include "DW.H" 7 8void dw_print_help(void) 9{ 10 printf("DataWorks (simple) commands:\n"); 11 printf(" DW <file.dw> PRINT\n"); 12 printf(" DW <file.dw> INSERT <value> $row,col\n"); 13 printf(" DW <file.dw> DEL_COL [col_index]\n"); 14 printf(" DW <file.dw> SET_COL_NAME <name> [col_index]\n"); 15 printf(" DW <file.dw> INTERACT\n"); 16 printf("Limits: %d rows, %d cols, cell size %d chars\n", DW_MAX_ROWS, DW_MAX_COLS, DW_MAX_CELL - 1); 17} 18 19int dw_run_command(const char *path, int argc, char **argv) 20{ 21 DWTable table; 22 int row; 23 int col; 24 int col_index; 25 int ok; 26 27 if (argc < 1) { 28 return 0; 29 } 30 31 dw_init_table(&table); 32 33 if (!dw_load_file(path, &table)) { 34 printf("Error: failed to load %s\n", path); 35 dw_free_table(&table); 36 return 0; 37 } 38 ok = 1; 39 40 if (dw_stricmp(argv[0], "PRINT") == 0) { 41 dw_print_table(&table); 42 } else if (dw_stricmp(argv[0], "INSERT") == 0) { 43 if (argc < 3) { 44 printf("Usage: DW <file.dw> INSERT <value> $row,col\n"); 45 ok = 0; 46 goto cleanup; 47 } 48 if (!dw_parse_cell_ref(argv[2], &row, &col)) { 49 printf("Error: invalid cell ref '%s'. Use $row,col\n", argv[2]); 50 ok = 0; 51 goto cleanup; 52 } 53 if (!dw_insert(&table, argv[1], row, col)) { 54 printf("Error: table limit reached\n"); 55 ok = 0; 56 goto cleanup; 57 } 58 if (!dw_save_file(path, &table)) { 59 printf("Error: failed to save %s\n", path); 60 ok = 0; 61 goto cleanup; 62 } 63 } else if (dw_stricmp(argv[0], "DEL_COL") == 0) { 64 col_index = (argc >= 2) ? atoi(argv[1]) : (table.cols - 1); 65 if (!dw_del_col(&table, col_index)) { 66 printf("Error: invalid column index\n"); 67 ok = 0; 68 goto cleanup; 69 } 70 if (!dw_save_file(path, &table)) { 71 printf("Error: failed to save %s\n", path); 72 ok = 0; 73 goto cleanup; 74 } 75 } else if (dw_stricmp(argv[0], "SET_COL_NAME") == 0) { 76 if (argc < 2) { 77 printf("Usage: DW <file.dw> SET_COL_NAME <name> [col_index]\n"); 78 ok = 0; 79 goto cleanup; 80 } 81 col_index = (argc >= 3) ? atoi(argv[2]) : (table.cols - 1); 82 if (!dw_set_col_name(&table, col_index, argv[1])) { 83 printf("Error: invalid column index\n"); 84 ok = 0; 85 goto cleanup; 86 } 87 if (!dw_save_file(path, &table)) { 88 printf("Error: failed to save %s\n", path); 89 ok = 0; 90 goto cleanup; 91 } 92 } else { 93 printf("Error: unknown command '%s'\n", argv[0]); 94 dw_print_help(); 95 ok = 0; 96 } 97 98cleanup: 99 dw_free_table(&table); 100 return ok; 101} 102[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.