xref: /minix3/crypto/external/bsd/openssl/dist/apps/vms_decc_init.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \
2ebfedea0SLionel Sambuc  defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000)
3ebfedea0SLionel Sambuc # define USE_DECC_INIT 1
4ebfedea0SLionel Sambuc #endif
5ebfedea0SLionel Sambuc 
6ebfedea0SLionel Sambuc #ifdef USE_DECC_INIT
7ebfedea0SLionel Sambuc 
8*0a6a1f1dSLionel Sambuc /*-
9ebfedea0SLionel Sambuc  * 2010-04-26 SMS.
10ebfedea0SLionel Sambuc  *
11ebfedea0SLionel Sambuc  *----------------------------------------------------------------------
12ebfedea0SLionel Sambuc  *
13ebfedea0SLionel Sambuc  *       decc_init()
14ebfedea0SLionel Sambuc  *
15ebfedea0SLionel Sambuc  *    On non-VAX systems, uses LIB$INITIALIZE to set a collection of C
16ebfedea0SLionel Sambuc  *    RTL features without using the DECC$* logical name method.
17ebfedea0SLionel Sambuc  *
18ebfedea0SLionel Sambuc  *----------------------------------------------------------------------
19ebfedea0SLionel Sambuc  */
20ebfedea0SLionel Sambuc 
21ebfedea0SLionel Sambuc # include <stdio.h>
22ebfedea0SLionel Sambuc # include <stdlib.h>
23ebfedea0SLionel Sambuc # include <unixlib.h>
24ebfedea0SLionel Sambuc 
25ebfedea0SLionel Sambuc /* Global storage. */
26ebfedea0SLionel Sambuc 
27ebfedea0SLionel Sambuc /* Flag to sense if decc_init() was called. */
28ebfedea0SLionel Sambuc 
29ebfedea0SLionel Sambuc int decc_init_done = -1;
30ebfedea0SLionel Sambuc 
31ebfedea0SLionel Sambuc /* Structure to hold a DECC$* feature name and its desired value. */
32ebfedea0SLionel Sambuc 
33*0a6a1f1dSLionel Sambuc typedef struct {
34ebfedea0SLionel Sambuc     char *name;
35ebfedea0SLionel Sambuc     int value;
36ebfedea0SLionel Sambuc } decc_feat_t;
37ebfedea0SLionel Sambuc 
38*0a6a1f1dSLionel Sambuc /*
39*0a6a1f1dSLionel Sambuc  * Array of DECC$* feature names and their desired values. Note:
40*0a6a1f1dSLionel Sambuc  * DECC$ARGV_PARSE_STYLE is the urgent one.
41ebfedea0SLionel Sambuc  */
42ebfedea0SLionel Sambuc 
43*0a6a1f1dSLionel Sambuc decc_feat_t decc_feat_array[] = {
44ebfedea0SLionel Sambuc     /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
45ebfedea0SLionel Sambuc     {"DECC$ARGV_PARSE_STYLE", 1},
46ebfedea0SLionel Sambuc 
47ebfedea0SLionel Sambuc     /* Preserve case for file names on ODS5 disks. */
48ebfedea0SLionel Sambuc     {"DECC$EFS_CASE_PRESERVE", 1},
49ebfedea0SLionel Sambuc 
50*0a6a1f1dSLionel Sambuc     /*
51*0a6a1f1dSLionel Sambuc      * Enable multiple dots (and most characters) in ODS5 file names, while
52*0a6a1f1dSLionel Sambuc      * preserving VMS-ness of ";version".
53ebfedea0SLionel Sambuc      */
54ebfedea0SLionel Sambuc     {"DECC$EFS_CHARSET", 1},
55ebfedea0SLionel Sambuc 
56ebfedea0SLionel Sambuc     /* List terminator. */
57ebfedea0SLionel Sambuc     {(char *)NULL, 0}
58ebfedea0SLionel Sambuc };
59ebfedea0SLionel Sambuc 
60ebfedea0SLionel Sambuc /* LIB$INITIALIZE initialization function. */
61ebfedea0SLionel Sambuc 
decc_init(void)62ebfedea0SLionel Sambuc static void decc_init(void)
63ebfedea0SLionel Sambuc {
64ebfedea0SLionel Sambuc     char *openssl_debug_decc_init;
65ebfedea0SLionel Sambuc     int verbose = 0;
66ebfedea0SLionel Sambuc     int feat_index;
67ebfedea0SLionel Sambuc     int feat_value;
68ebfedea0SLionel Sambuc     int feat_value_max;
69ebfedea0SLionel Sambuc     int feat_value_min;
70ebfedea0SLionel Sambuc     int i;
71ebfedea0SLionel Sambuc     int sts;
72ebfedea0SLionel Sambuc 
73ebfedea0SLionel Sambuc     /* Get debug option. */
74ebfedea0SLionel Sambuc     openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT");
75*0a6a1f1dSLionel Sambuc     if (openssl_debug_decc_init != NULL) {
76ebfedea0SLionel Sambuc         verbose = strtol(openssl_debug_decc_init, NULL, 10);
77*0a6a1f1dSLionel Sambuc         if (verbose <= 0) {
78ebfedea0SLionel Sambuc             verbose = 1;
79ebfedea0SLionel Sambuc         }
80ebfedea0SLionel Sambuc     }
81ebfedea0SLionel Sambuc 
82ebfedea0SLionel Sambuc     /* Set the global flag to indicate that LIB$INITIALIZE worked. */
83ebfedea0SLionel Sambuc     decc_init_done = 1;
84ebfedea0SLionel Sambuc 
85ebfedea0SLionel Sambuc     /* Loop through all items in the decc_feat_array[]. */
86ebfedea0SLionel Sambuc 
87*0a6a1f1dSLionel Sambuc     for (i = 0; decc_feat_array[i].name != NULL; i++) {
88ebfedea0SLionel Sambuc         /* Get the feature index. */
89ebfedea0SLionel Sambuc         feat_index = decc$feature_get_index(decc_feat_array[i].name);
90*0a6a1f1dSLionel Sambuc         if (feat_index >= 0) {
91ebfedea0SLionel Sambuc             /* Valid item.  Collect its properties. */
92ebfedea0SLionel Sambuc             feat_value = decc$feature_get_value(feat_index, 1);
93ebfedea0SLionel Sambuc             feat_value_min = decc$feature_get_value(feat_index, 2);
94ebfedea0SLionel Sambuc             feat_value_max = decc$feature_get_value(feat_index, 3);
95ebfedea0SLionel Sambuc 
96ebfedea0SLionel Sambuc             /* Check the validity of our desired value. */
97ebfedea0SLionel Sambuc             if ((decc_feat_array[i].value >= feat_value_min) &&
98*0a6a1f1dSLionel Sambuc                 (decc_feat_array[i].value <= feat_value_max)) {
99ebfedea0SLionel Sambuc                 /* Valid value.  Set it if necessary. */
100*0a6a1f1dSLionel Sambuc                 if (feat_value != decc_feat_array[i].value) {
101ebfedea0SLionel Sambuc                     sts = decc$feature_set_value(feat_index,
102*0a6a1f1dSLionel Sambuc                                                  1, decc_feat_array[i].value);
103ebfedea0SLionel Sambuc 
104*0a6a1f1dSLionel Sambuc                     if (verbose > 1) {
105ebfedea0SLionel Sambuc                         fprintf(stderr, " %s = %d, sts = %d.\n",
106ebfedea0SLionel Sambuc                                 decc_feat_array[i].name,
107*0a6a1f1dSLionel Sambuc                                 decc_feat_array[i].value, sts);
108ebfedea0SLionel Sambuc                     }
109ebfedea0SLionel Sambuc                 }
110*0a6a1f1dSLionel Sambuc             } else {
111ebfedea0SLionel Sambuc                 /* Invalid DECC feature value. */
112ebfedea0SLionel Sambuc                 fprintf(stderr,
113ebfedea0SLionel Sambuc                         " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n",
114ebfedea0SLionel Sambuc                         feat_value,
115*0a6a1f1dSLionel Sambuc                         feat_value_min, decc_feat_array[i].name,
116*0a6a1f1dSLionel Sambuc                         feat_value_max);
117ebfedea0SLionel Sambuc             }
118*0a6a1f1dSLionel Sambuc         } else {
119ebfedea0SLionel Sambuc             /* Invalid DECC feature name. */
120ebfedea0SLionel Sambuc             fprintf(stderr,
121ebfedea0SLionel Sambuc                     " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name);
122ebfedea0SLionel Sambuc         }
123ebfedea0SLionel Sambuc     }
124ebfedea0SLionel Sambuc 
125*0a6a1f1dSLionel Sambuc     if (verbose > 0) {
126ebfedea0SLionel Sambuc         fprintf(stderr, " DECC_INIT complete.\n");
127ebfedea0SLionel Sambuc     }
128ebfedea0SLionel Sambuc }
129ebfedea0SLionel Sambuc 
130ebfedea0SLionel Sambuc /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
131ebfedea0SLionel Sambuc 
132ebfedea0SLionel Sambuc # pragma nostandard
133ebfedea0SLionel Sambuc 
134*0a6a1f1dSLionel Sambuc /*
135*0a6a1f1dSLionel Sambuc  * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other
136*0a6a1f1dSLionel Sambuc  * attributes.  Note that "nopic" is significant only on VAX.
137ebfedea0SLionel Sambuc  */
138ebfedea0SLionel Sambuc # pragma extern_model save
139ebfedea0SLionel Sambuc 
140ebfedea0SLionel Sambuc # if __INITIAL_POINTER_SIZE == 64
141ebfedea0SLionel Sambuc #  define PSECT_ALIGN 3
142ebfedea0SLionel Sambuc # else
143ebfedea0SLionel Sambuc #  define PSECT_ALIGN 2
144ebfedea0SLionel Sambuc # endif
145ebfedea0SLionel Sambuc 
146ebfedea0SLionel Sambuc # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt
147ebfedea0SLionel Sambuc const int spare[8] = { 0 };
148ebfedea0SLionel Sambuc 
149ebfedea0SLionel Sambuc # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt
150ebfedea0SLionel Sambuc void (*const x_decc_init) () = decc_init;
151ebfedea0SLionel Sambuc 
152ebfedea0SLionel Sambuc # pragma extern_model restore
153ebfedea0SLionel Sambuc 
154ebfedea0SLionel Sambuc /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
155ebfedea0SLionel Sambuc 
156ebfedea0SLionel Sambuc # pragma extern_model save
157ebfedea0SLionel Sambuc 
158ebfedea0SLionel Sambuc int LIB$INITIALIZE(void);
159ebfedea0SLionel Sambuc 
160ebfedea0SLionel Sambuc # pragma extern_model strict_refdef
161ebfedea0SLionel Sambuc int dmy_lib$initialize = (int)LIB$INITIALIZE;
162ebfedea0SLionel Sambuc 
163ebfedea0SLionel Sambuc # pragma extern_model restore
164ebfedea0SLionel Sambuc 
165ebfedea0SLionel Sambuc # pragma standard
166ebfedea0SLionel Sambuc 
167ebfedea0SLionel Sambuc #else                           /* def USE_DECC_INIT */
168ebfedea0SLionel Sambuc 
169ebfedea0SLionel Sambuc /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */
170ebfedea0SLionel Sambuc int decc_init_dummy(void);
171ebfedea0SLionel Sambuc 
172ebfedea0SLionel Sambuc #endif                          /* def USE_DECC_INIT */
173