ref: 3f9f47b86b3e0f9b16d8613d1b62396b0ddae6fc
parent: 52bfaf7faba06ab40941fd01f97a9e7edebcef83
author: glenda <glenda@krsna>
date: Sun Aug 17 10:04:08 EDT 2025
cleanup
--- a/fc.c
+++ b/fc.c
@@ -6,26 +6,25 @@
#include <bio.h>
#include <ctype.h>
-/* Configuration Defaults */
-#define CONFIG_FILE "/tmp/fc.conf"
-#define DEFAULT_CTL_FILE "/tmp/fc.ctl"
-#define DEFAULT_SAVE_PATH "/tmp/sheet.spr"
-#define DEFAULT_BANNER_HEIGHT 25
-#define DEFAULT_STATUS_HEIGHT 20
-#define DEFAULT_STATUS_MARGIN 10
-#define DEFAULT_BOX_LABEL_OFFSET_Y 16
-#define DEFAULT_BOX_TEXT_MARGIN 5
-#define DEFAULT_FORMULA_INDICATOR_OFFSET 10
-#define DEFAULT_DIALOG_WIDTH 256
-#define DEFAULT_DIALOG_HEIGHT 48
-#define DEFAULT_DIALOG_PADDING 10
-#define DEFAULT_EMOJI_SPEED 3
-#define DEFAULT_EMOJI_FRAME_DELAY 10
-#define DEFAULT_CTL_CHECK_INTERVAL 200
-#define DEFAULT_REDRAW_INTERVAL 30
-#define DEFAULT_MAX_EVAL_DEPTH 10
-#define DEFAULT_MAX_RECALC_PASSES 10
-#define DEFAULT_FORMULA_PRECISION 2
+#define CONFIG_FILE "/tmp/fc.conf"
+#define DEFAULT_CTL_FILE "/tmp/fc.ctl"
+#define DEFAULT_SAVE_PATH "/tmp/sheet.spr"
+#define DEFAULT_BANNER_HEIGHT 25
+#define DEFAULT_STATUS_HEIGHT 20
+#define DEFAULT_STATUS_MARGIN 10
+#define DEFAULT_BOX_LABEL_OFFSET_Y 16
+#define DEFAULT_BOX_TEXT_MARGIN 5
+#define DEFAULT_FORMULA_INDICATOR_OFFSET 10
+#define DEFAULT_DIALOG_WIDTH 256
+#define DEFAULT_DIALOG_HEIGHT 48
+#define DEFAULT_DIALOG_PADDING 10
+#define DEFAULT_EMOJI_SPEED 3
+#define DEFAULT_EMOJI_FRAME_DELAY 10
+#define DEFAULT_CTL_CHECK_INTERVAL 200
+#define DEFAULT_REDRAW_INTERVAL 30
+#define DEFAULT_MAX_EVAL_DEPTH 10
+#define DEFAULT_MAX_RECALC_PASSES 10
+#define DEFAULT_FORMULA_PRECISION 2
/* Constants */
#define MAXBOXES 300
@@ -92,7 +91,6 @@
typedef struct Config Config;
struct Config {
- /* Visual */
int banner_height;
int status_height;
int status_margin;
@@ -99,34 +97,22 @@
int box_label_offset_y;
int box_text_margin;
int formula_indicator_offset;
-
- /* Dialog */
int dialog_width;
int dialog_height;
int dialog_padding;
-
- /* Animation */
int emoji_enabled;
int emoji_speed;
int emoji_frame_delay;
int ctl_check_interval;
int redraw_interval;
-
- /* Grid */
int gridsnap;
int gridsize;
-
- /* Behavior */
int max_eval_depth;
int max_recalc_passes;
int formula_precision;
int show_formula_indicator;
-
- /* Paths */
char ctl_file[256];
char default_save_path[256];
-
- /* Colors */
ulong color_bg;
ulong color_fg;
ulong color_box_bg;
@@ -135,8 +121,6 @@
ulong color_grid;
ulong color_label;
ulong color_formula;
-
- /* Formula format string */
char formula_format[32];
};
@@ -271,11 +255,10 @@
char *name;
ConfigType type;
void *ptr;
- int maxlen; /* for strings */
- void (*callback)(void); /* optional callback after setting */
+ int maxlen;
+ void (*callback)(void);
};
-/* Global Variables */
Config config;
Sheet sheet;
Image *colors[6];
@@ -284,8 +267,6 @@
Image *boxediting;
Image *gridcolor;
-
-/* Function Declarations */
void load_config(char *path);
void save_config(char *path);
void apply_config(void);
@@ -590,7 +571,6 @@
void
init_config_defaults(void)
{
- /* Visual */
config.banner_height = DEFAULT_BANNER_HEIGHT;
config.status_height = DEFAULT_STATUS_HEIGHT;
config.status_margin = DEFAULT_STATUS_MARGIN;
@@ -598,12 +578,10 @@
config.box_text_margin = DEFAULT_BOX_TEXT_MARGIN;
config.formula_indicator_offset = DEFAULT_FORMULA_INDICATOR_OFFSET;
- /* Dialog */
config.dialog_width = DEFAULT_DIALOG_WIDTH;
config.dialog_height = DEFAULT_DIALOG_HEIGHT;
config.dialog_padding = DEFAULT_DIALOG_PADDING;
- /* Animation */
config.emoji_enabled = 1;
config.emoji_speed = DEFAULT_EMOJI_SPEED;
config.emoji_frame_delay = DEFAULT_EMOJI_FRAME_DELAY;
@@ -610,21 +588,17 @@
config.ctl_check_interval = DEFAULT_CTL_CHECK_INTERVAL;
config.redraw_interval = DEFAULT_REDRAW_INTERVAL;
- /* Grid */
config.gridsnap = 1;
config.gridsize = 32;
- /* Behavior */
config.max_eval_depth = DEFAULT_MAX_EVAL_DEPTH;
config.max_recalc_passes = DEFAULT_MAX_RECALC_PASSES;
config.formula_precision = DEFAULT_FORMULA_PRECISION;
config.show_formula_indicator = 1;
- /* Paths */
strcpy(config.ctl_file, DEFAULT_CTL_FILE);
strcpy(config.default_save_path, DEFAULT_SAVE_PATH);
- /* Colors */
config.color_bg = 0xEEEEEEFF;
config.color_fg = 0x000000FF;
config.color_box_bg = 0xFFFFFFFF;
@@ -652,20 +626,15 @@
char *fields[3];
int nf;
ConfigField *cf;
-
- /* Initialize with defaults first */
init_config_defaults();
b = Bopen(path, OREAD);
- if(b == nil) {
- /* Config file doesn't exist, use defaults */
+ if(b == nil)
return;
- }
while((line = Brdline(b, '\n')) != nil) {
line[Blinelen(b)-1] = '\0';
- /* Skip comments and empty lines */
if(line[0] == '#' || line[0] == '\0')
continue;
@@ -673,7 +642,6 @@
if(nf < 2)
continue;
- /* Look up field in configuration table */
for(cf = config_fields; cf->name != nil; cf++) {
if(strcmp(fields[0], cf->name) == 0) {
/* Process based on type */
@@ -696,15 +664,13 @@
break;
}
- /* Call callback if present */
if(cf->callback)
cf->callback();
- break; /* Found field, move to next line */
+ break; /* Found, next line */
}
}
- /* Optional: warn about unknown fields */
if(cf->name == nil) {
fprint(2, "Warning: unknown config field '%s'\n", fields[0]);
}
@@ -716,7 +682,6 @@
void
validate_config(void)
{
- /* Ensure sane values */
if(config.banner_height < 0) config.banner_height = 0;
if(config.banner_height > 100) config.banner_height = 100;
@@ -735,7 +700,6 @@
if(config.max_recalc_passes < 1) config.max_recalc_passes = 1;
if(config.max_recalc_passes > 100) config.max_recalc_passes = 100;
- /* Ensure paths are not empty */
if(config.ctl_file[0] == '\0')
strcpy(config.ctl_file, DEFAULT_CTL_FILE);
if(config.default_save_path[0] == '\0')
@@ -746,12 +710,10 @@
void
apply_config(void)
{
- /* Apply config to sheet */
sheet.emoji_enabled = config.emoji_enabled;
sheet.gridsize = config.gridsize;
sheet.gridsnap = config.gridsnap;
- /* Re-allocate colors if they exist */
if(colors[0]) {
freeimage(colors[0]);
colors[0] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, config.color_fg);
@@ -1022,7 +984,6 @@
tokens[ntok].type = TOK_END;
ntok++;
}
-
return ntok;
}
@@ -1052,7 +1013,6 @@
subeval.tokens, nelem(subeval.tokens));
return eval_expr(&subeval);
}
-
return b->value;
}
return 0.0;
--
⑨