revtools.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /******************************************************************************
  2. *
  3. * project name: TIGCC Tools Suite
  4. * file name: revtools.h
  5. * initial date: 23/08/2000
  6. * author: thomas.nussbaumer@gmx.net
  7. * description: macros for automatic handling of version number output
  8. * which is in sync with the CVS version number
  9. *
  10. * examine one of the pctools source codes to see how it works ;-)
  11. *
  12. ******************************************************************************/
  13. /*
  14. This file is part of the TIGCC Tools Suite.
  15. This file is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU Lesser General Public
  17. License as published by the Free Software Foundation; either
  18. version 2.1 of the License, or (at your option) any later version.
  19. As a special exception, UNMODIFIED copies of some TIGCC Tools Suite utilities
  20. may also be redistributed or sold without source code, for any purpose. (The
  21. Lesser General Public License restrictions do apply in other respects; for
  22. example, they cover modification of the program.) Please refer to the main
  23. source file for the individual utility as to whether this is the case for a
  24. particular tool. This exception notice must be removed on modified copies of
  25. this file.
  26. This program is distributed in the hope that it will be useful,
  27. but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. Lesser General Public License for more details.
  30. You should have received a copy of the GNU Lesser General Public
  31. License along with this library; if not, write to the Free Software
  32. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  33. */
  34. //-----------------------------------------------------------------------------
  35. // [Usage]
  36. //
  37. // (1) include this file into your tool
  38. //
  39. //
  40. // (2) AFTER (!!) all includes put the following lines into your source code:
  41. //
  42. // #ifdef CVS_FILE_REVISION
  43. // #undef CVS_FILE_REVISION
  44. // #endif
  45. // ----------------------------------------------------------------------------
  46. // DON'T EDIT THE NEXT REVISION BY HAND! THIS IS DONE AUTOMATICALLY BY THE
  47. // CVS SYSTEM !!!
  48. // ----------------------------------------------------------------------------
  49. // #define CVS_FILE_REVISION "$Revision: 1.2 $"
  50. //
  51. // It must be placed AFTER (!!) all includes otherwise the macros may be
  52. // expanded wrong where you use them. For example: if you have added the above
  53. // lines at the top of your file and include afterwards a file which does
  54. // the same, the version of the included file will be used further due to the
  55. // #undef CVS_FILE_REVISION. Everything clear?
  56. //
  57. //
  58. // (3) to output the cvs revision number you can now to a simple:
  59. //
  60. // printf(CVSREV_PRINTPARAMS)
  61. //
  62. // if your file has, for example, the revision 1.3 the following string will
  63. // be printed: v1.03
  64. //
  65. // the prefix before the subversion is used to get equal-sized output strings
  66. // for mainversions between 1 ... 9 and subversion between 1 .. 99
  67. //
  68. // if your program leaves that range and you need to have equal-sized output
  69. // strings you have to implement it by your own by using the
  70. // CVSREV_MAIN and CVSREV_SUB macros which returns the main and sub versions
  71. // as plain integers. if there is something wrong with your revision string
  72. // CVSREV_MAIN and/or CVSREV_SUB will deliver 0, which is no valid CVS main
  73. // or subversion number.
  74. //
  75. // i will suggest that you use the CVS system. its simple to handle, keeps
  76. // track of your revisions and their history and with the smart macros below
  77. // you haven't to worry anymore about the version output strings of your
  78. // program. if you want a special version number you can force CVS at every
  79. // time to give this version number to your program (0 is not allowed as
  80. // main and subversion number - thats the only pity)
  81. //
  82. // within this tools suite every tool will use the automatic version handling
  83. // but the tool suite version number itself will be handled "by hand".
  84. // this number shouldn't change that quickly as with the tools.
  85. //
  86. //-----------------------------------------------------------------------------
  87. #ifndef __REV_TOOLS_H__
  88. #define __REV_TOOLS_H__
  89. #include <stdio.h>
  90. #include <stdlib.h>
  91. #include <string.h>
  92. //-----------------------------------------------------------------------------
  93. // just used internally
  94. //-----------------------------------------------------------------------------
  95. #define CVS_TRUNC_PREFIX ((strlen((CVS_FILE_REVISION))<=11) ? 0 : (CVS_FILE_REVISION+11))
  96. #define CVS_FIND_COMMA (strchr(CVS_TRUNC_PREFIX,'.'))
  97. #define CVSREV_MAIN (int)(!(CVS_TRUNC_PREFIX) ? 0 : atoi(CVS_TRUNC_PREFIX))
  98. #define CVSREV_SUB (int)(!(CVS_TRUNC_PREFIX) ? 0 : (!(CVS_FIND_COMMA) ? 0 : atoi(CVS_FIND_COMMA+1)))
  99. //-----------------------------------------------------------------------------
  100. // NOTE: THE FOLLOWING MACRO WILL ONLY HANDLE MAIN VERSION < 10 AT CONSTANT
  101. // LENGTH !!!
  102. // (subversions from 1 .. 99 are mapped to 01 .. 99)
  103. //
  104. // the following macro may be used to setup a printf(),sprintf() or fprintf()
  105. // call
  106. //-----------------------------------------------------------------------------
  107. #define CVSREV_PRINTPARAMS "v%d.%02d",CVSREV_MAIN,CVSREV_SUB
  108. #define PRINT_ID(name) {fprintf(stdout,"\n");fprintf(stdout, name" ");\
  109. fprintf(stdout,CVSREV_PRINTPARAMS);\
  110. fprintf(stdout," - TIGCC Tools Suite v"TTV_MAIN TTV_SUB"\n" \
  111. "(c) thomas.nussbaumer@gmx.net "__DATE__" "__TIME__"\n\n");}
  112. #endif
  113. //#############################################################################
  114. //###################### NO MORE FAKES BEYOND THIS LINE #######################
  115. //#############################################################################