Ejemplo n.º 1
0
/*
 * Reads the tokens from the file into an array which is returned via
 * the 'ary' parameter.  The caller is responsable for freeing the
 * array.
 *
 * Returns 0 on success and 1 on failure.
 */
static int read_token_array(FILE * f, char **ary, unsigned int *n){
    struct list_node *head, *p;
    unsigned int i;
    char *a;

    head = read_token_list(f, n);
    if (!head)
	return 1;

    a = malloc(sizeof(*a) * *n);
    if (!a) {
	perror("malloc failed");
	free_token_list(head);
	return 1;
    }

    i = *n - 1;
    p = head;
    while (p) {
	a[i] = p->val;
	p = p->next;
	i -= 1;
    }

    *ary = a;
    free_token_list(head);
    return 0;
}
Ejemplo n.º 2
0
t_parse		*ft_checking_syntax(t_token *tok)
{
	tok = inibitor_handler(tok);
	return_type_quoted(tok);
	tok = join_quoted(tok, QUOTES);
	tok = join_quoted(tok, SINGLE_QUOTES);
	tok = ft_subshell(tok);
	tok = check_dollar(tok);
	tok = ft_tild_expand(tok);
	ft_edit_useless(tok);
	if ((tok = ft_token_removal(tok, QUOTES)) == NULL)
		return (NULL);
	if ((tok = ft_token_removal(tok, SINGLE_QUOTES)) == NULL)
		return (NULL);
	tok = join_tokens(tok);
	if ((tok = ft_token_removal(tok, WHITESPACE)) == NULL)
		return (NULL);
	if (!tok)
		return (NULL);
	if (!(ft_command_isvalid(tok)))
	{
		free_token_list(tok);
		return (NULL);
	}
	return (parse_build_list(tok));
}
Ejemplo n.º 3
0
/* attempts to open a file, tokenize and then process it as a haserl script */
int
h_lua_loadfile (lua_State * L)
{
  script_t *scriptchain;
  token_t *tokenchain;
  buffer_t script_text;
  int status;

  /* get the filename */
  const char *filename = luaL_checkstring (L, 1);


  scriptchain = load_script ((char *) filename, NULL);
  tokenchain = build_token_list (scriptchain, NULL);
  preprocess_token_list (tokenchain);
  process_token_list (&script_text, tokenchain);
  free_token_list (tokenchain);
  free_script_list (scriptchain);

  /* script_text has the include file */
  status = luaL_loadbuffer (L, (char *) script_text.data,
			    script_text.ptr - script_text.data, filename);
  buffer_destroy (&script_text);
  if (status)
    {
      lua_error (L);
    }
  return (1);			/* we return one value, the buffer, as a function */
}
Ejemplo n.º 4
0
/*
 * Reads the tokens from a file into a linked list.  Returns the size
 * of the list via the 'num' parameter.  The caller is responsable for
 * freeing the list.
 *
 * Return NULL on failure;
 */
static struct list_node *read_token_list(FILE *f,
				  unsigned int *num){
    int _num;
    char c = '\0';
    struct list_node *head = NULL;

    _num = 0;
    while ((c = getc(f)) != EOF) {
	    if (c != '\n' && c != '\t' && c != ' '){
		    struct list_node *n;
		    n = malloc(sizeof(*n));
		    if (!n) {
			    perror("malloc failed");
			    free_token_list(head);
			    return NULL;
		    }
		    n->val = c;
		    _num += 1;
		    n->next = head;
		    head = n;
	    }
    }
    *num = _num;
    return head;
}
Ejemplo n.º 5
0
/*
 *
 * free_server - free a server and possibly its queues also
 *
 *   sinfo - the server_info list head
 *   free_queues_too - flag to free the queues attached to server also
 *
 * returns nothing
 *
 */
void free_server(server_info *sinfo, int free_objs_too)
  {
  if (sinfo == NULL)
    return;

  if (free_objs_too)
    {
    free_queues(sinfo -> queues, 1);
    free_nodes(sinfo -> nodes);
    }

  free_token_list(sinfo -> tokens);

  free_server_info(sinfo);
  }
Ejemplo n.º 6
0
Archivo: exit.c Proyecto: fdeage/asm
static void	free_lines(t_file *file)
{
	t_list	*tmp;
	t_list	*next;

	tmp = file->lines;
	while (tmp)
	{
		next = tmp->next;
		if (LINE->str)
			free(LINE->str);
		free_token_list(LINE->tokens);
		free(LINE);
		free(tmp);
		tmp = next;
	}
}
Ejemplo n.º 7
0
int main(void){
    char buffer[MAXLINE];
    
    printf("$ ");
    while( fgets(buffer, MAXLINE, stdin) != NULL ){
        if( buffer[strlen(buffer) - 1] == '\n' )
            buffer[strlen(buffer) - 1] = '\0';

        struct tokenized_node* tokenized_command = tokenize(buffer);
        command* parsed_command =
            create_parse_tree(tokenized_command);

        #ifdef DEBUG
            command* command_iterator;
            for (iterator(command_iterator, parsed_command))
            {
                printf("New command:\n");
                commanditem* command_contents = command_iterator->contents;
                for (iter(command_contents))
                {
                    printf("%s\n", (char*)(command_contents->contents));
                }
                if (command_iterator->input != NULL)
                    printf("\tInput: %s\n", command_iterator->input);
                if (command_iterator->output != NULL)
                    printf("\tOutput: %s\n", command_iterator->output);
                if (command_iterator->output_append)
                    printf("\tAppend\n");
                if (command_iterator->background)
                    printf("\tBackground this\n");
            }
        #endif

        execute(parsed_command);

        free_parse_tree(parsed_command);
        free_token_list(tokenized_command);

        printf("$ ");
    }

    return 0;
}
Ejemplo n.º 8
0
void completely_free_fact_list(fact_list l)
{
  fact_list temp;
  while(l) { temp = l->next; free_token_list(l->item); free(l); l = temp;}
}