Project

General

Profile

« Previous | Next » 

Revision 2401

Added by stephane about 13 years ago

UTILS_G
- first commit

View differences:

include/scol_plugin_win.h
1
/*! \file scol.h
2
*	\brief Scol plugin definition API
3
*   \author Sylvain HUET
4
*/
5

  
6
/*
7
// Modifications History
8
//
9
//$ LB (13/06/2002) : added the OBJgetNewHandler function to the cbmachine
10
// $ IRI (19/12/2010) : version windows
11
// $ IRI (31/01/2011) : add MMneedMemory
12
*/
13

  
14
#ifdef __cplusplus
15
extern "C" {
16
#endif
17

  
18
#ifndef SCOLPLUGIN_H
19
#define SCOLPLUGIN_H
20

  
21
#include <windows.h>
22

  
23
#include <stdio.h>
24
#include <stdlib.h>
25

  
26

  
27
/* DEFINITIONS DE TYPES ET DE CONSTANTES
28
  ---------------------------------------*/
29
#define SizeWord 4
30
#define SizeHeader 3
31

  
32
#define NIL -1
33

  
34
/* Scol virtual machine */
35
struct Mmachine
36
{
37
  int *tape;     /* tape pointer                */
38
  int sizetape;  /* size of the tape            */
39
  int pp;        /* stack pointer               */
40
  int maxpp;     /* max value of pp             */
41
  int topheap;   /* top of stack                */
42
  int sigGC;     /* GC activation distance      */
43
  int h;         /* current header position     */
44
  int err;
45
  int *top;		 /* top of tape */
46
  /*$BLG - v5.22: Add*/
47
  int lckdGC;	 /* Locked GC flag*/
48
};
49

  
50
typedef struct Mmachine *mmachine;
51

  
52
/* masq for MMmalloc : object table or other buffer */
53
#define TYPETAB 1
54
#define TYPEBUF 0
55

  
56
/* errors definition */
57
#define MERREND     1
58
#define MERROK      0
59
#define MERRMEM    -1
60
#define MERRTYP    -2
61
#define MERRRET    -3
62
#define MERRNUL    -4
63
#define MERRNF     -5
64
#define MERRLINK   -6
65
#define MERRFULL   -7
66
#define MERRUNKNOWN -8
67
#define MERRTOOLARGE -9
68
#define MERREP        -10
69
#define MERRFILE      -11
70
#define MERRCLOSE     -12
71
/*$BLG - v5.22: Add*/
72
#define MERRCHNLDWN   -13
73

  
74
/* offsets object definition */
75
#define OFFSCCUR 0
76

  
77
#define OFFOBJMAG   0
78
#define OFFOBJCHN   1
79
#define OFFOBJTYP   2
80
#define OFFOBJHAND  3
81
#define OFFOBJTPERE 4
82
#define OFFOBJHPERE 5
83
#define OFFOBJREF0  6
84
#define OFFOBJUSER0 7
85

  
86
/* console messages mask definition */
87
#define MSKFOO     1
88
#define MSKRUNTIME 2
89
#define MSKWARNING 4
90
#define MSKTRACE   8
91
#define MSKDEBUG   16
92

  
93

  
94
/* predefined Scol types */
95
#define TYPVAR    -1
96
#define TYPCONS   -2
97
#define TYPTYPE   -3
98
#define TYPFIELD  -4
99
#define TYPSTRUC  -5
100
#define TYPCONS0  -6
101
#define TYPCOM    -7
102
#define TYPCOMV   -8
103

  
104

  
105
/* Files management in Scol
106
  ------------------------------*/
107

  
108
#define SIZESIGN 1024
109

  
110
struct Packdir
111
{
112
	char path[SIZESIGN];		/* end by '/'*/
113
	int quota;					/* -1: read only, 0: unlimited*/
114
	struct Packdir *next;
115
};
116
typedef struct Packdir *packdir;
117

  
118
#define TYPESNONE  0
119
#define TYPESLOGIC 1
120

  
121

  
122
/*
123
 * Exported Kernel functions to plugin
124
  ----------------------------------------------*/
125

  
126
struct CBmachine
127
{
128
  int  (*MMpush)(mmachine m, int val);
129
  int  (*MMpushNoGC)(mmachine m, int val);
130
  int  (*MMpull)(mmachine m);
131
  int  (*MMgetPP)(mmachine m);
132
  void (*MMsetPP)(mmachine m,int i);
133
  int  (*MMget)(mmachine m,int i);
134
  void (*MMset)(mmachine m,int i,int v);
135
  int  (*MMgetglobal)(mmachine m,int i);
136
  void (*MMsetglobal)(mmachine m,int i,int v);
137
  int  (*MMgetbase)(mmachine m,int b,int i);
138
  void (*MMsetbase)(mmachine m,int b,int i,int v);
139
  int  (*MMfetch)(mmachine m,int s,int i);
140
  void (*MMstore)(mmachine m,int s,int i,int v);
141
  int* (*MMstart)(mmachine m,int s);
142
  int  (*MMsize)(mmachine m,int s);
143
  int  (*MMtype)(mmachine m,int s);
144
  char* (*MMstartstr)(mmachine m,int s);
145
  int  (*MMsizestr)(mmachine m,int s);
146
  void (*MMsetsizestr)(mmachine m,int s,int size);
147
  int  (*MMmalloc)(mmachine m, int size, int type);
148
  int  (*MMmallocCLR)(mmachine m, int size, int type);
149
  int  (*Mpushstrbloc)(mmachine m,char *buf);
150
  int  (*MBdeftab)(mmachine m);
151
  int  (*MBstrcat)(mmachine m);
152
  int  (*PKhardpak)(mmachine m, char *name,
153
                   int n, char **namefun, int (**fun)(mmachine z),
154
                   int *nargfun, char **typfun);
155
  int  (*PKloader)(mmachine m,char *name,char *simplename);
156
  int  (*SPfindfile)(packdir p,char *sign,int *size,char *path);
157
  int  (*SPaddfile)(packdir p,char *sign,int size,char *path);
158
  int  (*SCgetsrvsocket)(mmachine m, int server);
159
  int  (*SCgetsocket)(mmachine m, int channel);
160
  int  (*Mcutting)(char *comm, char **argv);
161
  void (*MMechostr)(int i,char *buf,...);
162
  size_t (*fread)(void* buf,size_t i,size_t j,FILE *f);
163
  packdir Firstpack;
164
  int  (*OBJcreate)(mmachine m,int typ,int handsys,int typpere,int handsyspere);
165
  int  (*OBJaddreflex)(mmachine m,int typ, int num);
166
  int  (*OBJbeginreflex)(mmachine m,int typ,int handsys,int num);
167
  int  (*OBJdel)(mmachine m,int p,int flag);
168
  int  (*OBJdestroy)(mmachine m, int typ,int handsys,int objm,int flag);
169
  int  (*OBJdelTH)(mmachine m,int typ,int handsys);
170
  int  (*OBJcallreflex)(mmachine m,int nbarg);
171
  int  (*OBJregister)(int nbrefl,int recrefl,int (*destroy)(mmachine m,int handsys,int objm),char *name);
172
  int  (*OBJtypebyname)(char *name);
173
  int  (*OBJdefEvent)(int event,int (*cbevent)(mmachine m,int hwnd, unsigned msg,
174
				              int wParam,int lParam,int *ret));
175
  int  (*OBJgetUserEvent)();
176
  void* (*SCgetExtra)(char *funcname);
177
  char* (*stdloadJpg)(char *name,int *w,int *h);
178
  int  (*OBJdelTM)(mmachine m,int typ,int q);
179
  int  (*OBJfindTH)(mmachine m,int typ,int handsys);
180
  int  (*OBJfindTM)(mmachine m,int typ,int objm);
181
  int (*Mpushstrblocn)(mmachine m,char *buf, int n);
182
  int (*Minterpreter)(mmachine m);
183
  int (*Msearchinsyspak)(mmachine m, char *name);
184
  int (*MBstrcatn)(mmachine m);
185
  int (*Buffer2texture)(mmachine m, char *buffer, int width, int height);
186
  void (*MMputs)(int i, const char* text);
187

  
188
  /*$ LB (13/06/2002)*/
189
  int (*OBJgetNewHandler)();
190

  
191
int (*MMneedMemory)(mmachine m,int size,int realsize); /* $Iri */
192

  
193

  
194
};
195
typedef struct CBmachine *cbmachine;
196

  
197
extern cbmachine ww;
198

  
199
#define SCOLinitplugin(X) ww=X
200

  
201
#define MMpush (ww->MMpush)
202
#define MMpushNoGC (ww->MMpushNoGC)
203
#define MMpull (ww->MMpull)
204
#define MMgetPP (ww->MMgetPP)
205
#define MMsetPP (ww->MMsetPP)
206
#define MMget (ww->MMget)
207
#define MMset (ww->MMset)
208
#define MMgetglobal (ww->MMgetglobal)
209
#define MMsetglobal (ww->MMsetglobal)
210
#define MMgetbase (ww->MMgetbase)
211
#define MMsetbase (ww->MMsetbase)
212
#define MMfetch (ww->MMfetch)
213
#define MMstore (ww->MMstore)
214
#define MMstart (ww->MMstart)
215
#define MMsize (ww->MMsize)
216
#define MMtype (ww->MMtype)
217
#define MMstartstr (ww->MMstartstr)
218
#define MMsizestr (ww->MMsizestr)
219
#define MMsetsizestr (ww->MMsetsizestr)
220
#define MMmalloc (ww->MMmalloc)
221
#define MMmallocCLR (ww->MMmallocCLR)
222
#define Mpushstrbloc (ww->Mpushstrbloc)
223
#define MBdeftab (ww->MBdeftab)
224
#define MBstrcat (ww->MBstrcat)
225
#define PKhardpak (ww->PKhardpak)
226
#define PKloader (ww->PKloader)
227
#define SPfindfile (ww->SPfindfile)
228
#define SPaddfile (ww->SPaddfile)
229
#define SCgetsrvsocket (ww->SCgetsrvsocket)
230
#define SCgetsocket (ww->SCgetsocket)
231
#define Mcutting (ww->Mcutting)
232
#define MMechostr (ww->MMechostr)
233
/*#define fread (ww->fread)*/
234
#define Firstpack (ww->Firstpack)
235
#define OBJcreate (ww->OBJcreate)
236
#define OBJaddreflex (ww->OBJaddreflex)
237
#define OBJbeginreflex (ww->OBJbeginreflex)
238
#define OBJdel (ww->OBJdel)
239
#define OBJdestroy (ww->OBJdestroy)
240
#define OBJdelTH (ww->OBJdelTH)
241
#define OBJcallreflex (ww->OBJcallreflex)
242
#define OBJregister (ww->OBJregister)
243
#define OBJtypebyname (ww->OBJtypebyname)
244
#define OBJdefEvent (ww->OBJdefEvent)
245
#define OBJgetUserEvent (ww->OBJgetUserEvent)
246
#define SCgetExtra (ww->SCgetExtra)
247
#define stdloadJpg (ww->stdloadJpg)
248
#define OBJdelTM (ww->OBJdelTM)
249
#define OBJfindTH (ww->OBJfindTH)
250
#define OBJfindTM (ww->OBJfindTM)
251
#define Mpushstrblocn (ww->Mpushstrblocn)
252
#define Minterpreter (ww->Minterpreter)
253
#define Msearchinsyspak (ww->Msearchinsyspak)
254
#define MBstrcatn (ww->MBstrcatn)
255
#define Buf2Tex (ww->Buffer2texture)
256
#define MMputs (ww->MMputs)
257

  
258
/*$ LB (13/06/2002)*/
259
#define OBJgetNewHandler (ww->OBJgetNewHandler)
260

  
261
#define MMneedMemory (ww->MMneedMemory) /* $Iri */
262

  
263

  
264
#endif
265

  
include/scol_plugin_lin.h
1
/*
2
        SCOLPLUGIN.H . 1996-99 . Sylvain HUET
3

  
4
         definitions pour les plugins Scol
5
*/
6

  
7

  
8
#ifndef SCOLPLUGIN_H
9
#define SCOLPLUGIN_H
10

  
11

  
12

  
13
#include <stdio.h>
14
#include <stdlib.h>
15

  
16
/* DEFINITIONS DE TYPES ET DE CONSTANTES
17
  ---------------------------------------*/
18
/* $iri  -> */
19
#define SizeWord 4
20
#define SizeHeader 3
21
/* <- $iri */
22

  
23
#define NIL -1
24

  
25
/* machine virtuelle Scol */
26
struct Mmachine
27
{
28
  int *tape;     /* pointeur vers la bande       */
29
  int sizetape;  /* taille de la bande (en mots) */
30
  int pp;        /* pointeur de pile             */
31
  int maxpp;     /* valeur max de pp             */
32
  int topheap;   /* sommet du tas                */
33
  int sigGC;     /* distance declenchant le GC   */
34
  int h;         /* position header courant      */
35
  int err;
36
  int *top;		 /* top of tape */ /* add by  $iri */
37
};
38
typedef struct Mmachine *mmachine;
39

  
40
extern mmachine mm;
41

  
42
/* masque pour MMmalloc : tableau d'objets ou buffer quelconque */
43
#define TYPETAB 1
44
#define TYPEBUF 0
45

  
46
/* definitions des erreurs */
47
#define MERREND     1
48
#define MERROK      0
49
#define MERRMEM    -1
50
#define MERRTYP    -2
51
#define MERRRET    -3
52
#define MERRNUL    -4
53
#define MERRNF     -5
54
#define MERRLINK   -6
55
#define MERRFULL   -7
56
#define MERRUNKNOWN -8
57
#define MERRTOOLARGE -9
58

  
59
/* definition des offsets objets */
60
#define OFFOBJMAG   0
61
#define OFFOBJCHN   1
62
#define OFFOBJTYP   2
63
#define OFFOBJHAND  3
64
#define OFFOBJTPERE 4
65
#define OFFOBJHPERE 5
66
#define OFFOBJREF0  6
67
#define OFFOBJUSER0 7
68

  
69
/* definitions des masques de message console */
70
#define MSKFOO     1
71
#define MSKRUNTIME 2
72
#define MSKWARNING 4
73
#define MSKTRACE   8
74
#define MSKDEBUG   16
75

  
76

  
77
/* types Scol predefinis */
78
#define TYPVAR    -1
79
#define TYPCONS   -2
80
#define TYPTYPE   -3
81
#define TYPFIELD  -4
82
#define TYPSTRUC  -5
83
#define TYPCONS0  -6
84
#define TYPCOM    -7
85
#define TYPCOMV   -8
86

  
87

  
88
/* GESTION DES FICHIERS EN SCOL
89
  ------------------------------*/
90

  
91
#define SIZESIGN 1024
92

  
93
struct Packdir
94
{
95
  char path[SIZESIGN];  /* se termine par '/' */
96
  int quota;   /* -1: read only, 0: unlimited */
97
  struct Packdir *next;
98
};
99
typedef struct Packdir *packdir;
100

  
101
#define TYPESNONE  0
102
#define TYPESLOGIC 1
103

  
104

  
105
/* FONCTIONS DU KERNEL EXPORTEES VERS LE PLUGIN
106
  ----------------------------------------------*/
107
#ifdef __cplusplus
108
extern "C" {
109
#endif
110
int  MMpush (mmachine m, int val);
111
int  MMpushNoGC (mmachine m, int val);
112
int  MMpull(mmachine m);
113
int  MMgetPP(mmachine m);
114
void MMsetPP(mmachine m,int i);
115
int  MMget(mmachine m,int i);
116
void MMset(mmachine m,int i,int v);
117
int  MMgetglobal(mmachine m,int i);
118
void MMsetglobal(mmachine m,int i,int v);
119
int  MMgetbase(mmachine m,int b,int i);
120
void MMsetbase(mmachine m,int b,int i,int v);
121
int  MMfetch(mmachine m,int s,int i);
122
void MMstore(mmachine m,int s,int i,int v);
123
int* MMstart(mmachine m,int s);
124
int  MMsize(mmachine m,int s);
125
int  MMtype(mmachine m,int s);
126
char* MMstartstr(mmachine m,int s);
127
int  MMsizestr(mmachine m,int s);
128
void MMsetsizestr(mmachine m,int s,int size);
129
int  MMmalloc(mmachine m, int size, int type);
130
int  MMmallocCLR(mmachine m, int size, int type);
131
int  Mpushstrbloc(mmachine m,char *buf);
132
int  MBdeftab(mmachine m);
133
int  MBstrcat(mmachine m);
134
void MMechostr(int i,char *buf,...);
135
int  SPfindfile(packdir p,char *sign,int *size,char *path);
136
int  SPaddfile(packdir p,char *sign,int size,char *path);
137
int  SCgetsocket(mmachine m, int channel);
138
int  SCgetsrvsocket(mmachine m, int server);
139
int  MBstrcatn(mmachine m);
140
int  Minterpreter(mmachine m);
141
int  PKhardpak(mmachine m, char *name,
142
                 int n, char **namefun, int (**fun)(mmachine z),
143
                 int *nargfun, char **typfun);
144
int  PKloader(mmachine m,char *name,char *simplename);
145

  
146
size_t fread(void* buf,size_t i,size_t j,FILE *f);
147

  
148
int MMneedMemory(mmachine m,int size,int realsize); /* $Iri */
149
#ifdef __cplusplus
150
}
151
#endif
152

  
153

  
154

  
155
int  Mcutting(char *comm, char **argv);
156

  
157
#ifdef __cplusplus
158
extern "C" {
159
#endif
160
int  OBJcreate(mmachine m,int typ,int handsys,int typpere,int handsyspere);
161
int  OBJaddreflex(mmachine m,int typ, int num);
162
int  OBJbeginreflex(mmachine m,int typ,int handsys,int num);
163
int  OBJdel(mmachine m,int p,int flag);
164
int  OBJdestroy(mmachine m, int typ,int handsys,int objm,int flag);
165
int  OBJdelTH(mmachine m,int typ,int handsys);
166
int  OBJcallreflex(mmachine m,int nbarg);
167
int  OBJregister(int nbrefl,int recrefl,int (*destroy)(mmachine m,int handsys,int objm),char *name);
168
int  OBJtypebyname(char *name);
169
int  OBJdefEvent(int event,int (*cbevent)(mmachine m,int hwnd, unsigned msg,
170
				            int wParam,int lParam,int *ret));
171
int  OBJgetUserEvent();
172

  
173

  
174
int  OBJdelTM(mmachine m,int typ,int q);
175
int  OBJfindTH(mmachine m,int typ,int handsys);
176
int  OBJfindTM(mmachine m,int typ,int objm);
177

  
178

  
179

  
180
extern int (*mt_start)(int per,int param,int (*fun)(int i,int param));
181
extern int (*mt_del)(int i);
182
#ifdef __cplusplus
183
}
184
#endif
185
char* stdloadJpg(char *name,int *w,int *h);
186
int  Mpushstrblocn(mmachine m,char *buf, int n);
187

  
188
int  Msearchinsyspak(mmachine m, char *name);
189

  
190
int  Buffer2texture(mmachine m, char *buffer, int width, int height);
191

  
192

  
193

  
194
void* objdd_get_buffer (mmachine m, int mobj);
195
int _CRbitmap (mmachine m);
196

  
197
/* old ones
198
int (*MMpush)(mmachine m, int val);
199
int (*MMpushNoGC)(mmachine m, int val);
200
int (*MMpull)(mmachine m);
201
int (*MMgetPP)(mmachine m);
202
void (*MMsetPP)(mmachine m,int i);
203
int (*MMget)(mmachine m,int i);
204
void (*MMset)(mmachine m,int i,int v);
205
int (*MMgetglobal)(mmachine m,int i);
206
void (*MMsetglobal)(mmachine m,int i,int v);
207
int (*MMgetbase)(mmachine m,int b,int i);
208
void (*MMsetbase)(mmachine m,int b,int i,int v);
209
int (*MMfetch)(mmachine m,int s,int i);
210
void (*MMstore)(mmachine m,int s,int i,int v);
211
int* (*MMstart)(mmachine m,int s);
212
int (*MMsize)(mmachine m,int s);
213
int (*MMtype)(mmachine m,int s);
214
char* (*MMstartstr)(mmachine m,int s);
215
int (*MMsizestr)(mmachine m,int s);
216
void (*MMsetsizestr)(mmachine m,int s,int size);
217
int (*MMmalloc)(mmachine m, int size, int type);
218
int (*MMmallocCLR)(mmachine m, int size, int type);
219
int (*Mpushstrbloc)(mmachine m,char *buf);
220
int (*MBdeftab)(mmachine m);
221
int (*MBstrcat)(mmachine m);
222
int (*PKhardpak)(mmachine m, char *name,
223
              int n, char **namefun, int (**fun)(mmachine z)
224
              , int *nargfun, char **typfun);
225
int (*PKloader)(mmachine m,char *name,char *simplename);
226
int (*SPfindfile)(packdir p,char *sign,int *size,char *path);
227
int (*SPaddfile)(packdir p,char *sign,int size,char *path);
228
int (*SCgetsrvsocket)(mmachine m, int server);
229
int (*SCgetsocket)(mmachine m, int channel);
230
int (*Mcutting)(char *comm, char **argv);
231
void (*MMechostr)(int i,char *buf,...);
232
int (*fread)(char* buf,int i,int j,FILE *f);
233
packdir Firstpack;
234
int (*OBJcreate)(mmachine m,int typ,int handsys,int typpere,int handsyspere);
235
int (*OBJaddreflex)(mmachine m,int typ, int num);
236
int (*OBJbeginreflex)(mmachine m,int typ,int handsys,int num);
237
int (*OBJdel)(mmachine m,int p,int flag);
238
int (*OBJdestroy)(mmachine m, int typ,int handsys,int objm,int flag);
239
int (*OBJdelTH)(mmachine m,int typ,int handsys);
240
int (*OBJcallreflex)(mmachine m,int nbarg);
241
int (*OBJregister)(int nbrefl,int recrefl,int (*destroy)(mmachine m,int handsys,int objm),char *name);
242
int (*OBJtypebyname)(char *name);
243
int (*OBJdefEvent)(int event,int (*cbevent)(mmachine m,HWND hwnd, unsigned msg,
244
				UINT wParam,LONG lParam,int *ret));
245
int (*OBJgetUserEvent)();
246
void* (*SCgetExtra)(char *funcname);
247
char* (*stdloadJpg)(char *name,int *w,int *h);
248
int (*OBJdelTM)(mmachine m,int typ,int q);
249
int (*OBJfindTH)(mmachine m,int typ,int handsys);
250
int (*OBJfindTM)(mmachine m,int typ,int objm);
251
int (*Mpushstrblocn)(mmachine m,char *buf, int n);
252
int (*Minterpreter)(mmachine m);
253
int (*Msearchinsyspak)(mmachine m, char *name);
254
int (*MBstrcatn)(mmachine m);
255
*/
256

  
257

  
258

  
259

  
260

  
261
#endif
262

  
include/main.h
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24

  
25

  
26

  
27
#ifndef __MAIN_H__
28
#define __MAIN_H__
29

  
30

  
31
#include <stdio.h>
32
#include <stdlib.h>
33
#include <string.h>
34
#include <math.h>
35
#include <libgen.h>
36
#include <glib.h>
37

  
38
#if ((defined __WIN32__) || (defined WIN32))
39
#include <windows.h>
40
#include "scol_plugin_win.h"
41
#else
42
#include "scol_plugin_lin.h"
43
#endif
44

  
45

  
46
#include "macros.h"
47

  
48

  
49
#define bullshit int (__cdecl *)(struct Mmachine *)
50

  
51

  
52
#define DEFAULT_STRING   "Untitle"
53

  
54
#endif  /* __MAIN_H__ */
include/macros.h
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24

  
25

  
26
/*
27
// File: macros.h
28
// Temporary macros (mostly used by debugger agent)
29
// from F.J. Alberti
30
*/
31

  
32

  
33
#ifndef _MACROS_H_
34
#define _MACROS_H_
35

  
36
#define SAFEdelete(p)      { if (p) { free (p); (p) = NULL; } }
37

  
38

  
39
#define _SEPTRBIT            0x00000001
40

  
41

  
42
/* SE conversions*/
43
#define SEW2I(w)             ((w)>>1)
44
#define SEW2P(w)             ((w)>>1)
45
#define SEI2W(n)             ((n)<<1)
46
#define SEP2W(p)             ((p)<<1 | _SEPTRBIT)
47

  
48
#define MTOI( mot )			 ((mot)>>1)
49
#define MTOP( mot )		     ((mot)>>1)
50
#define ITOM( mot )			 ((mot)<<1)
51
#define PTOM( mot )			 (((mot)<<1)+1)
52
/*#ifndef SCOL_FLOAT_DEFINITION
53
typedef float          float32;
54
#define SCOL_FLOAT_DEFINITION
55
#endif*/
56

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

  
60
/*Stack management*/
61
#define SEDROP(m, n)         ((m)->pp += (n))
62

  
63
/* String management*/
64
#define SEPUSHSTR(m, s)      (Mpushstrbloc((m), (s)))
65

  
66
#define CHECK(m)			if ((tmp_res=m)) return tmp_res
67

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

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

  
83
#endif
0 84

  
include/scol_glib_pregex.h
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24
#ifndef __SCOL_GTK_MISC_H__
25
#define __SCOL_GTK_MISC_H__
26

  
27
#include "main.h"
28

  
29
#define GLIB_PCRE_PKG_NB         1
30

  
31
#endif  /* __SCOL_GTK_MISC_H__ */
include/scol_glib_misc.h
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24

  
25
#ifndef __SCOL_GLIB_MISC_H__
26
#define __SCOL_GLIB_MISC_H__
27

  
28
#include <glib.h>
29

  
30

  
31
gboolean scol_glib_isabsolutepath (const gchar * p); /* return TRUE if a path is an absolute path */
32

  
33
/* The result of these functions should NOT be freed ! */
34
const gchar * scol_glib_name_scolexe (); /* return the name of the executable (must not be modified or freed) */
35
const gchar * scol_glib_get_env (const gchar *v); /* return the value of an environment variable */
36
const gchar * scol_glib_get_hostname (); /* return the host name  (must not be modified or freed) */
37
const gchar * scol_glib_get_username (); /* return the name of the current user */
38

  
39
/* The result of these functions should be freed when it is no longer needed ! */
40
gchar * scol_glib_filename_scol ();      /* return the absolute path of the current Scol. Use g_free */
41
gchar * scol_glib_dirname_scol ();       /* return the absolute path of the directory of Scol. Use g_free */
42
gchar * scol_glib_basename (const gchar *f); /* return the basename (the file) of any path. Use g_free */
43
char * scol_glib_get_sizefordisplay (int v);    /* return a comprehensive size string. Use g_free */
44

  
45
#endif  /* __SCOL_GLIB_MISC_H__ */
src/scol_glib_pregex.c
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24

  
25
#include "../include/scol_glib_pregex.h"
src/scol_glib_misc.c
1
/*
2
This source file is part of Scol
3
For the latest info, see http://www.scolring.org
4

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

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

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

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

  
21
For others informations, please contact us from http://www.scolring.org/
22
*/
23

  
24

  
25
#include "../include/scol_glib_misc.h"
26

  
27

  
28
/**
29
 * \brief Returns the name of the executable Scol. The filename should NOT be freed
30
 * It should return "scol.exe" (or "unsmwin.exe" on the old Scol version) on MS Windows
31
 * On GNU/ Linux, it should return "scol" or "usmunix"
32
 * \return gchar * : this filename
33
 */
34
const gchar * scol_glib_name_scolexe ()
35
{
36
    return g_get_application_name ();
37
}
38

  
39
/**
40
 * \brief Returns the filename of the current Scol. The filename should be freed with g_free
41
 * \return gchar * : this filename
42
 */
43
gchar * scol_glib_filename_scol ()
44
{
45
    return g_find_program_in_path (scol_glib_name_scolexe ());
46
}
47

  
48
/**
49
 * \brief Returns the directory of the current Scol. The filename should be freed with g_free
50
 * \return gchar * : this filename
51
 */
52
gchar * scol_glib_dirname_scol ()
53
{
54
    gchar * f = scol_glib_filename_scol ();
55
    gchar * p;
56

  
57
    p = g_path_get_dirname (f);
58
    g_free (f);
59
    return p;
60
}
61

  
62
/**
63
 * \brief Returns the basename of any filename. The result should be freed with g_free
64
 * \param : const gchar * : any filename
65
 * \return gchar * : this base name
66
 */
67
gchar * scol_glib_basename (const gchar *f)
68
{
69
    return g_path_get_basename (f);
70
}
71

  
72
/**
73
 * \brief Returns the value of any environment variable or NULL if not found
74
 * \param  const gchar * : an environment variable, without "$" on Linux and without "%" on Windows
75
 * \return const gchar * : the value or NULL if not ound
76
 * This is an alias of g_getenv ()
77
 * The result should not be freed
78
 */
79
const gchar * scol_glib_get_env (const gchar *v)
80
{
81
    return g_getenv (v);
82
}
83

  
84
/**
85
 * \brief Returns the name ofthe current user
86
 * \return const gchar * : the name
87
 * This is an alias of g_get_user_name ()
88
 */
89
const gchar * scol_glib_get_username ()
90
{
91
   return g_get_user_name ();
92
}
93

  
94
/**
95
 * \brief Returns the host name. Don't free !
96
 * \return const gchar * : the result.
97
 */
98
const gchar * scol_glib_get_hostname ()
99
{
100
    return g_get_host_name ();
101
}
102

  
103
/**
104
 * \brief Returns TRUE if the given path is an absolute path, otherwise FALSE
105
 * \param const gchar * : any path
106
 * \return gboolean
107
 */
108
gboolean scol_glib_isabsolutepath (const gchar * p)
109
{
110
    return g_path_is_absolute (p);
111
}
112

  
113
/**
114
 * \brief Returns a string with an easy sizenumber (from bytes to KB, MO, ..)
115
 * \param int : an integer (by example a Scol value)
116
 * \return char *
117
 * The result should be freed with g_free
118
 */
119
char * scol_glib_get_sizefordisplay (int v)
120
{
121
    return g_format_size_for_display ((goffset) v);
122
}
123

  
124

  
125

  
bin/libutils_g.dll.def
1
EXPORTS
2
    scol_glib_basename @1
3
    scol_glib_dirname_scol @2
4
    scol_glib_filename_scol @3
5
    scol_glib_get_env @4
6
    scol_glib_get_hostname @5
7
    scol_glib_get_sizefordisplay @6
8
    scol_glib_get_username @7
9
    scol_glib_isabsolutepath @8
10
    scol_glib_name_scolexe @9
bin/Debug/libutils_g.dll.def
1
EXPORTS
2
    scol_glib_basename @1
3
    scol_glib_dirname_scol @2
4
    scol_glib_filename_scol @3
5
    scol_glib_get_env @4
6
    scol_glib_get_hostname @5
7
    scol_glib_get_sizefordisplay @6
8
    scol_glib_get_username @7
9
    scol_glib_isabsolutepath @8
10
    scol_glib_name_scolexe @9
utils_g.cbp
1
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2
<CodeBlocks_project_file>
3
	<FileVersion major="1" minor="6" />
4
	<Project>
5
		<Option title="utils_g" />
6
		<Option pch_mode="2" />
7
		<Option compiler="gcc" />
8
		<Build>
9
			<Target title="Debug">
10
				<Option output="bin\Debug\libutils_g" prefix_auto="1" extension_auto="1" />
11
				<Option object_output="obj\Debug\" />
12
				<Option type="3" />
13
				<Option compiler="gcc" />
14
				<Option createDefFile="1" />
15
				<Option createStaticLib="1" />
16
				<Compiler>
17
					<Add option="-g" />
18
				</Compiler>
19
			</Target>
20
			<Target title="Release">
21
				<Option output="bin\libutils_g" prefix_auto="1" extension_auto="1" />
22
				<Option object_output="obj\" />
23
				<Option type="3" />
24
				<Option compiler="gcc" />
25
				<Option createDefFile="1" />
26
				<Option createStaticLib="1" />
27
				<Compiler>
28
					<Add option="-O2" />
29
				</Compiler>
30
				<Linker>
31
					<Add option="-s" />
32
				</Linker>
33
			</Target>
34
		</Build>
35
		<Compiler>
36
			<Add option="-Wall" />
37
		</Compiler>
38
		<Unit filename="main.c">
39
			<Option compilerVar="CC" />
40
		</Unit>
41
		<Extensions>
42
			<code_completion />
43
			<debugger />
44
		</Extensions>
45
	</Project>
46
</CodeBlocks_project_file>

Also available in: Unified diff