Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #14799

Critique My Script-Fu?

From Tom Hardy <rhardy702@gmail.com>
Newsgroups comp.os.linux.misc
Subject Critique My Script-Fu?
Date 2015-05-18 16:14 -0500
Organization A noiseless patient Spider
Message-ID <2636583.esRYQb6LpY@gmail.com> (permalink)

Show all headers | View raw


A couple of years ago, I described the screen visibility problems of 
driving around, day and night, with a laptop mounted in my car, and 
described my /usr/local/bin/.invert-display.sh which I can trigger 
with a panel button.  It uses xcalib to perform operations on the 
existing LUT entries and is independent of desktop environments.

I got comments, but no critique of the script, so it couldn't have 
been too bad.  

Well, I recently used perl to add graphing capability in a decidedly 
substandard manner.  I really tried to use awk, but couldn't swing 
it, so this is my introduction to perl.  The script is reproduced at 
the bottom.  It also requires the xcalib and plotutils packages.

xcalib -printramps -alter produces output like the following:

...
<approx 760 lines like the following>
...
Warning - red gamma table not monotonic
Warning - green gamma table not monotonic
Warning - blue gamma table not monotonic
Warning - red gamma table not monotonic
Warning - green gamma table not monotonic
Warning - blue gamma table not monotonic
ffff ffff ffff
ff4b ff4b ff4b
fe97 fe97 fe97
fde2 fde2 fde2
fd2d fd2d fd2d
fc79 fc79 fc79
...
<250 more lines, the last one being 0 0 0>
...

The warnings are produced when the display is inverted, as shown 
above, but xcalib otherwise performs normally.

I first thought to use awk to convert hex to the decimal needed by 
plotutils' 'graph'. It has a '--non-decimal-data' option that seemed 
promising, but I couldn't figure it out.

So, perl.  I am really overloading the hex function, first because 
it apparently evaluates strings like 'Warning' to 0, which I've 
excluded from the output, so the warnings are gone.  Second, it 
apparently only reads the first record off a string, which is 
sufficient for me.  And third, I am excluding 0 from output.  There 
should actually be one, either at the beginning or the end.

There are likely other blunders or issues worthy of comment.  For 
instance, couldn't 'test' be replaced by a shell built-in?  Could 
the files '~/.altered-display' and '~/inverted-display' be replaced 
by a single file that's never deleted but simply moved to a new 
name, or have configuration contents that change?  Would there be 
any advantage in doing so?

Can I use awk in place of perl?  Should I do the whole thing in 
perl?  What about formatting or overall program structure?

Comments welcome.

#!/bin/bash

if test -f ~/.inverted-display; then

   if test -f ~/.altered-display; then

      xcalib -clear -alter;
      rm -f ~/.altered-display ~/.inverted-display;

   else

      xcalib -co 60 -alter;  #contrast
      touch ~/.altered-display;

   fi;

else

   if test -f ~/.altered-display; then

      xcalib -clear -alter;
      xcalib -gc 0.7 -invert -alter;  #gamma correction
      mv ~/.altered-display ~/.inverted-display;

   else

      xcalib -gc 1.5 -alter;
      touch ~/.altered-display;

   fi;

fi;

if test Z$1 = 'Zgraph'; then

xcalib -p -a | perl -e 'while(<>) {my $a = hex $_; print $a, "\n" \
if $a ne 0;}' | graph -a -T X -x 0 254 -y 0 65535 -m-1 -S 1;
xcalib -l -a;

fi;

-- 
Tom Hardy <rhardy702@gmail.com>

Back to comp.os.linux.misc | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Critique My Script-Fu? Tom Hardy <rhardy702@gmail.com> - 2015-05-18 16:14 -0500
  Re: Critique My Script-Fu? "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> - 2015-05-19 13:45 +0200
    Re: Critique My Script-Fu? Tom Hardy <rhardy702@gmail.com> - 2015-05-19 19:53 -0500
      Re: Critique My Script-Fu? "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> - 2015-05-20 15:30 +0200
      Re: Critique My Script-Fu? Dan Espen <despen@verizon.net> - 2015-05-20 09:59 -0400
        Re: Critique My Script-Fu? Tom Hardy <rhardy702@gmail.com> - 2015-05-21 11:36 -0500
          Re: Critique My Script-Fu? Dan Espen <despen@verizon.net> - 2015-05-21 13:31 -0400

csiph-web