]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - string.c
client: Implement interactive mode.
[paraslash.git] / string.c
index 0a32c0f48b3b8fc9a1b5194587fc10068789a064..d226af963af82c6c99e557402694b919b26c2192 100644 (file)
--- a/string.c
+++ b/string.c
@@ -521,14 +521,15 @@ __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...)
        }
 }
 
-/** \cond LLONG_MAX and LLONG_MIN might not be defined. */
+/** \cond llong_minmax */
+/* LLONG_MAX and LLONG_MIN might not be defined. */
 #ifndef LLONG_MAX
 #define LLONG_MAX 9223372036854775807LL
 #endif
 #ifndef LLONG_MIN
 #define LLONG_MIN (-LLONG_MAX - 1LL)
 #endif
-/** \endcond */
+/** \endcond llong_minmax */
 
 /**
  * Convert a string to a 64-bit signed integer value.
@@ -710,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().
  *