gd_add_spec(3)

๐Ÿ’– gd_add_spec(3) โ€” GETDATA manual, but make it cute ๐Ÿ’–

okay bestie, sit down, hydrate, because we're learning how to add a field to a Dirfile and honestly? it's giving main character energy. this is gd_add_spec(3) from the GETDATA manual, and by the end of this page you're gonna be obsessed. ๐Ÿฆ‹


โœจ NAME โœจ

gd_add_spec, gd_madd_spec โ€” add a field to a Dirfile

like. that's it. that's the whole job. but the way they do it?? iconic. ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

#include <getdata.h>

int gd_add_spec(DIRFILE *dirfile, const char *line, int fragment_index);

int gd_madd_spec(DIRFILE *dirfile, const char *line, const char *parent);

โœจ DESCRIPTION โœจ

so. gd_add_spec() takes the field specification line in line and adds the field it describes to the dirfile you passed as dirfile. slay. ๐Ÿ’…

gd_madd_spec() is basically the same vibe, except it adds the field as a metafield under the field you name in parent. metafield under a parent fieldโ€ฆ it's giving nepotism but make it data. ๐ŸŽ€

field specification lines are explained in excruciating (affectionate) detail in dirfile-format(5). and here's a fun little glow-up: since Standards Version 7 (peep dirfile(5)) lets you specify a metafield without using the /META directive, you can also use gd_add_spec() to add metafields โ€” just specify the metafield's full field code. full deets live in dirfile-format(5), go read it, i'll wait. ๐Ÿ’œ

quick note for the gd_madd_spec() girlies: line should contain only a field specification, and not a /META directive. don't do it. i'm serious. ๐Ÿ™ˆ

if you hand these functions a directive line instead of a field specification line, you get a syntax error. periodt. and these functions never call the registered parser callback function โ€” not even if line has a syntax error in it. they simply do not care to involve your callback. ๐Ÿ˜ญ


โœจ RETURN VALUE โœจ

on success, gd_add_spec() and gd_madd_spec() return zero. cute, clean, no notes. โœจ

on error, you get a negative-valued error code. yes, negative. the vibes are bad. possible error codes are:

  • GD_E_ACCMODE โ€” the specified dirfile was opened read-only. you tried to write to something that said "look but don't touch." ๐Ÿšซ
  • GD_E_ALLOC โ€” the library was unable to allocate memory. it's not the library's fault, it's just tired. ๐Ÿ˜ฎโ€๐Ÿ’จ
  • GD_E_BAD_CODE โ€” the parent field code was not found, or was already a metafield. (metafieldยฒ is not a thing, bestie.) ๐Ÿ’€
  • GD_E_BAD_DIRFILE โ€” the supplied dirfile was invalid. rip.
  • GD_E_BAD_INDEX โ€” the fragment_index argument was out of range. it wandered off the map. ๐Ÿ—บ๏ธ
  • GD_E_FORMAT โ€” a syntax error was encountered in line. grammar police but for data. ๐Ÿšจ
  • GD_E_IO โ€” an I/O error occurred while creating an empty binary file to be associated with a newly added RAW field. ๐Ÿ˜ญ
  • GD_E_LINE_TOO_LONG โ€” the supplied line was longer than the parser was able to deal with. line lengths are limited by the storage size of size_t. (the parser said "tl;dr" fr fr.) ๐Ÿ“
  • GD_E_PROTECTED โ€” the metadata of the fragment was protected from change. or, the creation of a RAW field was attempted and the data of the fragment was protected. hands off, it's guarded. ๐Ÿ›ก๏ธ
  • GD_E_UNKNOWN_ENCODING โ€” the encoding scheme of the indicated format specification fragment is not known to the library. as a result, the library was unable to create an empty binary file to be associated with a newly added RAW field. it simply doesn't speak that language. ๐Ÿซค
  • GD_E_UNSUPPORTED โ€” the encoding scheme of the indicated format specification fragment does not support creating an empty binary file to be associated with a newly added RAW field. it knows the language, it just refuses. ๐Ÿ’…

the error code is also stored in the DIRFILE object, and you can grab it after this function returns by calling gd_error(3). want a descriptive error string instead of a number? call gd_error_string(3). you're welcome. ๐Ÿซถ


โœจ HISTORY โœจ

  • the functions dirfile_add_spec() and dirfile_madd_spec() appeared in GetData-0.4.0. the origin story. ๐ŸŒฑ
  • in GetData-0.7.0, these functions were renamed to gd_add_spec() and gd_madd_spec(). glow-up era. โœจ
  • in GetData-0.10.0, the error return from these functions changed from -1 to a negative-valued error code. character development. ๐Ÿ”ฅ

โœจ SEE ALSO โœจ

gd_add(3), all the gd_add_<entry-type> functions (e.g., gd_add_bit(3)), gd_error(3), gd_error_string(3), gd_madd(3), all the gd_madd_<entry-type> functions (e.g., gd_madd_bit(3)), gd_metaflush(3), gd_open(3), dirfile-format(5)

go forth and read them all, i believe in you. ๐ŸŒˆ


that's the whole page bestie!! this was Version 0.10.0, dated 25 December 2016, and honestly it ate. no cap. go add some fields. ๐Ÿ‘‘๐Ÿ’–