common.h - clic - Clic is an command line interactive client for gopher written… | |
git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
common.h (1703B) | |
--- | |
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <stdint.h> | |
4 #include <string.h> | |
5 #include <inttypes.h> | |
6 | |
7 #ifndef offsetof | |
8 #define offsetof(type, slot) ((long) ((char *) &(((type *) 0)->slot))) | |
9 #endif | |
10 #define getslot(type, slot) (((type *) 0)->slot) | |
11 #define sizeofslot(type, slot) (sizeof(getslot(type, slot))) | |
12 #define countofslot(type, slot) \ | |
13 (sizeof(getslot(type, slot)) / sizeof(getslot(type, slot)[0])) | |
14 #define stringify(x) #x | |
15 #define indirect_stringify(x) stringify(x) | |
16 | |
17 #define TYPE_SIGNED_P(type) (((type)-1)<0LL) | |
18 #define _64_BIT_VALUE_FITS_SIGNED_P(value) ( (value) <= 0x7FFFFFFFFFFFFF… | |
19 #define SLOT_SIGNED_P(result, type, slot) … | |
20 do { … | |
21 type slot_signed_p_struct; … | |
22 slot_signed_p_struct.slot = -1; … | |
23 (result) = slot_signed_p_struct.slot < 0; … | |
24 } while (0) | |
25 | |
26 void type_name(FILE *output, int signed_p, int size) { | |
27 if (signed_p) { | |
28 switch (size) { | |
29 case 1: fprintf(output, ":int8"); break; | |
30 case 2: fprintf(output, ":int16"); break; | |
31 case 4: fprintf(output, ":int32"); break; | |
32 case 8: fprintf(output, ":int64"); break; | |
33 default: goto error; | |
34 } | |
35 } else { | |
36 switch(size) { | |
37 case 1: fprintf(output, ":uint8"); break; | |
38 case 2: fprintf(output, ":uint16"); break; | |
39 case 4: fprintf(output, ":uint32"); break; | |
40 case 8: fprintf(output, ":uint64"); break; | |
41 default: goto error; | |
42 } | |
43 } | |
44 | |
45 return; | |
46 | |
47 error: | |
48 fprintf(output, "(cl:error \"No type of size ~D.\" %i)\n", size); | |
49 } | |
50 | |
51 char* print_double_for_lisp(double n) | |
52 { | |
53 static char buf[256]; | |
54 memset(buf, 0, 256); | |
55 snprintf(buf, 255, "(let ((*read-default-float-format* 'double-float… | |
56 return buf; | |
57 } |