get-command-string.sl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Get-Command-String.SL (TOPS-20 Version) - Get Program Command String
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 4 August 1982
  8. %
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. (BothTimes (load common jsys))
  11. (load strings)
  12. % The function GET-COMMAND-STRING returns the string argument given
  13. % to the program when it was invoked.
  14. (de char-blank? (ch)
  15. (or (= ch (char space)) (= ch (char tab))))
  16. (fluid '(command-string*))
  17. (de get-command-string ()
  18. (or command-string* (setq command-string* (dec20-get-command-string))))
  19. (de dec20-get-command-string ()
  20. % Read the process command string. This function should only be invoked once
  21. % in a given fork, and should be invoked as soon as possible. The process
  22. % command string is massaged to remove the program name and any trailing
  23. % CRLF.
  24. (prog (s high i j)
  25. (setq s (dec20-read-process-arg))
  26. (setq high (size s))
  27. (if (< high 0) (return ""))
  28. (setq i 0)
  29. (while (and (<= i high) (char-blank? (igets s i)))
  30. (setq i (+ i 1)))
  31. (setq j i)
  32. (while (and (<= j high) (not (char-blank? (igets s j))))
  33. (setq j (+ j 1)))
  34. (if (string-equal (substring s i j) "run") (return ""))
  35. (while (and (<= j high) (char-blank? (igets s j)))
  36. (setq j (+ j 1)))
  37. (while (and (> high j) (not (graphicp (igets s high))))
  38. (setq high (- high 1)))
  39. (return (substring s j (+ high 1)))
  40. ))
  41. (CompileTime (put 'prarg 'OpenCode '((jsys 357) (move (reg 1) (reg 3)))))
  42. (CompileTime (put 'rscan 'OpenCode '((jsys 320) (move (reg 1) (reg 1)))))
  43. (CompileTime (put 'sin 'OpenCode '((jsys 42) (move (reg 1) (reg 3)))))
  44. (de dec20-read-process-arg ()
  45. % On TOPS-20, the command argument can be passed to an inferior fork in two
  46. % ways. The first (and better) way is to pass a string in the process
  47. % argument block. The second (and more popular) way is to pass a string in
  48. % the RESCAN buffer (what a crock!). We will use the process argument block,
  49. % if it is nonempty, otherwise we will read from the RESCAN buffer.
  50. (prog (arg-len str)
  51. (setq arg-len (prarg #.(int2sys (xword 1 8#400000)) 4 0))
  52. (cond ((> arg-len 0)
  53. (setq str (MkString arg-len))
  54. (prarg #.(int2sys (xword 1 8#400000)) (jconv str) arg-len)
  55. (return (recopystringtonull str))
  56. ))
  57. (setq arg-len (rscan 0))
  58. (if (= arg-len 0) (return "")) % no input string
  59. (setq str (MkString arg-len))
  60. (sin 8#777777 (jconv str) (- arg-len))
  61. (return str)
  62. ))