Advertisement
Phins

LogCraft

Dec 13th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. --tArgs = {...}
  2. --if #tArgs ~= 3 or tArgs[1] ~= "startup" then
  3. --printError("USE: shell.run['LogCraft','startup','config','logs']")
  4. --os.sleep(3)
  5. -- os.reboot()
  6. --error("API ERROR",2)
  7. --end
  8.  
  9. a = "Doodle/logs.txt"
  10.  
  11. if printf then print = printf end
  12. if writef then write = writef end
  13. if readf then read = readf end
  14.  
  15. --Compiler \/
  16. function complile(filename)
  17. ----------------------
  18. file = fs.open(filename,"r")
  19. returndata = {} word = {} word2 = {}
  20. data = {}
  21. for str in string.gmatch(file.readAll(), "([^%s+])") do
  22. data[#data + 1] = str
  23. end
  24. file.close() i = 1
  25. if data[1] == "{" then
  26. while true do
  27. if num == nil then
  28. i = i + 1
  29. else
  30. i = i + num + 1
  31. num = nil
  32. end
  33. -- Datei <--
  34. if data[i] == "{" then
  35. printError("Dont use '{' , '}' , '=' or ';' as string")
  36. elseif data[i] == "}" then
  37. return returndata
  38. elseif #data < i then
  39. printError("'}' expected at line "..#returndata + 2)
  40. return
  41. elseif data[i] == "=" then
  42. for o=i + 1,#data do
  43. if data[o] == "=" or data[o] == "}" then
  44. printError("';' expected at line "..#returndata + 2)
  45. return
  46. elseif #word < 1 then
  47. printError("Unable to complier at line "..#returndata + 2)
  48. return
  49. elseif data[o] == ";" then
  50. if #word2 < 1 then
  51. printError("Unable to complier at line "..#returndata + 2)
  52. return
  53. end
  54. returndata[#returndata + 1] = {table.concat(word),table.concat(word2)}
  55. word = {} word2 = {}
  56. num = o - i
  57. break
  58. else
  59. word2[#word2 + 1] = data[o]
  60. end
  61. end
  62. elseif data[i] == ";" or data[i] == "}" then
  63. printError("'=' expected at line "..#returndata + 2)
  64. return
  65. else
  66. word[#word + 1] = data[i]
  67. end
  68. --
  69. end
  70. else
  71. printError("'{' at line 1")
  72. return
  73. end
  74. ---------------------
  75. return
  76. end
  77. -- Compiler /\
  78.  
  79. local function reset()
  80. term.setTextColor(colors.white)
  81. term.setBackgroundColor(colors.black)
  82. term.clear()
  83. term.setCursorPos(1,1)
  84. end
  85.  
  86. local function rebootscreen()
  87. reset()
  88. term.setBackgroundColor(colors.blue)
  89. term.setTextColor(colors.white)
  90. term.clear()
  91. print("LogCraft 0.1")
  92. term.setCursorPos(1,2)
  93. print("by Phins")
  94. paintutils.drawLine(1,19,51,19,colors.white)
  95. term.setTextColor(colors.black)
  96. for i=1,20 do
  97. term.setCursorPos(1,19)
  98. write((i*5).."% Loading")
  99. os.sleep(0.01)
  100. end
  101. reset()
  102. end
  103.  
  104. function setupconfig()
  105. if not fs.exists(tArgs[2]) then --EDIT
  106. file = fs.open(tArgs[2],"w") --EDIT
  107. file.write("{\n") file.write("logloader = false;\n")
  108. file.write("rebootscreen = false;\n")
  109. file.write("txtlog = false;\n")
  110. file.write("startlog = true;\n") file.write("}")
  111. file.close()
  112. end
  113. local data = complile(tArgs[2]) --EDIT
  114. logload = data[1][2] rebscreen = data[2][2]
  115. txtlog = data[3][2] stlog = data[4][2]
  116. end
  117.  
  118. --|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-x
  119. local log = {} --x
  120. --x
  121. local function loadLog() --x
  122. local file = fs.open(a, "r") --EDIT --x
  123. if file then --x
  124. log = {} --x
  125. local line = file.readLine() --x
  126. while line do --x
  127. table.insert(log, line) --x
  128. line = file.readLine() --x
  129. end --x
  130. file.close() --x
  131. end --x
  132. end --x
  133. --x
  134. local function saveLog() --x
  135. local file = fs.open(a, "w") --EDIT --x
  136. for i=1,#log do --x
  137. file.write(log[i].."\n") --x
  138. end --x
  139. file.close() --x --x
  140. end --x
  141. --x
  142. function addlog(s) --x
  143. table.insert(log, s) --x
  144. saveLog() --x
  145. end --x
  146. --x
  147. function dellog() --x
  148. list = fs.list("Doodle") --Edit --x
  149. for i=1,#list do --x
  150. if list[i] == a then --EDIT --x
  151. fs.open(a,"w") --EDIT --x
  152. end --x
  153. end --x
  154. end --x
  155. --x
  156. local function startlog() --x
  157. addlog("\n <-----\n")--x
  158. addlog("###############################") --x
  159. addlog("######## Log opened #########") --x
  160. addlog("###############################") --x
  161. addlog("Computer Details") --x
  162. addlog("++++++++++++++++++++++++++++++++++++") --x
  163. if term.isColor() then --x
  164. addlog("Type: Advanced") --x
  165. else --x
  166. addlog("Type: Normal") --x
  167. end --x
  168. addlog("ID: "..os.getComputerID()) --x
  169. if os.getComputerLabel() then --x
  170. addlog("Label: "..os.getComputerLabel()) --x
  171. else --x
  172. addlog("Label: Nil") --x
  173. end --x
  174. addlog("Version: "..os.version()) --x
  175. addlog("Time: "..os.time()) --x
  176. addlog("++++++++++++++++++++++++++++++++++++\n") --x
  177. end --x
  178. --x
  179. --|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-x
  180.  
  181. setupconfig()
  182. if logload == "true" then loadLog() end
  183. if rebscreen == "true" then rebootscreen() end
  184. if stlog == "true" then startlog() end
  185. if txtlog == "true" then
  186. local printf = print
  187. local writef = write
  188. local readf = read
  189. function print(strg)
  190. x,y = term.getCursorPos()
  191. addlog("Print: "..strg)
  192. printf(strg)
  193. end
  194.  
  195. function write(strg)
  196. x,y = term.getCursorPos()
  197. addlog("Write: "..strg)
  198. writef(strg)
  199. end
  200.  
  201. function read(strg)
  202. local inp = readf(strg)
  203. if inp then
  204. addlog("READ: "..inp)
  205. end
  206. return inp
  207. end
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement