Example #1
0
extern int
main(int argc, char* argv[])
{
    int c = EOF, comment = FALSE, i, j, k;
    cr = FALSE;
    line_nr = 0;
    nr_tags = 0;
    for (i = 1; i < argc; i += 1) {
        if (comment) {
            comment = FALSE;
            emits("// ");
            emits(argv[i]);
            emit('\n');
        } else if (strcmp(argv[i], "-comment") == 0) {
            comment = TRUE;
        } else {
            for (j = 0; j < MAX_TAG_LENGTH; j += 1) {
                c = argv[i][j];
                if (!is_alphanum(c)) {
                    break;
                }
                tags[nr_tags][j] = (char)c;
            }
            if (j == 0) {
                error(argv[i]);
            }
            tags[nr_tags][j] = 0;
            if (c == 0) {
                methods[nr_tags][0] = 0;
            } else if (c == ':') {
                j += 1;
                for (k = 0; k < MAX_TAG_LENGTH; k += 1) {
                    c = argv[i][j + k];
                    if (!is_alphanum(c)) {
                        break;
                    }
                    methods[nr_tags][k] = (char)c;
                }
                methods[nr_tags][k] = 0;
                if (k == 0 || c != 0) {
                    error(argv[i]);
                }
            } else {
                error(argv[i]);
            }
            nr_tags += 1;
        }
    }
    process();
    return 0;
}
Example #2
0
int		fill_lwd(t_my_lwd *lwd, t_my_wd *wd, int nb_w, int pos)
{
  int		nb_words;
  int		lp;
  t_my_lwd	*next;

  lp = 0;
  while (!(is_alphanum(wd->str[lp + pos])))
    {
      if (wd->str[lp + pos] == '\0')
	return (nb_w);
      wd->str[lp + pos] = '\0';
      ++lp;
    }
  if ((next = gbgc_malloc(sizeof(t_my_lwd))) == NULL)
    return (-1);
  next->prev = lwd;
  lwd->next = next;
  next->str = wd->str + lp + pos;
  while (is_alphanum(wd->str[++lp + pos]));
  nb_words = fill_lwd(next, wd, ++nb_w, lp + pos);
  return (nb_words);
}
Example #3
0
static int	exit_setenv(char **tab)
{
  if (tab_len(tab) > 3)
    {
      fprintf(stderr, "setenv: Too many arguments.\n");
      return (0);
    }
  if ((tab[1] && !is_alphanum(tab[1])))
    {
      fprintf(stderr, "setenv: Variable name must"
	      " contain alphanumeric characters.\n");
      return (0);
    }
  return (1);
}
Example #4
0
static void tokenize_identifier(tokenizer_t* t)
{
	int i = 0;

	t->token_value = (char*)malloc(MAX_IDENT_LENGTH);
	((char*)(t->token_value))[i++] = t->source[t->source_index++];
	while (is_alphanum( t->source[t->source_index])) {
		((char*)(t->token_value))[i++] = t->source[t->source_index++];
		if (MAX_IDENT_LENGTH == i) {
			fprintf(stderr, "MAX_IDENT_LENGTH reached :%d\n", t->line_number);
			exit(1);
		}
	}
	((char*)(t->token_value))[i] = '\0';
	for (i = 0; i < sizeof(keywords) / sizeof(keywords[0]); ++i) {
		if (strcmp(((char*)(t->token_value)), keywords[i].str) == 0) {
			t->token_type = keywords[i].token_type;
			return;
		}
	}
	t->token_type = TT_IDENT;
}
Example #5
0
void uart_rx_worker(void *parg)
  {
  uart_config_t *uart = (uart_config_t *) parg;

  while(true)
    {
    pop_front(&uart->rx_queue, uart->rx_worker_buffer, INDEFINITE_WAIT);
    
    if((uart->flags & NMEA_DECODER_ENABLE) != 0)
      {
      char *start = (char *) uart->rx_worker_buffer;
      char *end = start;
      uint8_t sentence = 0;
      uint8_t word = 0;
      uint8_t checksum = 0;
      bool checksum_marker = false;
      
      // calculate the checksum of the string
      while(*start != 0 && *start != '*')
        checksum ^= *start++;

      start = end;
      
      while(*start != 0)
        {
        if(checksum_marker)         // checksum marker
          {
                    // compare the checksum
          uint8_t chk = 0;
          if(is_alphanum(start[0]) &&
             is_alphanum(start[1]) &&
             start[2] == 0)
            {
            chk = hex_to_digit(start[0]) << 4;
            chk += hex_to_digit(start[1]);
            }

          (uart->callback.nmea_callback)(uart, 
            checksum != chk ? 0 : (char *) 1,
            sentence, word);

          start++;
          break;                  // and done, wait for next
          }
        
        for(end = start; *end != 0 && *end != ',' && *end != '*' ; end++);
        
        if(*end == '*')
          checksum_marker = true;
        
        *end = 0;
        
        sentence = (uart->callback.nmea_callback)(uart, start, sentence, word);
        word++;
        
        // skip token
        start = end;
        // and increment to next word
        start++;
        }
      }
    else
      (uart->callback.uart_callback)(uart, uart->rx_worker_buffer, strlen((const char *)uart->rx_worker_buffer));
    }
  }
Example #6
0
void do_help(CHAR_DATA *ch, char *argument)
{
	int numresults=0;
	MYSQL *conn;
	MYSQL_RES *res_set = NULL, *res_set2 = NULL;
	MYSQL_ROW row;
	char query[MSL*2], buf[MSL];

	if(!str_cmp(argument,""))
		return do_help(ch, "topics");
	else
	{
		if((!is_alphanum(argument) && !have_space(argument)) || have_schar(argument))
			return do_help(ch, "topics");
	}

	conn = open_conn();
	if(!conn)
		return send_to_char("Error opening help database.\n\r",ch);

	if(is_number(argument))
		sprintf(query,"select * from helpfiles where id=%d", atoi(argument));
	else if(!is_number(argument))
		sprintf(query,"select * from helpfiles where title RLIKE '%s' ORDER BY id ASC", argument);

	mysql_query(conn,query);
	res_set = mysql_store_result(conn);
	numresults = mysql_affected_rows(conn);
	
	if(!numresults || (res_set == NULL && mysql_field_count(conn)>0))
		send_to_char("No matching helpfiles found.\n\r",ch);
	else if(numresults == 1)
	{
		row = mysql_fetch_row (res_set);
		if(!can_see_help(ch, row, TRUE))
			send_to_char("No matching helpfiles found.\n\r",ch);
		else
			show_helpfile(ch, row);
	}
	else
	{
		sprintf(query,"select * from helpfiles where title RLIKE '\\'%s\\'' OR title = '%s'", argument, argument);
		mysql_query(conn,query);
		res_set2 = mysql_store_result(conn);
		numresults = mysql_affected_rows(conn);
		if(numresults > 0)
		{
			row = mysql_fetch_row(res_set2);
			if(!can_see_help(ch, row, FALSE))
				send_to_char("No matching helpfiles found.\n\r", ch);
			else
			{
				show_helpfile(ch, row);
				mysql_free_result(res_set2);
			}
		}
		else
		{
			send_to_char("Multiple helpfiles matched your request:\n\r",ch);
			while((row = mysql_fetch_row (res_set)) != NULL)
        	{
	   			if(!can_see_help(ch,row, FALSE))
					continue;
	   			sprintf(buf,"%-5s %s\n\r", row[0], row[1]);
	   			send_to_char(buf,ch);
        	}
		}
	}
	mysql_free_result (res_set);
	do_disc(conn);
}
Example #7
0
/* parse:  something param_name=param_value something [ "," something param_name="param_value" ....]
 * 'something' is required by Authenticate
 */
static int find_hf_value2_param(struct hname_data* hname, str* param_area, str* value, str* lump_upd, str* lump_del, char* delim) {
	int i, j, k, found, comma_flag;

	i = 0;
	*delim = 0;
	lump_del->len = 0;
	while (i < param_area->len) {

		lump_del->s = param_area->s + i;
		while (i<param_area->len && is_space(param_area->s[i])) i++;
		comma_flag = i < param_area->len && param_area->s[i] == ',';
		if (comma_flag) i++;
		while (i<param_area->len && is_space(param_area->s[i])) i++;

		if (i < param_area->len && is_alphanum(param_area->s[i])) {	/* found a param name ? */
			j = i;
			if (!*delim) *delim = ' ';
			while (i<param_area->len && is_alphanum(param_area->s[i])) i++;

			k = i;
			while (i<param_area->len && is_space(param_area->s[i])) i++;
			lump_upd->s = param_area->s + i;
			if (i < param_area->len && param_area->s[i] == '=') {	/* if equal then it's the param */
				*delim = ',';
				i++;
				found = hname->param.len == k-j && !strncasecmp(hname->param.s, param_area->s+j, k-j);
				while (i<param_area->len && is_space(param_area->s[i])) i++;

				value->s = param_area->s+i;
				value->len = 0;
				if (i < param_area->len) {
					if (param_area->s[i]=='\"') {
						i++;
						value->s++;
						for (; i<param_area->len; i++) {
							if (param_area->s[i]=='\"') {
								i++;
								break;
							}
							value->len++;
						}
					}
					else {
						for (; i<param_area->len && !is_space(param_area->s[i]) && param_area->s[i]!=','; i++, value->len++);
					}
				}
				if (found) {
					lump_upd->len = param_area->s+i - lump_upd->s;
					lump_del->len = param_area->s+i - lump_del->s;

					while (i<param_area->len && is_space(param_area->s[i])) i++;

					if (!comma_flag && i < param_area->len && param_area->s[i]==',') {
						i++;
						lump_del->len = param_area->s+i - lump_del->s;
					}
					return 1;
				}
			}
			while (i<param_area->len && is_space(param_area->s[i])) i++;
		}
		else {
			while (i<param_area->len && !is_space(param_area->s[i]) && !param_area->s[i]!=',') i++;
		}
	}
	lump_del->s = param_area->s + i;
	return 0;
}
/*******************************************************************************
 * Fonction principale de l'analyseur lexical, lit les caractères de yyin et
 * renvoie les tokens sous forme d'entier. Le code de chaque unité est défini 
 * dans symboles.h sinon (mot clé, idententifiant, etc.). Pour les tokens de 
 * type ID_FCT, ID_VAR et NOMBRE la valeur du token est dans yytext, visible 
 * dans l'analyseur syntaxique.
 ******************************************************************************/
int yylex(void)
{
  char c;
  int i;
  yytext[yyleng = 0] = '\0';
  
  if (mangeEspaces() == -1)
    return FIN;

  c = lireCar();


  // Symbole simple
  for( int i = 0; tableSymbole[i] != '\0'; ++i ) {
    if( c == tableSymbole[i] ) {
      return codeSymbole[i];
    }
  }

  // Nombre
  if( is_num( c ) )
  {
    do {
      lireCar();
    } while( is_num( yytext[yyleng-1] ) );
    delireCar();

    return NOMBRE;
  }

  //id_var
  if( c == '$' ) {
    i = 1; // 1 pour $

    do {
      lireCar();
      i++;
    } while( is_alphanum( yytext[yyleng-1] ) );
    i--;
    delireCar();


    if(i > 99) {
      return -1;
    }
    
    return ID_VAR;
  }

  // Mot clefs
  do {
    lireCar();
  } while( is_alphanum( yytext[yyleng-1] ) );
  delireCar();

  for( int i = 0; tableMotsClefs[i] != '\0'; ++i )
  {
    if( strcmp( tableMotsClefs[i], yytext ) == 0 ) {
        return codeMotClefs[i];
    }
  }

  for(; yyleng != 1; delireCar() );

  //id_fct
  if( is_alpha( c ) ) {
    int i = 1; // 1 pour $

    do {
      lireCar();
      i++;

    } while( is_alphanum( yytext[yyleng-1] ) );
    i--;
    delireCar();

    if(i > 99) {
      return -1;
    }

    return ID_FCT;
  }

  erreur("Aucune Correspondance");  
  return -1;
}
Example #9
0
static void
process()
{
/*
    Loop through the program text, looking for patterns.
*/
    int c, i, left = 0;
    line_nr = 1;
    c = get(FALSE);
    for (;;) {
        if (c == EOF) {
            break;
        } else if (c == '\'' || c == '"' || c == '`') {
            emit(c);
            string(c, FALSE);
            c = 0;
/*
    The most complicated case is the slash. It can mean division or a regexp
    literal or a line comment or a block comment. A block comment can also be
    a pattern to be expanded.
*/
        } else if (c == '/') {
/*
    A slash slash comment skips to the end of the file.
*/
            if (peek() == '/') {
                emit('/');
                for (;;) {
                    c = get(TRUE);
                    if (c == '\n' || c == '\r' || c == EOF) {
                        break;
                    }
                }
                c = get(FALSE);
/*
    The first component of a slash star comment might be the tag.
*/
            } else {
                if (peek() == '*') {
                    get(FALSE);
                    for (i = 0; i < MAX_TAG_LENGTH; i += 1) {
                        c = get(FALSE);
                        if (!is_alphanum(c)) {
                            break;
                        }
                        tag[i] = (char)c;
                    }
                    tag[i] = 0;
                    unget(c);
/*
    Did the tag match something?
*/
                    i = i == 0 ? -1 : match();
                    if (i >= 0) {
                        expand(i);
                        c = get(FALSE);
                    } else {
/*
    If the tag didn't match, then echo the comment.
*/
                        emits("/*");
                        emits(tag);
                        for (;;) {
                            if (c == EOF) {
                                error("unterminated comment.");
                            }
                            if (c == '/') {
                                c = get(TRUE);
                                if (c == '*') {
                                    error("nested comment.");
                                }
                            } else if (c == '*') {
                                c = get(TRUE);
                                if (c == '/') {
                                    break;
                                }
                            } else {
                                c = get(TRUE);
                            }
                        }
                        c = get(FALSE);
                    }
                } else {
                    emit('/');
/*
    We are looking at a single slash. Is it a division operator, or is it the
    start of a regexp literal? If is not possible to tell for sure without doing
    a complete parse of the program, and we are not going to do that. Instead,
    we are adopting the convention that a regexp literal must have one of a
    small set of characters to its left.
*/
                    if (pre_regexp(left)) {
                        regexp(FALSE);
                    }
                    left = '/';
                    c = get(FALSE);
                }
            }
        } else {
/*
    The character was nothing special, to just echo it.
    If it wasn't whitespace, remember it as the character to the left of the
    next character.
*/
            emit(c);
            if (c > ' ') {
                left = c;
            }
            c = get(FALSE);
        }
    }
}
Example #10
0
convertl (FILE *in, FILE *out)
{
int c;
char buf[1000], buf1[1000];
char rec[300];
char field[200];
char ind[200];
int i, j, k;
    for (;;)
    {
	c = fgetc (in);
	if (feof(in) || c == EOF)
	    break;
        if (!is_letter (c))
	    fputc (c, out);
	else
	{
	    i = 0;
	    for (;;)
	    {
		if (is_alphanum(c))
		{		
		    rec[i++] = c;
		    c = fgetc (in);
		}
		else 
		{
		    rec[i] = 0;
		    strcpy (buf, rec);
		loop:
		    if (c != '-')
		    {
			fprintf (out, "%s%c", buf, c);
			break;
                    }
		    else
		    {
			c = fgetc (in);
			if (c != '>')
			{
			    fprintf (out, "%s-%c", buf, c);   
			    break;
			}
			else
			{
			    c = fgetc (in);
			    j = 0;
			    for (;;)
			    {
				if (is_alphanum(c))
				{
				    field[j++] = c;
				    c = fgetc (in);
				}
				else
				{
				    field[j] = 0; 
				    if (c != '[')
				    {
					sprintf (buf1, "%s(%s)", field, buf);
					strcpy (buf, buf1);
					goto loop;
				    }
				    else
				    {
					k = 0;
					for (;;)
					{
					    c = fgetc (in);
					    if (c != ']')
						ind[k++] = c;
					    else
					    {
						ind[k] = 0;
						sprintf (buf1, "%s(%s,%s)",
						    field, ind, buf);
						strcpy (buf, buf1);
						c = fgetc (in);
						goto loop;
					    }				    
					}				
				    }
				}				    
			    }
			}
		    }
		}	    		
	    }  
	}
    }
}