Follow

Hey C folks, I have a question. My template has inline SVGs and they make the whole code unreadable. Is there a way to use a directive with a fopen to put the svg content inside it? Something like:

LOGO fopen("../assets/logo.svg", "r");

@thomasorus this function is pure vanity I’m not event sorry

@thomasorus Sure, you could fopen() and fread() the svg into a buffer and use it where you need it.

What you have there doesn't make sense though -- keep in mind that are literally just a text search-and-replace that occurs before the compiler even runs. You would just be replacing occurences of the text "LOGO" in your C source with that fopen() call.

@stevenf Ok thanks, I thought that was stretching things a little too much. I'll find another way!

@thomasorus Unfortunately, you can't do that exactly but, you might be able to move your templates over into separate include files or as separate C files (containing the string as global variables).

@leimon Having them into another file as global variables could be a good solution yes! Thanks for suggesting it, do you have any demo of this somewhere?

@thomasorus @leimon literally just split them out to a .h (header) or .inl (inline) file and that file where the variables are needed.

@thomasorus Umm, if you'd like I could whip up a little example for you later after my kiddos are in bed.

@thomasorus This is a bit of a crappy example but, here I've essentially embeded a sample "template" string within a second C source file and then just make the other source file aware of it by using an extern. Hopefully this will give you some inspiration.

psty.io/f?q=d7a

FYI: This pastebin site only keeps things up for about 24 hours. So hopefully this reaches you in time.

@thomasorus hmm. why preprocessor directives? could you not just define the svgs as strings in header files and include them? just off the top of my head...

Sign in to participate in the conversation
Merveilles

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.