
MODULE WBInfo;

  IMPORT
    d  := Dos,
    e  := Exec,
    I  := Intuition,
    ol := OberonLib,
    wb := Workbench,
    SYS:= SYSTEM;


  CONST
    version = "$VER: wbinfo 1.1 (12.5.94)";

  VAR
    args    : STRUCT (dummy: d.ArgsStruct) name,pub: e.STRPTR; END;
    lock    : d.FileLockPtr;
    name    : e.STRING;
    pub     : e.STRING;
    path    : e.STRING;
    fileptr : e.LSTRPTR;
    scr     : I.ScreenPtr;
    succ    : BOOLEAN;
    rd      : d.RDArgsPtr;
    pathptr : LONGINT;
    index   : LONGINT;

BEGIN
  IF version[0] = 0X THEN END;

  IF ol.wbStarted THEN HALT(0) END;

  IF (d.base.lib.version < 37) OR (wb.base=NIL) OR (wb.base.version < 39) THEN
    IF d.Write(d.Output(),"Need AmigaOS 3.0 or better\n",27)=0 THEN END;
    HALT(d.fail);
  END;


  rd := d.ReadArgs("NAME/A,U=PUBSCREEN/K",args,NIL);

  IF rd=NIL THEN
    SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
    HALT(d.warn)
  END;
  IF args.name # NIL THEN COPY(args.name^,name) END;
  IF args.pub  # NIL THEN COPY(args.pub^,pub)   END;

  d.FreeArgs(rd); rd := NIL;

  IF name # "" THEN

    fileptr := d.FilePart(name);
  
    COPY(name,path);
    pathptr := d.PathPart(path);
    index := pathptr-SYS.VAL(LONGINT,SYS.ADR(path));
  
    IF (index >= 0) & (index < SIZE(path)) THEN
      path[index] := 0X;
    END;
  
    lock := d.Lock(path,d.sharedLock);
  
    IF lock # NIL THEN

      IF pub="" THEN
        scr := I.LockPubScreen(NIL)
      ELSE
        scr := I.LockPubScreen(pub);
        IF scr=NIL THEN scr := I.LockPubScreen(NIL) END;
      END;

      IF scr # NIL THEN
        wb.WBInfo(lock,fileptr^,scr);
        I.UnlockPubScreen(NIL,scr);
      END;

      d.UnLock(lock);
    END;
  END;
END WBInfo.

