struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / tests / internal / testmacro.c
blobd25eecff2afddc20547d127dc5f295b988356fb6
1 #include <SDCCmacro.h>
2 #include <stdio.h>
4 static const char *_maps[] =
6 "immedzero", "#0",
7 "immedvala", "#0x%02X",
8 "stra", "%s",
9 "port", "z80",
10 "stdlibpath", "{basepath}/lib/{port}",
11 "stdlibname", "{port}.lib",
12 "portouttypeflag", "-i",
13 "srcfilename", "fish",
14 "portoutext", ".ihx",
15 "crt0name", "{stdlibpath}/crt0{portobjext}",
16 "portobjext", ".o",
17 "otherobjfiles", "none",
18 "basepath", "/home/michaelh/sdcc",
19 NULL
22 static hTab *
23 _populateHash(const char **pin)
25 hTab *pret = NULL;
27 while (*pin)
29 printf("Adding %s -> %s\n", pin[0], pin[1]);
30 shash_add (&pret, pin[0], pin[1]);
31 pin += 2;
35 return pret;
38 static void
39 _testEval(hTab *ph, const char *pin, const char *pexpect, ...)
41 va_list ap;
42 char *pgot;
44 va_start(ap, pexpect);
46 pgot = mvsprintf(ph, pin, ap);
48 if (strcmp(pgot, pexpect) != 0)
50 printf("Fail: expected: %s, got %s\n", pexpect, pgot);
52 else
54 printf("%s -> %s\n", pin, pgot);
57 va_end(ap);
60 void
61 testMacros(void)
63 hTab *ph = _populateHash(_maps);
65 _testEval(ph, "{immedzero}", "#0");
66 _testEval(ph, "{immedvala}", "#0x23", 0x23);
67 _testEval(ph, "{stra}", "#0", "{immedzero}");
69 printf("Link command:\n%s\n",
70 msprintf(ph,
71 "link-{port} -n -c -- -b_CODE=0x%04X -b_DATA=0x%04X"
72 " -m -j -k{stdlibpath} -l{stdlibname} {portouttypeflag}"
73 " {srcfilename}{portoutext} {crt0name} {srcfilename}{portobjext} {otherobjfiles}",
74 0x1234, 0x3456));
78 int
79 main(void)
81 testMacros();
83 return 0;