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

unix.superglobalmegacorp.com

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