* anchor.c (link_list_panel): support DecodeURL * display.c (make_lastline_link): support DecodeURL * etc.c (url_unquote_conv): added * fm.h (DecodeURL): added * history.c (historyBuffer): support DecodeURL * indep.c (QUOTE_MAP): added (HTML_QUOTE_MAP): added (html_quote_char): deleted (url_quote): use is_url_quote (file_quote): use is_file_quote (is_url_safe): deleted (Str_form_quote): use is_url_unsafe (Str_url_unquote): add safe args (is_shell_safe): delete (shell_quote): use is_shell_unsafe * indep.h (QUOTE_MAP): added (HTML_QUOTE_MAP): added (HTML_QUOTE_MASK): added (SHELL_UNSAFE_MASK): added (URL_QUOTE_MASK): added (FILE_QUOTE_MASK): added (URL_UNSAFE_MASK): added (GET_QUOTE_TYPE): added (is_html_quote): added (is_shell_unsafe): added (is_url_quote): added (is_file_quote): added (is_url_unsafe): added (html_quote_char): added (html_quote_char): deleted (Str_url_unquote): added safe (form_unquote): Str_url_unquote changes * linein.c (_prev): support DecodeURL (_next): ditto * main.c (goURL0): support DecodeURL (_peekURL): ditto (curURL): ditto * map.c (follow_map_panel): support DecodeURL (append_map_info): ditto (append_link_info): ditto (append_frame_info): ditto (page_info_panel): ditto * menu.c (initSelectMenu): delete SCM_LOCAL_CGI support DecodeURL (initSelTabMenu): delete SCM_LOCAL_CGI support DecodeURL (link_menu): support DecodeURL * parsetagx.c (parse_tag): is_html_quote * proto.h (url_unquote_conv): added * rc.c (CMT_DECODE_URL): added (params1): add decode_url * url.c (openURL): Str_url_unquote non safe From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
		
			
				
	
	
		
			218 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			218 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* $Id: history.c,v 1.9 2003/02/05 16:43:57 ukai Exp $ */
 | 
						|
#include "fm.h"
 | 
						|
 | 
						|
#ifdef USE_HISTORY
 | 
						|
Buffer *
 | 
						|
historyBuffer(Hist *hist)
 | 
						|
{
 | 
						|
    Str src = Strnew();
 | 
						|
    HistItem *item;
 | 
						|
    char *p, *q;
 | 
						|
 | 
						|
    Strcat_charp(src, "<html>\n<head><title>History Page</title></head>\n");
 | 
						|
    Strcat_charp(src, "<body>\n<h1>History Page</h1>\n<hr>\n");
 | 
						|
    Strcat_charp(src, "<ol>\n");
 | 
						|
    if (hist && hist->list) {
 | 
						|
	for (item = hist->list->last; item; item = item->prev) {
 | 
						|
	    q = html_quote((char *)item->ptr);
 | 
						|
	    if (DecodeURL)
 | 
						|
		p = html_quote(url_unquote_conv((char *)item->ptr, 0));
 | 
						|
	    else
 | 
						|
		p = q;
 | 
						|
	    Strcat_charp(src, "<li><a href=\"");
 | 
						|
	    Strcat_charp(src, q);
 | 
						|
	    Strcat_charp(src, "\">");
 | 
						|
	    Strcat_charp(src, p);
 | 
						|
	    Strcat_charp(src, "</a>\n");
 | 
						|
	}
 | 
						|
    }
 | 
						|
    Strcat_charp(src, "</ol>\n</body>\n</html>");
 | 
						|
    return loadHTMLString(src);
 | 
						|
}
 | 
						|
 | 
						|
void
 | 
						|
loadHistory(Hist *hist)
 | 
						|
{
 | 
						|
    FILE *f;
 | 
						|
    Str line;
 | 
						|
 | 
						|
    if (hist == NULL)
 | 
						|
	return;
 | 
						|
    if ((f = fopen(rcFile(HISTORY_FILE), "rt")) == NULL)
 | 
						|
	return;
 | 
						|
 | 
						|
    while (!feof(f)) {
 | 
						|
	line = Strfgets(f);
 | 
						|
	Strchop(line);
 | 
						|
	Strremovefirstspaces(line);
 | 
						|
	Strremovetrailingspaces(line);
 | 
						|
	if (line->length == 0)
 | 
						|
	    continue;
 | 
						|
	pushHist(hist, url_quote(line->ptr));
 | 
						|
    }
 | 
						|
    fclose(f);
 | 
						|
}
 | 
						|
 | 
						|
void
 | 
						|
saveHistory(Hist *hist, size_t size)
 | 
						|
{
 | 
						|
    FILE *f;
 | 
						|
    HistItem *item;
 | 
						|
    char *tmpf;
 | 
						|
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return;
 | 
						|
    tmpf = tmpfname(TMPF_DFL, NULL)->ptr;
 | 
						|
    if ((f = fopen(tmpf, "w")) == NULL) {
 | 
						|
	disp_err_message("Can't open history", FALSE);
 | 
						|
	return;
 | 
						|
    }
 | 
						|
    for (item = hist->list->first; item && hist->list->nitem > size;
 | 
						|
	 item = item->next)
 | 
						|
	size++;
 | 
						|
    for (; item; item = item->next)
 | 
						|
	fprintf(f, "%s\n", (char *)item->ptr);
 | 
						|
    fclose(f);
 | 
						|
    rename(tmpf, rcFile(HISTORY_FILE));
 | 
						|
}
 | 
						|
#endif				/* USE_HISTORY */
 | 
						|
 | 
						|
Hist *
 | 
						|
newHist()
 | 
						|
{
 | 
						|
    Hist *hist;
 | 
						|
 | 
						|
    hist = New(Hist);
 | 
						|
    hist->list = (HistList *)newGeneralList();
 | 
						|
    hist->current = NULL;
 | 
						|
    hist->hash = NULL;
 | 
						|
    return hist;
 | 
						|
}
 | 
						|
 | 
						|
Hist *
 | 
						|
copyHist(Hist *hist)
 | 
						|
{
 | 
						|
    Hist *new;
 | 
						|
    HistItem *item;
 | 
						|
 | 
						|
    if (hist == NULL)
 | 
						|
	return NULL;
 | 
						|
    new = newHist();
 | 
						|
    for (item = hist->list->first; item; item = item->next)
 | 
						|
	pushHist(new, (char *)item->ptr);
 | 
						|
    return new;
 | 
						|
}
 | 
						|
 | 
						|
HistItem *
 | 
						|
unshiftHist(Hist *hist, char *ptr)
 | 
						|
{
 | 
						|
    HistItem *item;
 | 
						|
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
 | 
						|
				   (ListItem *)hist->list->first, NULL);
 | 
						|
    if (hist->list->first)
 | 
						|
	hist->list->first->prev = item;
 | 
						|
    else
 | 
						|
	hist->list->last = item;
 | 
						|
    hist->list->first = item;
 | 
						|
    hist->list->nitem++;
 | 
						|
    return item;
 | 
						|
}
 | 
						|
 | 
						|
HistItem *
 | 
						|
pushHist(Hist *hist, char *ptr)
 | 
						|
{
 | 
						|
    HistItem *item;
 | 
						|
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
 | 
						|
				   NULL, (ListItem *)hist->list->last);
 | 
						|
    if (hist->list->last)
 | 
						|
	hist->list->last->next = item;
 | 
						|
    else
 | 
						|
	hist->list->first = item;
 | 
						|
    hist->list->last = item;
 | 
						|
    hist->list->nitem++;
 | 
						|
    return item;
 | 
						|
}
 | 
						|
 | 
						|
/* Don't mix pushHashHist() and pushHist()/unshiftHist(). */
 | 
						|
 | 
						|
HistItem *
 | 
						|
pushHashHist(Hist *hist, char *ptr)
 | 
						|
{
 | 
						|
    HistItem *item;
 | 
						|
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    item = getHashHist(hist, ptr);
 | 
						|
    if (item) {
 | 
						|
	if (item->next)
 | 
						|
	    item->next->prev = item->prev;
 | 
						|
	else			/* item == hist->list->last */
 | 
						|
	    hist->list->last = item->prev;
 | 
						|
	if (item->prev)
 | 
						|
	    item->prev->next = item->next;
 | 
						|
	else			/* item == hist->list->first */
 | 
						|
	    hist->list->first = item->next;
 | 
						|
	hist->list->nitem--;
 | 
						|
    }
 | 
						|
    item = pushHist(hist, ptr);
 | 
						|
    putHash_sv(hist->hash, ptr, (void *)item);
 | 
						|
    return item;
 | 
						|
}
 | 
						|
 | 
						|
HistItem *
 | 
						|
getHashHist(Hist *hist, char *ptr)
 | 
						|
{
 | 
						|
    HistItem *item;
 | 
						|
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    if (hist->hash == NULL) {
 | 
						|
	hist->hash = newHash_sv(HIST_HASH_SIZE);
 | 
						|
	for (item = hist->list->first; item; item = item->next)
 | 
						|
	    putHash_sv(hist->hash, (char *)item->ptr, (void *)item);
 | 
						|
    }
 | 
						|
    return (HistItem *)getHash_sv(hist->hash, ptr, NULL);
 | 
						|
}
 | 
						|
 | 
						|
char *
 | 
						|
lastHist(Hist *hist)
 | 
						|
{
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    if (hist->list->last) {
 | 
						|
	hist->current = hist->list->last;
 | 
						|
	return (char *)hist->current->ptr;
 | 
						|
    }
 | 
						|
    return NULL;
 | 
						|
}
 | 
						|
 | 
						|
char *
 | 
						|
nextHist(Hist *hist)
 | 
						|
{
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    if (hist->current && hist->current->next) {
 | 
						|
	hist->current = hist->current->next;
 | 
						|
	return (char *)hist->current->ptr;
 | 
						|
    }
 | 
						|
    return NULL;
 | 
						|
}
 | 
						|
 | 
						|
char *
 | 
						|
prevHist(Hist *hist)
 | 
						|
{
 | 
						|
    if (hist == NULL || hist->list == NULL)
 | 
						|
	return NULL;
 | 
						|
    if (hist->current && hist->current->prev) {
 | 
						|
	hist->current = hist->current->prev;
 | 
						|
	return (char *)hist->current->ptr;
 | 
						|
    }
 | 
						|
    return NULL;
 | 
						|
}
 |