Annotation of embedaddon/miniupnpc/wingenminiupnpcstrings.c, revision 1.1.1.3

1.1.1.3 ! misho       1: /* $Id: wingenminiupnpcstrings.c,v 1.6 2021/08/21 09:43:40 nanard Exp $ */
1.1       misho       2: /* Project: miniupnp
1.1.1.3 ! misho       3:  * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
1.1       misho       4:  * Author: Thomas Bernard
1.1.1.3 ! misho       5:  * Copyright (c) 2005-2021 Thomas Bernard
1.1       misho       6:  * This software is subjects to the conditions detailed
                      7:  * in the LICENSE file provided within this distribution */
                      8: #include <stdio.h>
                      9: #include <windows.h>
                     10: 
                     11: /* This program display the Windows version and is used to
                     12:  * generate the miniupnpcstrings.h
                     13:  * wingenminiupnpcstrings miniupnpcstrings.h.in miniupnpcstrings.h
                     14:  */
                     15: int main(int argc, char * * argv) {
                     16:        char buffer[256];
                     17:        OSVERSIONINFO osvi;
                     18:        FILE * fin;
                     19:        FILE * fout;
                     20:        int n;
                     21:        char miniupnpcVersion[32];
                     22:        /* dwMajorVersion :
                     23:        The major version number of the operating system. For more information, see Remarks.
                     24:      dwMinorVersion :
                     25:        The minor version number of the operating system. For more information, see Remarks.
                     26:      dwBuildNumber :
                     27:        The build number of the operating system.
                     28:      dwPlatformId
1.1.1.2   misho      29:        The operating system platform. This member can be the following value.
1.1       misho      30:      szCSDVersion
                     31:        A null-terminated string, such as "Service Pack 3", that indicates the
                     32:        latest Service Pack installed on the system. If no Service Pack has
                     33:        been installed, the string is empty.
                     34:    */
                     35:   ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
                     36:   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
                     37: 
                     38:   GetVersionEx(&osvi);
                     39: 
                     40:        printf("Windows %lu.%lu Build %lu %s\n",
                     41:               osvi.dwMajorVersion, osvi.dwMinorVersion,
                     42:               osvi.dwBuildNumber, (const char *)&(osvi.szCSDVersion));
                     43: 
                     44:        fin = fopen("VERSION", "r");
                     45:        fgets(miniupnpcVersion, sizeof(miniupnpcVersion), fin);
                     46:        fclose(fin);
1.1.1.3 ! misho      47:        for(n = 0; n < (int)sizeof(miniupnpcVersion); n++) {
1.1       misho      48:                if(miniupnpcVersion[n] < ' ')
                     49:                        miniupnpcVersion[n] = '\0';
                     50:        }
                     51:        printf("MiniUPnPc version %s\n", miniupnpcVersion);
                     52: 
                     53:        if(argc >= 3) {
                     54:                fin = fopen(argv[1], "r");
                     55:                if(!fin) {
                     56:                        fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
                     57:                        return 1;
                     58:                }
                     59:                fout = fopen(argv[2], "w");
                     60:                if(!fout) {
                     61:                        fprintf(stderr, "Cannot open %s for writing.\n", argv[2]);
1.1.1.3 ! misho      62:                        fclose(fin);
1.1       misho      63:                        return 1;
                     64:                }
                     65:                n = 0;
                     66:                while(fgets(buffer, sizeof(buffer), fin)) {
                     67:                        if(0 == memcmp(buffer, "#define OS_STRING \"OS/version\"", 30)) {
                     68:                                sprintf(buffer, "#define OS_STRING \"MSWindows/%ld.%ld.%ld\"\n",
                     69:                                        osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
                     70:                        } else if(0 == memcmp(buffer, "#define MINIUPNPC_VERSION_STRING \"version\"", 42)) {
                     71:                                sprintf(buffer, "#define MINIUPNPC_VERSION_STRING \"%s\"\n",
                     72:                                        miniupnpcVersion);
                     73:                        }
                     74:                        /*fputs(buffer, stdout);*/
                     75:                        fputs(buffer, fout);
                     76:                        n++;
                     77:                }
                     78:                fclose(fin);
                     79:                fclose(fout);
                     80:                printf("%d lines written to %s.\n", n, argv[2]);
                     81:        }
1.1.1.3 ! misho      82:        if(argc >= 4) {
        !            83:                fout = fopen(argv[3], "w");
        !            84:                if(fout == NULL) {
        !            85:                        fprintf(stderr, "Cannot open %s for writing.\n", argv[2]);
        !            86:                        return 1;
        !            87:                } else {
        !            88:                        char * cur, * next;
        !            89:                        fprintf(fout, "#define LIBMINIUPNPC_DOTTED_VERSION \"%s\"\n", miniupnpcVersion);
        !            90:                        next = strchr(miniupnpcVersion, '.');
        !            91:                        if (next && *next) {
        !            92:                                *next = '\0';
        !            93:                                next++;
        !            94:                        }
        !            95:                        fprintf(fout, "#define LIBMINIUPNPC_MAJOR_VERSION %s\n", miniupnpcVersion);
        !            96:                        cur = next;
        !            97:                        next = strchr(cur, '.');
        !            98:                        if (next && *next) {
        !            99:                                *next = '\0';
        !           100:                                next++;
        !           101:                        }
        !           102:                        fprintf(fout, "#define LIBMINIUPNPC_MINOR_VERSION %s\n", cur);
        !           103:                        cur = next;
        !           104:                        next = strchr(cur, '.');
        !           105:                        if (next && *next) {
        !           106:                                *next = '\0';
        !           107:                                next++;
        !           108:                        }
        !           109:                        fprintf(fout, "#define LIBMINIUPNPC_MICRO_VERSION %s\n", cur);
        !           110:                        fclose(fout);
        !           111:                        printf("%s written\n", argv[3]);
        !           112:                }
        !           113:        }
1.1       misho     114:   return 0;
                    115: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>