Red Rozenglass on Nostr: In other news, why did no one tell me about xxd -i before: -i | -include Output in C ...
In other news, why did no one tell me about xxd -i before:
-i | -include
Output in C include file style. A complete static array defini‐
tion is written (named after the input file), unless xxd reads
from stdin.
For example, you can add this to your build pipeline, to turn a string to an embedded array of characters. Just #include printf-template.html.h in your code. If printf-template.html contains printf control sequences, like %s, they do work if you pass them to printf(). You can have an HTML file parametrized with printf() for example.
xxd -i printf-template.html > printf-template.html.h
I assume you can embed anything this way; strings, images, 3D models, etc. This seems cross-platform enough. I'm starting to wonder if the new #embed C standard proposal is really needed, or just bloat now. (Even parameterized #embed sounds like something replaceable with some UNIX piping before you pass the data to xxd -i).
Published at
2025-03-24 16:17:54Event JSON
{
"id": "ab9bd9839dff6a74e65b328c6e6266877d8f6548abfb73f42367a2139b4b547b",
"pubkey": "ec9f49eafea9211a5d3c911adc0938d8ead1de1e299634b4ce3c38b681489b8a",
"created_at": 1742833074,
"kind": 1,
"tags": [
[
"t",
"include"
],
[
"t",
"embed"
],
[
"t",
"embed"
],
[
"proxy",
"https://fedi.dreamscape.link/rozenglass/p/1742833074.585401",
"activitypub"
]
],
"content": "In other news, why did no one tell me about xxd -i before:\n\n-i | -include\n Output in C include file style. A complete static array defini‐\n tion is written (named after the input file), unless xxd reads\n from stdin.\nFor example, you can add this to your build pipeline, to turn a string to an embedded array of characters. Just #include printf-template.html.h in your code. If printf-template.html contains printf control sequences, like %s, they do work if you pass them to printf(). You can have an HTML file parametrized with printf() for example.\n\nxxd -i printf-template.html \u003e printf-template.html.h\n\nI assume you can embed anything this way; strings, images, 3D models, etc. This seems cross-platform enough. I'm starting to wonder if the new #embed C standard proposal is really needed, or just bloat now. (Even parameterized #embed sounds like something replaceable with some UNIX piping before you pass the data to xxd -i).\n\n",
"sig": "f2bacb57fa708653420d712fdf34ede68f192b81b20fc6b1986350a1fec8dcd63e9ba790f6224a83d1929dc8233fc889607c6f78a3bcd7930545b7e3ad30b96b"
}