| 152 | } |
| 153 | |
| 154 | bool AddString(char **buf_p, size_t &maxlen, const char *string, int width, int prec, int flags) |
| 155 | { |
| 156 | int size = 0; |
| 157 | char *buf; |
| 158 | static char nlstr[] = {'(','n','u','l','l',')','\0'}; |
| 159 | |
| 160 | buf = *buf_p; |
| 161 | |
| 162 | if (string == NULL) |
| 163 | { |
| 164 | string = nlstr; |
| 165 | prec = -1; |
| 166 | flags |= NOESCAPE; |
| 167 | } |
| 168 | |
| 169 | if (prec >= 0) |
| 170 | { |
| 171 | for (size = 0; size < prec; size++) |
| 172 | { |
| 173 | if (string[size] == '\0') |
| 174 | { |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | while (string[size++]); |
| 182 | size--; |
| 183 | } |
| 184 | |
| 185 | if (size > (int)maxlen) |
| 186 | { |
| 187 | size = maxlen; |
| 188 | } |
| 189 | |
| 190 | width -= size; |
| 191 | |
| 192 | if (!(flags & LADJUST)) |
| 193 | { |
| 194 | while ((width-- > 0) && maxlen) |
| 195 | { |
| 196 | *buf++ = ' '; |
| 197 | maxlen--; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if (g_FormatEscapeDatabase && (flags & NOESCAPE) == 0) |
| 202 | { |
| 203 | char *tempBuffer = NULL; |
| 204 | if (prec != -1) |
| 205 | { |
| 206 | // I doubt anyone will ever do this, so just allocate. |
| 207 | tempBuffer = new char[maxlen + 1]; |
| 208 | memcpy(tempBuffer, string, size); |
| 209 | tempBuffer[size] = '\0'; |
| 210 | } |
| 211 | |