Project

General

Profile

1
/*! \file macros.h
2
*	\brief usefull Scol macros
3
*   \author Sylvain HUET, Stephane Bisaro
4
*/
5
/*
6
This source file is part of Scol
7
For the latest info, see http://www.scolring.org
8

    
9
Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>
10

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

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

    
20
You should have received a copy of the GNU Lesser General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23
http://www.gnu.org/copyleft/lesser.txt
24

    
25
For others informations, please contact us from http://www.scolring.org/
26
*/
27

    
28

    
29

    
30
/*
31
// File: macros.h
32
// Temporary macros (mostly used by debugger agent)
33
// from F.J. Alberti
34
*/
35

    
36

    
37
#ifndef _MACROS_H_
38
#define _MACROS_H_
39

    
40
#define SAFEdelete(p)      { if (p) { free (p); (p) = NULL; } }
41

    
42

    
43
#define _SEPTRBIT            0x00000001
44

    
45

    
46
/* SE conversions*/
47
#define SEW2I(w)             ((w)>>1)
48
#define SEW2P(w)             ((w)>>1)
49
#define SEI2W(n)             ((n)<<1)
50
#define SEP2W(p)             ((p)<<1 | _SEPTRBIT)
51

    
52
#define MTOI( mot )			 ((mot)>>1)
53
#define MTOP( mot )		     ((mot)>>1)
54
#define ITOM( mot )			 ((mot)<<1)
55
#define PTOM( mot )			 (((mot)<<1)+1)
56
/*#ifndef SCOL_FLOAT_DEFINITION
57
typedef float          float32;
58
#define SCOL_FLOAT_DEFINITION
59
#endif*/
60

    
61
/* Invert two positions in the stack*/
62
#define INVERT(m, a, b)       {tmp_res=MMget(m,a);MMset(m,a,MMget(m,b));MMset(m,b,tmp_res);}
63

    
64
/*Stack management*/
65
#define SEDROP(m, n)         ((m)->pp += (n))
66

    
67
/* String management*/
68
#define SEPUSHSTR(m, s)      (Mpushstrbloc((m), (s)))
69

    
70
#define CHECK(m)			if ((tmp_res=m)) return tmp_res
71

    
72
/* #define CHAR2WCHAR(c)        (c == NIL ? NULL : (PtrObjWChar) MMstart (mm,((PtrObjVoid)MMstart(mm,c))->Buffer>>1))*/
73

    
74
/* $Iri : convert any string to utf-8 (should be used with gtk ...) Don't forget to free after used !*/
75
#define SCOLUTF8(string, len) g_locale_to_utf8 (string, len, NULL, NULL, NULL)
76
/* $Iri : convert any string from utf-8 Don't forget to free after used !*/
77
#define UTF8SCOL(string, len) g_locale_from_utf8 (string, len, NULL, NULL, NULL)
78
/* $Iri : length of the int (234 -> 3)*/
79
#define SIZEINT(x)  floor (log10 (x)) + 1
80
/* $ Iri : float support */
81
#define FSET(val, f)  {                 \
82
  float g = (f);                      \
83
  (val) = (*(int*)&g) & 0xfffffffe;     \
84
}
85
#define FGET(val)     (*(float*)&(val))
86

    
87
#endif
(1-1/9)