xml2man.c
IntroductionConverts HeaderDoc-generated XML output into a
form suitable for use with Functions
checkcurwordReturns 1 if a token might potentially be misinterpreted as a macro. Used to control quoting. int checkcurword( char *word, int textcontainer) dodtgutsWrites the guts of a term-and-definition, flag, or argument. void dodtguts( FILE *fp, xmlNode *parent, char *initial_add) DiscussionIn this context, we can't change lines to send a new command, so only certain things are allowed, and all commands are handled inline. formattextEmits a block of text, quoting tokens within it as needed. char *formattext( char *text, int textcontainer) getflagargsReads the argument list for a flag (from the XML tree) and creates data structures accordingly. usage_t getflagargs( xmlNode *node) lasttextnodeReturns the last sibling of the current node, but only if it is a text node. xmlNode *lasttextnode( xmlNode *node) mainMain. int main( int argc, char *argv[]) malloccatA char *malloccat( const char *string1, const char *string2) nodematchingReturns the first node at the current level that matches the specified tag name. xmlNode *nodematching( char *name, xmlNode *cur) nodesmatchingReturns an array of nodes at the current level that match the specified tag name. xmlNode **nodesmatching( char *name, xmlNode *cur) parseUsageCalls void parseUsage( xmlNode *node, int pos) parseUsageSubExtracts the usage section from the XML tree and builds up data structures. void parseUsageSub( xmlNode *node, int pos, int drop_first_text) printUsageOptionListPrints a list of options (A | B | C) for the USAGE section of a manual page. void printUsageOptionList( usage_t cur, FILE *fp, char *starting, char *separator) propstringSearches a list of XML properties and returns a string containing the text of the first property that matches the specified name. char *propstring( char *name, struct _xmlAttr *prop) propvalReturns the numerical value (integer) of an XML property. int propval( char *name, struct _xmlAttr *prop) safe_asprintfCompatibility shim for Linux int safe_asprintf( char **ret, const char *format, ...) DiscussionUnlike the BSD implementation of Because it is poor programming practice to accept a pointer from a system routine without checking to see if the routine returned NULL, this results in a rather messy pair of checks in order to get the desired behavior (one check for the return value, then another for the pointer). This function works around that flaw in the Linux
implementation by simply checking the return value,
then setting the variable pointed to by strip_dotmxmlStrips the trailing void strip_dotmxml( char *filename) striplinesStrips leading whitespace and replaces all line breaks with spaces. char *striplines( char *line) textmatchingReturns the first text content of the first node at the current level that matches the specified tag name. char *textmatching( char *name, xmlNode *node, int missing_ok, char *debugstr) write_funcargsWrites function arguments to the output file. void write_funcargs( FILE *fp, usage_t cur) writeDataWrites a normal section to the output file. void writeData( FILE *fp, xmlNode *node) DiscussionCalls writeData_subWrites a normal section to the output file. void writeData_sub( FILE *fp, xmlNode *node, int state, int textcontainer, int next, int seendt) writeOptionsSubWrites the OPTIONS section of a manual page. void writeOptionsSub( FILE *fp, xmlNode *description, int lwc) writeOptionsSubWithObjectWrites an individual option entry in the OPTIONS section of a manual page. int writeOptionsSubWithObject( FILE *fp, usage_t obj, int pos, int topfirst, int lwc, int noheading) writeUsageWrites the USAGE section of a manual page. void writeUsage( FILE *fp, xmlNode *description) writeUsageSubWrites an individual command usage inside the USAGE section of a manual page. int writeUsageSub( FILE *fp, int showname, usage_t myusagehead, char *name_or_empty, char *optional_separator) xml2manThe main body of the translator code. void xml2man( xmlNode *root, char *output_filename, int append_section_number) DiscussionTakes an XML tree, an output filename, and a flag to indicate whether the section number should be appended to that filename, then translatest that into the -mdoc macro set. xsReturns a static buffer (not thread safe) containing the specified number of "X" characters. char *xs( int count) Enumerated Types
statesState values that represent where we are in the document. ConstantsstripstateThe current state in the enum stripstate { kSOL = 1, kText = 2 }; Constants |