Example #1
0
static SLang_Foreach_Context_Type *
cl_foreach_open (SLtype type, unsigned int num)
{
   SLang_Foreach_Context_Type *c;

   (void) type;

   if (num != 0)
     {
	_pSLang_verror (SL_NOT_IMPLEMENTED,
		      "%s does not support 'foreach using' form",
		      SLclass_get_datatype_name (type));
	return NULL;
     }

   if (NULL == (c = (SLang_Foreach_Context_Type *) SLcalloc (1, sizeof (SLang_Foreach_Context_Type))))
     return NULL;

   if (-1 == pop_list (&c->list))
     {
	SLfree ((char *) c);
	return NULL;
     }

   return c;
}
Example #2
0
void	pop_all_list(t_list **t)
{
  void	*data;

  while (42)
    if ((long)(data = pop_list(t)) < 0)
      break;
}
Example #3
0
/*=================================================
 * append_to_text_list - add onto fixed width string list
 *  newline: flag to not append to last element of list
 *  we build each line in current, and add it to list as done
 *  ptr points to the undone part of text
 *  curptr points to the end (insertion point) of current
 * NB: We also build list from last to first, so client can use
 *  FORLIST traversal (which is backwards)
 *  TO DO: Break at whitespace
 *=================================================*/
static void
append_to_text_list (LIST list, STRING text, INT width, BOOLEAN newline)
{
	STRING ptr = text;
	STRING temp, current, curptr;
	INT len, curlen;
	if (!text || !text[0])
		return;
	/* pull off last line into temp, to append to */
	if (newline) {
		temp = NULL;
	} else {
		temp = pop_list(list);
		if (temp && (INT)strlen(temp) >= width) {
			enqueue_list(list, temp);
			temp = NULL;
		}
	}
	current=stdalloc((width+1)*sizeof(char));
	current[0] = 0;
	curptr = current;
	curlen = width;
	if (temp) {
		llstrcatn(&curptr, temp, &curlen);
	}
	while (1) {
		len = strlen(ptr);
		if (!len) {
			/* done */
			if (current[0]) {
				enqueue_list(list, strsave(current));
			}
			stdfree(current);
			return;
		}
		if (len > curlen)
			len = curlen;
		temp = curptr;
		llstrcatn(&curptr, ptr, &curlen);
		ptr += (curptr - temp);
		if (!curlen) {
			/* filled up an item */
			enqueue_list(list, strsave(current));
			current[0] = 0;
			curptr = current;
			curlen = width;
		}
	}
}
Example #4
0
static void list_pop (void)
{
   int indx = 0;
   SLang_List_Type *list;

   if (SLang_Num_Function_Args == 2)
     {
	if (-1 == SLang_pop_integer (&indx))
	  return;
     }
   if (-1 == pop_list (&list))
     return;

   (void) list_pop_nth (list, indx);
   free_list (list);
}
Example #5
0
static int pop_insert_append_args (SLang_List_Type **listp,
				   SLang_Object_Type *obj, int *indx)
{
   if (SLang_Num_Function_Args == 3)
     {
	if (-1 == SLang_pop_integer (indx))
	  return -1;
     }
   if (-1 == SLang_pop (obj))
     return -1;
   if (-1 == pop_list (listp))
     {
	SLang_free_object (obj);
	return -1;
     }
   return 0;
}
Example #6
0
static void list_to_array (void)
{
   SLang_List_Type *list;
   SLtype type = 0;

   if ((SLang_Num_Function_Args == 2)
       && (-1 == SLang_pop_datatype (&type)))
     return;

   if (-1 == pop_list (&list))
     return;

   (void) _pSLarray_convert_to_array ((VOID_STAR) list,
				      l2a_get_type_callback,
				      l2a_push_callback,
				      list->length, type);

   free_list (list);
}
Example #7
0
int		opt_name_team(t_info *info, char **argv, int i)
{
  t_team	*team;
  int		flag;

  while (pop_list(&info->team));
  flag = 0;
  while (argv[i] && (is_options(argv[i]) == -1))
    {
      flag = 1;
      team = xmalloc(sizeof(*team));
      team->name = argv[i];
      team->nb = 0;
      team->max = info->nb_player;
      push_list(&info->team, team);
      i++;
    }
  return (flag == 1 ? i : -1);
}
Example #8
0
void		destroy_info(t_info *info)
{
  t_list	*clients;
  t_client	*client;
  int		i;

  close(info->socket);
  clients = info->clients;
  while ((client = pop_list(&clients)))
    {
      free(client->team_name);
      free(client);
    }
  for (i = 0; i < info->x; i++)
    free(info->object[i]);
  free(info->object);
  for (i = 0; i < info->x; i++)
    free(info->status[i]);
  free(info->status);
}
Example #9
0
void			move_player_to_pos(t_list *map, t_player *player, \
                                   int x, int y)
{
    t_case		*old_cas;
    t_case		*new_cas;

    if (map && player)
    {
        old_cas = find_case_by_index(map, player->x, player->y);
        new_cas = find_case_by_index(map, x, y);
        if (old_cas && new_cas)
        {
            old_cas->player = pop_list(old_cas->player, player);
            player->x = x;
            player->y = y;
            new_cas->player = append_list(new_cas->player, player);

            player->spell = false;
        }
    }
}
Example #10
0
static int pop_list_and_index (unsigned int num_indices,
			       SLang_List_Type **listp,
			       SLang_Array_Type **ind_atp,
			       SLindex_Type *indx)
{
   SLang_List_Type *list;

   *listp = NULL;

   if (-1 == pop_list (&list))
     return -1;

   if (num_indices != 1)
     {
	_pSLang_verror (SL_InvalidParm_Error, "List_Type objects are limited to a single index");
	free_list (list);
	return -1;
     }

   *ind_atp = NULL;
   if (SLang_peek_at_stack () == SLANG_ARRAY_INDEX_TYPE)
     {
	if (-1 == SLang_pop_array_index (indx))
	  {
	     free_list (list);
	     return -1;
	  }
     }
   else
     {
	if (-1 == _pSLarray_pop_index (list->length, ind_atp, indx))
	  {
	     free_list (list);
	     return -1;
	  }
     }

   *listp = list;
   return 0;
}
Example #11
0
int main(int argc, char const *argv[]) {
	struct LinkList* list = create_list();

	append_list(list, 1);
	insert_list(list, 2, 0);
	push_list(list, 10);
	show_list(list);

	int data = pop_list(list);
	printf("pop data is %d\n", data);
	show_list(list);

	push_list(list, 10);
	push_list(list, 11);
	push_list(list, 10);
	push_list(list, 11);
	show_list(list);

	remove_list(list, 1);
	show_list(list);

	remove_data_list(list, 10);
	show_list(list);

	remove_all_data_list(list, 11);
	show_list(list);

	struct Node* node = get_node_list(list, 0);
	printf("data is %d\n", node->data);

	int index = search_list(list, 2);
	printf("index is %d\n", index);

	destory_list(list);
	return 0;
}
int main(void)
{
	list* l = initialize_list();

	list_node* c_node = create_list_node("c");
	list_node* a_node = create_list_node("a");
	list_node* z_node = create_list_node("z");
	list_node* x_node = create_list_node("x");

	push_list_node(l, a_node);
	remove_internal_list_node(l, a_node);
	
	push_list_node(l, a_node);
	push_list(l, "b");
	push_list_node(l, c_node);
	unshift_list_node(l, z_node);
	unshift_list(l, "y");
	unshift_list_node(l, x_node);

	remove_internal_list_node(l, z_node);
	remove_internal_list_node(l, a_node);
	remove_internal_list_node(l, x_node);
	
	free_list_node(z_node);
	free_list_node(a_node);
	free_list_node(x_node);

	while(l->length > 0)
	{
		printf("%s\n", (char*)pop_list(l));
	}
	
	
	unsigned long dl;
	destroy_list(l, DESTROY_MODE_IGNORE_VALUES, &dl);


	printf("-------queue test-------------\n");	
	unsigned long priority;
	char* id;
	
	
	priority_queue* pq = initialize_priority_queue();
	push_priority_queue(pq, 30, "id_1", "value_1");
	push_priority_queue(pq, 10, "id_2", "value_2");
	push_priority_queue(pq, 10, "id_3", "value_3");
	push_priority_queue(pq, 40, "id_4", "value_4");
	push_priority_queue(pq,  5, "id_5", "value_5");
	push_priority_queue(pq, 30, "id_6", "value_6");
	push_priority_queue(pq, 30, "id_7", "value_7");

	
	printf("queue length = %ld\n", pq->length);
	unsigned long num_destroyed;

	char* tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);


	set_priority_for_id_in_priority_queue(pq, "id_5", 35);
	
	tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);
	
	set_priority_for_id_in_priority_queue(pq, "id_2", 36);

	tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);

	/*
	char** values = (char**)destroy_priority_queue(pq, DESTROY_MODE_RETURN_VALUES, &num_destroyed);
	int index = 0;
	for(index = 0; values[index] != NULL; index++)
	{
		printf("%s\n", values[index]);
	}
	*/

	
	while(pq->length > 0)
	{
		char* value = (char*)shift_priority_queue(pq, &priority, &id);
		printf("%s\n", value);
		free(id);
	}
	destroy_priority_queue(pq, DESTROY_MODE_FREE_VALUES, &dl);
	
	return 0;
}
Example #13
0
/*
 * Function: pop_retrieve
 *
 * Purpose: Retrieve a specified message from the maildrop.
 *
 * Arguments:
 * 	server	The server to retrieve from.
 * 	message	The message number to retrieve.
 *	markfrom
 * 		If true, then mark the string "From " at the beginning
 * 		of lines with '>'.
 *	msg_buf	Output parameter to which a buffer containing the
 * 		message is assigned.
 *
 * Return value: The number of bytes in msg_buf, which may contain
 * 	embedded nulls, not including its final null, or -1 on error
 * 	with pop_error set.
 *
 * Side effects: May kill connection on error.
 */
int
pop_retrieve (popserver server, int message, int markfrom, char **msg_buf)
{
  int *IDs, *sizes, bufsize, fromcount = 0, cp = 0;
  char *ptr, *fromserver;
  int ret;

  if (server->in_multi)
    {
      strcpy (pop_error, "In multi-line query in pop_retrieve");
      return (-1);
    }

  if (pop_list (server, message, &IDs, &sizes))
    return (-1);

  if (pop_retrieve_first (server, message, &fromserver))
    {
      return (-1);
    }

  /*
   * The "5" below is an arbitrary constant -- I assume that if
   * there are "From" lines in the text to be marked, there
   * probably won't be more than 5 of them.  If there are, I
   * allocate more space for them below.
   */
  bufsize = sizes[0] + (markfrom ? 5 : 0);
  ptr = (char *)malloc (bufsize);
  free ((char *) IDs);
  free ((char *) sizes);

  if (! ptr)
    {
      strcpy (pop_error, "Out of memory in pop_retrieve");
      pop_retrieve_flush (server);
      return (-1);
    }

  while ((ret = pop_retrieve_next (server, &fromserver)) >= 0)
    {
      if (! fromserver)
	{
	  ptr[cp] = '\0';
	  *msg_buf = ptr;
	  return (cp);
	}
      if (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' &&
	  fromserver[2] == 'o' && fromserver[3] == 'm' &&
	  fromserver[4] == ' ')
	{
	  if (++fromcount == 5)
	    {
	      bufsize += 5;
	      ptr = (char *)realloc (ptr, bufsize);
	      if (! ptr)
		{
		  strcpy (pop_error, "Out of memory in pop_retrieve");
		  pop_retrieve_flush (server);
		  return (-1);
		}
	      fromcount = 0;
	    }
	  ptr[cp++] = '>';
	}
      memcpy (&ptr[cp], fromserver, ret);
      cp += ret;
      ptr[cp++] = '\n';
    }

  free (ptr);
  return (-1);
}
Example #14
0
int ib_trans_line(
/*****************/

    section_def         *section,
    int                 alloc_size
) {
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[ 100 ];
    int                 indent = 0;
    int                 ctr;
    char                *file_name;

    // check for special pre-processing stuff first
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;

    // We start at a new line...
    Wrap_Safe = section->section_size;
    Cursor_X = 0;
    R_Chars = 0;

    if( Blank_line && ( ch != CH_LIST_ITEM ||
                        Curr_list->compact != LIST_SPACE_COMPACT ) ) {
        Blank_line = FALSE;
    }
    switch( ch ) {
    // Tabbed-example
    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
        } else {
            read_tabs( ptr + 1 );
            Tab_xmp = TRUE;
        }
        return( alloc_size );

    // Box-mode start
    case CH_BOX_ON:
        ctr = 0;
        // indent properly
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char( ' ', section, &alloc_size);
        }
        // draw the top line of the box
        trans_add_char( BOX_CORNER_TOP_LEFT, section, &alloc_size );
        for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) {
            trans_add_char( BOX_HBAR, section, &alloc_size );
        }
        trans_add_char( BOX_CORNER_TOP_RIGHT, section, &alloc_size );

        trans_add_char_wrap( '\n', section, &alloc_size);

        Box_Mode = TRUE;
        return( alloc_size );

    case CH_BOX_OFF:
        ctr = 0;
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char( ' ', section, &alloc_size);
        }

        trans_add_char( BOX_CORNER_BOTOM_LEFT, section, &alloc_size );
        for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) {
            trans_add_char( BOX_HBAR, section, &alloc_size );
        }
        trans_add_char( BOX_CORNER_BOTOM_RIGHT, section, &alloc_size );
        Box_Mode = FALSE;

        trans_add_char_wrap( '\n', section, &alloc_size );

        return( alloc_size );

    case CH_OLIST_START:
        new_list( LIST_TYPE_ORDERED );
        set_compact( ptr );
        Curr_indent += Text_Indent;
        return( alloc_size );

    case CH_LIST_START:
    case CH_DLIST_START:
        new_list( ( ch == CH_LIST_START ) ? LIST_TYPE_UNORDERED :
                                                        LIST_TYPE_DEFN );
        set_compact( ptr );
        Curr_indent += Text_Indent;

        if( ch == CH_DLIST_START ) {
            ptr = skip_blank( ptr + 1 );
            if( *ptr != '\0' ) {
                /* due to a weakness in GML, the definition term must be
                   allowed on the same line as the definition tag. So
                   if its there, continue */
                break;
            }
        }
        return( alloc_size );

    case CH_DLIST_TERM:
        Curr_indent -= Text_Indent;
        break;

    case CH_SLIST_START:
        indent = 0;
        if( Curr_list->type == LIST_TYPE_SIMPLE ) {
            /* nested simple lists, with no pre-indent. Force an
               indent */
            indent = Text_Indent;
        }

        new_list( LIST_TYPE_SIMPLE );
        set_compact( ptr );
        Curr_indent += indent;
        return( alloc_size );

    case CH_SLIST_END:
    case CH_OLIST_END:
    case CH_LIST_END:
    case CH_DLIST_END:
        pop_list();
        return( alloc_size );

    case CH_DLIST_DESC:
        Curr_indent += Text_Indent;
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            /* no description on this line. Ignore it so that no
               blank line gets generated */
            return( alloc_size );
        }
        break;

    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    // skip preceding blank lines
    if( *skip_blank( ptr ) == '\0' && Curr_ctx->empty ) {
        return( alloc_size );
    }

    // remove '\n' on the end
    if( Blank_line ) {
        --section->section_size;
    }

    // indent properly if the first char is not white-space
    if( ch != '\0' && ch != ' ' && ch != '\t') {
        ctr = ( ch == CH_LIST_ITEM && !Box_Mode &&
                        Curr_list->type != LIST_TYPE_SIMPLE )
                ? Text_Indent
                : 0;
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char_wrap( ' ', section, &alloc_size);
        }

        if( Box_Mode ) {
            trans_add_char_wrap( BOX_VBAR, section, &alloc_size);
            trans_add_char_wrap( ' ', section, &alloc_size);
        }
    }

    Blank_line = TRUE;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch != '\0' && ( ch != ' ' || ch != '\t' ) ) {
            Blank_line = FALSE;
        }
        if( ch == '\0' ) {
            // this just shuts off bolding after a def. list term
            if( Line_postfix == LPOSTFIX_TERM ) {
                Line_postfix = LPOSTFIX_NONE;
                trans_add_str( STR_BOLD_OFF, section, &alloc_size );
            }
            trans_add_char_wrap( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN || ch == CH_FLINK ) {
            Curr_ctx->empty = FALSE;
            if( ch == CH_FLINK ) {
                file_name = strchr( ptr + 1, ch );
                if( file_name == NULL ) {
                    error( ERR_BAD_LINK_DFN, TRUE );
                }
                *file_name = '\0';
            } else {
                file_name = ptr;
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_name = '\0';

            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_text = '\0';

            ctx_text = ctx_name + 1;
            ctx_name = file_name + 1;
            file_name = ptr + 1;
            if( ch != CH_FLINK ) {
                add_link( ctx_name );
            }

            ptr = ctx_text + strlen( ctx_text ) + 1;

            // Definition pop-up's are converted to hyper-links in InfoBench
            trans_add_char( CHR_TEMP_HLINK , section, &alloc_size );

            // Add line number to hyperlink so we can give meaningful errors
            trans_add_str( itoa( Line_num, buf, 10 ), section, &alloc_size );
            trans_add_char( CHR_TEMP_HLINK, section, &alloc_size );

            // We don't want links to break as IB doesn't like this...
            to_nobreak( ctx_text );

            indent = Curr_indent;
            if( indent < 0 )
                indent = 0;
            // find out the maximum allowed length for hyper-link text:
            ctr = Right_Margin - indent - ( ( Hyper_Brace_L == '<' ) ? 2 : 0 );

            // if the link name is too long then we warn & truncate it
            if( strlen( ctx_text ) > ctr ) {
                warning( "Hyperlink name too long", Line_num );
                ctx_text[ ctr ] = '\0';
            }

            /* If hyper-link bracing is on we have to do a kludge to fix
             * the spacing. The "XX" will make the wrap routine happy.
             * They're stripped off when it comes time to write the file.
             */
            if( Hyper_Brace_L == '<' ) {
                trans_add_str_wrap( "XX", section, &alloc_size );
            }
            trans_add_str_wrap( ctx_text, section, &alloc_size );
            trans_add_char( CHR_HLINK_BREAK , section, &alloc_size );
            trans_add_str( ctx_name, section, &alloc_size );
            if( ch == CH_FLINK ) {
                trans_add_char( CHR_HLINK_BREAK, section, &alloc_size );
                trans_add_str( file_name, section, &alloc_size );
            }
            trans_add_char( CHR_TEMP_HLINK , section, &alloc_size );
        } else if( ch == CH_LIST_ITEM ) {
            if( Curr_list->type != LIST_TYPE_SIMPLE ) {
                if( Curr_list->type == LIST_TYPE_UNORDERED ) {
                    // generate a bullet, correctly spaced for tab size
                    buf[0] = '\0';
                    for( ctr = 1; ctr <= Text_Indent; ctr++)
                    {
                        strcat( buf, " " );
                    }
                    buf[ Text_Indent / 2 - 1 ] = CHR_BULLET;
                } else if( Curr_list->type == LIST_TYPE_ORDERED ) {
                    /* ordered list type */
                    sprintf( buf, "%*d. ", Text_Indent - 2,
                                                        Curr_list->number );
                    ++Curr_list->number;
                }
                trans_add_str_wrap( buf, section, &alloc_size );
            }
            Eat_blanks = TRUE;
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            trans_add_str( STR_BOLD_ON, section, &alloc_size );
            Line_postfix = LPOSTFIX_TERM;
            ptr = skip_blank( ptr + 1 );
            Eat_blanks = TRUE;
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[end - ptr - 1] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords are
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            // we ignore paragraph resets
            ++ptr;
        } else if( ch == CH_BMP ) {
            // we ignore bitmaps
            ptr = strchr( ptr + 3, CH_BMP ) + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {

                // bold and italic map to bold
                case 'b':
                case 'i':
                    trans_add_str( STR_BOLD_ON, section, &alloc_size );
                    break;

                // underline and underscore map to underline
                case 'u':
                case 's':
                    trans_add_str( STR_UNDERLINE_ON, section, &alloc_size );
                    break;
                }
            }
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            // reset style (bold off, underline off)
            trans_add_str( Reset_Style, section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            // we basically ignore font type changes
            ptr = strchr( strchr( ptr + 1 , CH_FONTTYPE ) + 1,
                            CH_FONTTYPE ) + 1;
        } else {
            ++ptr;
            if( !Eat_blanks || ch != ' ' ) {
                Curr_ctx->empty = FALSE;

                if( Tab_xmp && ch == Tab_xmp_char ) {
                    tab_align( section, &alloc_size );
                    ptr = skip_blank( ptr );
                } else {
                    trans_add_char_wrap( ch, section, &alloc_size );
                }

                Eat_blanks = FALSE;
            }
        }
    }

    return( alloc_size );
}
int main(int argc, char **argv)
{
	char *table = argv[1];
	char *delete_chain = argv[2];
	if(argc != 3)
	{
		printf("USAGE: %s [TABLE] [CHAIN TO DELETE]\n\n", argv[0]);
		return 0;
	}

	char *command = dynamic_strcat(3, "iptables -t ", table, " -L -n --line-numbers 2>/dev/null");
	unsigned long num_lines = 0;
	char** table_dump = get_shell_command_output_lines(command, &num_lines);
	free(command);
	

	unsigned long line_index;
	char* current_chain = NULL;
	list* delete_commands = initialize_list();


	for(line_index=0; line_index < num_lines; line_index++)
	{
		char* line = table_dump[line_index];
		unsigned long num_pieces = 0;
		char whitespace[] = { '\t', ' ', '\r', '\n' };
		char** line_pieces = split_on_separators(line, whitespace, 4, -1, 0, &num_pieces);
		if(strcmp(line_pieces[0], "Chain") == 0)
		{
			if(current_chain != NULL) { free(current_chain); }
			current_chain = strdup(line_pieces[1]);
		}
		else 
		{
			unsigned long line_num;
			int read = sscanf(line_pieces[0], "%ld", &line_num);

			if(read > 0 && current_chain != NULL && num_pieces >1)
			{
				if(strcmp(line_pieces[1], delete_chain) == 0)
				{
					char* delete_command = dynamic_strcat(7, "iptables -t ", table, " -D ", current_chain, " ", line_pieces[0], " 2>/dev/null");
					push_list(delete_commands, delete_command);
				}
			}
		}

		//free line_pieces
		free_null_terminated_string_array(line_pieces);
	}
	free_null_terminated_string_array(table_dump);
	
	/* final two commands to flush chain being deleted and whack it */
	unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -F ", delete_chain, " 2>/dev/null"));
	unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -X ", delete_chain, " 2>/dev/null"));

	/* run delete commands */
	while(delete_commands->length > 0)
	{
		char *next_command = (char*)pop_list(delete_commands);
		char **out = get_shell_command_output_lines(next_command, &num_lines);
		free_null_terminated_string_array(out);
	}

	return 0;
}
Example #16
0
int SLang_pop_list (SLang_List_Type **list)
{
   return pop_list (list);
}
Example #17
-1
static void	levelup(t_client *client, t_info *info)
{
  t_list	*t;
  t_client	*c;
  void		*data;
  int		x;
  int		y;

  t = info->zone[client->x][client->y].clients;
  while (t)
    {
      c = t->data;
      c->level++;
      SEND(c->buf_write, LVLUP_OK);
      putnbr(c->level, c->buf_write);
      SEND(c->buf_write, "\n");
      t = t->next;
    }
  while ((data = pop_list(&(info->zone[client->x][client->y].ressources))))
    {
      x = get_random(info->x, client->x);
      y = get_random(info->y, client->y);
      push_list(&(info->zone[x][y].ressources), data);
      obs_send_new_item(info->observator, x, y, data);
    }
}