1 /* $Id$
2  *  Provides function to generate program version string
3  *  Written at 2002 by Stas Degteff 2:5080/102
4  *
5  * HUSKYLIB: common defines, types and functions for HUSKY
6  *
7  * This is part of The HUSKY Fidonet Software project:
8  * see http://husky.sourceforge.net for details
9  *
10  *
11  * HUSKYLIB is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * HUSKYLIB is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; see file COPYING. If not, write to the
23  * Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  * See also http://www.gnu.org, license may be found here.
26  */
27 
28 #include <string.h>
29 #include "compiler.h"
30 
31 /* export functions from DLL */
32 #define DLLEXPORT
33 #include "huskyext.h"
34 #include "huskylib.h"
35 
36 
37 /* Generate version string like
38  * programname/platform[-compiler] <major>.<minor>.<patchlevel>-<branch> [<cvs date>]
39  *
40  * Examples:
41  * "program/w32-MVC 1.2.3-release"
42  * "program/DPMI-DJGPP 1.2.3-stable 01-10-2002"
43  * "program/FreeBSD 1.3.0-current 01-10-2002"
44  * Return malloc'ed pointer
45  */
GenVersionStr(const char * programname,unsigned major,unsigned minor,unsigned patchlevel,unsigned branch,const char * cvsdate)46  char *GenVersionStr( const char *programname, unsigned major,
47    unsigned minor, unsigned patchlevel, unsigned branch, const char *cvsdate )
48 {
49   char *_version_str=NULL; /* compose to this var */
50   char *platform;
51   char *cbranch=NULL;      /* branch string */
52 
53 #ifdef UNAME                          /* Use '-DUNAME' compiler parameter */
54    platform = "/" UNAME;
55 
56 #elif defined(__linux__)              /*  gcc on Linux                    */
57    platform = "/lnx";
58 
59 #elif defined(__FreeBSD__)            /*  gcc on FreeBSD                  */
60    platform = "/fbsd";
61 
62 #elif defined(__NetBSD__)             /*  gcc on NetBSD                   */
63    platform = "/nbsd";
64 
65 #elif defined(__OpenBSD__)            /*  gcc on OpenBSD                  */
66    platform = "/obsd";
67 
68 #elif defined(__BSD__)                /*  gcc on other BSD clone          */
69    platform = "/bsd";
70 
71 #elif defined(__SUN__)                /*  SunOS (Solaris)                 */
72 #  if defined(__GNUC__)
73    platform = "/sun-gcc";
74 #  else
75    platform = "/sun";
76 #  endif
77 
78 #elif defined(__APPLE__) && defined(__MACH__)
79    platform = "/mac";
80 
81 #elif defined(_AIX)
82    platform = "/aix";
83 
84 #elif defined(__osf__)
85    platform = "/osf";
86 
87 #elif defined(__hpux)
88    platform = "/hpux";
89 
90 #elif defined(__OS2__) || defined(OS2)
91 #  if defined(__TURBOC__) /* Borland C/C++ for OS/2 */
92    platform = "/os2-bc";
93 #  elif defined(_MSC_VER) /* Microsoft C or Microsoft QuickC for OS/2 */
94    platform = "/os2-msc";
95 #  elif defined(__WATCOMC__)
96    platform = "/os2-wc";
97 #  elif defined(__IBMC__) /* IBM C/Set++ for OS/2 */
98    platform = "/os2-ibmc";
99 #  elif defined(__HIGHC__)/* MetaWare High C/C++ for OS/2 */
100    platform = "/os2-hc";
101 #  elif defined(__EMX__)  /* EMX for 32-bit OS/2 */
102    platform = "/os2-emx";
103 #  else
104    platform = "/os2";
105 #  endif
106 
107 #elif defined(__HIGHC__) /* MetaWare High C/C++ for OS/2 */
108    platform = "/os2-hc";
109 
110 #elif defined(__IBMC__) && !defined(UNIX)
111 /* IBM C/Set++ for OS/2 */
112    platform = "/os2-ibmc";
113 
114 #elif defined(__MSVC__)
115 #    if !defined(_MAKE_DLL_MVC_) && defined(_WIN64)
116      platform = "/w64-mvc";
117 #    elif defined(_MAKE_DLL_MVC_) && defined(_WIN64)
118      platform = "/w64-mvcdll";
119 #    elif defined(_MAKE_DLL_MVC_) && !defined(_WIN64)
120      platform = "/w32-mvcdll";
121 #    else
122      platform = "/w32-mvc";
123 #    endif
124 #elif defined(__MINGW32__)
125 #    if defined(_MAKE_DLL)
126      platform = "/w32-mgwdll";
127 #    else
128      platform = "/w32-mgw";
129 #    endif
130 #elif defined(__WIN32__)
131 
132 #  if defined(__TURBOC__) /* Borland C/C++ for Win32 */
133    platform = "/w32-bc";
134 #  elif defined(__WATCOMC__)
135    platform = "/w32-wc";
136 #  elif defined(__EMX__)    /* RSX for Windows NT */
137    platform = "/w32-rsx";
138 #  else
139    platform = "/w32";
140 #  endif
141 
142 #elif defined(_WINDOWS)
143 #  if defined(__WATCOMC__)
144    platform = "/win-wc";
145 #  else
146    platform = "/win";
147 #  endif
148 
149 #  elif defined(__EMX__)    /* EMX for 32-bit OS/2 */
150    platform = "/emx";
151 
152 #elif defined(__DJGPP__)
153    platform = "/dpmi-djgpp";
154 
155 #elif defined(__DOS__)
156 #  ifdef __DJGPP__
157    platform = "/dpmi-djgpp";
158 #  elif defined(__WATCOMC__) && defined(__DOS4G__)
159    platform = "/dos4g-wc";
160 #  elif defined(__WATCOMC__) && defined(__FLAT__)
161    platform = "/dpmi-wc";
162 #  elif defined(__WATCOMC__) && !defined(__FLAT__)
163    platform = "/dos-wc";
164 #  elif defined(__TURBOC__)
165    platform = "/dos-bc";
166 #  elif defined(__MSC__) /* Microsoft C or Microsoft QuickC for MS-DOS */
167    platform = "/dos-msc";
168 #  elif defined(__FLAT__)
169    platform = "/dpmi";
170 #  else
171    platform = "/dos";
172 #  endif
173 
174 #elif defined(__BEOS__)
175    platform = "/beos";
176 
177 #elif defined(SASC)                          /* SAS C for AmigaDOS */
178    platform = "/amiga-sasc";
179 
180 #elif defined(__UNIX__)
181    platform = "/unix";
182 
183 #else
184    platform = "";
185   #ifdef __GNUC__
186     #warning Unknown platform and compiler!
187   #else
188     #pragma message("Unknown platform and compiler!")
189   #endif
190 #endif
191 
192 
193   switch(branch){
194   case BRANCH_CURRENT: cbranch = "-cur";
195                        if( !(minor & 1) ){
196                          fprintf(stderr, __FILE__ ":%u: illegal usage of GenVersionStr(): minor value for current branch must be odd!\n", __LINE__);
197                        }
198                        if( patchlevel ){
199                          fprintf(stderr, __FILE__ ":%u: illegal usage of GenVersionStr(): patchlevel value for current branch must be zero!\n", __LINE__);
200 /*                         pathlevel = 0;*/
201                        }
202                        break;
203   case BRANCH_STABLE:  cbranch = "-sta";
204                        if( minor & 1 ){
205                          fprintf(stderr, __FILE__ ":%u: illegal usage of GenVersionStr(): minor value for stable branch must be even!\n", __LINE__);
206                        }
207                        break;
208   case BRANCH_RELEASE: cbranch = "-rel";
209                        if( minor & 1 ){
210                          fprintf(stderr, __FILE__ ":%u: illegal usage of GenVersionStr(): minor value for release branch must be even!\n", __LINE__);
211                        }
212                        break;
213   }
214 
215   if(branch==BRANCH_RELEASE)
216     /* Release date are known always */
217     xscatprintf( &_version_str, "%s%s %u.%u.%u%s",
218                      programname, platform, major, minor, patchlevel, cbranch);
219   else
220     xscatprintf( &_version_str, "%s%s %u.%u.%u%s %s",
221             programname, platform, major, minor, patchlevel, cbranch, cvsdate);
222 
223   return _version_str;
224 }
225