REM > CreateJCode:Create

DEF PROCCreate(Path$)
LOCAL Name$, Sprt$
LOCAL Temp%, Spr1%, Spr2%

REMLOCAL ERROR
REMON ERROR LOCAL RESTORE ERROR: PROCCreate_Error

Name$ = FNWimp_GetLeaf(Path$)

SYS"OS_CLI", "CDir " + Path$
SYS"OS_CLI", "Copy " + Task_Path$ + "Base " + Path$ + ".!" + Name$ + " A~C~DFL~N~P~QR~S~T~V"
SYS"OS_CLI", "CDir " + Path$ + "." + Name$
SYS"OS_CLI", "CDir " + Path$ + "." + Name$ + ".Basic"

PROCWimp_LoadFile(Task_Path$ + "Files.!Sprites", 1, "Sprites")
PROCWimp_LoadFile(Task_Path$ + "Files.!Sprites22", 1, "Sprites22")
Spr1% = FNHeap_Find(1, "Sprites")
Spr2% = FNHeap_Find(1, "Sprites22")
Sprt$ = "!" + FNString_Lower(LEFT$(Name$, 11))
$(Spr1% + 4 + &10) = Sprt$
$(Spr2% + 4 + &10) = Sprt$
Spr1%?(4 + &10 + LENSprt$) = 0
Spr2%?(4 + &10 + LENSprt$) = 0
SYS"OS_File", 10, Path$ + ".!" + Name$ + ".!Sprites", &FF9,, Spr1% + 4, Spr1% + !Spr1% + 4
SYS"OS_File", 10, Path$ + ".!" + Name$ + ".!Sprites22", &FF9,, Spr2% + 4, Spr2% + !Spr2% + 4
PROCHeap_Lose(1, "Sprites")
PROCHeap_Lose(1, "Sprites22")

Type$ = "Obey"
PROCCopy(Task_Path$ + "Files.!Run", Path$ + ".!" + Name$ + ".!Run")
PROCCopy(Task_Path$ + "Files.!Run2", Path$ + "." + Name$ + ".!Run")
PROCCopy(Task_Path$ + "Files.LinkCrunch", Path$ + "." + Name$ +".LinkCrunch")

Type$ = "Text"
PROCCopy(Task_Path$+"Files.Menus", Path$ + ".!" +Name$+".Resources.UK.Menus")

Type$ = "BASIC"
PROCBasic(Task_Path$ + "Files.!Main",    Path$ + "." + Name$ + ".!Main")
PROCBasic(Task_Path$+"Files.Basic.Click",Path$ + "." + Name$ +".Basic.Click")
PROCBasic(Task_Path$+"Files.Basic.Init", Path$ + "." + Name$ + ".Basic.Init")
PROCBasic(Task_Path$+"Files.Basic.Menu", Path$ + "." + Name$ + ".Basic.Menu")
PROCBasic(Task_Path$+"Files.Basic.Quit", Path$ + "." + Name$ + ".Basic.Quit")

ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCCreate_Error
PROCHeap_Lose(1, "*")
Erro_ERL% = ERL
Erro_REPORT$ = REPORT$
Erro_ERR% = Erro_Warn%
ERROR Erro_Warn%, REPORT$
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCCopy(Fil1$, Fil2$)
LOCAL Fil1%, Fil2%, Byte%, Byt1%, Byt2%, Loop%

Fil1% = OPENIN(Fil1$)
Fil2% = OPENOUT(Fil2$)

REMLOCAL ERROR
REMON ERROR LOCAL RESTORE ERROR: PROCCopy_Error

 WHILE NOT EOF#Fil1%
  Byte% = BGET#Fil1%
   IF Byte% = ASC"{" THEN
    Byt1% = BGET#Fil1%
    Byt2% = BGET#Fil1%
     IF (Byt1% = ASC"!") AND (Byt2% = ASC"}") THEN
       FOR Loop% = 1 TO LENName$
        BPUT#Fil2%, ASC(MID$(Name$, Loop%, 1))
       NEXT
     ELSE
      BPUT#Fil2%, Byte%
      BPUT#Fil2%, Byt1%
      BPUT#Fil2%, Byt2%
     ENDIF
   ELSE
    BPUT#Fil2%, Byte%
   ENDIF
 ENDWHILE

REMRESTORE ERROR

CLOSE#Fil1%
CLOSE#Fil2%
SYS"OS_CLI", "SetType " + Fil2$ + " " + Type$
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCCopy_Error
CLOSE#Fil1%
CLOSE#Fil2%
Erro_ERL% = ERL
Erro_REPORT$ = REPORT$
Erro_ERR% = Erro_Warn%
ERROR Erro_Warn%, REPORT$
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCBasic(Fil1$, Fil2$)
LOCAL Fil1%, Fil2%, Byte%, Byt1%, Byt2%

Fil1% = OPENIN(Fil1$)
Fil2% = OPENOUT(Fil2$)

REMLOCAL ERROR
REMON ERROR LOCAL RESTORE ERROR: PROCCopy_Error

Byte% = BGET#Fil1%      :REM &D
BPUT#Fil2%, Byte%
Byte% = BGET#Fil1%      :REM line 1
 WHILE Byte% <> &FF
  BPUT#Fil2%, Byte%
  Byte% = BGET#Fil1%    :REM line 2
  BPUT#Fil2%, Byte%
  Byte% = BGET#Fil1%    :REM length
  Line$ = ""
  Byte% = BGET#Fil1%
   WHILE Byte% <> &D
     IF Byte% = ASC"{" THEN
      Byt1% = BGET#Fil1%
      Byt2% = BGET#Fil1%
       IF (Byt1% = ASC"!") AND (Byt2% = ASC"}") THEN
        Line$ += Name$
       ENDIF
     ELSE
      Line$ += CHR$(Byte%)
     ENDIF
    Byte% = BGET#Fil1%
   ENDWHILE
  BPUT#Fil2%, LENLine$ + 4
  BPUT#Fil2%, Line$;
  BPUT#Fil2%, Byte%
  Byte% = BGET#Fil1%    :REM line 1
 ENDWHILE
BPUT#Fil2%, Byte%

REMRESTORE ERROR

CLOSE#Fil1%
CLOSE#Fil2%
SYS"OS_CLI", "SetType " + Fil2$ + " " + Type$
ENDPROC
