• 5 Posts
  • 7 Comments
Joined 7 miesięcy temu
cake
Cake day: lis 08, 2022

help-circle
rss
Hey guys. I've been working on a calorie counter for mobile Linux. For the Diary stack, I'd like to add both Beep and Meep widgets in the same row, instead of two different rows. It appears that this is possible, looking at the widget glossary for GTK3. How do I do this?
fedilink

Thanks for the help! I’ll definitely start using -Wall. I don’t know why I don’t do it by default…


Wow that’s cool. I had no idea GCC did stuff like this.


Awesome, thank you so much!

How do you use fanalyzer? I’m passing it as a build option in GCC, assuming that it’ll alert me of any issues on either compile or runtime.


I tried -fsanitize=undefined and -fsanitize=unreachable with no luck. Are there other appropriate sanitizers I’m missing?


Only a file that doesn’t change between runs. I posted a copy of the full source code in a different post here in this thread. It’s been minimised down to 105 lines. Still can’t figure out where the bug is.

I’ll try your suggestion though, thank you!


Thanks for the suggestion! I managed to squish the program down into 105 lines. This is my MRE.

#include<stdlib.h>
#include<confuse.h>

struct entry
	{
	int Day;
	long int Date;
	float C;
	float F;
	float P;
	float L;
	};

int DiaryNum;
struct entry  *Diary;
char DiaryPath[] = "/home/lofenyy/.config/Calorimeter/Diary";

cfg_opt_t entry_opts[] = 
	{
	CFG_INT("Date", 0, CFGF_NONE),
	CFG_INT("Day", 0, CFGF_NONE),
	CFG_FLOAT("C", 0, CFGF_NONE),
	CFG_FLOAT("F", 0, CFGF_NONE),
	CFG_FLOAT("P", 0, CFGF_NONE),
	CFG_FLOAT("L", 0, CFGF_NONE),
	CFG_END()
	};

cfg_opt_t entry_base_opts[] =
	{
	CFG_SEC("Entry", entry_opts, CFGF_MULTI),
	CFG_END()
	};

int lodEntry()
	{
	//Initialization
	cfg_t *cfg;
	cfg_t *cfg_entry;
	cfg = cfg_init(entry_base_opts, CFGF_NONE);
	
	//Open our file and check for errors
	if(cfg_parse(cfg, DiaryPath) == CFG_PARSE_ERROR)
		printf("Err!\n");
	
	//Allocate enough memory for our internal diary
	DiaryNum = cfg_size(cfg, "Entry");
	Diary = malloc(DiaryNum * sizeof(struct entry));	
	
	//For every entry in our external diary
	for(int C = 0;C < cfg_size(cfg, "Entry");C++)
		{
		//Copy our entries to our internal diary
		cfg_entry = cfg_getnsec(cfg, "Entry", C);
		Diary[C].Date	= cfg_getint(cfg_entry, "Date");
		Diary[C].Day	= cfg_getint(cfg_entry, "Day");
		Diary[C].C	= cfg_getfloat(cfg_entry, "C");
		Diary[C].F	= cfg_getfloat(cfg_entry, "F");
		Diary[C].P	= cfg_getfloat(cfg_entry, "P");
		Diary[C].L	= cfg_getfloat(cfg_entry, "L");
		}
	
	cfg_free(cfg);
	}

double getEntryCalories(int C)
	{
	//4 calories per carb and protein. 9 per lipid. 
	return 4*(Diary[C].C+Diary[C].P)+9*(Diary[C].L);
	}

int prnStats()
	{
	float C,F,P,L,Calories = 0;
	int day0 = Diary[0].Day;
	int day1 = Diary[DiaryNum -1].Day;
	int days = (day1 - day0) +1;
	
	//For every diary entry
	for(int i = 0;i < DiaryNum;i++)
		{
		//Count up our nutrients
		C = C + Diary[i].C;
		F = F + Diary[i].F;
		P = P + Diary[i].P;
		L = L + Diary[i].L;
		Calories = Calories + getEntryCalories(i);
		}
	
	//Print them out
	printf("Average Calories: %2.2f\n", (float)(Calories/days));
	printf("Average Carbs: %2.2f\n", (float)(C/days));
	printf("Average Fibre: %2.2f\n", (float)(F/days));
	printf("Average Proteins: %2.2f\n", (float)(P/days));
	printf("Average Lipids: %2.2f\n", (float)(L/days));
	}

int main(int argc, char  *argv[])
	{
	// Load our internal food diary from our external food diary
	// print out our statistics
	lodEntry();
	prnStats();
	}

This is the contents of Diary

Entry
{
	Date = 1679542784
	Day = 0
	C = 6.000000
	F = 5.000000
	P = 4.000000
	L = 3.000000
}

Entry
{
	Date = 1679546112
	Day = 0
	C = 60.000000
	F = 50.000000
	P = 20.000000
	L = 1.000000
}

Entry
{
	Date = 1679547008
	Day = 0
	C = 4.000000
	F = 4.000000
	P = 4.000000
	L = 4.000000
}

Entry
{
	Date = 1679547136
	Day = 1
	C = 4.000000
	F = 4.000000
	P = 4.000000
	L = 4.000000
}

Entry
{
	Date = 1679547136
	Day = 5
	C = 60.000000
	F = 50.000000
	P = 20.000000
	L = 1.000000
}

Is this likely the case if the program runs only in a single thread?


Fellas, why is this happening, especially sometimes but not other times? Here, I run the program three times, getting the exact same correct output. On the fourth, it outputs broken numbers. The function prnStats what's being executed.
fedilink

Fellas, I need help working on a user interface. I want to add controls, like a toolbar of sorts I guess, to this project (a calorie counter). It seems like I'd want them within the recipe and diary stacks, since the controls are the same, but not the stats stack, since that's just for displaying information. This idea though, seems super awkward. I could add a menu bar to the whole thing instead, but I'm writing for mobile. Neither idea seems good. I could work on an ncurses version instead, until Trisquel releases GTK4, libadwaita and newer versions of libhandy. All this does though, is push the issue into the future. Any ideas on how to proceed?
fedilink

Ncurses woes
I've found a new project to obsess over. It's a calorie tracking app. I spent quite a while implementing the guts. Now I'm working on the UI. GUI stuff however, has been a pain. On Trisquel, I'm limited to GTK3 and ncurses. I'll implement both, but I'm working on the ncurses version so it'll be easier to write the GTK version. The trouble with writing a full-blown ui in ncurses is, it's getting very big, very fast. It's a lot of repeated code that I realize can be shrunken down if there were such a thing as a widget toolkit for ncurses. This realization, is as cursed as a ouija board on a Friday the 13th, guarded by a black cat underneath a ladder. I'm worried that the UI is going to end up being too big to maintain if I keep going forward as is, but creating and pasting a set of widgets is likely a project of its own. Fellas, do you have any ideas on how I should proceed? ![Program screenshot](https://lemmy.ca/pictrs/image/151ed087-3229-4067-801b-3f6a2b918925.png) ![Code screenshot](https://lemmy.ca/pictrs/image/46f2de7a-78e7-4c82-91d3-28774c433a5a.png)
fedilink

As an on-the-ground mapper in OpenStreetMap, I personally prioritize the local city transit network. It's an economic powerhouse, and generally important public infrastructure as an alternative to driving. While mapping out transit nodes such as bus stops, I find it difficult to keep track of my progress. I wrote this program as a personal tool, but recognizing its potential, I've decided to publish it an expand its capabilities. It cross references two CSV files, one provided by a city of all known bus stops, and one that contains all bus stops that exist in OpenStreetMap, and produces an SVG file, illustrating how well mapped out the city is.
fedilink