home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / mail / mush / 323 next >
Encoding:
Text File  |  1992-09-08  |  2.2 KB  |  83 lines

  1. Newsgroups: comp.mail.mush
  2. Path: sparky!uunet!usc!rpi!psinntp!psinntp!pool!buck
  3. From: buck@pool.info.sunyit.edu (Jesse Buckley)
  4. Subject: Re: filtering the response
  5. Message-ID: <1992Sep4.182227.27445@pool.info.sunyit.edu>
  6. Keywords: filter, responding
  7. Organization: State University of New York -- Institute of Technology
  8. References: <1992Aug28.132940.25322@corwin.barra.com>
  9. Date: Fri, 4 Sep 1992 18:22:27 GMT
  10. Lines: 71
  11.  
  12. In article <1992Aug28.132940.25322@corwin.barra.com> robertb@BARRA.COM (Robert Brown) writes:
  13. >
  14. >I asked this question long ago, but I don't think it ever actually got
  15. >posted...
  16. >
  17. >I'd like to be able to specify a filter of some sort that filters the
  18. >message that I'm responding to before it gets "autoinclude"d.  I would
  19. >prefer that this filter be an executeable that I can specify, perhaps
  20. >through a variable.
  21. >
  22. >The reason I want to do this is to filter tabs into spaces because the
  23. >tabs get all messed up once they get the indent_str is put onto the
  24. >beginning of each line.
  25. >
  26. >Does anyone know how I can do this?  Is this possible with the current
  27. >mush?  If it is not possible, has anyone implemented something like
  28. >this?
  29.  
  30. With perl all things are possible.  =)
  31.  
  32. Set your editor to detabed.  Don't forget this is a hack...
  33.  
  34. #! /usr/local/bin/perl
  35. #
  36. # Author: Jesse R. Buckley, Jr. (buck@sunyit.edu NIC:JRB69)
  37. #
  38. # detabed -- A quick hack to use tabs the right way...
  39. #
  40. # Useage: detabed file prefix
  41. #
  42.  
  43. $TEMP    = "$ENV{'HOME'}/.mushtmp$$";
  44. $FILE    = $ARGV[0];
  45. $EDITOR = $ENV{'EDITOR'} || "/usr/ucb/vi";
  46.  
  47. $prefix= $ARGV[1] || '} ';    # The stuff in the 'quotes' 
  48.                 # is the default prefix.
  49. open(IN,"$FILE");
  50. open(OUT,">$TEMP");
  51.  
  52. $prelen = length($prefix);
  53. while(<IN>)
  54. {
  55.  
  56.     if (/^$prefix/o)
  57.     {
  58.  
  59.  
  60.     $_ = substr($_,$prelen);
  61.     # This is taken verbatim from the Camel book.
  62.         1 while s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
  63.     print OUT "$prefix$_";
  64.  
  65.     }
  66.     else
  67.     {
  68.         print OUT;
  69.     }
  70.  
  71. }
  72. close(OUT);
  73. system("cp $TEMP $FILE");
  74. system("rm -f $TEMP");
  75. system("$EDITOR $FILE");
  76.  
  77.  
  78. -- 
  79. =) Buck (buck@sunyit.edu)
  80. "There are some micro-organisms that exhibit characteristics of both plants
  81. and animals.  When exposed to light they undergo photosynthesis; and when the
  82. lights go out, they turn into animals.  But then again, don't we all?"
  83.