import fileinput import sys, math, random #python multigen.py . 1346 1 if len(sys.argv) != 4: print("Error: example usage lang lineAmount fileAmount", file=sys.stderr) exit(0) random.seed(32384) lang=sys.argv[1] lineAmount=int(sys.argv[2]) fileAmount=int(sys.argv[3]) insertError=len(sys.argv)==5 nextOpenIndex=0 nextFunctionIndex=0 fileIndex=0 file=0 functionNumbers=[] functionStartIndex=0 if lang in ["bolin", "bol", "."]: for i in range(0, lineAmount): if i == nextOpenIndex: if fileIndex != 0: file.close() file=open(f"file{fileIndex}.bolin", "wt") fileIndex += 1 nextOpenIndex = math.ceil((fileIndex/fileAmount)*lineAmount) if i == nextFunctionIndex: functionStartIndex = i file.write(f"test{i}() s32 {{\n") nextFunctionIndex = min(nextFunctionIndex + math.floor(random.random()*1600)+500, nextOpenIndex) file.write(f"\tarray := $s32[{nextFunctionIndex-functionStartIndex}]\n") functionNumbers.append(i) file.write(f"\tarray[{i-functionStartIndex}] = {i*3}\n") if i == nextFunctionIndex-1: r = math.floor(random.random()*(nextFunctionIndex-functionStartIndex)) file.write(f"\treturn array[{r}]\n") file.write(f"}}\n") file.write("main() {\n") for i in functionNumbers: file.write(f"\ttest{i}();\n") file.write("}\n") elif lang == "go": for i in range(0, lineAmount): if i == nextOpenIndex: if fileIndex != 0: file.close() file=open(f"file{fileIndex}.go", "wt") fileIndex += 1 nextOpenIndex = math.ceil((fileIndex/fileAmount)*lineAmount) file.write("package main\n") if i == nextFunctionIndex: functionStartIndex = i file.write(f"func test{i}() int {{\n") nextFunctionIndex = min(nextFunctionIndex + math.floor(random.random()*1600)+500, nextOpenIndex) file.write(f"\tvar array[{nextFunctionIndex-functionStartIndex}]int\n") functionNumbers.append(i) file.write(f"\tarray[{i-functionStartIndex}] = {i*3}\n") if i == nextFunctionIndex-1: r = math.floor(random.random()*(nextFunctionIndex-functionStartIndex)) file.write(f"\treturn array[{r}]\n") file.write(f"}}\n") file.write("func main() {\n") for i in functionNumbers: file.write(f"\ttest{i}();\n") file.write("}\n") elif lang == "c": for i in range(0, lineAmount): if i == nextOpenIndex: if fileIndex != 0: file.close() file=open(f"file{fileIndex}.c", "wt") fileIndex += 1 nextOpenIndex = math.ceil((fileIndex/fileAmount)*lineAmount) if i == nextFunctionIndex: functionStartIndex = i file.write(f"int test{i}() {{\n") nextFunctionIndex = min(nextFunctionIndex + math.floor(random.random()*1600)+500, nextOpenIndex) file.write(f"\tstatic int array[{nextFunctionIndex-functionStartIndex}];\n") functionNumbers.append(i) file.write(f"\tarray[{i-functionStartIndex}] = {i*3};\n") if i == nextFunctionIndex-1: r = math.floor(random.random()*(nextFunctionIndex-functionStartIndex)) file.write(f"\treturn array[{r}];\n") file.write(f"}}\n") for i in functionNumbers: file.write(f"int test{i}();\n") file.write("int main() {\n") for i in functionNumbers: file.write(f"\ttest{i}();\n") file.write("}\n") else: file.write("Incorrect language")