240 lines
6.8 KiB
Plaintext
240 lines
6.8 KiB
Plaintext
{
|
|
=========================================================================
|
|
PROGRAMA : MAINMENU
|
|
OBJETIVO : INICIAR EL MENU DEL SISTEMA
|
|
PROGRAMADOR : ING. JUAN SOTO
|
|
FECHA : 13 de Marzo 2009
|
|
========================================================================
|
|
}
|
|
IMPORT os
|
|
CONSTANT filename = "mainmenu.data"
|
|
DEFINE dirs DYNAMIC ARRAY OF RECORD
|
|
ddir STRING
|
|
END RECORD
|
|
DEFINE mbs DYNAMIC ARRAY OF RECORD
|
|
mbs STRING,
|
|
prog STRING,
|
|
type STRING,
|
|
desc STRING
|
|
END RECORD
|
|
DEFINE nmbs INTEGER
|
|
DEFINE longDesc STRING
|
|
|
|
|
|
MAIN
|
|
DEFINE cmd STRING
|
|
DEFINE currForm ui.Form
|
|
OPTIONS ACCEPT KEY RETURN
|
|
OPTIONS INPUT WRAP
|
|
|
|
OPEN FORM main FROM "mainmenuform"
|
|
DISPLAY FORM main
|
|
|
|
CALL ui.Interface.LoadStyles("mainmenu")
|
|
|
|
CALL init_mbs()
|
|
DIALOG ATTRIBUTES(FIELD ORDER FORM, UNBUFFERED)
|
|
DISPLAY ARRAY dirs TO dirs.*
|
|
BEFORE ROW
|
|
CALL sync_mbs(DIALOG)
|
|
CALL DIALOG.setCurrentRow("mbs",1)
|
|
END DISPLAY
|
|
|
|
DISPLAY ARRAY mbs TO mbs.*
|
|
END DISPLAY
|
|
|
|
INPUT BY NAME longDesc
|
|
END INPUT
|
|
|
|
ON ACTION show
|
|
CALL show_mbs(DIALOG)
|
|
|
|
ON ACTION close
|
|
EXIT DIALOG
|
|
END DIALOG
|
|
|
|
END MAIN
|
|
|
|
FUNCTION show_mbs(d)
|
|
DEFINE d ui.Dialog
|
|
DEFINE rdir, rmbs INTEGER
|
|
DEFINE cmd,pwd STRING
|
|
|
|
LET rdir = d.getCurrentRow("dirs")
|
|
LET rmbs = d.getCurrentRow("mbs")
|
|
IF mbs[rmbs].prog IS NULL THEN RETURN END IF
|
|
|
|
IF mbs[rmbs].type = "services" THEN
|
|
{ LET cmd = "cd " || dirs[rdir].ddir || " && fglrun " || mbs[rmbs].prog
|
|
IF os.Path.dirname(dirs[rdir].ddir)="Tools" THEN
|
|
-- Special treatment for the Tools dir: all tools must have shells to start program
|
|
IF fgl_getenv("WINDIR") IS NOT NULL THEN
|
|
LET cmd = ".\\Tools\\" || os.Path.basename(dirs[rdir].ddir) || "\\" || mbs[rmbs].prog || ".bat"
|
|
|
|
call fgl_winmessage("prueba",cmd,"stop")
|
|
ELSE
|
|
LET cmd = "./Tools/" || os.Path.basename(dirs[rdir].ddir) || "/" || mbs[rmbs].prog || ".sh"
|
|
END IF
|
|
END IF
|
|
}
|
|
LET cmd = fgl_getenv("FGLPROG") || "\\" || mbs[rmbs].prog || ".bat"
|
|
call fgl_winmessage("prueba",cmd,"stop")
|
|
RUN cmd WITHOUT WAITING
|
|
RETURN
|
|
END IF
|
|
|
|
IF mbs[rmbs].type = "file" THEN
|
|
CALL showfile(dirs[rdir].ddir || "/" || mbs[rmbs].prog)
|
|
RETURN
|
|
END IF
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION init_mbs()
|
|
DEFINE reader om.XmlReader,
|
|
attributes om.SaxAttributes,
|
|
saxevent STRING
|
|
LET reader = om.XmlReader.createFileReader(filename)
|
|
|
|
LET attributes = reader.getAttributes()
|
|
LET saxevent = reader.read()
|
|
CALL dirs.clear()
|
|
CALL mbs.clear()
|
|
WHILE saxevent IS NOT NULL
|
|
CASE saxevent
|
|
WHEN 'StartDocument'
|
|
LET nmbs=0
|
|
WHEN 'StartElement'
|
|
CASE reader.getTagName()
|
|
WHEN 'mbs'
|
|
-- Nothing
|
|
WHEN 'DDir'
|
|
CALL dirs.appendElement()
|
|
LET dirs[dirs.getLength()].ddir = attributes.getValue('name')
|
|
WHEN 'mbs'
|
|
-- Nothing
|
|
OTHERWISE
|
|
DISPLAY "Error: wrong tagName:",reader.getTagName()
|
|
END CASE
|
|
WHEN 'EndElement'
|
|
-- Nothing
|
|
END CASE
|
|
LET saxevent=reader.read()
|
|
END WHILE
|
|
END FUNCTION
|
|
|
|
FUNCTION sync_mbs(d)
|
|
DEFINE d ui.Dialog
|
|
DEFINE reader om.XmlReader,
|
|
attributes om.SaxAttributes,
|
|
saxevent,ddir STRING
|
|
DEFINE n INTEGER
|
|
LET reader = om.XmlReader.createFileReader(filename)
|
|
LET attributes = reader.getAttributes()
|
|
LET saxevent = reader.read()
|
|
INITIALIZE longDesc TO NULL
|
|
CALL mbs.clear()
|
|
WHILE saxevent IS NOT NULL
|
|
CASE saxevent
|
|
WHEN 'StartDocument'
|
|
LET nmbs=0
|
|
WHEN 'StartElement'
|
|
CASE reader.getTagName()
|
|
WHEN 'mbs'
|
|
-- Nothing
|
|
WHEN 'DDir'
|
|
IF attributes.getValue('name') == dirs[d.getCurrentRow("dirs")].ddir THEN
|
|
LET saxevent = reader.read()
|
|
WHILE saxevent IS NOT NULL
|
|
IF saxevent == 'StartElement' THEN
|
|
CASE reader.getTagName()
|
|
WHEN 'mbs'
|
|
CASE attributes.getValue('type')
|
|
WHEN "V"
|
|
CALL mbs.appendElement()
|
|
LET n = mbs.getLength()
|
|
LET mbs[n].type="services"
|
|
LET mbs[n].mbs=attributes.getValue('name')
|
|
LET mbs[n].prog=attributes.getValue('program')
|
|
LET mbs[n].desc=attributes.getValue('description')
|
|
WHEN "B"
|
|
|
|
IF attributes.getValue('program') == "README" THEN
|
|
LET longDesc = readfile(dirs[d.getCurrentRow("dirs")].ddir || "/README")
|
|
|
|
ELSE
|
|
CALL mbs.appendElement()
|
|
LET n = mbs.getLength()
|
|
LET mbs[n].type="file"
|
|
LET mbs[n].mbs=attributes.getValue('name')
|
|
LET mbs[n].prog=attributes.getValue('program')
|
|
LET mbs[n].desc=attributes.getValue('description')
|
|
END IF
|
|
WHEN "C"
|
|
CALL mbs.appendElement()
|
|
LET n = mbs.getLength()
|
|
LET mbs[n].type="file"
|
|
LET mbs[n].mbs=attributes.getValue('name')
|
|
LET mbs[n].prog=attributes.getValue('program')
|
|
LET mbs[n].desc=attributes.getValue('description')
|
|
|
|
END CASE
|
|
OTHERWISE
|
|
RETURN
|
|
END CASE
|
|
END IF
|
|
LET saxevent = reader.read()
|
|
END WHILE
|
|
END IF
|
|
WHEN 'mbs'
|
|
OTHERWISE
|
|
DISPLAY "Error: wrong tagName:",reader.getTagName()
|
|
END CASE
|
|
WHEN 'EndElement'
|
|
-- Nothing
|
|
END CASE
|
|
LET saxevent=reader.read()
|
|
END WHILE
|
|
END FUNCTION
|
|
|
|
FUNCTION showfile(fn)
|
|
DEFINE fn STRING
|
|
DEFINE txt STRING
|
|
OPEN WINDOW w WITH FORM "Maindisp"
|
|
ATTRIBUTE(TEXT="File: ["||fn||"]",STYLE="dialog")
|
|
LET txt = readfile(fn)
|
|
INPUT BY NAME txt WITHOUT DEFAULTS
|
|
LET int_flag=FALSE
|
|
CLOSE WINDOW w
|
|
END FUNCTION
|
|
|
|
FUNCTION readfile(fn)
|
|
DEFINE fn STRING
|
|
DEFINE txt STRING
|
|
DEFINE ln STRING
|
|
DEFINE ch base.Channel
|
|
LET ch=base.Channel.create()
|
|
call fgl_winmessage("prueba",fn,"stop")
|
|
CALL ch.openfile(fn,"r")
|
|
|
|
CALL ch.setDelimiter("")
|
|
WHILE ch.read(ln)
|
|
IF txt IS NULL THEN
|
|
IF ln IS NULL THEN
|
|
LET txt = "\n"
|
|
else
|
|
LET txt = ln
|
|
END IF
|
|
ELSE
|
|
IF ln IS NULL THEN
|
|
LET txt = txt || "\n"
|
|
ELSE
|
|
LET txt = txt || "\n" || ln
|
|
END IF
|
|
END IF
|
|
END WHILE
|
|
CALL ch.close()
|
|
RETURN txt
|
|
END FUNCTION
|
|
|