Esempio n. 1
0
instruction_ptr Parser::parse_instruction()
{
    if (!ErrorHandler::is_ok())
        return instruction_ptr();
    
    
    save();
    instruction_ptr result = parse_assignment();
    
    if (!result)
    {
        restore();
        result = parse_expression();
    }
    
    if (!result)
        result = parse_if_block();
    
    if (!result)
        result = parse_while_block();
    
    if (!result)
        result = parse_return();
    
    if (!result)
        result = parse_print();
    
    if (!result)
        result = parse_read();
    
    if (result)
        next_line();
    
    return result;
}
Esempio n. 2
0
void parse(u8 *string)
{
	u16 wordNumber;
	u8 *wordString;	// the string data of the word

	memset(word_string, 0, sizeof(word_string));
	memset(word_num, 0, sizeof(word_num));

	parse_read(string);
	word_total = 0;
	strPtr = parse_string;
	
	while ((*strPtr != 0) && (word_total < WORD_BUF_SIZE))
	{
		wordString = strPtr;
		wordNumber = word_find();
	
		if (wordNumber == 0xFFFF)	// bad
		{
			word_string[word_total] = strPtr;
			state.var[V09_BADWORD] = word_total + 1;	// bad word
			word_total++;
			assert(word_total > 0); // we need flag 2 set
			break;
		}

		if (wordNumber != WORD_IGNORE)	// good
		{
			word_num[word_total] = wordNumber;
			word_string[word_total] = wordString;
			word_total++;
		}
		// if WORD_IGNORE then skip it
	}
	
	if (word_total > 0)
		flag_set(F02_PLAYERCMD);
}
Esempio n. 3
0
static int		cache_fd(const int fd, char **buf, char **tab, char **line)
{
	int		ret;
	int		i;
	char	*temp;
	char	*temp2;

	i = 0;
	ret = 1;
	temp = line[0];
	temp2 = NULL;
	if ((ret = check_tab(&tab[fd], line, buf)) != 3)
		return (ret);
	else
	{
		if ((ret = read(fd, buf[0], BUFF_SIZE)) != 0)
		{
			if (ret < 0)
				return (ret);
			return (parse_read(&tab[fd], buf, line, NULL));
		}
	}
	return (ft_strlen(*line) == 0 ? 0 : 1);
}
Esempio n. 4
0
uint16_t handle_StreamsCommand(TCF_Command* command, char* buf) {
	TCF_Streams_Command streams_cmd;

	/* Start building return message */
	start_tcf_field(buf, (char *)TCF_S_R); /* Start */
	append_tcf_field(buf, command->token);  /* Token */

	if (strcmp(command->commandName, Streams_Read) == 0) {
		/* C • <token> • Streams • read • <string: stream ID> • <int: size> • */
		/* R • <token> • <string: data> • <error report> • <int: lost size> • <boolean: EOS> */
		if(parse_read(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}

		/* Add data field */
		mystrcat(buf, JSON_Stringify);
		int len = TCF_TTY_ReadString(tmp_stream, 199);
        if(len >= 200){
            return 0;
        }
		tmp_stream[len] = '\0'; /* Terminate to be sure */
		mystrcat(buf, tmp_stream);
		mystrcat(buf, JSON_Stringify);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);

		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);

		//mystrcat(buf, Streams_LostSize);
		ultoa(0,tmp_stream,10);
		mystrcat(buf,tmp_stream);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);

		//mystrcat(buf, Streams_EOS);
		mystrcat(buf, Streams_false);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	} else if (strcmp(command->commandName, Streams_Write) == 0) {
		/* C • <token> • Streams • write • <string: stream ID> • <int: size> • <string: data> • */
		/* R • <token> • <error report> */
		if(parse_write(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}

		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	} else if (strcmp(command->commandName, Streams_Subscribe) == 0) {
		/* R • <token> • <error report> */
		if(parse_id(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}
		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	}else if (strcmp(command->commandName, Streams_Unsubscribe) == 0) {
		/* R • <token> • <error report> */
		if(parse_id(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}
		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	}else if (strcmp(command->commandName, Streams_Connect) == 0) {
		/* R • <token> • <error report> */
		if(parse_id(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}
		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	}else if (strcmp(command->commandName, Streams_Disconnect) == 0) {
		/* R • <token> • <error report> */
		if(parse_id(command->arguments,&streams_cmd,command->args_len) != E_OK){
			return 0;
		}
		/* Add error field */
		mystrcat(buf, JSON_null);
		mystrcat(buf, TCF_S_EOFIELD_MARKER);
	}

	convert_to_tcf_message(buf);
	uint16_t len = message_length(buf, TCF_MAX_FIELD_LENGTH);

	return len;
}
Esempio n. 5
0
int main(int argc, char* argv[])
{
	if (argc != 2) {
		fprintf(stderr, "[-] Error: usage: %s config_file\n", argv[0]);
		return EXIT_FAILURE;
	}

	char* filename = argv[1];

	FILE* fp = fopen(filename, "r");
	if (!fp) {
		fprintf(stderr, "[-] Error: failed to open file %s\n", filename);
		return EXIT_FAILURE;
	}

	/* File buffer */
	char* buffer;
	int nbytes = 128;

	buffer = (char*)malloc(2048*sizeof(char));

	/* Parsing vars */
	int m_size;
	int p_id;
	int p_size;
	int r_page;
	int r_id;
	int w_page;
	int w_id;
	int e_id;

	init_process_table();

	/* Main loop */
	while ((getline(&buffer, (size_t*)&nbytes, fp) != -1)) {

		/* Todas as operações começam com letras diferentes */
		switch(buffer[0]) {
			case 'M': /* MEMSIZE SIZE */
			case 'm':
				parse_memsize(buffer, &m_size);
				printf("[+] MEMSIZE %d\n", m_size);
				memsize(m_size);
				break;

			case 'P': /* PROCSIZE ID SIZE */
			case 'p':
				parse_procsize(buffer, &p_id, &p_size);
				printf("[+] PROCSIZE %d %d\n", p_id, p_size);
				procsize(p_id, p_size);
				break;

			case 'R': /* READ PAGE ID */
			case 'r':
				parse_read(buffer, &r_page, &r_id);
				printf("[+] READ %d %d\n", r_page, r_id);
				read_p(r_page, r_id);
				break;

			case 'W': /* WRITE PAGE ID */
			case 'w':
				parse_write(buffer, &w_page, &w_id);
				printf("[+] WRITE %d %d\n", w_page, w_id);
				write_p(w_page, w_id);
				break;

			case 'E': /* ENDPROC ID */
			case 'e':
				parse_endproc(buffer, &e_id);
				printf("[+] ENDPROC %d\n", e_id);
				endproc(e_id);
				break;

			default:
				printf("[-] Invalid Operation!\n");
		}
	}

	/* Write stats here */
	write_stats();

	fclose(fp);
	return EXIT_SUCCESS;
}
Esempio n. 6
0
void parse_options(int argc, char* argv[]) { // {{{

	int c;
	int digit_optind = 0;

	struct config_t* cfg = config_init(config());

	int _did_reset_discc = 0;

	while (1) {
		int this_option_optind = optind ? optind : 1;
		int option_index = 0;
		static struct option long_options[] = {
			{"0",               no_argument,       0, '0' },
			{"minage",          required_argument, 0, 'm' },
			{"eval",            required_argument, 0, 'e' },
			{"hard-link",       no_argument,       0, 'H' },
			{"symbolic-link",   no_argument,       0, 'L' },
			{"show-merge-0",    required_argument, 0, 'O' },
			{"show-merge",      required_argument, 0, 'o' },
			{"dry-run",         no_argument,       0, 'n' },
			{"nice",            required_argument, 0, 'N' },
			{"ionice",          required_argument, 0, 'i' },
			{"cgroup",          required_argument, 0, 'c' },
			{"verbose",         no_argument,       0, 'v' },
			{"jobs",            required_argument, 0, 'j' },
			{"read",            required_argument, 0, 'R' },
			{"help",            no_argument,       0, '?' },
			{0,                 0,                 0,  0  }
		};

		c = getopt_long(argc, argv, "0m:e:HLO:o:nN:i:c:t:vj:R:h",
				long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case '0':
				path_source_set(&cfg->flags, PATHSOURCE_STDIN0);
				break;

			case 'm':
				cfg->minage = parse_age(optarg);
				break;

			case 'e':
				if (!_did_reset_discc) {
					_did_reset_discc = 1;
					cfg->discriminantc = 0;
				}
				discriminantv_parse(optarg, cfg->discriminantv + cfg->discriminantc++);
				break;

			case 'H':
				link_type_set_hard(cfg->flags);
				break;

			case 'L':
				link_type_set_symb(cfg->flags);
				break;

			case 'O':
				cfg->report_file = strdup(optarg);
				cfg->report_separator = '\0';
				break;

			case 'o':
				cfg->report_file = strdup(optarg);
				cfg->report_separator = '\n';
				break;

			case 'n':
				cfg->flags |= CONFIG_DRYRUN;
				break;

			case 'N':
				if (sscanf(optarg, "%d", &cfg->nice) != 1)
					fatal("Invalid nice level (expecting an positive integer value).\n");

				if (cfg->nice < 0)
					fatal("Only positive integers are allowed in nice value.\n");

				break;

			case 'i':
				cfg->ionice = ionice_parse(optarg);
				break;

			case 'c':
				cfg->cgroups = realloc(cfg->cgroups, ++cfg->cgroupc * sizeof(char*));
				cfg->cgroups[cfg->cgroupc-1] = strdup(optarg);
				break;

			case 'v':
				cfg->verbose++;
				break;

			case 'R':
				parse_read(optarg, &cfg->read_policy, &cfg->bufsize);
				break;

			case '?':
			case 'h':
				help();
				exit(0);

			default:
				fatal("Unknown switch %s\n.", argv[option_index]);
		}
	}

	discriminantv_post_parse(cfg->discriminantv, cfg->discriminantc);

	if (cfg->report_file) {
		if (!strcmp(cfg->report_file, "-"))
			cfg->report_fd = 0;
		else
			cfg->report_fd = open(cfg->report_file, O_CREAT | O_RDWR | O_TRUNC, 0640);

		if (cfg->report_fd < 0)
			fatal("Could not open file %s: %s.\n", cfg->report_file, strerror(errno));
	}

	if (optind < argc) {
		if ((cfg->flags & PATHSOURCE_ARGS) == 0)
			fatal("Extra arguments found.\n");

		while (optind < argc)
			add_path(argv[optind++]);

	} else if ((cfg->flags & PATHSOURCE_STDIN) == 0) {
		path_source_set(&cfg->flags, PATHSOURCE_STDIN);

	}
} // }}}