home *** CD-ROM | disk | FTP | other *** search
- MODULE showdate;
- __IMP_SWITCHES__
- __DEBUG__
- #ifdef HM2
- #ifdef __LONG_WHOLE__
- (*$!i+: Modul muss mit $i- uebersetzt werden! *)
- (*$!w+: Modul muss mit $w- uebersetzt werden! *)
- #else
- (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
- (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
- #endif
- #endif
-
- (* Eine ``Read-Only''-Version von 'date', um die Funktionen aus 'tim' zu
- * demonstrieren.
- *
- * Ohne Parameter wird die lokale Zeit ausgegeben, mit dem Parameter -u
- * die UTC-Zeit.
- *
- * Das Programm wertet das 'LC_TIME'-Locale aus: wenn die entsprechende
- * Environmentvariable (z.B. LANG) den Wert 'german' hat, werden
- * Datum und Zeit mehr den deutschen Konventionen entsprechend ausgegeben,
- * sonst wird das bei POSIX.2 verwendete Format benutzt.
- *
- * 29-Mai-94, Holger Kleinschmidt
- *)
-
- #if (defined MM2) && (defined __DEBUG_CODE__)
- IMPORT Debug;
- #endif
-
- VAL_INTRINSIC
- CAST_IMPORT
-
-
- FROM SYSTEM IMPORT
- (* PROC *) ADR;
-
- FROM Terminal IMPORT
- (* PROC *) WriteString, WriteLn, Read;
-
- FROM types IMPORT
- (* CONST*) NULL,
- (* TYPE *) StrPtr, sizeT;
-
- FROM pSTRING IMPORT
- (* PROC *) EQUAL;
-
- FROM cstr IMPORT
- (* PROC *) strcmp;
-
- FROM cmdline IMPORT
- (* PROC *) ArgCount, GetArg;
-
- FROM sys IMPORT
- (* PROC *) time;
-
- FROM tim IMPORT
- (* TYPE *) TmRec, TmPtr,
- (* PROC *) strftime, localtime, gmtime;
-
- FROM loc IMPORT
- (* TYPE *) LcType,
- (* PROC *) setlocale;
-
- (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
-
- VAR
- buf : ARRAY [0..100] OF CHAR;
- fmt : ARRAY [0..40] OF CHAR;
- len : INTEGER;
- utc : BOOLEAN;
- which : StrPtr;
- c : CHAR;
-
- (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
-
- BEGIN
- GetArg(1, buf);
- utc := EQUAL("-u", buf);
-
- buf := "";
- which := setlocale(LcTime, ADR(buf));
- buf := "german";
- IF strcmp(which, ADR(buf)) = 0 THEN
- IF utc THEN
- fmt := "%A, %e. %B %Y, %H:%M Uhr UTC";
- ELSE
- fmt := "%A, %e. %B %Y, %H:%M Uhr %Z";
- END;
- ELSE
- IF utc THEN
- fmt := "%a %b %e %H:%M:%S UTC %Y";
- ELSE
- fmt := "%a %b %e %H:%M:%S %Z %Y";
- END;
- END;
-
- IF utc THEN
- len := INT(strftime(CAST(StrPtr,ADR(buf)),
- SIZE(buf),
- ADR(fmt),
- gmtime(time(NULL))));
- ELSE
- len := INT(strftime(CAST(StrPtr,ADR(buf)),
- SIZE(buf),
- ADR(fmt),
- localtime(time(NULL))));
- END;
-
- IF len > 0 THEN
- WriteString(buf);
- ELSE
- WriteString("*** error");
- END;
- WriteLn;
-
- Read(c);
- END showdate.
-