<commit_before>/*
    LibCGI - A library to make CGI programs using C
    Copyright (C) 2001 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    You can contact the author by e-mail: <EMAIL>
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "error.h"
#include "cgi.h"

// Add a new item to the list
void slist_add(formvars *item, formvars **start, formvars **last)
{
	// if *start is empty, then our list is also empty. So, the only
	// task to do is fill the variables *start and *last with the data pointed by item
	// *start contains the firts item in the list, and we need *last to know the
	// end of the list
	if (!*start) {
		// item->next needs to be NULL, otherwise we never will
		// find the end of list
		item->next = NULL;

		*start = item;
		*last = item;

		return;
	}

	// Ok, in this case, the next item will contain the
	// new data. Note that, before it, (*last)->next contains
	// NULL ( the end of the list )
	(*last)->next = item;

	// The 'next' argument of item variable need to contain
	// NULL, or in other words, it will be the end ;0
	item->next = NULL;

	// Finaly, the actual end of list will contain the new item
	*last = item;
}

// Delete from list the item pointed by name

// This code is a bit complicated, and I needed some
// long hours to terminate it. In a future release,
// I will explain the algorithm better
int slist_delete(char *name, formvars **start, formvars **last)
{
	// *begin will be used to store the start of the list,
	// *prior will store the prior item relacted to actual in the loop
	formvars *begin, *prior;

	if ( !*start ) return 0;

	// Before of all, is more simple to check if the item
	// to delete is in the next item. If true, we don't need
	// to enter in the loop
	if (!strcasecmp((*start)->name, name)) {
		// The start of the list will contains the next item
		*start = (*start)->next;

		// if start is null, then we haven't more itens
		// in the list..
		if (!*start)
			*last = NULL;

		return 1 ;
	}

	// Stores the start of the list
	begin = *start;

	// Stays in the loop while the item to be deleted
	// is not found
	while (*start) {
		// Stores the prior item of the list
		// Note that, in the loop, we're really changing
		// the value of start variable, then it works correctly
		prior = *start;

		// Critical section:<commit_msg>list delete: return if next element is null (fixes #20)<commit_after>/*
    LibCGI - A library to make CGI programs using C
    Copyright (C) 2001 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    You can contact the author by e-mail: <EMAIL>
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "error.h"
#include "cgi.h"

// Add a new item to the list
void slist_add(formvars *item, formvars **start, formvars **last)
{
	// if *start is empty, then our list is also empty. So, the only
	// task to do is fill the variables *start and *last with the data pointed by item
	// *start contains the firts item in the list, and we need *last to know the
	// end of the list
	if (!*start) {
		// item->next needs to be NULL, otherwise we never will
		// find the end of list
		item->next = NULL;

		*start = item;
		*last = item;

		return;
	}

	// Ok, in this case, the next item will contain the
	// new data. Note that, before it, (*last)->next contains
	// NULL ( the end of the list )
	(*last)->next = item;

	// The 'next' argument of item variable need to contain
	// NULL, or in other words, it will be the end ;0
	item->next = NULL;

	// Finaly, the actual end of list will contain the new item
	*last = item;
}

// Delete from list the item pointed by name

// This code is a bit complicated, and I needed some
// long hours to terminate it. In a future release,
// I will explain the algorithm better
int slist_delete(char *name, formvars **start, formvars **last)
{
	// *begin will be used to store the start of the list,
	// *prior will store the prior item relacted to actual in the loop
	formvars *begin, *prior;

	if ( !*start ) return 0;

	// Before of all, is more simple to check if the item
	// to delete is in the next item. If true, we don't need
	// to enter in the loop
	if (!strcasecmp((*start)->name, name)) {
		// The start of the list will contains the next item
		*start = (*start)->next;

		// if start is null, then we haven't more itens
		// in the list..
		if (!*start)
			*last = NULL;

		return 1 ;
	}

	// Stores the start of the list
	begin = *start;

	// Stays in the loop while the item to be deleted
	// is not found
	while (*start) {
		// Stores the prior item of the list
		// Note that, in the loop, we're really changing
		// the value of start variable, then it works correctly
		prior = *start;

		if ( !(*start)->next ) return 0;

		// Critical section:
{'fraction_non_alphanumeric': 0.08971447112264763, 'fraction_numerical': 0.007949383517196625, 'mean_word_length': 2.946862996158771, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2579605', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1792, 'n_words': 964}