1. Eu2C translator batch file

-- just for fun, in case anyone is interested:


--#!/home/kenneth/euphoria/bin/exu
--  file    : ecx.exu
--  author  : Kenneth Rhodes, derived from replace.ex
---             1.10 by jiri babor
--  email   : ken_rhodes30436 at yahoo.com
--  project : adapt ecu generated emake file to use
--          :  gcc-3.2 in place of gcc(-2.96)
--          : automate ecu translation of code,
--          : execute emake, compile and
--          : compress executable file using UXP
--          : removes - "cleans up" files generated
--          :  by ecu 
--  tool    : euphoria 2.4
--  platform: Linux
--  date    : 03-01-2003
--  version : 1.0

---------< this code adapted from Jiri 
--          Babor'sreplace.ex >------------

include file.e

sequence buffer, fn, cl, new_text, old_text, operation
integer exit_code

procedure help(sequence error_message)
    puts(1,"Error :  " & error_message & "\n")
    puts(1,"Syntax:  exu ecx.exu filename.exu.\n")
    abort(1)
end procedure

procedure read()
    integer f, len, n

    f=open("emake","rb")
    if f=-1 then
	help("Couldn't open " & fn & " !\n")
    end if
    n=seek(f, -1)               -- go to end of input
file
    len=where(f)                -- get length of input
file in bytes
    n=seek(f, 0)                -- go back to
beginning of input file
    buffer = repeat(0, len)     -- init buffer
    for i=1 to len do
	buffer[i] = getc(f)     -- read file into buffer
    end for
    close(f)
end procedure -- read

procedure replace_and_write()
    integer f, i, lo, ln

    f=open("emake", "wb")       -- open output file
    lo = length(old_text)
    ln = length(new_text)

    i = match(old_text, buffer)
    while i do
	puts(f, buffer[1..i-1])
	puts(f, new_text)
	buffer = buffer[i+lo..length(buffer)]
	i = match(old_text, buffer)
    end while
    puts(f, buffer)
    close(f)                    -- close output file
end procedure -- replace_and_write

---------< code adapted from Jiri Babor's replace.ex
>-------------------------


-- main


constant    COULD_NOT_RUN = -1,
	    SUCCESSFUL = 0,
	    SCREEN = 1

procedure report_exit_codes()
    if exit_code = COULD_NOT_RUN then
	puts(SCREEN, "\n" & operation & " failed")
    elsif exit_code = SUCCESSFUL then
	printf(SCREEN,"\n%s SUCCESSfUL", {operation})
    elsif exit_code = 256 then
	printf(SCREEN, "\n%s FAILED with code %d \n(file not
found)", {operation, exit_code})
    else
	printf(SCREEN, "\n%s FAILED with code %d",
{operation, exit_code})
    end if
end procedure


old_text = "gcc"
new_text = "gcc-3.2"


cl=command_line()
if length(cl) < 3 then
  help("Insufficient number of arguments!")
end if

fn  = cl[3]
 

    operation = ("translation of " & fn & " to  c_code
")
    exit_code = system_exec("ecu " & fn, 0)
    report_exit_codes()

    
    read()
    replace_and_write()
  
    operation = ( "running emake ")
    exit_code = system_exec("./emake", 0)
    report_exit_codes()

    operation = ("removing c files ")
    exit_code = system_exec("rm *.c *.h emake", 0)
    report_exit_codes()

    operation = "Compressing executable with UPX "
    fn = fn[1..match(".", fn)-1]
    exit_code = system_exec("upx --best " & fn, 0)
    report_exit_codes()


puts(1, "\nDone!\n")

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu