Artifact
28303e0786570a853699b57606a394774790847e :
File
c/common.h
— part of check-in
[0ad5ae5e3d]
at
2011-08-16 19:20:58
on branch work-for-critcl-3
— Split the "crimp::core" package off "crimp". The core provides the common data structures, their acessors, and globally useful utility macros. "crimp" now is the collection of algorithms, plus handling of basic file formats (ppm, pgm). Modified "crimp::tk" to use the new core, beyond it stays the collection of the Tk dependent parts, with Tk photo images a pseudo-file format we can read from and write to. Plans: Extended the core with buffer management and functions to help with the processing of file formats, then write handlers for BMP and GIF, as separate packages, then split the basic file format handling off "crimp" as well.
(user:
andreask
size: 1510)
[more...]
0000: 23 69 66 6e 64 65 66 20 43 52 49 4d 50 5f 43 4f #ifndef CRIMP_CO
0010: 4d 4d 4f 4e 5f 48 0a 23 64 65 66 69 6e 65 20 43 MMON_H.#define C
0020: 52 49 4d 50 5f 43 4f 4d 4d 4f 4e 5f 48 0a 2f 2a RIMP_COMMON_H./*
0030: 0a 20 2a 20 43 52 49 4d 50 20 3a 3a 20 43 6f 6d . * CRIMP :: Com
0040: 6d 6f 6e 20 44 65 63 6c 61 72 61 74 69 6f 6e 73 mon Declarations
0050: 20 3a 3a 20 50 55 42 4c 49 43 0a 20 2a 20 28 43 :: PUBLIC. * (C
0060: 29 20 32 30 31 31 2e 0a 20 2a 2f 0a 0a 23 64 65 ) 2011.. */..#de
0070: 66 69 6e 65 20 43 52 49 4d 50 5f 52 41 4e 47 45 fine CRIMP_RANGE
0080: 4f 4b 28 69 2c 6e 29 20 28 28 30 20 3c 3d 20 28 OK(i,n) ((0 <= (
0090: 69 29 29 20 26 26 20 28 69 20 3c 20 28 6e 29 29 i)) && (i < (n))
00a0: 29 0a 0a 2f 2a 0a 20 2a 20 43 6f 6e 76 65 6e 69 )../*. * Conveni
00b0: 65 6e 74 20 63 68 65 63 6b 69 6e 67 20 6f 66 20 ent checking of
00c0: 69 6d 61 67 65 20 74 79 70 65 73 2e 0a 20 2a 2f image types.. */
00d0: 0a 0a 23 64 65 66 69 6e 65 20 43 52 49 4d 50 5f ..#define CRIMP_
00e0: 41 53 53 45 52 54 5f 49 4d 47 54 59 50 45 28 69 ASSERT_IMGTYPE(i
00f0: 6d 61 67 65 2c 69 6d 74 79 70 65 29 20 5c 0a 20 mage,imtype) \.
0100: 20 20 20 43 52 49 4d 50 5f 41 53 53 45 52 54 20 CRIMP_ASSERT
0110: 28 28 69 6d 61 67 65 29 2d 3e 69 74 79 70 65 20 ((image)->itype
0120: 3d 3d 20 63 72 69 6d 70 5f 69 6d 61 67 65 74 79 == crimp_imagety
0130: 70 65 5f 66 69 6e 64 20 28 22 63 72 69 6d 70 3a pe_find ("crimp:
0140: 3a 69 6d 61 67 65 3a 3a 22 20 43 52 49 4d 50 5f :image::" CRIMP_
0150: 53 54 52 28 69 6d 74 79 70 65 29 29 2c 20 5c 0a STR(imtype)), \.
0160: 09 20 20 20 20 22 65 78 70 65 63 74 65 64 20 69 . "expected i
0170: 6d 61 67 65 20 74 79 70 65 20 22 20 43 52 49 4d mage type " CRIM
0180: 50 5f 53 54 52 28 69 6d 74 79 70 65 29 29 0a 0a P_STR(imtype))..
0190: 23 64 65 66 69 6e 65 20 43 52 49 4d 50 5f 41 53 #define CRIMP_AS
01a0: 53 45 52 54 5f 4e 4f 54 49 4d 47 54 59 50 45 28 SERT_NOTIMGTYPE(
01b0: 69 6d 61 67 65 2c 69 6d 74 79 70 65 29 20 5c 0a image,imtype) \.
01c0: 20 20 20 20 43 52 49 4d 50 5f 41 53 53 45 52 54 CRIMP_ASSERT
01d0: 20 28 28 69 6d 61 67 65 29 2d 3e 69 74 79 70 65 ((image)->itype
01e0: 20 21 3d 20 63 72 69 6d 70 5f 69 6d 61 67 65 74 != crimp_imaget
01f0: 79 70 65 5f 66 69 6e 64 20 28 22 63 72 69 6d 70 ype_find ("crimp
0200: 3a 3a 69 6d 61 67 65 3a 3a 22 20 43 52 49 4d 50 ::image::" CRIMP
0210: 5f 53 54 52 28 69 6d 74 79 70 65 29 29 2c 20 5c _STR(imtype)), \
0220: 0a 09 20 20 20 20 22 75 6e 65 78 70 65 63 74 65 .. "unexpecte
0230: 64 20 69 6d 61 67 65 20 74 79 70 65 20 22 20 43 d image type " C
0240: 52 49 4d 50 5f 53 54 52 28 69 6d 74 79 70 65 29 RIMP_STR(imtype)
0250: 29 0a 0a 2f 2a 0a 20 2a 20 41 73 73 65 72 74 69 )../*. * Asserti
0260: 6f 6e 73 20 73 75 70 70 6f 72 74 20 69 6e 20 67 ons support in g
0270: 65 6e 65 72 61 6c 2c 20 61 6e 64 20 61 73 73 65 eneral, and asse
0280: 72 74 69 6e 67 20 74 68 65 20 70 72 6f 70 65 72 rting the proper
0290: 20 72 61 6e 67 65 20 6f 66 20 61 6e 20 61 72 72 range of an arr
02a0: 61 79 0a 20 2a 20 69 6e 64 65 78 20 65 73 70 65 ay. * index espe
02b0: 63 69 61 6c 6c 79 2e 0a 20 2a 2f 0a 0a 23 75 6e cially.. */..#un
02c0: 64 65 66 20 20 43 52 49 4d 50 5f 44 45 42 55 47 def CRIMP_DEBUG
02d0: 20 20 20 2f 2a 20 46 75 74 75 72 65 3a 20 63 6f /* Future: co
02e0: 6e 74 72 6f 6c 6c 65 64 20 62 79 20 61 20 75 73 ntrolled by a us
02f0: 65 72 2d 73 70 65 63 69 66 69 65 64 20 63 72 69 er-specified cri
0300: 74 63 6c 20 6f 70 74 69 6f 6e 20 2a 2f 0a 23 64 tcl option */.#d
0310: 65 66 69 6e 65 20 43 52 49 4d 50 5f 44 45 42 55 efine CRIMP_DEBU
0320: 47 20 31 20 2f 2a 20 2a 2f 0a 0a 23 69 66 64 65 G 1 /* */..#ifde
0330: 66 20 43 52 49 4d 50 5f 44 45 42 55 47 0a 23 64 f CRIMP_DEBUG.#d
0340: 65 66 69 6e 65 20 43 52 49 4d 50 5f 58 53 54 52 efine CRIMP_XSTR
0350: 28 78 29 20 23 78 0a 23 64 65 66 69 6e 65 20 43 (x) #x.#define C
0360: 52 49 4d 50 5f 53 54 52 28 78 29 20 43 52 49 4d RIMP_STR(x) CRIM
0370: 50 5f 58 53 54 52 28 78 29 0a 23 64 65 66 69 6e P_XSTR(x).#defin
0380: 65 20 43 52 49 4d 50 5f 41 53 53 45 52 54 28 78 e CRIMP_ASSERT(x
0390: 2c 6d 73 67 29 20 69 66 20 28 21 28 78 29 29 20 ,msg) if (!(x))
03a0: 7b 20 54 63 6c 5f 50 61 6e 69 63 20 28 6d 73 67 { Tcl_Panic (msg
03b0: 20 22 20 28 22 20 23 78 20 22 29 2c 20 69 6e 20 " (" #x "), in
03c0: 66 69 6c 65 20 22 20 5f 5f 46 49 4c 45 5f 5f 20 file " __FILE__
03d0: 22 20 40 6c 69 6e 65 20 22 20 43 52 49 4d 50 5f " @line " CRIMP_
03e0: 53 54 52 28 5f 5f 4c 49 4e 45 5f 5f 29 29 3b 7d STR(__LINE__));}
03f0: 0a 23 64 65 66 69 6e 65 20 43 52 49 4d 50 5f 41 .#define CRIMP_A
0400: 53 53 45 52 54 5f 42 4f 55 4e 44 53 28 69 2c 6e SSERT_BOUNDS(i,n
0410: 29 20 43 52 49 4d 50 5f 41 53 53 45 52 54 20 28 ) CRIMP_ASSERT (
0420: 43 52 49 4d 50 5f 52 41 4e 47 45 4f 4b 28 69 2c CRIMP_RANGEOK(i,
0430: 6e 29 2c 22 61 72 72 61 79 20 69 6e 64 65 78 20 n),"array index
0440: 6f 75 74 20 6f 66 20 62 6f 75 6e 64 73 3a 20 22 out of bounds: "
0450: 20 43 52 49 4d 50 5f 53 54 52 28 69 29 20 22 20 CRIMP_STR(i) "
0460: 3e 20 22 20 43 52 49 4d 50 5f 53 54 52 28 6e 29 > " CRIMP_STR(n)
0470: 29 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 ).#else.#define
0480: 43 52 49 4d 50 5f 41 53 53 45 52 54 28 78 2c 6d CRIMP_ASSERT(x,m
0490: 73 67 29 0a 23 64 65 66 69 6e 65 20 43 52 49 4d sg).#define CRIM
04a0: 50 5f 41 53 53 45 52 54 5f 42 4f 55 4e 44 53 28 P_ASSERT_BOUNDS(
04b0: 69 2c 6e 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a i,n).#endif../*.
04c0: 20 2a 20 48 65 61 70 20 61 6c 6c 6f 63 61 74 69 * Heap allocati
04d0: 6f 6e 20 68 65 6c 70 65 72 73 2e 0a 20 2a 2f 0a on helpers.. */.
04e0: 0a 23 64 65 66 69 6e 65 20 43 52 49 4d 50 5f 41 .#define CRIMP_A
04f0: 4c 4c 4f 43 28 74 79 70 65 29 20 20 20 20 20 20 LLOC(type)
0500: 20 20 20 28 28 74 79 70 65 20 2a 29 20 63 6b 61 ((type *) cka
0510: 6c 6c 6f 63 20 28 73 69 7a 65 6f 66 20 28 74 79 lloc (sizeof (ty
0520: 70 65 29 29 29 0a 23 64 65 66 69 6e 65 20 43 52 pe))).#define CR
0530: 49 4d 50 5f 41 4c 4c 4f 43 5f 41 52 52 41 59 28 IMP_ALLOC_ARRAY(
0540: 6e 2c 74 79 70 65 29 20 28 28 74 79 70 65 20 2a n,type) ((type *
0550: 29 20 63 6b 61 6c 6c 6f 63 20 28 28 6e 29 20 2a ) ckalloc ((n) *
0560: 20 73 69 7a 65 6f 66 20 28 74 79 70 65 29 29 29 sizeof (type)))
0570: 0a 0a 0c 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 6c 20 ..../*. * Local
0580: 56 61 72 69 61 62 6c 65 73 3a 0a 20 2a 20 6d 6f Variables:. * mo
0590: 64 65 3a 20 63 0a 20 2a 20 63 2d 62 61 73 69 63 de: c. * c-basic
05a0: 2d 6f 66 66 73 65 74 3a 20 34 0a 20 2a 20 66 69 -offset: 4. * fi
05b0: 6c 6c 2d 63 6f 6c 75 6d 6e 3a 20 37 38 0a 20 2a ll-column: 78. *
05c0: 20 45 6e 64 3a 0a 20 2a 2f 0a 23 65 6e 64 69 66 End:. */.#endif
05d0: 20 2f 2a 20 43 52 49 4d 50 5f 43 4f 4d 4d 4f 4e /* CRIMP_COMMON
05e0: 5f 48 20 2a 2f 0a _H */.