wingenminiupnpcstrings.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /* This program display the Windows version and is used to
  11. * generate the miniupnpcstrings.h
  12. * wingenminiupnpcstrings miniupnpcstrings.h.in miniupnpcstrings.h
  13. */
  14. int main(int argc, char * * argv) {
  15. char buffer[256];
  16. OSVERSIONINFO osvi;
  17. FILE * fin;
  18. FILE * fout;
  19. int n;
  20. /* dwMajorVersion :
  21. The major version number of the operating system. For more information, see Remarks.
  22. dwMinorVersion :
  23. The minor version number of the operating system. For more information, see Remarks.
  24. dwBuildNumber :
  25. The build number of the operating system.
  26. dwPlatformId
  27. The operating system platform. This member can be the following value.
  28. szCSDVersion
  29. A null-terminated string, such as "Service Pack 3", that indicates the
  30. latest Service Pack installed on the system. If no Service Pack has
  31. been installed, the string is empty.
  32. */
  33. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  34. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  35. GetVersionEx(&osvi);
  36. printf("Windows %lu.%lu Build %lu %s\n",
  37. osvi.dwMajorVersion, osvi.dwMinorVersion,
  38. osvi.dwBuildNumber, (const char *)&(osvi.szCSDVersion));
  39. if(argc >= 3) {
  40. fin = fopen(argv[1], "r");
  41. if(!fin) {
  42. fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
  43. return 1;
  44. }
  45. fout = fopen(argv[2], "w");
  46. if(!fout) {
  47. fprintf(stderr, "Cannot open %s for writing.\n", argv[2]);
  48. return 1;
  49. }
  50. n = 0;
  51. while(fgets(buffer, sizeof(buffer), fin)) {
  52. if(0 == memcmp(buffer, "#define OS_STRING \"OS/version\"", 30)) {
  53. sprintf(buffer, "#define OS_STRING \"MSWindows/%ld.%ld.%ld\"\n",
  54. osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
  55. }
  56. /*fputs(buffer, stdout);*/
  57. fputs(buffer, fout);
  58. n++;
  59. }
  60. fclose(fin);
  61. fclose(fout);
  62. printf("%d lines written to %s.\n", n, argv[2]);
  63. }
  64. return 0;
  65. }
粤ICP备19079148号