#ifndef DSTRING_H
#define DSTRING_H

#include <time.h>

typedef struct {
  char *string;
  int length;
  int spaceAvl;
} DString;

#ifdef __GNUC__
/* This function uses printf-style formats, so tell GNUC to do printf
 * format checking. */
#define ATTRIBUTE_PRINTF(fmt, args) \
   __attribute__ ((format (printf, fmt, args)))
#else
#define ATTRIBUTE_PRINTF(fmt, args)
#endif

/* Create new, empty DString. */
extern void  DStringInit(DString *d);

/* Append 'string' of length 'length' to 'd'. */
extern char *DStringAppend(DString *d, char *string, int length);

/* Append 'string' to 'd', while quoting characters in 'quote'. */
char *DStringAppendQuoted(DString *d, char *string, char *quote);

/* Append DString 'src' to DString 'dst'. */
extern char *DStringAppendD(DString *dst, DString *src);

/* sprintf() into DString 'd' using format 'format'. */
extern char *DStringPrintf(DString *d, char *format, ...)
     ATTRIBUTE_PRINTF(2, 3);

/* Convert time 'tm' to text using 'format', with destination 'd'. */
extern char *DStringStrftime(DString *d, char *format, struct tm *tm); 

/* Convert time 't' to text using 'format', with destination 'd'. If
'localtime' is 0, GMT is used. */
extern char *DStringCftime(DString *d, char *format, time_t t, int localtime);

/* Return char * value of DString. */
extern char *DStringValue(DString *d);

/* Remove leading and trailing white space from DString. */
extern char *DStringTrim(DString *d);

/* Trim allocation of DString to actual size. */
extern void  DStringTrunc(DString *d);

/* Free storage for DString. */
extern void  DStringFree(DString *d);

/* Return length of DString 'd'. */
extern int   DStringLength(DString *d);

#undef ATTRIBUTE_PRINTF
#endif
