]> git.sesse.net Git - vlc/blob - modules/visualization/galaktos/tree_types.c
0201222c826718054f86091e7ba8fc53f26ab366
[vlc] / modules / visualization / galaktos / tree_types.c
1 /*****************************************************************************
2  * tree_types.c:
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet <asmax@videolan.org>
8  *          code from projectM http://xmms-projectm.sourceforge.net
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <stdlib.h>
26
27 #include "common.h"
28
29 /* Compares integer value numbers in 32 bit range */
30 int compare_int(int * num1, int * num2) {
31
32         if ((*num1) < (*num2))
33                 return -1;
34         if ((*num1) > (*num2))
35                 return 1;
36         
37         return 0;
38 }
39
40 /* Compares strings in lexographical order */
41 int compare_string(char * str1, char * str2) {
42
43   //  printf("comparing \"%s\" to \"%s\"\n", str1, str2);
44   //return strcmp(str1, str2);
45   return strncmp(str1, str2, MAX_TOKEN_SIZE-1);
46         
47 }       
48
49 /* Compares a string in version order. That is, file1 < file2 < file10 */
50 int compare_string_version(char * str1, char * str2) {
51
52   return strverscmp(str1, str2);
53
54 }
55
56
57 void free_int(void * num) {
58         free(num);
59 }
60
61
62 void free_string(char * string) {
63         
64         free(string);   
65 }       
66  
67 void * copy_int(int * num) {
68         
69         int * new_num;
70         
71         if ((new_num = (int*)malloc(sizeof(int))) == NULL)
72                 return NULL;
73
74         *new_num = *num;
75         
76         return (void*)new_num;
77 }       
78
79
80 void * copy_string(char * string) {
81         
82         char * new_string;
83         
84         if ((new_string = (char*)malloc(MAX_TOKEN_SIZE)) == NULL)
85                 return NULL;
86         
87         strncpy(new_string, string, MAX_TOKEN_SIZE-1);
88         
89         return (void*)new_string;
90 }