atexpand(3)

πŸ’– atexpand(3) β€” bestie edition πŸ’–

AtFS Toolkit Library Β· section 3, the library calls, we love her πŸ’…


✨ NAME ✨

atExpandAttrs, atExpand β€” attribute expansion, aka the glow-up machine for your strings 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <atfs.h>
#include <atfstk.h>

int atExpandAttrs (Af_key *aso, char *buf, size_t bufSize, FILE *dest,
size_t destSize, int mode);

int atExpand;

yeah that second one is just a variable, no parentheses, she's living her best life 🫢


πŸ‘‘ DESCRIPTION πŸ‘‘

okay so, atExpandAttrs goes on a lil scavenger hunt through the char buffer buf, and it looks all the way up to bufSize for strings shaped like $__attributeName β€” and sometimes that lil guy is followed by a delimiting second dollar sign ($), cute, optional, iconic.

When it finds one of those? Everything in the buffer up to the character right before that first dollar sign gets sent straight to the destination output dest. ✨

Then, if an attribute named attributeName is actually set for the current attributed software object aso, that citation-string gets swapped out for the value of that attribute and appended to the output. slay. πŸ’…

And then β€” this is the part people miss β€” output of the buf contents picks back up at the first character after the whitespace character or dollar sign that delimited attributeName. no cap.


πŸŽ€ the string-buffer plot twist πŸŽ€

ngl, the type of the dest argument is "pointer to file structure," but bestie, you can still make atExpandAttrs copy its output into a string buffer instead of an open file. here's the tea πŸ“:

  • you must pass the constant AT_EXPAND_STRING as the mode argument
  • and bufSize must be set to indicate the length of the destination buffer dest (it gets casted to character pointer, don't worry abt it)
🚨 if destSize is too small to hold the result string, atExpandAttrs returns a negative value. beware, she will not be silenced, she will simply say no.

in the regular case β€” the one where output shall be written to a file β€” the mode parameter must be AT_EXPAND_FILE. periodt. πŸ”₯


🧚 the atExpand variable 🧚

the atExpand variable suppresses attribute expansion when set FALSE. (that's the whole personality.)

you can set it:

  1. directly from the application program, or
  2. indirectly by evaluation of the pseudo attribute citation $__xpoff in any buffer scanned by atExpandAttrs

and then there's her sister $__xpon, another pseudo attribute citation β€” she cancels the effect of a previous $__xpoff and switches attribute citation back on again. πŸ”„

⚠️ but lowkey important: $__xpon does not enable attribute citation if it was disabled explicitly by the application program. she can undo her own drama, not yours. πŸ™ˆ

πŸ’€ DIAGNOSTICS πŸ’€

atExpandAttrs returns -1 on error. and bestie, it doesn't just ghost you β€” additionally, the atError variable is set, and afErrMsg holds a diagnostic message. the group chat has receipts. 😭


🌈 SEE ALSO 🌈


that's the whole page, you're so welcome, go expand some attributes, you absolute main character πŸ‘‘βœ¨

mwah πŸ’– β€” written up by the AtFS Toolkit Library, version AtFStk-1.12, dated Fri Jun 25 16:39:36 1993 (an elder, but a legend fr fr πŸŽ€)

πŸ“¦ where this page comes from