int
example_main(int argc, char **argv)
{
    int rc = EXIT_FAILURE;
    db_t hdb;

    if( 2 < argc && 0 == strncmp( "-h", argv[1], 2 ) ) {
        fprintf( stdout,
                 "Usage:\n"
                 "    %s <messageid> <locale>\n"
                 "Parameters:\n"
                 "    messageid - Integer in range [1-%d]. '1' by default\n"
                 "    locale    - One of en, jp, fr, es, ru. 'ru' by default\n"
                 "",
                 argv[0], DB_ARRAY_DIM(texts)
                 );
    }

    hdb = create_database( EXAMPLE_DATABASE, &db_schema );

    if( hdb != NULL ) {
        rc = load_data( hdb );
        if( 0 == rc ) {
            rc = find_text( hdb, argc > 1 ? argv[1] : "1", argc > 2 ? argv[2] : "ru" );
        }
    }

    db_shutdown(hdb, DB_SOFT_SHUTDOWN, NULL);

    return rc;
}
예제 #2
0
	bool find_element (char * question, char * module_name, PrologElement * head, int element_id) {
		db_element el; el . type = 0;
		if (! find_element (question, element_id, & el)) return false;
		PrologAtom * atom;
		switch (el . type) {
		case 0: head -> setEarth (); return true;
		case 1:
			head -> setPair ();
			find_element (question, module_name, head -> getLeft (), el . reference);
			find_element (question, module_name, head -> getRight (), el . reference_right);
			return true;
		case 2: head -> setVar (el . reference); return true;
		case 3:
			atom = find_or_create_atom (question, el . reference);
			if (atom == NULL) return false;
			head -> setAtom (atom);
			return true;
		case 4: head -> setSlash (); return true;
		case 5: head -> setFail (); return true;
		case 6:
			if (! find_text (question, el . reference)) return false;
			head -> setText (question);
			return true;
		case 7: head -> setHead (NULL); return true;
		case 8: head -> setInteger (el . reference); return true;
		case 9: head -> setDouble (el . value); return true;
		default: return false;
		}
		return true;
	}
예제 #3
0
// Действия при нажатии кнопки Find
void EditorFindDialog::find_clicked(void)
{
 QString text=lineEdit->text();

 QTextDocument::FindFlags flags=0;
 if(mathCase->isChecked())      flags|=QTextDocument::FindCaseSensitively;
 if(wholeWords->isChecked())    flags|=QTextDocument::FindWholeWords;
 if(searchBackward->isChecked())flags|=QTextDocument::FindBackward;

 emit find_text(text, flags);
}
예제 #4
0
파일: edit.c 프로젝트: kotuku-aero/diy-efis
/**
 * Edit a stream
 * @param console_in   stream to read console from
 * @param console_out  stream to write console to
 * @param stream  stream to read/write file to
 */
void muon_edit(handle_t console_in, handle_t console_out, const char *title, handle_t stream)
  {
  int rc;
  int i;

  editor_t *ed = (editor_t *) neutron_malloc(sizeof(editor_t));
  memset(ed, 0, sizeof(editor_t));
  ed->console_in = console_in;
  ed->console_out = console_out;
  ed->title = title;
  ed->anchor = -1;

  rc = load_file(ed, stream);

  get_console_size(ed);

  bool done = false;
  int key;

  ed->refresh = 1;
  while (!done)
    {
    if (ed->refresh)
      {
      draw_screen(ed);
      draw_full_statusline(ed);
      ed->refresh = 0;
      ed->lineupdate = 0;
      }
    else if (ed->lineupdate)
      {
      update_line(ed);
      ed->lineupdate = 0;
      draw_statusline(ed);
      }
    else
      {
      draw_statusline(ed);
      }

    position_cursor(ed);

    key = getkey(ed);

    if (key >= ' ' && key <= 0x7F)
      {
      insert_char(ed, (char) key);
      }
    else
      {
      switch (key)
        {
        case KEY_F1:
          help(ed);
          break;
        case KEY_F5:
          redraw_screen(ed);
          break;
       case KEY_UP:
         up(ed, 0);
          break;
        case KEY_DOWN:
          down(ed, 0);
          break;
        case KEY_LEFT:
          left(ed, 0);
          break;
        case KEY_RIGHT:
          right(ed, 0);
          break;
        case KEY_HOME:
          home(ed, 0);
          break;
        case KEY_END:
          end(ed, 0);
          break;
        case KEY_PGUP:
          pageup(ed, 0);
          break;
        case KEY_PGDN:
          pagedown(ed, 0);
          break;
        case KEY_CTRL_RIGHT:
          wordright(ed, 0);
          break;
        case KEY_CTRL_LEFT:
          wordleft(ed, 0);
          break;
        case KEY_CTRL_HOME:
          top(ed, 0);
          break;
        case KEY_CTRL_END:
          bottom(ed, 0);
          break;
        case KEY_SHIFT_UP:
          up(ed, 1);
          break;
        case KEY_SHIFT_DOWN:
          down(ed, 1);
          break;
        case KEY_SHIFT_LEFT:
          left(ed, 1);
          break;
        case KEY_SHIFT_RIGHT:
          right(ed, 1);
          break;
        case KEY_SHIFT_PGUP:
          pageup(ed, 1);
          break;
        case KEY_SHIFT_PGDN:
          pagedown(ed, 1);
          break;
        case KEY_SHIFT_HOME:
          home(ed, 1);
          break;
        case KEY_SHIFT_END:
          end(ed, 1);
          break;
        case KEY_SHIFT_CTRL_RIGHT:
          wordright(ed, 1);
          break;
        case KEY_SHIFT_CTRL_LEFT:
          wordleft(ed, 1);
          break;
        case KEY_SHIFT_CTRL_HOME:
          top(ed, 1);
          break;
        case KEY_SHIFT_CTRL_END:
          bottom(ed, 1);
          break;
        case ctrl('a'):
          select_all(ed);
          break;
        case ctrl('c'):
          copy_selection(ed);
          break;
        case ctrl('f'):
          find_text(ed, 0);
          break;
        case ctrl('l'):
          goto_line(ed);
          break;
        case ctrl('g'):
          find_text(ed, 1);
          break;
        case KEY_TAB:
          indent(ed, INDENT);
          break;
        case KEY_SHIFT_TAB:
          unindent(ed, INDENT);
          break;
        case KEY_ENTER:
          newline(ed);
          break;
        case KEY_BACKSPACE:
          backspace(ed);
          break;
        case KEY_DEL:
          del(ed);
          break;
        case ctrl('x'):
          cut_selection(ed);
          break;
        case ctrl('z'):
          undo(ed);
          break;
        case ctrl('r'):
          redo(ed);
          break;
        case ctrl('v'):
          paste_selection(ed);
          break;
        case ctrl('s'):
          save_editor(ed);
          break;
        case ctrl('q'):
          done = close_editor(ed);
          break;
        }
      }
    }

  gotoxy(ed, 0, ed->lines + 1);

  outstr(ed, RESET_COLOR CLREOL);

  if (ed->clipboard)
    neutron_free(ed->clipboard);

  if (ed->search)
    neutron_free(ed->search);

  if (ed->linebuf)
    neutron_free(ed->linebuf);

  clear_undo(ed);
  neutron_free(ed);
  }
예제 #5
0
int check_text(Settings *opts, Previous_data *seen) {
  static Key_value_pair *kvp = NULL;
  static size_t sz_kvp = 0;
  static int iolib_bug_warn = 0;

  size_t  n_kvp = 0;
  size_t  i;
  char   *start;
  char   *end = NULL;
  ssize_t remaining;
  int     res;
  char   *fn;

  if (seen->text_sz < 2) {
    printf("Zero-length TEXT chunk found\n");
    return -1;
  }
  if ('\0' != seen->text[0]) {
    printf("check_text given compressed TEXT data\n");
    return -1;
  }
  
  start     = seen->text + 1;
  remaining = seen->text_sz - 1;
  while (remaining > 0 && '\0' != *start) {
    if (n_kvp == sz_kvp) {
      sz_kvp = sz_kvp ? sz_kvp * 2 : 16;
      kvp = srealloc(kvp, sz_kvp * sizeof(*kvp));
    }
    kvp[n_kvp].key = start;
    end = memchr(start, 0, remaining);
    if (NULL == end) break;                    /* Unterminated key */
    remaining -= end - start + 1;
    if (remaining <= 0) { end = NULL; break; } /* Only key, no value */
    kvp[n_kvp].value = end + 1;
    end = memchr(kvp[n_kvp].value, 0, remaining);
    if (NULL == end) break;                    /* Unterminated value */
    remaining -= end - kvp[n_kvp].value + 1;
    n_kvp++;
    if (remaining <= 0) break;            /* Should be at least 1 byte left */
    start = end + 1;
  }
  if (remaining != 1 || '\0' != *start) {
    if (0 != remaining || NULL == end) {
      printf("Error decoding TEXT chunk\n");
      return -1;
    } else {
      /* Ignore bug in io_lib up to 1.12.1 */
      if (!iolib_bug_warn) {
	printf("\nWarning: Your version of io_lib doesn't include the final\n"
	       "NULL byte to indicate the end of a TEXT chunk.  This means\n"
	       "it strictly breaks the ZTR specification.  It'sbeen like\n"
	       "that for a long time though, and it isn't too serious so\n"
	       "we'll let it go for now.\n\n");
	iolib_bug_warn = 1;
      }
    }
  }

  qsort(kvp, n_kvp, sizeof(*kvp), key_compare);

  /* Look for repeat entries */
  for (i = 1; i < n_kvp; i++) {
    if (0 == strcmp(kvp[i - 1].key, kvp[i].key)) {
      printf("Duplicate identifier found in TEXT chunk\n");
      return -1;
    }
  }

  res  = check_file(opts, "config.xml",
		    find_text(kvp, n_kvp, "ILLUMINA_GA_BUSTARD_CONFIG"));
  res += check_file(opts, "../config.xml",
		    find_text(kvp, n_kvp, "ILLUMINA_GA_FIRECREST_CONFIG"));
  res += check_file(opts, "BustardSummary.xml",
		    find_text(kvp, n_kvp, "ILLUMINA_GA_BUSTARD_SUMMARY"));
  res += check_file(opts,
		    find_text(kvp, n_kvp, "ILLUMINA_GA_MATRIX_FWD_FILENAME"),
		    find_text(kvp, n_kvp, "ILLUMINA_GA_MATRIX_FWD"));
  res += check_file(opts,
		    find_text(kvp, n_kvp, "ILLUMINA_GA_PHASING_FWD_FILENAME"),
		    find_text(kvp, n_kvp, "ILLUMINA_GA_PHASING_FWD"));
  if (NULL != (fn = find_text(kvp, n_kvp, "ILLUMINA_GA_MATRIX_REV_FILENAME"))){
    res += check_file(opts, fn,
		      find_text(kvp, n_kvp, "ILLUMINA_GA_MATRIX_REV"));
  }
  if (NULL != (fn = find_text(kvp, n_kvp,"ILLUMINA_GA_PHASING_REV_FILENAME"))){
    res += check_file(opts, fn,
		      find_text(kvp, n_kvp, "ILLUMINA_GA_PHASING_REV"));
  }

  return res;
}
예제 #6
0
int
io_list(field_t *f)
{
 int c = 0, i = -1, y = -1, max_x = 0, max_y = 0, top = 0, bot = 0;
 int index = 0, offset = 0, size = 0, j = 0, first = 1, k = 0;
 int n = 0, rows = 0, find_index = 0, value_count = 0, increase = 0;
 char *s = NULL, *p = NULL, s_v[2] = {'\0', '\0'};
 size_t *on = NULL;

 s_v[0] = value_separator;
 if ( BOOLEAN_T != f->type ) {
     if ( NULL == f->list ) {
         return (0);
     } else if ( access(f->list, X_OK) < 0 ) {
         return (-1);
     }
 }
 if ( ((BOOLEAN_T == f->type ) || (f->list)) && (0 == f->constant) ) { 
     if ( (list(f) < 0) || (0 == S_count) ) {
         return (0);  /*  XXX  */
     } else {
         if ( NULL == (on = calloc(S_count, sizeof(size_t))) ) {
             return (0); /*  XXX  */
         }
         for (;;) {
             getmaxyx(stdscr, max_y, max_x);
             if ( (max_y < MIN_Y) || (max_x < MIN_X) ) {
                 return (0);
             } else {
                 clear(); mvprintw(1, 30, "%s", f->label); bot = max_y-5;
                 if ( 1 == f->max_values ) {
                     top = 5;
                     mvaddstr(3,2,
                               "Move cursor to desired item and press Enter.");
                 } else {
                     top = 7;
                     mvaddstr(top-4, 2,
                                  "Move cursor to desired item and press F7.");
                     mvaddstr(top-3, 6, "ONE OR MORE items can be selected.");
                     mvaddstr(top-2, 2,
                                   "Press Enter AFTER making all selections.");
                 }
                 if ( S_count > max_y-12 ) {
                     top++; bot--;
                 }
             }
             LIST_LEGEND;
             if ( 1 == f->max_values ) {
                 rows = max_y-12;
             } else {
                 rows = max_y-14;
             }
             for (;;) {
                 for ( i = offset, y = top; i < S_count && y < bot; i++, y++) {
                     mvaddch(y, 2, on[i] ? '>' : ' ');
                     mvaddnstr(y, 4, S[i], max_x-6); clrtoeol();
                 }
                 attron(A_STANDOUT);
                 mvaddnstr(top+(index-offset), 4, S[index], max_x-6);
                 attroff(A_STANDOUT);
                 if ( S_count > max_y-12 ) {
                     if ( offset ) {
                         mvprintw(top-1, 2, "[MORE...%d]", offset); clrtoeol();
                     } else {
                         mvaddstr(top-1, 2, "[TOP]"); clrtoeol();
                     }
                     if ( S_count > offset+(bot-top) ) {
                         mvprintw(max_y-6, 2, "[MORE...%d]",
                                                   S_count-(offset+(bot-top)));
                         clrtoeol();
                     } else {
                         mvaddstr(max_y-6, 2, "[BOTTOM]"); clrtoeol();
                     }
                 }
                 (void)border('|', '|', '-', '-', '+', '+', '+', '+');
                 c = get_key(top+(index-offset), 3);
                 if ( KEY_DOWN == c ) {
                     if ( index < S_count-1 ) {
                         index++;
                         if ( (index-offset) > (bot-top-1) ) {
                             offset++;
                         }
                     }
                 } else if ( KEY_UP == c ) {
                     if ( index ) {
                         if ( index == offset ) {
                             offset--;
                         }
                         index--;
                     }
                 } else if ( KEY_PPAGE == c ) {
                     if ( offset > 0 ) {
                         if ( offset > rows ) {
                             offset -= rows; index -= rows;
                         } else {
                             index -= offset; offset = 0;
                         }
                     } else {
                         index = 0;
                     }
                 } else if ( KEY_NPAGE == c ) {
                     if ( offset < S_count-rows ) {
                         if ( offset < S_count-2*rows ) {
                             offset += rows; index += rows;
                         } else {
                             index  += S_count-offset-rows;
                             offset += S_count-offset-rows;
                         }
                     } else {
                         index = S_count-1;
                     } 
                 } else if ( (KEY_F(1) == c) || (KEY_F(10) == c)  ) {
                     return (c);
                 } else if ( KEY_F(3) == c ) {
                     return (KEY_F(2));
                 } else if ( (KEY_F(7) == c) || (' ' == c) ) {
                     if ( f->max_values > 1 ) {
                         if ( on[index] ) {
                             size -= on[index]; on[index] = 0; value_count--;
                         } else if ( value_count < f->max_values ) {
                             increase = strlen(S[index]);
                             if ( value_count ) {
                                 increase+=1;
                             }
                             if ( size+increase < f->width ) {
                                 on[index] = increase; value_count++;
                                 size+=increase;
                             }
                         } /*  XXX else ERROR  */
                     }
                 } else if ( KEY_F(8) == c ) {
                     if ( (KEY_F(1) == (k = image())) || (KEY_F(10) == k)  ) {
                         return (k);
                     } else if ( KEY_F(2) == k ) {
                         refresh();
                     }
                 } else if ( '/' == c ) {
                     find_index = find_text(index);
                     if ( FIND_CANCEL == find_index ) {
                         find_index = 0;  /*  No-op.  */
                     } else if ( FIND_EXIT == find_index ) {
                         free(srch_txt); srch_txt = NULL;
                         return ( KEY_F(10) );
                     } else if ( find_index > offset+rows-1 ) {
                         /* Forward find off page. */
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         /* Backward find off page. */
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                     LIST_LEGEND;
                 } else if ( 'n' == c ) {
                     find_index = find_next(index);
                     if ( find_index > offset+rows-1 ) {
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                 } else if ( (KEY_ENTER == c) || ('\r' == c) || ('\n' == c) ) {
                     if ( 1 == f->max_values ) {
                         for ( k = 0; k < S_count; k++ ) {
                             on[k] = 0;
                         }
                         on[index] = 1;
                     }
                     f->buf[0] = '\0';
                     for ( j = 0; j < S_count; j++ ) {
                         if ( on[j] ) {
                             if ( !first ) {
                                 strcat(f->buf, s_v);
                             }
                             strcat(f->buf, S[j]); first = 0;
                         }
                     }
                     for ( k = 0; k < S_count; k++ ) {
                         free(S[k]); S[k] = NULL;
                     }
                     free(S); S = NULL; free(on); S_count = 0; return (0);
                 }
             }
         }
     }
 }
 return (0);
}
예제 #7
0
파일: Ex.cpp 프로젝트: RamessesYin/SE1_1
int main()
{
	cout << "以下实验是规定了Document的值,测试时可以自行改变其值与测试内容" << endl;
	char b1[5] = { 'i', '9', '5', ',', 's' };
	Line a1 (b1, b1 + 5);
	char b2[7] = { ' ', 'c', 'r', 'l', ' ','c','o' };
	Line a2(b2,b2+7);
	char b3[6] = { '8','w', ' ', 'l', '*', 'l'};
	Line a3(b3, b3 + 6);
	list<Line>answer;
	answer.push_back(a1);
	answer.push_back(a2);
	answer.push_back(a3);
	Document my_doc(answer);
	Document tmp = my_doc;
	cout << "原来文件为:" << endl;
	print(tmp);
	cout << endl;
	cout << "文件的字符数为:" << number(tmp) << endl;
	cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl;
	cout << "其中字母序列(第二种算法):" << number2(tmp)<<endl;
	const string  pre= "i7";
	cout << "查找单词为:" << pre<<endl;

	Text_iterator p = find_text(tmp, pre);
	if (p==tmp.end() )
	{
		cout << "不存在该单词" << endl;
	}
	else
	{			
		cout << "存在该单词" << endl;
		int length = pre.length();
		string  now = "wa56 ker";
		cout << "替换为:" << now << endl;
		cout << "替换后的文件为:" << endl;	
		p.change(length, now);
		print(tmp);
		cout << endl;
		cout << "文件的字符数为:" << number(tmp) << endl;
		cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl;
		cout << "其中字母序列(第二种算法):" << number2(tmp) << endl;
	
	}
	

	tmp = my_doc;
	string  pres = "crl";
	cout << "查找单词为:" << pres << endl;

	Text_iterator s = find_text(tmp, pres);
	if (s == tmp.end())
	{
		cout << "不存在该单词" << endl;
	}
	else
	{
		cout << "存在该单词" << endl;
	    int  length = pres.length();
		string  now = "wa56 er";	
		cout << "替换为:" << now << endl;
		cout << "替换后的文件为:" << endl;	
		s.change(length, now);
		print(tmp);
		cout << endl;
		cout << "文件的字符数为:" << number(tmp) << endl;
		cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl;
		cout << "其中字母序列(第二种算法):" << number2(tmp) << endl;

	}
	getchar();
	getchar();
	getchar();
}
예제 #8
0
void  GetToken( Lexer* lexer, Token* token )
{
    const char* text = lexer->text;
    int pos = lexer->pos;
    token->type = TOKEN_NORMAL;

    while( isspace(text[pos])) pos++;
    token->start = pos;

    switch( text[pos] )
    {
    case '/': pos++;
              switch( text[pos] )
              {
              case '/': /* end-line comment */
                  token->type = TOKEN_COMMENT;
                  ++pos; while( text[pos] != '\n' && text[pos] != '\0' ) pos++;
                  break;
              case '*':
                  token->type = TOKEN_COMMENT;
                  ++pos;
                  while( text[pos] != '\0' )
                  {
                      if( text[pos] == '*' && text[pos+1] == '/')
                      {
                          pos += 2;
                          break;
                      }
                      pos++;
                  }
                  break;
              }
              break;
    case '\0':  token->type = TOKEN_END;
                return;

    case '\"':  token->type = TOKEN_STRING;
                pos++;
                for(;;)
                {
                    if( text[pos] == '\0' || text[pos] == '\"' || text[pos] == '\n' )
                        break;
                    if( text[pos] == '\\' )
                    {
                        pos += 2;
                        if( text[pos] == '\n' ) pos++;
                    }
                    else
                    {
                        pos++;
                    }
                }
                if( text[pos] == '\"') pos++;
                break;

    case '\'':  token->type = TOKEN_STRING;
                pos++;
                for(;;)
                {
                    if( text[pos] == '\0' || text[pos] == '\'' || text[pos] == '\n' )
                        break;
                    pos += text[pos] == '\\' ? 2 : 1;
                }
                if( text[pos] == '\'') pos++;
                break;
    default:
        if( isalpha( text[pos] ) || text[pos] == '_' )
        {
            pos++;
            while( isalnum( text[pos] ) || text[pos] == '_' ) pos++;

            if( find_text( text + token->start, pos - token->start ))
            {
                token->type = TOKEN_KEYWORD;
            }
        }
        else if( isdigit(text[pos]) || (text[pos] == '.' && isdigit(text[pos+1])))
        {
            int pos1 = pos;
            token->type = TOKEN_NUMBER;
            pos++; while( isalnum( text[pos])) pos++;
            if( (text[pos] == '+' || text[pos] == '-') && text[pos-1] == 'e')
            {
                while( isdigit(text[pos1]) || text[pos1] == '.') pos1++;
                if( pos1 == pos - 1 )
                {
                    pos++;
                    while( isdigit(text[pos])) pos++;
                }
            }
        }
        else
        {
            pos++;
        }
    }

    lexer->pos = pos;
}