MTU-Changing program - Input.lisp


/ Published in: Lisp
Save to your folder(s)

Everything that handles user-input.


Copy this code and paste it in your HTML
  1. ;;;; Input focused, anything the user supplies
  2.  
  3. ;;; Input Checkers
  4.  
  5. (defun interface_input_check (input interface-list)
  6. "Check if the interface selected is a valid interface"
  7. (if (numberp input)
  8. (progn
  9. (setf input (- input 1))
  10. (if (< input 0)
  11. 'exit
  12. (if (nth input interface-list)
  13. (nth input interface-list)
  14. 'invalid)))
  15. 'invalid))
  16.  
  17.  
  18. (defun menu_input_check (input arg-list)
  19. "Returns the function requested, if it doesn't exist returns invalid
  20. Arguments:
  21. 1 - preset | Used for checking preset listing if not nil"
  22. (let* ((preset (car arg-list)))
  23. (cond ((equal input 1)
  24. 'showMtu)
  25. ((equal input 2)
  26. 'EditMTU)
  27. ((equal input 3)
  28. 'CreatePMTU)
  29. ((equal input 9)
  30. 'settings)
  31. (preset ; If extended menu, allow the other functionality
  32. (cond
  33. ((equal input 4)
  34. 'LoadPMTU)
  35. ((equal input 5)
  36. 'EditPMTU)
  37. ((equal input 6)
  38. 'DeletePMTU)
  39. (t 'invalid)))
  40. (t 'invalid))))
  41.  
  42.  
  43. (defun settings_input_check (input arg-list)
  44. "Check for valid settings-input"
  45. (if (equal input 1)
  46. 'changeInterface
  47. 'invalid))
  48.  
  49.  
  50. (defun input_loop (input_checker arg-list)
  51. "Input loop to ensure valid option is suplied
  52. What option is valid is defined in the input_checker
  53.  
  54. Arguments:
  55. Input_checker - Takes a function that knows what input is valid and what isn't
  56. arg-list - List of arguments used for the Input_Checker
  57.  
  58. Return:
  59. 'exit - if 0 is inputed, it will default to exit
  60. retval - The value given by the input_checker"
  61. (let* ((input (read))
  62. (retval (funcall input_checker input arg-list)))
  63. (cond ((equal input 0)
  64. 'exit)
  65. ((equal retval 'invalid)
  66. (format t "Invalid Input!~%>> ")
  67. (input_loop input_checker arg-list))
  68. (t retval))))

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.