Example #1
0
/*
 * set power on handle
 */
static int hx280_set_power_on_handle(char *argp)
{
	int i;
	int ret = -1;

#define SKIP_BLANKS(p) { while (*(p) == ' ') (p)++; }

	SKIP_BLANKS(argp);

	for (i = 0; hx280_power_on_handles[i].name != NULL; i++) {
		if (!strncmp(argp, hx280_power_on_handles[i].name,
				strlen(hx280_power_on_handles[i].name))) {

			xgold_vpu_enc_pm_state_on_p
				= hx280_power_on_handles[i].p_handle;

			pr_info("hx280dbg set power on handle to %s\n",
				hx280_power_on_handles[i].name);
			pr_info("hx280dbg note: %s\n",
				hx280_power_on_handles[i].note);

			ret = i;
			break;
		}
	}

	if (ret < 0)
		pr_info("hx280dbg did not find power on handle for \"%s\"\n",
			argp);

	return ret;
}
Example #2
0
static char *
name_from_address(char *str, int n)
{
    char *s, *p;
    int l;
		bool space = true;

    s = allocStr(str, -1);
    SKIP_BLANKS(s);
    if (*s == '<' && (p = strchr(s, '>'))) {
	*p++ = '\0';
	SKIP_BLANKS(p);
	if (*p == '\0')		/* <address> */
	    s++;
	else			/* <address> name ? */
	    s = p;
    }
    else if ((p = strchr(s, '<')))	/* name <address> */
	*p = '\0';
    else if ((p = strchr(s, '(')))	/* address (name) */
	s = p;
    if (*s == '"' && (p = strchr(s + 1, '"'))) {	/* "name" */
	*p = '\0';
	s++;
    }
    else if (*s == '(' && (p = strchr(s + 1, ')'))) {	/* (name) */
	*p = '\0';
	s++;
    }
    for (p = s, l = 0; *p; p += get_mclen(p)) {
	if (IS_SPACE(*p)) {
	    if (space)
		continue;
	    space = true;
	}
	else
	    space = false;
	l += get_mcwidth(p);
	if (l > n)
	    break;
    }
    *p = '\0';
    return s;
}
Example #3
0
static bool
matchMailcapAttr(char *p, char *attr, size_t len, Str *value)
{
    bool quoted = false;
    char *q = NULL;

    if (strncasecmp(p, attr, len) == 0) {
	p += len;
	SKIP_BLANKS(p);
	if (value) {
	    *value = Strnew();
	    if (*p == '=') {
		p++;
		SKIP_BLANKS(p);
		while (*p && (quoted || *p != ';')) {
		    if (quoted || !IS_SPACE(*p))
			q = p;
		    if (quoted)
			quoted = false;
		    else if (*p == '\\')
			quoted = true;
		    Strcat_char(*value, *p);
		    p++;
		}
		if (q)
		    Strshrink(*value, p - q - 1);
	    }
	    return true;
	}
	else {
	    if (*p == '\0' || *p == ';') {
		return true;
	    }
	}
    }
    return false;
}
Example #4
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void SJ_ReloadConfiguration( )
{
	swprintf_s( g_txt, L"%s/%s", g_skin, CONFIG_FILE );
	FILE* f = _wfopen( g_txt, L"rt" );
	if ( !f ) return;
	wchar_t* ptr;
	int skip = 0;
	float* tgtKey;
	while ( !feof(f) )
	{
		fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f );
		ptr = g_txt;
		SKIP_BLANKS(ptr);						// skip line starting blanks
		if ( *ptr == COMMENT_TOKEN ) continue;	// comments
		TRIM(ptr);								// right trim
		tgtKey = NULL;
		if		( _wcsnicmp( ptr, L"topBounce", 9 ) == 0 )		{ tgtKey=&g_topBounce; skip=9; }
		else if ( _wcsnicmp( ptr, L"lateralBounce", 13 ) == 0 )	{ tgtKey=&g_lateralBounce; skip=13; }
		else if ( _wcsnicmp( ptr, L"bottomBounce", 12 ) == 0 )	{ tgtKey=&g_bottomBounce; skip=12; }
		else if ( _wcsnicmp( ptr, L"boostForce", 10 ) == 0 )	{ tgtKey=&g_boostForce; skip=10; }
		else if ( _wcsnicmp( ptr, L"lateralForce", 12 ) == 0 )	{ tgtKey=&g_lateralForce; skip=12; }
		else if ( _wcsnicmp( ptr, L"lateralFriction", 15 ) == 0){ tgtKey=&g_lateralFriction; skip=15; }
		else if ( _wcsnicmp( ptr, L"gravityFactor", 13 ) == 0 )	{ tgtKey=&g_gravTimeFactor; skip=13; }
		else if ( _wcsnicmp( ptr, L"gravity", 7 ) == 0 )		{ tgtKey=&g_gravity; skip=7; }
		else if ( _wcsnicmp( ptr, L"lives", 5 ) == 0 )			{ ptr+=5; SKIP_BLANKS(ptr); g_livesMax = (char)::_wtol(ptr); }
	//	else if ( _wcsnicmp( ptr, L"players", 7 ) == 0 )		{ ptr+=7; SKIP_BLANKS(ptr); g_nPlayers = (char)::_wtol(ptr); }
		else if ( _wcsnicmp( ptr, L"fontName", 8) == 0 )		{ ptr+=8; SKIP_BLANKS(ptr); wcscpy_s( g_fontName, ptr ); }
		else if ( _wcsnicmp( ptr, L"fontSize", 8) == 0 )		{ ptr+=8; SKIP_BLANKS(ptr); g_fontSize = (char)::_wtol(ptr); }
		if ( tgtKey )
		{
			ptr+=skip; // jump to value
			SKIP_BLANKS(ptr);
			*tgtKey = (float)::_wtof(ptr);
		}
	}
}
Example #5
0
/* Assuming p points to some character beyond an opening parenthesis, copy
   everything to outfile up to but not including the closing parenthesis.
*/
char *copy_up_to_paren(register char *p)
{
	for (;;) {
		SKIP_BLANKS(p);	/* We don't call skip_blanks() in order to */
		CHECK_EOL(p);	/* preserve blanks at the beginning of the line */
		if (*p == ')')
			break;

		if (*p == '\"')
			p = copy_quoted_string(p);
		else
			fputc(*p++, outfile);
	}
	return p;
}
Example #6
0
struct parsed_tag *
parse_tag(char **s, int internal)
{
    struct parsed_tag *tag = NULL;
    int tag_id;
    char tagname[MAX_TAG_LEN], attrname[MAX_TAG_LEN];
    char *p, *q;
    int i, attr_id = 0, nattr;

    /* Parse tag name */
    q = (*s) + 1;
    p = tagname;
    if (*q == '/') {
	*(p++) = *(q++);
	SKIP_BLANKS(q);
    }
    while (*q && !IS_SPACE(*q) && !(tagname[0] != '/' && *q == '/') &&
	   *q != '>' && p - tagname < MAX_TAG_LEN - 1) {
	*(p++) = TOLOWER(*q);
	q++;
    }
    *p = '\0';
    while (*q && !IS_SPACE(*q) && !(tagname[0] != '/' && *q == '/') &&
	   *q != '>')
	q++;

    tag_id = getHash_si(&tagtable, tagname, HTML_UNKNOWN);

    if (tag_id == HTML_UNKNOWN ||
	(!internal && TagMAP[tag_id].flag & TFLG_INT))
	goto skip_parse_tagarg;

    tag = New(struct parsed_tag);
    bzero(tag, sizeof(struct parsed_tag));
    tag->tagid = tag_id;

    if ((nattr = TagMAP[tag_id].max_attribute) > 0) {
	tag->attrid = NewAtom_N(unsigned char, nattr);
	tag->value = New_N(char *, nattr);
	tag->map = NewAtom_N(unsigned char, MAX_TAGATTR);
	memset(tag->map, MAX_TAGATTR, MAX_TAGATTR);
	memset(tag->attrid, ATTR_UNKNOWN, nattr);
	for (i = 0; i < nattr; i++)
	    tag->map[TagMAP[tag_id].accept_attribute[i]] = i;
    }
Example #7
0
File: frame.c Project: richq/w3m
static int
parseFrameSetLength(char *s, char ***ret)
{
    int i, len;
    char *p, *q, **lv;

    i = 1;

    if (s)
	for (p = s; (p = strchr(p, ',')); ++p)
	    ++i;
    else
	s = "*";

    lv = New_N(char *, i);

    for (i = 0, p = s;; ++p) {
	SKIP_BLANKS(p);
	len = strtol(p, &q, 10);

	switch (*q) {
	case '%':
	    lv[i++] = Sprintf("%d%%", len)->ptr;
	    break;
	case '*':
	    lv[i++] = "*";
	    break;
	default:
	    lv[i++] = Sprintf("%d", len)->ptr;
	    break;
	}

	if (!(p = strchr(q, ',')))
	    break;
    }

    *ret = lv;
    return i;
}
Example #8
0
int
gethtmlcmd(char **s)
{
    extern Hash_si tagtable;
    char cmdstr[MAX_CMD_LEN];
    char *p = cmdstr;
    char *save = *s;
    int cmd;

    (*s)++;
    /* first character */
    if (IS_ALNUM(**s) || **s == '_' || **s == '/') {
	*(p++) = TOLOWER(**s);
	(*s)++;
    }
    else
	return HTML_UNKNOWN;
    if (p[-1] == '/')
	SKIP_BLANKS(*s);
    while ((IS_ALNUM(**s) || **s == '_') && p - cmdstr < MAX_CMD_LEN) {
	*(p++) = TOLOWER(**s);
	(*s)++;
    }
    if (p - cmdstr == MAX_CMD_LEN) {
	/* buffer overflow: perhaps caused by bad HTML source */
	*s = save + 1;
	return HTML_UNKNOWN;
    }
    *p = '\0';

    /* hash search */
    cmd = getHash_si(&tagtable, cmdstr, HTML_UNKNOWN);
    while (**s && **s != '>')
	(*s)++;
    if (**s == '>')
	(*s)++;
    return cmd;
}
Example #9
0
/**
 * strtrim: make string from original string with deleting blanks.
 *
 *	@param[in]	p	original string.
 *	@param[in]	flag	TRIM_HEAD:	from only head,
 *			TRIM_TAIL:	from only tail,
 *			TRIM_BOTH:	from head and tail,
 *			TRIM_ALL:	from all
 *	@param[out]	len	length of result string,
 *			if len == NULL then nothing returned.
 *	@return		result string
 *
 * Usage:
 *	strtrim(" # define ", TRIM_HEAD, NULL)	=> "# define "
 *	strtrim(" # define ", TRIM_TAIL, NULL)	=> " # define"
 *	strtrim(" # define ", TRIM_BOTH, NULL)	=> "# define"
 *	strtrim(" # define ", TRIM_ALL, NULL)	=> "#define"
 *
 * [Note] The result string area is function local. So, following call
 *	 to this function may destroy the area.
 */
const char *
strtrim(const char *p, int flag, int *len)
{
	STATIC_STRBUF(sb);
	int cut_off = -1;

	strbuf_clear(sb);
	/*
	 * Delete blanks of the head.
	 */
	if (flag != TRIM_TAIL)
		SKIP_BLANKS(p);
	/*
	 * Copy string.
	 */
	for (; *p; p++) {
		if (isspace(*p)) {
			if (flag != TRIM_ALL) {
				if (cut_off == -1 && flag != TRIM_HEAD)
					cut_off = strbuf_getlen(sb);
				strbuf_putc(sb,*p);
			}
		} else {
			strbuf_putc(sb,*p);
			cut_off = -1;
		}
	}
	/*
	 * Delete blanks of the tail.
	 */
	if (cut_off != -1)
		strbuf_setlen(sb, cut_off);
	if (len)
		*len = strbuf_getlen(sb);
	return strbuf_value(sb);
}
Example #10
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool SJ_NextLevel( const wchar_t* filename /*= LEVEL_NEXT*/ )
{
	// reset player variables
	for ( char i = 0; i < g_nPlayers; ++i )
		SJ_ResetPlayer( g_player[i] );

	// reset level variables
	g_remainBlocks=0;
	g_levelName[0] = 0;
	memset( g_sprites, 0, sizeof(sSprite)*MAX_SPRITES );
	
	if ( wcscmp( filename, LEVEL_NEXT ) == 0 ) // get next from folder
	{
		swprintf_s( g_txt, L"%s/levels/%s/Level_%03d.txt", g_skin, g_difficulty, g_nextLevel );
	}else // a real filename provided
	{
		wcscpy_s( g_txt, filename );
	}
	// performs open
	FILE* f = _wfopen( g_txt, L"rt" );
	if ( !f ) 
	{
		g_nextLevel = 0;
		return false;
	}
	// read from file
	int bcount = g_nPlayers;
	int line = 0;
	while ( ! feof(f) && line < TILES_HEIGHT && bcount < MAX_SPRITES )
	{
		fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f );
		for ( int c = 0; c < TILES_WIDTH && g_txt[c] != L'\0'; ++c )
		{
			int spr = -1; char texId = IDT_JUMPING;
			switch ( g_txt[c] )
			{
				case TILE_BLOCK: spr = bcount; texId = IDT_BLOCK; ++bcount; break;
				case TILE_SPAWN0: 
				case TILE_SPAWN1: 
				case TILE_SPAWN2: 
				case TILE_SPAWN3:
				{
					const char ispawn = char(g_txt[c] - TILE_SPAWN0);
					spr = ispawn < g_nPlayers ? ispawn : -1; 
				}break;
			}
			if ( spr != -1 )
			{
				g_sprites[spr].x = (c*g_blDim[0]); 
				g_sprites[spr].y = (line*g_blDim[1]); 
				g_sprites[spr].active = 1;
				g_sprites[spr].texId = texId;
				g_sprites[spr].alpha = 1.0f;
			}
		}
		++line;
	}
	// level params		
	wchar_t* ptr = NULL;
	while ( ! feof(f) )
	{
		fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f );
		ptr = g_txt;
		SKIP_BLANKS(ptr);
		if ( *ptr == COMMENT_TOKEN ) continue; // comments
		TRIM(ptr);
		if		( _wcsnicmp( ptr, L"levelName", 9 ) == 0 ) 
		{ 
			ptr+=9; 
			SKIP_BLANKS(ptr); 
			wcsncpy_s( g_levelName, ptr, 64 ); 
			g_levelName[63]=0; 
		}else if ( _wcsnicmp( ptr, L"boosts", 6 ) == 0 )    
		{ 
			ptr+=6; 
			SKIP_BLANKS(ptr); 
			const char b = (char)::_wtol(ptr);
			for ( char i = 0; i < g_nPlayers; ++i )
				g_player[i].levelBoosts = b;
		}else if ( _wcsnicmp( ptr, L"time", 4 ) == 0 )
		{
			ptr+=4;
			SKIP_BLANKS(ptr);
			g_levelTime = ::_wtof(ptr);
		}
	}
	fclose(f);

	// counting remaining blocks
	for ( int i = 0; i < MAX_SPRITES; ++i )
	{
		if ( i < g_nPlayers || g_sprites[i].active == 0 ) continue;
		++g_remainBlocks;
	}
	// correcting init for players
	for ( char i = 0; i < g_nPlayers; ++i )
	{
		sSprite& plSpr = g_sprites[ g_player[i].sprId ];
		// center in tile
		plSpr.x += g_blDim[0]/2.0f-g_plDim[0]/2.0f;
		plSpr.y += g_blDim[1]/2.0f-g_plDim[1]/2.0f;	
	}
	return true;
}
Example #11
0
File: frame.c Project: richq/w3m
static int
createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
		int force_reload)
{
    int r, c, t_stack;
    URLFile f2;
#ifdef USE_M17N
    wc_ces charset, doc_charset;
#endif
    char *d_target, *p_target, *s_target, *t_target;
    ParsedURL *currentURL, base;
    MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
    int flag;

    if (f == NULL)
	return -1;

    if (level == 0) {
	if (SETJMP(AbortLoading) != 0) {
	    TRAP_OFF;
	    return -1;
	}
	TRAP_ON;
	f->name = "_top";
    }

    if (level > 7) {
	fputs("Too many frameset tasked.\n", f1);
	return -1;
    }

    if (level == 0) {
	fprintf(f1, "<html><head><title>%s</title></head><body>\n",
		html_quote(current->buffername));
	fputs("<table hborder width=\"100%\">\n", f1);
    }
    else
	fputs("<table hborder>\n", f1);

    currentURL = f->currentURL ? f->currentURL : &current->currentURL;
    for (r = 0; r < f->row; r++) {
	fputs("<tr valign=top>\n", f1);
	for (c = 0; c < f->col; c++) {
	    union frameset_element frame;
	    struct frameset *f_frameset;
	    int i = c + r * f->col;
	    char *p = "";
	    int status = R_ST_NORMAL;
	    Str tok = Strnew();
	    int pre_mode = 0;
	    int end_tag = 0;

	    frame = f->frame[i];

	    if (frame.element == NULL) {
		fputs("<td>\n</td>\n", f1);
		continue;
	    }

	    fputs("<td", f1);
	    if (frame.element->name)
		fprintf(f1, " id=\"_%s\"", html_quote(frame.element->name));
	    if (!r)
		fprintf(f1, " width=\"%s\"", f->width[c]);
	    fputs(">\n", f1);

	    flag = 0;
	    if (force_reload) {
		flag |= RG_NOCACHE;
		if (frame.element->attr == F_BODY)
		    unloadFrame(frame.body);
	    }
	    switch (frame.element->attr) {
	    default:
		/* FIXME: gettextize? */
		fprintf(f1, "Frameset \"%s\" frame %d: type unrecognized",
			html_quote(f->name), i + 1);
		break;
	    case F_UNLOADED:
		if (!frame.body->name && f->name) {
		    frame.body->name = Sprintf("%s_%d", f->name, i)->ptr;
		}
		fflush(f1);
		f_frameset = frame_download_source(frame.body,
						   currentURL,
						   current->baseURL, flag);
		if (f_frameset) {
		    deleteFrame(frame.body);
		    f->frame[i].set = frame.set = f_frameset;
		    goto render_frameset;
		}
		/* fall through */
	    case F_BODY:
		init_stream(&f2, SCM_LOCAL, NULL);
		if (frame.body->source) {
		    fflush(f1);
		    examineFile(frame.body->source, &f2);
		}
		if (f2.stream == NULL) {
		    frame.body->attr = F_UNLOADED;
		    if (frame.body->flags & FB_NO_BUFFER)
			/* FIXME: gettextize? */
			fprintf(f1, "Open %s with other method",
				html_quote(frame.body->url));
		    else if (frame.body->url)
			/* FIXME: gettextize? */
			fprintf(f1, "Can't open %s",
				html_quote(frame.body->url));
		    else
			/* FIXME: gettextize? */
			fprintf(f1,
				"This frame (%s) contains no src attribute",
				frame.body->name ? html_quote(frame.body->name)
				: "(no name)");
		    break;
		}
		parseURL2(frame.body->url, &base, currentURL);
		p_target = f->name;
		s_target = frame.body->name;
		t_target = "_blank";
		d_target = TargetSelf ? s_target : t_target;
#ifdef USE_M17N
		charset = WC_CES_US_ASCII;
		if (current->document_charset != WC_CES_US_ASCII)
		    doc_charset = current->document_charset;
		else
		    doc_charset = DocumentCharset;
#endif
		t_stack = 0;
		if (frame.body->type &&
		    !strcasecmp(frame.body->type, "text/plain")) {
		    Str tmp;
		    fprintf(f1, "<pre>\n");
		    while ((tmp = StrmyUFgets(&f2))->length) {
			tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
					  doc_charset);
			fprintf(f1, "%s", html_quote(tmp->ptr));
		    }
		    fprintf(f1, "</pre>\n");
		    UFclose(&f2);
		    break;
		}
		do {
		    int is_tag = FALSE;
		    char *q;
		    struct parsed_tag *tag;

		    do {
			if (*p == '\0') {
			    Str tmp = StrmyUFgets(&f2);
			    if (tmp->length == 0)
				break;
			    tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
					      doc_charset);
			    p = tmp->ptr;
			}
			read_token(tok, &p, &status, 1, status != R_ST_NORMAL);
		    } while (status != R_ST_NORMAL);

		    if (tok->length == 0)
			continue;

		    if (tok->ptr[0] == '<') {
			if (tok->ptr[1] &&
			    REALLY_THE_BEGINNING_OF_A_TAG(tok->ptr))
			    is_tag = TRUE;
			else if (!(pre_mode & (RB_PLAIN | RB_INTXTA |
					       RB_SCRIPT | RB_STYLE))) {
			    p = Strnew_m_charp(tok->ptr + 1, p, NULL)->ptr;
			    tok = Strnew_charp("&lt;");
			}
		    }
		    if (is_tag) {
			if (pre_mode & (RB_PLAIN | RB_INTXTA | RB_SCRIPT |
					RB_STYLE)) {
			    q = tok->ptr;
			    if ((tag = parse_tag(&q, FALSE)) &&
				tag->tagid == end_tag) {
				if (pre_mode & RB_PLAIN) {
				    fputs("</PRE_PLAIN>", f1);
				    pre_mode = 0;
				    end_tag = 0;
				    goto token_end;
				}
				pre_mode = 0;
				end_tag = 0;
				goto proc_normal;
			    }
			    if (strncmp(tok->ptr, "<!--", 4) &&
				(q = strchr(tok->ptr + 1, '<'))) {
				tok = Strnew_charp_n(tok->ptr, q - tok->ptr);
				p = Strnew_m_charp(q, p, NULL)->ptr;
				status = R_ST_NORMAL;
			    }
			    is_tag = FALSE;
			}
			else if (pre_mode & RB_INSELECT) {
			    q = tok->ptr;
			    if ((tag = parse_tag(&q, FALSE))) {
				if ((tag->tagid == end_tag) ||
				    (tag->tagid == HTML_N_FORM)) {
				    if (tag->tagid == HTML_N_FORM)
					fputs("</SELECT>", f1);
				    pre_mode = 0;
				    end_tag = 0;
				    goto proc_normal;
				}
				if (t_stack) {
				    switch (tag->tagid) {
				    case HTML_TABLE:
				    case HTML_N_TABLE:
				      CASE_TABLE_TAG:
					fputs("</SELECT>", f1);
					pre_mode = 0;
					end_tag = 0;
					goto proc_normal;
				    }
				}
			    }
			}
		    }

		  proc_normal:
		    if (is_tag) {
			char *q = tok->ptr;
			int j, a_target = 0;
			ParsedURL url;

			if (!(tag = parse_tag(&q, FALSE)))
			    goto token_end;

			switch (tag->tagid) {
			case HTML_TITLE:
			    fputs("<!-- title:", f1);
			    goto token_end;
			case HTML_N_TITLE:
			    fputs("-->", f1);
			    goto token_end;
			case HTML_BASE:
			    /* "BASE" is prohibit tag */
			    if (parsedtag_get_value(tag, ATTR_HREF, &q)) {
				q = url_encode(remove_space(q), NULL, charset);
				parseURL(q, &base, NULL);
			    }
			    if (parsedtag_get_value(tag, ATTR_TARGET, &q)) {
				if (!strcasecmp(q, "_self"))
				    d_target = s_target;
				else if (!strcasecmp(q, "_parent"))
				    d_target = p_target;
				else
				    d_target = url_quote_conv(q, charset);
			    }
			    Strshrinkfirst(tok, 1);
			    Strshrink(tok, 1);
			    fprintf(f1, "<!-- %s -->", html_quote(tok->ptr));
			    goto token_end;
			case HTML_META:
			    if (parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q)
				&& !strcasecmp(q, "refresh")) {
				if (parsedtag_get_value(tag, ATTR_CONTENT, &q)
				    ) {
				    Str s_tmp = NULL;
				    int refresh_interval =
					getMetaRefreshParam(q, &s_tmp);
				    if (s_tmp) {
					q = html_quote(s_tmp->ptr);
					fprintf(f1,
						"Refresh (%d sec) <a href=\"%s\">%s</a>\n",
						refresh_interval, q, q);
				    }
				}
			    }
#ifdef USE_M17N
			    if (UseContentCharset &&
				parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q)
				&& !strcasecmp(q, "Content-Type")
				&& parsedtag_get_value(tag, ATTR_CONTENT, &q)
				&& (q = strcasestr(q, "charset")) != NULL) {
				q += 7;
				SKIP_BLANKS(q);
				if (*q == '=') {
				    wc_ces c;
				    q++;
				    SKIP_BLANKS(q);
				    if ((c = wc_guess_charset(q, 0)) != 0) {
					doc_charset = c;
					charset = WC_CES_US_ASCII;
				    }
				}
			    }
#endif
			    /* fall thru, "META" is prohibit tag */
			case HTML_HEAD:
			case HTML_N_HEAD:
			case HTML_BODY:
			case HTML_N_BODY:
			case HTML_DOCTYPE:
			    /* prohibit_tags */
			    Strshrinkfirst(tok, 1);
			    Strshrink(tok, 1);
			    fprintf(f1, "<!-- %s -->", html_quote(tok->ptr));
			    goto token_end;
			case HTML_TABLE:
			    t_stack++;
			    break;
			case HTML_N_TABLE:
			    t_stack--;
			    if (t_stack < 0) {
				t_stack = 0;
				Strshrinkfirst(tok, 1);
				Strshrink(tok, 1);
				fprintf(f1,
					"<!-- table stack underflow: %s -->",
					html_quote(tok->ptr));
				goto token_end;
			    }
			    break;
			  CASE_TABLE_TAG:
			    /* table_tags MUST be in table stack */
			    if (!t_stack) {
				Strshrinkfirst(tok, 1);
				Strshrink(tok, 1);
				fprintf(f1, "<!-- %s -->",
					html_quote(tok->ptr));
				goto token_end;

			    }
			    break;
			case HTML_SELECT:
			    pre_mode = RB_INSELECT;
			    end_tag = HTML_N_SELECT;
			    break;
			case HTML_TEXTAREA:
			    pre_mode = RB_INTXTA;
			    end_tag = HTML_N_TEXTAREA;
			    break;
			case HTML_SCRIPT:
			    pre_mode = RB_SCRIPT;
			    end_tag = HTML_N_SCRIPT;
			    break;
			case HTML_STYLE:
			    pre_mode = RB_STYLE;
			    end_tag = HTML_N_STYLE;
			    break;
			case HTML_LISTING:
			    pre_mode = RB_PLAIN;
			    end_tag = HTML_N_LISTING;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			case HTML_XMP:
			    pre_mode = RB_PLAIN;
			    end_tag = HTML_N_XMP;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			case HTML_PLAINTEXT:
			    pre_mode = RB_PLAIN;
			    end_tag = MAX_HTMLTAG;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			default:
			    break;
			}
			for (j = 0; j < TagMAP[tag->tagid].max_attribute; j++) {
			    switch (tag->attrid[j]) {
			    case ATTR_SRC:
			    case ATTR_HREF:
			    case ATTR_ACTION:
				if (!tag->value[j])
				    break;
				tag->value[j] =
				    url_encode(remove_space(tag->value[j]),
					       &base, charset);
				tag->need_reconstruct = TRUE;
				parseURL2(tag->value[j], &url, &base);
				if (url.scheme == SCM_UNKNOWN ||
#ifndef USE_W3MMAILER
				    url.scheme == SCM_MAILTO ||
#endif
				    url.scheme == SCM_MISSING)
				    break;
				a_target |= 1;
				tag->value[j] = parsedURL2Str(&url)->ptr;
				parsedtag_set_value(tag,
						    ATTR_REFERER,
						    parsedURL2Str(&base)->ptr);
#ifdef USE_M17N
				if (tag->attrid[j] == ATTR_ACTION &&
				    charset != WC_CES_US_ASCII)
				    parsedtag_set_value(tag,
							ATTR_CHARSET,
							wc_ces_to_charset
							(charset));
#endif
				break;
			    case ATTR_TARGET:
				if (!tag->value[j])
				    break;
				a_target |= 2;
				if (!strcasecmp(tag->value[j], "_self")) {
				    parsedtag_set_value(tag,
							ATTR_TARGET, s_target);
				}
				else if (!strcasecmp(tag->value[j], "_parent")) {
				    parsedtag_set_value(tag,
							ATTR_TARGET, p_target);
				}
				break;
			    case ATTR_NAME:
			    case ATTR_ID:
				if (!tag->value[j])
				    break;
				parsedtag_set_value(tag,
						    ATTR_FRAMENAME, s_target);
				break;
			    }
			}
			if (a_target == 1) {
			    /* there is HREF attribute and no TARGET
			     * attribute */
			    parsedtag_set_value(tag, ATTR_TARGET, d_target);
			}
			if (parsedtag_need_reconstruct(tag))
			    tok = parsedtag2str(tag);
			Strfputs(tok, f1);
		    }
		    else {
			if (pre_mode & RB_PLAIN)
			    fprintf(f1, "%s", html_quote(tok->ptr));
			else if (pre_mode & RB_INTXTA)
			    fprintf(f1, "%s",
				    html_quote(html_unquote(tok->ptr)));
			else
			    Strfputs(tok, f1);
		    }
		  token_end:
		    Strclear(tok);
		} while (*p != '\0' || !iseos(f2.stream));
		if (pre_mode & RB_PLAIN)
		    fputs("</PRE_PLAIN>\n", f1);
		else if (pre_mode & RB_INTXTA)
		    fputs("</TEXTAREA></FORM>\n", f1);
		else if (pre_mode & RB_INSELECT)
		    fputs("</SELECT></FORM>\n", f1);
		else if (pre_mode & (RB_SCRIPT | RB_STYLE)) {
		    if (status != R_ST_NORMAL)
			fputs(correct_irrtag(status)->ptr, f1);
		    if (pre_mode & RB_SCRIPT)
			fputs("</SCRIPT>\n", f1);
		    else if (pre_mode & RB_STYLE)
			fputs("</STYLE>\n", f1);
		}
		while (t_stack--)
		    fputs("</TABLE>\n", f1);
		UFclose(&f2);
		break;
	    case F_FRAMESET:
	      render_frameset:
		if (!frame.set->name && f->name) {
		    frame.set->name = Sprintf("%s_%d", f->name, i)->ptr;
		}
		createFrameFile(frame.set, f1, current, level + 1,
				force_reload);
		break;
	    }
	    fputs("</td>\n", f1);
	}
	fputs("</tr>\n", f1);
    }

    fputs("</table>\n", f1);
    if (level == 0) {
	fputs("</body></html>\n", f1);
	TRAP_OFF;
    }
    return 0;
}
Example #12
0
static int
extractMailcapEntry(char *mcap_entry, struct mailcap *mcap)
{
    int j, k;
    char *p;
    bool quoted = false;
    Str tmp;

    memset(mcap, 0, sizeof(struct mailcap));
    p = mcap_entry;
    SKIP_BLANKS(p);
    k = -1;
    for (j = 0; p[j] && p[j] != ';'; j++) {
	if (!IS_SPACE(p[j]))
	    k = j;
    }
    mcap->type = allocStr(p, (k >= 0) ? k + 1 : j);
    if (!p[j])
	return 0;
    p += j + 1;

    SKIP_BLANKS(p);
    k = -1;
    for (j = 0; p[j] && (quoted || p[j] != ';'); j++) {
	if (quoted || !IS_SPACE(p[j]))
	    k = j;
	if (quoted)
	    quoted = false;
	else if (p[j] == '\\')
	    quoted = true;
    }
    mcap->viewer = allocStr(p, (k >= 0) ? k + 1 : j);
    p += j;

    while (*p == ';') {
	p++;
	SKIP_BLANKS(p);
	if (matchMailcapAttr(p, "needsterminal", 13, NULL)) {
	    mcap->flags |= MAILCAP_NEEDSTERMINAL;
	}
	else if (matchMailcapAttr(p, "copiousoutput", 13, NULL)) {
	    mcap->flags |= MAILCAP_COPIOUSOUTPUT;
	}
	else if (matchMailcapAttr(p, "x-htmloutput", 12, NULL) ||
		 matchMailcapAttr(p, "htmloutput", 10, NULL)) {
	    mcap->flags |= MAILCAP_HTMLOUTPUT;
	}
	else if (matchMailcapAttr(p, "test", 4, &tmp)) {
	    mcap->test = allocStr(tmp->ptr, tmp->length);
	}
	else if (matchMailcapAttr(p, "nametemplate", 12, &tmp)) {
	    mcap->nametemplate = allocStr(tmp->ptr, tmp->length);
	}
	else if (matchMailcapAttr(p, "edit", 4, &tmp)) {
	    mcap->edit = allocStr(tmp->ptr, tmp->length);
	}
	quoted = false;
	while (*p && (quoted || *p != ';')) {
	    if (quoted)
		quoted = false;
	    else if (*p == '\\')
		quoted = true;
	    p++;
	}
    }
    return 1;
}
Example #13
0
XmlErr XmlProfile::XmlParseBuffer(char *buffer) {
	XmlErr err;
	int state=XML_ELEMENT_NONE;
	char *p=buffer;
	//unsigned int offset=fileStat.st_size;

#define XML_FREE_ATTRIBUTES \
	if(nAttrs>0) {\
		for(int i=0;i<nAttrs;i++) {\
			if(attrs[i]) free(attrs[i]);\
			if(values[i]) free(values[i]);\
		}\
		free(attrs);\
		attrs=NULL;\
		free(values);\
		values=NULL;\
		nAttrs=0;\
	}\
	if(start) free(start);

#define SKIP_BLANKS(__p) \
	while((*__p==' ' || *__p=='\t' || *__p=='\r' || *__p == '\n') && *__p!=0) __p++; \
	if(*__p==0) break;
		
#define ADVANCE_ELEMENT(__p) \
	while(*__p!='>' && *__p!=' ' && *__p!='\t' && *__p!='\r' && *__p != '\n' && *__p!=0) __p++; \
	if(*__p==0) break;
		
#define ADVANCE_TO_ATTR_VALUE(__p) \
	while(*__p!='=' && *__p!=' ' && *__p!='\t' && *__p!='\r' && *__p != '\n' && *__p!=0) __p++;\
	SKIP_BLANKS(__p);

	while(*p!=0) {
		SKIP_BLANKS(p);
		char *mark;
		if(*p=='<') {
			p++;
			if(*p=='/') {
				p++;
				SKIP_BLANKS(p);
				mark=p;
				while(*p!='>' && *p!=0) p++;
				if(*p=='>') {
					char *end=(char *)malloc(p-mark+1);
					strncpy(end,mark,p-mark);
					end[p-mark]=0;
					p++;
					state=XML_ELEMENT_END;
					err=XmlEndHandler(end);
					if(end) free(end);
					if(err!=XML_NOERR) return(err);
				}
			}
			else if(strncmp(p,"!--",3) == 0) { /* comment */
				p += 3; /* skip !-- */ 
				mark = p;
				p = strstr(mark,"-->");
				if(!p) 
				{
					/* XXX - TODO - This error condition must be handled asap */
				}
				char *comment = (char *)calloc(1,p-mark+1);
				if(!comment)
				{
					return XML_MEMORY_ERR;
				}
				strncpy(comment,mark,p-mark);
				err = XmlCommentHandler(comment);
				free(comment);
				p+=3;
			}
			//else if(*p =='?') { /* head */
			//	p++;
			//	mark = p;
			//	p = strstr(mark,"?>");
			//	if(xml->head) free(xml->head); /* XXX - should notify this behaviour? */
			//	xml->head = calloc(1,p-mark+1);
			//	strncpy(xml->head,mark,p-mark);
			//	p+=2;
			//}
			else { /* start tag */
				char *start = NULL;
				char **attrs = NULL;
				char **values = NULL;
				unsigned int nAttrs = 0;
				state=XML_ELEMENT_START;
				SKIP_BLANKS(p);
				mark=p;
				ADVANCE_ELEMENT(p);
				start = (char *)malloc(p-mark+1);
				strncpy(start,mark,p-mark);
				if(*p=='>' && *(p-1)=='/') {
					start[p-mark-1]=0;
					state=XML_ELEMENT_UNIQUE;
				}
				else {
					start[p-mark]=0;
				}
				SKIP_BLANKS(p);
				while(*p!='>' && *p!=0) {
					mark=p;
					ADVANCE_TO_ATTR_VALUE(p);
					if(*p=='=') {
						char *tmpAttr=(char *)malloc(p-mark+1);
						strncpy(tmpAttr,mark,p-mark);
						tmpAttr[p-mark]=0;
						p++;
						SKIP_BLANKS(p);
						if(*p == '"' || *p == '\'') {
							int quote = *p;
							p++;
							mark=p;
							while(*p!=quote && *p!=0) p++;
							if(*p==quote) {
								char *tmpVal = (char *)malloc(p-mark+1);
								strncpy(tmpVal,mark,p-mark);
								tmpVal[p-mark]=0;
								/* add new attribute */
								nAttrs++;
								attrs=(char **)realloc(attrs,sizeof(char *)*(nAttrs+1));
								attrs[nAttrs-1]=tmpAttr;
								attrs[nAttrs]=NULL;
								values=(char **)realloc(values,sizeof(char *)*(nAttrs+1));
								values[nAttrs-1]=tmpVal;
								values[nAttrs]=NULL;
								p++;
								SKIP_BLANKS(p);
							}
							else {
								free(tmpAttr);
							}
						} /* if(*p == '"' || *p == '\'') */
						else {
							free(tmpAttr);
						}
					} /* if(*p=='=') */
					if(*p == '/' && *(p+1) == '>') {
						p++;
						state=XML_ELEMENT_UNIQUE;
					}
				} /* while(*p!='>' && *p!=0) */
				err = XmlStartHandler(start,attrs,values);
				if(err!=XML_NOERR) {
					XML_FREE_ATTRIBUTES
					return err;
				}
				if(state==XML_ELEMENT_UNIQUE) {
					err = XmlEndHandler(start);
					if(err!=XML_NOERR) {
						XML_FREE_ATTRIBUTES
						return err;
					}
				}