editors

view jEdit/install_mode.ex @ 57:149815b0874c

* 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
children
line source
1 include std/types.e
2 include std/filesys.e
3 include std/os.e
4 include std/io.e
6 procedure err(sequence msg)
7 puts(STDERR, "Cannot install mode: "&msg&"\n")
8 abort(1)
9 end procedure
11 puts(STDOUT, "This program will install the EUPHORIA mode for jEdit.\n" &
12 "Press ENTER to continue or CNTRL+C to stop.\n")
13 object line
14 line = gets(STDIN)
16 constant home = getenv("HOME")
17 constant appdata = getenv("APPDATA")
18 ifdef WINDOWS then
19 if atom(appdata) then
20 err("No AppData directory.")
21 end if
22 elsedef
23 if atom(home) then
24 err("No HOME directory.")
25 end if
26 end ifdef
28 ifdef LINUX then
29 constant settings = home & "/.jedit"
30 elsifdef OSX then
31 constant settings = home & "/Library/jEdit"
32 elsifdef WINDOWS then
33 constant settings = appdir & "\\jEdit"
34 elsedef
35 constant settings = 0
36 err("Your OS is not supported.")
37 end ifdef
39 sequence catdir = settings & SLASH & "modes"
40 sequence iname = catdir & SLASH & "catalog"
41 sequence oname = catdir & SLASH & "catalog.new"
42 integer ifd = open(iname, "r")
43 integer ofd = open(oname, "w")
45 procedure delete_temporary_file(integer discard)
46 if ofd != -1 then
47 -- must close ofd before deleting oname.
48 close(ofd)
49 end if
50 delete_file(oname)
51 end procedure
53 -- the janitor is responsible for things getting cleaned up when the program ends unexpectedly
54 atom janitor = delete_routine(0, routine_id("delete_temporary_file"))
56 if ifd = -1 or ofd = -1 then
57 ifd = -1
58 ofd = -1
59 err("Unable to open catalog file for editing.")
60 end if
63 boolean found_target = FALSE
64 while sequence(line) with entry do
65 puts(ofd, line)
66 if match("<MODES>", line) then
67 found_target = TRUE
68 exit
69 end if
70 entry
71 line = gets(ifd)
72 end while
73 if not found_target then
74 err( "Cannot find <MODES> string.")
75 end if
76 while sequence(line) with entry do
77 if match("<MODE NAME=\"euphoria\"", line) then
78 -- supress this, we are rewriting this.
79 line = gets(ifd)
80 continue
81 end if
82 if match("</MODES>", line) then
83 puts(ofd, """<MODE NAME="euphoria" FILE="euphoria.xml" """&
84 """FILE_NAME_GLOB="*.{ex,ew,exw,e}" />""" & '\n')
85 end if
86 puts(ofd, line)
87 entry
88 line = gets(ifd)
89 end while
91 -- must close here so we may replace the old catalog.
92 close(ifd)
93 close(ofd)
94 -- set these so the janitor doesn't try to close the handles
95 -- a second time.
96 ifd = -1
97 ofd = -1
98 if not copy_file("euphoria.xml", home & SLASH & ".jedit" & SLASH & "modes" & SLASH & "euphoria.xml", TRUE) then
99 err("Cannot copy euphoria mode file")
100 end if
101 if not move_file(iname, iname & ".bak", TRUE) then
102 err("Cannot backup the catalog.")
103 end if
104 if not move_file(oname, iname, TRUE) then
105 err("Cannot move new mode configuration into place.")
106 end if
107 puts(STDERR, "Euphoria mode installed.\n")

SCM Home | OpenEuphoria.org Home