~ubuntu-branches/ubuntu/precise/miniupnpc/precise

« back to all changes in this revision

Viewing changes to wingenminiupnpcstrings.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Goirand
  • Date: 2010-12-29 16:49:20 UTC
  • Revision ID: james.westby@ubuntu.com-20101229164920-vltq442q9tny283z
Tags: upstream-1.4.20101221
ImportĀ upstreamĀ versionĀ 1.4.20101221

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: wingenminiupnpcstrings.c,v 1.1 2009/12/10 18:46:15 nanard Exp $ */
 
2
/* Project: miniupnp
 
3
 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
 
4
 * Author: Thomas Bernard
 
5
 * Copyright (c) 2005-2009 Thomas Bernard
 
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
        /* dwMajorVersion :
 
22
       The major version number of the operating system. For more information, see Remarks.
 
23
     dwMinorVersion :
 
24
       The minor version number of the operating system. For more information, see Remarks.
 
25
     dwBuildNumber :
 
26
       The build number of the operating system.
 
27
     dwPlatformId
 
28
       The operating system platform. This member can be the following value. 
 
29
     szCSDVersion
 
30
       A null-terminated string, such as "Service Pack 3", that indicates the
 
31
       latest Service Pack installed on the system. If no Service Pack has
 
32
       been installed, the string is empty.
 
33
   */
 
34
  ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
 
35
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
36
 
 
37
  GetVersionEx(&osvi);
 
38
 
 
39
        printf("Windows %lu.%lu Build %lu %s\n",
 
40
               osvi.dwMajorVersion, osvi.dwMinorVersion,
 
41
               osvi.dwBuildNumber, (const char *)&(osvi.szCSDVersion));
 
42
 
 
43
        if(argc >= 3) {
 
44
                fin = fopen(argv[1], "r");
 
45
                if(!fin) {
 
46
                        fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
 
47
                        return 1;
 
48
                }
 
49
                fout = fopen(argv[2], "w");
 
50
                if(!fout) {
 
51
                        fprintf(stderr, "Cannot open %s for writing.\n", argv[2]);
 
52
                        return 1;
 
53
                }
 
54
                n = 0;
 
55
                while(fgets(buffer, sizeof(buffer), fin)) {
 
56
                        if(0 == memcmp(buffer, "#define OS_STRING \"OS/version\"", 30)) {
 
57
                                sprintf(buffer, "#define OS_STRING \"MSWindows/%ld.%ld.%ld\"\n",
 
58
                                        osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
 
59
                        }
 
60
                        /*fputs(buffer, stdout);*/
 
61
                        fputs(buffer, fout);
 
62
                        n++;
 
63
                }
 
64
                fclose(fin);
 
65
                fclose(fout);
 
66
                printf("%d lines written to %s.\n", n, argv[2]);
 
67
        }
 
68
  return 0;
 
69
}