/*
    $VER: TeX-Start.ged V0.97 (19.3.94) Axel Burghardt
*/

OPTIONS RESULTS

IF SHOW('P','GOLDED.1') THEN
  ADDRESS "GOLDED.1"

'LOCK CURRENT'

Title = "TeX-Start V0.97"
Port = 'TEX.1'

IF SHOW('P','TEX.1') THEN DO

  IF "" = GETCLIP("TEXQUERY") THEN 
    Askformat = 0
  ELSE 
    Askformat = 1

  PARSE ARG Format .
  IF "?" = Format THEN DO
    Askformat= 1
    Format   = ""
  END
  ELSE 
    IF '&' = LEFT(Format,1) THEN
      Format = SUBSTR(Format,2)

  'QUERY DOC VAR FULLNAME'

/* ---------------- Den absoluten Namen ermitteln ----------------- */

  PARSE VALUE namestruc(Fullname) WITH ivol idirs ibase .

  IF "" == SUBSTR(Fullname, 1+ivol+idirs+ibase) | UPPER(RIGHT(Fullname,3)) ~= "TEX" THEN DO
    'REQUEST BODY="Datei muß mit '.TeX' enden!" TITLE="'Title'"'
    EXIT 5
  END

  IF 0 = ivol THEN DO
    Direc = PRAGMA('d')
    IF RIGHT(Direc,1)~='/' & RIGHT(Direc,1)~=':' THEN Direc=Direc'/'
    Fullname = Direc||Fullname
    DROP Direc
  END
  DROP ivol idirs ibase

  'QUERY MODIFY VAR MODIFY'
  IF (Modify = 1) THEN
    'SAVE ALL'

/* --------------------- Setze das TeX-Format --------------------- */

  Envformat = NewGetenv("TEXFORMAT")
  IF "" == Format THEN DO
    Format = Envformat
    IF askformat | "" = Envformat THEN DO
      IF "" = Format THEN Format = 'plain'
      'REQUEST STRING BODY="Welches Format soll benutzt werden?" VAR NFORMAT TITLE="'Title'"'
      IF Format ~= Nformat THEN Format = Nformat
    END
  END

  IF Format ~= Envformat THEN CALL NewSetenv("TEXFORMAT",Format)

  ADDRESS VALUE Port
  'COMPILE' Format Fullname
  ADDRESS VALUE 'GOLDED.1'
  'UNLOCK'
  EXIT 0
END
ELSE DO
  'REQUEST BODY="TeX-Server läuft noch nicht!" BUTTON="_Starten|_Abbrechen" TITLE="'Title'"'
  IF Result ~= 0 THEN DO
    'UNLOCK'
    call 'GOLDED:AREXX/TeX-Server-Start.ged'
    EXIT 0
  END
  ELSE DO
    'UNLOCK'
    EXIT 5
  END
END



NewGetenv: PROCEDURE
  PARSE ARG Name

  IF open(TEMPFILE,"ENV:"Name,'r') THEN DO
    Gives = readln(TEMPFILE)
    CALL close TEMPFILE
  END
  ELSE gives = ""
  RETURN gives

NewSetenv: PROCEDURE
  PARSE ARG Name,Content

  ADDRESS COMMAND "SetEnv" Name Content
  RETURN
