Added compatibility for PAF 4.
[gedcom-parse.git] / t / src / portability.c
1 /* Test program for the Gedcom library.
2    Copyright (C) 2001, 2002 The Genes Development Team
3    This file is part of the Gedcom parser library.
4    Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
5
6    The Gedcom parser library is free software; you can redistribute it
7    and/or modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The Gedcom parser library is distributed in the hope that it will be
12    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the Gedcom parser library; if not, write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #include <string.h>
25 #include "config.h"
26
27 char* null_str = "(null)";
28 char* non_null_ptr = "0x<non-null>";
29 char* null_ptr = "0x<null>";
30
31 char* str_val(char* input)
32 {
33   if (input)
34     return input;
35   else
36     return null_str;
37 }
38
39 char* ptr_val(void* ptr)
40 {
41   if (ptr)
42     return non_null_ptr;
43   else
44     return null_ptr;
45 }
46
47 long int void_ptr_to_int(void* ptr)
48 {
49   long int i;
50 #if SIZEOF_VOID_P == 4
51     i = (int)ptr;
52 #else
53 # if SIZEOF_VOID_P == 8
54     i = (long int)ptr;
55 # else
56 #  error "Unhandled case for size of void pointer!"
57 # endif
58 #endif
59   return i;
60 }
61
62 void* int_to_void_ptr(int i)
63 {
64 #if SIZEOF_VOID_P == 4
65     int t;
66 #else
67 # if SIZEOF_VOID_P == 8
68     long int t;
69 # else
70 #  error "Unhandled case for size of void pointer!"
71 # endif
72 #endif
73   t = i;
74   return (void*)t;
75 }
76
77 char* simple_base_name(char* filename)
78 {
79   char* runner = NULL;
80   if (filename) {
81     runner = filename + strlen(filename) - 1;
82     while (runner != filename && *(runner-1) != '/') runner--;
83   }
84   return runner;
85 }