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

  1. MODULE tsys;
  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. (* Test- und Anwendungsbeispiel fuer Modul 'sys'.
  14.  *
  15.  * Falls dem Programm ein Argument uebergeben wird, wird dieses als
  16.  * Pfadname interpretiert, der anstatt des aktuellen Verzeichnisses
  17.  * zur Ermittlung der Systemdaten mit "statfs()" und "pathconf()"
  18.  * benutzt werden soll.
  19.  *
  20.  * 29-Mai-94, Holger Kleinschmidt
  21.  *)
  22.  
  23. #if (defined MM2) && (defined __DEBUG_CODE__)
  24. IMPORT Debug;
  25. #endif
  26.  
  27. VAL_INTRINSIC
  28.  
  29. FROM SYSTEM IMPORT
  30. (* PROC *) ADR;
  31.  
  32. IMPORT e;
  33.  
  34. FROM PORTAB IMPORT
  35. (* TYPE *) SIGNEDLONG, UNSIGNEDWORD;
  36.  
  37. FROM types IMPORT
  38. (* CONST*) EOS,
  39. (* TYPE *) PathName;
  40.  
  41. FROM sys IMPORT
  42. (* TYPE *) PConfVal, SConfVal, UtsnameRec, StatfsRec,
  43. (* PROC *) pathconf, sysconf, time, uname, statfs;
  44.  
  45. FROM cstr IMPORT
  46. (* PROC *) strerror, AssignCToM2;
  47.  
  48. FROM lib IMPORT
  49. (* PROC *) ltoa;
  50.  
  51. FROM cmdline IMPORT
  52. (* PROC *) GetArg;
  53.  
  54. FROM InOut IMPORT
  55. (* PROC *) WriteString, WriteLn, Write, Read;
  56.  
  57. FROM pOUT IMPORT
  58. (* PROC *) PutInt;
  59.  
  60. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  61.  
  62. CONST
  63.   ERROR = LIC(-1);
  64.  
  65. VAR
  66.   limit   : SIGNEDLONG;
  67.   valStr  : ARRAY [0..40] OF CHAR;
  68.   ch      : CHAR;
  69.   res     : INTEGER;
  70.   argc    : INTEGER;
  71.   uts     : UtsnameRec;
  72.   statbuf : StatfsRec;
  73.   path    : PathName;
  74.  
  75. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  76.  
  77. PROCEDURE TestVal ((* EIN/ -- *) proc   : ARRAY OF CHAR;
  78.                    (* EIN/ -- *) limit  : SIGNEDLONG    );
  79. BEGIN
  80.  WriteString(proc);
  81.  IF limit = ERROR THEN
  82.    IF e.errno <> 0 THEN
  83.      WriteString("**failed**:: ");
  84.      AssignCToM2(strerror(e.errno), 0, valStr);
  85.      WriteString(valStr);
  86.      e.errno := 0;
  87.    ELSE
  88.      WriteString("nicht ermittelbar");
  89.    END;
  90.  ELSE
  91.    ltoa(limit, ADR(valStr), 10);
  92.    WriteString(valStr);
  93.  END;
  94.  WriteLn;
  95. END TestVal;
  96.  
  97. (*---------------------------------------------------------------------------*)
  98.  
  99. PROCEDURE TestBool ((* EIN/ -- *) proc   : ARRAY OF CHAR;
  100.                     (* EIN/ -- *) limit  : SIGNEDLONG;
  101.                     (* EIN/ -- *) yes    : ARRAY OF CHAR;
  102.                     (* EIN/ -- *) no     : ARRAY OF CHAR );
  103. BEGIN
  104.  WriteString(proc);
  105.  IF limit = ERROR THEN
  106.    IF e.errno <> 0 THEN
  107.      WriteString("**failed**:: ");
  108.      AssignCToM2(strerror(e.errno), 0, valStr);
  109.      WriteString(valStr);
  110.      e.errno := 0;
  111.    ELSE
  112.      WriteString(no);
  113.    END;
  114.  ELSE
  115.    WriteString(yes);
  116.  END;
  117.  WriteLn;
  118. END TestBool;
  119.  
  120. (*===========================================================================*)
  121.  
  122. BEGIN
  123.  res := uname(uts);
  124.  WITH uts DO
  125.    WriteString("sysname  : "); WriteString(sysname); WriteLn;
  126.    WriteString("nodename : "); WriteString(nodename); WriteLn;
  127.    WriteString("release  : "); WriteString(release); WriteLn;
  128.    WriteString("version  : "); WriteString(version); WriteLn;
  129.    WriteString("machine  : "); WriteString(machine); WriteLn;
  130.  END;
  131.  WriteLn;
  132.  
  133.  e.errno := 0;
  134.  TestVal("sysconf(_SC_ARG_MAX) : ", sysconf(scArgMax));
  135.  
  136.  TestVal("sysconf(_SC_OPEN_MAX) : ", sysconf(scOpenMax));
  137.  
  138.  TestVal("sysconf(_SC_CHILD_MAX) : ", sysconf(scChildMax));
  139.  
  140.  TestVal("sysconf(_SC_CLK_TCK) : ", sysconf(scClkTck));
  141.  
  142.  TestVal("sysconf(_SC_VERSION) : ", sysconf(scVersion));
  143.  
  144.  TestBool("sysconf(_SC_JOB_CONTROL) : ", sysconf(scJobControl),
  145.           "wird unterstützt", "wird nicht unterstützt");
  146.  
  147.  TestBool("sysconf(_SC_SAVED_IDS) : ", sysconf(scSavedIds),
  148.           "wird unterstützt", "wird nicht unterstützt");
  149.  
  150.  limit := sysconf(scNGroupsMax);
  151.  ltoa(limit, ADR(valStr), 10);
  152.  TestBool("sysconf(_SC_NGROUPS_MAX) : ", limit, valStr,
  153.           "wird nicht unterstützt");
  154.  WriteLn;
  155.  
  156.  GetArg(1, path);
  157.  IF path[0] = EOS THEN
  158.    (* kein Argument angegeben, aktuelles Verzeichnis verwenden *)
  159.    path := ".";
  160.  END;
  161.  WriteString("Dateisystemabhängige Daten für <path> = "); WriteString(path);
  162.  WriteLn; WriteLn;
  163.  
  164.  IF statfs(path, statbuf) < 0 THEN
  165.    WriteString("'statfs' **failed**:: ");
  166.    AssignCToM2(strerror(e.errno), 0, valStr);
  167.    WriteString(valStr);
  168.    WriteLn;
  169.  ELSE
  170.    WriteString("Dateisystem:"); WriteLn;
  171.    WriteString("------------"); WriteLn;
  172.    WITH statbuf DO
  173.      WriteString("              Typ: ");
  174.      CASE VAL(UNSIGNEDWORD,fFsid.val[0]) OF
  175.        1: WriteString("V1 Minix-FS");
  176.       |2: WriteString("V2 Minix-FS");
  177.      ELSE WriteString("TOS-FS oder unbekannt");
  178.      END;
  179.      WriteLn;
  180.      WriteString("  Bytes pro Block: "); PutInt(fBsize, 10); WriteLn;
  181.      WriteString(" Blöcke insgesamt: "); PutInt(fBlocks, 10); WriteLn;
  182.      WriteString("     freie Blöcke: "); PutInt(fBfree, 10); WriteLn;
  183.      WriteString("      freie Bytes: "); PutInt(fBfree * fBsize, 10); WriteLn;
  184.      WriteString("I-Nodes insgesamt: "); PutInt(fFiles, 10); WriteLn;
  185.      WriteString("    freie I-Nodes: "); PutInt(fFfree, 10); WriteLn;
  186.    END;
  187.  END;
  188.  WriteLn;
  189.  
  190.  
  191.  TestVal('pathconf(<path>, _PC_LINK_MAX) : ', pathconf(path, pcLinkMax));
  192.  
  193.  TestVal('pathconf(<path>, _PC_PATH_MAX) : ', pathconf(path, pcPathMax));
  194.  
  195.  TestVal('pathconf(<path>, _PC_NAME_MAX) : ', pathconf(path, pcNameMax));
  196.  
  197.  TestVal('pathconf(<path>, _PC_PIPE_BUF) : ', pathconf(path, pcPipeBuf));
  198.  
  199.  TestVal('pathconf("/dev/tty", _PC_VDISABLE) : ',
  200.          pathconf("/dev/tty", pcVdisable));
  201.  
  202.  TestVal('pathconf("/dev/tty", _PC_MAX_CANON) : ',
  203.          pathconf("/dev/tty", pcMaxCanon));
  204.  
  205.  TestVal('pathconf("/dev/tty", _PC_MAX_INPUT) : ',
  206.          pathconf("/dev/tty", pcMaxInput));
  207.  
  208.  limit := pathconf(path, pcNoTrunc);
  209.  TestBool('pathconf(<path>, _PC_NO_TRUNC) : ', limit,
  210.           "Dateinamen werden nicht gekuerzt","Dateinamen werden gekuerzt");
  211.  
  212.  limit := pathconf(path, pcChownRestricted);
  213.  TestBool('pathconf(<path>, _PC_CHOWN_RESTRICTED) : ', limit,"ja", "nein");
  214.  
  215.  Read(ch);
  216. END tsys.
  217.