iscompat.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * COMPONENT_NAME: austext
  25. *
  26. * FUNCTIONS: false
  27. * is_compatible_version
  28. *
  29. * ORIGINS: 27
  30. *
  31. *
  32. * (C) COPYRIGHT International Business Machines Corp. 1993,1995
  33. * All Rights Reserved
  34. * Licensed Materials - Property of IBM
  35. * US Government Users Restricted Rights - Use, duplication or
  36. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  37. */
  38. /*********************** ISCOMPAT.C ************************
  39. * $XConsortium: iscompat.c /main/7 1996/11/21 19:50:44 drk $
  40. * November 1993.
  41. * Verifies version number compatibility between caller and this program.
  42. *
  43. * $Log$
  44. * Revision 2.2 1995/10/25 17:46:54 miker
  45. * Added prolog.
  46. *
  47. * Revision 2.1 1995/09/22 20:55:37 miker
  48. * Freeze DtSearch 0.1, AusText 2.1.8
  49. *
  50. * Revision 1.4 1995/09/05 18:10:55 miker
  51. * Name changes for DtSearch.
  52. */
  53. #include "SearchP.h"
  54. #include <stdlib.h>
  55. #define X_INCLUDE_STRING_H
  56. #define XOS_USE_NO_LOCKING
  57. #include <X11/Xos_r.h>
  58. /****#define DEBUG_ISCOMPAT****/
  59. #ifdef DEBUG_ISCOMPAT
  60. static int false (int n) { printf("iscompat=%d\n",n); return FALSE; }
  61. #else
  62. #define false(n) FALSE
  63. #endif
  64. /************************************************/
  65. /* */
  66. /* is_compatible_version */
  67. /* */
  68. /************************************************/
  69. /* Returns TRUE if the caller's 'version' and 'revision' numbers,
  70. * ie the first two numbers of a standard "v.r.m" or "v.r"
  71. * version string, are between VERSCONST and the version
  72. * compiled for this program, ie the constant AUSAPI_VERSION.
  73. * VERSCONST is also expected to be a #define constant,
  74. * either SCHEMA_VERSION, when the last schema change occurred,
  75. * or PROTOCOL_VERSION, when the protocol between the ui and
  76. * the engine changed.
  77. * Returns FALSE if caller's version is not within that range.
  78. * Uses strtok()!
  79. */
  80. int is_compatible_version (char *callers_version, char *VERSCONST)
  81. {
  82. char safebuf [24];
  83. char *ptr;
  84. int fuzzy_v, fuzzy_r, his_v, his_r, my_v, my_r;
  85. _Xstrtokparams strtok_buf;
  86. if (callers_version == NULL)
  87. return false(1);
  88. if (*callers_version == '\0')
  89. return false(2);
  90. strncpy (safebuf, callers_version, sizeof(safebuf));
  91. safebuf[sizeof(safebuf) - 1] = 0;
  92. if ((ptr = _XStrtok (safebuf, ".", strtok_buf)) == NULL)
  93. return false(3);
  94. if ((his_v = atoi (ptr)) == 0)
  95. if (*ptr != '0')
  96. return false(4);
  97. if ((ptr = _XStrtok (NULL, ".", strtok_buf)) == NULL)
  98. return false(5);
  99. if ((his_r = atoi (ptr)) == 0)
  100. if (*ptr != '0')
  101. return false(6);
  102. strncpy (safebuf, VERSCONST, sizeof(safebuf));
  103. safebuf[sizeof(safebuf) - 1] = 0;
  104. if ((ptr = _XStrtok (safebuf, ".", strtok_buf)) == NULL)
  105. return false(7);
  106. if ((my_v = atoi (ptr)) == 0)
  107. if (*ptr != '0')
  108. return false(8);
  109. if ((ptr = _XStrtok (NULL, ".", strtok_buf)) == NULL)
  110. return false(9);
  111. if ((my_r = atoi (ptr)) == 0)
  112. if (*ptr != '0')
  113. return false(10);
  114. strncpy (safebuf, AUSAPI_VERSION, sizeof(safebuf));
  115. safebuf[sizeof(safebuf) - 1] = 0;
  116. if ((ptr = _XStrtok (safebuf, ".", strtok_buf)) == NULL)
  117. return false(11);
  118. if ((fuzzy_v = atoi (ptr)) == 0)
  119. if (*ptr != '0')
  120. return false(12);
  121. if ((ptr = _XStrtok (NULL, ".", strtok_buf)) == NULL)
  122. return false(13);
  123. if ((fuzzy_r = atoi (ptr)) == 0)
  124. if (*ptr != '0')
  125. return false(14);
  126. if (his_v < my_v || fuzzy_v < his_v)
  127. return false(15);
  128. if (his_v == my_v && his_r < my_r)
  129. return false(16);
  130. if (fuzzy_v == his_v && fuzzy_r < his_r)
  131. return false(17);
  132. return TRUE;
  133. } /* is_compatible_version() */
  134. /*********************** ISCOMPAT.C ************************/