Re: Contest #2... Example Programs
- Posted by unkmar Dec 21, 2010
- 2178 views
File: message.ex
#!/usr/bin/eui include std/text.e include get.e with trace constant VALIDS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " function purify(sequence msg) integer rp, vcp sequence temp, result temp = upper(msg) result = temp rp = 1 -- Result Pointer for A = 1 to length(temp) do vcp = find(temp[A], VALIDS) if vcp then result[rp] = temp[A] rp += 1 end if end for return result[1..rp-1] end function function convert(sequence msg) integer rp, vcp sequence result result = msg rp = 1 -- Result Pointer for A = 1 to length(result) do vcp = find(result[A], VALIDS) if vcp then result[rp] = {} while (vcp > 9) do result[rp] &= 9 vcp -= 9 end while result[rp] &= vcp rp += 1 end if end for return result[1..rp-1] end function integer fp integer comments sequence YesNo, msg, cmsg fp = open("message.txt", "w") comments = 0 YesNo = "YyNn" puts(1, "\tYour message code will be output to message.txt\n") puts(1, "\tMax Message length is 989\n\n") puts(1, "\t Longer codes can be generated\n") puts(1, "\t And will crash the cpu program\n") puts(1, "\tDo you want to output code Comments? [Y/n]") while (0 = find(comments, YesNo)) do comments = wait_key() if find(comments, "\r\n") then comments = 'Y' end if end while if comments = 'Y' or comments = 'y' then puts(1, " Yes\n") else puts(1, " No\n") end if puts(1, "\n") puts(1, "Message: ") msg = gets(0) msg = purify(msg) cmsg = convert(msg) puts(1, "\n") if comments = 'Y' then if (40 > length(msg)) then printf (fp, "391 ; %s\n", {34 & msg & 34}) end if printf(fp, "39%d ; --==[ Letter START ]==-\n", length(cmsg[1]) + 3) puts(fp, "321 ; MP += 1\n") printf(fp, "21%d ; %s (Letter goes here)\n", {cmsg[1][1], msg[1]}) for B = 2 to length(cmsg[1]) do printf(fp, "31%d\n", cmsg[1][B]) end for puts(fp, "912 ; [PUSH] --==[ Letter END ]==-\n") else printf(fp, "39%d\n", length(cmsg) + 3) puts(fp, "321\n") printf(fp, "215\n", cmsg[1][1]) for B = 2 to length(cmsg[1]) do printf(fp, "31%d\n", cmsg[1][B]) end for puts(fp, "912\n") end if for A = 2 to length(msg) do if comments = 'Y' then printf(fp, "39%d ; --==[ Letter START ]==-\n", length(cmsg[A]) + 3) puts(fp, "321 ; MP += 1\n") printf(fp, "21%d ; %s (Letter)\n", {cmsg[A][1], msg[A]}) for B = 2 to length(cmsg[A]) do printf(fp, "31%d\n", cmsg[A][B]) end for puts(fp, "912 ; [PUSH]\n") else printf(fp, "39%d\n", length(cmsg) + 3) puts(fp, "321\n") printf(fp, "215\n", cmsg[A][1]) for B = 2 to length(cmsg[A]) do printf(fp, "31%d\n", cmsg[A][B]) end for puts(fp, "912\n") end if end for close(fp)