buildnum.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the included (GNU.txt) GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <quakedef.h>
  18. // char *date = "Oct 24 1996";
  19. // char *time = "13:22:52";
  20. char *date = __DATE__ ;
  21. char *time = __TIME__ ;
  22. char *mon[12] =
  23. { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  24. char mond[12] =
  25. { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  26. // returns days since Oct 24 1996
  27. int build_number( void )
  28. {
  29. int m = 0;
  30. int d = 0;
  31. int y = 0;
  32. int hr, min;
  33. static int b = 0;
  34. if (b != 0)
  35. return b;
  36. for (m = 0; m < 11; m++)
  37. {
  38. if (_strnicmp( &date[0], mon[m], 3 ) == 0)
  39. break;
  40. d += mond[m];
  41. }
  42. d += atoi( &date[4] ) - 1;
  43. y = atoi( &date[7] ) - 1900;
  44. b = d + (int)((y - 1) * 365.25);
  45. if (((y % 4) == 0) && m > 1)
  46. {
  47. b += 1;
  48. }
  49. b -= 34995; // Oct 24 1996
  50. hr = (time[0] - '0') * 10 + (time[1] - '0');
  51. min = (time[3] - '0') * 10 + (time[4] - '0');
  52. // sec = (time[6] - '0') * 10 + (time[7] - '0');
  53. b *= 60*24;
  54. b += hr * 60 + min;
  55. return b;
  56. }