Skip to content
Browse files

Went on an anti-whitespace crusade

Trailing whitespace is now dead. Very dead.

Let's hope it does not return.
  • Loading branch information...
1 parent 693cb8f commit 79964a2d539505c2277bcba0b3ddf5961f33c8d3 Dave Täht committed Jan 10, 2011
View
4 doc/index.org
@@ -1,7 +1,7 @@
#+TITLE: GNUGOL
#+AUTHOR: Dave Täht
-#+EMAIL: d at taht.net
-#+DATE: <2010-12-21 Tue>
+#+EMAIL: d + gnugol at taht.net
+#+DATE: <2011-01-10 Mon>
#+LANGUAGE: en
#+TEXT: A command line text only web search client
#+DESCRIPTION: GNUGOL - an org-mode compatible search client
View
42 src/clients/gnugol_cgi.c
@@ -17,12 +17,12 @@ void Cookies();
/* It will be simpler to just generate a cookie based on the set options */
-int Query(QueryOptions *q) {
+int Query(QueryOptions *q) {
int i;
int n = query_main(q,"::1");
// int n = query_main(q,"2001:4f8:3:36:2e0:81ff:fe23:90d3");
- int output =
- q->options.urls >> 3 | q->options.snippets >> 2 |
+ int output =
+ q->options.urls >> 3 | q->options.snippets >> 2 |
q->options.titles >> 1; // | q->options.ads ;
// fprintf(cgiOut,"shift = %d\n",output);
@@ -92,15 +92,15 @@ int titlepage(QueryData *q, char *title) {
fprintf(cgiOut,"<img src=/gnugol/images/gnugol.png><br><hr>");
} else {
fprintf(cgiOut, "<body>");
- }
+ }
}
int EmptySubmit(QueryData *q) {
titlepage(q,"Gnugol Search");
ShowForm(q);
// FIXME - check to see if we've primed the cache recently
// q->options.prime=1;
- // int n = query_main(q,"::1");
+ // int n = query_main(q,"::1");
}
void HandleSubmit(QueryData *q)
@@ -110,7 +110,7 @@ void HandleSubmit(QueryData *q)
strcpy(query,q->keywords);
// cgiFormStringNoNewlines("q", query, 1024);
cgiHtmlEscape(query);
- cgiFormString("q", query, sizeof(query));
+ cgiFormString("q", query, sizeof(query));
titlepage(q,query);
q->options.urls = q->options.snippets = 1;
q->options.nresults = 3;
@@ -236,28 +236,28 @@ void Cookies()
arrayStep++;
}
fprintf(cgiOut, "</table>\n");
- cgiFormString("cname", cname, sizeof(cname));
- cgiFormString("cvalue", cvalue, sizeof(cvalue));
+ cgiFormString("cname", cname, sizeof(cname));
+ cgiFormString("cvalue", cvalue, sizeof(cvalue));
if (strlen(cname)) {
fprintf(cgiOut, "New Cookie Set On This Call:<p>\n");
- fprintf(cgiOut, "Name: ");
+ fprintf(cgiOut, "Name: ");
cgiHtmlEscape(cname);
- fprintf(cgiOut, "Value: ");
+ fprintf(cgiOut, "Value: ");
cgiHtmlEscape(cvalue);
fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "If your browser accepts cookies (many do not), this new cookie should appear in the above list the next time the form is submitted.<p>\n");
+ fprintf(cgiOut, "If your browser accepts cookies (many do not), this new cookie should appear in the above list the next time the form is submitted.<p>\n");
}
cgiStringArrayFree(array);
}
-
+
void ShowForm(QueryData *q)
{
char keywords[1080];
fprintf(cgiOut, "<form method=\"GET\"");
fprintf(cgiOut, "action=\"");
cgiValueEscape(cgiScriptName);
fprintf(cgiOut, "\"><p>");
- if(cgiFormString("q", keywords, sizeof(keywords)));
+ if(cgiFormString("q", keywords, sizeof(keywords)));
if(keywords[0] != '\0') {
strcpy(q->keywords,keywords);
@@ -277,21 +277,21 @@ void CookieSet()
char cname[1024];
char cvalue[1024];
/* Must set cookies BEFORE calling cgiHeaderContentType */
- cgiFormString("cname", cname, sizeof(cname));
- cgiFormString("cvalue", cvalue, sizeof(cvalue));
+ cgiFormString("cname", cname, sizeof(cname));
+ cgiFormString("cvalue", cvalue, sizeof(cvalue));
if (strlen(cname)) {
/* Cookie lives for one day (or until browser chooses
to get rid of it, which may be immediately),
- and applies only to this script on this site. */
+ and applies only to this script on this site. */
cgiHeaderCookieSetString(cname, cvalue,
86400, cgiScriptName, SERVER_NAME);
}
}
void LoadEnvironment()
{
- if (cgiReadEnvironment(SAVED_ENVIRONMENT) !=
- cgiEnvironmentSuccess)
+ if (cgiReadEnvironment(SAVED_ENVIRONMENT) !=
+ cgiEnvironmentSuccess)
{
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<head>Error</head>\n");
@@ -306,8 +306,8 @@ void LoadEnvironment()
void SaveEnvironment()
{
- if (cgiWriteEnvironment(SAVED_ENVIRONMENT) !=
- cgiEnvironmentSuccess)
+ if (cgiWriteEnvironment(SAVED_ENVIRONMENT) !=
+ cgiEnvironmentSuccess)
{
fprintf(cgiOut, "<p>cgiWriteEnvironment failed. Most "
"likely %s is not a valid path or is not "
@@ -319,7 +319,7 @@ void SaveEnvironment()
"scenario: "
"<form method=POST action=\"");
cgiValueEscape(cgiScriptName);
- fprintf(cgiOut, "\">"
+ fprintf(cgiOut, "\">"
"<input type=\"submit\" "
"value=\"Load Environment\" "
"name=\"loadenvironment\"></form><p>\n");
View
18 src/clients/gnugol_fcgi.c
@@ -1,5 +1,5 @@
-/* This code is Copyright (C) 2008 by Michael David Taht
- and released under the terms of the GNU AFFERO PUBLIC_LICENSE, version 3
+/* This code is Copyright (C) 2008 by Michael David Taht
+ and released under the terms of the GNU AFFERO PUBLIC_LICENSE, version 3
for details of this license see the COPYRIGHT file */
/* fastcgi client for gnugol */
@@ -38,7 +38,7 @@ static struct output_types output_type[] = {
#define penabled(a) if(o->a) fprintf(fp,"" # a " ");
-int
+int
print_enabled_options(QueryOptions_t *o, FILE *fp) {
if(o->verbose) fprintf(fp,"Search Keywords: %s\n",o->keywords);
fprintf(fp,"Results Requested: %d\n", o->nresults);
@@ -99,8 +99,8 @@ main(int argc, char **argv) {
strcpy(q.keywords,"test%ipv6");
- if(!(q.urls | q.snippets | q.ads | q.titles)) {
- q.urls = 1; // Always default to fetching urls
+ if(!(q.urls | q.snippets | q.ads | q.titles)) {
+ q.urls = 1; // Always default to fetching urls
}
if(q.dummy) {
@@ -111,9 +111,9 @@ main(int argc, char **argv) {
} else {
fprintf(stderr,"Error %s",q.err.s);
}
-
+
} else {
-
+
if(engine_bing(&q) == 0) {
printf("Content-type: text/html\r\n"
"\r\n"
@@ -122,11 +122,11 @@ main(int argc, char **argv) {
fprintf(stderr,"%s\n",q.err.s);
}
}
-
+
if(q.debug)
fprintf(stderr,"len = %d\n size = %d, Result = %s\n",q.out.len, q.out.size, q.out.s);
}
gnugol_free_QueryOptions(&q);
- return(0);
+ return(0);
}
View
20 src/common/format.c
@@ -29,26 +29,26 @@ meta_charset_map = {
*/
-int gnugol_init_QueryOptions(QueryOptions_t *q)
+int gnugol_init_QueryOptions(QueryOptions_t *q)
{
assert(q != NULL);
-
+
memset(q,0,sizeof(QueryOptions_t));
q->err.size = 4 * 1024;
q->out.size = 64 * 1024;
q->wrn.size = 4 * 1024;
-
+
q->err.s = malloc(q->err.size);
q->out.s = malloc(q->out.size);
q->wrn.s = malloc(q->wrn.size);
return (q->err.s == NULL) || (q->out.s == NULL) || (q->wrn.s == NULL);
}
-int gnugol_reset_QueryOptions(QueryOptions_t *q)
+int gnugol_reset_QueryOptions(QueryOptions_t *q)
{
assert(q != NULL); /* when will this *ever* be false? */
-
+
buffer_obj_t terr = q->err;
buffer_obj_t twrn = q->wrn;
buffer_obj_t tout = q->out;
@@ -61,15 +61,15 @@ int gnugol_reset_QueryOptions(QueryOptions_t *q)
return(0);
}
-int gnugol_free_QueryOptions(QueryOptions_t *q)
+int gnugol_free_QueryOptions(QueryOptions_t *q)
{
assert(q != NULL);
-
+
free(q->err.s);
free(q->out.s);
free(q->wrn.s);
-#ifndef NDEBUG
+#ifndef NDEBUG
q->err.s = q->out.s = q->wrn.s = NULL;
q->err.size = q->err.len = 0;
q->out.size = q->out.len = 0;
@@ -79,10 +79,10 @@ int gnugol_free_QueryOptions(QueryOptions_t *q)
return(0);
}
-int gnugol_header_out(QueryOptions_t *q)
+int gnugol_header_out(QueryOptions_t *q)
{
assert(q != NULL);
-
+
if(q->header) {
char buffer[SNIPPETSIZE];
strncpy(buffer,q->keywords,SNIPPETSIZE);
View
2 src/common/nodelist.c
@@ -46,7 +46,7 @@ Node *(ListRemHead)(List *const pl)
pn = ListGetHead(pl);
assert(pn != NULL);
- if (NodeValid(pn))
+ if (NodeValid(pn))
NodeRemove(pn);
return(pn);
}
View
10 src/common/parser.c
@@ -9,9 +9,9 @@
// FIXME, this needed to be more free format
// See snippet
-// And we need to init the
+// And we need to init the
-/*
+/*
int parse_section(QueryData *q,char *proto) {
pstart = strstr(s, "LNK\n");
if (pstart == NULL) {
@@ -150,15 +150,15 @@ int answer_parse(QueryData *q) {
int main() {
int nlinks, i;
QueryData q;
-
+
strcpy(q.answer,"LNK\nhttp://www.teklibre.com\nhttp://www.lwn.net\nhttp://www.slashdot.org\nhttp://a.very.busted.url\ngnugol://test+query\nEND\nSNP\nTeklibre is about to become the biggest albatross around David's head\nLwn Rocks\nSlashdot Rules\nThis is a very busted url\nOne day we'll embed search right in the browser\nEND\n");
nlinks = answer_parse(&q);
if (nlinks == -1) {
printf("Error!\n");
exit(1);
}
-
- for(i=0; i<nlinks; i++)
+
+ for(i=0; i<nlinks; i++)
printf("[%d] [%s] [%s]\n", i, q.links[i], q.snippets[i]); // SYNTAX HELL
return 0;
View
4 src/common/utf8_urlencode.c
@@ -138,7 +138,7 @@ else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
}
*/
}
-
+
buf[j] = '\0';
if(to == NULL) {
@@ -193,7 +193,7 @@ else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
}
*/
}
-
+
buf[j] = '\0';
if(to == NULL) {
View
2 src/engines/bing.c
@@ -1,5 +1,5 @@
/*
- This file implements a gnugol -> bing api -> gnugol json translator plugin
+ This file implements a gnugol -> bing api -> gnugol json translator plugin
*/
#include <stdio.h>
View
12 src/engines/dummy.c
@@ -1,4 +1,4 @@
-/* This engine implements dummy layer - useful for debugging the
+/* This engine implements dummy layer - useful for debugging the
formatting engine */
#include <stdio.h>
@@ -17,19 +17,19 @@
// turn quotes back into quotes and other utf-8 stuff
// FIXME: Error outs cause a memory leak from "root"
-// FIXME: do fuller error checking
+// FIXME: do fuller error checking
// Some Fuzzed inputs
// Maybe back off the number of results when we overflow the buffer
-// Arguably this should obey other gnugol options (nresults, position)
+// Arguably this should obey other gnugol options (nresults, position)
// at some point
// More Test cases for bad inputs should go here:
const char description[] = "The dummy engine is used for generating test/malformed data for each of the output formatters.";
int search(QueryOptions_t *q) {
- if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
- if(q->debug) GNUGOL_OUTW(q,"trying keywords: %s", q->keywords);
+ if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
+ if(q->debug) GNUGOL_OUTW(q,"trying keywords: %s", q->keywords);
q->indent = 1;
gnugol_header_out(q);
gnugol_result_out(q,GNUGOL_SITE "bugs.html", "Gnugol Engine Tests", "Some tests of the formatter");
@@ -52,7 +52,7 @@ int search(QueryOptions_t *q) {
q->indent -= 1; gnugol_result_out(q,GNUGOL_SITE "bugs.html", "Bad HTML", "");
q->indent += 1; GNUGOL_OUTW(q,"Tests: Bad HTML\n");
gnugol_result_out(q,GNUGOL_SITE "bugs.html", "Unimplemented", "No tests for bad HTML implemented yet");
-
+
q->indent -= 1; gnugol_result_out(q,GNUGOL_SITE "bugs.html", "Empty String", "");
q->indent += 1; GNUGOL_OUTW(q,"Tests: Empty string\n");
gnugol_result_out(q,"","There was no url in this test", "Empty url");
View
30 src/engines/googlev2.c
@@ -1,4 +1,4 @@
-/* This engine implements a gnugol -> google web api -> gnugol json translator plugin
+/* This engine implements a gnugol -> google web api -> gnugol json translator plugin
using the google web api v2 */
/* DISCLAIMER: I actually read the terms of service on this API, and I wish I didn't.
@@ -7,13 +7,13 @@
It looks impossible to setup gnugol to "do the right thing" using this API.
- IANAL, but I believe that gnugol's usage would be covered under a DMCA exemption,
- for purposes of "interoperability" with org, wiki, and speech synthesis.
+ IANAL, but I believe that gnugol's usage would be covered under a DMCA exemption,
+ for purposes of "interoperability" with org, wiki, and speech synthesis.
- It would be my hope that google would recognise this and grant me an exception
+ It would be my hope that google would recognise this and grant me an exception
to this before I release the code in a finished version.
- Regardless, this API is 1/2 the speed of the other google API - and thus I
+ Regardless, this API is 1/2 the speed of the other google API - and thus I
don't use it at present. I'm just keeping the code around if one day I figure
out how to make it useful.
@@ -34,7 +34,7 @@
#define TEMPLATE "https://www.googleapis.com/customsearch/v1?"
-/* See options at
+/* See options at
http://code.google.com/apis/customsearch/v1/using_rest.html#response
including:
size= large | small (8 vs 4)
@@ -84,20 +84,20 @@ GET https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=0175766625
/* WE WOULD NEED A CUSTOM SEARCH ENGINE HERE cx="bla" for this to work at all */
- if(size > 0) {
- snprintf(string,URL_SIZE-1,"%skey=%s&prettyprint=false&num=%d&start=%d&q=",TEMPLATE,key,q->nresults,q->position);
+ if(size > 0) {
+ snprintf(string,URL_SIZE-1,"%skey=%s&prettyprint=false&num=%d&start=%d&q=",TEMPLATE,key,q->nresults,q->position);
} else {
snprintf(string,URL_SIZE-1,"%sprettyprint=false&num=%d&start=%d&q=",TEMPLATE, q->nresults,q->position);
}
- if(q->debug) GNUGOL_OUTW(q,"Keywords: %s\n", q->keywords);
+ if(q->debug) GNUGOL_OUTW(q,"Keywords: %s\n", q->keywords);
strcat(string,q->keywords); // FIXME: convert to urlencoding
return size;
}
// turn quotes back into quotes and other utf-8 stuff
// FIXME: Error outs cause a memory leak from "root"
// use thread local storage? or malloc for the buffer
-// FIXME: do fuller error checking
+// FIXME: do fuller error checking
// Fuzz inputs!
// Maybe back off the number of results when we overflow the buffer
@@ -111,7 +111,7 @@ GET https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=0175766625
"link": "http://en.wikipedia.org/wiki/Flower",
"displayLink": "en.wikipedia.org",
"snippet": "A flower, sometimes known as a bloom or blossom, is the reproductive structure found in flowering plants (plants of the division Magnoliophyta, ...",
- }
+ }
*/
int search(QueryOptions_t *q) {
@@ -120,11 +120,11 @@ int search(QueryOptions_t *q) {
char url[URL_SIZE];
json_t *root, *items, *handleResponse;
json_error_t error;
- if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
+ if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
text = jsonrequest(q->querystr);
if(!text) {
- GNUGOL_OUTE(q,"url failed to work: %s", q->querystr);
+ GNUGOL_OUTE(q,"url failed to work: %s", q->querystr);
return 1;
}
@@ -136,9 +136,9 @@ int search(QueryOptions_t *q) {
GNUGOL_OUTE(q,"error: on line %d: %s\n", error.line, error.text);
return 1;
}
-
+
GETOBJ(root,handleResponse);
- GETARRAY(handleResponse,items);
+ GETARRAY(handleResponse,items);
gnugol_header_out(q);
for(i = 0; i < json_array_size(items); i++)
View
48 src/engines/stackapps.c
@@ -241,51 +241,49 @@ AND it would be kind of cool to take the comments and have them in the outline
// Answers -> title
// Answers -> body
// In thinking about this, maybe doing a google site search
-// AND then following it up with a search for the ids involved
+// And then following it up with a search for the ids involved
// Would build up a useful faq-like result
int search(QueryOptions_t *q) {
- unsigned int i;
- char *text;
- json_t *root,*questions;
- json_error_t error;
- if(q->debug) GNUGOL_OUTW(q,"%s: trying url: %s\n", q->engine_name, q->querystr);
-
- text = jsonrequest(q->querystr);
- if(!text) {
+ unsigned int i;
+ char *text;
+ json_t *root,*questions;
+ json_error_t error;
+ if(q->debug) GNUGOL_OUTW(q,"%s: trying url: %s\n", q->engine_name, q->querystr);
+ text = jsonrequest(q->querystr);
+ if(!text)
+ {
GNUGOL_OUTE(q,"url failed to work: %s", q->querystr);
return -1;
}
-
root = json_loads(text, &error);
free(text);
-
if(!root)
- {
+ {
GNUGOL_OUTE(q,"error: on line %d: %s\n", error.line, error.text);
return -1;
- }
+ }
GETARRAY(root,questions);
gnugol_header_out(q);
-// Maybe use the score or whether the answer is known for the title?
+// Maybe use the score or whether the answer is known for the title?
// Or the date?
// Or the accepted_answer id, if it exists, rather than referencing
// the question
for(i = 0; i < json_array_size(questions); i++)
- {
- json_t *question, *question_answers_url, *title;
- json_t *score;
- char buffer[1024];
- char buffer2[1024];
- GETARRAYIDX(questions,question,i);
- GETSTRING(question,question_answers_url);
- GETSTRING(question,title);
- GETNUMBER(question,score);
-// GETNUMBER(question,accepted_answer_id);
-// GETSTRING(question,body); // doesn't exist, although documented
+ {
+ json_t *question, *question_answers_url, *title;
+ json_t *score;
+ char buffer[1024];
+ char buffer2[1024];
+ GETARRAYIDX(questions,question,i);
+ GETSTRING(question,question_answers_url);
+ GETSTRING(question,title);
+ GETNUMBER(question,score);
+ // GETNUMBER(question,accepted_answer_id);
+ // GETSTRING(question,body); // doesn't exist, although documented
// if(strlen(accepted_answer_id) > 0) {
// snprintf(buffer,1024,"http://stackoverflow.com%s",jsv(question_answers_url));
// } else {
View
8 src/engines/wikipedia.c
@@ -63,19 +63,19 @@ int setup(QueryOptions_t *q) {
}
// turn quotes back into quotes and other utf-8 stuff
-// FIXME: do fuller error checking
+// FIXME: do fuller error checking
// Fuzz inputs!
// Maybe back off the number of results when we overflow the buffer
int search(QueryOptions_t *q) {
char *text;
json_t *root,*query, *pages, *page, *result;
json_error_t error;
- if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
+ if(q->debug) GNUGOL_OUTW(q,"trying url: %s", q->querystr);
text = jsonrequest(q->querystr);
if(!text) {
- GNUGOL_OUTE(q,"url failed to work: %s", q->querystr);
+ GNUGOL_OUTE(q,"url failed to work: %s", q->querystr);
return 1;
}
@@ -87,7 +87,7 @@ int search(QueryOptions_t *q) {
GNUGOL_OUTE(q,"error: on line %d: %s\n", error.line, error.text);
return 1;
}
-
+
GETOBJ(root,query);
GETOBJ(query,pages);
GETSTRING(page,query); // the next object is GETSTR?
View
2 src/include/common.h
@@ -3,6 +3,6 @@
#ifdef DEBUG
#define log(a,b) printf(a,b)
#else
-#define log(a,b)
+#define log(a,b)
#endif
#endif
View
2 src/include/formats.h
@@ -9,7 +9,7 @@
#ifndef PATH_MAX
#define PATH_MAX (1024)
#endif
-#define SNIPPETSIZE (2048)
+#define SNIPPETSIZE (2048)
#define OUTPUTSIZE (64*1024)
#define STRIPHTML(a) strip_html(SNIPPETSIZE,a)
View
2 src/include/handy.h
@@ -6,7 +6,7 @@ extern int strip_html(int len, char *htmlstr);
#define jsv(a) json_string_value(a)
#define jsn(a) json_number_value(a)
-// Mapping one language to another requires
+// Mapping one language to another requires
// lots of repetitive code and error checking
// Macros may be ugly, but they do (in this case)
// ensure that all errors are captured.
View
2 src/include/nodelist.h
@@ -58,7 +58,7 @@ static inline void ListAddHead(List *const pl,Node *const pn)
{
assert(pl != NULL);
assert(pn != NULL);
-
+
NodeInsert((Node *)&pl->lh_Head,pn);
}

0 comments on commit 79964a2

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