Header .h file with structures definitions to ahk array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Brazolek123
Posts: 187
Joined: 06 Jun 2016, 16:02

Header .h file with structures definitions to ahk array

Post by Brazolek123 » 04 Aug 2021, 02:25

Hi!

I know that chances are low but I'll ask anyway. I have a header .h file that contains typedefinitions for structures that we use in our embedded code for electronics stuff. I'm not allowed to share the code, but example is shown below:

Code: Select all

typedef struct {
	CAR Peugeot206;
	CAR Peugeot407;
	CAR Peugeot607;
} PEUGEOT_CARS;

typedef struct {
	int seats;
	int wheels;
	float mass;
	string engine;
	LIGHTS reflectors;
} CAR;

typedef struct {
	string left_front;
	string right_front;
} LIGHTS;

extern PEUGEOT_CARS PeugeotCars;
My ultimate goal is to put the h.file path into an ahk app and get output of text:

Code: Select all

PeugeotCars.Peugeot206.seats;
PeugeotCars.Peugeot206.wheels;
PeugeotCars.Peugeot206.mass;
PeugeotCars.Peugeot206.engine;
PeugeotCars.Peugeot206.reflectors.left_front;
PeugeotCars.Peugeot206.reflectors.right_front;
PeugeotCars.Peugeot407.seat;
PeugeotCars.Peugeot407.wheels;
PeugeotCars.Peugeot407.mass;
PeugeotCars.Peugeot407.engine;
PeugeotCars.Peugeot407.reflectors.left_front;
PeugeotCars.Peugeot407.reflectors.right_front;
PeugeotCars.Peugeot607.seats;
PeugeotCars.Peugeot607.wheels;
PeugeotCars.Peugeot607.mass;
PeugeotCars.Peugeot607.engine;
PeugeotCars.Peugeot607.reflectors.left_front;
PeugeotCars.Peugeot607.reflectors.right_front;
The hardest part is to convert the .h file into ahk array. If I had an array then the rest would be easy. I do realize that chances are low but do you perhaps have such a code or could you give me some ideas how can I make it on my own?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Header .h file with structures definitions to ahk array  Topic is solved

Post by mikeyww » 04 Aug 2021, 06:41

Use Loop, Read to process each line. Split or parse the line to examine the words. Build arrays based on the words. Build the output text based on the arrays. Since a potential array name is defined at the end of each source block in braces, you can build a temporary array for each block, and then assign the whole temporary array to an array element based on that array name. You can add handling for your cases where the first word is not "int", "float", or "string".

User avatar
Brazolek123
Posts: 187
Joined: 06 Jun 2016, 16:02

Re: Header .h file with structures definitions to ahk array

Post by Brazolek123 » 04 Aug 2021, 07:18

Yes, I also thought about it, that's probably the way to go. Thanks for time you spent on analyzing my problem.

Anyway, if anyone pass through this topic with the same question as mine, here's a code I will use to extract structure names https://www.autohotkey.com/boards/viewtopic.php?f=75&t=63624
instead of using "Loop, Parse" method proposed by user mikeyww. Then I'll go as he wrote in his post.

Post Reply

Return to “Ask for Help (v1)”