interactivestream.awk 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # Copyright (C) 2005, 2006 Stephen Jungels
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # See COPYING for the full text of the license.
  15. BEGIN {
  16. search = "";
  17. savesearch = "";
  18. }
  19. state==0 {
  20. printf \
  21. ("y: yes\nn: no\nY: yes to all\nN: no to all\n/: search\n") \
  22. > "/dev/tty";
  23. state = 1;
  24. }
  25. state==1 {
  26. long = $0;
  27. sub("# ", "", long);
  28. brief = long;
  29. brief = substr(brief, 1, 72);
  30. action = "";
  31. response = "";
  32. if (all!="")
  33. {
  34. action = all;
  35. }
  36. if (action=="" && search!="")
  37. {
  38. if (tolower(long) ~ tolower(search))
  39. {
  40. search = "";
  41. }
  42. else
  43. {
  44. action = "n";
  45. }
  46. }
  47. if (action=="y")
  48. {
  49. getline;
  50. printf ("%s\n", $0);
  51. }
  52. else if (action=="n")
  53. {
  54. getline;
  55. }
  56. # if search and "all" gave no instructions, ask the user
  57. else if (action=="")
  58. {
  59. printf("Play %s (ynYN/)? ", brief) > "/dev/tty";
  60. getline response < "/dev/tty";
  61. if (response ~ /Y(es)?/)
  62. {
  63. response = "y";
  64. all = "y";
  65. }
  66. else if (response ~ /N(o)?/)
  67. {
  68. response = "n";
  69. all = "n";
  70. }
  71. else if (response ~ /^\//)
  72. {
  73. search = substr(response, 2);
  74. if (search=="")
  75. {
  76. search = savesearch;
  77. }
  78. if (search=="")
  79. {
  80. printf("Search string: ") > "/dev/tty";
  81. getline search < "/dev/tty";
  82. }
  83. savesearch = search;
  84. response = "n";
  85. }
  86. if (response ~ /y(es)?/ || response=="")
  87. {
  88. getline;
  89. printf ("%s\n", $0);
  90. }
  91. else
  92. {
  93. getline;
  94. }
  95. }
  96. }