Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #14799 > unrolled thread
| Started by | Tom Hardy <rhardy702@gmail.com> |
|---|---|
| First post | 2015-05-18 16:14 -0500 |
| Last post | 2015-05-21 13:31 -0400 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.os.linux.misc
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
| From | Tom Hardy <rhardy702@gmail.com> |
|---|---|
| Date | 2015-05-18 16:14 -0500 |
| Subject | Critique My Script-Fu? |
| Message-ID | <2636583.esRYQb6LpY@gmail.com> |
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>
[toc] | [next] | [standalone]
| From | "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> |
|---|---|
| Date | 2015-05-19 13:45 +0200 |
| Message-ID | <60e35ba85a615494b1e24f9cbbd0cfe0@remailer.privacy.at> |
| In reply to | #14799 |
Tom Hardy <rhardy...@gmail.com> [TH]:
TH> Can I use awk in place of perl?
You sure can. The following might be a good starting point:
awk '
/^[0-9a-f \r]+$/{ # select interesting lines
print "*** Input line:" $0; # debugging output
n=split($0,a," ");
for (i=1; i <= n; i++){ # for all fields
/* get their decimal value and use it as needed */
printf strtonum("0x" a[i]) (i != n ? " " : "\n");
};
}
'
[toc] | [prev] | [next] | [standalone]
| From | Tom Hardy <rhardy702@gmail.com> |
|---|---|
| Date | 2015-05-19 19:53 -0500 |
| Message-ID | <2375937.NUOuFrXXZc@gmail.com> |
| In reply to | #14800 |
Anonymous Remailer (austria) wrote: > > Tom Hardy <rhardy...@gmail.com> [TH]: > TH> Can I use awk in place of perl? > > You sure can. The following might be a good starting point: <code> Hm, well, one advantage of the perl code is that it is short. I will be studying this. Awk, regex, shell programming are all areas where I could use a lot of practice. Your code gives me something to chew on. -- Tom Hardy <rhardy702@gmail.com>
[toc] | [prev] | [next] | [standalone]
| From | "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> |
|---|---|
| Date | 2015-05-20 15:30 +0200 |
| Message-ID | <744b18f002d80b6f8e128d4e408606a3@remailer.privacy.at> |
| In reply to | #14812 |
Tom Hardy <rhardy...@gmail.com> [TH]: TH> one advantage of the perl code is that it is short. It is (at the cost of increased resources used by the perl executable, which might be totally acceptable in your situation). My sample code sacrifices some brevity for the sake of readability.
[toc] | [prev] | [next] | [standalone]
| From | Dan Espen <despen@verizon.net> |
|---|---|
| Date | 2015-05-20 09:59 -0400 |
| Message-ID | <mji3u4$vph$1@dont-email.me> |
| In reply to | #14812 |
Tom Hardy <rhardy702@gmail.com> writes: > Anonymous Remailer (austria) wrote: > >> >> Tom Hardy <rhardy...@gmail.com> [TH]: >> TH> Can I use awk in place of perl? >> >> You sure can. The following might be a good starting point: > > <code> > > Hm, well, one advantage of the perl code is that it is short. Another advantage is that you can do the whole thing in Perl. No need to mix Perl and sh. > I will be studying this. Awk, regex, shell programming are all > areas where I could use a lot of practice. Your code gives me > something to chew on. Years ago, I'd start a project in sh, and often get to point where I'd drug in sed, awk, cut, head. IMO, a complete mess. Just start out in Perl. -- Dan Espen
[toc] | [prev] | [next] | [standalone]
| From | Tom Hardy <rhardy702@gmail.com> |
|---|---|
| Date | 2015-05-21 11:36 -0500 |
| Message-ID | <4278188.aj6kXJMRvL@gmail.com> |
| In reply to | #14816 |
Dan Espen wrote: [...] > Just start out in Perl. Trying to think what that would mean, given the simplicity of the script; a few tests, touch, mv, xcalib, etc. in the first part, and the second part a single line with perl sandwiched in the middle of a pipe. (It could be a separate script as it's not necessary to the everyday use of .invert-display.sh. Ultimately, perl whold be your shell. Is that in any way feasible? -- Tom Hardy <rhardy702@gmail.com>
[toc] | [prev] | [next] | [standalone]
| From | Dan Espen <despen@verizon.net> |
|---|---|
| Date | 2015-05-21 13:31 -0400 |
| Message-ID | <mjl4nk$m96$1@dont-email.me> |
| In reply to | #14826 |
Tom Hardy <rhardy702@gmail.com> writes: > Dan Espen wrote: > > [...] > >> Just start out in Perl. > > Trying to think what that would mean, given the simplicity of the > script; a few tests, touch, mv, xcalib, etc. in the first part, and > the second part a single line with perl sandwiched in the middle of > a pipe. (It could be a separate script as it's not necessary to the > everyday use of .invert-display.sh. That means, when you think you have a simple shell script to write, give some thought to what that shell might grow into. I found a number of times that what started out simple grew steadily more complex. In your case, part of your shell turned into perl. Rather than having mixtures of sh, perl, awk, and a bunch of other stuff, perl can do the whole job. Surprisingly, I didn't find any Perl modules for xcalib, but when there is a perl module, (like for web access or html parsing), perl becomes even more of a win. > Ultimately, perl whold be your shell. Is that in any way feasible? No. -- Dan Espen
[toc] | [prev] | [standalone]
Back to top | Article view | comp.os.linux.misc
csiph-web