/* addStringValue * * Associate a name with either a string or no value. */ static tOptionValue* addStringValue( void** pp, char const* pzName, size_t nameLen, char const* pzValue, size_t dataLen ) { tOptionValue* pNV; size_t sz = nameLen + dataLen + sizeof(*pNV); pNV = AGALOC( sz, "option name/str value pair" ); if (pNV == NULL) return NULL; if (pzValue == NULL) { pNV->valType = OPARG_TYPE_NONE; pNV->pzName = pNV->v.strVal; } else { pNV->valType = OPARG_TYPE_STRING; if (dataLen > 0) { char const * pzSrc = pzValue; char * pzDst = pNV->v.strVal; int ct = dataLen; do { int ch = *(pzSrc++) & 0xFF; if (ch == NUL) goto data_copy_done; if (ch == '&') ch = get_special_char(&pzSrc, &ct); *(pzDst++) = ch; } while (--ct > 0); data_copy_done: *pzDst = NUL; } else { pNV->v.strVal[0] = NUL; } pNV->pzName = pNV->v.strVal + dataLen + 1; } memcpy( pNV->pzName, pzName, nameLen ); pNV->pzName[ nameLen ] = NUL; addArgListEntry( pp, pNV ); return pNV; }
Boolean XmlWriteString ( FILE *file, XmlContent *content, XmlDocument *document ) /* Input: content - The string to write to file document - The document to where content appears in Output: file - The string was written to this file Returns: TRUE on succes, otherwise FALSE. Description: This function writes the contents of string to file. */ { int count, string_len; char *alias; string_len = strlen(content->data.string); for (count = 0; count < string_len; count++) { alias = get_special_char(content->data.string[count]); /* If we do not have to replace the character by an alias */ if (alias == NULL) { putc (content->data.string[count], file); } else { /* Replace the character by an alias */ fprintf (file, "&%s", alias); } if (content->data.string[count] == '\n' && count+1 < string_len) { indent (file, level); } } return (TRUE); }
/** * Associate a name with either a string or no value. * * @param[in,out] pp argument list to add to * @param[in] name the name of the "suboption" * @param[in] nm_len the length of the name * @param[in] val the string value for the suboption * @param[in] d_len the length of the value * * @returns the new value structure */ static tOptionValue * add_string(void ** pp, char const * name, size_t nm_len, char const * val, size_t d_len) { tOptionValue * pNV; size_t sz = nm_len + d_len + sizeof(*pNV); pNV = AGALOC(sz, "option name/str value pair"); if (val == NULL) { pNV->valType = OPARG_TYPE_NONE; pNV->pzName = pNV->v.strVal; } else { pNV->valType = OPARG_TYPE_STRING; if (d_len > 0) { char const * src = val; char * pzDst = pNV->v.strVal; int ct = (int)d_len; do { int ch = *(src++) & 0xFF; if (ch == NUL) goto data_copy_done; if (ch == '&') ch = get_special_char(&src, &ct); *(pzDst++) = (char)ch; } while (--ct > 0); data_copy_done: *pzDst = NUL; } else { pNV->v.strVal[0] = NUL; } pNV->pzName = pNV->v.strVal + d_len + 1; } memcpy(pNV->pzName, name, nm_len); pNV->pzName[ nm_len ] = NUL; addArgListEntry(pp, pNV); return pNV; }