123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?xml version='1.0' encoding='iso-8859-1'?>
- <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
- <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
- <head>
- <title>
- strfbits.c
- </title>
- <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
- <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
- <meta name='author' content='cmaier@cmassoc.net'/>
- <meta name='robots' content='noindex,nofollow'/>
- <link href='toolkit.css' rel='stylesheet' type='text/css'/>
- </head>
- <body>
- <div class='headerlink'>
- [<a href='strdecr.c.html' title=' strdecr.c '>PREV</a>]
- [<a href='toolkit.html' title=' Index '>HOME</a>]
- [<a href='strincr.c.html' title=' strincr.c '>NEXT</a>]
- </div>
- <pre>
- /*====================================================================*
- *
- * size_t strfbits (char buffer [], size_t length, char const * operands [], char const * operator, unsigned flagword);
- *
- * format.h
- *
- * format buffer with an enumerated list of the bits in a flagword;
- * each flagword bit position corresponds to a string in operands[]
- * and operator is the string separating formatted operands;
- *
- * enumeration continues until all bits are enumerated or operands
- * are exhausted or the buffer fills;
- *
- * for example, the following formats buffer with the literal string
- * "one, three, five, six" since those bits are set;
- *
- * char buffer[100];
- * char const operator = ", ";
- * char const *operands[] =
- * {
- * "zero",
- * "one",
- * "two",
- * "three",
- * "four",
- * "five",
- * "six",
- * "seven",
- * "eight",
- * "nine",
- * "ten",
- * (char *)(0)
- * };
- * flag_t flags = 0x006C;
- *
- * strfbits (buffer, sizeof(buffer), operands, operator, flags);
- *
- * we decrement length before starting to reserve room for the NUL
- * terminator; not room ... no write; we then add length to buffer
- * before to compute the terminator address then subtract it after
- * to compute the buffer start; this minimizes indexing and offset
- * calculations within the loop;
- *
- * Motley Tools by Charles Maier <cmaier@cmassoc.net>;
- * Copyright (c) 2001-2006 by Charles Maier Associates;
- * Licensed under the Internet Software Consortium License;
- *
- *--------------------------------------------------------------------*/
- #ifndef STRFBITS_SOURCE
- #define STRFBITS_SOURCE
- #include <unistd.h>
- #include "../tools/memory.h"
- #include "../tools/flags.h"
- size_t strfbits (char buffer [], size_t length, char const * operands [], char const * operator, unsigned flagword)
- {
- char * string = (char *)(buffer);
- char const *separator = "";
- if (length--)
- {
- buffer += length;
- while ((*operands) && (flagword))
- {
- if (flagword & 1)
- {
- char const *symbol;
- for (symbol = separator; (*symbol) && (string < buffer); symbol++)
- {
- *string++ = *symbol;
- }
- for (symbol = *operands; (*symbol) && (string < buffer); symbol++)
- {
- *string++ = *symbol;
- }
- separator = operator;
- }
- flagword >>= 1;
- operands++;
- }
- *string = (char) (0);
- buffer -= length;
- }
- return (string - (char *)(buffer));
- }
- #endif
- </pre>
- <div class='footerlink'>
- [<a href='strdecr.c.html' title=' strdecr.c '>PREV</a>]
- [<a href='toolkit.html' title=' Index '>HOME</a>]
- [<a href='strincr.c.html' title=' strincr.c '>NEXT</a>]
- </div>
- </body>
- </html>
|