コード例 #1
0
ファイル: wuc.c プロジェクト: carriercomm/Exult
int main(int argc,char *argv[])
{
	int i,opsize=sizeof(opcode_table)/sizeof(opcode_desc),
		pushsize=sizeof(push_table)/sizeof(opcode_desc),
		compsize=sizeof(compiler_table)/sizeof(char*);
	const char **func_table = bg_intrinsic_table;
	int funsize = bg_intrinsic_size;
	int findex = 1;			// Index in argv of 1st filename.
	indata=codesize=datasize=0;
	printf("Wody's Usecode Compiler v0.009\nCopyright (c) 1999 Wody "
		"Dragon (a.k.a. Wouter Dijkslag)\n");
	if (argc<3)
	{
		printf("syntax: %s [-s] infile outfile\n", argv[0]);
		exit(0);
	}
					// Serpent Isle?
	if (strcmp(argv[1], "-s") == 0)
		{
		findex++;
		func_table = si_intrinsic_table;
		funsize = si_intrinsic_size;
		}

 lindex=0;
 for (pass=0;pass<2;pass++)
 {
  printf("Pass %d\n",pass+1);
  if ((fi=fopen(argv[findex],"r"))==NULL)
  {
   printf("Can't open infile for reading\n");
   exit(0);
  }
  if ((fo=fopen(argv[findex + 1],"wb"))==NULL)
  {
   printf("Can't open outfile for writing\n");
   exit(0);
  }
  while (!feof(fi))
  {
   read_token(fi);
   if (pass==0 && token[strlen(token)-1]==':') add_label();
   else
   if (!strcmp(token,".code"))
   {
	indata=0;
	offset=0;
   }
   else
   if (!strcmp(token,".data"))
   {
	indata=1;
	offset=0;
   }
   else
   if (!strcmp(token,".funcnumber"))
   {
	read_token(fi);
	sscanf(token,"%x",&word);
	emit_word(word);
	emit_word(0);
	emit_word(0);
	codesize=2;
   }
   else
   if (token[0]=='.')
   {
	indata=0;
	for (i=0;i<compsize;i++)
		if (!strcasecmp(compiler_table[i],token))
		{
			read_token(fi);
			sscanf(token,"%x",&word);
			emit_word(word);
		}
   }
   else
   if (!strcmp(token,"db"))
   {
	read_token(fi);
	if (token[0]==39)
		for (i=1;i<strlen(token);i++)
			emit_byte(token[i]);
	else
	{
		sscanf(token,"%x",&byte);
		emit_byte(byte);
	}
   }
   else
   if (!strcasecmp(token,"dw"))
   {
	read_token(fi);
	sscanf(token,"%x",&word);
	emit_word(word);
   }
   else
   for (i=0;i<opsize;i++)
   {
    if (!strcasecmp(opcode_table[i].mnemonic,token))
    {
     if (opcode_table[i].nbytes==0 && opcode_table[i].type==0)
       emit_byte(i);
     else
     switch (opcode_table[i].type)
     {
	case BYTE:
		emit_byte(i);
		read_token(fi);
		sscanf(token,"%x",&word);
		emit_byte(word);
		break;
	case CALL:
		emit_byte(i);
		read_token(fi);
		if ((token2=strchr(token,'@'))!=NULL)
		{
			token2++;
			token[strchr(token,'@')-token]=0;
			strcpy(token,token+1);
			for (i=0;i<funsize;i++)
				if (!strcasecmp(token,func_table[i]))
				{
					emit_word(i);
					break;
				}
			if (i==funsize)
			{
				printf("Do not know function '%s'\n",token);
				exit(0);
			}
			sscanf(token2,"%d",&word);
		}
		else
		{
			sscanf(token,"%x",&word);
			emit_word(word);
			read_token(fi);
			sscanf(token,"%d",&word);
		}
		emit_byte(word);
		break;
	case DATA_STRING:
		emit_byte(i);
		read_token(fi);
		emit_word(get_label());
		break;
	case EXTCALL:
	case VARREF:
		emit_byte(i);
		read_token(fi);
		sscanf(token,"[%x]",&word);
		emit_word(word);
		break;
	case FLGREF:
		emit_byte(i);
		read_token(fi);
		sscanf(token,"flag:[%x]",&word);
		emit_word(word);
		break;
	case PUSH:
		read_token(fi);
		for (i=0;i<pushsize;i++)
		{
			if (!strcasecmp(push_table[i].mnemonic,token))
			{
				emit_byte(push_table[i].type);
				break;
			}
		}
		if (i==pushsize)
		{
			emit_byte(0x21);
			sscanf(token,"[%x]",&word);
			emit_word(word);
		}
		break;
	case IMMED:
		emit_byte(i);
		read_token(fi);
		sscanf(token,"%x",&word);
		emit_word(word);
		break;
	case RELATIVE_JUMP:
		emit_byte(i);
		read_token(fi);
		if (pass==1)
			emit_word(get_label()-offset-2);
		else
			emit_word(-1);
		break;
	case IMMED_AND_RELATIVE_JUMP:
		emit_byte(i);
		read_token(fi);
		sscanf(token,"%x",&word);
		emit_word(word);
		read_token(fi);
		if (pass==1)
			emit_word(get_label()-offset-2);
		else
			emit_word(-1);
		break;
	default:
		break;
     }
    }
   }
  }
  fseek(fo,2,SEEK_SET);
  indata=0;
  i=codesize;
  emit_word(i);
  emit_word(datasize);
  fclose(fo);
  fclose(fi);
 }
 return 0;
}
コード例 #2
0
/** 
 * Read in global options.
 * 
 * @param fp [in] file pointer
 * @param op [out] pointer to store the global options
 */
static void
read_global_opt(FILE *fp, HTK_HMM_Options *op)
{
  int i;
  short tmptype;
  int num;

  for (;;) {
    if (rdhmmdef_token == NULL) break;
    if (currentis("HMMSETID")) { /* <HMMSETID> */
      read_token(fp);
      NoTokErr("missing HMMSETID argument");
    } else if (currentis("STREAMINFO")) { /* <STREAMINFO> */
      read_token(fp);
      NoTokErr("missing STREAMINFO num");
      op->stream_info.num = atoi(rdhmmdef_token);
      /*DM("%d STREAMs:", op->stream_info.num);*/
      if (op->stream_info.num > MAXSTREAMNUM) {
	jlog("Error: rdhmmdef_options: stream num exceeded %d\n", MAXSTREAMNUM);
	rderr(NULL);
      }
      for (i=0;i<op->stream_info.num;i++) {
	read_token(fp);
	NoTokErr("missing STREAMINFO vector size");
	op->stream_info.vsize[i] = atoi(rdhmmdef_token);
	/*DM(" %d",op->stream_info.vsize[i]);*/
      }
      /*DM("\n");*/
      
    } else if (currentis("VECSIZE")) {	/* <VECSIZE> */
      read_token(fp);
      NoTokErr("missing VECSIZE value");
      op->vec_size = atoi(rdhmmdef_token);
      /*DM("vector size: %d\n", op->vec_size);*/
      
    } else if (currentis("MSDINFO")) { /* <MSDINFO> by HTS */
      /* Julius can auto-detect MSD-HMM, so just skip this */
      read_token(fp);
      NoTokErr("missing MSDINFO num");
      num = atoi(rdhmmdef_token);
      for (i=0;i<num;i++) {
	read_token(fp);
      }

    } else {
      /* covariance matrix type */
      for (i=0;optcov[i].name!=NULL;i++) {
	if (currentis(optcov[i].name)) {
	  op->cov_type = optcov[i].type;
	  /*DM("covariance matrix type: %s\n", optcov[i].desc);*/
	  goto optloop;
	}
      }
      /* duration type */
      for (i=0;optdur[i].name!=NULL;i++) {
	if (currentis(optdur[i].name)) {
	  op->dur_type = optdur[i].type;
	  /*DM("duration type: %s\n", optdur[i].desc);*/
	  goto optloop;
	}
      }
      /* parameter type */
      tmptype = param_str2code(rdhmmdef_token);
      if (tmptype != F_ERR_INVALID) { /* conv success */
	op->param_type = tmptype;
	/*DM("param type: %s", param_code2str(buf, op->param_type, FALSE));*/
	goto optloop;
      } else {
	/* nothing of above --- not option */
	if(rdhmmdef_token[0] != '~') {
	  jlog("Error: rdhmmdef_options: unknown option in header: %s\n", rdhmmdef_token);
	  rderr("unknown option in header");
	}
	return;
      }
    }
  optloop:
    read_token(fp);
  }
}
コード例 #3
0
ファイル: SourceTokenC.hpp プロジェクト: DavidPH/DH-acc
 static Reference create(SourceStream *in)
 {
     Reference tok(new SourceTokenC);
     read_token(in, tok);
     return tok;
 }
コード例 #4
0
ファイル: cssread.c プロジェクト: erkyrath/mincss
/* Read in a block. When called, the current token must be an LBrace.
   On return, the current token is whatever was after the RBrace.
*/
static node *read_block(mincss_context *context)
{
    tokentype toktyp = context->nexttok.typ;
    if (toktyp == tok_EOF || toktyp != tok_LBrace) {
        mincss_note_error(context, "(Internal) Unexpected token at read_block");
        return NULL;
    }
    read_token(context);
    read_token_skipspace(context);

    node *nod = new_node(context, nod_Block);

    while (1) {
        toktyp = context->nexttok.typ;
        if (toktyp == tok_EOF) {
            mincss_note_error(context, "Unexpected end of block");
            return nod;
        }

        switch (toktyp) {

        case tok_RBrace:
            /* Done */
            read_token(context);
            read_token_skipspace(context);
            return nod;

        case tok_LBrace: {
            /* Sub-block */
            node *blocknod = read_block(context);
            if (!blocknod) {
                /* error, already reported */
                continue;
            }
            node_add_node(nod, blocknod);
            continue;
        }

        case tok_Semicolon: {
            node *subnod = new_node_token(context, &context->nexttok);
            node_add_node(nod, subnod);
            read_token(context);
            continue;
        }

        case tok_AtKeyword: {
            node *atnod = new_node_token(context, &context->nexttok);
            node_add_node(nod, atnod);
            read_token(context);
            continue;
        }

        case tok_Function: {
            node *subnod = new_node(context, nod_Function);
            node_copy_text(subnod, &context->nexttok);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LParen: {
            node *subnod = new_node(context, nod_Parens);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LBracket: {
            node *subnod = new_node(context, nod_Brackets);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RBracket);
            continue;
        }

        case tok_CDO:
        case tok_CDC:
            mincss_note_error(context, "HTML comment delimiters not allowed inside block");
            read_token(context);
            read_token_skipspace(context);
            continue;

        case tok_RParen:
            mincss_note_error(context, "Unexpected close-paren inside block");
            read_token(context);
            continue;

        case tok_RBracket:
            mincss_note_error(context, "Unexpected close-bracket inside block");
            read_token(context);
            continue;

        default: {
            /* Anything else is a single "any". */
            node *subnod = new_node_token(context, &context->nexttok);
            node_add_node(nod, subnod);
            read_token(context);
        }
        }
    }
}
コード例 #5
0
ファイル: frame.c プロジェクト: 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;
}
コード例 #6
0
ファイル: cssread.c プロジェクト: erkyrath/mincss
/* If the current token is whitespace, read more tokens until it's not. */
static void read_token_skipspace(mincss_context *context)
{
    while (context->nexttok.typ == tok_Space)
        read_token(context);
}
コード例 #7
0
ファイル: cssread.c プロジェクト: erkyrath/mincss
/* Read an "any*" sequence, up until end-of-file or an AtKeyword
   token. Appends nodes to the node passed in (which will be a
   TopLevel).

   On return, the current token is EOF, LBrace (meaning start of
   a block), or AtKeyword.
*/
static void read_any_top_level(mincss_context *context, node *nod)
{
    while (1) {
        tokentype toktyp = context->nexttok.typ;
        if (toktyp == tok_EOF) {
            return; /* end of file */
        }

        switch (toktyp) {

        case tok_LBrace:
            return;
            
        case tok_Function: {
            node *subnod = new_node(context, nod_Function);
            node_copy_text(subnod, &context->nexttok);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LParen: {
            node *subnod = new_node(context, nod_Parens);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LBracket: {
            node *subnod = new_node(context, nod_Brackets);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RBracket);
            continue;
        }

        case tok_CDO:
        case tok_CDC:
            /* Swallow, ignore */
            read_token(context);
            read_token_skipspace(context);
            continue;

        case tok_RParen:
            mincss_note_error(context, "Unexpected close-paren");
            read_token(context);
            continue;

        case tok_RBracket:
            mincss_note_error(context, "Unexpected close-bracket");
            read_token(context);
            continue;

        case tok_AtKeyword:
            return;

        case tok_Semicolon: {
            node *toknod = new_node_token(context, &context->nexttok);
            node_add_node(nod, toknod);
            read_token(context);
            read_token_skipspace(context);
            continue;
        }

        default: {
            node *toknod = new_node_token(context, &context->nexttok);
            node_add_node(nod, toknod);
            read_token(context);
        }
        }
    }
}
コード例 #8
0
ファイル: 7a.c プロジェクト: 7shi/Betelgeuse
int read_sign(const char *sign)
{
    return is_sign(read_token(), sign);
}
コード例 #9
0
void getNextToken()
{
      tokenLen = read_token(&ch,str);
}
コード例 #10
0
ファイル: dpp.c プロジェクト: ageneau/ecl-mirror
void
main_loop(void)
{
        int c;
        int in_defun=0;
        char *p;

        lineno = 1;

        reset();
        put_lineno();
LOOP:
        c = jump_to_at();
        if (c == ')') {
                if (!in_defun)
                        error("unmatched @) found");
                in_defun = 0;
                putc('}',out);
                reset();
                goto LOOP;
        } else if (c == '\'') {
                char *p;
                poolp = pool;
                p = read_symbol(0);
                pushc('\0');
                fprintf(out,"%s",p);
                goto LOOP;
        }  else if (c == '[') {
                char *p;
                poolp = pool;
                p = read_symbol(1);
                pushc('\0');
                fprintf(out,"%s",p);
                goto LOOP;
        } else if (c != '(') {
                char *p;
                unreadc(c);
                poolp = pool;
                poolp = p = read_function();
                fprintf(out,"%s",translate_function(poolp));
                goto LOOP;
        }
        p = read_token();
        if (strcmp(p, "defun") == 0) {
                if (in_defun)
                        error("@) expected before new function definition");
                in_defun = 1;
                get_function();
                get_lambda_list();
                put_fhead();
                put_lineno();
                c = jump_to_at();
                put_declaration();
                put_lineno();
        } else if (strcmp(p, "return") == 0) {
                tab_save = tab;
                get_return();
                put_return();
        } else
                error_symbol(p);
        goto LOOP;
}
コード例 #11
0
ファイル: 7a.c プロジェクト: 7shi/Betelgeuse
int read_reg(enum Regs *reg, const char *msg)
{
    return get_reg(reg, read_token(), msg);
}
コード例 #12
0
ファイル: dpp.c プロジェクト: ageneau/ecl-mirror
void
get_lambda_list(void)
{
        int c;
        char *p;

        if ((c = nextc()) != '(')
                error("( expected");
        for (;;) {
                if ((c = nextc()) == ')')
                        return;
                if (c == '&') {
                        p = read_token();
                        goto _OPT;
                }
                unreadc(c);
                p = read_token();
                if (nreq >= MAXREQ)
                        error("too many required variables");
                required[nreq++] = p;
        }

_OPT:
        if (strcmp(p, "optional") != 0 && strcmp(p, "o") != 0)
                goto _REST;
        for (;;  nopt++) {
                if ((c = nextc()) == ')')
                        return;
                if (c == '&') {
                        p = read_token();
                        goto _REST;
                }
                if (nopt >= MAXOPT)
                        error("too many optional argument");
                if (c == '(') {
                        optional[nopt].o_var = read_token();
                        if ((c = nextc()) == ')')
                                continue;
                        unreadc(c);
                        optional[nopt].o_init = read_token();
                        if ((c = nextc()) == ')')
                                continue;
                        unreadc(c);
                        optional[nopt].o_svar = read_token();
                        if (nextc() != ')')
                                error(") expected");
                } else {
                        unreadc(c);
                        optional[nopt].o_var = read_token();
                }
        }

_REST:
        if (strcmp(p, "rest") != 0 && strcmp(p, "r") != 0)
                goto _KEY;
        rest_flag = TRUE;
        if ((c = nextc()) == ')' || c == '&')
                error("&rest var missing");
        unreadc(c);
        rest_var = read_token();
        if ((c = nextc()) == ')')
                return;
        if (c != '&')
                error("& expected");
        p = read_token();

_KEY:
        if (strcmp(p, "key") != 0 && strcmp(p, "k") != 0)
                goto _AUX;
        key_flag = TRUE;
        for (;;  nkey++) {
                if ((c = nextc()) == ')')
                        return;
                if (c == '&') {
                        p = read_token();
                        if (strcmp(p, "allow_other_keys") == 0 ||
                            strcmp(p, "aok") == 0) {
                                allow_other_keys_flag = TRUE;
                                if ((c = nextc()) == ')')
                                        return;
                                if (c != '&')
                                        error("& expected");
                                p = read_token();
                        }
                        goto _AUX;
                }
                if (nkey >= MAXKEY)
                        error("too many optional argument");
                if (c == '(') {
                        if ((c = nextc()) == '(') {
                                p = read_token();
                                if (p[0] != ':' || p[1] == '\0')
                                        error("keyword expected");
                                keyword[nkey].k_key = p + 1;
                                keyword[nkey].k_var = read_token();
                                if (nextc() != ')')
                                        error(") expected");
                        } else {
                                unreadc(c);
                                keyword[nkey].k_key
                                = keyword[nkey].k_var
                                = read_token();
                        }
                        if ((c = nextc()) == ')')
                                continue;
                        unreadc(c);
                        keyword[nkey].k_init = read_token();
                        if ((c = nextc()) == ')')
                                continue;
                        unreadc(c);
                        keyword[nkey].k_svar = read_token();
                        if (nextc() != ')')
                                error(") expected");
                } else {
                        unreadc(c);
                        keyword[nkey].k_key
                        = keyword[nkey].k_var
                        = read_token();
                }
        }

_AUX:
        if (strcmp(p, "aux") != 0 && strcmp(p, "a") != 0)
                error("illegal lambda-list keyword");
        for (;;) {
                if ((c = nextc()) == ')')
                        return;
                if (c == '&')
                        error("illegal lambda-list keyword");
                if (naux >= MAXAUX)
                        error("too many auxiliary variable");
                if (c == '(') {
                        aux[naux].a_var = read_token();
                        if ((c = nextc()) == ')')
                                continue;
                        unreadc(c);
                        aux[naux].a_init = read_token();
                        if (nextc() != ')')
                                error(") expected");
                } else {
                        unreadc(c);
                        aux[naux].a_var = read_token();
                }
                naux++;
        }
}
コード例 #13
0
	void read_op(sm4_op* pop)
	{
		sm4_op& op = *pop;
		sm4_token_operand optok;
		read_token(&optok);
		assert(optok.file < SM4_FILE_COUNT);
		op.swizzle[0] = 0;
		op.swizzle[1] = 1;
		op.swizzle[2] = 2;
		op.swizzle[3] = 3;
		op.mask = 0xf;
		switch(optok.comps_enum)
		{
		case SM4_OPERAND_COMPNUM_0:
			op.comps = 0;
			break;
		case SM4_OPERAND_COMPNUM_1:
			op.comps = 1;
			break;
		case SM4_OPERAND_COMPNUM_4:
			op.comps = 4;
			op.mode = optok.mode;
			switch(optok.mode)
			{
			case SM4_OPERAND_MODE_MASK:
				op.mask = SM4_OPERAND_SEL_MASK(optok.sel);
				break;
			case SM4_OPERAND_MODE_SWIZZLE:
				op.swizzle[0] = SM4_OPERAND_SEL_SWZ(optok.sel, 0);
				op.swizzle[1] = SM4_OPERAND_SEL_SWZ(optok.sel, 1);
				op.swizzle[2] = SM4_OPERAND_SEL_SWZ(optok.sel, 2);
				op.swizzle[3] = SM4_OPERAND_SEL_SWZ(optok.sel, 3);
				break;
			case SM4_OPERAND_MODE_SCALAR:
				op.swizzle[0] = op.swizzle[1] = op.swizzle[2] = op.swizzle[3] = SM4_OPERAND_SEL_SCALAR(optok.sel);
				break;
			}
			break;
		case SM4_OPERAND_COMPNUM_N:
			fail("Unhandled operand component type");
		}
		op.file = (sm4_file)optok.file;
		op.num_indices = optok.num_indices;

		if(optok.extended)
		{
			sm4_token_operand_extended optokext;
			read_token(&optokext);
			if(optokext.type == 0)
			{}
			else if(optokext.type == 1)
			{
				op.neg = optokext.neg;
				op.abs= optokext.abs;
			}
			else
				fail("Unhandled extended operand token type");
		}

		for(unsigned i = 0; i < op.num_indices; ++i)
		{
			unsigned repr;
			if(i == 0)
				repr = optok.index0_repr;
			else if(i == 1)
				repr = optok.index1_repr;
			else if(i == 2)
				repr = optok.index2_repr;
			else
				fail("Unhandled operand index representation");
			op.indices[0].disp = 0;
			// TODO: is disp supposed to be signed here??
			switch(repr)
			{
			case SM4_OPERAND_INDEX_REPR_IMM32:
				op.indices[i].disp = (int32_t)read32();
				break;
			case SM4_OPERAND_INDEX_REPR_IMM64:
				op.indices[i].disp = read64();
				break;
			case SM4_OPERAND_INDEX_REPR_REG:
relative:
				op.indices[i].reg.reset(new sm4_op());
				read_op(&*op.indices[0].reg);
				break;
			case SM4_OPERAND_INDEX_REPR_REG_IMM32:
				op.indices[i].disp = (int32_t)read32();
				goto relative;
			case SM4_OPERAND_INDEX_REPR_REG_IMM64:
				op.indices[i].disp = read64();
				goto relative;
			}
		}

		if(op.file == SM4_FILE_IMMEDIATE32)
		{
			for(unsigned i = 0; i < op.comps; ++i)
				op.imm_values[i].i32 = read32();
		}
		else if(op.file == SM4_FILE_IMMEDIATE64)
		{
			for(unsigned i = 0; i < op.comps; ++i)
				op.imm_values[i].i64 = read64();
		}
	}
コード例 #14
0
	void do_parse()
	{
		read_token(&program.version);

		unsigned lentok = read32();
		tokens_end = tokens - 2 + lentok;

		while(tokens != tokens_end)
		{
			sm4_token_instruction insntok;
			read_token(&insntok);
			unsigned* insn_end = tokens - 1 + insntok.length;
			sm4_opcode opcode = (sm4_opcode)insntok.opcode;
			check(opcode < SM4_OPCODE_COUNT);

			if(opcode == SM4_OPCODE_CUSTOMDATA)
			{
				unsigned customlen = read32() - 2;
				skip(customlen);
				continue;
			}

			if((opcode >= SM4_OPCODE_DCL_RESOURCE && opcode <= SM4_OPCODE_DCL_GLOBAL_FLAGS)
				|| (opcode >= SM4_OPCODE_DCL_STREAM && opcode <= SM4_OPCODE_DCL_RESOURCE_STRUCTURED))
			{
				sm4_dcl& dcl = *new sm4_dcl;
				program.dcls.push_back(&dcl);
				(sm4_token_instruction&)dcl = insntok;

				sm4_token_instruction_extended exttok;
				memcpy(&exttok, &insntok, sizeof(exttok));
				while(exttok.extended)
				{
					read_token(&exttok);
				}

#define READ_OP_ANY dcl.op.reset(new sm4_op()); read_op(&*dcl.op);
#define READ_OP(FILE) READ_OP_ANY
				//check(dcl.op->file == SM4_FILE_##FILE);

				switch(opcode)
				{
				case SM4_OPCODE_DCL_GLOBAL_FLAGS:
					break;
				case SM4_OPCODE_DCL_RESOURCE:
					READ_OP(RESOURCE);
					read_token(&dcl.rrt);
					break;
				case SM4_OPCODE_DCL_SAMPLER:
					READ_OP(SAMPLER);
					break;
				case SM4_OPCODE_DCL_INPUT:
				case SM4_OPCODE_DCL_INPUT_PS:
					READ_OP(INPUT);
					break;
				case SM4_OPCODE_DCL_INPUT_SIV:
				case SM4_OPCODE_DCL_INPUT_SGV:
				case SM4_OPCODE_DCL_INPUT_PS_SIV:
				case SM4_OPCODE_DCL_INPUT_PS_SGV:
					READ_OP(INPUT);
					dcl.sv = (sm4_sv)(uint16_t)read32();
					break;
				case SM4_OPCODE_DCL_OUTPUT:
					READ_OP(OUTPUT);
					break;
				case SM4_OPCODE_DCL_OUTPUT_SIV:
				case SM4_OPCODE_DCL_OUTPUT_SGV:
					READ_OP(OUTPUT);
					dcl.sv = (sm4_sv)(uint16_t)read32();
					break;
				case SM4_OPCODE_DCL_INDEX_RANGE:
					READ_OP_ANY;
					check(dcl.op->file == SM4_FILE_INPUT || dcl.op->file == SM4_FILE_OUTPUT);
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_TEMPS:
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_INDEXABLE_TEMP:
					READ_OP(INDEXABLE_TEMP);
					dcl.indexable_temp.num = read32();
					dcl.indexable_temp.comps = read32();
					break;
				case SM4_OPCODE_DCL_CONSTANT_BUFFER:
					READ_OP(CONSTANT_BUFFER);
					break;
				case SM4_OPCODE_DCL_GS_INPUT_PRIMITIVE:
				case SM4_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
					break;
				case SM4_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT:
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_GS_INSTANCE_COUNT:
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT:
				case SM4_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT:
				case SM4_OPCODE_DCL_TESS_DOMAIN:
				case SM4_OPCODE_DCL_TESS_PARTITIONING:
				case SM4_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE:
					break;
				case SM4_OPCODE_DCL_HS_MAX_TESSFACTOR:
					dcl.f32 = read32();
					break;
				case SM4_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT:
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_FUNCTION_BODY:
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_FUNCTION_TABLE:
					dcl.num = read32();
					dcl.data = malloc(dcl.num * sizeof(uint32_t));
					for(unsigned i = 0; i < dcl.num; ++i)
						((uint32_t*)dcl.data)[i] = read32();
					break;
				case SM4_OPCODE_DCL_INTERFACE:
					dcl.intf.id = read32();
					dcl.intf.expected_function_table_length = read32();
					{
						uint32_t v = read32();
						dcl.intf.table_length = v & 0xffff;
						dcl.intf.array_length = v >> 16;
					}
					dcl.data = malloc(dcl.intf.table_length * sizeof(uint32_t));
					for(unsigned i = 0; i < dcl.intf.table_length; ++i)
						((uint32_t*)dcl.data)[i] = read32();
					break;
				case SM4_OPCODE_DCL_THREAD_GROUP:
					dcl.thread_group_size[0] = read32();
					dcl.thread_group_size[1] = read32();
					dcl.thread_group_size[2] = read32();
					break;
				case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED:
					READ_OP(UNORDERED_ACCESS_VIEW);
					read_token(&dcl.rrt);
					break;
				case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW:
					READ_OP(UNORDERED_ACCESS_VIEW);
					break;
				case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED:
					READ_OP(UNORDERED_ACCESS_VIEW);
					dcl.structured.stride = read32();
					break;
				case SM4_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
					READ_OP(THREAD_GROUP_SHARED_MEMORY);
					dcl.num = read32();
					break;
				case SM4_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
					READ_OP(THREAD_GROUP_SHARED_MEMORY);
					dcl.structured.stride = read32();
					dcl.structured.count = read32();
					break;
				case SM4_OPCODE_DCL_RESOURCE_RAW:
					READ_OP(RESOURCE);
					break;
				case SM4_OPCODE_DCL_RESOURCE_STRUCTURED:
					READ_OP(RESOURCE);
					dcl.structured.stride = read32();
					break;
				case SM4_OPCODE_DCL_STREAM:
					/* TODO: dcl_stream is undocumented: what is it? */
					fail("Unhandled dcl_stream since it's undocumented");
				default:
					fail("Unhandled declaration");
				}

				check(tokens == insn_end);
			}
			else
			{
コード例 #15
0
ファイル: gss-token.c プロジェクト: elric1/gss-token
int
main(int argc, char **argv)
{
	OM_uint32	 min;
	gss_name_t	 service = NULL;
	extern char	*optarg;
	extern int	 optind;
	size_t		 count = 1;
	int		 ch;
	int		 Dflag = 0;
	int		 Nflag = 0;
	int		 lflag = 0;
	int		 rflag = 0;
	int		 ret = 0;
	char		*ccname = NULL;

	while ((ch = getopt(argc, argv, "C:DNc:nlr")) != -1) {
		switch (ch) {
		case 'C':
			ccname = optarg;
			break;
		case 'D':
			Dflag = 1;
			break;
		case 'N':
			Nflag = 1;
			break;
		case 'c':
			count = atoi(optarg);
			break;
		case 'n':
			nflag = 1;
			break;
		case 'l':
			lflag = 1;
			break;
		case 'r':
			rflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc > 0)
		service = import_service(*argv);

	if (!rflag) {
		if (!argc) {
			fprintf(stderr, "Without -r, hostbased_service must "
			    "be provided.\n");
			usage();
		}
		if (ccname) {
			fprintf(stderr, "Specifying a target ccache doesn't "
			    "make sense without -r.\n");
			usage();
		}
		ret = write_token(service, Dflag, Nflag, count);
		goto done;
	}

	if (Dflag) {
		fprintf(stderr, "Delegating credentials (-D) doesn't make "
		    "sense when reading tokens (-r).\n");
		usage();
	}

	do {
		ret = read_token(service, ccname, Nflag, count);
	} while (lflag && !ret && !feof(stdin));

done:
	if (service)
		gss_release_name(&min, &service);

	return ret;
}
コード例 #16
0
ファイル: read.c プロジェクト: SatoHiroki/julia
static u_int32_t peek(void)
{
    char c, *end;
    fixnum_t x;
    int ch, base;

    if (toktype != TOK_NONE)
        return toktype;
    c = nextchar();
    if (ios_eof(F)) return TOK_NONE;
    if (c == '(') {
        toktype = TOK_OPEN;
    }
    else if (c == ')') {
        toktype = TOK_CLOSE;
    }
    else if (c == '[') {
        toktype = TOK_OPENB;
    }
    else if (c == ']') {
        toktype = TOK_CLOSEB;
    }
    else if (c == '\'') {
        toktype = TOK_QUOTE;
    }
    else if (c == '`') {
        toktype = TOK_BQ;
    }
    else if (c == '"') {
        toktype = TOK_DOUBLEQUOTE;
    }
    else if (c == '#') {
        ch = ios_getc(F); c = (char)ch;
        if (ch == IOS_EOF)
            lerror(ParseError, "read: invalid read macro");
        if (c == '.') {
            toktype = TOK_SHARPDOT;
        }
        else if (c == '\'') {
            toktype = TOK_SHARPQUOTE;
        }
        else if (c == '\\') {
            uint32_t cval;
            if (ios_getutf8(F, &cval) == IOS_EOF)
                lerror(ParseError, "read: end of input in character constant");
            if (cval == (uint32_t)'u' || cval == (uint32_t)'U' ||
                cval == (uint32_t)'x') {
                read_token('u', 0);
                if (buf[1] != '\0') {  // not a solitary 'u','U','x'
                    if (!read_numtok(&buf[1], &tokval, 16))
                        lerror(ParseError,
                               "read: invalid hex character constant");
                    cval = numval(tokval);
                }
            }
            else if (cval >= 'a' && cval <= 'z') {
                read_token((char)cval, 0);
                tokval = symbol(buf);
                if (buf[1] == '\0')       /* one character */;
                else if (tokval == nulsym)        cval = 0x00;
                else if (tokval == alarmsym)      cval = 0x07;
                else if (tokval == backspacesym)  cval = 0x08;
                else if (tokval == tabsym)        cval = 0x09;
                else if (tokval == linefeedsym)   cval = 0x0A;
                else if (tokval == newlinesym)    cval = 0x0A;
                else if (tokval == vtabsym)       cval = 0x0B;
                else if (tokval == pagesym)       cval = 0x0C;
                else if (tokval == returnsym)     cval = 0x0D;
                else if (tokval == escsym)        cval = 0x1B;
                else if (tokval == spacesym)      cval = 0x20;
                else if (tokval == deletesym)     cval = 0x7F;
                else
                    lerrorf(ParseError, "read: unknown character #\\%s", buf);
            }
            toktype = TOK_NUM;
            tokval = mk_wchar(cval);
        }
        else if (c == '(') {
            toktype = TOK_SHARPOPEN;
        }
        else if (c == '<') {
            lerror(ParseError, "read: unreadable object");
        }
        else if (isdigit(c)) {
            read_token(c, 1);
            c = (char)ios_getc(F);
            if (c == '#')
                toktype = TOK_BACKREF;
            else if (c == '=')
                toktype = TOK_LABEL;
            else
                lerror(ParseError, "read: invalid label");
            errno = 0;
            x = strtol(buf, &end, 10);
            if (*end != '\0' || errno)
                lerror(ParseError, "read: invalid label");
            tokval = fixnum(x);
        }
        else if (c == '!') {
            // #! single line comment for shbang script support
            do {
                ch = ios_getc(F);
            } while (ch != IOS_EOF && (char)ch != '\n');
            return peek();
        }
        else if (c == '|') {
            // multiline comment
            int commentlevel=1;
            while (1) {
                ch = ios_getc(F);
            hashpipe_gotc:
                if (ch == IOS_EOF)
                    lerror(ParseError, "read: eof within comment");
                if ((char)ch == '|') {
                    ch = ios_getc(F);
                    if ((char)ch == '#') {
                        commentlevel--;
                        if (commentlevel == 0)
                            break;
                        else
                            continue;
                    }
                    goto hashpipe_gotc;
                }
                else if ((char)ch == '#') {
                    ch = ios_getc(F);
                    if ((char)ch == '|')
                        commentlevel++;
                    else
                        goto hashpipe_gotc;
                }
            }
            // this was whitespace, so keep peeking
            return peek();
        }
        else if (c == ';') {
            // datum comment
            (void)do_read_sexpr(UNBOUND); // skip
            return peek();
        }
        else if (c == ':') {
            // gensym
            ch = ios_getc(F);
            if ((char)ch == 'g')
                ch = ios_getc(F);
            read_token((char)ch, 0);
            errno = 0;
            x = strtol(buf, &end, 10);
            if (*end != '\0' || buf[0] == '\0' || errno)
                lerror(ParseError, "read: invalid gensym label");
            toktype = TOK_GENSYM;
            tokval = fixnum(x);
        }
        else if (symchar(c)) {
            read_token(ch, 0);

            if (((c == 'b' && (base= 2)) ||
                 (c == 'o' && (base= 8)) ||
                 (c == 'd' && (base=10)) ||
                 (c == 'x' && (base=16))) &&
                (isdigit_base(buf[1],base) ||
                 buf[1]=='-')) {
                if (!read_numtok(&buf[1], &tokval, base))
                    lerrorf(ParseError, "read: invalid base %d constant", base);
                return (toktype=TOK_NUM);
            }

            toktype = TOK_SHARPSYM;
            tokval = symbol(buf);
        }
        else {
            lerror(ParseError, "read: unknown read macro");
        }
    }
    else if (c == ',') {
        toktype = TOK_COMMA;
        ch = ios_getc(F);
        if (ch == IOS_EOF)
            return toktype;
        if ((char)ch == '@')
            toktype = TOK_COMMAAT;
        else if ((char)ch == '.')
            toktype = TOK_COMMADOT;
        else
            ios_ungetc((char)ch, F);
    }
    else {
        if (!read_token(c, 0)) {
            if (buf[0]=='.' && buf[1]=='\0') {
                return (toktype=TOK_DOT);
            }
            else {
                if (read_numtok(buf, &tokval, 0))
                    return (toktype=TOK_NUM);
            }
        }
        toktype = TOK_SYM;
        tokval = symbol(buf);
    }
    return toktype;
}
コード例 #17
0
static int
process_filter(struct event_format *event, struct filter_arg **parg,
	       char **error_str, int not)
{
	enum event_type type;
	char *token = NULL;
	struct filter_arg *current_op = NULL;
	struct filter_arg *current_exp = NULL;
	struct filter_arg *left_item = NULL;
	struct filter_arg *arg = NULL;
	enum op_type op_type;
	enum filter_op_type btype;
	enum filter_exp_type etype;
	enum filter_cmp_type ctype;
	int ret;

	*parg = NULL;

	do {
		free(token);
		type = read_token(&token);
		switch (type) {
		case EVENT_SQUOTE:
		case EVENT_DQUOTE:
		case EVENT_ITEM:
			arg = create_arg_item(event, token, type, error_str);
			if (!arg)
				goto fail;
			if (!left_item)
				left_item = arg;
			else if (current_exp) {
				ret = add_right(current_exp, arg, error_str);
				if (ret < 0)
					goto fail;
				left_item = NULL;
				/* Not's only one one expression */
				if (not) {
					arg = NULL;
					if (current_op)
						goto fail_print;
					free(token);
					*parg = current_exp;
					return 0;
				}
			} else
				goto fail_print;
			arg = NULL;
			break;

		case EVENT_DELIM:
			if (*token == ',') {
				show_error(error_str,
					   "Illegal token ','");
				goto fail;
			}

			if (*token == '(') {
				if (left_item) {
					show_error(error_str,
						   "Open paren can not come after item");
					goto fail;
				}
				if (current_exp) {
					show_error(error_str,
						   "Open paren can not come after expression");
					goto fail;
				}

				ret = process_filter(event, &arg, error_str, 0);
				if (ret != 1) {
					if (ret == 0)
						show_error(error_str,
							   "Unbalanced number of '('");
					goto fail;
				}
				ret = 0;

				/* A not wants just one expression */
				if (not) {
					if (current_op)
						goto fail_print;
					*parg = arg;
					return 0;
				}

				if (current_op)
					ret = add_right(current_op, arg, error_str);
				else
					current_exp = arg;

				if (ret < 0)
					goto fail;

			} else { /* ')' */
				if (!current_op && !current_exp)
					goto fail_print;

				/* Make sure everything is finished at this level */
				if (current_exp && !check_op_done(current_exp))
					goto fail_print;
				if (current_op && !check_op_done(current_op))
					goto fail_print;

				if (current_op)
					*parg = current_op;
				else
					*parg = current_exp;
				return 1;
			}
			break;

		case EVENT_OP:
			op_type = process_op(token, &btype, &ctype, &etype);

			/* All expect a left arg except for NOT */
			switch (op_type) {
			case OP_BOOL:
				/* Logic ops need a left expression */
				if (!current_exp && !current_op)
					goto fail_print;
				/* fall through */
			case OP_NOT:
				/* logic only processes ops and exp */
				if (left_item)
					goto fail_print;
				break;
			case OP_EXP:
			case OP_CMP:
				if (!left_item)
					goto fail_print;
				break;
			case OP_NONE:
				show_error(error_str,
					   "Unknown op token %s", token);
				goto fail;
			}

			ret = 0;
			switch (op_type) {
			case OP_BOOL:
				arg = create_arg_op(btype);
				if (current_op)
					ret = add_left(arg, current_op);
				else
					ret = add_left(arg, current_exp);
				current_op = arg;
				current_exp = NULL;
				break;

			case OP_NOT:
				arg = create_arg_op(btype);
				if (current_op)
					ret = add_right(current_op, arg, error_str);
				if (ret < 0)
					goto fail;
				current_exp = arg;
				ret = process_filter(event, &arg, error_str, 1);
				if (ret < 0)
					goto fail;
				ret = add_right(current_exp, arg, error_str);
				if (ret < 0)
					goto fail;
				break;

			case OP_EXP:
			case OP_CMP:
				if (op_type == OP_EXP)
					arg = create_arg_exp(etype);
				else
					arg = create_arg_cmp(ctype);

				if (current_op)
					ret = add_right(current_op, arg, error_str);
				if (ret < 0)
					goto fail;
				ret = add_left(arg, left_item);
				if (ret < 0) {
					arg = NULL;
					goto fail_print;
				}
				current_exp = arg;
				break;
			default:
				break;
			}
			arg = NULL;
			if (ret < 0)
				goto fail_print;
			break;
		case EVENT_NONE:
			break;
		default:
			goto fail_print;
		}
	} while (type != EVENT_NONE);

	if (!current_op && !current_exp)
		goto fail_print;

	if (!current_op)
		current_op = current_exp;

	current_op = collapse_tree(current_op);

	*parg = current_op;

	return 0;

 fail_print:
	show_error(error_str, "Syntax error");
 fail:
	free_arg(current_op);
	free_arg(current_exp);
	free_arg(arg);
	free(token);
	return -1;
}
コード例 #18
0
ファイル: bios150v3.c プロジェクト: cpu-mips/riscv
int main(void)
{
    uwrite_int8s("\r\n");

    for ( ; ; ) {
        uwrite_int8s("Hell> ");

        int8_t buffer[BUFFER_LEN];
        int8_t* input = read_token(buffer, BUFFER_LEN, " \x0d");

        if (strcmp(input, "file") == 0) {
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t file_length = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            store(address, file_length);
        } else if (strcmp(input, "jal") == 0) {
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));

            entry_t start = (entry_t)(address);
            start();
        } else if (strcmp(input, "lw") == 0) {
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            volatile uint32_t* p = (volatile uint32_t*)(address);

            uwrite_int8s(uint32_to_ascii_hex(address, buffer, BUFFER_LEN));
            uwrite_int8s(":");
            uwrite_int8s(uint32_to_ascii_hex(*p, buffer, BUFFER_LEN));
            uwrite_int8s("\r\n");
        } else if (strcmp(input, "lhu") == 0) {
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            volatile uint16_t* p = (volatile uint16_t*)(address);

            uwrite_int8s(uint32_to_ascii_hex(address, buffer, BUFFER_LEN));
            uwrite_int8s(":");
            uwrite_int8s(uint16_to_ascii_hex(*p, buffer, BUFFER_LEN));
            uwrite_int8s("\r\n");
        } else if (strcmp(input, "lbu") == 0) {
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            volatile uint8_t* p = (volatile uint8_t*)(address);

            uwrite_int8s(uint32_to_ascii_hex(address, buffer, BUFFER_LEN));
            uwrite_int8s(":");
            uwrite_int8s(uint8_to_ascii_hex(*p, buffer, BUFFER_LEN));
            uwrite_int8s("\r\n");
        } else if (strcmp(input, "sw") == 0) {
            uint32_t word = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));

            volatile uint32_t* p = (volatile uint32_t*)(address);
            *p = word;
        } else if (strcmp(input, "sh") == 0) {
            uint16_t half = ascii_hex_to_uint16(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));

            volatile uint16_t* p = (volatile uint16_t*)(address);
            *p = half;
        } else if (strcmp(input, "sb") == 0) {
            uint8_t byte = ascii_hex_to_uint8(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t address = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));

            volatile uint8_t* p = (volatile uint8_t*)(address);
            *p = byte;
        } else if (strcmp(input, "fill") == 0) {
            uint32_t color = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            fill(color);
        } else if (strcmp(input, "hwline") == 0) {
	    int8_t buffer[64];
            uint32_t color = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t x0 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t y0 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t x1 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t y1 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
	    uwrite_int8s("\r\n");
	    uwrite_int8s(uint32_to_ascii_hex(color, buffer, 64));
	    uwrite_int8s("\r\n");
	    uwrite_int8s(uint32_to_ascii_hex(x0, buffer, 64));
	    uwrite_int8s("\r\n");
	    uwrite_int8s(uint32_to_ascii_hex(y0, buffer, 64));
	    uwrite_int8s("\r\n");
	    uwrite_int8s(uint32_to_ascii_hex(x1, buffer, 64));
	    uwrite_int8s("\r\n");
	    uwrite_int8s(uint32_to_ascii_hex(y1, buffer, 64));
	    uwrite_int8s("\r\n");
	    uwrite_int8s("\r\n");
            hwline(color, x0, y0, x1, y1);
        } else if (strcmp(input, "swline") == 0) {
            uint32_t color = ascii_hex_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t x0 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t y0 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t x1 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            uint32_t y1 = ascii_dec_to_uint32(read_token(buffer, BUFFER_LEN, " \x0d"));
            swline(color, x0, y0, x1, y1);
        } else {
            uwrite_int8s("\n\rGo fuck yourself: ");
            uwrite_int8s(input);
            uwrite_int8s("\n\r");
        }
    }

    return 0;
}
コード例 #19
0
ファイル: cssread.c プロジェクト: erkyrath/mincss
/* Read one AtRule or TopLevel. A TopLevel is basically a sequence of anything
   that isn't an AtRule. 
*/
static node *read_statement(mincss_context *context)
{
    tokentype toktyp = context->nexttok.typ;
    if (toktyp == tok_EOF)
        return NULL;

    if (toktyp == tok_AtKeyword) {
        node *nod = new_node(context, nod_AtRule);
        node_copy_text(nod, &context->nexttok);
        read_token(context);
        read_token_skipspace(context);
        read_any_until_semiblock(context, nod);
        toktyp = context->nexttok.typ;
        if (toktyp == tok_EOF) {
            return nod; /* end of file */
        }
        if (toktyp == tok_Semicolon) {
            /* drop the semicolon, end the AtRule */
            read_token(context);
            read_token_skipspace(context);
            return nod;
        }
        if (toktyp == tok_LBrace) {
            /* beginning of block */
            node *blocknod = read_block(context);
            if (!blocknod) {
                /* error */
                free_node(nod);
                return NULL;
            }
            node_add_node(nod, blocknod);
            return nod; /* the block ends the AtRule */
        }
        /* error */
        mincss_note_error(context, "(Internal) Unexpected token after read_any_until_semiblock");
        free_node(nod);
        return NULL;
    }
    else {
        /* The syntax spec lets us parse a ruleset here. But we don't
           bother; we just parse any/blocks until the next AtKeyword. 
           They all get stuffed into a single TopLevel node. (Unless
           there's no content at all, in which case we don't create a
           node.) */
        node *nod = new_node(context, nod_TopLevel);
        while (1) {
            read_any_top_level(context, nod);
            tokentype toktyp = context->nexttok.typ;
            if (toktyp == tok_EOF) {
                break; /* end of file */
            }
            if (toktyp == tok_AtKeyword) {
                break; /* an @-rule is next */
            }
            if (toktyp == tok_LBrace) {
                node *blocknod = read_block(context);
                if (!blocknod) {
                    /* error, already reported */
                    continue;
                }
                node_add_node(nod, blocknod);
                continue;
            }
            mincss_note_error(context, "(Internal) Unexpected token after read_any_top_level");
            free_node(nod);
            return NULL;
        }
        if (nod->numnodes == 0) {
            /* empty group, don't bother returning it. */
            free_node(nod);
            return NULL;
        }
        return nod;
    }
}
コード例 #20
0
ファイル: http.c プロジェクト: 6e6f36/nmap
static const char *http_read_challenge(const char *s, struct http_challenge *challenge)
{
    const char *p;
    char *scheme;

    http_challenge_init(challenge);

    scheme = NULL;
    s = read_token(s, &scheme);
    if (s == NULL)
        goto bail;
    if (str_equal_i(scheme, "Basic")) {
        challenge->scheme = AUTH_BASIC;
    } else if (str_equal_i(scheme, "Digest")) {
        challenge->scheme = AUTH_DIGEST;
    } else {
        challenge->scheme = AUTH_UNKNOWN;
    }
    free(scheme);
    scheme = NULL;

    /* RFC 2617, section 1.2, requires at least one auth-param:
         challenge = auth-scheme 1*SP 1#auth-param
       But there are some schemes (NTLM and Negotiate) that can be without
       auth-params, so we allow that here. A comma indicates the end of this
       challenge and the beginning of the next (see the comment in the loop
       below). */
    while (is_space_char(*s))
        s++;
    if (*s == ',') {
        s++;
        while (is_space_char(*s))
            s++;
        if (*s == '\0')
            goto bail;
        return s;
    }

    while (*s != '\0') {
        char *name, *value;

        p = read_token(s, &name);
        if (p == NULL)
            goto bail;
        while (is_space_char(*p))
            p++;
        /* It's possible that we've hit the end of one challenge and the
           beginning of another. Section 14.33 says that the header value can be
           1#challenge, in other words several challenges separated by commas.
           Because the auth-params are also separated by commas, the only way we
           can tell is if we find a token not followed by an equals sign. */
        if (*p != '=')
            break;
        p++;
        while (is_space_char(*p))
            p++;
        p = read_token_or_quoted_string(p, &value);
        if (p == NULL) {
            free(name);
            goto bail;
        }
        if (str_equal_i(name, "realm"))
            challenge->realm = Strdup(value);
        else if (challenge->scheme == AUTH_DIGEST) {
            if (str_equal_i(name, "nonce")) {
                if (challenge->digest.nonce != NULL)
                    goto bail;
                challenge->digest.nonce = Strdup(value);
            } else if (str_equal_i(name, "opaque")) {
                if (challenge->digest.opaque != NULL)
                    goto bail;
                challenge->digest.opaque = Strdup(value);
            } else if (str_equal_i(name, "algorithm")) {
                if (str_equal_i(value, "MD5"))
                    challenge->digest.algorithm = ALGORITHM_MD5;
                else
                    challenge->digest.algorithm = ALGORITHM_UNKNOWN;
            } else if (str_equal_i(name, "qop")) {
                char **tokens;
                size_t n;
                int i;
                const char *tmp;

                tmp = read_token_list(value, &tokens, &n);
                if (tmp == NULL) {
                    free(name);
                    free(value);
                    goto bail;
                }
                for (i = 0; i < n; i++) {
                    if (str_equal_i(tokens[i], "auth"))
                        challenge->digest.qop |= QOP_AUTH;
                    else if (str_equal_i(tokens[i], "auth-int"))
                        challenge->digest.qop |= QOP_AUTH_INT;
                }
                for (i = 0; i < n; i++)
                    free(tokens[i]);
                free(tokens);
                if (*tmp != '\0') {
                    free(name);
                    free(value);
                    goto bail;
                }
            }
        }
        free(name);
        free(value);
        while (is_space_char(*p))
            p++;
        if (*p == ',') {
            p++;
            while (is_space_char(*p))
                p++;
            if (*p == '\0')
                goto bail;
        }
        s = p;
    }

    return s;

bail:
    if (scheme != NULL)
        free(scheme);
    http_challenge_free(challenge);

    return NULL;
}
コード例 #21
0
ファイル: cssread.c プロジェクト: erkyrath/mincss
/* Read an "any* sequence up until a particular close token (RBracket or
   RParen). Blocks cannot occur in this context.

   On return, the current token is whatever's next.
*/
static void read_any_until_close(mincss_context *context, node *nod, tokentype closetok)
{
    while (1) {
        tokentype toktyp = context->nexttok.typ;
        if (toktyp == tok_EOF) {
            mincss_note_error(context, "Missing close-delimiter");
            return;
        }

        if (toktyp == closetok) {
            /* The expected close-token. */
            read_token(context);
            return;
        }

        switch (toktyp) {

        case tok_Semicolon: 
            mincss_note_error(context, "Unexpected semicolon inside brackets");
            read_token(context);
            continue;
            
        case tok_LBrace:
            mincss_note_error(context, "Unexpected block inside brackets");
            read_block(context);
            continue;

        case tok_Function: {
            node *subnod = new_node(context, nod_Function);
            node_copy_text(subnod, &context->nexttok);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LParen: {
            node *subnod = new_node(context, nod_Parens);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RParen);
            continue;
        }

        case tok_LBracket: {
            node *subnod = new_node(context, nod_Brackets);
            node_add_node(nod, subnod);
            read_token(context);
            read_any_until_close(context, subnod, tok_RBracket);
            continue;
        }

        case tok_CDO:
        case tok_CDC:
            mincss_note_error(context, "HTML comment delimiters not allowed inside brackets");
            read_token(context);
            read_token_skipspace(context);
            continue;

        case tok_RParen:
            mincss_note_error(context, "Unexpected close-paren inside brackets");
            read_token(context);
            continue;

        case tok_RBracket:
            mincss_note_error(context, "Unexpected close-bracket inside brackets");
            read_token(context);
            continue;

        case tok_AtKeyword:
            mincss_note_error(context, "Unexpected @-keyword inside brackets");
            read_token(context);
            continue;

        default: {
            node *toknod = new_node_token(context, &context->nexttok);
            node_add_node(nod, toknod);
            read_token(context);
        }
        }
    }
}
コード例 #22
0
ファイル: http.c プロジェクト: 6e6f36/nmap
static const char *http_read_credentials(const char *s,
    struct http_credentials *credentials)
{
    const char *p;
    char *scheme;

    credentials->scheme = AUTH_UNKNOWN;

    s = read_token(s, &scheme);
    if (s == NULL)
        return NULL;
    if (str_equal_i(scheme, "Basic")) {
        http_credentials_init_basic(credentials);
    } else if (str_equal_i(scheme, "Digest")) {
        http_credentials_init_digest(credentials);
    } else {
        free(scheme);
        return NULL;
    }
    free(scheme);

    while (is_space_char(*s))
        s++;
    if (credentials->scheme == AUTH_BASIC) {
        p = s;
        /* Read base64. */
        while (is_alpha_char(*p) || is_digit_char(*p) || *p == '+' || *p == '/' || *p == '=')
            p++;
        credentials->u.basic = mkstr(s, p);
        while (is_space_char(*p))
            p++;
        s = p;
    } else if (credentials->scheme == AUTH_DIGEST) {
        char *name, *value;

        while (*s != '\0') {
            p = read_token(s, &name);
            if (p == NULL)
                goto bail;
            while (is_space_char(*p))
                p++;
            /* It's not legal to combine multiple Authorization or
               Proxy-Authorization values. The productions are
                 "Authorization" ":" credentials  (section 14.8)
                 "Proxy-Authorization" ":" credentials  (section 14.34)
               Contrast this with WWW-Authenticate and Proxy-Authenticate and
               their handling in http_read_challenge. */
            if (*p != '=')
                goto bail;
            p++;
            while (is_space_char(*p))
                p++;
            p = read_token_or_quoted_string(p, &value);
            if (p == NULL) {
                free(name);
                goto bail;
            }
            if (str_equal_i(name, "username")) {
                if (credentials->u.digest.username != NULL)
                    goto bail;
                credentials->u.digest.username = Strdup(value);
            } else if (str_equal_i(name, "realm")) {
                if (credentials->u.digest.realm != NULL)
                    goto bail;
                credentials->u.digest.realm = Strdup(value);
            } else if (str_equal_i(name, "nonce")) {
                if (credentials->u.digest.nonce != NULL)
                    goto bail;
                credentials->u.digest.nonce = Strdup(value);
            } else if (str_equal_i(name, "uri")) {
                if (credentials->u.digest.uri != NULL)
                    goto bail;
                credentials->u.digest.uri = Strdup(value);
            } else if (str_equal_i(name, "response")) {
                if (credentials->u.digest.response != NULL)
                    goto bail;
                credentials->u.digest.response = Strdup(value);
            } else if (str_equal_i(name, "algorithm")) {
                if (str_equal_i(value, "MD5"))
                    credentials->u.digest.algorithm = ALGORITHM_MD5;
                else
                    credentials->u.digest.algorithm = ALGORITHM_MD5;
            } else if (str_equal_i(name, "qop")) {
                if (str_equal_i(value, "auth"))
                    credentials->u.digest.qop = QOP_AUTH;
                else if (str_equal_i(value, "auth-int"))
                    credentials->u.digest.qop = QOP_AUTH_INT;
                else
                    credentials->u.digest.qop = QOP_NONE;
            } else if (str_equal_i(name, "cnonce")) {
                if (credentials->u.digest.cnonce != NULL)
                    goto bail;
                credentials->u.digest.cnonce = Strdup(value);
            } else if (str_equal_i(name, "nc")) {
                if (credentials->u.digest.nc != NULL)
                    goto bail;
                credentials->u.digest.nc = Strdup(value);
            }
            free(name);
            free(value);
            while (is_space_char(*p))
                p++;
            if (*p == ',') {
                p++;
                while (is_space_char(*p))
                    p++;
                if (*p == '\0')
                    goto bail;
            }
            s = p;
        }
    }

    return s;

bail:
    http_credentials_free(credentials);

    return NULL;
}
コード例 #23
0
ファイル: arff.c プロジェクト: effigies/prelieff
int lex (char *buf, arff_info_t * info)
{
	char *tok;
	char c;
	int i, r;
	token_t delimiter;

	for (;;) {
		if ((c = *buf++) == '\0')
			break;

		switch (c) {
		case ' ':
		case '\t':
		case '\r':
			// ignore
			break;
		case '%':
			/* a comment */
			do {
				c = *buf++;
			} while ((c != '\n') && (c != '\0'));
			buf--;
			break;
		case '\n':
			/* a new line */
			TRY (r, parse (TOKEN_NEWLINE, NULL, info));
			break;
		case ',':
			/* a comma */
			TRY (r, parse (TOKEN_COMMA, NULL, info));
			break;
		case '{':
			/* a left brace */
			TRY (r, parse (TOKEN_LEFTBRACE, NULL, info));
			break;
		case '}':
			/* a right brace */
			TRY (r, parse (TOKEN_RIGHTBRACE, NULL, info));
			break;
		default:
			/* something else */
			buf--;
			tok = read_token (&buf, &delimiter);

			/* check if it is a special token */
			for (i = 0; special[i].string != NULL; i++) {
				if (!stricmp (tok, special[i].string)) {
					TRY (r,
					     parse (special[i].type, tok,
						    info));
					break;
				}
			}
			if (special[i].string == NULL)
				TRY (r, parse (TOKEN_TOKEN, tok, info));
			if (delimiter < TOKEN_NUM_TYPES)
				TRY (r, parse (delimiter, NULL, info));
			break;
		}
	}

	parse_end (info);

	return 0;
}
コード例 #24
0
ファイル: ioutil.c プロジェクト: Infovarius/findif
void init_param(int argc, char** argv,double *dtnext,int flag)
{
int ver;
FILE *iop;
double d;
 if(argc<2 || (iop=fopen(argv[1],"r"))==NULL) //no ini file
     nrerror("Start from no ini file!",-1,-1);

 if(fscanf(iop,"%d",&ver)<1 || ver!=2) nrerror("parameters' file has wrong version",0,0);
      read_token(iop,&rc);
      read_token(iop,&R);
      read_token(iop,&Re);
      read_token(iop,&parabole);
      read_token(iop,&Noise);
      read_token(iop,&NoiseNorm);
      read_token(iop,&UpLimit);
      read_token(iop,&chimax);
      read_token(iop,&d);         N1 = (int)d;
      read_token(iop,&d);         N3 = (int)d;
      read_token(iop,&d);         nvar = (int)d;
      read_token(iop,&d);         approx = (int)d;
      read_token(iop,dtnext);
      read_token(iop,&d);         max_okr = (int)d;
      read_token(iop,&d);         OutStep = (int)d;
      read_token(iop,&d);         SnapStep = (int)d;
      read_token(iop,&SnapDelta);
      if(ver>=2) read_token(iop,&DumpInterval);
      if(ver>=2) read_token(iop,&d);         DumpKeep = (int)d;
      read_token(iop,&d);         CheckStep = (int)d;
      read_token(iop,&d);         VarStep = (int)d;
      read_token(iop,&Ttot);
      read_token(iop,&ChangeParamTime);
      read_token(iop,&DeltaParam);
      read_token(iop,&d);
  if(flag)
     {
      if(d==0)	{
      		    goon = 0;
                strcpy(NameInitFile,"END");
                }
      else if(d>0)  {
         	    goon = 1;
                sprintf(NameInitFile,"%s_%d_%05d.snp",NameSnapFile,size,(int)d);
                }
	  else {// without reading (d<0)
			goon=0;
			strcpy(NameInitFile,"-1");
	  }
     }
  
  Master if(!goon && !count) nmessage("Parameters were extracted from file",0,0);
  fileclose(iop);
   
 	Gamma=1e-4;
	ghost=(approx-1)/2+3;                  //radius of approx sample
	dx[0]=2*R/N1;
	dx[2]=2*R/N3;
	p1 = 4/Re;
}
コード例 #25
0
ファイル: expr_eval.cpp プロジェクト: venustom85/gragon
double expression_eval(const char * expr)
{
    vector<token> rpn;

    stack<token> op_stk;
    token start_token;
    start_token.type = R;
    start_token.value.op = '#';
    op_stk.push(start_token);

    token tk;
    int i = 0;
    read_token(expr, i, tk);
    while (!op_stk.empty()) {
        if (tk.type == D) {
            rpn.push_back(tk);
            read_token(expr, i, tk);
        } else if (tk.type == R) {
            int top = op_stk.top().value.op;
            int c = op_compare(top, tk.value.op);
            if (c == -1) {
                token t;
                t.type = R;
                t.value.op = tk.value.op;
                op_stk.push(t);
                read_token(expr, i, tk);
            } else if (c == 1) { 
                rpn.push_back(op_stk.top());
                op_stk.pop();
            } else if (c == 0) {
                op_stk.pop();
                read_token(expr, i, tk);
            } else {
                cerr << "ERROR format of expression " << expr << endl;
                return -1;
            }
        }
    }

    stack<double> e_stk;
    for (vector<token>::iterator i = rpn.begin(); i != rpn.end(); ++i) {
        if (i->type == D) {
            e_stk.push(i->value.num);
        } else {
            if (e_stk.size() < 2) {
                cerr << "ERROR format of expression " << expr << endl;
                return -1;
            }
            double a2 = e_stk.top();
            e_stk.pop();
            double a1 = e_stk.top();
            e_stk.pop();

            double b = 0;
            switch (i->value.op) {
                case '+': b = a1 + a2; break;
                case '-': b = a1 - a2; break;
                case '*': b = a1 * a2; break;
                case '/': b = a1 / a2; break;
            }
            e_stk.push(b);
        }
    }

    return e_stk.top();
}
コード例 #26
0
ファイル: lex.c プロジェクト: ft/debian_fdm
int
yylex(void)
{
	int		 ch, value;
	char		*path;
	struct replpath	 rp;

	/* Switch to new file. See comment in read_token below. */
	if (lex_include) {
		while ((ch = lex_getc()) != EOF && isspace((u_char) ch))
			;

		if (ch != '"' && ch != '\'')
			yyerror("syntax error");
		if (ch == '"')
			rp.str = read_string('"', 1);
		else
			rp.str = read_string('\'', 0);
		path = replacepath(&rp, parse_tags, NULL, NULL, conf.user_home);
		xfree(rp.str);
		include_start(path);
		lex_include = 0;
	}

restart:
	while ((ch = lex_getc()) != EOF) {
		switch (ch) {
		case '#':
			/* Comment: discard until EOL. */
			while ((ch = lex_getc()) != '\n' && ch != EOF)
				;
			parse_file->line++;
			break;
		case '\'':
			yylval.string = read_string('\'', 0);
			value = STRING;
			goto out;
		case '"':
			yylval.string = read_string('"', 1);
			value = STRING;
			goto out;
		case '$':
			ch = lex_getc();
			if (ch == '(') {
				yylval.string = read_command();
				value = STRCOMMAND;
				goto out;
			}
			if (ch == '{' || isalnum((u_char) ch)) {
				yylval.string = read_macro('$', ch);
				value = STRMACRO;
				goto out;
			}
			yyerror("invalid macro name");
		case '%':
			ch = lex_getc();
			if (ch == '(') {
				yylval.string = read_command();
				value = NUMCOMMAND;
				goto out;
			}
			if (ch == '{' || isalnum((u_char) ch)) {
				yylval.string = read_macro('%', ch);
				value = NUMMACRO;
				goto out;
			}
			yyerror("invalid macro name");
		case '=':
			ch = lex_getc();
			if (ch == '=') {
				value = TOKEQ;
				goto out;
			}
			lex_ungetc(ch);
			value = '=';
			goto out;
		case '!':
			ch = lex_getc();
			if (ch == '=') {
				value = TOKNE;
				goto out;
			}
			lex_ungetc(ch);
			value = '!';
			goto out;
		case '~':
		case '+':
		case '(':
		case ')':
		case ',':
		case '<':
		case '>':
		case '{':
		case '}':
		case '*':
			value = ch;
			goto out;
		case '\n':
			parse_file->line++;
			break;
		case ' ':
		case '\t':
			break;
		default:
			if (ch != '_' && ch != '-' && !isalnum((u_char) ch))
				yyerror("unexpected character: %c", ch);

			if (isdigit((u_char) ch)) {
				yylval.number = read_number(ch);
				value = NUMBER;
				goto out;
			}

			value = read_token(ch);
			goto out;
		}
	}

	if (!include_finish())
		goto restart;
	if (lex_ifdef != 0)
		yyerror("missing endif");
	return (EOF);

out:
	if (lex_skip)
		goto restart;
	return (value);
}
コード例 #27
0
ファイル: SourceTokenC.hpp プロジェクト: DavidPH/DH-acc
 void readToken(SourceStream *in) {
     read_token(in, this);
 }
コード例 #28
0
/** 
 * @brief  Main top routine to read in HTK %HMM definition file.
 *
 * A HTK %HMM definition file will be read from @a fp.  After reading,
 * the parameter type is checked and calculate some statistics.
 * 
 * @param fp [in] file pointer
 * @param hmm [out] pointer to a %HMM definition structure to store data.
 * 
 * @return TRUE on success, FALSE on failure.
 */
boolean
rdhmmdef(FILE *fp, HTK_HMM_INFO *hmm)
{
  char macrosw;
  char *name;

  /* variances in htkdefs are not inversed yet */
  hmm->variance_inversed = FALSE;

  /* read the first token */
  /* read new 1 line */
  line = 1;
  if (getl(buf, MAXBUFLEN, fp) == NULL) {
    rdhmmdef_token = NULL;
  } else {
    rdhmmdef_token = mystrtok_quote(buf, HMMDEF_DELM);
  }
  
  /* the toplevel loop */
  while (rdhmmdef_token != NULL) {/* break on EOF */
    if (rdhmmdef_token[0] != '~') { /* toplevel commands are always macro */
      return FALSE;
    }
    macrosw = rdhmmdef_token[1];
    read_token(fp);		/* read next token after the "~.."  */
    switch(macrosw) {
    case 'o':			/* global option */
      if (set_global_opt(fp,hmm) == FALSE) {
	return FALSE;
      }
      break;
    case 't':			/* transition macro */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_trans_macro(name, fp, hmm);
      break;
    case 's':			/* state macro */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_state_macro(name, fp, hmm);
      break;
    case 'm':			/* density (mixture) macro */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_dens_macro(name, fp, hmm);
      break;
    case 'h':			/* HMM define */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_HMM(name, fp, hmm);
      break;
    case 'v':			/* Variance macro */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_var_macro(name, fp, hmm);
      break;
    case 'w':			/* Stream weight macro */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_streamweight_macro(name, fp, hmm);
      break;
    case 'r':			/* Regression class macro (ignore) */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_regtree_macro(name, fp, hmm);
      break;
    case 'p':			/* Mixture pdf macro (extension of HTS) */
      name = mybstrdup2(rdhmmdef_token, &(hmm->mroot));
      if (strlen(name) >= MAX_HMMNAME_LEN) rderr("Macro name too long");
      read_token(fp);
      def_mpdf_macro(name, fp, hmm);
      break;
    }
  }

  /* convert transition prob to log scale */
  conv_log_arc(hmm);

  jlog("Stat: rdhmmdef: ascii format HMM definition\n");
  
  /* check limitation */
  if (check_all_hmm_limit(hmm)) {
    jlog("Stat: rdhmmdef: limit check passed\n");
  } else {
    jlog("Error: rdhmmdef: cannot handle this HMM due to system limitation\n");
    return FALSE;
  }

  /* determine whether this model needs multi-path handling */
  hmm->need_multipath = htk_hmm_has_several_arc_on_edge(hmm);
  if (hmm->need_multipath) {
    jlog("Stat: rdhmmdef: this HMM requires multipath handling at decoding\n");
  } else {
    jlog("Stat: rdhmmdef: this HMM does not need multipath handling\n");
  }
  
  /* inverse all variance values for faster computation */
  if (! hmm->variance_inversed) {
    htk_hmm_inverse_variances(hmm);
    hmm->variance_inversed = TRUE;
  }

  /* check HMM parameter option type */
  if (!check_hmm_options(hmm)) {
    jlog("Error: rdhmmdef: hmm options check failed\n");
    return FALSE;
  }

  /* add ID number for all HTK_HMM_State if not assigned */
  {
    HTK_HMM_State *stmp;
    int n;
    boolean has_sid;

    /* caclculate total num and check if has sid */
    has_sid = FALSE;
    n = 0;
    for (stmp = hmm->ststart; stmp; stmp = stmp->next) {
      n++;
      if (n >= MAX_STATE_NUM) {
	jlog("Error: rdhmmdef: too much states in a model > %d\n", MAX_STATE_NUM);
	return FALSE;
      }
      if (stmp->id != -1) {
	has_sid = TRUE;
      }
    }
    hmm->totalstatenum = n;
    if (has_sid) {
      jlog("Stat: rdhmmdef: <SID> found in the definition\n");
      /* check if each state is assigned a valid sid */
      if (htk_hmm_check_sid(hmm) == FALSE) {
	jlog("Error: rdhmmdef: error in SID\n");
	return FALSE;
      }
    } else {
      /* assign internal sid (will not be saved) */
      jlog("Stat: rdhmmdef: no <SID> embedded\n");
      jlog("Stat: rdhmmdef: assign SID by the order of appearance\n");
      n = hmm->totalstatenum;
      for (stmp = hmm->ststart; stmp; stmp = stmp->next) {
	stmp->id = --n;
      }
    }
  }
  /* calculate the maximum number of mixture */
  {
    HTK_HMM_State *stmp;
    int max, s, mix;
    max = 0;
    for (stmp = hmm->ststart; stmp; stmp = stmp->next) {
      for(s=0;s<stmp->nstream;s++) {
	mix = stmp->pdf[s]->mix_num;
	if (max < mix) max = mix;
      }
    }
    hmm->maxmixturenum = max;
  }
  /* compute total number of HMM models and maximum length */
  {
    HTK_HMM_Data *dtmp;
    int n, maxlen;
    n = 0;
    maxlen = 0;
    for (dtmp = hmm->start; dtmp; dtmp = dtmp->next) {
      if (maxlen < dtmp->state_num) maxlen = dtmp->state_num;
      n++;
    }
    hmm->maxstatenum = maxlen;
    hmm->totalhmmnum = n;
  }
  /* compute total number of Gaussians */
  {
    HTK_HMM_Dens *dtmp;
    int n = 0;
    for (dtmp = hmm->dnstart; dtmp; dtmp = dtmp->next) {
      n++;
    }
    hmm->totalmixnum = n;
  }
  /* check of HMM name length exceed the maximum */
  {
    HTK_HMM_Dens *dtmp;
    int n = 0;
    for (dtmp = hmm->dnstart; dtmp; dtmp = dtmp->next) {
      n++;
    }
    hmm->totalmixnum = n;
  }
  /* compute total number of mixture PDFs */
  {
    HTK_HMM_PDF *p;
    int n = 0;
    for (p = hmm->pdfstart; p; p = p->next) {
      n++;
    }
    hmm->totalpdfnum = n;
  }
  /* assign ID number for all HTK_HMM_Trans */
  {
    HTK_HMM_Trans *ttmp;
    int n = 0;
    for (ttmp = hmm->trstart; ttmp; ttmp = ttmp->next) {
      ttmp->id = n++;
    }
    hmm->totaltransnum = n;
  }
#ifdef ENABLE_MSD
  /* check if MSD-HMM */
  htk_hmm_check_msd(hmm);
#endif

  return(TRUE);			/* success */
}
コード例 #29
0
ファイル: lex.c プロジェクト: Rudolph-Miller/trial-c
Token *peek_token(void) {
  Token *tok = read_token();
  unget_token(tok);
  return tok;
}
コード例 #30
0
/******************************************************
 interpreter関数
   ソケット通信でclientからコマンドがきたら、コマンドに応じて返信する
 *****************************************************/
int interpreter(char *line){
  char com[128];
  char *ptr;
  int command_flag=FALSE;
  int fd = get_socket_fd();
  char result[8024];   //結果の文字列領域
  int size;
  int i;

  //コマンドを切り出す
  while (*line && whitespace (*line)) line++;
  ptr = read_token(line, "%s", com);
  //fprintf(stderr, "recv command: %s\n", com);

  /******** コマンドに応じて返すデータを変更(ここから)  *********/
  //生画像データが欲しい
  if(strcmp(com, "write-rawdata") == 0){
    //rawdataを送っている間に画像データが書き変わらないようにロックをかける
    sema_lock(raw_semaphore);
    write(fd, rawdata, (process_width*process_height*3));
    sema_unlock(raw_semaphore);
    command_flag = TRUE;
  }
  //処理語画像データが欲しい
  else if(strcmp(com, "write-processdata") == 0){
    sema_lock(process_semaphore);
    write(fd, processdata, (process_width*process_height*3));
    sema_unlock(process_semaphore);
    command_flag = TRUE;
  }
  //処理結果(座標等)が欲しい  
  //  euslispで解釈しやすいように、()のリスト情報で情報付しておいてやるのがよい
  //  仕様は自分で決めて、後でclientのeuslisp側のソフトが動くものを作ればいい
  //  ここでは重心位置を返すようにしている
  else if(strcmp(com, "result") == 0){
    size = sprintf(result, "((:centroid");
    for(i=0; i<label_num; i++){
      size += sprintf(result+size, " #f(%d %d)", (int)linfo[i].xpos,(int)linfo[i].ypos);
    }
    size += sprintf(result+size, ")");
    size += sprintf(result+size, " (:area");
    for(i=0; i<label_num; i++){
      size += sprintf(result+size, " %d", linfo[i].area);
    }
    size += sprintf(result+size, "))\n");
    write(fd, result, size);
    command_flag = TRUE;
  }
  //縦横を返す for vision-viewer
  else if(strcmp(com, "vision-size")==0){
    size = sprintf(result, "(%d %d)\n", process_height, process_width);
    write(fd, result, size);
    command_flag = TRUE;
  }
  //閾値を変更したい
  else if(strcmp(com, "color-threshold") == 0){
    for(i=0; i<6; i++){
      ptr = read_token(ptr, "%d", &rgb_thre[i]);
    }
    fprintf(stderr, "change rgb_threshold ");
    for(i=0; i<6; i++){
      fprintf(stderr, "%d ", rgb_thre[i]);
    }
    fprintf(stderr, "\n");
    command_flag = TRUE;
  }
  //閾値を取得したい
  else if(strcmp(com, "get-color-threshold") == 0){
    size = sprintf(result, "#f(");
    for(i=0; i<6; i++){
      size += sprintf(result+size, "%d ", rgb_thre[i]);
    }
    size += sprintf(result+size, ")\n");
    write(fd, result, size);
    command_flag = TRUE;
  }
  //Labeling個数をセット 引数一つ
  else if(strcmp(com, "set-displaylabel-num") == 0){
    ptr = read_token(ptr, "%d", &display_label_num);
    fprintf(stderr, "change displaylabelnum %d\n", display_label_num);
    command_flag = TRUE;
  }
  //Labeling個数を取得
  else if(strcmp(com, "get-displaylabel-num") == 0){
    size = sprintf(result, "%d\n", display_label_num);
    write(fd, result, size);
    command_flag = TRUE;
  }
  //表示最小面積をセット 引数ひとつ
  else if(strcmp(com, "set-minarea") == 0){
    ptr = read_token(ptr, "%d", &minimum_area);
    fprintf(stderr, "change minimu area size %d\n", minimum_area);
    command_flag = TRUE;
  }
  //表示最小面積を取得
  else if(strcmp(com, "get-minarea") == 0){
    size = sprintf(result, "%d\n", minimum_area);
    write(fd, result, size);
    command_flag = TRUE;
  }
  /******** コマンドに応じて返すデータを変更(ここまで)  *********/
  //該当しないコマンドがきた場合はその旨を表示
  if(command_flag == FALSE){
    fprintf(stderr, "No such command %s\n", com);
  }
  return 0;
}