Annotation of coherent/f/tmp/inst2/setdate.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * setdate: used in post processing of install to setup /etc/timezone
        !             3:  */
        !             4: 
        !             5: /*
        !             6:  * includes
        !             7:  */
        !             8: 
        !             9: #include <stdio.h>
        !            10: #include <time.h>
        !            11: #include "build0.h"
        !            12: 
        !            13: 
        !            14: /*
        !            15:  * declarations
        !            16:  */
        !            17: 
        !            18: char   tzone[NBUF];                    /* timezone             */
        !            19: char   tzone5[NBUF];                   /* timezone for Sys V   */
        !            20: 
        !            21: /*
        !            22:  * Set up a nonstandard timezone.
        !            23:  */
        !            24: void
        !            25: get_timezone(dstflag)
        !            26: int dstflag;
        !            27: {
        !            28:        register char *s;
        !            29:        int diff;
        !            30:        char std_abbr[20], dst_abbr[20];
        !            31:        int east_of_gr;
        !            32: 
        !            33:        /* tzone5 is like tzone except no colons and number is in hours */
        !            34: 
        !            35:        printf(
        !            36: "You need to specify an abbreviation for your timezone,\n"
        !            37: "whether you are east or west of Greenwich, England,\n"
        !            38: "and the difference in minutes between your timezone\n"
        !            39: "and Greenwich Time (called UT or GMT).  For example,\n"
        !            40: "Germany is 60 minutes of time east of Greenwich.\n"
        !            41:                );
        !            42:        s = get_line("Abbreviation for your timezone:");
        !            43:        strcpy(std_abbr, s);
        !            44:        east_of_gr = yes_no("Is your timezone east of Greenwich");
        !            45:        s = get_line("Difference in minutes from GMT:");
        !            46:        diff = atoi(s);
        !            47:        if (east_of_gr)
        !            48:                diff = -diff;
        !            49:        if (dstflag) {
        !            50:                s = get_line("Abbreviation for your daylight savings timezone:");
        !            51:                strcpy(dst_abbr, s);
        !            52:                sprintf(tzone, "%s:%d:%s:1.1.4", std_abbr, diff, dst_abbr);
        !            53:                sprintf(tzone5, "%s%d%s", std_abbr, diff/60, dst_abbr);
        !            54:        } else {
        !            55:                sprintf(tzone, "%s:%d:", std_abbr, diff);
        !            56:                sprintf(tzone5, "%s%d", std_abbr, diff/60);
        !            57:        }
        !            58: }
        !            59: 
        !            60: 
        !            61: /*
        !            62:  * Date and time.
        !            63:  */
        !            64: 
        !            65: main()
        !            66: {
        !            67:        register char *s;
        !            68:        int dst_conv;           /* 1 if DST conversion will be used */
        !            69:        int dst_now;            /* 1 if DST in effect today */
        !            70:        int n;
        !            71:        char *tz;
        !            72:        time_t now;
        !            73:        struct tm *tmp;
        !            74:        char *timestr;
        !            75: 
        !            76: again:
        !            77:        /* new set_date */
        !            78: 
        !            79:        /*
        !            80:         * yyy:
        !            81:         *
        !            82:         * dst_conv = FALSE
        !            83:         * dst_now = FALSE
        !            84:         *
        !            85:         * if using DST conversion
        !            86:         *      dst_conv = TRUE
        !            87:         *      if DST in effect today
        !            88:         *              dst_now = TRUE
        !            89:         * get date from system clock
        !            90:         * if dst_conv and dst_now
        !            91:         *      add 1 hour to date fetched
        !            92:         * display date
        !            93:         * while date not correct
        !            94:         *      if proceed without setting clock
        !            95:         *              goto xxx
        !            96:         *      read date from kb
        !            97:         *      write date to CMOS clock and RAM clock
        !            98:         *      if dst_conv and dst_now
        !            99:         *              subtract 1 hour from date entered
        !           100:         *              write adjusted date to CMOS clock
        !           101:         * xxx:
        !           102:         * set TIMEZONE and TZ variables
        !           103:         * if date, TIMEZONE, and TZ not all correct
        !           104:         *      goto yyy
        !           105:         */
        !           106:        cls(0);
        !           107:        dst_conv = 0;
        !           108:        dst_now = 0;
        !           109:        printf(
        !           110: "You can run COHERENT with or without conversion for daylight savings time\n"
        !           111: "(summer time).  You should normally run with daylight savings time\n"
        !           112: "conversion.  However, if you are going to use both COHERENT and MS-DOS\n"
        !           113: "and you choose to run with daylight savings time conversion,\n"
        !           114: "your time will be wrong (by one hour) during daylight savings time\n"
        !           115: "while you are running under MS-DOS.\n"
        !           116: "\n"
        !           117:                );
        !           118:        if (yes_no(
        !           119:          "Do you want COHERENT to use daylight savings time conversion")) {
        !           120:                dst_conv = 1;
        !           121:                printf(
        !           122: "\n"
        !           123: "By default, COHERENT assumes daylight savings time begins on the\n"
        !           124: "first Sunday in April and ends on the last Sunday in October.\n"
        !           125: "If you want to change the defaults, edit the file \"/etc/timezone\"\n"
        !           126: "after you finish installing COHERENT.\n"
        !           127: "\n"
        !           128:                );
        !           129:                if (yes_no("Is daylight savings time currently in effect"))
        !           130:                        dst_now = 1;
        !           131:        }
        !           132:        system("/bin/date `/etc/ATclock` > /dev/null");
        !           133:        now = time(0);
        !           134:        if (dst_conv && dst_now)
        !           135:                now += 3600;
        !           136:        timestr = ctime(&now);
        !           137:        printf(
        !           138: "\nAccording to your system clock, your local date and time are:\n"
        !           139:        );
        !           140:        printf("%s\n", timestr);
        !           141:        if (!yes_no("Is this correct")) {
        !           142:                n = 0;
        !           143:                do {
        !           144:                        if (++n > 3) {
        !           145:                                printf(
        !           146: "The command which sets the internal real-time clock of your system is\n"
        !           147: "failing repeatedly.  Either you are entering the date and time incorrectly\n"
        !           148: "or your clock hardware is not completely AT-compatible.  If your clock\n"
        !           149: "hardware is incompatible, you can continue with the installation without\n"
        !           150: "setting the clock correctly.  However, if you do so, subsequent clock\n"
        !           151: "references (including file access and modification time information) will be\n"
        !           152: "incorrect and some commands (such as \"date\") will not function correctly.\n"
        !           153:                                        );
        !           154:                                if (yes_no("Do you want to proceed without setting the clock correctly"))
        !           155:                                        break;
        !           156:                                n = 0;
        !           157:                        }
        !           158:                        s = get_line(
        !           159: "\nEnter the correct date and time in the form YYMMDDHHMM.SS:"
        !           160:                                );
        !           161:                        sprintf(cmd, "/etc/ATclock %s >/dev/null", s);
        !           162:                } while (sys(cmd, S_NONFATAL) != 0);
        !           163:                sys("/bin/date `/etc/ATclock` >/dev/null", S_NONFATAL);
        !           164: 
        !           165:                if (dst_conv && dst_now) {
        !           166:                        /* Adjust for DST: set hardware clock back one hour. */
        !           167:                        now = time(0) - 3600;
        !           168:                        tmp = localtime(&now);
        !           169:                        sprintf(cmd,
        !           170:                          "/etc/ATclock %02d%02d%02d%02d%02d.%02d >/dev/null",
        !           171:                          tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
        !           172:                          tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
        !           173:                        sys(cmd, S_NONFATAL);
        !           174:                }
        !           175: 
        !           176:        }
        !           177: 
        !           178:        /* Timezone. */
        !           179:        cls(0);
        !           180:        printf(
        !           181: "Please choose one of the following timezones:\n"
        !           182: "\t0\tCentral European\n"
        !           183: "\t1\tGreenwich\n"
        !           184: "\t2\tNewfoundland\n"
        !           185: "\t3\tAtlantic\n"
        !           186: "\t4\tEastern\n"
        !           187: "\t5\tCentral\n"
        !           188: "\t6\tMountain\n"
        !           189: "\t7\tPacific\n"
        !           190: "\t8\tYukon\n"
        !           191: "\t9\tAlaska\n"
        !           192: "\t10\tBering\n"
        !           193: "\t11\tHawaii\n"
        !           194: "\t12\tOther\n"
        !           195:                );
        !           196:        do {
        !           197:                s = get_line("Timezone code:");
        !           198:        } while ((n = atoi(s)) < 0 || n > 12);
        !           199:        switch (n) {
        !           200:        /* N.B. entries truncated at tz[8] below if !dst_conv. */
        !           201:        case 0:         tz = "EST:-60:EDT:1.1.4";       break;
        !           202:        case 1:         tz = "GMT:000:GDT:1.1.4";       break;
        !           203:        case 2:         tz = "NST:210:NDT:1.1.4";       break;
        !           204:        case 3:         tz = "AST:240:ADT:1.1.4";       break;
        !           205:        case 4:         tz = "EST:300:EDT:1.1.4";       break;
        !           206:        case 5:         tz = "CST:360:CDT:1.1.4";       break;
        !           207:        case 6:         tz = "MST:420:MDT:1.1.4";       break;
        !           208:        case 7:         tz = "PST:480:PDT:1.1.4";       break;
        !           209:        case 8:         tz = "YST:540:YDT:1.1.4";       break;
        !           210:        case 9:         tz = "AST:600:ADT:1.1.4";       break;
        !           211:        case 10:        tz = "BST:660:BDT:1.1.4";       break;
        !           212:        case 11:        tz = "HST:600:HDT:1.1.4";       break;
        !           213:        case 12:        tz = NULL;                      break;
        !           214:        }
        !           215: 
        !           216:        if (tz == NULL)
        !           217:                get_timezone(dst_conv);
        !           218:        else {
        !           219:                strcpy(tzone, tz);
        !           220:                if (dst_conv) {
        !           221:                        /* for TZ, AST:240:ADT becomes AST4ADT */
        !           222:                        sprintf(tzone5, "%.3s%d%cDT",
        !           223:                          tz, atoi(tzone + 4)/60, tz[0]);
        !           224:                } else {
        !           225:                        /* for TZ, AST:240 becomes AST4 */
        !           226:                        sprintf(tzone5, "%.3s%d", tz, atoi(tzone + 4)/60);
        !           227:                        tzone[8] = '\0';
        !           228:                }
        !           229:        }
        !           230:        /* Done, print current time and retry if user botched it. */
        !           231:        printf("\nYour current local date and time are now:\n");
        !           232:        sprintf(cmd, "TIMEZONE='%s' /bin/date -s `/etc/ATclock`", tzone);
        !           233:        sys(cmd, S_NONFATAL);
        !           234: 
        !           235:        /* Write the timezone to /tmp/timezone for debug */
        !           236:        sprintf(cmd, "/bin/echo export TIMEZONE=\\\"%s\\\" >/tmp/timezone", tzone);
        !           237:        sys(cmd, S_NONFATAL);
        !           238:        sprintf(cmd, "/bin/echo export TZ=\\\"%s\\\" >>/tmp/timezone", tzone5);
        !           239:        sys(cmd, S_NONFATAL);
        !           240:        if (!yes_no("Is this correct"))
        !           241:                goto again;
        !           242:        system("/bin/cp /tmp/timezone /etc/timezone");
        !           243:        system("/bin/chmog 644 bin bin /etc/timezone");
        !           244:        exit(0);
        !           245: }
        !           246: 

unix.superglobalmegacorp.com

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