Skip to content

Commit

Permalink
Went on an anti-whitespace crusade
Browse files Browse the repository at this point in the history
Trailing whitespace is now dead. Very dead.

Let's hope it does not return.
  • Loading branch information
Dave Täht committed Jan 10, 2011
1 parent 693cb8f commit 79964a2
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 105 deletions.
4 changes: 2 additions & 2 deletions doc/index.org
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 21 additions & 21 deletions src/clients/gnugol_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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 "
Expand All @@ -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");
Expand Down
18 changes: 9 additions & 9 deletions src/clients/gnugol_fcgi.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
Expand All @@ -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);
}

20 changes: 10 additions & 10 deletions src/common/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/common/nodelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/common/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/common/utf8_urlencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
}
*/
}

buf[j] = '\0';

if(to == NULL) {
Expand Down Expand Up @@ -193,7 +193,7 @@ else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
}
*/
}

buf[j] = '\0';

if(to == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/engines/bing.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
12 changes: 6 additions & 6 deletions src/engines/dummy.c
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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");
Expand All @@ -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");
Expand Down
Loading

0 comments on commit 79964a2

Please sign in to comment.