editors

changeset 57:149815b0874c tip

* added installer for jEdit mode
author Shawn David Pringle B.Sc. <shawn.pringle@gmail.com>
date Fri Sep 25 00:03:32 2015 -0300 (2015-09-25)
parents 1197106848bf
children
files jEdit/install_mode.ex
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/jEdit/install_mode.ex	Fri Sep 25 00:03:32 2015 -0300
     1.3 @@ -0,0 +1,108 @@
     1.4 +include std/types.e
     1.5 +include std/filesys.e
     1.6 +include std/os.e
     1.7 +include std/io.e
     1.8 +
     1.9 +procedure err(sequence msg)
    1.10 +	puts(STDERR, "Cannot install mode: "&msg&"\n")
    1.11 +	abort(1)
    1.12 +end procedure
    1.13 +
    1.14 +puts(STDOUT, "This program will install the EUPHORIA mode for jEdit.\n" &
    1.15 +	"Press ENTER to continue or CNTRL+C to stop.\n")
    1.16 +object line
    1.17 +line = gets(STDIN)
    1.18 +
    1.19 +constant home = getenv("HOME")
    1.20 +constant appdata = getenv("APPDATA")
    1.21 +ifdef WINDOWS then
    1.22 +	if atom(appdata) then
    1.23 +		err("No AppData directory.")
    1.24 +	end if
    1.25 +elsedef
    1.26 +	if atom(home) then
    1.27 +		err("No HOME directory.")
    1.28 +	end if
    1.29 +end ifdef
    1.30 +
    1.31 +ifdef LINUX then
    1.32 +	constant settings = home & "/.jedit"
    1.33 +elsifdef OSX then
    1.34 +	constant settings = home & "/Library/jEdit"
    1.35 +elsifdef WINDOWS then
    1.36 +	constant settings = appdir & "\\jEdit"
    1.37 +elsedef
    1.38 +	constant settings = 0
    1.39 +	err("Your OS is not supported.")
    1.40 +end ifdef
    1.41 +
    1.42 +sequence catdir = settings & SLASH & "modes" 
    1.43 +sequence iname = catdir & SLASH & "catalog"
    1.44 +sequence oname = catdir & SLASH & "catalog.new"
    1.45 +integer ifd = open(iname, "r")
    1.46 +integer ofd = open(oname, "w")
    1.47 +
    1.48 +procedure delete_temporary_file(integer discard)
    1.49 +	if ofd != -1 then
    1.50 +		-- must close ofd before deleting oname.
    1.51 +		close(ofd)
    1.52 +	end if
    1.53 +	delete_file(oname)
    1.54 +end procedure
    1.55 +
    1.56 +-- the janitor is responsible for things getting cleaned up when the program ends unexpectedly
    1.57 +atom janitor = delete_routine(0, routine_id("delete_temporary_file"))
    1.58 +
    1.59 +if ifd = -1 or ofd = -1 then
    1.60 +	ifd = -1
    1.61 +	ofd = -1
    1.62 +	err("Unable to open catalog file for editing.")
    1.63 +end if
    1.64 +
    1.65 +
    1.66 +boolean found_target = FALSE
    1.67 +while sequence(line) with entry do
    1.68 +	puts(ofd, line)
    1.69 +	if match("<MODES>", line) then
    1.70 +		found_target = TRUE
    1.71 +		exit
    1.72 +	end if
    1.73 +entry
    1.74 +	line = gets(ifd)
    1.75 +end while
    1.76 +if not found_target then
    1.77 +	err( "Cannot find <MODES> string.")
    1.78 +end if
    1.79 +while sequence(line) with entry do
    1.80 +	if match("<MODE NAME=\"euphoria\"", line) then
    1.81 +		-- supress this, we are rewriting this.
    1.82 +		line = gets(ifd)
    1.83 +		continue
    1.84 +	end if
    1.85 +	if match("</MODES>", line) then
    1.86 +		puts(ofd, """<MODE NAME="euphoria" FILE="euphoria.xml" """&
    1.87 +			"""FILE_NAME_GLOB="*.{ex,ew,exw,e}" />""" & '\n')
    1.88 +	end if
    1.89 +	puts(ofd, line)
    1.90 +entry
    1.91 +	line = gets(ifd)
    1.92 +end while
    1.93 +
    1.94 +-- must close here so we may replace the old catalog.
    1.95 +close(ifd)
    1.96 +close(ofd)
    1.97 +-- set these so the janitor doesn't try to close the handles
    1.98 +-- a second time.
    1.99 +ifd = -1
   1.100 +ofd = -1
   1.101 +if not copy_file("euphoria.xml", home & SLASH & ".jedit" & SLASH & "modes" & SLASH & "euphoria.xml", TRUE) then
   1.102 +	err("Cannot copy euphoria mode file")
   1.103 +end if
   1.104 +if not move_file(iname, iname & ".bak", TRUE) then
   1.105 +	err("Cannot backup the catalog.")
   1.106 +end if
   1.107 +if not move_file(oname, iname, TRUE) then
   1.108 +	err("Cannot move new mode configuration into place.")
   1.109 +end if
   1.110 +puts(STDERR, "Euphoria mode installed.\n")
   1.111 +

SCM Home | OpenEuphoria.org Home