1 /* VERSION.C    (c) Copyright Roger Bowler, 1999-2009                */
2 /*              Hercules Version Display Module                      */
3 
4 /*-------------------------------------------------------------------*/
5 /* This module displays the Hercules program name and version,       */
6 /* copyright notice, build date and time, and build information.     */
7 /*-------------------------------------------------------------------*/
8 
9 #include "hstdinc.h"
10 
11 #define _VERSION_C_
12 #define _HUTIL_DLL_
13 
14 #include "hercules.h"
15 #include "machdep.h"
16 
17 /*--------------------------------------------------*/
18 /*   "Unusual" (i.e. noteworthy) build options...   */
19 /*--------------------------------------------------*/
20 
21 static const char *build_info[] = {
22 
23 #if defined(_MSVC_)
24     "Windows (MSVC) "
25   #if defined(DEBUG)
26     "** DEBUG ** "
27   #endif
28     "build for " MSTRING(HOST_ARCH)
29   #if defined(CUSTOM_BUILD_STRING)
30     ": \"" CUSTOM_BUILD_STRING "\""
31   #endif
32     ,
33 #elif defined(CUSTOM_BUILD_STRING)
34     CUSTOM_BUILD_STRING,
35 #endif
36 
37 #if !defined(_ARCHMODE2)
38     "Mode:"
39 #else
40     "Modes:"
41 #endif
42 #if defined(_370)
43     " " _ARCH_370_NAME
44 #endif
45 #if defined(_390)
46     " " _ARCH_390_NAME
47 #endif
48 #if defined(_900)
49     " " _ARCH_900_NAME
50 #endif
51     ,
52 
53     "Max CPU Engines: " MSTRING(MAX_CPU_ENGINES),
54 
55 #if !defined(_MSVC_)
56   #if defined(NO_SETUID)
57     "No setuid support",
58   #else
59     "Using "
60     #if defined(HAVE_SETRESUID)
61       "setresuid()"
62     #elif defined(HAVE_SETREUID)
63       "setreuid()"
64     #else
65       "(UNKNOWN)"
66     #endif
67     " for setting privileges",
68   #endif
69 #endif
70 
71 #if defined(OPTION_FTHREADS)
72     "Using fthreads instead of pthreads",
73 #endif
74 #if defined(OPTION_DYNAMIC_LOAD)
75     "Dynamic loading support",
76 #else
77     "No Dynamic loading support",
78 #endif
79 #if defined(HDL_BUILD_SHARED)
80     "Using shared libraries",
81 #else
82     "Using static libraries",
83 #endif
84 
85 #if !defined(EXTERNALGUI)
86     "No External GUI support",
87 #endif
88 
89 #if defined(OPTION_HTTP_SERVER)
90     "HTTP Server support",
91 #if defined(PKGDATADIR) && defined(DEBUG)
92     "HTTP document default root directory is "PKGDATADIR,
93 #endif
94 #endif
95 
96 #if defined(NO_SIGABEND_HANDLER)
97     "No SIGABEND handler",
98 #endif
99 
100 #if !defined(CCKD_BZIP2)
101     "No CCKD BZIP2 support",
102 #endif
103 
104 #if !defined(HAVE_LIBZ)
105     "No ZLIB support",
106 #endif
107 
108 #if defined(HAVE_REGEX_H) || defined(HAVE_PCRE)
109     "Regular Expressions support",
110 #endif
111 
112 #if defined(OPTION_HAO)
113     "Automatic Operator support",
114 #endif
115 
116 #if !defined(HET_BZIP2)
117     "No HET BZIP2 support",
118 #endif
119 
120     "Machine dependent assists:"
121 #if !defined( ASSIST_CMPXCHG1  ) \
122  && !defined( ASSIST_CMPXCHG4  ) \
123  && !defined( ASSIST_CMPXCHG8  ) \
124  && !defined( ASSIST_CMPXCHG16 ) \
125  && !defined( ASSIST_FETCH_DW  ) \
126  && !defined( ASSIST_STORE_DW  ) \
127  && !defined( MULTI_BYTE_ASSIST)
128     " (none)",
129 #else
130   #if defined( ASSIST_CMPXCHG1 )
131                     " cmpxchg1"
132   #endif
133   #if defined( ASSIST_CMPXCHG4 )
134                     " cmpxchg4"
135   #endif
136   #if defined( ASSIST_CMPXCHG8 )
137                     " cmpxchg8"
138   #endif
139   #if defined( ASSIST_CMPXCHG16 )
140                     " cmpxchg16"
141   #endif
142   #if defined( ASSIST_FETCH_DW )
143                     " fetch_dw"
144   #endif
145   #if defined( ASSIST_STORE_DW )
146                     " store_dw"
147   #endif
148   #if defined( MULTI_BYTE_ASSIST )
149                     " multi_byte"
150   #endif
151     ,
152 #endif
153 
154 };
155 
156 /*-------------------------------------------------------------------*/
157 /* Retrieve ptr to build information strings array...                */
158 /*         (returns #of entries in array)                            */
159 /*-------------------------------------------------------------------*/
get_buildinfo_strings(const char *** pppszBldInfoStr)160 DLL_EXPORT int  get_buildinfo_strings(const char*** pppszBldInfoStr)
161 {
162     if (!pppszBldInfoStr) return 0;
163     *pppszBldInfoStr = build_info;
164     return ( sizeof(build_info) / sizeof(build_info[0]) );
165 }
166 
167 
168 /*-------------------------------------------------------------------*/
169 /* Display version and copyright                                     */
170 /*-------------------------------------------------------------------*/
display_version_2(FILE * f,char * prog,const char verbose,int httpfd)171 DLL_EXPORT void display_version_2 (FILE *f, char *prog, const char verbose,int httpfd)
172 {
173     unsigned int i;
174     const char** ppszBldInfoStr = NULL;
175 
176 #if defined(EXTERNALGUI)
177     /* If external gui being used, set stdout & stderr streams
178        to unbuffered so we don't have to flush them all the time
179        in order to ensure consistent sequence of log messages.
180     */
181     if (extgui)
182     {
183         setvbuf(stderr, NULL, _IONBF, 0);
184         setvbuf(stdout, NULL, _IONBF, 0);
185     }
186 #endif /*EXTERNALGUI*/
187 
188         /* Log version */
189 
190     if ( f != stdout )
191         if(httpfd<0)
192             fprintf (f, _("%sVersion %s\n"), prog, VERSION);
193         else
194             hprintf (httpfd, _("%sVersion %s\n"), prog, VERSION);
195     else
196         logmsg  (   _("%sVersion %s\n"), prog, VERSION);
197 
198     /* Log Copyright */
199 
200     if ( f != stdout )
201         if(httpfd<0)
202             fprintf (f, "%s\n", HERCULES_COPYRIGHT);
203         else
204             hprintf (httpfd, "%s\n", HERCULES_COPYRIGHT);
205     else
206         logmsg  (   "%s\n", HERCULES_COPYRIGHT);
207 
208     /* If we're being verbose, display the rest of the info */
209     if (verbose)
210     {
211         /* Log build date/time */
212 
213         if ( f != stdout )
214             if(httpfd<0)
215                 fprintf (f, _("Built on %s at %s\n"), __DATE__, __TIME__);
216             else
217                 hprintf (httpfd, _("Built on %s at %s\n"), __DATE__, __TIME__);
218         else
219             logmsg  (   _("Built on %s at %s\n"), __DATE__, __TIME__);
220 
221         /* Log "unusual" build options */
222 
223         if ( f != stdout )
224             if(httpfd<0)
225                 fprintf (f, _("Build information:\n"));
226             else
227                 hprintf (httpfd, _("Build information:\n"));
228         else
229             logmsg  (   _("Build information:\n"));
230 
231         if (!(i = get_buildinfo_strings( &ppszBldInfoStr )))
232         {
233             if ( f != stdout )
234                 if(httpfd<0)
235                     fprintf (f, "  (none)\n");
236                 else
237                     hprintf (httpfd, "  (none)\n");
238             else
239                 logmsg  (   "  (none)\n");
240         }
241         else
242         {
243             for(; i; i--, ppszBldInfoStr++ )
244             {
245                 if ( f != stdout )
246                     if(httpfd<0)
247                         fprintf (f, "  %s\n", *ppszBldInfoStr);
248                     else
249                         hprintf (httpfd, "  %s\n", *ppszBldInfoStr);
250                 else
251                     logmsg  (   "  %s\n", *ppszBldInfoStr);
252             }
253         }
254 
255         if(f != stdout)
256             if(httpfd<0)
257                 display_hostinfo( &hostinfo, f, -1 );
258             else
259                 display_hostinfo( &hostinfo, (FILE *)-1,httpfd );
260         else
261             display_hostinfo( &hostinfo, f, -1 );
262     }
263 
264 } /* end function display_version */
265 
display_version(FILE * f,char * prog,const char verbose)266 DLL_EXPORT void display_version(FILE *f,char *prog,const char verbose)
267 {
268     display_version_2(f,prog,verbose,-1);
269 }
270