summary refs log blame commit diff stats
path: root/rod/c2nim/tests/systest.c
blob: 528ae89e3c66f95bf39a40d4fe3711b664976bb6 (plain) (tree)
1
2
3
4
5
6
7
8
9
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450








                                         

                                  
                             
 




















































































































































































































































































































































































































































                                                                                 
/* This file has been written by Blablub.
 *
 * Another comment line.
 */

#ifdef __cplusplus
extern "C" {
#endif

typedef char gchar;
typedef unsigned int gunsignedint;
typedef unsigned char guchar;

point* newPoint(void) {  
  for (int i = 0; i < 89; ++i) echo("test" " string "  "concatenation");
  for (; j < 54; j++) {}
  for (;; j--) ;
  for (;;) {}
  mytype * x = y * z;
 
  if (**p == ' ') {
    --p;
  } else if (**p == '\t') {
    p += 3;
  } else {
    p = 45 + (mytype*)45;
    p = 45 + ((mytype*)45);
    p = 45 + ((mytype)45);
  }

  while (x >= 6 && x <= 20) 
    --x;
  
  switch (*p) {
    case 'A'...'Z':
    case 'a'...'z':
      ++p;
      break;
    case '0':
      ++p;
      break;
    default:
      return NULL;
  }
}

enum {
  a1, a2 = 4, a3
};

typedef enum crazyTAG {
  x1, x2, x3 = 8, x4, x5
} myEnum, *pMyEnum;

typedef enum {
  x1, x2, x3 = 8, x4, x5
} myEnum, *pMyEnum;

// Test multi-line macro: 

#define MUILTILINE "abc" \ 
  "xyz" \
  "def"

#define MULTILINE(x, y) do { \
  ++y; ++x; \
} while (0)

#ifdef C2NIM
#  dynlib iupdll
#  cdecl
#  mangle "'GTK_'{.*}" "TGtk$1"
#  mangle "'PGTK_'{.*}" "PGtk$1"
#  if defined(windows)
#    define iupdll "iup.dll"
#  elif defined(macosx)
#    define iupdll "libiup.dynlib"
#  else
#    define iupdll "libiup.so"
#  endif
#endif

typedef struct stupidTAG {
  mytype a, b;
} GTK_MyStruct, *PGTK_MyStruct;

typedef struct  {
  mytype a, b;
} GTK_MyStruct, *PGTK_MyStruct;

int IupConvertXYToPos(PIhandle ih, int x, int y);

#ifdef DEBUG
#  define OUT(x) printf("%s\n", x)
#else
#  define OUT(x)
#endif


  #skip EXPORT
  // does parse now!
  EXPORT int f(void);
  EXPORT int g(void); 

#  define abc 34
#  define xyz 42

#  define wuseldusel "my string\nconstant"

#undef ignoreThis

char* x;

typedef struct {
  char x, y, *z;
} point;

char* __stdcall printf(char* frmt, const char* const** ptrToStrArray,
             const int* const dummy, ...);

inline char* myinlineProc(char* frmt, const char* const* strArray,
             const int* const dummy, ...);

// Test void parameter list:
void myVoidProc(void);

void emptyReturn(void) { return; }

// POSIX stuff:

#ifdef C2NIM
#prefix posix_
int c2nimBranch;
#elif defined(MACOSX)
int* x, y, z;
#else
int dummy;
#endif

#ifndef C2NIM
int dontTranslateThis;
#elif defined(Windows)
int WindowsTrue = true;
#endif

int   posix_spawn(pid_t *restrict, const char *restrict,
          const posix_spawn_file_actions_t *,
          const posix_spawnattr_t *restrict, char *const [restrict],
          char *const [restrict]);
int   posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
          int);
int   posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *,
          int, int);
int   posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict,
          int, const char *restrict, int, mode_t);
int   posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
int   posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
int   posix_spawnattr_destroy(posix_spawnattr_t *);
int   posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict,
          sigset_t *restrict);
int   posix_spawnattr_getflags(const posix_spawnattr_t *restrict,
          short *restrict);
int   posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict,
          pid_t *restrict);
int   posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict,
          struct sched_param *restrict);
int   posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict,
          int *restrict);
int   posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict,
          sigset_t *restrict);
int   posix_spawnattr_init(posix_spawnattr_t *);
int   posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict,
          const sigset_t *restrict);
int   posix_spawnattr_setflags(posix_spawnattr_t *, short);
int   posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);


int   posix_spawnattr_setschedparam(posix_spawnattr_t *restrict,
          const struct sched_param *restrict);
int   posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
int   posix_spawnattr_setsigmask(posix_spawnattr_t *restrict,
          const sigset_t *restrict);
int   posix_spawnp(pid_t *restrict, const char *restrict,
          const posix_spawn_file_actions_t *,
          const posix_spawnattr_t *restrict,
          char *const [restrict], char *const [restrict]);

typedef struct
{
  float R, G, B;
}
RGBType;
typedef struct
{
  float H, W, B;
}
HWBType;

static HWBType *
RGB_to_HWB (RGBType RGB, HWBType * HWB)
{

  /*
   * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is  
   * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.  
   */

  float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
  int i;

  w = MIN3 (R, G, B);
  v = MAX3 (R, G, B);
  b &= 1 - v;
  if (v == w)
    RETURN_HWB (HWB_UNDEFINED, w, b);
  f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
  i = (R == w) ? 3 : ((G == w) ? 5 : 1);
  RETURN_HWB (i - f / (v - w), w, b);

}

static int
clip_1d (int *x0, int *y0, int *x1, int *y1, int mindim, int maxdim)
{
  double m;                        // gradient of line
  if (*x0 < mindim)
    {                                // start of line is left of window 
      if (*x1 < mindim) // as is the end, so the line never cuts the window 
        return 0;
      m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line
      // adjust x0 to be on the left boundary (ie to be zero), and y0 to match 
      *y0 -= m * (*x0 - mindim);
      *x0 = mindim;
      // now, perhaps, adjust the far end of the line as well
      if (*x1 > maxdim)
        {
          *y1 += m * (maxdim - *x1);
          *x1 = maxdim;
        }
      return 1;
    }
  if (*x0 > maxdim)
    { // start of line is right of window - complement of above 
      if (*x1 > maxdim) // as is the end, so the line misses the window 
        return 0;
      m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line
      *y0 += m * (maxdim - *x0);        // adjust so point is on the right
                                        // boundary
      *x0 = maxdim;
      // now, perhaps, adjust the end of the line
      if (*x1 < mindim)
        {
          *y1 -= m * (*x1 - mindim);
          *x1 = mindim;
        }
      return 1;
    }
  // the final case - the start of the line is inside the window
  if (*x1 > maxdim)
    {                                // other end is outside to the right
      m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of the line 
      *y1 += m * (maxdim - *x1);
      *x1 = maxdim;
      return 1;
    }
  if (*x1 < mindim)
    {                                // other end is outside to the left 
      m = (*y1 - *y0) / (double) (*x1 - *x0); // calculate the slope of line 
             *y1 -= m * (*x1 - mindim);
      *x1 = mindim;
      return 1;
    }
  // only get here if both points are inside the window
  return 1;
}

// end of line clipping code

static void
gdImageBrushApply (gdImagePtr im, int x, int y)
{
  int lx, ly;
  int hy;
  int hx;
  int x1, y1, x2, y2;
  int srcx, srcy;
  if (!im->brush)
    {
      return;
    }
  hy = gdImageSY (im->brush) / 2;
  y1 = y - hy;
  y2 = y1 + gdImageSY (im->brush);
  hx = gdImageSX (im->brush) / 2;
  x1 = x - hx;
  x2 = x1 + gdImageSX (im->brush);
  srcy = 0;
  if (im->trueColor)
    {
      if (im->brush->trueColor)
        {
          for (ly = y1; (ly < y2); ly++)
            {
              srcx = 0;
              for (lx = x1; (lx < x2); lx++)
                {
                  int p;
                  p = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
                  // 2.0.9, Thomas Winzig: apply simple full transparency
                  if (p != gdImageGetTransparent (im->brush))
                    {
                      gdImageSetPixel (im, lx, ly, p);
                    }
                  srcx++;
                }
              srcy++;
            }
        }
      else
        {
          // 2.0.12: Brush palette, image truecolor (thanks to Thorben Kundinger
          // for pointing out the issue)
          for (ly = y1; (ly < y2); ly++)
            {
              srcx = 0;
              for (lx = x1; (lx < x2); lx++)
                {
                  int p, tc;
                  p = gdImageGetPixel (im->brush, srcx, srcy);
                  tc = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
                  // 2.0.9, Thomas Winzig: apply simple full transparency 
                  if (p != gdImageGetTransparent (im->brush))
                    {
                      gdImageSetPixel (im, lx, ly, tc);
                    }
                  srcx++;
                }
              srcy++;
            }
        }
    }
  else
    {
      for (ly = y1; (ly < y2); ly++)
        {
          srcx = 0;
          for (lx = x1; (lx < x2); lx++)
            {
              int p;
              p = gdImageGetPixel (im->brush, srcx, srcy);
              // Allow for non-square brushes!
              if (p != gdImageGetTransparent (im->brush))
                {
                  // Truecolor brush. Very slow
                  // on a palette destination.
                  if (im->brush->trueColor)
                    {
                      gdImageSetPixel (im, lx, ly,
                                       gdImageColorResolveAlpha(im,
                                       gdTrueColorGetRed(p),
                                       gdTrueColorGetGreen(p),
                                       gdTrueColorGetBlue(p),
                                       gdTrueColorGetAlpha(p)));
                    }
                  else
                    {
                      gdImageSetPixel (im, lx, ly, im->brushColorMap[p]);
                    }
                }
              srcx++;
            }
          srcy++;
        }
    } 
}


void gdImageSetPixel (gdImagePtr im, int x, int y, int color)
{
  int p;
  switch (color)
    {
    case gdStyled:
      if (!im->style)
        {
          // Refuse to draw if no style is set.
          return;
        }
      else
        {
          p = im->style[im->stylePos++];
        }
      if (p != (gdTransparent))
        {
          gdImageSetPixel (im, x, y, p);
        }
      im->stylePos = im->stylePos % im->styleLength;
      break;
    case gdStyledBrushed:
      if (!im->style)
        {
          // Refuse to draw if no style is set.
          return;
        }
      p = im->style[im->stylePos++];
      if ((p != gdTransparent) && (p != 0))
        {
          gdImageSetPixel (im, x, y, gdBrushed);
        }
      im->stylePos = im->stylePos % im->styleLength;
      break;
    case gdBrushed:
      gdImageBrushApply (im, x, y);
      break;
    case gdTiled:
      gdImageTileApply (im, x, y);
      break;
    case gdAntiAliased:
      // This shouldn't happen (2.0.26) because we just call
      // gdImageAALine now, but do something sane.
      gdImageSetPixel(im, x, y, im->AA_color);
      break;
    default:
      if (gdImageBoundsSafeMacro (im, x, y))
        {
          if (im->trueColor)
            {
              if (im->alphaBlendingFlag)
                {
                  im->tpixels[y][x] = gdAlphaBlend (im->tpixels[y][x], color);
                }
              else
                {
                  im->tpixels[y][x] = color;
                }
            }
          else
            {
              im->pixels[y][x] = color;
            }
        }
      break;
    }
}

#ifdef __cplusplus
}
#endif