Advertisement
jesusthekiller

pig

Jun 7th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. --[[
  2.     Project info:
  3.    
  4.     Name: Pig
  5.     Creator: Jesusthekiller
  6.     Language: Lua (CC)
  7.     Website: None
  8.     License: GNU GPL
  9.         License file can be fount at www.jesusthekiller.com/license-gpl.html
  10.  
  11.     Version: 1.2
  12. ]]--
  13.  
  14. --[[
  15.     Changelog:
  16.       1.0:
  17.         Public Release
  18.       1.1:
  19.         Now proper Pig Latin :P
  20.         way prefix support
  21.       1.2:
  22.         File output
  23. ]]--
  24.  
  25. --[[
  26.     LICENSE:
  27.    
  28.     Pig - Pig Latin translator
  29.     Copyright (c) 2013 Jesusthekiller
  30.  
  31.     This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  32.  
  33.     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  34.  
  35.     See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  36. ]]--
  37.  
  38. local args = {...}
  39.  
  40. term.setBackgroundColor(colors.black)
  41. term.setTextColor(colors.white)
  42. term.clear()
  43. term.setCursorPos(1, 1)
  44.  
  45. if #args < 2 then
  46.     print([[
  47. Usage:
  48.   Code:
  49.     pig c <text>
  50.   Decode:
  51.     pig d <text>
  52.    
  53. Output is also saved to pig_out]])
  54.     return
  55. end
  56.  
  57. local function isVowel(l)
  58.     l = l:lower()
  59.     local cosonant = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z', 'w', 'y'}
  60.    
  61.     for i = 1, #cosonant do
  62.         if l == cosonant[i] then
  63.             return false
  64.         end
  65.     end
  66.    
  67.     return true
  68. end
  69.  
  70. local f = fs.open("pig_out", "w")
  71. local ow = write
  72.  
  73. local write = function(t)
  74.     f.write(t)
  75.     f.flush()
  76.     ow(t)
  77. end
  78.  
  79.  
  80. if args[1] == "c" then
  81.     for i = 2, #args do
  82.         local w = args[i]
  83.         if isVowel(w:sub(1,1)) then
  84.             if #w < 2 then
  85.                 write(w.."way ")
  86.             else
  87.                 write(w:sub(2)..w:sub(1,1).."way ")
  88.             end
  89.         else
  90.             if #w < 2 then
  91.                 write(w.."ay ")
  92.             else
  93.                 write(w:sub(2)..w:sub(1,1).."ay ")
  94.             end
  95.         end
  96.     end
  97. elseif args[1] == "d" then
  98.     for i = 2, #args do
  99.         local w = args[i]
  100.        
  101.         if w:sub(#w-2) == "way" then
  102.             if #w == 4 then
  103.                 write(w:sub(1,1).." ")
  104.             else
  105.                 write(w:sub(#w-3, #w-3)..w:sub(1, #w-4).." ")
  106.             end
  107.         else
  108.             if #w == 3 then
  109.                 write(w:sub(1,1).." ")
  110.             else
  111.                 write(w:sub(#w-2, #w-2)..w:sub(1, #w-3).." ")
  112.             end
  113.         end
  114.     end
  115. else
  116.     print([[
  117. Usage:
  118.   Code:
  119.     pig c <text>
  120.   Decode:
  121.     pig d <text>]])
  122.     return
  123. end
  124.  
  125. local x, y = term.getCursorPos()
  126. term.setCursorPos(1, y + 1)
  127. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement