1. An effort to strip GUI code from Jean-Marc Duro's "Code Beautifier" program

Reference: http://rapideuphoria.com/beautifier_v0.1.0.zip

I renamed "beautifier.ex" to "tidy.e" and tacked the following function onto the end of Jean-Marc Duro's "beautifier.ex. I was using most of the code with Jiri Babor's old code "beautifier, "tidy.ex". I may have stripped out some other code "beautifier.ex" code as well.

Basically, I was trying to incorporate a secure backup routine along with the code beautification function. I would really like to see how someone who knows what they are doing approaches this... smile

 
include std/text.e 
include std/io.e 
include std/filesys.e 
include std/sequence.e 
include std/search.e 
include std/error.e 
include std/types.e 
include ./myLibs/myDebug.e 
include ./myLibs/common.e 
 
public function tidy(sequence FName) 
    sequence source = FName 
    -- first backup the input file 
    integer TIDY = TRUE 
    if copy_file(FName, FName & "~", 1) then 
        TIDY = TRUE 
    else 
	TIDY = FALSE 
	msg = sprintf("%s~ BACKUP FAILED!!!  tidy.ex aborting.... ", {FName}) 
    end if 
-------------------------------------------------------------------------------- 
    f1 = open(FName,"r")             -- input 
    if f1=-1 then 
	msg = sprintf("Couldn\'t open input file %s: tidy.ex aborting...", FName) 
	TIDY = FALSE 
    else 
        TIDY = TRUE 
    end if 
     
    if TIDY then 
        f_out = open(FName&".tidy","w")                  -- tidied file 
        if f_out=-1 then 
          TIDY = FALSE 
            msg = "Couldn\'t open output file "& f_out &" for writing. Aborting..." 
        else 
          TIDY = TRUE 
        end if 
    end if 
     
      if TIDY then 
          sequence lines = read_lines(FName) 
          allWords = getWords(lines) 
          analyzeObject(allWords, "allWords", f_debug) 
          beautify(lines) 
          close(f1) 
          close(f_out) 
      end if 
   
    if TIDY then 
      -- copy  the "tidied" file, f_out, back over the original source-file, FName. 
	if copy_file(f_out, source, 1) then 
	    msg = sprintf("The file \"%s\" has been backed up as: \"%s~\" and \"tidied\" !!", {source, source}) 
         else 
         TIDY = FALSE 
             msg = sprintf("FAILE to \"tidy\" the file \"%s\"; however the file was archived as: \"%s~\" !!", {source, source}) 
	end if 
    end if 
return msg  
----------------- 
end function 

Next I added a front-end command line program:

 
-- 
--  tidy.ex 
--  an effort to strip GUI code from 
--  Jean-Marc Duro's "Code Beautifier" program 
-- 
include tidy.e 
-- 
include std/filesys.e 
include std/text.e 
include std/error.e 
include std/console.e 
include ./myLibs/myDebug.e 
------------------------------------------------------------------------------ 
object FName 
object cmd = command_line() 
if length(cmd)<3 then 
    puts(1,"\n\ntidy.ex: Enter file to be \"tidied\":  ") 
    FName=gets(0) 
    puts(1,"\n") 
    if atom(FName) then 
        FName=" " 
    else 
        FName = trim_tail(FName) 
    end if 
    if equal(FName,"") then 
        puts(1, "\n\t Usage: \n\t\t\teui tidy.ex <FName> ") 
        puts(1, "\n\n\t\t\tPress any key...\n") 
        abort(1) 
    end if 
elsif length(cmd)=3 then 
      FName=cmd[3] 
      tidy(FName) 
       
      -- maybe someone else can make the 
      -- following code useful 
      sequence info = pathinfo(cmd[2]) 
      void = chdir(info[PATH_DIR]) 
      InitialDir = current_dir() 
    sequence cur_date = date() 
    f_debug = open(InitialDir&SLASH&"debug.log", "w") 
    crash_file(InitialDir&SLASH&"ex.err") 
    -- debugLevel = 1 
    close(f_debug)     
end if 
new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu