removing a strdup() call and a buffer from rparagraph.

This commit is contained in:
Enno Rehling 2006-01-26 23:05:40 +00:00
parent 6c6c1174d8
commit cf996bc5fb
7 changed files with 58 additions and 40 deletions

View File

@ -225,7 +225,7 @@ rpsnr(FILE * F, const char * s, int offset)
if (*(x - 1) && indent && *x == ' ') indent += 2;
if (!indent) indent = offset;
x = s;
memset(inset, 32, indent * sizeof(char));
memset(inset, ' ', indent * sizeof(char));
inset[indent] = 0;
while (s <= x+len) {
size_t line = min(len-(s-x), REPORTWIDTH - indent*ui);
@ -349,27 +349,39 @@ centre(FILE * F, const char *s, boolean breaking)
static void
rparagraph(FILE *F, const char *s, int indent, char mark)
{
static char mbuf[BUFSIZE+1];
/* static size_t bsize = 0; */
size_t size;
char inset[REPORTWIDTH];
static const char * spaces = " ";
size_t length = REPORTWIDTH - indent;
const char * end = s;
if (indent) {
memset(inset, ' ', indent);
inset[indent]=0;
if (mark)
inset[indent - 2] = mark;
} else {
assert(mark == 0);
inset[0] = 0;
}
inset[indent]=0;
size = strlen(s)+indent+1;
if (size==1) return;
strcpy(mbuf, inset);
strncpy(mbuf+indent, s, BUFSIZE-indent);
*(mbuf+size-1)=0;
rps(F, mbuf);
while (*s) {
const char * last_space = s;
if (mark && indent>=2) {
fwrite(spaces, sizeof(char), indent-2, F);
fputc(mark, F);
fputc(' ', F);
mark = 0;
} else {
fwrite(spaces, sizeof(char), indent, F);
}
while (*end && end!=s+length) {
if (*end==' ') {
last_space = end;
}
++end;
}
if (last_space==s) {
/* there was no space in this line. clip it */
last_space = end;
}
fwrite(s, sizeof(char), last_space-s, F);
s = last_space;
while (*s==' ') {
++s;
}
if (s>end) end = s;
fputc('\n', F);
}
}
static void
@ -1700,9 +1712,12 @@ guards(FILE * F, const region * r, const faction * see)
static void
rpline(FILE * F)
{
rpc(F, ' ', 1);
rpc(F, '-', REPORTWIDTH);
rnl(F);
static char line[REPORTWIDTH+1];
if (line[0]!='-') {
memset(line, '-', sizeof(line));
line[REPORTWIDTH] = '\n';
}
fwrite(line, sizeof(char), sizeof(line), F);
}
static void

View File

@ -27,11 +27,12 @@
#include "save.h"
/* util includes */
#include <base36.h>
#include <functions.h>
#include <resolve.h>
#include <event.h>
#include <language.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/functions.h>
#include <util/language.h>
#include <util/resolve.h>
#include <util/umlaut.h>
/* libc includes */
#include <assert.h>

View File

@ -98,7 +98,6 @@ struct building_type;
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/umlaut.h>
#include <util/variant.h>
#include <util/vmap.h>
#include <util/vset.h>
@ -1067,12 +1066,6 @@ extern void guard(struct unit * u, unsigned int mask);
* 'mask' kann einzelne flags zusätzlich und-maskieren.
*/
typedef struct local_names {
struct local_names * next;
const struct locale * lang;
struct tnode names;
} local_names;
extern boolean hunger(int number, struct unit * u);
extern int lifestyle(const struct unit*);
extern int besieged(const struct unit * u);

View File

@ -39,6 +39,7 @@
#include <util/functions.h>
#include <util/goodies.h>
#include <util/message.h>
#include <util/umlaut.h>
/* libc includes */
#include <assert.h>

View File

@ -24,10 +24,11 @@
#include "skill.h"
/* util includes */
#include <base36.h>
#include <event.h>
#include <xml.h>
#include <language.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/language.h>
#include <util/umlaut.h>
#include <util/xml.h>
/* libc includes */
#include <stdlib.h>

View File

@ -35,6 +35,7 @@
/* util includes */
#include <util/goodies.h>
#include <util/language.h>
#include <util/umlaut.h>
/* Bitte die Sprüche nach Gebieten und Stufe ordnen, denn in derselben
* Reihenfolge wie in Spelldaten tauchen sie auch im Report auf

View File

@ -35,6 +35,12 @@ typedef struct tnode {
int findtoken(const struct tnode * tk, const char * str, variant* result);
void addtoken(struct tnode * root, const char* str, variant id);
typedef struct local_names {
struct local_names * next;
const struct locale * lang;
struct tnode names;
} local_names;
#ifdef __cplusplus
}
#endif