X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.c;h=d226af963af82c6c99e557402694b919b26c2192;hp=cefb45d674075cf1fcb2e42b42e5b0a929a52c16;hb=b5e5c97342576b3a5f2b09feb68b38abea5dad22;hpb=63aab30b55d5809704a2d0e1c4e8de20e8228d7d diff --git a/string.c b/string.c index cefb45d6..d226af96 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(). *