X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=string.c;h=8c8c50ac6ef30e51ec86751837e44e0e2a4ef95f;hb=d4b040af5e31260dbf71f4547484179f32be4746;hp=f7d70353db977d6543055c19c7bd68a17b83a3ce;hpb=f48194d3ff2a3983f21cab1553fbe29529f2e790;p=paraslash.git diff --git a/string.c b/string.c index f7d70353..8c8c50ac 100644 --- a/string.c +++ b/string.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2011 Andre Noll + * Copyright (C) 2004-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -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(). *