remove trailing whitespace

This commit is contained in:
christos 2013-02-10 23:24:18 +00:00
parent 01401401c3
commit 9d8fe63b1b
4 changed files with 70 additions and 70 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: apropos-utils.c,v 1.9 2013/01/14 21:26:25 christos Exp $ */
/* $NetBSD: apropos-utils.c,v 1.10 2013/02/10 23:24:18 christos Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: apropos-utils.c,v 1.9 2013/01/14 21:26:25 christos Exp $");
__RCSID("$NetBSD: apropos-utils.c,v 1.10 2013/02/10 23:24:18 christos Exp $");
#include <sys/queue.h>
#include <sys/stat.h>
@ -99,8 +99,8 @@ lower(char *str)
/*
* concat--
* Utility function. Concatenates together: dst, a space character and src.
* dst + " " + src
* Utility function. Concatenates together: dst, a space character and src.
* dst + " " + src
*/
void
concat(char **dst, const char *src)
@ -131,7 +131,7 @@ concat2(char **dst, const char *src, size_t srclen)
/* Append a space at the end of dst */
(*dst)[dst_len++] = ' ';
/* Now, copy src at the end of dst */
/* Now, copy src at the end of dst */
memcpy(*dst + dst_len, src, srclen + 1);
}
@ -152,7 +152,7 @@ create_db(sqlite3 *db)
const char *sqlstr = NULL;
char *schemasql;
char *errmsg = NULL;
/*------------------------ Create the tables------------------------------*/
#if NOTYET
@ -207,7 +207,7 @@ out:
*/
static void
zip(sqlite3_context *pctx, int nval, sqlite3_value **apval)
{
{
int nin;
long int nout;
const unsigned char * inbuf;
@ -278,7 +278,7 @@ get_dbpath(const char *manconf)
tp = gettag("_mandb", 1);
if (!tp)
return NULL;
if (TAILQ_EMPTY(&tp->entrylist))
return NULL;
@ -289,15 +289,15 @@ get_dbpath(const char *manconf)
/* init_db --
* Prepare the database. Register the compress/uncompress functions and the
* stopword tokenizer.
* db_flag specifies the mode in which to open the database. 3 options are
* db_flag specifies the mode in which to open the database. 3 options are
* available:
* 1. DB_READONLY: Open in READONLY mode. An error if db does not exist.
* 2. DB_READWRITE: Open in read-write mode. An error if db does not exist.
* 3. DB_CREATE: Open in read-write mode. It will try to create the db if
* it does not exist already.
* RETURN VALUES:
* The function will return NULL in case the db does not exist and DB_CREATE
* was not specified. And in case DB_CREATE was specified and yet NULL is
* The function will return NULL in case the db does not exist and DB_CREATE
* was not specified. And in case DB_CREATE was specified and yet NULL is
* returned, then there was some other error.
* In normal cases the function should return a handle to the db.
*/
@ -329,7 +329,7 @@ init_db(int db_flag, const char *manconf)
/* Now initialize the database connection */
sqlite3_initialize();
rc = sqlite3_open_v2(dbpath, &db, db_flag, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
sqlite3_shutdown();
@ -362,7 +362,7 @@ init_db(int db_flag, const char *manconf)
sqlite3_finalize(stmt);
sqlite3_extended_result_codes(db, 1);
/* Register the zip and unzip functions for FTS compression */
rc = sqlite3_create_function(db, "zip", 1, SQLITE_ANY, NULL, zip, NULL, NULL);
if (rc != SQLITE_OK) {
@ -371,7 +371,7 @@ init_db(int db_flag, const char *manconf)
goto error;
}
rc = sqlite3_create_function(db, "unzip", 1, SQLITE_ANY, NULL,
rc = sqlite3_create_function(db, "unzip", 1, SQLITE_ANY, NULL,
unzip, NULL, NULL);
if (rc != SQLITE_OK) {
warnx("Unable to register function: uncompress: %s",
@ -391,14 +391,14 @@ error:
* Sqlite user defined function for ranking the documents.
* For each phrase of the query, it computes the tf and idf and adds them over.
* It computes the final rank, by multiplying tf and idf together.
* Weight of term t for document d = (term frequency of t in d *
* inverse document frequency of t)
* Weight of term t for document d = (term frequency of t in d *
* inverse document frequency of t)
*
* Term Frequency of term t in document d = Number of times t occurs in d /
* Number of times t appears in all
* Term Frequency of term t in document d = Number of times t occurs in d /
* Number of times t appears in all
* documents
*
* Inverse document frequency of t = log(Total number of documents /
* Inverse document frequency of t = log(Total number of documents /
* Number of documents in which t occurs)
*/
static void
@ -424,12 +424,12 @@ rank_func(sqlite3_context *pctx, int nval, sqlite3_value **apval)
int icol;
const unsigned int *phraseinfo = &matchinfo[2 + ncol+ iphrase * ncol * 3];
for(icol = 1; icol < ncol; icol++) {
/* nhitcount: number of times the current phrase occurs in the current
* column in the current document.
* nglobalhitcount: number of times current phrase occurs in the current
* column in all documents.
* ndocshitcount: number of documents in which the current phrase
* ndocshitcount: number of documents in which the current phrase
* occurs in the current column at least once.
*/
int nhitcount = phraseinfo[3 * icol];
@ -440,7 +440,7 @@ rank_func(sqlite3_context *pctx, int nval, sqlite3_value **apval)
if (idf->status == 0 && ndocshitcount)
idf->value += log(((double)ndoc / ndocshitcount))* weight;
/* Dividing the tf by document length to normalize the effect of
/* Dividing the tf by document length to normalize the effect of
* longer documents.
*/
if (nglobalhitcount > 0 && nhitcount)
@ -448,9 +448,9 @@ rank_func(sqlite3_context *pctx, int nval, sqlite3_value **apval)
}
}
idf->status = 1;
/* Final score = (tf * idf)/ ( k + tf)
* Dividing by k+ tf further normalizes the weight leading to better
* Dividing by k+ tf further normalizes the weight leading to better
* results.
* The value of k is experimental
*/
@ -464,9 +464,9 @@ rank_func(sqlite3_context *pctx, int nval, sqlite3_value **apval)
* Performs the searches for the keywords entered by the user.
* The 2nd param: snippet_args is an array of strings providing values for the
* last three parameters to the snippet function of sqlite. (Look at the docs).
* The 3rd param: args contains rest of the search parameters. Look at
* The 3rd param: args contains rest of the search parameters. Look at
* arpopos-utils.h for the description of individual fields.
*
*
*/
int
run_query(sqlite3 *db, const char *snippet_args[3], query_args *args)
@ -492,7 +492,7 @@ run_query(sqlite3 *db, const char *snippet_args[3], query_args *args)
easprintf(&machine_clause, "AND machine = \'%s\' ", args->machine);
/* Register the rank function */
rc = sqlite3_create_function(db, "rank_func", 1, SQLITE_ANY, (void *)&idf,
rc = sqlite3_create_function(db, "rank_func", 1, SQLITE_ANY, (void *)&idf,
rank_func, NULL, NULL);
if (rc != SQLITE_OK) {
warnx("Unable to register the ranking function: %s",
@ -501,12 +501,12 @@ run_query(sqlite3 *db, const char *snippet_args[3], query_args *args)
sqlite3_shutdown();
exit(EXIT_FAILURE);
}
/* We want to build a query of the form: "select x,y,z from mandb where
* mandb match :query [AND (section LIKE '1' OR section LIKE '2' OR...)]
* ORDER BY rank DESC..."
* NOTES: 1. The portion in square brackets is optional, it will be there
* only if the user has specified an option on the command line to search in
* NOTES: 1. The portion in square brackets is optional, it will be there
* only if the user has specified an option on the command line to search in
* one or more specific sections.
* 2. I am using LIKE operator because '=' or IN operators do not seem to be
* working with the compression option enabled.
@ -623,7 +623,7 @@ callback_html(void *data, const char *section, const char *name,
size_t sz = 0;
int count = 0;
struct orig_callback_data *orig_data = (struct orig_callback_data *) data;
int (*callback) (void *, const char *, const char *, const char *,
int (*callback) (void *, const char *, const char *, const char *,
const char *, size_t) = orig_data->callback;
/* First scan the snippet to find out the number of occurrences of {'>', '<'
@ -696,7 +696,7 @@ callback_html(void *data, const char *section, const char *name,
/*
* run_query_html --
* Utility function to output query result in HTML format.
* It internally calls run_query only, but it first passes the output to it's
* It internally calls run_query only, but it first passes the output to it's
* own custom callback function, which preprocess the snippet for quoting
* inline HTML fragments.
* After that it delegates the call the actual user supplied callback function.
@ -742,7 +742,7 @@ ul_pager(const char *s)
* more or less.
*/
static int
callback_pager(void *data, const char *section, const char *name,
callback_pager(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, size_t snippet_length)
{
struct orig_callback_data *orig_data = (struct orig_callback_data *) data;
@ -832,7 +832,7 @@ ul_term(const char *s, const struct term_args *ta)
* more or less.
*/
static int
callback_term(void *data, const char *section, const char *name,
callback_term(void *data, const char *section, const char *name,
const char *name_desc, const char *snippet, size_t snippet_length)
{
struct term_args *ta = data;

View File

@ -1,4 +1,4 @@
/* $NetBSD: apropos-utils.h,v 1.5 2013/01/14 21:26:25 christos Exp $ */
/* $NetBSD: apropos-utils.h,v 1.6 2013/02/10 23:24:18 christos Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@ -91,4 +91,4 @@ int run_query(sqlite3 *, const char *[3], query_args *);
int run_query_html(sqlite3 *, query_args *);
int run_query_pager(sqlite3 *, query_args *);
int run_query_term(sqlite3 *, query_args *);
#endif
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: apropos.c,v 1.10 2013/01/14 21:26:25 christos Exp $ */
/* $NetBSD: apropos.c,v 1.11 2013/02/10 23:24:18 christos Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* All rights reserved.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: apropos.c,v 1.10 2013/01/14 21:26:25 christos Exp $");
__RCSID("$NetBSD: apropos.c,v 1.11 2013/02/10 23:24:18 christos Exp $");
#include <err.h>
#include <search.h>
@ -85,9 +85,9 @@ main(int argc, char *argv[])
usage();
memset(&aflags, 0, sizeof(aflags));
/*If the user specifies a section number as an option, the corresponding
* index element in sec_nums is set to the string representing that
/*If the user specifies a section number as an option, the corresponding
* index element in sec_nums is set to the string representing that
* section number.
*/
while ((ch = getopt(argc, argv, "123456789Ccn:pS:s:")) != -1) {
@ -130,10 +130,10 @@ main(int argc, char *argv[])
usage();
}
}
argc -= optind;
argv += optind;
if (!argc)
usage();
@ -177,7 +177,7 @@ main(int argc, char *argv[])
rc = run_query_term(db, &args);
else
rc = run_query_pager(db, &args);
free(query);
close_db(db);
if (errmsg) {
@ -190,7 +190,7 @@ main(int argc, char *argv[])
/* Something wrong with the database. Exit */
exit(EXIT_FAILURE);
}
if (cbdata.count == 0) {
warnx("No relevant results obtained.\n"
"Please make sure that you spelled all the terms correctly "

View File

@ -1,4 +1,4 @@
/* $NetBSD: makemandb.c,v 1.17 2013/01/14 18:01:59 christos Exp $ */
/* $NetBSD: makemandb.c,v 1.18 2013/02/10 23:24:18 christos Exp $ */
/*
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: makemandb.c,v 1.17 2013/01/14 18:01:59 christos Exp $");
__RCSID("$NetBSD: makemandb.c,v 1.18 2013/02/10 23:24:18 christos Exp $");
#include <sys/stat.h>
#include <sys/types.h>
@ -108,7 +108,7 @@ static void pmdoc_Nd(const struct mdoc_node *, mandb_rec *);
static void pmdoc_Sh(const struct mdoc_node *, mandb_rec *);
static void pmdoc_Xr(const struct mdoc_node *, mandb_rec *);
static void pmdoc_Pp(const struct mdoc_node *, mandb_rec *);
static void pmdoc_macro_handler(const struct mdoc_node *, mandb_rec *,
static void pmdoc_macro_handler(const struct mdoc_node *, mandb_rec *,
enum mdoct);
static void pman_node(const struct man_node *n, mandb_rec *);
static void pman_parse_node(const struct man_node *, secbuff *);
@ -387,7 +387,7 @@ main(int argc, char *argv[])
free(errmsg);
exit(EXIT_FAILURE);
}
sqlstr = "CREATE TABLE metadb.file_cache(device, inode, mtime, parent,"
" file PRIMARY KEY);"
"CREATE UNIQUE INDEX metadb.index_file_cache_dev"
@ -464,13 +464,13 @@ traversedir(const char *parent, const char *file, sqlite3 *db,
warn("stat failed: %s", file);
return;
}
/* If it is a regular file or a symlink, pass it to build_cache() */
if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode)) {
build_file_cache(db, parent, file, &sb);
return;
}
/* If it is a directory, traverse it recursively */
if (S_ISDIR(sb.st_mode)) {
if ((dp = opendir(file)) == NULL) {
@ -478,7 +478,7 @@ traversedir(const char *parent, const char *file, sqlite3 *db,
warn("opendir error: %s", file);
return;
}
while ((dirp = readdir(dp)) != NULL) {
/* Avoid . and .. entries in a directory */
if (strncmp(dirp->d_name, ".", 1)) {
@ -784,7 +784,7 @@ update_db(sqlite3 *db, struct mparse *mp, mandb_rec *rec)
free(buf);
sqlite3_finalize(stmt);
if (mflags.verbosity == 2) {
printf("Total Number of new or updated pages encountered = %d\n"
"Total number of (hard or symbolic) links found = %d\n"
@ -1179,7 +1179,7 @@ pman_node(const struct man_node *n, mandb_rec *rec)
pman_node(n->next, rec);
}
/*
/*
* pman_parse_name --
* Parses the NAME section and puts the complete content in the name_desc
* variable.
@ -1212,7 +1212,7 @@ pman_block(const struct man_node *n, mandb_rec *rec)
{
}
/*
/*
* pman_sh --
* This function does one of the two things:
* 1. If the present section is NAME, then it will:
@ -1283,7 +1283,7 @@ pman_sh(const struct man_node *n, mandb_rec *rec)
/* Remove any leading spaces. */
while (name_desc[0] == ' ')
name_desc++;
/* If the line begins with a "\&", avoid those */
if (name_desc[0] == '\\' && name_desc[1] == '&')
name_desc += 2;
@ -1375,7 +1375,7 @@ pman_sh(const struct man_node *n, mandb_rec *rec)
/*
* pman_parse_node --
* Generic function to iterate through a node. Usually called from
* Generic function to iterate through a node. Usually called from
* man_parse_section to parse a particular section of the man page.
*/
static void
@ -1386,14 +1386,14 @@ pman_parse_node(const struct man_node *n, secbuff *s)
if (n->type == MAN_TEXT)
append(s, n->string);
pman_parse_node(n->child, s);
pman_parse_node(n->next, s);
}
/*
* man_parse_section --
* Takes two parameters:
* Takes two parameters:
* sec: Tells which section we are present in
* n: Is the present node of the AST.
* Depending on the section, we call pman_parse_node to parse that section and
@ -1464,12 +1464,12 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
char *ln = NULL;
char *errmsg = NULL;
long int mandb_rowid;
/*
* At the very minimum we want to make sure that we store
* the following data:
* Name, one line description, and the MD5 hash
*/
*/
if (rec->name == NULL || rec->name_desc == NULL ||
rec->md5_hash == NULL) {
cleanup(rec);
@ -1601,14 +1601,14 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
sqlite3_finalize(stmt);
goto Out;
}
idx = sqlite3_bind_parameter_index(stmt, ":md5_hash");
rc = sqlite3_bind_text(stmt, idx, rec->md5_hash, -1, NULL);
if (rc != SQLITE_OK) {
sqlite3_finalize(stmt);
goto Out;
}
idx = sqlite3_bind_parameter_index(stmt, ":machine");
if (rec->machine)
rc = sqlite3_bind_text(stmt, idx, rec->machine, -1, NULL);
@ -1626,10 +1626,10 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
}
sqlite3_finalize(stmt);
/* Get the row id of the last inserted row */
mandb_rowid = sqlite3_last_insert_rowid(db);
/*------------------------Populate the mandb_meta table-----------------------*/
sqlstr = "INSERT INTO mandb_meta VALUES (:device, :inode, :mtime,"
" :file, :md5_hash, :id)";
@ -1752,7 +1752,7 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
/*------------------------ Populate the mandb_links table---------------------*/
char *str = NULL;
char *links;
char *links;
if (rec->links && strlen(rec->links)) {
links = rec->links;
for(ln = strtok(links, " "); ln; ln = strtok(NULL, " ")) {
@ -1760,7 +1760,7 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
ln++;
if(ln[strlen(ln) - 1] == ',')
ln[strlen(ln) - 1] = 0;
str = sqlite3_mprintf("INSERT INTO mandb_links"
" VALUES (%Q, %Q, %Q, %Q, %Q)",
ln, rec->name, rec->section,
@ -1839,7 +1839,7 @@ check_md5(const char *file, sqlite3 *db, const char *table, char **md5sum,
}
if (sqlite3_step(stmt) == SQLITE_ROW) {
sqlite3_finalize(stmt);
sqlite3_finalize(stmt);
free(sqlstr);
return 0;
}
@ -1869,7 +1869,7 @@ optimize(sqlite3 *db)
}
}
/*
/*
* cleanup --
* cleans up the global buffers
*/
@ -2018,7 +2018,7 @@ parse_escape(const char *str)
} while (backslash != NULL);
if (last_backslash != NULL)
strcpy(iter, last_backslash);
replace_hyph(result);
return result;
}