Home > Archive > AWK > February 2008 > GUI Awk
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| happytoday 2008-01-25, 10:01 pm |
| Where can I find a version of awk that hs a GUI interface ? I need to
build Executalbe script under windows environment . Thanks in
advance . Bless u
| |
| Janis Papanagnou 2008-01-26, 8:00 am |
| happytoday wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in
> advance . Bless u
To write your awk program you can use any text editor with GUI
interface. The awk program saved in the file system can then be
called from any command shell you have on your WinDOS environment
(DOS box, MKS kornshell, Cygwin bash, etc.). If that doesn't fit;
what exactly do you want the GUI to do? (Do you want an IDE?)
Janis
| |
| Kees Nuyt 2008-01-26, 8:00 am |
| On Fri, 25 Jan 2008 18:37:15 -0800 (PST), happytoday
<ehabaziz2001@gmail.com> wrote:
>Where can I find a version of awk that hs a GUI interface ? I need to
>build Executalbe script under windows environment . Thanks in
>advance . Bless u
I don't think there is a GUI.
In a MS Windows environment people usually make .cmd and
..awk scripts with notepad or a similar ASCII editor and
put a shortcut to the .cmd script on the users' desktop.
End users can drag their files on the shortcut, or
double-click it to trigger the required processing.
Parameters can be asked for with the SET /P comamnd and
passed to the awk script via the environment array.
It takes some learning and creativity to accomplish that.
If you're not willing to invest in that, awk probably is
not the right tool for you.
Note: Some subscribers in this group may regard this
subject Off Topic for discussing any further.
--
( Kees
)
c[_] In the free world the media isn't government run; the
government is media run. (/.) (#482)
| |
| Ted Davis 2008-01-26, 10:03 pm |
| On Fri, 25 Jan 2008 18:37:15 -0800, happytoday wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in advance .
To make executables, you need a compiler. Good luck finding one.
Considering what awk is for, there doesn't seem to be any real use for a
GUI interface for awk programs. There is an awk2c translater, and there
are awk libraries for C.
In ages past, there was TAWK, which was a very good awk compiler, but
Thompson Automation no longer sells it (and it didn't have an IDE, but it
did have a debugger).
If you mean an IDE type wrapper for creating scripts, any good
programmer's text editor with syntax highlighting would be more than
enough when combined with a separate shell window for testing the program.
Debugging is mostly done by inserting print commands in the script to keep
you informed about what's really happening.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
|
| happytoday <ehabaziz2001@gmail.com> wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in
> advance . Bless u
You can perhaps use gtk server with some awk interpreter...
http://www.gtk-server.org/
I don't know how well or even if it works on windows..
You probably should consider another language if your goal is
to create windows applications.
--
pgas @ SDF Public Access UNIX System - http://sdf.lonestar.org
| |
| happytoday 2008-01-26, 10:03 pm |
| On Jan 26, 7:22=A0pm, pgas <pierre.gas...@gmail.com> wrote:
> happytoday <ehabaziz2...@gmail.com> wrote:
>
> You can perhaps use gtk server with some awk interpreter...http://www.gtk-=
server.org/
> I don't know how well or even if it works on windows..
>
> You probably should consider another language if your goal is
> to create windows applications.
>
> --
> pgas @ SDF Public Access UNIX System -http://sdf.lonestar.org
I need to have interface with the user though some windows and dialogs
though awk . I mean the output of the executing will be including GUI
interface with the user .
Thanks
| |
| happytoday 2008-01-26, 10:03 pm |
| On Jan 26, 10:13=A0pm, happytoday <ehabaziz2...@gmail.com> wrote:
> On Jan 26, 7:22=A0pm, pgas <pierre.gas...@gmail.com> wrote:
>
>
k-server.org/[color=darkred]
>
>
>
> I need to have interface with the user though some windows and dialogs
> though awk . I mean the output of the executing will be including GUI
> interface with the user .
> Thanks
Is the GTK server available under windows operating system
environment ?
| |
| Cesar Rabak 2008-01-26, 10:03 pm |
| happytoday escreveu:
> On Jan 26, 7:22 pm, pgas <pierre.gas...@gmail.com> wrote:
>
> I need to have interface with the user though some windows and dialogs
> though awk . I mean the output of the executing will be including GUI
> interface with the user .
Although OT in this NG, you may consider using Tcl/Tk for this, with
minor tweaks should work for most platforms.
| |
| Kenny McCormack 2008-01-26, 10:04 pm |
| In article <613176da-d574-4e89-ab77-4a428243af96@s13g2000prd.googlegroups.com>,
happytoday <ehabaziz2001@gmail.com> wrote:
....
>I need to have interface with the user though some windows and dialogs
>though awk . I mean the output of the executing will be including GUI
>interface with the user .
>Thanks
I think I see what you are getting at - that you would like to have an
application that has a nice, windowsy front end, but uses AWK in the
background to do the stuff that AWK does best.
Interestingly enough, I have done some stuff along these lines. I use
WinBatch as my front end coding language; WB makes "DllCall"s into the
TAWK DLL to do string stuff. It is quite .
FWIW, you could probably do the same sort of thing in, e.g., Visual
Basic, and I think there are Windows DLL versions of GAWK floating
around as well.
| |
| happytoday 2008-01-26, 10:04 pm |
| On Jan 26, 10:41=A0pm, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <613176da-d574-4e89-ab77-4a428243a...@s13g2000prd.googlegroups.=
com>,happytoday =A0<ehabaziz2...@gmail.com> wrote:
>
> ...
>
>
> I think I see what you are getting at - that you would like to have an
> application that has a nice, windowsy front end, but uses AWK in the
> background to do the stuff that AWK does best.
>
> Interestingly enough, I have done some stuff along these lines. =A0I use
> WinBatch as my front end coding language; WB makes "DllCall"s into the
> TAWK DLL to do string stuff. =A0It is quite .
>
> FWIW, you could probably do the same sort of thing in, e.g., Visual
> Basic, and I think there are Windows DLL versions of GAWK floating
> around as well.
Is TAWK DLL has the strength as gawk functions has ?
| |
| happytoday 2008-01-26, 10:04 pm |
| On Jan 26, 10:41=A0pm, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <613176da-d574-4e89-ab77-4a428243a...@s13g2000prd.googlegroups.=
com>,happytoday =A0<ehabaziz2...@gmail.com> wrote:
>
> ...
>
>
> I think I see what you are getting at - that you would like to have an
> application that has a nice, windowsy front end, but uses AWK in the
> background to do the stuff that AWK does best.
>
> Interestingly enough, I have done some stuff along these lines. =A0I use
> WinBatch as my front end coding language; WB makes "DllCall"s into the
> TAWK DLL to do string stuff. =A0It is quite .
>
> FWIW, you could probably do the same sort of thing in, e.g., Visual
> Basic, and I think there are Windows DLL versions of GAWK floating
> around as well.
Can you please just send the trial version of WinBatch to my email .
I failed to download it from all sites .
Thanks
| |
| Ted Davis 2008-01-26, 10:04 pm |
| On Sat, 26 Jan 2008 15:09:21 -0800, happytoday wrote:
> Is TAWK DLL has the strength as gawk functions has ?
Yes and no. It has true multi-dimensional arrays, but does not have the
gawk extensions to plain awk. I no longer use TAWK because gawk better
suits my text processing needs.
For GUI user interfaces, I use apache and Firefox with gawk doing the CGI
processes. Also with some PHP mixed in. I no longer use WinBatch either
- I have compiler licenses for both TAWK and WinBatch, but they just sit
there unused. The text mode interface in the window running gawk is
adequate for most purposes. The main exception is file selection via a
windows file selection dialog box - for this I use a free utility from
Frank Westlake (<http://www.geocities.com/fp.westlake/nt/> ) called
ConGetFile with this syntax
"congetfile.exe\" | getline string
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
| happytoday 2008-01-27, 7:02 pm |
| On Jan 27, 3:16 am, Ted Davis <tda...@umr.edu> wrote:
> On Sat, 26 Jan 2008 15:09:21 -0800, happytoday wrote:
>
> Yes and no. It has true multi-dimensional arrays, but does not have the
> gawk extensions to plain awk. I no longer use TAWK because gawk better
> suits my text processing needs.
>
> For GUI user interfaces, I use apache and Firefox with gawk doing the CGI
> processes. Also with some PHP mixed in. I no longer use WinBatch either
> - I have compiler licenses for both TAWK and WinBatch, but they just sit
> there unused. The text mode interface in the window running gawk is
> adequate for most purposes. The main exception is file selection via a
> windows file selection dialog box - for this I use a free utility from
> Frank Westlake (<http://www.geocities.com/fp.westlake/nt/> ) called
> ConGetFile with this syntax
>
> "congetfile.exe\" | getline string
>
> --
>
> T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
> used to be UMR (University of Missouri - Rolla).
Is the gawk can have interface interaction under Solaris (Unix) ?
| |
| Ted Davis 2008-01-27, 7:02 pm |
| On Sun, 27 Jan 2008 14:48:40 -0800, happytoday wrote:
>
> Is the gawk can have interface interaction under Solaris (Unix) ?
It is fundamentally an Unix tool. It is a perfect fit for the "Unix Way"
- any program or utility that also fits that mindset will work with it.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
|
|
| Adrian Davis 2008-01-28, 8:00 am |
| On 26 Jan, 02:37, happytoday <ehabaziz2...@gmail.com> wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in
> advance . Bless u
I think your best bet would be to use Tcl/Tk instead of AWK.
Best Regards,
=Adrian=
| |
| ggrothendieck 2008-01-29, 4:00 am |
| On Jan 25, 9:37=A0pm, happytoday <ehabaziz2...@gmail.com> wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in
> advance . Bless u
You could write the GUI portion in a combination of HTML and either
vbscript or jscript (i.e. javascript), both of which come with
Windows.
To run your program directly from Windows rather than through the
Browser
your program would be called an HTML Application or .hta so google
for
.hta command line
for info on HTAs that run command line programs such as awk.
| |
| happytoday 2008-01-29, 7:01 pm |
| On Jan 28, 1:57=A0pm, Adrian Davis <adr...@satisoft.com> wrote:
> On 26 Jan, 02:37, happytoday <ehabaziz2...@gmail.com> wrote:
>
>
> I think your best bet would be to use Tcl/Tk instead of AWK.
>
> Best Regards,
> =A0 =A0=3DAdrian=3D
Is Tcl/Tk has the stregth of awk in files processing ?
| |
|
| "Kenny McCormack" <gazelle@xmission.xmission.com> wrote in message
news:fng5u1$8q7$1@news.xmission.com...
> In article
> <613176da-d574-4e89-ab77-4a428243af96@s13g2000prd.googlegroups.com>,
> happytoday <ehabaziz2001@gmail.com> wrote:
> ...
>
> I think I see what you are getting at - that you would like to have an
> application that has a nice, windowsy front end, but uses AWK in the
> background to do the stuff that AWK does best.
>
> Interestingly enough, I have done some stuff along these lines. I use
> WinBatch as my front end coding language; WB makes "DllCall"s into the
> TAWK DLL to do string stuff. It is quite .
>
> FWIW, you could probably do the same sort of thing in, e.g., Visual
> Basic, and I think there are Windows DLL versions of GAWK floating
> around as well.
>
Kenny
Picking up your comment on using the Tawk.dll, I have always been curious on
how to use this Tawk feature.
I have Tawk and use it constantly at work for really big mine model
files --- i.e pre & post-processing millions of lines in mining block files
made by expensive software.
I look at the Tawk documentation and can't get any traction on how to uses
it as a DLL. I've always thought that it would be really
use in that way. Any hints would be appreciated.
Regards,
Rex
| |
| Juergen Kahrs 2008-01-30, 4:00 am |
| happytoday wrote:
> Is Tcl/Tk has the stregth of awk in files processing ?
Tcl/Tk is good for writing GUIs.
For files processing, I would prefer AWK.
But if you are willing to learn Tcl really
well, then you might be able to achieve
comparable results.
An alternative is Perl/Tk.
| |
|
| happytoday wrote:
> Where can I find a version of awk that hs a GUI interface ? I need to
> build Executalbe script under windows environment . Thanks in
> advance . Bless u
http://jackparke.googlepages.com/awkgui
Never tried it.
| |
| Ted Davis 2008-02-02, 7:01 pm |
| On Sat, 02 Feb 2008 07:59:25 +0000, Al wrote:
> happytoday wrote:
>
>
>
> http://jackparke.googlepages.com/awkgui
>
> Never tried it.
I'm not impressed: it's a crude pseudoIDE for mawk. It's in the form of
a .hta file, so it can be modified to use gawk, but when I tried it with
one of my (rather complicated) scripts, it failed to do anything useful.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
|
|
"Ted Davis" <tdavis@umr.edu> schreef in bericht
news:pan.2008.02.02.17.16.57.875000@umr.edu...
> On Sat, 02 Feb 2008 07:59:25 +0000, Al wrote:
>
>
> I'm not impressed: it's a crude pseudoIDE for mawk. It's in the form of
> a .hta file, so it can be modified to use gawk, but when I tried it with
> one of my (rather complicated) scripts, it failed to do anything useful.
>
> --
>
> T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and
> Technology)
> used to be UMR (University of Missouri - Rolla).
>
>
in the readme it says:
A simple HTA GUI for AWK.
Load and save your favorite queries.
Suited for analysing IIS log files.
so, its simple...
" it failed to do anything useful."
that 'could' be cause bye your script... ;-)
| |
| Ted Davis 2008-02-02, 10:04 pm |
| On Sat, 02 Feb 2008 18:42:27 +0100, Luuk wrote:
>
> "Ted Davis" <tdavis@umr.edu> schreef in bericht
> news:pan.2008.02.02.17.16.57.875000@umr.edu...
> in the readme it says:
> A simple HTA GUI for AWK.
> Load and save your favorite queries.
> Suited for analysing IIS log files.
>
> so, its simple...
For MAWK ... explicitly.
>
> " it failed to do anything useful."
> that 'could' be cause bye your script... ;-)
That script runs perfectly once a day every day. That's under Linux - it
does malfunction in XP under well defined machine specific conditions,
none of which applied during the test.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
| colin.macleod@tesco.net 2008-02-04, 7:01 pm |
| On 29 Jan, 22:04, happytoday <ehabaziz2...@gmail.com> wrote:
> On Jan 28, 1:57=A0pm, Adrian Davis <adr...@satisoft.com> wrote:
>
> Is Tcl/Tk has the stregth of awk in files processing ?
Take a look at http://wiki.tcl.tk/1063 which gives Tcl equivalents for
various awk operations. Of course they tend to be longer, as awk is
optimised for file processing, while Tcl tries to be more general
purpose.
| |
| Kenny McCormack 2008-02-04, 7:01 pm |
| In article <374bfa24-578e-4bfe-bde1-4c9194f0d0b8@1g2000hsl.googlegroups.com>,
<colin.macleod@tesco.net> wrote:
>On 29 Jan, 22:04, happytoday <ehabaziz2...@gmail.com> wrote:
>
>Take a look at http://wiki.tcl.tk/1063 which gives Tcl equivalents for
>various awk operations. Of course they tend to be longer, as awk is
>optimised for file processing, while Tcl tries to be more general
>purpose.
True. Note that Tcl is an ugly language, and I think if you like AWK,
you probably won't like Tcl. I like the original concept of Tcl, which
was to be an embeddable language. Not the best language in the world,
by any means, but generic enough to be used in the context of other
tools. Unfortunately, the fabulously useful "Expect" application is the
only instance that I know of where this, the original intent and purpose
of Tcl, was actually utilized. I learned enough Tcl to get around in
Expect, but never was too fond of it (Tcl) as a language.
| |
| Adrian Davis 2008-02-04, 7:01 pm |
| > True. =A0Note that Tcl is an ugly language, and I think if you like AWK,
> you probably won't like Tcl. =A0I like the original concept of Tcl, which
> was to be an embeddable language. =A0Not the best language in the world,
> by any means, but generic enough to be used in the context of other
> tools. =A0Unfortunately, the fabulously useful "Expect" application is the=
> only instance that I know of where this, the original intent and purpose
> of Tcl, was actually utilized. =A0I learned enough Tcl to get around in
> Expect, but never was too fond of it (Tcl) as a language.
I think you will find that there are many people who find Tcl to be a
simple and elegant language. It is also a *very* good general purpose
language. It seems that, in many instances, this opinion is based on
earlier versions of Tcl. Tcl has come a long way in the last five
years.
Best Regards,
=3DAdrian=3D
| |
| happytoday 2008-02-07, 6:59 pm |
| On Feb 3, 3:20=A0am, Ted Davis <tda...@umr.edu> wrote:
> On Sat, 02 Feb 2008 18:42:27 +0100, Luuk wrote:
>
>
>
[color=darkred]
[color=darkred]
>
>
>
of[color=darkred]
h[color=darkred]
..[color=darkred]
>
>
>
>
>
> For MAWK ... explicitly.
>
>
>
>
> That script runs perfectly once a day every day. That's under Linux - it
> does malfunction in XP under well defined machine specific conditions,
> none of which applied during the test.
>
> --
>
> T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology=
)
> used to be UMR (University of Missouri - Rolla).- Hide quoted text -
>
> - Show quoted text -
All those nelow graphic libraries used under Linux but not under
Solaris or windows !!!!
http://linux.pte.hu/%7Epipas/gtkdialog/index.html
http://www.gtk-server.org/
| |
| Ted Davis 2008-02-07, 6:59 pm |
| On Thu, 07 Feb 2008 08:47:34 -0800, happytoday wrote:
> All those nelow graphic libraries used under Linux but not under Solaris
> or windows !!!!
> http://linux.pte.hu/%7Epipas/gtkdialog/index.html
> http://www.gtk-server.org/
I have GTK on two XP machines - it's used by Gimp. I
know it's available for Solaris as well.
Since you can run KDE on XP, I see no reason why GTKDialog could be made
to work there, and it should certainly work on Solaris, at least to the
extent it's Posix compliant.
--
T.E.D. (tdavis@mst.edu)
| |
| happytoday 2008-02-08, 6:59 pm |
| On Feb 7, 11:25=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Thu, 07 Feb 2008 08:47:34 -0800, happytoday wrote:
[color=darkred]
>
> I have GTK on two XP machines - it's used by Gimp. =A0I
> know it's available for Solaris as well.
>
> Since you can run KDE on XP, I see no reason why GTKDialog could be made
> to work there, and it should certainly work on Solaris, at least to the
> extent it's Posix compliant.
>
> --
> T.E.D. (tda...@mst.edu)
Could you please send the exact URL for downloadinf for Solaris , XP .
Thanks in advance
| |
| Ted Davis 2008-02-08, 6:59 pm |
| On Fri, 08 Feb 2008 12:27:00 -0800, happytoday wrote:
> On Feb 7, 11:25_pm, Ted Davis <tda...@umr.edu> wrote:
>
> Could you please send the exact URL for downloadinf for Solaris , XP .
> Thanks in advance
Google is your friend:
download gtk solaris OR XP
returns many sources, including these
Windows: http://tinyurl.com/23tt2a (sourceforge)
Solaris 10 on SPARC: http://tinyurl.com/29un38 (sunfreeware)
--
T.E.D. (tdavis@mst.edu)
| |
| happytoday 2008-02-09, 6:58 pm |
| On Feb 8, 11:25=A0pm, Ted Davis <tda...@umr.edu> wrote:
> On Fri, 08 Feb 2008 12:27:00 -0800, happytoday wrote:
>
>
e[color=darkred]
[color=darkred]
>
>
>
> Google is your friend:
> =A0 download gtk solaris OR XP
> returns many sources, including these
>
> Windows:http://tinyurl.com/23tt2a(sourceforge)
> Solaris 10 on SPARC:http://tinyurl.com/29un38(sunfreeware)
>
> --
> T.E.D. (tda...@mst.edu)- Hide quoted text -
>
> - Show quoted text -
I can a lot of items . which one I will use ?
GTK+ Preference Tool 0.4.1 December 12, 2007 - Download
GTK+ Runtime Environment GTK+ 2.12 February 2, 2008 - Download
GTK+ Themes Installer 2008-01-21 January 21, 2008 - Download
Legacy GTK+ Dev. Environment 2.2.4-3 May 2, 2004 - Download
Legacy GTK+ Runtime Env. 2.2.4-3 May 2, 2004 - Download
Legacy GTK+ Source releases 2.2.4-2 March 5, 2004 - Download
Other Support Files 2007-12-15 December 15, 2007 - Download
| |
| Ted Davis 2008-02-09, 10:02 pm |
| On Sat, 09 Feb 2008 12:19:53 -0800, happytoday wrote:
>
> I can a lot of items . which one I will use ?
>
> GTK+ Preference Tool 0.4.1 December 12, 2007 - Download GTK+ Runtime
> Environment GTK+ 2.12 February 2, 2008 - Download GTK+ Themes Installer
> 2008-01-21 January 21, 2008 - Download Legacy GTK+ Dev. Environment
> 2.2.4-3 May 2, 2004 - Download Legacy GTK+ Runtime Env. 2.2.4-3 May 2,
> 2004 - Download Legacy GTK+ Source releases 2.2.4-2 March 5, 2004 -
> Download Other Support Files 2007-12-15 December 15, 2007 - Download
Certainly the Run Time Environment - that's necessary for everything.
Other than that, you will have to figure out what you need based on what
you want to do and the computing environment.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
| happytoday 2008-02-16, 7:58 am |
| On Feb 10, 3:27=A0am, Ted Davis <tda...@umr.edu> wrote:
> On Sat, 09 Feb 2008 12:19:53 -0800, happytoday wrote:
>
>
me[color=darkred]
aller[color=darkred]
t[color=darkred]
y 2,[color=darkred]
=A0-[color=darkred]
ad[color=darkred]
>
> Certainly the Run Time Environment - that's necessary for everything.
> Other than that, you will have to figure out what you need based on what
> you want to do and the computing environment.
>
> --
>
> T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology=
)
> used to be UMR (University of Missouri - Rolla).
Here is the path of the GTK-server and the example in the site with
that error :
H:\programs\sedawk\Gtk>gawk -f test.awk
gawk: test.awk:13: fatal: `|&' not supported
PATH:
H:\programs\sedawk\Gtk>echo %PATH%
h:\compiler\sedawk\bin;G:\Program Files\GnuWin32\bin;G:\GTK-server;G:
\Program Files\GTK2-Runtime\lib; G:\Program Files\GTK2-Runtime\bin;G:
\GTK-SE~1\Modules\Genric;G:\GTK-SE~1\Modules\Scriptbasic;c:\windows
\system32
Any advice !!! Thanks for help
| |
|
|
| Ted Davis 2008-02-16, 10:01 pm |
| On Sat, 16 Feb 2008 05:30:24 -0800, happytoday wrote:
> Here is the path of the GTK-server and the example in the site with that
> error :
> H:\programs\sedawk\Gtk>gawk -f test.awk gawk: test.awk:13: fatal: `|&' not
> supported
<snip>
>
> Any advice !!! Thanks for help
There are several features of gawk that work only under *ix because other
operating systems don't support them. You found one.
There are two things you can do:
A) find another way to handle the task, perhaps using a transient file
B) run the program on a real Unix/Linux machine (not Cygwin - it's still
limited by the underlying OS.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
| |
| Kees Nuyt 2008-02-16, 10:01 pm |
| On Sat, 16 Feb 2008 10:55:43 -0600, Ted Davis
<tdavis@umr.edu> wrote:
>On Sat, 16 Feb 2008 05:30:24 -0800, happytoday wrote:
><snip>
>
>There are several features of gawk that work only under *ix because other
>operating systems don't support them. You found one.
>
>There are two things you can do:
> A) find another way to handle the task, perhaps using a transient file
> B) run the program on a real Unix/Linux machine (not Cygwin - it's still
>limited by the underlying OS.
Yes, it's hard to find a gawk with 2way pipes for
MSWindows, but there is a cygwin gawk version that does.
It is called gawki.exe :
$ gawki --version
GNU Awk 3.1.1
Copyright (C) 1989, 1991-2002 Free Software Foundation.
It also supports 2way pipes to TCP / UDP ports.
Just for fun, here is the core of an awk script for gawki
that implements a webserver ("Lakota"):
===
dtsvcstart = strftime("%Y-%m-%d %H:%M:%S")
LakotaVersion = "2.2"
RC["200"] = "Ok"
RC["203"] = "Not found"
Listen = 80
httpd = "/inet/tcp/" Listen "/0/0"
printf("%s Lakota started\n",dtsvcstart)
headers = \
"HTTP/1.1 %s %s" ORS \
"Server: Lakota/" LakotaVersion ORS \
"Connection: close" ORS \
"Cache-control: no-cache, no-store" ORS \
"MIME-version: 1.0" ORS \
"Content-type: text/html" ORS
KeepRunning = (1 == 1) # true
while (KeepRunning){
print strftime("%Y-%m-%d %H:%M:%S Listen ") Listen
while ((httpd |& getline) > 0){
request = $0
# strip all control chars (0x0D 0x0A leftovers etc.)
gsub(/[[:cntrl:]]+/,"",request)
# strip leading whitespace
gsub(/^[[:blank:]]+/,"",request)
# strip trailing whitespace
gsub(/[[:blank:]]+$/,"",request)
if (request ~ /^GET /){
datetime = strftime("%Y-%m-%d %H:%M:%S")
URL = \
substr(request,5,index(request," HTTP/") - 5)
# getpage() :
# - reads the page from disk
# - handles invalid URLs and similar errors
# - if needed, generates an errorpage
# - sets status to 200 or 203,
# - may also change KeepRunning
#
html = getpage(URL)
contlen = length(html)
} # GET, other request headers are ignored
# empty line is end of request,
# so it's time to respond
if ($0 ~ /^[[:cntrl:][:blank:]]*$/){
printf("%s %s URL:%s:",datetime,status,URL)
printf(headers,status,RC[status]) |& httpd
printf("Content-Length: %d%s%s",\
contlen,ORS,ORS) |& httpd
printf("%s",html) |& httpd
break
}
}
printf("\n")
fflush("") # flush ALL output buffers
close(httpd) # keep-alive not honored
} # while (KeepRunning)
===
I use it as an "emergency" webserver, when apache is down
for maintenance.
--
( Kees
)
c[_] If cleanliness is next to godliness then your desk
must be an atheist. (G horoscopes) (#354)
| |
| happytoday 2008-02-16, 10:01 pm |
| On Feb 16, 9:18=A0pm, Kees Nuyt <k.n...@nospam.demon.nl> wrote:
> On Sat, 16 Feb 2008 10:55:43 -0600, Ted Davis
>
>
>
>
>
> <tda...@umr.edu> wrote:
t[color=darkred]
not[color=darkred]
>
>
[color=darkred]
>
[color=darkred]
>
> Yes, it's hard to find a gawk with 2way pipes for
> MSWindows, but there is a cygwin gawk version that does.
>
> It is called gawki.exe :
> $ gawki --version
> GNU Awk 3.1.1
> Copyright (C) 1989, 1991-2002 Free Software Foundation.
>
> It also supports 2way pipes to TCP / UDP ports.
>
> Just for fun, here is the core of an awk script for gawki
> that implements a webserver ("Lakota"):
>
> =3D=3D=3D
> =A0 =A0 =A0 =A0 dtsvcstart =A0 =A0=3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0 =A0 =A0 LakotaVersion =3D "2.2"
>
> =A0 =A0 =A0 =A0 RC["200"] =3D "Ok"
> =A0 =A0 =A0 =A0 RC["203"] =3D "Not found"
> =A0 =A0 =A0 =A0 Listen =A0 =A0=3D 80
> =A0 =A0 =A0 =A0 httpd =A0 =A0 =3D "/inet/tcp/" Listen "/0/0"
> =A0 =A0 =A0 =A0 printf("%s Lakota started\n",dtsvcstart)
> =A0 =A0 =A0 =A0 headers =3D \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "HTTP/1.1 %s %s" ORS \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Server: Lakota/" LakotaVersion ORS \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Connection: close" ORS \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Cache-control: no-cache, no-store" ORS \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "MIME-version: 1.0" ORS \
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Content-type: text/html" ORS
>
> =A0 =A0 =A0 =A0 KeepRunning =3D (1 =3D=3D 1) # true
> =A0 =A0 =A0 =A0 while (KeepRunning){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print strftime("%Y-%m-%d %H:%M:%S Listen "=
) Listen
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 while ((httpd |& getline) > 0){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 request =3D $0
> # strip all control chars (0x0D 0x0A leftovers etc.)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gsub(/[[:cntrl:]]+/,"",req=
uest) =A0 =A0 =A0
> # strip leading =A0whitespace
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gsub(/^[[:blank:]]+/,"",re=
quest) =A0 =A0 =A0
> # strip trailing whitespace
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gsub(/[[:blank:]]+$/,"",re=
quest)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (request ~ /^GET /){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 datetime =
=3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 URL =3D \
> substr(request,5,index(request," HTTP/") - 5)
>
> # getpage() :
> # - =A0reads the page from disk
> # - =A0handles invalid URLs and similar errors
> # - =A0if needed, generates an errorpage
> # - =A0sets status to 200 or 203,
> # - =A0may also change KeepRunning
> #
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 html =3D g=
etpage(URL)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 contlen =
=3D length(html)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } # GET, other request hea=
ders are ignored
>
> # empty line is end of request,
> # so it's time to respond
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ($0 ~ /^[[:cntrl:][:bla=
nk:]]*$/){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("%s=
%s URL:%s:",datetime,status,URL)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(hea=
ders,status,RC[status]) =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("Co=
ntent-Length: %d%s%s",\
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 contlen,ORS,ORS) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("%s=
",html) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("\n")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fflush("") =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0# flush ALL output buffers
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 close(httpd) =A0 =A0 =A0 =A0 =A0 =A0# keep=
-alive not honored
> =A0 =A0 =A0 =A0 } # while (KeepRunning)
> =3D=3D=3D
>
> I use it as an "emergency" webserver, when apache is down
> for maintenance.
> --
> =A0( =A0Kees
> =A0 )
> c[_] If cleanliness is next to godliness then your desk
> =A0 =A0 =A0must be an atheist. (G horoscopes) =A0(#354)- Hide quoted te=
xt -
>
> - Show quoted text -
If you run this script under windows . What are the step did you take
to run them under windows ?
| |
| Kees Nuyt 2008-02-16, 10:01 pm |
| On Sat, 16 Feb 2008 13:31:17 -0800 (PST), happytoday <ehabaziz2001@gmail.com> wrote:
>On Feb 16, 9:18_pm, Kees Nuyt <k.n...@nospam.demon.nl> wrote:
[snip code]
[color=darkred]
[color=darkred]
>If you run this script under windows . What are the step did
>you take to run them under windows ?
Some zealots consider that off-topic in comp.lang.awk,
but I'll bite the bullet for the sake of awk promotion ;)
The code in my previous article is just the core.
Here is some more code.
It sure isn't the prettiest awk code around,
but it's legible and it works for me.
All stuff below assumes a directory tree like:
dir (files)
------------ ----------------------
%serverroot% (lakota.cmd, lakota.awk)
bin (
2002-10-16 23:00 240.640 gawki.exe
2003-08-09 23:00 37.888 cygintl-2.dll
2004-07-05 23:00 1.015.128 cygiconv-2.dll
2005-07-02 23:00 1.295.582 cygwin1.dll )
conf (lakota.conf)
htdocs (index.html server*.html ....)
logs
Scripts:
- lakota.cmd
start script
- conf/lakota.conf
Contains server parameters, like DocumentRoot etc.
- lakota.awk
The server itself, basically:
BEGIN{
init
serverloop
exit 0
}
function getpage(){
} and a few more functions.
getpage supports a few Server Side Includes (SSI)
The SSI substitution is a little ugly :-)
- htdocs/index.html
- htdocs/server-status.html
- htdocs/server-stop.html
(Of course I use something else than **some_magic**)
Notes:
All .html pages should conform w3c XHTML 1.0 Strict
This post has extra long line length, but
some lines may still be wrapped by usenet
========
lakota.cmd
========
if not exist logs mkdir logs
pushd logs
for %%v in (request.log) do if exist %%v del %%v
popd
bin\gawki.exe "{gsub(/\t/,\" \");gsub(/**the_magic**/,\"**some_magic**\");print}" lakota.awk >htdocs\lakota.awk
bin\gawki.exe -f conf/httpd.conf -f lakota.awk
type lakota.hit
sleep 5
:Z
========
conf/httpd.conf
========
#
## Lakota configuration file
## syntax is awk
#
BEGIN{
Listen = 80
DocumentRoot = "htdocs"
DirectoryIndex = "index.html"
CustomLog = "logs/access.log"
ErrorLog = "logs/error.log"
RequestLog = "logs/request.log"
ServerAdmin = "webmaster@your.domain.invalid"
}
========
lakota.awk
========
#
# %ServerRoot%/lakota.awk Microscopic Webserver
# uses gawki.exe (gnu awk with IP protocol extensions)
#
# Copyright (C) 2007,2008 by Kees Nuyt
#
# version history:
# [snipped]
#
#% is for debugging
#
BEGIN{
dtsvcstart = strftime("%Y-%m-%d %H:%M:%S")
LakotaVersion = "2.2"
fSetHit = "lakota.hit"
RS = "\x0D"
ORS = "\x0D\x0A"
if (!Listen) Listen = 80
if (!DocumentRoot) DocumentRoot = "htdocs"
if (!DirectoryIndex) DirectoryIndex = "index.html"
if (!CustomLog) CustomLog = "logs/access.log"
if (!ErrorLog) ErrorLog = "logs/error.log"
if (!RequestLog) RequestLog = "logs/request.log"
if (!ServerAdmin) ServerAdmin = "webmaster@sub.domain.invalid"
doctype = \
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ORS ORS
hits = 0
if ((getline <fSetHit) >0){ # LakotaSessionsHitsBytes
sessions = $1 + 1
hits = $2 + 0
servedbytes = $3 + 0
}
close(fSetHit)
RC["200"] = "Ok"
RC["203"] = "Not found"
httpd = "/inet/tcp/" Listen "/0/0"
printf("%s Lakota started\n",dtsvcstart)
printf("%s Lakota started\n",dtsvcstart) >>CustomLog
printf("%s port:%s; RS:%s; ORS:%s;\n",dtsvcstart,Listen,RS,ORS) >>CustomLog
headers = \
"HTTP/1.1 %s %s" ORS \
"Server: Lakota/" LakotaVersion ORS \
"Set-Cookie: salutation=\"Lakota Webserver Says Hello\"; Max-Age=\"3600\"; Version=\"1\"" ORS \
"Set-Cookie: onbehalfof=\"" ServerAdmin "\"; Max-Age=\"3600\"; Version=\"1\"" ORS \
"Connection: close" ORS \
"Cache-control: no-cache, no-store" ORS \
"MIME-version: 1.0" ORS \
"Content-type: text/html" ORS
KeepRunning = (1 == 1) # true
while (KeepRunning){
print strftime("%Y-%m-%d %H:%M:%S Listen ") Listen
rqlines = 0
while ((httpd |& getline) > 0){
request = $0
gsub(/[[:cntrl:]]+/,"",request) # strip all control chars (0x0D 0x0A leftovers etc.)
gsub(/^[[:blank:]]+/,"",request) # strip leading whitespace
gsub(/[[:blank:]]+$/,"",request) # strip trailing whitespace
if (request ~ /^GET /){
delete rq # gawk specific
datetime = strftime("%Y-%m-%d %H:%M:%S")
URL = substr(request,5,index(request," HTTP/") - 5)
html = getpage(URL) # sets status 200 or 203, may also change KeepRunning
contlen = length(html)
loghit(URL,hits,status,contlen)
} else if ((pc = index(request,":")) > 2){ # eval request header, hit counts
hdrnm = substr(request,1,pc - 1) # header name
hdrvl = substr(request,pc + 1) # header values
rq[hdrnm] = hdrvl # for later use in pagebuilder
if (hdrnm in hit_hnm){
hit_hnm[hdrnm]++
} else {
hit_hnm[hdrnm] = 1
}
if ((hdrnm,hdrvl) in hit_hnm_hvl){
hit_hnm_hvl[hdrnm,hdrvl]++
} else {
hit_hnm_hvl[hdrnm,hdrvl] = 1
}
}
printf("%s#%05d#%03d %s\n",datetime,hits,++rqlines,request) >>RequestLog
if ($0 ~ /^[[:cntrl:][:blank:]]*$/){ # empty line is end of request
printf("%s %s URL:%s:",datetime,status,URL)
printf(headers,status,RC[status]) |& httpd
printf("Content-Length: %d%s%s",\
contlen,ORS,ORS) |& httpd
printf("%s",html) |& httpd
break
}
}
printf("-- \n") >>RequestLog
printf("\n")
fflush("") # flush ALL output buffers
close(httpd) # keep-alive not honored
printf( "%d %d %d LakotaSessionsHitsBytes\n",sessions,hits,servedbytes) >fSetHit
close(fSetHit)
}
datetime = strftime("%Y-%m-%d %H:%M:%S")
print datetime " stopped"
print datetime " Lakota stopped" >>CustomLog
print getstat() >>CustomLog
close(CustomLog)
close(RequestLog)
exit 0
}
#
##
#
function loghit(_URL,_hits,_stat,_len){
printf("%s %05d %s %5d %s\n",datetime,_hits,_stat,_len,_URL) >>CustomLog
if (!(_stat in resp)){
resp[_stat] = 0
fstresp[_stat] = datetime
}
resp[_stat]++
lstresp[_stat] = datetime
if (!(_URL in hit)){
hit[_URL] = 0
fsthit[_URL] = datetime
}
hit[_URL]++
lsthit[_URL] = datetime
hits++
servedbytes += _len
}
#
##
#
function getstat( _resp,_hits,_idx,_idy){
_resp = ""
for (_idx in resp){
_resp = _resp \
sprintf("<tr><td>%s </td><td align=\"right\">%d </td><td>%s </td><td>%s </td></tr>",\
_idx,resp[_idx],fstresp[_idx],lstresp[_i
dx])
}
_hits = ""
for (_idx in hit){
_hits = _hits \
sprintf("<tr><td>%s </td><td align=\"right\">%d </td><td>%s </td><td>%s </td></tr>",\
_idx,hit[_idx],fsthit[_idx],lsthit[_idx]
)
}
_hdrs = ""
for (_idx in hit_hnm){
for (_idy in hit_hnm_hvl){
split (_idy,tmp,SUBSEP)
#% print _idy "\n"
if (tmp[1] == _idx){
_hdrs = _hdrs \
sprintf("<tr><td>%s </td><td align=\"right\">%d </td><td>%s </td></tr>",\
_idx,hit_hnm_hvl[_idy],tmp[2])
}
}
}
return \
"<table border=\"1\" summary=\" URL statistics\"><tr><th>URL</th><th>hits</th><th>first</th><th>last</th></tr>"\
_hits "</table><br />" ORS \
"<table border=\"1\" summary=\"Response
statistics\"><tr><th>response</th><th>hits</th><th>first</th><th>last</th></tr>"\
_resp "</table><br />" ORS \
"<table border=\"1\" summary=\"Header statistics\"><tr><th>header</th><th>hits</th><th>value</th></tr>"\
_hdrs "</table><br />" ORS
}
#
##
#
function getpage( _fHTML,_html,_lines,_line){
_fHTML = URL
sub(/^\//,"",_fHTML)
if (_fHTML == ""){
_fHTML = DirectoryIndex
URL = "/" _fHTML
}
_fHTML = DocumentRoot "/" _fHTML
_lines = 0
while (_lines < 1){
_html = ""
#% printf("read:%s:",_fHTML)
ext = tolower(substr(_fHTML,length(_fHTML)-3,4))
while ((getline _line <_fHTML) >0){
_lines++
_html = _html _line ORS
}
close(_fHTML)
if (_lines < 1){
_html = "<html><head><title>Not found</title></head>" ORS \
"<body><h1>Page " URL " not found on the server.</h1>" ORS \
"<p><a href=\"/index.html\">back home</a> "\
"<a href=\"mailto:<!--#server_admin -->\">info</a></p>" ORS \
"</body></html>"
_lines = 2
status = "203"
} else {
status = "200"
}
}
if ((ext == "html") || (status != "200")){ # substitutions
while (match(_html, /<!--#[^->]*-->/)){ # SSI format <!--#expression -->
rawexp = substr(_html,RSTART, RLENGTH)
#% print "%%%" rawexp "%%%"
express = tolower(substr(_html,RSTART + 5, RLENGTH - 8))
gsub(/[[:blank:]]+/," ",express) # multiple spaces to single, tabs to space
gsub(/^[[:blank:]]+/,"",express) # strip leading whitespace
gsub(/[[:blank:]]+$/,"",express) # strip trailing whitespace
if (express == "server_status"){
gsub(rawexp,getstat(),_html)
} else if (express == "**some_magic**"){
KeepRunning = (1 == 0) # false
print datetime " Stop command processed."
gsub(rawexp,"Stop command processed.",_html)
} else if (express == "server_start"){
gsub(rawexp,dtsvcstart,_html)
} else if (express == "server_version"){
gsub(rawexp,LakotaVersion,_html)
} else if (express == "server_admin"){
gsub(rawexp,ServerAdmin,_html)
} else if (express == "current_time"){
gsub(rawexp,datetime,_html)
} else if (express == "hit_count"){
gsub(rawexp,sprintf("%05d",hits + 1),_html)
} else if (express == "url"){
gsub(rawexp,URL,_html)
} else {
gsub(rawexp,"Unknow SSI expression: " express,_html)
}
}
} else {
#% printf("add tags:")
gsub(/^&/,"\\&",_html) # replace ampersand with ampersand a m p semicolon
gsub(/</,"\\<",_html) # replace less with ampersand l t semicolon
gsub(/>/,"\\>",_html) # replace greater with ampersand g t semicolon
_html = "<html>" ORS \
"<head><title>" _fHTML \
"</title></head>" ORS \
"<body>" ORS \
"<p><a href=\"/index.html\">home</a> <a href=\"mailto:<!--#server_admin -->\">info</a></p>" ORS \
"<pre>" _html "</pre></body></html>"
}
return doctype _html
}
========
htdocs/index.html
========
<html>
<head>
<title>Lakota webserver</title>
</head>
<body>
<h1>I'm sorry,</h1>
<h2>the website is unavailable</h2>
<p>This is a <a title="Lakota is a microscopic webserver implemented in GNU awk. Click to show the source."
href="lakota.awk">Lakota</a> smoke signal to tell you that<br />
<b>Apache is down for maintenance</b> since <small><!--#server_start --></small>.</p>
<p><small><a href="mailto:<!--#server_admin -->">info</a></small></p>
<p>
<small>
<!--#current_time -->
<span style="color: yellow; background-color: black; font-weight: bold">
<!--#hit_count -->
</span> (<!--#url --> )
</small>
</p>
</body>
</html>
========
htdocs/server-status.html
========
<html>
<head>
<title>Lakota v<!--#server_version --> webserver</title>
</head>
<body>
<h1>Lakota v<!--#server_version --> webserver status</h1>
<a href="/index.html">home</a> <a href="/server-stop.html">stop</a>
<div><!--#server_status --></div>
<p>
<small>Running <!--#server_start --> thru <!--#current_time -->
<span style="color: yellow; background-color: black; font-weight: bold">
<!--#hit_count -->
</span> (<!--#url --> )
</small>
</p>
</body>
</html>
========
htdocs/server-stop.html
========
<html>
<head>
<title>Lakota webserver terminating</title>
</head>
<body>
<h1><a title="Lakota is a microscopic webserver implemented in GNU awk"
href="mailto:<!--#server_admin -->">LAKOTA</a>will terminate.</h1>
<div><!--#server_status --></div>
<div><!--#**some_magic** --></div>
<p><small><!--#server_start --></small></p>
<p><small><!--#current_time --> <span style="color: yellow; background-color: black; font-weight:
bold"><!--#hit_count --></span> (<!--#url --> )</small></p>
</body>
</html>
==================
Well, there it is. Good luck cutting 'n pasting.
I'm not sure the pages validate :D
--
( Kees
)
c[_] Oliver's Law: Experience is something you don't get until just after you need it. (#514)
| |
| Jürgen Kahrs 2008-02-17, 7:58 am |
| Reply-To: Juergen.KahrsDELETETHIS@vr-web.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: individual.net UFMifaImveWiMgVXGGc8tw+L05PuRT0tHXxNORFa
YYxrUZq4Y=
Cancel-Lock: sha1:ODP3VsH9aZUqBcqfmNr6eaD0/DA=
User-Agent: Thunderbird 2.0.0.9 (X11/20070801)
In-Reply-To: < bimer3hmsndphp579iecmb375g9jejnein@dim53
.demon.nl>
Bytes: 1614
Xref: number1.nntp.dca.giganews.com comp.lang.awk:39416
Kees Nuyt wrote:
> Some zealots consider that off-topic in comp.lang.awk,
> but I'll bite the bullet for the sake of awk promotion ;)
This is interesting. I dont think this is off-topic.
The majority of what you posted is still written in
the AWK language.
| |
| Kees Nuyt 2008-02-17, 9:58 pm |
| On Sun, 17 Feb 2008 11:20:42 +0100, Jürgen Kahrs <Juergen.KahrsDELETETHIS@vr-web.de> wrote:
>Kees Nuyt wrote:
>
>
>This is interesting. I dont think this is off-topic.
>The majority of what you posted is still written in
>the AWK language.
Thanks for the encouragement!
--
( Kees
)
c[_] Can you grow birds by planting birdseed? (#299)
| |
| happytoday 2008-02-17, 9:58 pm |
| On Feb 17, 1:18=A0am, Kees Nuyt <k.n...@nospam.demon.nl> wrote:
> On Sat, 16 Feb 2008 13:31:17 -0800 (PST), happytoday <ehabaziz2...@gmail.c=
om> wrote:
>
>
>
>
>
>
>
> [snip code]
>
>
>
> Some zealots consider that off-topic in comp.lang.awk,
> but I'll bite the bullet for the sake of awk promotion ;)
>
> The code in my previous article is just the core.
> Here is some more code.
> It sure isn't the prettiest awk code around,
> but it's legible and it works for me.
>
> All stuff below assumes a directory tree like:
> dir =A0 =A0 =A0 =A0 =A0 (files)
> ------------ =A0----------------------
> %serverroot% =A0(lakota.cmd, lakota.awk)
> =A0 =A0 =A0 =A0 bin =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2002-10-16 23:00 =A0 =A024=
0.640 gawki.exe
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2003-08-09 23:00 =A0 =A0 3=
7.888 cygintl-2.dll
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2004-07-05 23:00 =A01.015.=
128 cygiconv-2.dll
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2005-07-02 23:00 =A01.295.=
582 cygwin1.dll )
> =A0 =A0 =A0 =A0 conf =A0 =A0 =A0 (lakota.conf)
> =A0 =A0 =A0 =A0 htdocs =A0 =A0 (index.html server*.html ....)
> =A0 =A0 =A0 =A0 logs
>
> Scripts:
> - lakota.cmd
> =A0 =A0 =A0 =A0 start script
> - conf/lakota.conf
> =A0 =A0 =A0 =A0 Contains server parameters, like DocumentRoot etc.
> - lakota.awk
> =A0 =A0 =A0 =A0 The server itself, basically:
> =A0 =A0 =A0 =A0 BEGIN{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 init
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 serverloop
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit 0
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 function getpage(){
> =A0 =A0 =A0 =A0 } and a few more functions.
> =A0 =A0 =A0 =A0 getpage supports a few Server Side Includes (SSI)
> =A0 =A0 =A0 =A0 The SSI substitution is a little ugly :-)
>
> - htdocs/index.html
> - htdocs/server-status.html
> - htdocs/server-stop.html
> =A0 =A0 =A0 =A0 (Of course I use something else than **some_magic**)
>
> Notes:
> =A0 =A0 =A0 =A0 All .html pages should conform w3c XHTML 1.0 Strict
> =A0 =A0 =A0 =A0 This post has extra long line length, but
> =A0 =A0some lines may still be wrapped by usenet
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> lakota.cmd
> =3D=3D=3D=3D=3D=3D=3D=3D
> =A0 =A0 =A0 =A0 if not exist logs mkdir logs
> =A0 =A0 =A0 =A0 pushd logs
> =A0 =A0 =A0 =A0 for %%v in (request.log) do if exist %%v del %%v
> =A0 =A0 =A0 =A0 popd
> =A0 =A0 =A0 =A0 bin\gawki.exe "{gsub(/\t/,\" =A0 \");gsub(/**the_magic**/,=
\"**some_magic**\");print}" lakota.awk >htdocs\lakota.awk
> =A0 =A0 =A0 =A0 bin\gawki.exe -f conf/httpd.conf -f lakota.awk
> =A0 =A0 =A0 =A0 type lakota.hit
> =A0 =A0 =A0 =A0 sleep 5
> :Z
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> conf/httpd.conf
> =3D=3D=3D=3D=3D=3D=3D=3D
> #
> ## Lakota configuration file
> ## syntax is awk
> #
> BEGIN{
> =A0 =A0 =A0 =A0 Listen =A0 =A0 =A0 =A0 =A0=3D 80
> =A0 =A0 =A0 =A0 DocumentRoot =A0 =A0=3D "htdocs"
> =A0 =A0 =A0 =A0 DirectoryIndex =A0=3D "index.html"
> =A0 =A0 =A0 =A0 CustomLog =A0 =A0 =A0 =3D "logs/access.log"
> =A0 =A0 =A0 =A0 ErrorLog =A0 =A0 =A0 =A0=3D "logs/error.log"
> =A0 =A0 =A0 =A0 RequestLog =A0 =A0 =A0=3D "logs/request.log"
> =A0 =A0 =A0 =A0 ServerAdmin =A0 =A0 =3D "webmas...@your.domain.invalid"
>
> }
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> lakota.awk
> =3D=3D=3D=3D=3D=3D=3D=3D
> #
> # %ServerRoot%/lakota.awk Microscopic Webserver
> # uses gawki.exe (gnu awk with IP protocol extensions)
> #
> # Copyright (C) 2007,2008 by Kees Nuyt
> #
> # version history:
> # [snipped]
> #
> #% is for debugging
> #
> BEGIN{
> =A0 =A0dtsvcstart =A0 =A0=3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0LakotaVersion =3D "2.2"
> =A0 =A0fSetHit =A0 =A0 =A0 =3D "lakota.hit"
> =A0 =A0RS =A0=3D "\x0D"
> =A0 =A0ORS =3D "\x0D\x0A"
> =A0 =A0if (!Listen) =A0 =A0 =A0 =A0 Listen =A0 =A0 =A0 =A0 =A0=3D 80
> =A0 =A0if (!DocumentRoot) =A0 DocumentRoot =A0 =A0=3D "htdocs"
> =A0 =A0if (!DirectoryIndex) DirectoryIndex =A0=3D "index.html"
> =A0 =A0if (!CustomLog) =A0 =A0 =A0CustomLog =A0 =A0 =A0 =3D "logs/access.l=
og"
> =A0 =A0if (!ErrorLog) =A0 =A0 =A0 ErrorLog =A0 =A0 =A0 =A0=3D "logs/error.=
log"
> =A0 =A0if (!RequestLog) =A0 =A0 RequestLog =A0 =A0 =A0=3D "logs/request.lo=
g"
> =A0 =A0if (!ServerAdmin) =A0 =A0ServerAdmin =A0 =A0 =3D "webmas...@sub.dom=
ain.invalid"
> =A0 =A0doctype =A0 =A0 =A0=3D \
> "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ORS ORS
> =A0 =A0hits =A0 =A0 =A0 =A0 =3D 0
> =A0 =A0if ((getline <fSetHit) >0){ # LakotaSessionsHitsBytes
> =A0 =A0 =A0 sessions =A0 =A0=3D $1 + 1
> =A0 =A0 =A0 hits =A0 =A0 =A0 =A0=3D $2 + 0
> =A0 =A0 =A0 servedbytes =3D $3 + 0
> =A0 =A0}
> =A0 =A0close(fSetHit)
> =A0 =A0RC["200"] =A0 =A0=3D "Ok"
> =A0 =A0RC["203"] =A0 =A0=3D "Not found"
> =A0 =A0httpd =A0 =A0 =A0 =A0=3D "/inet/tcp/" Listen "/0/0"
> =A0 =A0printf("%s Lakota started\n",dtsvcstart)
> =A0 =A0printf("%s Lakota started\n",dtsvcstart) >>CustomLog
> =A0 =A0printf("%s port:%s; RS:%s; ORS:%s;\n",dtsvcstart,Listen,RS,ORS) >>C=
ustomLog
> =A0 =A0headers =3D \
> =A0 =A0 =A0 "HTTP/1.1 %s %s" ORS \
> =A0 =A0 =A0 "Server: Lakota/" LakotaVersion ORS \
> =A0 =A0 =A0 "Set-Cookie: salutation=3D\"Lakota Webserver Says Hello\"; Max=
-Age=3D\"3600\"; Version=3D\"1\"" ORS \
> =A0 =A0 =A0 "Set-Cookie: onbehalfof=3D\"" ServerAdmin "\"; Max-Age=3D\"360=
0\"; Version=3D\"1\"" ORS \
> =A0 =A0 =A0 "Connection: close" ORS \
> =A0 =A0 =A0 "Cache-control: no-cache, no-store" ORS \
> =A0 =A0 =A0 "MIME-version: 1.0" ORS \
> =A0 =A0 =A0 "Content-type: text/html" ORS
> =A0 =A0KeepRunning =3D (1 =3D=3D 1) # true
> =A0 =A0while (KeepRunning){
> =A0 =A0 =A0 print strftime("%Y-%m-%d %H:%M:%S Listen ") Listen
> =A0 =A0 =A0 rqlines =3D 0
> =A0 =A0 =A0 while ((httpd |& getline) > 0){
> =A0 =A0 =A0 =A0 =A0request =3D $0
> =A0 =A0 =A0 =A0 =A0gsub(/[[:cntrl:]]+/,"",request) =A0 # strip all control=
chars (0x0D 0x0A leftovers etc.)
> =A0 =A0 =A0 =A0 =A0gsub(/^[[:blank:]]+/,"",request) =A0 # strip leading =
=A0whitespace
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+$/,"",request) =A0 # strip trailing w=
hitespace
> =A0 =A0 =A0 =A0 =A0if (request ~ /^GET /){
> =A0 =A0 =A0 =A0 =A0 =A0 delete rq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 # gawk specific
> =A0 =A0 =A0 =A0 =A0 =A0 datetime =3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0 =A0 =A0 =A0 =A0 URL =3D substr(request,5,index(request," HTTP/") -=
5)
> =A0 =A0 =A0 =A0 =A0 =A0 html =3D getpage(URL) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0# sets status 200 or 203, may also change KeepRunning
> =A0 =A0 =A0 =A0 =A0 =A0 contlen =3D length(html)
> =A0 =A0 =A0 =A0 =A0 =A0 loghit(URL,hits,status,contlen)
> =A0 =A0 =A0 =A0 =A0} else if ((pc =3D index(request,":")) > 2){ =A0 # eval=
request header, hit counts
> =A0 =A0 =A0 =A0 =A0 =A0 hdrnm =3D substr(request,1,pc - 1) =A0 =A0 =A0 =A0=
=A0# header name
> =A0 =A0 =A0 =A0 =A0 =A0 hdrvl =3D substr(request,pc + 1) =A0 =A0 =A0 =A0 =
=A0 =A0# header values
> =A0 =A0 =A0 =A0 =A0 =A0 rq[hdrnm] =3D hdrvl =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 # for later use =A0in pagebuilder
> =A0 =A0 =A0 =A0 =A0 =A0 if (hdrnm in hit_hnm){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm[hdrnm]++
> =A0 =A0 =A0 =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm[hdrnm] =3D 1
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 if ((hdrnm,hdrvl) in hit_hnm_hvl){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm_hvl[hdrnm,hdrvl]++
> =A0 =A0 =A0 =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm_hvl[hdrnm,hdrvl] =3D 1
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0printf("%s#%05d#%03d %s\n",datetime,hits,++rqlines,requ=
est) >>RequestLog
> =A0 =A0 =A0 =A0 =A0if ($0 ~ /^[[:cntrl:][:blank:]]*$/){ =A0 # empty line i=
s end of request
> =A0 =A0 =A0 =A0 =A0 =A0 printf("%s %s URL:%s:",datetime,status,URL)
> =A0 =A0 =A0 =A0 =A0 =A0 printf(headers,status,RC[status]) =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 printf("Content-Length: %d%s%s",\
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0contlen,ORS,ORS) =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 printf("%s",html) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 break
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0 =A0 printf("-- \n") >>RequestLog
> =A0 =A0 =A0 printf("\n")
> =A0 =A0 =A0 fflush("") =A0 =A0 =A0 =A0 # flush ALL output buffers
> =A0 =A0 =A0 close(httpd) =A0 =A0 =A0# keep-alive not honored
> =A0 =A0 =A0 printf( "%d %d %d LakotaSessionsHitsBytes\n",sessions,hits,ser=
vedbytes) >fSetHit
> =A0 =A0 =A0 close(fSetHit)
> =A0 =A0}
> =A0 =A0datetime =3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0print datetime " stopped"
> =A0 =A0print datetime " Lakota stopped" >>CustomLog
> =A0 =A0print getstat() >>CustomLog
> =A0 =A0close(CustomLog)
> =A0 =A0close(RequestLog)
> =A0 =A0exit 0}
>
> #
> ##
> #
> function loghit(_URL,_hits,_stat,_len){
> =A0 =A0printf("%s %05d %s %5d %s\n",datetime,_hits,_stat,_len,_URL) >>Cust=
omLog
> =A0 =A0if (!(_stat in resp)){
> =A0 =A0 =A0 resp[_stat] =3D 0
> =A0 =A0 =A0 fstresp[_stat] =3D datetime
> =A0 =A0}
> =A0 =A0resp[_stat]++
> =A0 =A0lstresp[_stat] =3D datetime
>
> =A0 =A0if (!(_URL in hit)){
> =A0 =A0 =A0 hit[_URL] =3D 0
> =A0 =A0 =A0 fsthit[_URL] =3D datetime
> =A0 =A0}
> =A0 =A0hit[_URL]++
> =A0 =A0lsthit[_URL] =3D datetime
>
> =A0 =A0hits++
> =A0 =A0servedbytes +=3D _len}
>
> #
> ##
> #
> function getstat( =A0 _resp,_hits,_idx,_idy){
> =A0 =A0_resp =3D ""
> =A0 =A0for (_idx in resp){
> =A0 =A0 =A0 _resp =3D _resp \
> =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d </td><td>%s =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0_idx,resp[_idx],fstresp[_idx],lstresp
[_idx])
> =A0 =A0}
> =A0 =A0_hits =3D ""
> =A0 =A0for (_idx in hit){
> =A0 =A0 =A0 _hits =3D _hits \
> =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d </td><td>%s =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0_idx,hit[_idx],fsthit[_idx],lsthit[_i
dx])
> =A0 =A0}
> =A0 =A0_hdrs =3D ""
> =A0 =A0for (_idx in hit_hnm){
> =A0 =A0 =A0 for (_idy in hit_hnm_hvl){
> =A0 =A0 =A0 =A0 =A0split (_idy,tmp,SUBSEP)
> #% =A0 =A0 =A0 =A0 print _idy "\n"
> =A0 =A0 =A0 =A0 =A0if (tmp[1] =3D=3D _idx){
> =A0 =A0 =A0 =A0 =A0 =A0 _hdrs =3D _hdrs \
> =A0 =A0 =A0 =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_idx,hit_hnm_hvl[_idy],tmp[2])
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0}
> =A0 =A0return \
> "<table border=3D\"1\" summary=3D\" URL statistics\"><tr><th>URL</th><th>h=
its</th><th>first</th><th>last</th></tr>"=AD\
> _hits "</table><br />" ORS \
> "<table border=3D\"1\" summary=3D\"Response
> statistics\"><tr><th>response</th><th>hits</th><th>first</th><th>last</th>=
<=AD/tr>"\
> _resp "</table><br />" ORS \
> "<table border=3D\"1\" summary=3D\"Header statistics\"><tr><th>header</th>=
<th>hits</th><th>value</th></tr>"\
> _hdrs "</table><br />" ORS}
>
> #
> ##
> #
> function getpage( =A0_fHTML,_html,_lines,_line){
> =A0 =A0_fHTML =3D URL
> =A0 =A0sub(/^\//,"",_fHTML)
> =A0 =A0if (_fHTML =3D=3D ""){
> =A0 =A0 =A0 _fHTML =3D DirectoryIndex
> =A0 =A0 =A0 URL =A0 =3D "/" _fHTML
> =A0 =A0}
> =A0 =A0_fHTML =3D DocumentRoot "/" _fHTML
> =A0 =A0_lines =3D 0
> =A0 =A0while (_lines < 1){
> =A0 =A0 =A0 _html =A0=3D ""
> #% =A0 =A0 =A0printf("read:%s:",_fHTML)
> =A0 =A0 =A0 ext =3D tolower(substr(_fHTML,length(_fHTML)-3,4))
> =A0 =A0 =A0 while ((getline _line <_fHTML) >0){
> =A0 =A0 =A0 =A0 =A0_lines++
> =A0 =A0 =A0 =A0 =A0_html =3D _html _line ORS
> =A0 =A0 =A0 }
> =A0 =A0 =A0 close(_fHTML)
> =A0 =A0 =A0 if (_lines =A0< 1){
> =A0 =A0 =A0 =A0 =A0_html =3D "<html><head><title>Not found</title></head>"=
ORS \
> "<body><h1>Page " URL " not found on the server.</h1>" ORS \
> "<p><a href=3D\"/index.html\">back home</a> "\
> "<a href=3D\"mailto:<!--#server_admin -->\">info</a></p>" ORS \
> "</body></html>"
> =A0 =A0 =A0 =A0 =A0_lines =3D 2
> =A0 =A0 =A0 =A0 =A0status =3D "203"
> =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0status =3D "200"
> =A0 =A0 =A0 }
> =A0 =A0}
> =A0 =A0if ((ext =3D=3D "html") || (status !=3D "200")){ =A0 =A0 =A0 =A0 # =
substitutions
> =A0 =A0 =A0 while (match(_html, /<!--#[^->]*-->/)){ =A0 =A0 =A0 =A0 # SSI =
format =A0<!--#expression -->
> =A0 =A0 =A0 =A0 =A0rawexp =A0=3D substr(_html,RSTART, RLENGTH)
> #% =A0 =A0 =A0 =A0 print "%%%" rawexp "%%%"
> =A0 =A0 =A0 =A0 =A0express =3D tolower(substr(_html,RSTART + 5, RLENGTH - =
8))
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+/," ",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # multiple spaces to single, tabs to space
> =A0 =A0 =A0 =A0 =A0gsub(/^[[:blank:]]+/,"",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # strip leading whitespace
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+$/,"",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # strip trailing whitespace
> =A0 =A0 =A0 =A0 =A0if =A0 =A0 =A0 =A0(express =3D=3D "server_status"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,getstat(),_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "**some_magic**"){
> =A0 =A0 =A0 =A0 =A0 =A0 KeepRunning =3D (1 =3D=3D 0) =A0 # false
> =A0 =A0 =A0 =A0 =A0 =A0 print datetime " Stop command processed."
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,"Stop command processed.",_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_start"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,dtsvcstart,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_version"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,LakotaVersion,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_admin"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,ServerAdmin,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "current_time"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,datetime,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "hit_count"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,sprintf("%05d",hits + 1),_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "url"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,URL,_html)
> =A0 =A0 =A0 =A0 =A0} else {
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,"Unknow SSI expression: " express,_htm=
l)
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0} else {
> #% =A0 =A0 =A0printf("add tags:")
> =A0 =A0 =A0 gsub(/^&/,"\\&",_html) =A0# replace ampersand with ampersa=
nd a m p semicolon
> =A0 =A0 =A0 gsub(/</,"\\<",_html) =A0 =A0# replace =A0 less =A0 =A0with=
ampersand l t semicolon
> =A0 =A0 =A0 gsub(/>/,"\\>",_html) =A0 =A0# replace =A0greater =A0with a=
mpersand g t semicolon
> =A0 =A0 =A0 _html =3D "<html>" ORS \
> "<head><title>" _fHTML \
> "</title></head>" ORS \
> "<body>" ORS \
> "<p><a href=3D\"/index.html\">home</a> <a href=3D\"mailto:<!--#=
server_admin -->\">info</a></p>" ORS \
> "<pre>" _html "</pre></body></html>"
> =A0 =A0}
> =A0 =A0return doctype _html
>
> }
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/index.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota webserver</title>
> =A0</head>
> =A0<body>
> =A0 <h1>I'm sorry,</h1>
> =A0 <h2>the website is unavailable</h2>
> =A0 <p>This is a <a title=3D"Lakota is a microscopic webserver implemented=
in GNU awk. Click to show the source."
> =A0href=3D"lakota.awk">Lakota</a> smoke signal to tell you that<br />
> =A0 <b>Apache is down for maintenance</b> since <small><!--#server_start -=
-></small>.</p>
> =A0 <p><small><a href=3D"mailto:<!--#server_admin -->">info</a></small></p=
>
> =A0 <p>
> =A0 =A0<small>
> =A0 =A0 <!--#current_time -->
> =A0 =A0 <span style=3D"color: yellow; background-color: black; font-weight=
: bold">
> =A0 =A0 =A0<!--#hit_count -->
> =A0 =A0 </span> (<!--#url --> )
> =A0 =A0</small>
> =A0 </p>
> =A0</body>
> </html>
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/server-status.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota v<!--#server_version --> webserver</title>
> =A0</head>
> =A0<body>
> =A0 <h1>Lakota v<!--#server_version --> webserver status</h1>
> =A0 =A0<a href=3D"/index.html">home</a> <a href=3D"/server-stop.html"=
>stop</a>
> =A0 =A0<div><!--#server_status --></div>
> =A0 <p>
> =A0 =A0<small>Running <!--#server_start --> thru <!--#current_time --> =A0=
> =A0 =A0 <span style=3D"color: yellow; background-color: black; font-weight=
: bold">
> =A0 =A0 =A0<!--#hit_count -->
> =A0 =A0 </span> (<!--#url --> )
> =A0 =A0</small>
> =A0 </p>
> =A0</body>
> </html>
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/server-stop.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota webserver terminating</title>
> =A0</head>
> =A0<body>
> =A0 <h1><a title=3D"Lakota is a microscopic webserver implemented in GNU a=
wk"
> =A0href=3D"mailto:<!--#server_admin -->">LAKOTA</a>will terminate.</h1>
> =A0 =A0<div><!--#server_status --></div>
> =A0 =A0<div><!--#**some_magic** --></div>
> =A0 <p><small><!--#server_start --></small></p>
> =A0 <p><small><!--#current_time --> =A0<span style=3D"color: yellow; backg=
round-color: black; font-weight:
> bold"><!--#hit_count --></span> (<!--#url --> )</small></p>
> =A0</body>
> </html>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D
>
> Well, there it is. Good luck cutting 'n pasting.
> I'm not sure the pages validate :D
> --
> =A0( =A0Kees
> =A0 )
> c[_] Oliver's Law: Experience is something you don't get until just after =
you need it. =A0(#514)
I may seem little stupid but I searched internet gawki.exe I did not
find it at all . Please sepcify applications needed to be downloaded
and their download URL.
Thanks
| |
| Kenny McCormack 2008-02-17, 9:58 pm |
| In article <84d155ab-ffae-435c-a4df-1d072250cdaf@n75g2000hsh.googlegroups.com>,
happytoday <ehabaziz2001@gmail.com> wrote:
....
>I may seem little stupid but I searched internet gawki.exe I did not
>find it at all . Please sepcify applications needed to be downloaded
>and their download URL.
>Thanks
I suggest you d/l Cygwin gcc, and compile it yourself.
It's not that hard.
| |
|
|
| happytoday 2008-02-17, 9:58 pm |
| On Feb 17, 7:32=A0pm, J=FCrgen Kahrs <Juergen.KahrsDELETET...@vr-web.de>
wrote:
> happytoday wrote:
>
> This should do what you need:
>
> =A0http://usuarios.arsystel.com/wzrlpy/xgawk/
> =A0http://usuarios.arsystel.com/wzrlpy/xgawk/xgawk.exe.gz
Is xgawk.exe the same as gawki.exe ? Thanks
| |
| Juergen Kahrs 2008-02-18, 4:17 am |
| happytoday wrote:
> On Feb 17, 7:32 pm, Jürgen Kahrs <Juergen.KahrsDELETET...@vr-web.de>
> wrote:
>
> Is xgawk.exe the same as gawki.exe ? Thanks
No, not exactly. gawki is an abbreviation that I
have never seen before. igawk is part of the official
GNU Awk distribution (a wrapper script aroung gawk).
xgawk is the name of a distribution that is built on
top of GNU Awk, but contains some extensions.
| |
| Ted Davis 2008-02-18, 6:59 pm |
| On Sun, 17 Feb 2008 13:40:53 -0800, happytoday wrote:
>
> Is xgawk.exe the same as gawki.exe ? Thanks
No, xgawk is a version of gawk extended and optimized for processing files
in XML and it's subsets such as HTML; Gawki is a city in Poland. igawk is
a shell script wrapper for gawk that adds include file capability.
igawk.bat and igawk.cmd for Windows don't work.
--
T.E.D. (tdavis@mst.edu)
| |
| Kees Nuyt 2008-02-18, 6:59 pm |
| On Sun, 17 Feb 2008 13:40:53 -0800 (PST), happytoday
<ehabaziz2001@gmail.com> wrote:
>On Feb 17, 7:32_pm, Jürgen Kahrs <Juergen.KahrsDELETET...@vr-web.de>
>wrote:
>
>Is xgawk.exe the same as gawki.exe ? Thanks
It is entirely possible that I renamed that specific
cygwin version of gawk.exe to gawki.exe myself, in
order to distinguish it from a lean-and-mean basic gawk
without 2way pipes.
Sorry for the confusion.
If you can't find it, I made a zip file with the
program and the bare minimum of cygwin .dll's available
for download:
http://www.knuyt.demon.nl/dl/gawki.zip
(it will be there until 2008-02-25)
--
( Kees
)
c[_] Dyslexics of the World, Untie! (#457)
| |
| happytoday 2008-02-18, 6:59 pm |
| On Feb 17, 1:18=A0am, Kees Nuyt <k.n...@nospam.demon.nl> wrote:
> On Sat, 16 Feb 2008 13:31:17 -0800 (PST), happytoday <ehabaziz2...@gmail.c=
om> wrote:
>
>
>
>
>
>
>
> [snip code]
>
>
>
> Some zealots consider that off-topic in comp.lang.awk,
> but I'll bite the bullet for the sake of awk promotion ;)
>
> The code in my previous article is just the core.
> Here is some more code.
> It sure isn't the prettiest awk code around,
> but it's legible and it works for me.
>
> All stuff below assumes a directory tree like:
> dir =A0 =A0 =A0 =A0 =A0 (files)
> ------------ =A0----------------------
> %serverroot% =A0(lakota.cmd, lakota.awk)
> =A0 =A0 =A0 =A0 bin =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2002-10-16 23:00 =A0 =A024=
0.640 gawki.exe
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2003-08-09 23:00 =A0 =A0 3=
7.888 cygintl-2.dll
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2004-07-05 23:00 =A01.015.=
128 cygiconv-2.dll
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2005-07-02 23:00 =A01.295.=
582 cygwin1.dll )
> =A0 =A0 =A0 =A0 conf =A0 =A0 =A0 (lakota.conf)
> =A0 =A0 =A0 =A0 htdocs =A0 =A0 (index.html server*.html ....)
> =A0 =A0 =A0 =A0 logs
>
> Scripts:
> - lakota.cmd
> =A0 =A0 =A0 =A0 start script
> - conf/lakota.conf
> =A0 =A0 =A0 =A0 Contains server parameters, like DocumentRoot etc.
> - lakota.awk
> =A0 =A0 =A0 =A0 The server itself, basically:
> =A0 =A0 =A0 =A0 BEGIN{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 init
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 serverloop
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit 0
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 function getpage(){
> =A0 =A0 =A0 =A0 } and a few more functions.
> =A0 =A0 =A0 =A0 getpage supports a few Server Side Includes (SSI)
> =A0 =A0 =A0 =A0 The SSI substitution is a little ugly :-)
>
> - htdocs/index.html
> - htdocs/server-status.html
> - htdocs/server-stop.html
> =A0 =A0 =A0 =A0 (Of course I use something else than **some_magic**)
>
> Notes:
> =A0 =A0 =A0 =A0 All .html pages should conform w3c XHTML 1.0 Strict
> =A0 =A0 =A0 =A0 This post has extra long line length, but
> =A0 =A0some lines may still be wrapped by usenet
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> lakota.cmd
> =3D=3D=3D=3D=3D=3D=3D=3D
> =A0 =A0 =A0 =A0 if not exist logs mkdir logs
> =A0 =A0 =A0 =A0 pushd logs
> =A0 =A0 =A0 =A0 for %%v in (request.log) do if exist %%v del %%v
> =A0 =A0 =A0 =A0 popd
> =A0 =A0 =A0 =A0 bin\gawki.exe "{gsub(/\t/,\" =A0 \");gsub(/**the_magic**/,=
\"**some_magic**\");print}" lakota.awk >htdocs\lakota.awk
> =A0 =A0 =A0 =A0 bin\gawki.exe -f conf/httpd.conf -f lakota.awk
> =A0 =A0 =A0 =A0 type lakota.hit
> =A0 =A0 =A0 =A0 sleep 5
> :Z
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> conf/httpd.conf
> =3D=3D=3D=3D=3D=3D=3D=3D
> #
> ## Lakota configuration file
> ## syntax is awk
> #
> BEGIN{
> =A0 =A0 =A0 =A0 Listen =A0 =A0 =A0 =A0 =A0=3D 80
> =A0 =A0 =A0 =A0 DocumentRoot =A0 =A0=3D "htdocs"
> =A0 =A0 =A0 =A0 DirectoryIndex =A0=3D "index.html"
> =A0 =A0 =A0 =A0 CustomLog =A0 =A0 =A0 =3D "logs/access.log"
> =A0 =A0 =A0 =A0 ErrorLog =A0 =A0 =A0 =A0=3D "logs/error.log"
> =A0 =A0 =A0 =A0 RequestLog =A0 =A0 =A0=3D "logs/request.log"
> =A0 =A0 =A0 =A0 ServerAdmin =A0 =A0 =3D "webmas...@your.domain.invalid"
>
> }
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> lakota.awk
> =3D=3D=3D=3D=3D=3D=3D=3D
> #
> # %ServerRoot%/lakota.awk Microscopic Webserver
> # uses gawki.exe (gnu awk with IP protocol extensions)
> #
> # Copyright (C) 2007,2008 by Kees Nuyt
> #
> # version history:
> # [snipped]
> #
> #% is for debugging
> #
> BEGIN{
> =A0 =A0dtsvcstart =A0 =A0=3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0LakotaVersion =3D "2.2"
> =A0 =A0fSetHit =A0 =A0 =A0 =3D "lakota.hit"
> =A0 =A0RS =A0=3D "\x0D"
> =A0 =A0ORS =3D "\x0D\x0A"
> =A0 =A0if (!Listen) =A0 =A0 =A0 =A0 Listen =A0 =A0 =A0 =A0 =A0=3D 80
> =A0 =A0if (!DocumentRoot) =A0 DocumentRoot =A0 =A0=3D "htdocs"
> =A0 =A0if (!DirectoryIndex) DirectoryIndex =A0=3D "index.html"
> =A0 =A0if (!CustomLog) =A0 =A0 =A0CustomLog =A0 =A0 =A0 =3D "logs/access.l=
og"
> =A0 =A0if (!ErrorLog) =A0 =A0 =A0 ErrorLog =A0 =A0 =A0 =A0=3D "logs/error.=
log"
> =A0 =A0if (!RequestLog) =A0 =A0 RequestLog =A0 =A0 =A0=3D "logs/request.lo=
g"
> =A0 =A0if (!ServerAdmin) =A0 =A0ServerAdmin =A0 =A0 =3D "webmas...@sub.dom=
ain.invalid"
> =A0 =A0doctype =A0 =A0 =A0=3D \
> "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ORS ORS
> =A0 =A0hits =A0 =A0 =A0 =A0 =3D 0
> =A0 =A0if ((getline <fSetHit) >0){ # LakotaSessionsHitsBytes
> =A0 =A0 =A0 sessions =A0 =A0=3D $1 + 1
> =A0 =A0 =A0 hits =A0 =A0 =A0 =A0=3D $2 + 0
> =A0 =A0 =A0 servedbytes =3D $3 + 0
> =A0 =A0}
> =A0 =A0close(fSetHit)
> =A0 =A0RC["200"] =A0 =A0=3D "Ok"
> =A0 =A0RC["203"] =A0 =A0=3D "Not found"
> =A0 =A0httpd =A0 =A0 =A0 =A0=3D "/inet/tcp/" Listen "/0/0"
> =A0 =A0printf("%s Lakota started\n",dtsvcstart)
> =A0 =A0printf("%s Lakota started\n",dtsvcstart) >>CustomLog
> =A0 =A0printf("%s port:%s; RS:%s; ORS:%s;\n",dtsvcstart,Listen,RS,ORS) >>C=
ustomLog
> =A0 =A0headers =3D \
> =A0 =A0 =A0 "HTTP/1.1 %s %s" ORS \
> =A0 =A0 =A0 "Server: Lakota/" LakotaVersion ORS \
> =A0 =A0 =A0 "Set-Cookie: salutation=3D\"Lakota Webserver Says Hello\"; Max=
-Age=3D\"3600\"; Version=3D\"1\"" ORS \
> =A0 =A0 =A0 "Set-Cookie: onbehalfof=3D\"" ServerAdmin "\"; Max-Age=3D\"360=
0\"; Version=3D\"1\"" ORS \
> =A0 =A0 =A0 "Connection: close" ORS \
> =A0 =A0 =A0 "Cache-control: no-cache, no-store" ORS \
> =A0 =A0 =A0 "MIME-version: 1.0" ORS \
> =A0 =A0 =A0 "Content-type: text/html" ORS
> =A0 =A0KeepRunning =3D (1 =3D=3D 1) # true
> =A0 =A0while (KeepRunning){
> =A0 =A0 =A0 print strftime("%Y-%m-%d %H:%M:%S Listen ") Listen
> =A0 =A0 =A0 rqlines =3D 0
> =A0 =A0 =A0 while ((httpd |& getline) > 0){
> =A0 =A0 =A0 =A0 =A0request =3D $0
> =A0 =A0 =A0 =A0 =A0gsub(/[[:cntrl:]]+/,"",request) =A0 # strip all control=
chars (0x0D 0x0A leftovers etc.)
> =A0 =A0 =A0 =A0 =A0gsub(/^[[:blank:]]+/,"",request) =A0 # strip leading =
=A0whitespace
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+$/,"",request) =A0 # strip trailing w=
hitespace
> =A0 =A0 =A0 =A0 =A0if (request ~ /^GET /){
> =A0 =A0 =A0 =A0 =A0 =A0 delete rq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 # gawk specific
> =A0 =A0 =A0 =A0 =A0 =A0 datetime =3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0 =A0 =A0 =A0 =A0 URL =3D substr(request,5,index(request," HTTP/") -=
5)
> =A0 =A0 =A0 =A0 =A0 =A0 html =3D getpage(URL) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0# sets status 200 or 203, may also change KeepRunning
> =A0 =A0 =A0 =A0 =A0 =A0 contlen =3D length(html)
> =A0 =A0 =A0 =A0 =A0 =A0 loghit(URL,hits,status,contlen)
> =A0 =A0 =A0 =A0 =A0} else if ((pc =3D index(request,":")) > 2){ =A0 # eval=
request header, hit counts
> =A0 =A0 =A0 =A0 =A0 =A0 hdrnm =3D substr(request,1,pc - 1) =A0 =A0 =A0 =A0=
=A0# header name
> =A0 =A0 =A0 =A0 =A0 =A0 hdrvl =3D substr(request,pc + 1) =A0 =A0 =A0 =A0 =
=A0 =A0# header values
> =A0 =A0 =A0 =A0 =A0 =A0 rq[hdrnm] =3D hdrvl =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 # for later use =A0in pagebuilder
> =A0 =A0 =A0 =A0 =A0 =A0 if (hdrnm in hit_hnm){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm[hdrnm]++
> =A0 =A0 =A0 =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm[hdrnm] =3D 1
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 if ((hdrnm,hdrvl) in hit_hnm_hvl){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm_hvl[hdrnm,hdrvl]++
> =A0 =A0 =A0 =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hit_hnm_hvl[hdrnm,hdrvl] =3D 1
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0printf("%s#%05d#%03d %s\n",datetime,hits,++rqlines,requ=
est) >>RequestLog
> =A0 =A0 =A0 =A0 =A0if ($0 ~ /^[[:cntrl:][:blank:]]*$/){ =A0 # empty line i=
s end of request
> =A0 =A0 =A0 =A0 =A0 =A0 printf("%s %s URL:%s:",datetime,status,URL)
> =A0 =A0 =A0 =A0 =A0 =A0 printf(headers,status,RC[status]) =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 printf("Content-Length: %d%s%s",\
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0contlen,ORS,ORS) =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 printf("%s",html) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 |& httpd
> =A0 =A0 =A0 =A0 =A0 =A0 break
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0 =A0 printf("-- \n") >>RequestLog
> =A0 =A0 =A0 printf("\n")
> =A0 =A0 =A0 fflush("") =A0 =A0 =A0 =A0 # flush ALL output buffers
> =A0 =A0 =A0 close(httpd) =A0 =A0 =A0# keep-alive not honored
> =A0 =A0 =A0 printf( "%d %d %d LakotaSessionsHitsBytes\n",sessions,hits,ser=
vedbytes) >fSetHit
> =A0 =A0 =A0 close(fSetHit)
> =A0 =A0}
> =A0 =A0datetime =3D strftime("%Y-%m-%d %H:%M:%S")
> =A0 =A0print datetime " stopped"
> =A0 =A0print datetime " Lakota stopped" >>CustomLog
> =A0 =A0print getstat() >>CustomLog
> =A0 =A0close(CustomLog)
> =A0 =A0close(RequestLog)
> =A0 =A0exit 0}
>
> #
> ##
> #
> function loghit(_URL,_hits,_stat,_len){
> =A0 =A0printf("%s %05d %s %5d %s\n",datetime,_hits,_stat,_len,_URL) >>Cust=
omLog
> =A0 =A0if (!(_stat in resp)){
> =A0 =A0 =A0 resp[_stat] =3D 0
> =A0 =A0 =A0 fstresp[_stat] =3D datetime
> =A0 =A0}
> =A0 =A0resp[_stat]++
> =A0 =A0lstresp[_stat] =3D datetime
>
> =A0 =A0if (!(_URL in hit)){
> =A0 =A0 =A0 hit[_URL] =3D 0
> =A0 =A0 =A0 fsthit[_URL] =3D datetime
> =A0 =A0}
> =A0 =A0hit[_URL]++
> =A0 =A0lsthit[_URL] =3D datetime
>
> =A0 =A0hits++
> =A0 =A0servedbytes +=3D _len}
>
> #
> ##
> #
> function getstat( =A0 _resp,_hits,_idx,_idy){
> =A0 =A0_resp =3D ""
> =A0 =A0for (_idx in resp){
> =A0 =A0 =A0 _resp =3D _resp \
> =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d </td><td>%s =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0_idx,resp[_idx],fstresp[_idx],lstresp
[_idx])
> =A0 =A0}
> =A0 =A0_hits =3D ""
> =A0 =A0for (_idx in hit){
> =A0 =A0 =A0 _hits =3D _hits \
> =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d </td><td>%s =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0_idx,hit[_idx],fsthit[_idx],lsthit[_i
dx])
> =A0 =A0}
> =A0 =A0_hdrs =3D ""
> =A0 =A0for (_idx in hit_hnm){
> =A0 =A0 =A0 for (_idy in hit_hnm_hvl){
> =A0 =A0 =A0 =A0 =A0split (_idy,tmp,SUBSEP)
> #% =A0 =A0 =A0 =A0 print _idy "\n"
> =A0 =A0 =A0 =A0 =A0if (tmp[1] =3D=3D _idx){
> =A0 =A0 =A0 =A0 =A0 =A0 _hdrs =3D _hdrs \
> =A0 =A0 =A0 =A0 =A0 =A0 sprintf("<tr><td>%s </td><td align=3D\"right\">%d =
</td><td>%s </td></tr>",\
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_idx,hit_hnm_hvl[_idy],tmp[2])
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0}
> =A0 =A0return \
> "<table border=3D\"1\" summary=3D\" URL statistics\"><tr><th>URL</th><th>h=
its</th><th>first</th><th>last</th></tr>"=AD\
> _hits "</table><br />" ORS \
> "<table border=3D\"1\" summary=3D\"Response
> statistics\"><tr><th>response</th><th>hits</th><th>first</th><th>last</th>=
<=AD/tr>"\
> _resp "</table><br />" ORS \
> "<table border=3D\"1\" summary=3D\"Header statistics\"><tr><th>header</th>=
<th>hits</th><th>value</th></tr>"\
> _hdrs "</table><br />" ORS}
>
> #
> ##
> #
> function getpage( =A0_fHTML,_html,_lines,_line){
> =A0 =A0_fHTML =3D URL
> =A0 =A0sub(/^\//,"",_fHTML)
> =A0 =A0if (_fHTML =3D=3D ""){
> =A0 =A0 =A0 _fHTML =3D DirectoryIndex
> =A0 =A0 =A0 URL =A0 =3D "/" _fHTML
> =A0 =A0}
> =A0 =A0_fHTML =3D DocumentRoot "/" _fHTML
> =A0 =A0_lines =3D 0
> =A0 =A0while (_lines < 1){
> =A0 =A0 =A0 _html =A0=3D ""
> #% =A0 =A0 =A0printf("read:%s:",_fHTML)
> =A0 =A0 =A0 ext =3D tolower(substr(_fHTML,length(_fHTML)-3,4))
> =A0 =A0 =A0 while ((getline _line <_fHTML) >0){
> =A0 =A0 =A0 =A0 =A0_lines++
> =A0 =A0 =A0 =A0 =A0_html =3D _html _line ORS
> =A0 =A0 =A0 }
> =A0 =A0 =A0 close(_fHTML)
> =A0 =A0 =A0 if (_lines =A0< 1){
> =A0 =A0 =A0 =A0 =A0_html =3D "<html><head><title>Not found</title></head>"=
ORS \
> "<body><h1>Page " URL " not found on the server.</h1>" ORS \
> "<p><a href=3D\"/index.html\">back home</a> "\
> "<a href=3D\"mailto:<!--#server_admin -->\">info</a></p>" ORS \
> "</body></html>"
> =A0 =A0 =A0 =A0 =A0_lines =3D 2
> =A0 =A0 =A0 =A0 =A0status =3D "203"
> =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0status =3D "200"
> =A0 =A0 =A0 }
> =A0 =A0}
> =A0 =A0if ((ext =3D=3D "html") || (status !=3D "200")){ =A0 =A0 =A0 =A0 # =
substitutions
> =A0 =A0 =A0 while (match(_html, /<!--#[^->]*-->/)){ =A0 =A0 =A0 =A0 # SSI =
format =A0<!--#expression -->
> =A0 =A0 =A0 =A0 =A0rawexp =A0=3D substr(_html,RSTART, RLENGTH)
> #% =A0 =A0 =A0 =A0 print "%%%" rawexp "%%%"
> =A0 =A0 =A0 =A0 =A0express =3D tolower(substr(_html,RSTART + 5, RLENGTH - =
8))
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+/," ",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # multiple spaces to single, tabs to space
> =A0 =A0 =A0 =A0 =A0gsub(/^[[:blank:]]+/,"",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # strip leading whitespace
> =A0 =A0 =A0 =A0 =A0gsub(/[[:blank:]]+$/,"",express) =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # strip trailing whitespace
> =A0 =A0 =A0 =A0 =A0if =A0 =A0 =A0 =A0(express =3D=3D "server_status"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,getstat(),_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "**some_magic**"){
> =A0 =A0 =A0 =A0 =A0 =A0 KeepRunning =3D (1 =3D=3D 0) =A0 # false
> =A0 =A0 =A0 =A0 =A0 =A0 print datetime " Stop command processed."
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,"Stop command processed.",_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_start"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,dtsvcstart,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_version"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,LakotaVersion,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "server_admin"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,ServerAdmin,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "current_time"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,datetime,_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "hit_count"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,sprintf("%05d",hits + 1),_html)
> =A0 =A0 =A0 =A0 =A0} else if (express =3D=3D "url"){
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,URL,_html)
> =A0 =A0 =A0 =A0 =A0} else {
> =A0 =A0 =A0 =A0 =A0 =A0 gsub(rawexp,"Unknow SSI expression: " express,_htm=
l)
> =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 }
> =A0 =A0} else {
> #% =A0 =A0 =A0printf("add tags:")
> =A0 =A0 =A0 gsub(/^&/,"\\&",_html) =A0# replace ampersand with ampersa=
nd a m p semicolon
> =A0 =A0 =A0 gsub(/</,"\\<",_html) =A0 =A0# replace =A0 less =A0 =A0with=
ampersand l t semicolon
> =A0 =A0 =A0 gsub(/>/,"\\>",_html) =A0 =A0# replace =A0greater =A0with a=
mpersand g t semicolon
> =A0 =A0 =A0 _html =3D "<html>" ORS \
> "<head><title>" _fHTML \
> "</title></head>" ORS \
> "<body>" ORS \
> "<p><a href=3D\"/index.html\">home</a> <a href=3D\"mailto:<!--#=
server_admin -->\">info</a></p>" ORS \
> "<pre>" _html "</pre></body></html>"
> =A0 =A0}
> =A0 =A0return doctype _html
>
> }
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/index.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota webserver</title>
> =A0</head>
> =A0<body>
> =A0 <h1>I'm sorry,</h1>
> =A0 <h2>the website is unavailable</h2>
> =A0 <p>This is a <a title=3D"Lakota is a microscopic webserver implemented=
in GNU awk. Click to show the source."
> =A0href=3D"lakota.awk">Lakota</a> smoke signal to tell you that<br />
> =A0 <b>Apache is down for maintenance</b> since <small><!--#server_start -=
-></small>.</p>
> =A0 <p><small><a href=3D"mailto:<!--#server_admin -->">info</a></small></p=
>
> =A0 <p>
> =A0 =A0<small>
> =A0 =A0 <!--#current_time -->
> =A0 =A0 <span style=3D"color: yellow; background-color: black; font-weight=
: bold">
> =A0 =A0 =A0<!--#hit_count -->
> =A0 =A0 </span> (<!--#url --> )
> =A0 =A0</small>
> =A0 </p>
> =A0</body>
> </html>
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/server-status.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota v<!--#server_version --> webserver</title>
> =A0</head>
> =A0<body>
> =A0 <h1>Lakota v<!--#server_version --> webserver status</h1>
> =A0 =A0<a href=3D"/index.html">home</a> <a href=3D"/server-stop.html"=
>stop</a>
> =A0 =A0<div><!--#server_status --></div>
> =A0 <p>
> =A0 =A0<small>Running <!--#server_start --> thru <!--#current_time --> =A0=
> =A0 =A0 <span style=3D"color: yellow; background-color: black; font-weight=
: bold">
> =A0 =A0 =A0<!--#hit_count -->
> =A0 =A0 </span> (<!--#url --> )
> =A0 =A0</small>
> =A0 </p>
> =A0</body>
> </html>
>
> =3D=3D=3D=3D=3D=3D=3D=3D
> htdocs/server-stop.html
> =3D=3D=3D=3D=3D=3D=3D=3D
> <html>
> =A0<head>
> =A0 <title>Lakota webserver terminating</title>
> =A0</head>
> =A0<body>
> =A0 <h1><a title=3D"Lakota is a microscopic webserver implemented in GNU a=
wk"
> =A0href=3D"mailto:<!--#server_admin -->">LAKOTA</a>will terminate.</h1>
> =A0 =A0<div><!--#server_status --></div>
> =A0 =A0<div><!--#**some_magic** --></div>
> =A0 <p><small><!--#server_start --></small></p>
> =A0 <p><small><!--#current_time --> =A0<span style=3D"color: yellow; backg=
round-color: black; font-weight:
> bold">< | | |