示例#1
0
	void build(string &s, bool add_dollar = 0) {
		for(int i = 0; i < s.length(); ++i) {
			add_letter(s[i]);
		}
		if (add_dollar) {
			add_letter(dollar);
		}
	}
示例#2
0
文件: task3.c 项目: tridcatov/publicc
text input_text() {
    text result = 0;
    text current;
    char c;
    while ( 1 ) {
        c = getc(stdin);
        if ( c == '\n')
            break;

        if ( result == 0 ) {
            result = (text)malloc(sizeof(word));
            result->first = 0;
            result->prev = 0;
            result->next = 0;
            current = result;
        }

        if ( c != ' ' ) {
            add_letter(current, c);
        } else {
            text newtext = (text)malloc(sizeof(word));
            newtext->first = 0;
            newtext->prev = current;
            current->next = newtext;
            newtext->next = 0;
            current = newtext;
        }
    }
    return result;
}
示例#3
0
static int buff_hdl(uint32_t tid, char* buff,
                    size_t size, char last)
{
    dmsg2("start %s, %d: word %s, count %d, *buff %c\n",
          __FUNCTION__, tid, word, count, *buff);

    for( ; size; size--, buff++)
    {
        if(!IS_A_LETTER(*buff))
        {
            /*Not a letter */
            if(add_sep(tid))
                return -1;
            continue;
        }
        /* A letter */
        if(add_letter(*buff))
            return -1;
    }

    /* If this is the last buffer, end the word (if any)*/
    if(last)
    {
        add_sep(tid);
    }

    dmsg3("end %s, %d: word %s, count %d, *buff %c\n",
          __FUNCTION__, tid, word, count, *buff);

    return 0;
}
示例#4
0
// Draws the character on the search bar and updates the search matcher
void do_key(char key){
	add_letter(key);

	/* Ignore the matcher if the string query length is below the threshhold to provide matchings
	   Update and delete matches when we add letters */
	if(qs_length() < SEARCH_THRESHHOLD){
		draw_information_box("ENTER YOUR SEARCH!");
	}
	if(qs_length() > SEARCH_THRESHHOLD && MN_COUNT > 0){
		del_matches();
	}
	if(qs_length() == SEARCH_THRESHHOLD){
		add_matches();
	}
}
示例#5
0
void
draw_marquee(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	char       *space = (char *) "        ";
	unsigned char       *ch;
	marqueestruct *mp = &marquees[MI_SCREEN(mi)];

	if (marquees == NULL)
		return;
	mp = &marquees[MI_SCREEN(mi)];
	if (mp->gc == None && mode_font != None)
		return;

	MI_IS_DRAWN(mi) = True;
	ch = (unsigned char*) mp->words;
	if (isRibbon()) {
		ch = (unsigned char*) mp->words;
		switch (*ch) {
			case '\0':
				if (add_blanks(mp)) {
					init_marquee(mi);
					return;
				}
				break;
			case '\b':
			case '\r':
			case '\n':
			case '\t':
			case '\v':
			case '\f':
				add_letter(mp, " ");
				mp->words++;
				break;
			default:
				add_letter(mp, (char *) ch);
				mp->words++;
		}
		if (MI_NPIXELS(mi) > 2) {
			XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color));
			if (++mp->color == MI_NPIXELS(mi))
				mp->color = 0;
		} else
			XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi));
		(void) XDrawImageString(display, MI_WINDOW(mi), mp->gc,
			 mp->x, mp->y + mp->ascent, mp->modwords, mp->t + 2);
	} else {
		switch (*ch) {
			case '\0':
				if (++mp->time > 16)
					init_marquee(mi);
				return;
			case '\b':
				if (mp->t) {
					/* see note in text_font_width */
					mp->t--;
					mp->x -= char_width[(int) (' ')];
				}
				break;
			case '\v':
			case '\f':
			case '\n':
				mp->x = mp->startx;
				mp->t = 0;
				mp->y += mp->height;
				if (mp->y + mp->height > mp->win_height) {
					XCopyArea(display, window, window, mp->gc,
						  0, mp->height, mp->win_width, mp->y - mp->height, 0, 0);
					XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi));
					mp->y -= mp->height;
					XFillRectangle(display, window, mp->gc,
					0, mp->y, mp->win_width, mp->height);
				}
				break;
			case '\t':
				(void) XDrawString(display, window, mp->gc, mp->x, mp->y + mp->ascent,
						   space, 8 - (mp->t % 8));
				mp->x += char_width[(int) (' ')] * (8 - (mp->t % 8));
				mp->t = ((mp->t + 8) / 8) * 8;
				break;
			case '\r':
				break;
			default:
				if (MI_NPIXELS(mi) > 2) {
					XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color));
					if (++mp->color == MI_NPIXELS(mi))
						mp->color = 0;
				} else
					XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi));
				if (is_char_back_char((char *) ch)) {
					int         xmid = mp->x + (char_back_char_width((char *) ch) + 1) / 2;

					(void) XDrawString(display, window, mp->gc,
							   xmid - char_width[(int) (const char) *ch] / 2,
						mp->y + mp->ascent, (char *) ch, 1);
					(void) XDrawString(display, window, mp->gc,
							   xmid - char_width[(int) (const char) *(ch + 2)] / 2,
						mp->y + mp->ascent, (char *) ch + 2, 1);
					mp->x += char_back_char_width((char *) ch);
					mp->words += 2;
				} else {
					int mb = charBytes(*ch);

					(void) XDrawString(display, window, mp->gc,
						mp->x, mp->y + mp->ascent, (char *) ch, mb);
					mp->x += charWidth((char *) ch);
				}
				mp->t++;
		}
		mp->words += charBytes(*ch);
	}
}
示例#6
0
Token lex_get_token(void){
  Token ret;
  LexerState state = INITIAL_STATE;
  char token[256];
  int ch;
    
  token[0] = '\0';
  while ((ch = getc(st_source_file)) != EOF){
    switch (state){
    case INITIAL_STATE:
      if(isdigit(ch)){  // 数字?
        add_letter(token, ch);
        state = INT_VALUE_STATE;
      }else if(isalpha(ch) || ch == '_'){ // 英文字? _?
        add_letter(token, ch);
        state = IDENTIFIER_STATE;
      }else if(ch == '\"'){ // 文字列?
        state = STRING_STATE;
      }else if(in_operator(token, ch)){ // 演算子?
        add_letter(token, ch);
        state = OPERATOR_STATE;
      }else if(isspace(ch)){ // 空白?
        if(ch == '\n'){ // 改行?
          st_current_line_number++;
        }
      }else if(ch == '#'){ // コメント?
        state = COMMENT_STATE;
      }else{
        lex_error("bad character", ch); // エラー
      }
      break;
    case INT_VALUE_STATE:
      if (isdigit(ch)) {
        add_letter(token, ch);
      } else {
        ret.kind = INT_VALUE_TOKEN;
        sscanf(token, "%d", &ret.u.int_value);
        ungetc(ch, st_source_file);
        goto LOOP_END;
      }
      break;
    case IDENTIFIER_STATE:
      if(isalpha(ch) || ch == '_' || isdigit(ch)){
        add_letter(token, ch);
      }else{
        ret.u.identifier = token;
        ungetc(ch, st_source_file);
        goto LOOP_END;
      }
      break;
    case STRING_STATE:
      if (ch == '\"') {
        ret.kind = STRING_LITERAL_TOKEN;
        ret.u.string = my_strdup(token);
        goto LOOP_END;
      } else {
        add_letter(token, ch);
      }
      break;
    case OPERATOR_STATE:
      if (in_operator(token, ch)) {
        add_letter(token, ch);
      } else {
        ungetc(ch, st_source_file);
        goto LOOP_END;
      }
      break;
    case COMMENT_STATE:
      if (ch == '\n') {
        state = INITIAL_STATE;
      }
      break;
    default:
      assert(0);
    }
  }
 LOOP_END:
  if (ch == EOF) {
    if (state == INITIAL_STATE
         || state == COMMENT_STATE) {
      ret.kind = END_OF_FILE_TOKEN;
      return ret;
    }
  }
  if (state == IDENTIFIER_STATE) {
    if (!is_keyword(token, &ret.kind)) {
      ret.kind = IDENTIFIER_TOKEN;
      ret.u.string = my_strdup(token);
    }
  } else if (state == OPERATOR_STATE) {
    ret.kind = select_operator(token);
  }
  return ret;
}