help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: awk and graphics


From: david kerns
Subject: Re: awk and graphics
Date: Mon, 6 Nov 2023 00:51:07 -0700

missed a local x declaration in function:

function printcontent(f, out, cmd, x)

On Mon, Nov 6, 2023 at 12:44 AM david kerns <david.t.kerns@gmail.com> wrote:

> Here's a quick and *really* dirty version...it reads the same file over
> and over (reads a pbm even though the html asks for a png)
> run on Linux (with ImageMagick installed, for the convert app)
> then point your browser to localhost:8000
>
> $ ls
> pic.pbm
> picserver.awk
> $ cat picserver.awk
> function printcontent(f, out, cmd)
> {
>   sub("png", "pbm" f)
>   cmd = "convert " f " png:-" # assumes the convert app is available
>   while ((cmd | getline x) > 0) print x |& out
>   close(cmd)
> }
> BEGIN {
>   service = "/inet/tcp/8000/0/0";
>   d1 = "<html><head><meta http-equiv=\"refresh\"
> content=\"1\"></head><body><img src=\"pic.png\" /></body></html>"
>   h1 = "HTTP/1.1 200 OK\nContent-Type: text/html; charset=UTF-8\n"
>   h2 = "HTTP/1.1 200 OK\nContent-Type: image/png\n"
>   h3 = "HTTP/1.1 404 Not Found\nContent-Type: text/html; charset=UTF-8\n"
>   d3 = "<html><head><title>404 Not Found</title></head><body>file not
> found</body></html>"
>   while (1) {
>     service |& getline d
>     print d
>     if (d ~ "GET") {
>       n = split(d, a, " ");
>       if (a[2] == "/") {
>         print h1 |& service
>         print d1 |& service
>       } else if (a[2] == "/pic.png") { # we ask for png, but read a pbm
> and convert on the fly
>         print h2 |& service
>         printcontent(substr(a[2],2), service)
>       } else {
>         print h3 |& service
>         print d3 |& service
>       }
>     }
>     close(service)
>   }
> }
> $ gawk -f picserver.awk &
> $ firefox http://localhost:8000
>
>
> On Sun, Nov 5, 2023 at 10:23 PM Wolfgang Laun <wolfgang.laun@gmail.com>
> wrote:
>
>> Perhaps an interface from gawk to C code controlling the browser (cf.
>> Lib/webbrowser.py
>> <https://github.com/python/cpython/tree/3.12/Lib/webbrowser.py>) might
>> be less effort.
>>
>> Wolfgang
>>
>> On Sun, 5 Nov 2023 at 16:31, david kerns <david.t.kerns@gmail.com> wrote:
>>
>>> you could also make a web server from awk and serve it to a browser
>>>
>>> On Sun, Nov 5, 2023 at 7:59 AM Manuel Collado <mcollado2011@gmail.com>
>>> wrote:
>>>
>>> > El 5/11/23 a las 10:10, Miriam English escribió:
>>> > > Does anybody know some simple, fast, screen display extension that
>>> awk
>>> > > can use?
>>> > >
>>> > > I've been fiddling around with some of my old cellular automata
>>> > > programs and have translated them to a few languages, including awk.
>>> I
>>> > > haven't found any way to output graphics to the screen directly from
>>> > > awk, so I've made it write to a .pbm image file. The great advantage
>>> of
>>> > > this is that pbm is an ascii format, and easy to write to from awk.
>>> > > (I've attached a pbm file of a cellular automaton, and another
>>> converted
>>> > > to png in case you can't view pbm. It is an old format.)
>>> > > [...]
>>> > >
>>> > > Anybody know of something I can use?
>>> >
>>> > There are a lot of other textual source code for graphics, in addition
>>> > to .pbm. But it seems you want direct generation of images in the
>>> screen
>>> > instead of creating graphic files for later inspection.
>>> >
>>> > Perhaps a possible approach could be to pipe awk output to some
>>> > interpreter that draws the image on screen. For instance, you can pipe
>>> > awk output to a Tcl/Tk intepreter (tclsh/wish), and send commands for
>>> > creating and draw elements in a canvas widget.
>>> >
>>> > This way the screen image could be modified on the fly, I think.
>>> >
>>> > HTH.
>>> > --
>>> > Manuel Collado - http://mcollado.z15.es
>>> >
>>> >
>>>
>>
>>
>> --
>> Wolfgang Laun
>>
>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]