Ejemplo n.º 1
0
static int read_comment(struct input *input)
{
	char separator[128];
	char *line = input_line(input);
	line = readtoken(separator, line, " \n");
	input_next(input);
	while ((line = input_line(input)) && !startswith(line, separator))
		input_next(input);
	return 0;
}
Ejemplo n.º 2
0
// Reads from cin until EOF. (Or until the ~ character as the first character on
// a line.)
inline std::string OT_CLI_ReadUntilEOF()
{
    std::string result("");

    for (;;) {
        std::string input_line("");
        if (std::getline(std::cin, input_line, '\n')) {
            input_line += "\n";

            if (input_line[0] == '~') // This is our special "break" character
                // for multi-line input.
                break;

            result += input_line;
        }
        else {
            opentxs::otErr << "OT_CLI_ReadUntilEOF: getline() was unable to "
                           "read a string from std::cin\n";
            break;
        }
        if (std::cin.eof() || std::cin.fail() || std::cin.bad()) {
            std::cin.clear();
            break;
        }
    }

    return result;
}
Ejemplo n.º 3
0
static int write_file(struct input *input)
{
	char separator[128];
	char filename[MAXPATHLEN];
	FILE *output;
	char *line = input_line(input);
	nthtoken(separator, line, " \n", 1);
	nthtoken(filename, line, " \n", 3);
	output = fopen(filename, "w");
	input_next(input);
	while ((line = input_line(input))) {
		if (startswith(line, separator))
			break;
		fputs(line, output);
		input_next(input);
	}
	fclose(output);
	return 0;
}
Ejemplo n.º 4
0
Archivo: book.c Proyecto: kou029w/work
// 検索する
void search(){
	char buff[1024];
	char pattern[1024];
	Bookdata *tail;
	Bookdata *matches[1024];
	int count;
	int i;
	
	printf("/");
	input_line(pattern, 1024);
	
	count = 0;
	for(tail = booklist_head; tail != NULL; tail = tail->next){
		if(smatch(pattern, tail->title)
		|smatch(pattern, tail->author)
		|smatch(pattern, tail->publisher)
		|smatch(pattern, tail->note)){
			puts("---");
			matches[count++] = tail;
			show_data(tail);
		}
	}
	
	if(count <= 0) return; // 見つからないので、戻る
	puts("---");
	printf("削除[d] 戻る[x] ");
	input_line(buff, 1024);
	strtolower(buff);
	
	if(strcmp(buff, "d") == 0){
		printf("削除します。よろしいですか? [y/N] ");
		if(select_y('N')){
			for(i=0; i<count; i++){
				delete_data(matches[i]);
			}
		}
		return;
	}else if(strcmp(buff, "x") == 0){
		return;
	}
}
Ejemplo n.º 5
0
static int match_files(struct input *input, FILE *realfile)
{
	char separator[128];
	char line[MAXLINELEN];
	char *expected = input_line(input);

	nthtoken(separator, expected, " \n", 1);
	input_next(input);
	while ((expected = input_line(input))) {
		if (startswith(expected, separator))
			break;
		if (!fgets(line, MAXLINELEN, realfile))
			return 1;
		if (strcmp(expected, line))
			return 1;
		input_next(input);
	}
	if (fgets(line, MAXLINELEN, realfile))
		return 1;
	return 0;
}
Ejemplo n.º 6
0
  int MetaProcessor::process(const char* input_text,
                             StoredValueRef* result /*=0*/,
                             Interpreter::CompilationResult* compRes /*=0*/ ) {
    int expectedIndent = m_InputValidator->getExpectedIndent();
    if (compRes) {
      if (expectedIndent) {
        *compRes = Interpreter::kMoreInputExpected;
      } else {
        *compRes = Interpreter::kSuccess;
      }
    }
    if (!input_text || !input_text[0]) {
      // nullptr / empty string, nothing to do.
      return expectedIndent;
    }
    std::string input_line(input_text);
    if (input_line == "\n") { // just a blank line, nothing to do.
      return expectedIndent;
    }
    //  Check for and handle meta commands.
    m_MetaParser->enterNewInputLine(input_line);
    if (m_MetaParser->isMetaCommand()) {

      if (m_MetaParser->isQuitRequested())
        return -1;

      //TODO: set the compilation result if there was error in the meta commands
      if (result)
        *result = m_MetaParser->getLastResultedValue();
      return expectedIndent;
    }

    // Check if the current statement is now complete. If not, return to
    // prompt for more.
    if (m_InputValidator->validate(input_line) == InputValidator::kIncomplete) {
      if (compRes)
        *compRes = Interpreter::kMoreInputExpected;
      return m_InputValidator->getExpectedIndent();
    }

    //  We have a complete statement, compile and execute it.
    std::string input = m_InputValidator->getInput();
    m_InputValidator->reset();
    Interpreter::CompilationResult compResLocal;
    // if (m_Options.RawInput)
    //   compResLocal = m_Interp.declare(input);
    // else
    compResLocal = m_Interp.process(input, result);
    if (compRes) *compRes = compResLocal;

    return 0;
  }
Ejemplo n.º 7
0
static int read_file(struct input *input)
{
	char filename[MAXPATHLEN];
	FILE *realinput;
	char *line = input_line(input);
	int result;

	nthtoken(filename, line, " \n", 3);
	if (!(realinput = fopen(filename, "r")))
		return 1;
	result = match_files(input, realinput);
	fclose(realinput);
	return result;
}
Ejemplo n.º 8
0
  int MetaProcessor::process(const char* input_text,
                             Interpreter::CompilationResult& compRes,
                             Value* result) {
    if (result)
      *result = Value();
    compRes = Interpreter::kSuccess;
    int expectedIndent = m_InputValidator->getExpectedIndent();

    if (expectedIndent)
      compRes = Interpreter::kMoreInputExpected;
    if (!input_text || !input_text[0]) {
      // nullptr / empty string, nothing to do.
      return expectedIndent;
    }
    std::string input_line(input_text);
    if (input_line == "\n") { // just a blank line, nothing to do.
      return expectedIndent;
    }
    //  Check for and handle meta commands.
    m_MetaParser->enterNewInputLine(input_line);
    MetaSema::ActionResult actionResult = MetaSema::AR_Success;
    if (m_MetaParser->isMetaCommand(actionResult, result)) {

      if (m_MetaParser->isQuitRequested())
        return -1;

      if (actionResult != MetaSema::AR_Success)
        compRes = Interpreter::kFailure;
       // ExpectedIndent might have changed after meta command.
       return m_InputValidator->getExpectedIndent();
    }

    // Check if the current statement is now complete. If not, return to
    // prompt for more.
    if (m_InputValidator->validate(input_line) == InputValidator::kIncomplete) {
      compRes = Interpreter::kMoreInputExpected;
      return m_InputValidator->getExpectedIndent();
    }

    //  We have a complete statement, compile and execute it.
    std::string input = m_InputValidator->getInput();
    m_InputValidator->reset();
    // if (m_Options.RawInput)
    //   compResLocal = m_Interp.declare(input);
    // else
    compRes = m_Interp.process(input, result);

    return 0;
  }
Ejemplo n.º 9
0
static Bool begin_1(Streamer * s){
	InputInfo * info = (InputInfo *) s->info;
	if(info == NULL){
		s->info = malloc(sizeof(InputInfo));
		info = (InputInfo *) s->info;
	}
	puts("Please type a string as the input of the automata.");
	/* cannot input the empty string by the following statement.
	 * scanf("%s", inputString);
	 */
	input_line(info->inputString, INPUT_LINE_LIMIT, "Type a line ending by the Enter/Return key. ");
	info->inputPosition = 0;
	info->beginPosition = 0;
	info->endPosition = strlen(info->inputString); /* endposition is the index of '\0' */
	return TRUE;
}
Ejemplo n.º 10
0
int main(){
	char buff[1024];
	openlist("booklist.csv");
	for(;;){
		printf("追加[a] 検索[s] 終了[q] ");
		input_line(buff, 1024);
		strtolower(buff);
		
		if(strcmp(buff, "a") == 0){
			regist_data();
		}else if(strcmp(buff, "s") == 0){
			search();
		}else if(strcmp(buff, "q") == 0){
			savelist("booklist.csv");
			exit(0);
		}
	}
	return 0;
}
Ejemplo n.º 11
0
/*
 * Get next input command from terminal.
 *
 *   Returns: 1 if got input
 *            0 if timeout
 *           -1 if EOF or error
 */
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
   int len;

   if (!stop) {
      if (output == stdout || teeout) {
         sendit(prompt);
      }
   }

again:
   switch (wait_for_readable_fd(fileno(input), sec, true)) {
   case 0:
      return 0;                    /* timeout */
   case -1:
      return -1;                   /* error */
   default:
      len = sizeof_pool_memory(sock->msg) - 1;
      if (stop) {
         sleep(1);
         goto again;
      }
#ifdef HAVE_CONIO
      if (bisatty(fileno(input))) {
         input_line(sock->msg, len);
         break;
      }
#endif
      if (fgets(sock->msg, len, input) == NULL) {
         return -1;
      }
      break;
   }

   if (usrbrk()) {
      clrbrk();
   }

   strip_trailing_junk(sock->msg);
   sock->msglen = strlen(sock->msg);

   return 1;
}
Ejemplo n.º 12
0
/*
 * Get next input command from terminal.
 *
 *   Returns: 1 if got input
 *           -1 if EOF or error
 */
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
   int len;

   if (!stop) {
      if (output == stdout || teeout) {
         sendit(prompt);
      }
   }

again:
   len = sizeof_pool_memory(sock->msg) - 1;
   if (stop) {
      sleep(1);
      goto again;
   }

#ifdef HAVE_CONIO
   if (bisatty(fileno(input))) {
      input_line(sock->msg, len);
      goto ok_out;
   }
#endif

   if (input == stdin) {
      if (win32_cgets(sock->msg, len) == NULL) {
         return -1;
      }
   } else {
      if (fgets(sock->msg, len, input) == NULL) {
         return -1;
      }
   }

   if (usrbrk()) {
      clrbrk();
   }

   strip_trailing_junk(sock->msg);
   sock->msglen = strlen(sock->msg);

   return 1;
}
Ejemplo n.º 13
0
int handle_word(char buf[], FILE *files[], struct sc_config const *config)
{
    int ret = -1;
    char tmp[strlen(buf)];
    char inp[MAX_WORD_LENGTH];
    trim_word(buf, tmp);
    if (is_number(tmp))
        goto NEXT;
    if (word_exists(files[FILE_DIC], tmp)) {
        fprintf(files[FILE_OUT], "%s", buf);
    } else {
        printf(CLSCRN);
        print_header(config->file[FILE_DOC]);
        print_hr();
        print_preview(files[FILE_DOC], buf);
        print_hr();
        printf("word \"%s\" not found in dict\n", tmp);
        print_progress(files[FILE_DOC]);
        switch (show_menu()) {
        case 'a':
            fprintf(files[FILE_DIC], "%s\n", tmp);
            fprintf(files[FILE_OUT], "%s", tmp);
            break;
        case 's':
            printf("substitute %s: ", buf);
            input_line(inp, sizeof(inp));
            fprintf(files[FILE_OUT], "%s", inp);
            break;
        case 'c':
            fprintf(files[FILE_OUT], "%s", buf);
            break;
        case 'q':
            goto ERROR;
        }
    }

NEXT:
    ret = 0;

ERROR:
    return ret;
}
Ejemplo n.º 14
0
void Input()
{
	char c;
	str password;
	FILE *in=fopen("token.txt","r");
	input_line(in,TOKEN);
	fclose(in);

	in=fopen("data.txt","r");
	N=0;
	while(input_line(in,all[N].url)!=EOF)
	{
		input_line(in,all[N].cn_name);
		input_line(in,all[N].en_name);
		input_line(in,all[N].id);
		input_line(in,all[N].key);
		input_line(in,all[N].more);
		++N;
	}
	fclose(in);
}
Ejemplo n.º 15
0
static int exec_ironout(struct input *input, char *ironout)
{
	char token[128];
	char command[MAXPATHLEN];
	FILE *output;
	char *line = input_line(input);
	int result;
	char *cur = command;

	line = nthtoken(token, line, " \n", 2);
	strcpy(cur, ironout);
	cur += strlen(cur);
	while (*line) {
		line = readtoken(token, line, " \n");
		cur += sprintf(cur, " %s", token);
	}
	if (!(output = popen(command, "r")))
		return 1;
	result = match_files(input, output);
	if (pclose(output))
		return 1;
	return result;
}
Ejemplo n.º 16
0
static int runtest(char *filename, char *ironout)
{
	struct input *input = input_open(filename);
	char current_line[MAXLINELEN];
	char cmd[128];
	char *line;
	if (!input)
		return 1;
	while ((line = input_line(input))) {
		int result = -1;
		strcpy(current_line, line);
		nthtoken(cmd, line, " \n", 2);
		if (!strcmp(cmd, "comment") || !strcmp(cmd, "#") || !*cmd)
			result = read_comment(input);
		if (!strcmp(cmd, "write") || !strcmp(cmd, ">"))
			result = write_file(input);
		if (!strcmp(cmd, "read") || !strcmp(cmd, "<"))
			result = read_file(input);
		if (!strcmp(cmd, "ironout"))
			result = exec_ironout(input, ironout);
		if (result == -1) {
			printf("unknown cmd: %s\n", cmd);
			return 1;
		}
		if (result > 0) {
			char *testname = filename;
			if (strchr(testname, '/'))
				testname = strrchr(testname, '/') + 1;
			printf("%s:%d %s",
			       testname, input->lineno, current_line);
			return 1;
		}
	}
	input_free(input);
	return 0;
}