functions.ss 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/slidescript
  2. #############################################################
  3. #### Welcome to the world of SlideScript! ####
  4. #### This script is here for the learning purposes of SS ####
  5. #### Any line starting with a hashtag will treated as a ####
  6. #### comment! ####
  7. #############################################################
  8. # Slide Script, also refered to as SS, is extremely forgiving in
  9. # syntax handling!
  10. # Example:
  11. # print "content"
  12. # print("content")
  13. ###
  14. ### These will operate properly, as well as:
  15. # Example:
  16. # write "filename.txt" "data"
  17. # write "filename.txt", "data"
  18. # write("filename.txt" "data")
  19. # write("filename.txt", "data")
  20. #
  21. # IT ALL WORKS!
  22. # SlideScript really syntaxes based on quotes and key function words,
  23. # as well as pipes. It really doesn't mind whats around it otherwise
  24. # And every variable is called by %varname%, defining variables, as normal
  25. # Variables in SS
  26. ss_filename=file.txt
  27. ss_stringdata=Data to encrypt and decrypt
  28. ss_exec_command=uname -a
  29. # Printing function in SS
  30. print "Welcome to SlideScript!"
  31. # Sleep function in SS
  32. print "Some content to print, working with '%ss_filename%' today!"
  33. # Below demonstrates SS encrypting a string, passing the output
  34. # over a pipe, and using the write function and %PIPE% variable
  35. # holding the first functions output, writes to %ss_filename%; file.txt
  36. ### %PIPE% is the output from the first line function, enc
  37. ### %PIPE% is always applied when a pipe is used!
  38. encode "%ss_stringdata%" | write "%ss_filename%" "%PIPE%"
  39. # You're left with file.txt, lets move on
  40. # Lets read the file we just created and show how SS handles its
  41. # own decryption algorithm
  42. read "%ss_filename%" | decrypt "%PIPE%"
  43. # Will display the original variable string!
  44. # SS MD5 function
  45. # Lets get the md5sum of file.txt with our md5 function
  46. md5 "%ss_filename%" | write "%ss_filename%.md5" "%PIPE%"
  47. # Use a pipe, and push the md5 into a text file of file.txt
  48. # You can also stack pipes for whatever tasks you may need
  49. # Here's the encrypt function in action, can also be used as encode
  50. md5 "%ss_filename%" | encode "%PIPE%" | write "%ss_filename%.md5.enc" "%PIPE%"
  51. # Read md5 file
  52. print "%ss_filename%.md5:"
  53. read "%ss_filename%.md5"
  54. # Read encrypted md5 file and decrypt using decode alias
  55. print "%ss_filename%.md5.enc:"
  56. read "%ss_filename%.md5.enc" | decode "%PIPE%"
  57. # Delete function, SS can delete files and directories with one function
  58. # NOTE: it is extremely powerful and can wreck your system if used in the
  59. # wrong way! Proceed with caution, delete "/" WILL send your files to the
  60. # grave.
  61. ###
  62. # Lets delete the files we've been messing with, no system calls needed
  63. delete "%ss_filename%"
  64. delete "%ss_filename%.md5"
  65. delete "%ss_filename%.md5.enc"
  66. # Gone!
  67. print "Playing with some calc..."
  68. # calc function, lets do some basic math
  69. calc "32 * 1024"
  70. # You can pipe calc to do multi layer equations
  71. calc "32 * 1024" | calc "%PIPE% * 2"
  72. # Lets play with some big numbers here!
  73. # SlideScript parses its calc functions using floating points, so you can
  74. # handle decimal as well
  75. calc "1024 * 1024" | calc "%PIPE% * %PIPE%"
  76. # Decimal
  77. print "Here comes the decimal:"
  78. calc "46 / 3.4"
  79. # Execute function, SS can call unix system calls!
  80. # Executes the ss_exec_command variable data, 'ls'
  81. print "Testing exec function on system"
  82. # comp, loop, if, and ifn examples
  83. # Check to see if /bin/sh exists
  84. exist=`isfile "/bin/sh"`
  85. # Report findings on /bin/sh
  86. if: %exist%; print "/bin/sh exists!"
  87. ifn: %exist%; printf "/bin/sh does not exist!"
  88. # Loop functions, example
  89. loop: 3; print "Loop print 3 times"
  90. # Compare strings
  91. compvar=`comp: "matching" "match"`
  92. ifn: %compvar%; print "Strings don't match"
  93. # Unset compvar
  94. unset "compvar"
  95. # Set again, and compare integers
  96. compvar=`comp: "245" "245"`
  97. if: %compvar%; print "Values match!"
  98. # Want to use SS as a shell?
  99. # System wide executables can be ran!
  100. %ss_exec_command%