1. Builder
- Posted by mistertrik at hotmail.com Apr 12, 2002
- 398 views
I wrote a builder program, for when you are distributing a piece of software... because I'm sick of looking inside include files to see what is included ... so I can add those include files, and see what is included.... it's annoying. (if you know what I mean) This program uses a command-line interface: ex builder.ex [main file] [destination directory] It opens the main file, figures out which files it's dependant on, and adds them, then checks which files THEY are dependent, and adds them.. etc. Also adds the correct interpreter and a batch file. That's all well and good, but it's still missing something. It doesn't find all dependant files, only the includes. It needs to find .bmp and .dat files.... and other such things... any ideas on how? BTW, I don't have full version of Eu, just the PD. That's why I made this prog. Below is the source code. I can send as an attachment if necessary. The code that needs supplementing is in the function "findDependencies" If anything doesn't make sense I can explain it... but it's fairly simple. Tell me what you think. +++++++++ Mr Trick File: builder.ex ---------------- include file.e constant includesDir = "c:\\Euphoria\\Include\\" constant binDir = "c:\\Euphoria\\bin\\" constant params = command_line() constant thisDir = current_dir() sequence errorStr, masterFileList --contains all the files, in --{ name, checkedflag } form --if a listed file doesn't exist, it adds it, and displays at the end procedure makeError(sequence file) if not length(errorStr) then errorStr = "Some files listed by one of your files are either\n" & "missing, or named incorrectly. See below:\n\n\n" end if errorStr &= file & "\n" end procedure --similar to find, but you specify a subscript of a 2d seq. function indexFind(object a, atom ind, sequence seq) for t = 1 to length(seq) do if not compare(a,seq[t][ind]) then return t end if end for return 0 end function --removes excess spaces and \n marks function clean(sequence line) atom s s = 1 while line[1] = ' ' do line = line[2..length(line)] end while while s <= length(line) and not find(line[s], " \n\r") do s += 1 end while line = line[1..s - 1] return line end function --given a file... will return the location of the file, or -- -1 if it doesn't exist. function chkFile(sequence file) if sequence(dir(file)) then return file elsif sequence(dir(includesDir&file)) then return includesDir&file elsif sequence(dir(binDir&file)) then return binDir&file end if return -1 end function --THIS FUNCTION NEEDS WORK --in: a file name --out: all the files that it needs to run, or a -1 (file not found) --at the moment only looks for 'include' and takes the string after it. function getDependencies(sequence file) atom fn,t object line, list, f f = chkFile(file) if atom(f) then makeError(file) return -1 end if fn = open(f,"r") if fn = -1 then makeError(file) return -1 end if line = gets(fn) list = {} while sequence(line) do t = match("include", line) if t and (not match("--",line) or t < match("--", line)) then list &= {clean(line[t+8..length(line)])} end if line = gets(fn) end while close(fn) return list end function --given a sequence of files, it adds any not already present to the list function update(sequence list, sequence files) for a = 1 to length(files) do if not indexFind(files[a],1, list) then list &= {{ files[a], 0}} end if end for return list end function --==Main==-- if length(params) < 4 then puts(1,"More parameters needed.\nUsage: builder [filename] [directory to put it in]") abort(0) end if masterFileList = {{params[3],0}} errorStr = {} object temp atom ind ind = indexFind(0,2,masterFileList) --while there are 0's, some files haven't puts(1,"Scanning for dependencies.....\n") --been checked. while ind do --while not finished temp = getDependencies( masterFileList[ind][1] ) masterFileList[ind][2] = 1 --when a file is checked, this goes high if sequence(temp) then --if there are any dependencies masterFileList = update( masterFileList, temp) end if ind = indexFind(0,2,masterFileList) --get next unfinished one end while for a = 1 to length(masterFileList) do puts(1,masterFileList[a][1] &"\n") --lists files end for ---------------------Now transfer all to a folder of your choice.---- puts(1,"Building folder and transferring files......\n") sequence targetDir if match(":\\", params[4]) then --absolute targetDir = params[4] else targetDir = thisDir & "\\" & params[4] end if puts(1,"Path: " & targetDir & "\n") system("mkdir " & targetDir, 2) --create directory for a = 1 to length(masterFileList) do system("copy " & chkFile(masterFileList[a][1]) & " " & targetDir, 2) puts(1,"\n") --copy to directory end for puts(1, "Transferring executable...\n") if match(".exw", params[3]) or match(".ew", params[3]) then temp = "exw.exe" elsif match(".exu", params[3]) then temp = "exu.exe" else temp = "ex.exe" end if system("copy " & binDir & temp & " " & targetDir, 2) if length(errorStr) then puts(1,errorStr & "\nCheck that these files are in the right place.") end if puts(1,"Building BAT file...") sequence name name = params[3] ind = match(".e", name) name = name[1..ind] & "bat" ind = open(name, "w") puts(ind, temp & " " & name) close(ind) puts(1,"done") --end--