Annotation of coherent/b/STREAMS/conf_79/mktune.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *-IMPORTS:
                      3:  *     <sys/compat.h>
                      4:  *             LOCAL
                      5:  *             USE_PROTO
                      6:  *             ARGS ()
                      7:  *     <stdio.h>
                      8:  *             NULL
                      9:  *             FILE
                     10:  *             stdout
                     11:  *             fopen ()
                     12:  *             fclose ()
                     13:  *             fprintf ()
                     14:  *     <time.h>
                     15:  *             time_t
                     16:  *             localtime ()
                     17:  *             time ()
                     18:  *             strftime ()
                     19:  *     <limits.h>
                     20:  *             INT_MAX
                     21:  *             INT_MIN
                     22:  */
                     23: 
                     24: #include <sys/compat.h>
                     25: #include <stdio.h>
                     26: #include <time.h>
                     27: #include <limits.h>
                     28: 
                     29: #include "mtune.h"
                     30: #include "stune.h"
                     31: #include "symbol.h"
                     32: #include "ehand.h"
                     33: 
                     34: #include "mkconf.h"
                     35: 
                     36: 
                     37: /*
                     38:  * Write out C-language definitions for the values of the tunable parameters.
                     39:  */
                     40: 
                     41: #ifdef USE_PROTO
                     42: LOCAL void (write_params) (FILE * out)
                     43: #else
                     44: LOCAL void
                     45: write_params ARGS ((out))
                     46: FILE         * out;
                     47: #endif
                     48: {
                     49:        mtune_t       * scan;
                     50:        enum {
                     51:                FIRST,
                     52:                REST
                     53:        } state = FIRST;
                     54: 
                     55:        for (scan = mtunes () ; scan != NULL ; scan = scan->mt_next) {
                     56:                long    value;
                     57: 
                     58:                /*
                     59:                 * Parameters that are within the range of representation of
                     60:                 * an integer go into an enumeration. Unless this is Coherent,
                     61:                 * numbers larger than that become "static const long".
                     62:                 *
                     63:                 * Note that Coherent compiles comparisons to INT_MIN into
                     64:                 * broken code as of this writing (April '93).
                     65:                 */
                     66: 
                     67:                value = scan->mt_stune == NULL ? scan->mt_default :
                     68:                                scan->mt_stune->st_value;
                     69: 
                     70: #ifndef        __COHERENT__
                     71:                if (value < INT_MIN || value > INT_MAX) {
                     72:                        if (state == REST)
                     73:                                fprintf (out, "\n};\n");
                     74:                        state = FIRST;
                     75: 
                     76:                        fprintf (out, "#ifdef\t__cplusplus\n");
                     77:                        fprintf (out, "static const long %s = %ld;\n",
                     78:                                 scan->mt_name->s_data, value);
                     79:                        fprintf (out, "#else\n");
                     80:                        fprintf (out, "#define %s %ldL\n",
                     81:                                 scan->mt_name->s_data, value);
                     82:                        fprintf (out, "#endif\n");
                     83:                } else {
                     84: #endif
                     85:                        fprintf (out, state == FIRST ? "enum {\n" : ",\n");
                     86:                        fprintf (out, "\t%s = %ld", scan->mt_name->s_data,
                     87:                                 value);
                     88:                        state = REST;
                     89: #ifndef        __COHERENT__
                     90:                }
                     91: #endif
                     92:        }
                     93: 
                     94:        if (state == REST)
                     95:                fprintf (out, "\n};\n\n");
                     96: }
                     97: 
                     98: 
                     99: /*
                    100:  * Write out a C-language header file with definitions for the values of all
                    101:  * the tunable parameters in the system.
                    102:  */
                    103: 
                    104: #ifdef __USE_PROTO__
                    105: int (write_conf_h) (CONST char * name)
                    106: #else
                    107: int
                    108: write_conf_h ARGS ((name))
                    109: CONST char    *        name;
                    110: #endif
                    111: {
                    112:        time_t          gentime;
                    113:        char            timebuf [70];
                    114:        FILE          * out;
                    115:        ehand_t         err;
                    116: 
                    117:        if (name == NULL)
                    118:                out = stdout;
                    119:        else if ((out = fopen (name, "w")) == NULL)
                    120:                throw_error ("Unable to open output file for writing");
                    121: 
                    122:        if (PUSH_HANDLER (err) == 0) {
                    123:                time (& gentime);
                    124: 
                    125:                fprintf (out, "#ifndef\t__SYS_CONF_H__\n");
                    126:                fprintf (out, "#define\t__SYS_CONF_H__\n\n");
                    127: 
                    128:                fprintf (out, "/*\n");
                    129:                fprintf (out, " * The code in this file was automatically "
                    130:                              "generated. Do not hand-modify!\n");
                    131: 
                    132: #ifdef __COHERENT__
                    133:                strncpy (timebuf, asctime (localtime (& gentime)),
                    134:                         sizeof (timebuf) - 1);
                    135:                timebuf [sizeof (timebuf) - 1] = 0;
                    136: #else
                    137:                strftime (timebuf, sizeof (timebuf) - 1, "%x %X %Z",
                    138:                          localtime (& gentime));
                    139: #endif
                    140: 
                    141:                fprintf (out, " * Generated at %s\n", timebuf);
                    142:                fprintf (out, " */\n\n");
                    143: 
                    144:                write_params (out);
                    145: 
                    146:                fprintf (out, "#endif\t/* ! defined (__SYS_CONF_H__) */\n");
                    147: 
                    148:                if (out != stdout)
                    149:                        fclose (out);
                    150:        } else {
                    151:                if (out != stdout)
                    152:                        fclose (out);
                    153:                CHAIN_ERROR (err);
                    154:        }
                    155: 
                    156:        POP_HANDLER (err);
                    157:        return 0;
                    158: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.