X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;h=3bddd5e80896e843470687671a05cb0ef09051e2;hp=f7d70353db977d6543055c19c7bd68a17b83a3ce;hb=f7d3162fdf4c348beb7d315a85b34af6e1cdaff5;hpb=f48194d3ff2a3983f21cab1553fbe29529f2e790 diff --git a/string.c b/string.c index f7d70353..3bddd5e8 100644 --- a/string.c +++ b/string.c @@ -711,6 +711,32 @@ out: return ret; } +/** + * Get the number of the word the cursor is on. + * + * \param buf The zero-terminated line buffer. + * \param delim Characters that separate words. + * \param point The cursor position. + * + * \return Zero-based word number. + */ +int compute_word_num(const char *buf, const char *delim, int point) +{ + int ret, num_words; + const char *p; + char *word; + + for (p = buf, num_words = 0; ; p += ret, num_words++) { + ret = get_next_word(p, delim, &word); + if (ret <= 0) + break; + free(word); + if (p + ret >= buf + point) + break; + } + return num_words; +} + /** * Free an array of words created by create_argv(). *