コード例 #1
0
/*
15.6.2.2531 [ELSE]
“bracket-else”
TOOLS EXT
Compilation: Perform the execution semantics given below.
Execution: ( “hspacesiname ...” -- )
Skipping leading spaces, parse and discard space-delimited words from the parse area,
including nested occurrences of [IF] ...
[THEN] and [IF] ...
[ELSE] ...
[THEN], until the word [THEN] has been parsed and discarded. If the parse area be-
comes exhausted, it is refilled as with REFILL. [ELSE] is an immediate word.
See: 3.4.1 Parsing, A.15.6.2.2531 [ELSE].
15.6.2.2532 [IF]
“bracket-if”
TOOLS EXT
*/
static void do_bracket_else(void)
{
/*

: [else]
	1 ( initialize [if]/[else]/[then] nesting level)
	begin
	bl word count dup 
	0= ( refill input buffer) if drop drop refill 0= if ( refill failed) drop ( drop nesting level) ." error: input exhausted" cr exit then [ over ] ( continue loop) again then
	0 if 2dup ." found word: " type cr then
	2dup s" [if]" compare 0= if ( increase nesting level) rot 1+ rot rot then
	2dup s" [else]" compare 0= if ( special-case for the nesting level) rot dup 1 = if 1- then rot rot then
	s" [then]" compare 0= if ( decrease nesting level) 1- then
	dup 0= until
	drop ; immediate

: [if] 0= if postpone [else] then ; immediate

: [then] ; immediate
*/
	/* initialize [if]/[else]/[then] nesting level */
	sf_push(1);
	do
	{
		do_bl(); do_word(); do_count();
		if (!sf_top())
		{
			/* input exhausted, refill input buffer */
			do_drop(); do_drop(); do_refill();
			if (!sf_pop()) { /* 'refill' failed */ /* drop nesting level */ do_drop(); print_str(__func__);
				print_str("(): input exhausted; aborting\n"); do_abort(); }
			continue;
		}

		do_two_to_r();

		do_two_r_fetch();
		//sf_push((cell) "\04[if]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 4) { if (!xmemcmp((void *) sf_pop(), "[if]", 4)) /* increase nesting level */ do_one_plus(); }
		else do_drop();

		do_two_r_fetch();
		//sf_push((cell) "\06[else]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[else]", 6)) /* see if an [if] block should be terminated */ if (sf_top() == 1) do_one_minus(); }
		else do_drop();

		do_two_r_from();
		//sf_push((cell) "\06[then]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[then]", 6)) /* decrease nesting level */ do_one_minus(); }
		else do_drop();
	}
	while (sf_top());
	/* drop nesting level */
	do_drop();

}
コード例 #2
0
ファイル: do_client.c プロジェクト: hanningll/online_dict
int do_client(int sockfd,sqlite3 *pdb)
{
	MSG msg;
	char *p_username,*p_password;

	while(1)
	{
		recv(sockfd,&msg,sizeof(msg),0);

		switch(msg.type)
		{
		case REGISTER:
			p_password = strdup(msg.password);
			p_username = strdup(msg.username);
			
			do_register(sockfd,pdb,p_username,p_password);	
			
			free(p_username);
			free(p_password);
			break;
		
		case LOGIN:
			p_password = strdup(msg.password);
			p_username = strdup(msg.username);
			
			do_login(sockfd,pdb,p_username,p_password);

			free(p_username);
			free(p_password);
			break;

		case WORD:
			do_word(sockfd,pdb,msg.mtext);
			break;

		defalut:
			exit(EXIT_SUCCESS);
		}	
	}

	return 0;
}
コード例 #3
0
/*-----------------------------------------------------------------------------------*/
static u16_t
parse_word(char *data, u8_t dlen)
{
  static u8_t i;
  static u8_t len;
  unsigned char c;

  len = dlen;

  switch(s.minorstate) {
  case MINORSTATE_TEXT:
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(iswhitespace(c)) {
	do_word();
      } else if(c == ISO_lt) {
	s.minorstate = MINORSTATE_TAG;
	s.tagptr = 0;
	/*	do_word();*/
	break;
      } else if(c == ISO_ampersand) {
	s.minorstate = MINORSTATE_EXTCHAR;
	break;
      } else {
	add_char(c);
      }
    }
    break;
  case MINORSTATE_EXTCHAR:
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == ISO_semicolon) {	
	s.minorstate = MINORSTATE_TEXT;
	add_char(' ');
	break;
      } else if(iswhitespace(c)) {	
	s.minorstate = MINORSTATE_TEXT;
	add_char('&');
	add_char(' ');
	break;
      }
    }
    break;
  case MINORSTATE_TAG:
    /* We are currently parsing within the name of a tag. We check
       for the end of a tag (the '>' character) or whitespace (which
       indicates that we should parse a tag attr argument
       instead). */
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == ISO_gt) {
	/* Full tag found. We continue parsing regular text. */
	s.minorstate = MINORSTATE_TEXT;
	s.tagattrptr = s.tagattrparamptr = 0;
	endtagfound();	  
	parse_tag();
	break;
      } else if(iswhitespace(c)) {
	/* The name of the tag found. We continue parsing the tag
	   attr.*/
	s.minorstate = MINORSTATE_TAGATTR;
	s.tagattrptr = 0;
	endtagfound();
	break;
      } else {
	/* Keep track of the name of the tag, but convert it to
	   lower case. */
	  
	s.tag[s.tagptr] = lowercase(c);
	++s.tagptr;
	/* Check if the ->tag field is full. If so, we just eat up
	   any data left in the tag. */
	if(s.tagptr == sizeof(s.tag)) {
	  s.minorstate = MINORSTATE_TAGEND;
	  break;
	}
      }
	
      /* Check for HTML comment, indicated by <!-- */
      if(s.tagptr == 3 &&
	 s.tag[0] == ISO_bang &&
	 s.tag[1] == ISO_dash &&
	 s.tag[2] == ISO_dash) {
	PRINTF(("Starting comment...\n"));
	s.minorstate = MINORSTATE_HTMLCOMMENT;
	s.tagptr = 0;
	endtagfound();
	break;
      }
    }
    break;
  case MINORSTATE_TAGATTR:
    /* We parse the "tag attr", i.e., the "href" in <a
       href="...">. */
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == ISO_gt) {
	/* Full tag found. */
	s.minorstate = MINORSTATE_TEXT;
	s.tagattrparamptr = 0;
	s.tagattrptr = 0;
	endtagfound();
	parse_tag();
	s.tagptr = 0;
	endtagfound();
	break;
      } else if(iswhitespace(c)) {
	if(s.tagattrptr == 0) {
	  /* Discard leading spaces. */
	} else {
	  /* A non-leading space is the end of the attribute. */
	  s.tagattrparamptr = 0;
	  endtagfound();
	  parse_tag();
	  s.minorstate = MINORSTATE_TAGATTRSPACE;
	  break;
	  /*	    s.tagattrptr = 0;
		    endtagfound();*/
	}
      } else if(c == ISO_eq) {	
	s.minorstate = MINORSTATE_TAGATTRPARAMNQ;
	s.tagattrparamptr = 0;
	endtagfound();
	break;
      } else {
	s.tagattr[s.tagattrptr] = lowercase(c);
	++s.tagattrptr;
	/* Check if the "tagattr" field is full. If so, we just eat
	   up any data left in the tag. */
	if(s.tagattrptr == sizeof(s.tagattr)) {
	  s.minorstate = MINORSTATE_TAGEND;
	  break;
	}
      }
    }
    break;
  case MINORSTATE_TAGATTRSPACE:
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(iswhitespace(c)) {
	/* Discard spaces. */
      } else if(c == ISO_eq) {
	s.minorstate = MINORSTATE_TAGATTRPARAMNQ;
	s.tagattrparamptr = 0;
	endtagfound();
	parse_tag();
	break;
      } else {
	s.tagattr[0] = lowercase(c);
	s.tagattrptr = 1;
	s.minorstate = MINORSTATE_TAGATTR;
	break;
      }
    }
    break;
  case MINORSTATE_TAGATTRPARAMNQ:
    /* We are parsing the "tag attr parameter", i.e., the link part
       in <a href="link">. */
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == ISO_gt) {
	/* Full tag found. */
	endtagfound();
	parse_tag();
	s.minorstate = MINORSTATE_TEXT;
	s.tagattrptr = 0;       
	endtagfound();
	parse_tag();
	s.tagptr = 0;       
	endtagfound();
	break;
      } else if(iswhitespace(c) &&
		s.tagattrparamptr == 0) {
	/* Discard leading spaces. */	  
      } else if((c == ISO_citation ||
		 c == ISO_citation2) &&
		s.tagattrparamptr == 0) {
	s.minorstate = MINORSTATE_TAGATTRPARAM;
	s.quotechar = c;
	PRINTF(("tag attr param q found\n"));
	break;
      } else if(iswhitespace(c)) {
	PRINTF(("Non-leading space found at %d\n",
		s.tagattrparamptr));
	/* Stop parsing if a non-leading space was found */
	endtagfound();
	parse_tag();
	  
	s.minorstate = MINORSTATE_TAGATTR;
	s.tagattrptr = 0;
	endtagfound();
	break;
      } else {
	s.tagattrparam[s.tagattrparamptr] = c;
	++s.tagattrparamptr;
	/* Check if the "tagattr" field is full. If so, we just eat
	   up any data left in the tag. */
	if(s.tagattrparamptr >= sizeof(s.tagattrparam) - 1) {
	  s.minorstate = MINORSTATE_TAGEND;
	  break;
	}
      }
    }
    break;
  case MINORSTATE_TAGATTRPARAM:
    /* We are parsing the "tag attr parameter", i.e., the link
       part in <a href="link">. */
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == s.quotechar) {
	/* Found end of tag attr parameter. */
	endtagfound();
	parse_tag();
	  
	s.minorstate = MINORSTATE_TAGATTR;
	s.tagattrptr = 0;
	endtagfound();
	break;
      } else {
	if(iswhitespace(c)) {
	  s.tagattrparam[s.tagattrparamptr] = ISO_space;
	} else {
	  s.tagattrparam[s.tagattrparamptr] = c;
	}
	  
	++s.tagattrparamptr;
	/* Check if the "tagattr" field is full. If so, we just eat
	   up any data left in the tag. */
	if(s.tagattrparamptr >= sizeof(s.tagattrparam) - 1) {
	  s.minorstate = MINORSTATE_TAGEND;
	  break;
	}
      }
    }
    break;
  case MINORSTATE_HTMLCOMMENT:
    for(i = 0; i < len; ++i) {
      c = data[i];
      if(c == ISO_dash) {
	++s.tagptr;
      } else if(c == ISO_gt && s.tagptr > 0) {
	PRINTF(("Comment done.\n"));
	s.minorstate = MINORSTATE_TEXT;
	break;
      } else {
	s.tagptr = 0;
      }
    }
    break;
  case MINORSTATE_TAGEND:
    /* Discard characters until a '>' is seen. */
    for(i = 0; i < len; ++i) {
      if(data[i] == ISO_gt) {
	s.minorstate = MINORSTATE_TEXT;
	s.tagattrptr = 0;
	endtagfound();
	parse_tag();
	break;
      }
    }
    break;
  default:
    i = 0;
    break;
  }
  if(i >= len) {
    return len;
  }
  return i + 1;
}
コード例 #4
0
/*-----------------------------------------------------------------------------------*/
static void
parse_tag(void)
{
  static char *tagattrparam;
  static unsigned char size;

  static char dummy;
  
  PRINTF(("Parsing tag '%s' '%s' '%s'\n",
	  s.tag, s.tagattr, s.tagattrparam));

  switch(find_tag(s.tag)) {
  case TAG_P:
  case TAG_H1:
  case TAG_H2:
  case TAG_H3:
  case TAG_H4:
    /*    parse_char(ISO_nl);*/
    newline();
    /* FALLTHROUGH */
  case TAG_BR:
  case TAG_TR:
  case TAG_SLASHH:
    /*    parse_char(ISO_nl);*/
    dummy = 0;
    newline();
    break;
  case TAG_LI:
    newline();
    add_char(ISO_asterisk);
    add_char(ISO_space);
    break;
  case TAG_SCRIPT:
  case TAG_STYLE:
  case TAG_SELECT:
    switch_majorstate(MAJORSTATE_DISCARD);
    break;
  case TAG_SLASHSCRIPT:
  case TAG_SLASHSTYLE:
  case TAG_SLASHSELECT:
    do_word();
    switch_majorstate(s.lastmajorstate);
    break;
  case TAG_BODY:
    s.majorstate = s.lastmajorstate = MAJORSTATE_BODY;
    break;
  case TAG_FRAME:
    if(strncmp(s.tagattr, html_src, sizeof(html_src)) == 0 &&
       s.tagattrparam[0] != 0) {
      switch_majorstate(MAJORSTATE_BODY);
      newline();
      add_char(ISO_rbrack);
      do_word();
      htmlparser_link((char *)html_frame, (unsigned char)strlen(html_frame), s.tagattrparam);
      PRINTF(("Frame [%s]\n", s.tagattrparam));
      add_char(ISO_lbrack);
      newline();
    }
    break;
  case TAG_IMG:
    if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 &&
       s.tagattrparam[0] != 0) {
      /*      parse_char(ISO_lt);*/
      add_char(ISO_lt);
      tagattrparam = &s.tagattrparam[0];
      while(*tagattrparam) {
	/*	parse_char(*tagattrparam);*/
	add_char(*tagattrparam);
	++tagattrparam;
      }
      /*      parse_char(ISO_gt);*/
      add_char(ISO_gt);
      do_word();
    }
    break;
  case TAG_A:
    PRINTF(("A %s %s\n", s.tagattr, s.tagattrparam));
    if(strncmp(s.tagattr, html_href, sizeof(html_href)) == 0 &&
       s.tagattrparam[0] != 0) {
      strcpy(s.linkurl, s.tagattrparam);
      do_word();
      switch_majorstate(MAJORSTATE_LINK);
    }
    break;
  case TAG_SLASHA:
    if(s.majorstate == MAJORSTATE_LINK) {
      switch_majorstate(s.lastmajorstate);
      s.word[s.wordlen] = 0;
      htmlparser_link(s.word, s.wordlen, s.linkurl);
      s.wordlen = 0;
    }
    break;
#if WWW_CONF_FORMS
  case TAG_FORM:
    PRINTF(("Form tag\n"));
    switch_majorstate(MAJORSTATE_FORM);
    if(strncmp(s.tagattr, html_action, sizeof(html_action)) == 0) {
      PRINTF(("Form action '%s'\n", s.tagattrparam));
      strncpy(s.formaction, s.tagattrparam, WWW_CONF_MAX_FORMACTIONLEN - 1);
    } else if(strncmp(s.tagattr, html_name, sizeof(html_name)) == 0) {
      PRINTF(("Form name '%s'\n", s.tagattrparam));
      strncpy(s.formname, s.tagattrparam, WWW_CONF_MAX_FORMNAMELEN - 1);
    }
    s.inputname[0] = s.inputvalue[0] = 0;
    break;
  case TAG_SLASHFORM:
    switch_majorstate(MAJORSTATE_BODY);
    s.formaction[0] = s.formname[0] = 0;
    break;
  case TAG_INPUT:
    if(s.majorstate == MAJORSTATE_FORM) {
      /* First check if we are called at the end of an input tag. If
	 so, we should render the input widget. */
      if(s.tagattr[0] == 0 &&
	 s.inputname[0] != 0) {
	PRINTF(("Render input type %d\n", s.inputtype));
	switch(s.inputtype) {
	case HTMLPARSER_INPUTTYPE_NONE:
	case HTMLPARSER_INPUTTYPE_TEXT:
	  s.inputvalue[s.inputvaluesize] = 0;
	  htmlparser_inputfield(s.inputvaluesize, s.inputvalue, s.inputname,
				s.formname, s.formaction);
	  break;
	case HTMLPARSER_INPUTTYPE_SUBMIT:
	case HTMLPARSER_INPUTTYPE_IMAGE:
	  htmlparser_submitbutton(s.inputvalue, s.inputname,
				  s.formname, s.formaction);
	  break;
	}
	s.inputtype = HTMLPARSER_INPUTTYPE_NONE;
      } else {
	PRINTF(("Input '%s' '%s'\n", s.tagattr, s.tagattrparam));
	if(strncmp(s.tagattr, html_type, sizeof(html_type)) == 0) {
	  if(strncmp(s.tagattrparam, html_submit,
		     sizeof(html_submit)) == 0) {
	    s.inputtype = HTMLPARSER_INPUTTYPE_SUBMIT;
	  } else if(strncmp(s.tagattrparam, html_image,
			    sizeof(html_image)) == 0) {
	    s.inputtype = HTMLPARSER_INPUTTYPE_IMAGE;
	  } else if(strncmp(s.tagattrparam, html_text,
			    sizeof(html_text)) == 0) {
	    s.inputtype = HTMLPARSER_INPUTTYPE_TEXT;
	  } else {
	    s.inputtype = HTMLPARSER_INPUTTYPE_OTHER;
	  }
	} else if(strncmp(s.tagattr, html_name,
			  sizeof(html_name)) == 0) {
	  strncpy(s.inputname, s.tagattrparam,
		  WWW_CONF_MAX_INPUTNAMELEN);
	} else if(strncmp(s.tagattr, html_alt,
			  sizeof(html_alt)) == 0 &&
		  s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) {	  
	  strncpy(s.inputvalue, s.tagattrparam,
		  WWW_CONF_MAX_INPUTVALUELEN);	  
	} else if(strncmp(s.tagattr, html_value,
			  sizeof(html_value)) == 0) {
	  strncpy(s.inputvalue, s.tagattrparam,
		  WWW_CONF_MAX_INPUTVALUELEN);
	} else if(strncmp(s.tagattr, html_size,
			  sizeof(html_size)) == 0) {
	  size = 0;
	  if(s.tagattrparam[0] >= '0' &&
	     s.tagattrparam[0] <= '9') {
	    size = s.tagattrparam[0] - '0';
	    if(s.tagattrparam[1] >= '0' &&
	       s.tagattrparam[1] <= '9') {
	      size = size * 10 + (s.tagattrparam[1] - '0');
	    }
	  }
	  if(size >= WWW_CONF_MAX_INPUTVALUELEN) {
	    size = WWW_CONF_MAX_INPUTVALUELEN - 1;
	  }
	  s.inputvaluesize = size;
	  /*	  strncpy(s.inputvalue, s.tagattrparam,
		  WWW_CONF_MAX_INPUTVALUELEN);*/
	}
      }
      
    }
    break;
#endif /* WWW_CONF_FORMS */    
#if WWW_CONF_RENDERSTATE
  case TAG_CENTER:
    /*    parse_char(ISO_nl);    */
    newline();
    htmlparser_renderstate(HTMLPARSER_RENDERSTATE_BEGIN |
			   HTMLPARSER_RENDERSTATE_CENTER);
    break;
  case TAG_SLASHCENTER:
    /*    parse_char(ISO_nl);*/
    newline();
    htmlparser_renderstate(HTMLPARSER_RENDERSTATE_END |
			   HTMLPARSER_RENDERSTATE_CENTER);
    break;
#endif /* WWW_CONF_RENDERSTATE */
  }
}
コード例 #5
0
/*-----------------------------------------------------------------------------------*/
static void
newline(void)
{
  do_word();
  htmlparser_newline();
}
コード例 #6
0
static void do_bracket_defined(void)
{
	/*: [defined] bl word find swap drop 0<> ; immediate */
	do_bl(); do_word(); do_find(); do_swap(); do_drop(); do_zero_not_equals();
}