home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / m2posx14 / test / showdate.mpp < prev    next >
Encoding:
Text File  |  1994-05-29  |  2.6 KB  |  120 lines

  1. MODULE showdate;
  2. __IMP_SWITCHES__
  3. __DEBUG__
  4. #ifdef HM2
  5. #ifdef __LONG_WHOLE__
  6. (*$!i+: Modul muss mit $i- uebersetzt werden! *)
  7. (*$!w+: Modul muss mit $w- uebersetzt werden! *)
  8. #else
  9. (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
  10. (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
  11. #endif
  12. #endif
  13.  
  14. (* Eine ``Read-Only''-Version von 'date', um die Funktionen aus 'tim' zu
  15.  * demonstrieren.
  16.  *
  17.  * Ohne Parameter wird die lokale Zeit ausgegeben, mit dem Parameter -u
  18.  * die UTC-Zeit.
  19.  *
  20.  * Das Programm wertet das 'LC_TIME'-Locale aus: wenn die entsprechende
  21.  * Environmentvariable (z.B. LANG) den Wert 'german' hat, werden
  22.  * Datum und Zeit mehr den deutschen Konventionen entsprechend ausgegeben,
  23.  * sonst wird das bei POSIX.2 verwendete Format benutzt.
  24.  *
  25.  * 29-Mai-94, Holger Kleinschmidt
  26.  *)
  27.  
  28. #if (defined MM2) && (defined __DEBUG_CODE__)
  29. IMPORT Debug;
  30. #endif
  31.  
  32. VAL_INTRINSIC
  33. CAST_IMPORT
  34.  
  35.  
  36. FROM SYSTEM IMPORT
  37. (* PROC *) ADR;
  38.  
  39. FROM Terminal IMPORT
  40. (* PROC *) WriteString, WriteLn, Read;
  41.  
  42. FROM types IMPORT
  43. (* CONST*) NULL,
  44. (* TYPE *) StrPtr, sizeT;
  45.  
  46. FROM pSTRING IMPORT
  47. (* PROC *) EQUAL;
  48.  
  49. FROM cstr IMPORT
  50. (* PROC *) strcmp;
  51.  
  52. FROM cmdline IMPORT
  53. (* PROC *) ArgCount, GetArg;
  54.  
  55. FROM sys IMPORT
  56. (* PROC *) time;
  57.  
  58. FROM tim IMPORT
  59. (* TYPE *) TmRec, TmPtr,
  60. (* PROC *) strftime, localtime, gmtime;
  61.  
  62. FROM loc IMPORT
  63. (* TYPE *) LcType,
  64. (* PROC *) setlocale;
  65.  
  66. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  67.  
  68. VAR
  69.   buf : ARRAY [0..100] OF CHAR;
  70.   fmt : ARRAY [0..40] OF CHAR;
  71.   len : INTEGER;
  72.   utc : BOOLEAN;
  73.   which : StrPtr;
  74.   c   : CHAR;
  75.  
  76. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  77.  
  78. BEGIN
  79.  GetArg(1, buf);
  80.  utc := EQUAL("-u", buf);
  81.  
  82.  buf   := "";
  83.  which := setlocale(LcTime, ADR(buf));
  84.  buf   := "german";
  85.  IF strcmp(which, ADR(buf)) = 0 THEN
  86.    IF utc THEN
  87.      fmt := "%A, %e. %B %Y, %H:%M Uhr UTC";
  88.    ELSE
  89.      fmt := "%A, %e. %B %Y, %H:%M Uhr %Z";
  90.    END;
  91.  ELSE
  92.    IF utc THEN
  93.      fmt := "%a %b %e %H:%M:%S UTC %Y";
  94.    ELSE
  95.      fmt := "%a %b %e %H:%M:%S %Z %Y";
  96.    END;
  97.  END;
  98.  
  99.  IF utc THEN
  100.    len := INT(strftime(CAST(StrPtr,ADR(buf)),
  101.                        SIZE(buf),
  102.                        ADR(fmt),
  103.                        gmtime(time(NULL))));
  104.  ELSE
  105.    len := INT(strftime(CAST(StrPtr,ADR(buf)),
  106.                        SIZE(buf),
  107.                        ADR(fmt),
  108.                        localtime(time(NULL))));
  109.  END;
  110.  
  111.  IF len > 0 THEN
  112.    WriteString(buf);
  113.  ELSE
  114.    WriteString("*** error");
  115.  END;
  116.  WriteLn;
  117.  
  118.  Read(c);
  119. END showdate.
  120.