Skip to content

Commit

Permalink
shorten the Gopher search prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed May 2, 2023
1 parent 849db38 commit 7251bc2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions gopher.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ static void parse_gophermap_line(char *line, int *pre, Selector **sel, SelectorL
/*============================================================================*/
static char *gopher_request(const Selector *sel, URL *url, int ask, int *len) {
static char buffer[1024 + 3]; /* path\r\n\0 */
char *query = NULL, *criteria = NULL;
char *query = NULL, *input = NULL;

if (sel->prompt || strncmp(url->path, "/7/", 3) == 0) {
switch (curl_url_get(url->cu, CURLUPART_QUERY, &query, 0)) {
case CURLUE_OK: criteria = query; break;
case CURLUE_OK: input = query; break;
case CURLUE_NO_QUERY: break;
default: return NULL;
}
if (criteria == NULL || *criteria == '\0') {
if (!ask || (criteria = bestline(color ? "\33[35mSearch criteria>\33[0m " : "Search criteria> ")) == NULL || !set_input(url, criteria)) { curl_free(query); return NULL; }
if (interactive) { bestlineHistoryAdd(criteria); bestlineHistoryAdd(url->url); }
if (input == NULL || *input == '\0') {
if (!ask || (input = bestline(color ? "\33[35mQuery>\33[0m " : "Query> ")) == NULL || !set_input(url, input)) { curl_free(query); return NULL; }
if (interactive) { bestlineHistoryAdd(input); bestlineHistoryAdd(url->url); }
}
}
if (criteria && *criteria != '\0') *len = snprintf(buffer, sizeof(buffer), "%s\t%s\r\n", strncmp(url->path, "/7/", 3) == 0 ? url->path + 2 : url->path, criteria);
if (input && *input != '\0') *len = snprintf(buffer, sizeof(buffer), "%s\t%s\r\n", strncmp(url->path, "/7/", 3) == 0 ? url->path + 2 : url->path, input);
else *len = snprintf(buffer, sizeof(buffer), "%s\r\n", (url->path[1] != '/' && url->path[1] != '\0' && url->path[2] == '/') ? url->path + 2 : url->path);

if (criteria != query) free(criteria);
if (input != query) free(input);
curl_free(query);
return buffer;
}
Expand Down

0 comments on commit 7251bc2

Please sign in to comment.