Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
- Change variable type from char to array of string
it's easier to find some text and replace it
- Change using to have <parameterName>_init() to initialize the parameter
- Can find quantity of parameter on pageCount that had defined
  • Loading branch information
playelek authored Apr 6, 2017
1 parent 0230b49 commit cb54827
Showing 1 changed file with 87 additions and 21 deletions.
108 changes: 87 additions & 21 deletions html2Ccode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,109 @@ def openFile(argv):

def main(argv):
Ifile, Ofile, Param = openFile(argv)
txtTmp = []
s = ""
try:
localtime = time.asctime( time.localtime(time.time()) )
InputObj = open(Ifile,'r+')
OutputObj = open(Ofile,'w+')
OutputObj.write('/*Generated by html2Ccode.py\n')
OutputObj.write('Made by PlayElek.com\n')
OutputObj.write('Generated on \n')
OutputObj.write(localtime + '\n')
OutputObj.write('Parameter is '+ Param +'\n')
OutputObj.write('*/\n')
#OutputObj.write(InputObj.readline())
#OutputObj.write('/*Generated by html2Ccode.py\n')
s = '/*Generated by html2Ccode.py\n'
#OutputObj.write('Made by PlayElek.com\n')
s += 'Made by PlayElek.com\n'
#OutputObj.write('Generated on \n')
s += 'Generated on \n'
#OutputObj.write(localtime + '\n')
s += localtime + '\n'
#OutputObj.write('Parameter is '+ Param +'\n')
s += 'Parameter is '+ Param +'\n'
#OutputObj.write('*/\n')
s += '*/\n'
#print s
txtTmp.append(s)
endline = 0
txtsize = 0
pgsize = 0
try:
OutputObj.write("#ifndef " + Param +"_H\n")
OutputObj.write("#define " + Param +"_H\n")
OutputObj.write("int "+Param+"Size = 0;\n")
#OutputObj.write("char "+Param+"[2000];\n")
#OutputObj.write(Param+"Size = snprintf("+Param+",")
#OutputObj.write("char " + Param +"[] = {\n"+'"')
OutputObj.write("char "+Param+'[] = "HTTP/1.1 200 OK\\r\\nContent-Type: text/html\\r\\n\\r\\n\\'+'\n')
#OutputObj.write("#ifndef " + Param +"_H\n")
s = "#ifndef " + str(Param) +"_H\n"
#OutputObj.write("#define " + Param +"_H\n")
s += "#define " + str(Param) +"_H\n"
s += "#include <string.h>\n"
#OutputObj.write("#define pageCount "+pgsize+"\n")
s += "#define pageCount "+str(pgsize)+"\n"
searchDef = "#define pageCount \n"
#OutputObj.write("int "+Param+"Size = 0;\n")
s += "String "+str(Param)+"[pageCount];\n"
#OutputObj.write("char "+Param+'[pageCount][] = "HTTP/1.1 200 OK\\r\\nContent-Type: text/html\\r\\n\\r\\n\\'+'\n')
s += "void htmlCode_Init(void){\n"
s += str(Param)+'[0] = "HTTP/1.1 200 OK\\r\\nContent-Type: text/html\\r\\n\\r\\n\\'+'\n'
#OutputObj.write('"')
#print s

txtTmp.append(s)
s = ""
for c in InputObj.read():
if c == "'" or c == '"':
OutputObj.write("\\"+c)
endline = 0
#OutputObj.write("\\"+c)
s += "\\"+c
endline = 0
elif c=='\n' or c=="\n":
if endline == 0:
OutputObj.write("\\n\\"+"\n")
#OutputObj.write("\\n\\"+"\n")
s += "\\n\\"+"\n"
endline = 1
elif endline == 1 :
#OutputObj.write("\";\n")
s += "\";\n"
#print s
txtTmp.append(s)
pgsize += 1
txtsize = 0
#OutputObj.write("char "+Param+'['+str(pgsize)+'][] = \"\\'+'\n')
s = str(Param)+'['+str(pgsize)+'] = \"\\'+'\n'
endline = 2
else:
OutputObj.write(c)
#OutputObj.write(c)
s += c
endline = 0
#OutputObj.write('");\n')
OutputObj.write("\";\n")
if txtsize < 1000:
txtsize += 1
else :
#OutputObj.write("\";\n")
s += "\";\n"
#print s
txtTmp.append(s)
pgsize += 1
txtsize = 0
#OutputObj.write("char "+Param+'['+str(pgsize)+'[] = \"\\'+'\n')
s = str(Param)+'['+str(pgsize)+'] = \"\\'+'\n'

#OutputObj.write("\";\n")
s += "\";\n}\n"
#OutputObj.write("int "+Param+"Size = "+str(txtsize+1)+';\n')
OutputObj.write("#endif\n")
#OutputObj.write("#endif\n")
s += "#endif\n"
#print s
txtTmp.append(s)
i = 0
s = str(txtTmp[1])
i = s.index ("0")
print "\nindex : " + str(i) + "in text : " +s+ '\n'
s_before = s[:i]
s_after = s[i+1:]

s = s_before + str(pgsize+1) + s_after
print "New text : " +s+'\n'
txtTmp[1] = s

for c in txtTmp:
OutputObj.write(c)
i += 1
print " - " +str(c) + " Count - " + str(i)

OutputObj.close()

except Exception as e:
print str(e)
sys.exit(4)
Expand Down

0 comments on commit cb54827

Please sign in to comment.