File indexing completed on 2024-05-12 04:39:39

0001 /*
0002     SPDX-FileCopyrightText: 2010 Patrick Spendrin <ps_ml@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 /* 
0008 *  This helper program is needed for the Visual Studio compiler 
0009 *  to find out the standard macros, there is no "gcc -dM -E -".
0010 *  A trick is used to find out the standard macros. You can 
0011 *  exchange the compiler. The standard macros are written in
0012 *  a environment variable. This helper program analysis this
0013 *  variable and prints the output to stdout.
0014 */
0015 
0016 #include <cstdio>
0017 #include <cstdlib>
0018 #include <cstring>
0019 
0020 int main(int argc, char**argv)
0021 {
0022     char *next, *token, *tmp, *equal;
0023     int nextlen, currentlen;
0024     next = getenv("MSC_CMD_FLAGS");
0025 
0026     while (next != NULL)
0027     {
0028         token = next;
0029         next = strstr(next + 1, " -");
0030 
0031         if(strncmp(token, " -D", 3) == 0) {
0032             if(next != NULL) 
0033                 nextlen = strlen(next);
0034             else
0035                 nextlen = 0;
0036 
0037             currentlen = strlen(token);
0038             tmp = new char[(currentlen - nextlen + 1)];
0039             strncpy(tmp, token, currentlen - nextlen);
0040             tmp[currentlen - nextlen] = '\0';
0041             equal = strchr(tmp, '=');
0042             if(equal != NULL) *equal = ' ';
0043             printf("#define %s\n", tmp + 3);
0044             delete [] tmp;
0045         }
0046     }
0047     // return an error so that the compiler doesn't check for the output
0048     return 1;
0049 }