X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-lib%2Fstr.h;h=1beac83790c4aea914680f71bd10154f0cd62e9b;hb=bf962aa95d973d266241deb552e5e4ffae484692;hp=882a103ffaf5e2b113161ec3d10f1a0473335621;hpb=693bfbaf2d595042ed12eea010bf01bb0ea9c125;p=apps%2Fmadmutt.git diff --git a/lib-lib/str.h b/lib-lib/str.h index 882a103..1beac83 100644 --- a/lib-lib/str.h +++ b/lib-lib/str.h @@ -193,6 +193,8 @@ static inline ssize_t m_strnlen(const char *s, ssize_t n) { return 0; } +ssize_t m_strwidth(const char *s); + /****************************************************************************/ /* comparisons */ /****************************************************************************/ @@ -301,6 +303,25 @@ static inline ssize_t m_strputc(char *dst, ssize_t n, int c) { return 1; } +/** \brief Sets a portion of a string to a defined character, à la memset. + * + * \param[in] dst pointer to the buffer. + * \param[in] n size of that buffer, (negative values allowed). + * \param[in] c the char to use in the padding. + * \param[in] len length of the padding. + * \return MAX(0, len). + */ +__attribute__((nonnull(1))) +static inline ssize_t m_strpad(char *dst, ssize_t n, int c, ssize_t len) +{ + ssize_t dlen = MIN(n - 1, len); + if (dlen > 0) { + memset(dst, c, dlen); + dst[dlen] = '\0'; + } + return MAX(0, len); +} + ssize_t m_strcpy(char *dst, ssize_t n, const char *src) __attribute__((nonnull(1))); @@ -340,6 +361,24 @@ m_strncat(char *dst, ssize_t n, const char *src, ssize_t l) { return dlen + m_strncpy(dst + dlen, n - dlen, src, l); } +/* flags for m_strformat() */ +typedef enum { + M_FORMAT_FORCESUBJ = (1 << 0), /* print the subject even if unchanged */ + M_FORMAT_TREE = (1 << 1), /* draw the thread tree */ + M_FORMAT_MAKEPRINT = (1 << 2), /* make sure that all chars are printable */ + M_FORMAT_OPTIONAL = (1 << 3), + M_FORMAT_STAT_FILE = (1 << 4), /* used by mutt_attach_fmt */ + M_FORMAT_ARROWCURSOR = (1 << 5), /* reserve space for arrow_cursor */ + M_FORMAT_INDEX = (1 << 6) /* this is a main index entry */ +} format_flag; + +typedef const char * +format_t(char *, ssize_t, char, const char *, + const char *, const char *, const char *, anytype, format_flag); + +ssize_t m_strformat(char *, ssize_t, int, const char *, + format_t *, anytype, format_flag); + /****************************************************************************/ /* parsing related */ /****************************************************************************/