[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Ayttm-commits] CVS: ayttm/src llist.c,NONE,1.1 llist.h,NONE,1.1 mem_uti
From: |
Philip S Tellis <address@hidden> |
Subject: |
[Ayttm-commits] CVS: ayttm/src llist.c,NONE,1.1 llist.h,NONE,1.1 mem_util.c,NONE,1.1 mem_util.h,NONE,1.1 Makefile.am,1.15,1.16 |
Date: |
Thu, 23 Jan 2003 01:06:42 -0500 |
Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv29288
Modified Files:
Makefile.am
Added Files:
llist.c llist.h mem_util.c mem_util.h
Log Message:
added linked list and memory routines - they are still not referenced from
anywhere
--- NEW FILE: llist.c ---
/*
* llist.c: linked list routines
*
* Some code copyright (C) 2002-2003, Philip S Tellis <philip . tellis AT gmx .
net>
* Other code copyright Meredydd Luff <meredydd AT everybuddy.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Most of this code was borrowed from elist.c in the eb-lite sources
*
*/
#include <stdlib.h>
#include "llist.h"
LList *l_list_append(LList * list, void *data)
{
LList *n;
LList *new_list = malloc(sizeof(LList));
LList *attach_to = NULL;
new_list->next = NULL;
new_list->data = data;
for (n = list; n != NULL; n = n->next) {
attach_to = n;
}
if (attach_to == NULL) {
new_list->prev = NULL;
return new_list;
} else {
new_list->prev = attach_to;
attach_to->next = new_list;
return list;
}
}
LList *l_list_remove(LList * list, void *data)
{
LList *n;
for (n = list; n != NULL; n = n->next) {
if (n->data == data) {
return l_list_remove_link(list, n);
}
}
return list;
}
/* Warning */
/* link MUST be part of list */
LList *l_list_remove_link(LList * list, const LList * link)
{
if (!link)
return list;
if (link->next)
link->next->prev = link->prev;
if (link->prev)
link->prev->next = link->next;
if (link == list)
list = link->next;
/* link->prev = link->next = NULL; */
return list;
}
int l_list_length(LList * list)
{
int retval = 0;
LList *n = list;
for (n = list; n != NULL; n = n->next) {
retval++;
}
return retval;
}
LList *l_list_copy(LList * list)
{
LList *n;
LList *copy = NULL;
for (n = list; n != NULL; n = n->next) {
copy = l_list_append(copy, n->data);
}
return copy;
}
void l_list_free_1(LList * list)
{
free(list);
}
void l_list_free(LList * list)
{
LList *n = list;
while (n != NULL) {
LList *next = n->next;
free(n);
n = next;
}
}
LList *l_list_find_custom(LList * list, void *data, LListCompFunc comp)
{
LList *l;
for (l = list; l; l = l->next)
if (comp(l->data, (const void *) data) == 0)
return l;
return NULL;
}
--- NEW FILE: llist.h ---
/*
* llist.h: linked list routines
*
* Some code copyright (C) 2002-2003, Philip S Tellis <philip . tellis AT gmx .
net>
* Other code copyright Meredydd Luff <meredydd AT everybuddy.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* This is a replacement for the GList. It only provides functions that
* we use in Ayttm. Thanks to Meredyyd from everybuddy dev for doing
* most of it.
*/
#ifndef __LLIST_H__
#define __LLIST_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _LList {
struct _LList *next;
struct _LList *prev;
void *data;
} LList;
typedef int (*LListCompFunc) (const void *, const void *);
LList *l_list_append(LList * list, void *data);
LList *l_list_remove_link(LList * list, const LList * link);
LList *l_list_remove(LList * list, void *data);
LList *l_list_copy(LList * list);
void l_list_free_1(LList * list);
void l_list_free(LList * list);
int l_list_length(LList * list);
LList *l_list_find_custom(LList * list, void *data, LListCompFunc comp);
#ifdef __cplusplus
}
#endif
#endif
--- NEW FILE: mem_util.c ---
/*
* mem_util.c: memory handling utility functions
*
* taken from libyahoo2
*
* Copyright (C) 2002, Philip S Tellis <philip . tellis AT gmx . net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if STDC_HEADERS
# include <string.h>
#else
# if !HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
char *strchr (), *strrchr ();
# if !HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# define memmove(d, s, n) bcopy ((s), (d), (n))
# endif
#endif
#include "mem_util.h"
char * ay_string_append(char * string, char * append)
{
int size = strlen(string) + strlen(append) + 1;
char * new_string = ay_renew(char, string, size);
if(new_string == NULL) {
new_string = ay_new(char, size);
strcpy(new_string, string);
ay_free(string);
}
strcat(new_string, append);
return new_string;
}
char * ay_str_to_utf8(const char *in)
{
unsigned int n, i = 0;
char *result = NULL;
if(in == NULL || *in == '\0')
return "";
result = ay_new(char, strlen(in) * 2 + 1);
/* convert a string to UTF-8 Format */
for (n = 0; n < strlen(in); n++) {
unsigned char c = (unsigned char)in[n];
if (c < 128) {
result[i++] = (char) c;
} else {
result[i++] = (char) ((c >> 6) | 192);
result[i++] = (char) ((c & 63) | 128);
}
}
result[i] = '\0';
return result;
}
char * ay_utf8_to_str(const char *in)
{
int i = 0;
unsigned int n;
char *result = NULL;
if(in == NULL || *in == '\0')
return "";
result = ay_new(char, strlen(in) + 1);
/* convert a string from UTF-8 Format */
for (n = 0; n < strlen(in); n++) {
unsigned char c = in[n];
if (c < 128) {
result[i++] = (char) c;
} else {
result[i++] = (c << 6) | (in[++n] & 63);
}
}
result[i] = '\0';
return result;
}
#if !HAVE_GLIB
void ay_strfreev(char ** vector)
{
char **v;
for(v = vector; *v; v++) {
ay_free(*v);
}
ay_free(vector);
}
char ** ay_strsplit(char * str, char * sep, int nelem)
{
char ** vector;
char *s, *p;
int i=0;
int l = strlen(sep);
if(nelem < 0) {
char * s;
nelem=0;
for(s=strstr(str, sep); s; s=strstr(s+l, sep),nelem++)
;
if(strcmp(str+strlen(str)-l, sep))
nelem++;
}
vector = ay_new(char *, nelem + 1);
for(p=str, s=strstr(p,sep); i<nelem && s; p=s+l, s=strstr(p,sep), i++) {
int len = s-p;
vector[i] = ay_new(char, len+1);
strncpy(vector[i], p, len);
vector[i][len] = '\0';
}
if(i<nelem) /* str didn't end with sep */
vector[i++] = strdup(p);
vector[i] = NULL;
return vector;
}
void * ay_memdup(const void * addr, int n)
{
void * new_chunk = malloc(n);
if(new_chunk)
memcpy(new_chunk, addr, n);
return new_chunk;
}
#endif
--- NEW FILE: mem_util.h ---
/*
* mem_util.h: memory handling utility functions
*
* taken from libyahoo2
*
* Copyright (C) 2002, Philip S Tellis <philip . tellis AT gmx . net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __MEM_UTIL_H__
#define __MEM_UTIL_H__
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if HAVE_GLIB
# include <glib.h>
# define ay_free(x) if(x) {g_free(x); x=NULL;}
# define ay_new g_new
# define ay_new0 g_new0
# define ay_renew g_renew
# define ay_memdup g_memdup
# define ay_strsplit g_strsplit
# define ay_strfreev g_strfreev
# ifndef strdup
# define strdup g_strdup
# endif
# ifndef strncasecmp
# define strncasecmp g_strncasecmp
# define strcasecmp g_strcasecmp
# endif
# define snprintf g_snprintf
# define vsnprintf g_vsnprintf
#else
/* No glib - we use our own */
# include <stdlib.h>
# include <stdarg.h>
# define ay_free(x) if(x) {free(x); x=NULL;}
# define ay_new(type, n) (type *)malloc(sizeof(type) * (n))
# define ay_new0(type, n) (type *)calloc((n), sizeof(type))
# define ay_renew(type, mem, n) (type *)realloc(mem, n)
void * ay_memdup(const void * addr, int n);
char ** ay_strsplit(char * str, char * sep, int nelem);
void ay_strfreev(char ** vector);
int strncasecmp(const char * s1, const char * s2, size_t n);
int strcasecmp(const char * s1, const char * s2);
char * strdup(const char *s);
int snprintf(char *str, size_t size, const char *format, ...);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef MAX
#define MAX(x,y) ((x)>(y)?(x):(y))
#endif
/*
* The following three functions return newly allocated memory.
* You must free it yourself
*/
char * ay_string_append(char * str, char * append);
char * ay_str_to_utf8(const char * in);
char * ay_utf8_to_str(const char * in);
#endif
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Makefile.am 20 Jan 2003 12:33:44 -0000 1.15
+++ Makefile.am 23 Jan 2003 06:06:40 -0000 1.16
@@ -8,7 +8,7 @@
trigger.c console_session.c gtk_eb_html.c input_list.c nomodule.c \
plugin_api.c plugin.c file_select.c extgtktext.c contact_actions.c \
smileys.c help_menu.c crash.c account_parser.y account_scanner.l \
- contact_parser.y contact_scanner.l
+ contact_parser.y contact_scanner.l llist.c mem_util.c
noinst_HEADERS = account.h service.h contact.h gtk_globals.h globals.h \
status.h info_window.h chat_window.h util.h add_contact_window.h \
@@ -18,7 +18,7 @@
gtk_eb_html.h browser.h input_list.h plugin.h plugin_api.h debug.h \
nomodule.h file_select.h extgtktext.h contact_actions.h \
smileys.h intl.h account_parser.h contact_parser.h crash.h \
- externs.h
+ externs.h llist.h mem_util.h
EXTRA_DIST =
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Ayttm-commits] CVS: ayttm/src llist.c,NONE,1.1 llist.h,NONE,1.1 mem_util.c,NONE,1.1 mem_util.h,NONE,1.1 Makefile.am,1.15,1.16,
Philip S Tellis <address@hidden> <=
- Prev by Date:
[Ayttm-commits] CVS: ayttm/modules/yahoo2 Makefile.am,1.4,1.5 yahoo.c,1.18,1.19
- Next by Date:
[Ayttm-commits] CVS: ayttm ChangeLog,1.181,1.182 configure.in,1.177,1.178
- Previous by thread:
[Ayttm-commits] CVS: ayttm/modules/yahoo2 Makefile.am,1.4,1.5 yahoo.c,1.18,1.19
- Next by thread:
[Ayttm-commits] CVS: ayttm ChangeLog,1.181,1.182 configure.in,1.177,1.178
- Index(es):