Beispiel #1
0
static void make_opcode(char *str)
{
  int i = 0;
  unsigned char *ptr;
  int size;

  size = size_opcode(str);
  opcode_mode.size = size;
  ptr = xmalloc(size * sizeof(char));
  memset(ptr, 0x00, size * sizeof(char));
  while (i != size)
    {
      if (*str != '\\' && *str != 'x')
        {
          fprintf(stderr, "%sSyntax error%s: Bad separator\n", RED, ENDC);
          fprintf(stderr, "              Please respect this syntax: \\xcd\\x80\n");
          exit(EXIT_FAILURE);
        }
      while (*str == '\\' || *str == 'x')
        str++;
      check_char(*str);
      check_char(*(str + 1));
      ptr[i] = strtol(str, NULL, 16);
      i++;
      str += 2;
    }
  opcode_mode.opcode = ptr;
}
Beispiel #2
0
static void test_unstr_strstr_char(void)
{
	char *ret = 0;
	char *ans1 = "4567890";
	char *ans2 = "7890";
	char *s1 = "45";
	char *s2 = "7890";
	char *s3 = "hoge";
	unstr_t *str = unstr_init("1234567890");
	unstr_t *emp = unstr_init_memory(1);
	check_null(unstr_strstr_char(NULL, s1));
	check_null(unstr_strstr_char(NULL, ""));
	check_null(unstr_strstr_char(str, NULL));
	check_null(unstr_strstr_char(emp, NULL));
	check_null(unstr_strstr_char(str, ""));
	check_null(unstr_strstr_char(emp, s1));
	check_null(unstr_strstr_char(str, s3));

	ret = unstr_strstr_char(str, s1);
	check_assert(ret != NULL);
	check_char(ret, ans1);

	ret = unstr_strstr_char(str, s2);
	check_assert(ret != NULL);
	check_char(ret, ans2);

	unstr_delete(2, str, emp);
}
Beispiel #3
0
void Wifi_Init(void) {
	printf("AT+CIPMUX=0\x0d\x0a\n");
	delay_ms(10);
	while (check_char(Char_OK) == 0) delay_ms(5);
	printf("AT+CIPSTART=\"UDP\",\"192.168.1.100\",6789\x0d\x0a");
	delay_ms(10);
	while (check_char(Char_OK) == 0) delay_ms(5);
}
Beispiel #4
0
pstring netlist_parser::getstring()
{
    skipws();
    check_char('"');
    pstring ret = getname2_ext('"', 0, NULL);
    check_char('"');
    skipws();
    return ret;
}
Beispiel #5
0
void fractions_input(struct fractions* current, char error[50]) {
    int current_nom;
    int current_denom;
    
    while(!check_char(&current_nom) || !check_char(&current_denom)){
        printf("%s\n", error);
    }
    current->nominator = current_nom;
    current->denominator = current_denom;
}
Beispiel #6
0
void netlist_parser::netdev_device(const pstring &dev_type)
{
	pstring devname;
	net_device_t_base_factory *f = m_setup.factory().factory_by_name(dev_type, m_setup);
	netlist_device_t *dev;
	nl_util::pstring_list termlist = f->term_param_list();
	pstring def_param = f->def_param();

	int cnt;

	skipws();
	devname = getname2(',', ')');
	dev = f->Create();
	m_setup.register_dev(dev, devname);

	NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr()));

	if (def_param != "")
	{
        pstring paramfq = devname + "." + def_param;
	    NL_VERBOSE_OUT(("Defparam: %s\n", def_param.cstr()));
        check_char(',');
	    skipws();
	    if (peekc() == '"')
	    {
            pstring val = getstring();
            m_setup.register_param(paramfq, val);
	    }
	    else
	    {
	        double val = eval_param();
	        m_setup.register_param(paramfq, val);
	    }
	    if (termlist.count() > 0)
	        check_char(',');
	}

	cnt = 0;
	while (getc() != ')' && cnt < termlist.count())
	{
		skipws();
		pstring output_name = getname2(',', ')');

		m_setup.register_link(devname + "." + termlist[cnt], output_name);

		skipws();
		cnt++;
	}
    if (cnt != termlist.count())
        fatalerror("netlist: input count mismatch for %s - expected %d found %d\n", devname.cstr(), termlist.count(), cnt);
}
Beispiel #7
0
void ccladd (int cclp, int ch)
{
	int     ind, len, newpos, i;

	check_char (ch);

	len = ccllen[cclp];
	ind = cclmap[cclp];

	/* check to see if the character is already in the ccl */

	for (i = 0; i < len; ++i)
		if (ccltbl[ind + i] == ch)
			return;

	/* mark newlines */
	if (ch == nlch)
		ccl_has_nl[cclp] = true;

	newpos = ind + len;

	if (newpos >= current_max_ccl_tbl_size) {
		current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;

		++num_reallocs;

		ccltbl = reallocate_Character_array (ccltbl,
						     current_max_ccl_tbl_size);
	}

	ccllen[cclp] = len + 1;
	ccltbl[newpos] = (unsigned char) ch;
}
Beispiel #8
0
char	*parsMessage(const char *input)
{
  if (check_char(input, (char*)"-/\\") == 0 || input[0] != '-')
    return ((char*)input);
  else
    return ((char*)"-<strong>[Error]: </strong>Wrong message format!");
}
Beispiel #9
0
void netlist_parser::netdev_device(const pstring &dev_type, const pstring &default_param, bool isString)
{
	netlist_device_t *dev;

	skipws();
	pstring devname = getname2(',', ')');
	pstring defparam = devname + "." + default_param;
	dev = m_setup.factory().new_device_by_name(dev_type, m_setup);
	m_setup.register_dev(dev, devname);
	NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr()));
	if (getc() != ')')
	{
		// have a default param
		skipws();
		if (isString)
		{
			pstring val = getname(')');
			ungetc();
			NL_VERBOSE_OUT(("Parser: Default param: %s %s\n", defparam.cstr(), val.cstr()));
			m_setup.register_param(defparam, val);
		}
		else
		{
			double val = eval_param();
			NL_VERBOSE_OUT(("Parser: Default param: %s %f\n", defparam.cstr(), val));
			m_setup.register_param(defparam, val);
		}
	}
	check_char(')');
}
Beispiel #10
0
int			check_tetraminos(char *str)
{
	int	i;

	i = 0;
	i = check_char(str, 0);
	if (i == 1)
	{
		i = 0;
		if (str[0] != '\n' || str[5] != '\n' || str[10] != '\n'
				|| str[15] != '\n' || str[20] != '\n')
		{
			error();
			return (0);
		}
		i = 0;
		i = check_tetra(str, 1);
		if (i == 0)
		{
			error();
			return (-1);
		}
	}
	return (i);
}
/* Using Dynamic Programming, we use a look up table and search for the words on the board.
 * our lookup table, the dictionary, is preprocess before time. This reduces the complexity of the algorithm
 * allowing complexity time of O(N*W), N the length of the array * length of the string!
*/
vector<string> word_search(int w, int h, char (&board)[SIZE][SIZE], vector<string> wl) {
	bool visited[SIZE][SIZE];
	vector<string> found;

	for(unsigned int w = 0; w < wl.size(); w++) { // Traverse the length of the wordlist.
		string str = wl[w]; // Dynamic Programming. Checking the Word in the dictionary rather than compiling words and checking the dictionary.
		for(int y = 0; y < SIZE; y++) { // Height of the board.
			for(int x = 0; x < SIZE; x++) { // Width of the board.
				memset(visited, false, sizeof(visited)); // set (visited)adjacent matrix.

				if(str.at(0) == board[x][y]) { // Optimization, Compares first character to the board. If false, move to the next word.
					visited[x][y] = true; // Set current position to visited. 
					fx = x;
					fy = y;
					for(unsigned int i = 1; i < str.length(); i++) { 
						char * c = &str.at(i);

						/* Checking for the characters in adjacent cells */
						if(!check_char(fx, fy, board, visited, c)) {
							break; // Stop seaching character in the string if if the current character isnt found in the adjacent cells.
						}

						// If all the characters are found then add it to our found array.
						if(i == str.length() - 1) {
							found.push_back(str);
						}
					}
				}
			}
		}
	}

	return found;
}
Beispiel #12
0
void	check_tab(char **tab)
{
  if (check_char(tab) == 1)
    put_err("One character is not * or X");
  if (check_size(tab) == 1)
    put_err("The lab is not a rectangle");
}
Beispiel #13
0
void		shoot_right(t_struct *st)
{
  int		i;

  i = 0;
  if (check_gun(st) == -1)
    return;
  Mix_PlayChannel(2, st->gun, 0);
  while (i < 4)
    {
      st->heros.fl = 1;
      if (check_char(st->tmap[st->heros.y][st->heros.x + 1 + i]) == 1)
	{
	  st->tmap[st->heros.y][st->heros.x + 1 + i] = 'e';
	  fct_ptr(st);
	  SDL_Flip(st->ecran);
	  st->tmap[st->heros.y][st->heros.x + 1 + i] =
	    check_wich_4(st->tab, st->heros.y, st->heros.x + 1 + i, st);
	  fct_ptr(st);
	}
      else
	{
	  check_right_sh(st, i);
	  i = 4;
	}
      i++;
    }
}
Beispiel #14
0
t_tetriminos	*collect_blocks(char *str, int nbtetri)
{
	t_tetriminos	*result;
	int				block_count;
	int				i;

	block_count = 0;
	i = 0;
	if (!(result = (t_tetriminos *)malloc(sizeof(t_tetriminos))))
		return (NULL);
	while (i <= 20 && check_char(i, block_count, str[i]))
	{
		if (str[i] == '#')
		{
			result->blocks[block_count] = (t_block) {.x = i % 5, .y = i / 5};
			block_count = block_count + 1;
		}
		i++;
	}
	result->letter = nbtetri + 'A';
	if (i == 21 && block_count == 4)
		return (result);
	free(result);
	return (NULL);
}
Beispiel #15
0
void netlist_parser::net_model()
{
    // don't do much
    pstring model = getstring();
    m_setup.register_model(model);
    check_char(')');
}
Beispiel #16
0
	bool parser::parse_null(context& ctx, null_type& value, IteratorType& ch, IteratorType end)
	{
		if (check_char(ctx, 'n', ch, end))
		{
			if (check_char(ctx, 'u', ch, end))
			{
				if (check_char(ctx, 'l', ch, end))
				{
					if (check_char(ctx, 'l', ch, end))
					{
						value = null_type();

						return true;
					}
				}
			}
		}

		return false;
	}
Beispiel #17
0
void Wifi_Send(uint8_t length, uint8_t* S) {
	printf("AT+CIPSEND=%d,%d\x0d\x0a", id, length + 1);
	nTIME_OUT = WIFI_IME_OUT_VALUE;
	while (check_char(Char_Send) == 0) {
		if ((nTIME_OUT--) == 0) {
			Wifi_Send_Fail();
			return;
		}
		delay_ms(10);
	}
	printf("%s\n", S);
}
Beispiel #18
0
void Wifi_Send_ACC(float ACC_X, float ACC_Y, float ACC_Z) {
	printf("AT+CIPSEND=%d\x0d\x0a", 19);
	nTIME_OUT = WIFI_IME_OUT_VALUE;
	while (check_char(Char_Send) == 0) {
		if ((nTIME_OUT--) == 0) {
			Wifi_Send_Fail();
			return;
		}
		delay_ms(10);
	}
	printf("%6.2f%6.2f%6.2f\n", ACC_X, ACC_Y, ACC_Z);
}
Beispiel #19
0
void Wifi_Send_ACC_Raw(uint16_t data_X, uint16_t data_Y, uint16_t data_Z) {
	printf("AT+CIPSEND=%d\x0d\x0a", 4);	
	nTIME_OUT = WIFI_IME_OUT_VALUE;
	while (check_char(Char_Send) == 0) {
		if ((nTIME_OUT--) == 0) {
			Wifi_Send_Fail();
			return;
		}
		delay_ms(10);
	}
	printf("%c%c%c\n", (uint8_t)(data_X >> 8), (uint8_t)(data_Y >> 8), (uint8_t)(data_Z >> 8));
}
Beispiel #20
0
void netlist_parser::netdev_param()
{
	pstring param;
	double val;
	skipws();
	param = getname(',');
	skipws();
	val = eval_param();
	NL_VERBOSE_OUT(("Parser: Param: %s %f\n", param.cstr(), val));
	m_setup.register_param(param, val);
	check_char(')');
}
Beispiel #21
0
void getInput()
{
	char buffer[BUF_SZ];
	int n;
	
	my_str(PROMPT);
	
	while(1)
	{
		n = read(0, buffer, BUF_SZ - 1);
		check_char(buffer);
	}
}
Beispiel #22
0
 inline mask(const char * s)
 {
     char * it = m_array;
     char * const last = m_array + static_size;
     for ( ; it != last && *s != '\0' ; ++it, ++s )
     {
         char c = *s;
         check_char(c);
         *it = c;
     }
     if ( it != last )
     {
         ::memset(it, '*', last - it);
     }
 }
Beispiel #23
0
	bool parser::parse_boolean(context& ctx, boolean_type& value, IteratorType& ch, IteratorType end)
	{
		if (check_char(ctx, 't', ch, end))
		{
			if (check_char(ctx, 'r', ch, end))
			{
				if (check_char(ctx, 'u', ch, end))
				{
					if (check_char(ctx, 'e', ch, end))
					{
						value = true;

						return true;
					}
				}
			}
		}

		if (check_char(ctx, 'f', ch, end))
		{
			if (check_char(ctx, 'a', ch, end))
			{
				if (check_char(ctx, 'l', ch, end))
				{
					if (check_char(ctx, 's', ch, end))
					{
						if (check_char(ctx, 'e', ch, end))
						{
							value = false;

							return true;
						}
					}
				}
			}
		}

		return false;
	}
Beispiel #24
0
void netlist_parser::netdev_const(const pstring &dev_name)
{
	pstring name;
	netlist_device_t *dev;
	pstring paramfq;
	double val;

	skipws();
	name = getname(',');
	dev = m_setup.factory().new_device_by_name(dev_name, m_setup);
	m_setup.register_dev(dev, name);
	skipws();
	val = eval_param();
	paramfq = name + ".CONST";
	NL_VERBOSE_OUT(("Parser: Const: %s %f\n", name.cstr(), val));
	check_char(')');
	m_setup.register_param(paramfq, val);
}
Beispiel #25
0
/*
 * Main file of myselect
 * Links everything together, and executes the program
 *
 * Precondition: argc > 1
 * Postcondition: The elements are printed on the screen
 */
int      main(int argc, char** argv)
{
    int  count;
    int  bytes;
    char input[READMIN + 2];

    if(argc < 2 || !my_strpos(argv[1], '*'))
    {
        my_str("No files found!\n");
        exit(1);
    }

    signal(SIGWINCH, show_elems);

    //Get all the termcaps
    init_caps();

    //Prepare the terminal
    init_terminal();

    //Setup the elements
    setup_elems(argc - 1, &argv[1]);

    //Turn off the cursor
    tputs(gl_env.cursoroff, 0, my_termprint);

    //Print the elements for the first time
    show_elems();

    //Main loop
    while(1)
    {
        bytes = read(0, &input, READMIN + 2);
        input[bytes] = '\0';

        if(!gl_env.flag)
        {
            check_char(input);
        }
    }
    
    return 0;
}
Beispiel #26
0
void test_str_ncpy()
{
	const char *src = "foo";
	char dest[80];
	char *result, *expected_result;

	dest[60] = 'X';
	check_unsigned_int(sizeof(dest), 80);
	check_char(dest[60], 'X');

	result = str_ncpy(dest, src, sizeof(dest));
	check_strs(dest, src, "1");
	check_ptrs(result, dest, "2");
	check_chars(dest[60], '\0', "should null-out rest of buffer");

	expected_result = strncpy(dest, src, sizeof(dest));
	check_strs(dest, src, "3");
	check_ptrs(result, expected_result, "4");
}
Beispiel #27
0
double netlist_parser::eval_param()
{
	static const char *macs[6] = {"", "RES_K(", "RES_M(", "CAP_U(", "CAP_N(", "CAP_P("};
	static double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
	int i;
	int f=0;
	bool e;
	double ret;

	pstring s = getname2(')',',');

	for (i=1; i<6;i++)
		if (strncmp(s.cstr(), macs[i], strlen(macs[i])) == 0)
			f = i;
	ret = s.substr(strlen(macs[f])).as_double(&e);
	if ((f>0) && e)
		m_setup.netlist().xfatalerror("Parser: Error with parameter ...\n");
	if (f>0)
		check_char(')');
	return ret * facs[f];
}
Beispiel #28
0
int main() {
    int c;
    int i = 0;
    int open_c, close_c;
    extern int last_nest_char;
    extern char nest_chars[];
    int code;
    int now_in_str = 0;
    for(i=0; i < MAXNESTLEN; i++) {
        nest_chars[i] = '\0';
    }
    while((c = getchar()) != EOF) {
        // 开启符判断
        code = check_char(c);
        open_c = is_open_char(code);
        close_c = is_close_char(code);
        now_in_str = in_str();
        if (c == '"' || c == '\'') {
        }  
        if ((now_in_str && last_nest_char == close_c) || (!now_in_str && match(last_nest_char, close_c))) {
            if (!(last_nest_char = pull_nest_char())) {
                printf("Error: Unmached right syntax: %c \n", close_c);
                exit(0);
            }
        }
 
        else if ((!(now_in_str == '\'' && open_c == '"')) && ((now_in_str != '"' && open_c) || (now_in_str == '"' && open_c == '\''))) {
            last_nest_char = open_c;
            if (!push_nest_char(last_nest_char)) {
                printf("Error: Reach max nest len \n");
                exit(0);
            }
                
        }
      
    }
    //printf("Remain unclosed chars: %s \n", nest_chars);
}
Beispiel #29
0
int				get_tetrimo(char *buffer, t_tetrimos *to_fill)
{
	int			count;
	int			nb;

	nb = 0;
	count = 0;
	while (buffer[count])
	{
		if (!check_char(buffer[count], count + 1, nb))
			return (0);
		if (buffer[count] == '#')
		{
			to_fill->bloc[nb].x = count / 5;
			to_fill->bloc[nb].y = count % 5;
			nb++;
		}
		count++;
	}
	if (nb != 4)
		return (0);
	return (1);
}
Beispiel #30
0
int main(int argc, char** argv){

	int  data;
	char input[READMIN + 2];

	if(argc < 2){
		my_str("Usage: ./myselect itemSelector\n");
		exit(1);
	}
	if(my_strpos(argv[1], '*') == 0){
		my_str("No files were found\n");
		exit(1);
	}

	signal(SIGWINCH, show_elems);

	init_caps(); //Get the termcaps

	init_terminal();  //initilize the terminal

	setup_elems(argc - 1, &argv[1]);  //Setup elems

	tputs(gl_env.cursoroff, 0, my_termprint);  //Turn off cursor	

	show_elems();  //actually show the elements

	while(1){
		data = read(0, &input, READMIN + 2);
		input[data] = '\0';

		if(!gl_env.flag){
			check_char(input);
		}
	}
	
	return 0;
}