Skip to content
Browse files

Move remvoe_stopwords to apropos-utils.c

  • Loading branch information...
1 parent 66573eb commit 569e2c629b2f9cf419ab4787cd347d1b96b3ec73 @abhinav-upadhyay committed Mar 11, 2012
Showing with 45 additions and 46 deletions.
  1. +44 −0 apropos-utils.c
  2. +1 −0 apropos-utils.h
  3. +0 −46 apropos.c
View
44 apropos-utils.c
@@ -83,6 +83,50 @@ static const double col_weights[] = {
1.00 //machine
};
+#include "stopwords.c"
+/*
+ * remove_stopwords--
+ * Scans the query and removes any stop words from it.
+ * Returns the modified query or NULL, if it contained only stop words.
+ */
+
+char *
+remove_stopwords(const char *query)
+{
+ size_t len, idx;
+ char *output, *buf;
+ const char *sep, *next;
+
+ output = buf = emalloc(strlen(query) + 1);
+
+ for (; query[0] != '\0'; query = next) {
+ sep = strchr(query, ' ');
+ if (sep == NULL) {
+ len = strlen(query);
+ next = query + len;
+ } else {
+ len = sep - query;
+ next = sep + 1;
+ }
+ if (len == 0)
+ continue;
+ idx = stopwords_hash(query, len);
+ if (memcmp(stopwords[idx], query, len) == 0 &&
+ stopwords[idx][len] == '\0')
+ continue;
+ memcpy(buf, query, len);
+ buf += len;
+ *buf++ = ' ';
+ }
+
+ if (output == buf) {
+ free(output);
+ return NULL;
+ }
+ buf[-1] = '\0';
+ return output;
+}
+
/*
* lower --
* Converts the string str to lower case
View
1 apropos-utils.h
@@ -89,5 +89,6 @@ void close_db(sqlite3 *);
int run_query(sqlite3 *, const char *[3], query_args *);
int run_query_html(sqlite3 *, query_args *);
int run_query_pager(sqlite3 *, query_args *);
+char *remove_stopwords(const char *);
char *spell(sqlite3*, char *);
#endif
View
46 apropos.c
@@ -58,7 +58,6 @@ typedef struct callback_data {
apropos_flags *aflags;
} callback_data;
-static char *remove_stopwords(const char *);
static int query_callback(void *, const char * , const char *, const char *,
const char *, size_t);
__dead static void usage(void);
@@ -259,51 +258,6 @@ query_callback(void *data, const char *section, const char *name,
return 0;
}
-#include "stopwords.c"
-
-/*
- * remove_stopwords--
- * Scans the query and removes any stop words from it.
- * Returns the modified query or NULL, if it contained only stop words.
- */
-
-static char *
-remove_stopwords(const char *query)
-{
- size_t len, idx;
- char *output, *buf;
- const char *sep, *next;
-
- output = buf = emalloc(strlen(query) + 1);
-
- for (; query[0] != '\0'; query = next) {
- sep = strchr(query, ' ');
- if (sep == NULL) {
- len = strlen(query);
- next = query + len;
- } else {
- len = sep - query;
- next = sep + 1;
- }
- if (len == 0)
- continue;
- idx = stopwords_hash(query, len);
- if (memcmp(stopwords[idx], query, len) == 0 &&
- stopwords[idx][len] == '\0')
- continue;
- memcpy(buf, query, len);
- buf += len;
- *buf++ = ' ';
- }
-
- if (output == buf) {
- free(output);
- return NULL;
- }
- buf[-1] = '\0';
- return output;
-}
-
/*
* usage --
* print usage message and die

0 comments on commit 569e2c6

Please sign in to comment.
Something went wrong with that request. Please try again.