wm_getver.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define LINE_LEN_MAX 1024
  5. int main(int argc, char *argv[])
  6. {
  7. FILE *fp;
  8. char buf[LINE_LEN_MAX];
  9. char *pos;
  10. unsigned char major = 0;
  11. unsigned char minor = 0;
  12. unsigned char patch = 0;
  13. int done = 0;
  14. if (2 != argc)
  15. {
  16. printf("error: parameters please pass wm_main.c path\r\n");
  17. return -1;
  18. }
  19. fp = fopen(argv[1], "rb");
  20. if (!fp)
  21. {
  22. printf("error: failed to open %s\r\n", argv[1]);
  23. return -2;
  24. }
  25. while (fgets(buf, LINE_LEN_MAX, fp))
  26. {
  27. if (0 == done)
  28. {
  29. pos = strstr(buf, "FW_MAJOR_VER");
  30. if (pos)
  31. {
  32. pos = strchr(pos, '0');
  33. if (pos)
  34. {
  35. major = strtol(pos, NULL, 16);
  36. done = 1;
  37. }
  38. }
  39. }
  40. if (1 == done)
  41. {
  42. pos = strstr(buf, "FW_MINOR_VER");
  43. if (pos)
  44. {
  45. pos = strchr(pos, '0');
  46. if (pos)
  47. {
  48. minor = strtol(pos, NULL, 16);
  49. done = 2;
  50. }
  51. }
  52. }
  53. if (2 == done)
  54. {
  55. pos = strstr(buf, "FW_PATCH_VER");
  56. if (pos)
  57. {
  58. pos = strchr(pos, '0');
  59. if (pos)
  60. {
  61. patch = strtol(pos, NULL, 16);
  62. done = 3;
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. fclose(fp);
  69. if (3 == done)
  70. {
  71. sprintf(buf, "G%02X.%02X.%02X", major, minor, patch);
  72. printf("%s", buf);
  73. return 0;
  74. }
  75. return -4;
  76. }