|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
graphics with c piping to postscript
Hello.
I'm interested to have graphic output using c code, but without a graphic library for c (es cairo). The idea is to use only printf to obtain, in stdout, commands in postscript language. Examples of postscript commands are Code:
0 0 moveto 100 100 rlineto stroke I'm not able to set the right pipe sintax in the shell command. This is the code of the c program. Code:
#include<stdio.h> int main(){ char c; int i; for (i=0; i<10; i++){ printf("%d %d %s\n",0,5*i,"moveto"); printf("%d %d %s\n",100,0,"rlineto"); printf("%s\n","stroke"); scanf("%c",&c); } } The scanf line is useful to obtain pauses between one line and the next. Supposing the code is compiled in a.out, the following two commands work: Code:
$ ./a.out >output-file $ gs output-file But I'm not able to pipe and to see a line after each "enter". The "enter"s are needed (due to scanf) and wanted to obtain a graphic that proceeds step by step. I tried ./a.out | gs - but didn't work. I tried also with a fifo, but it didn't work. I'm not sure to have been able to explain the problem. Is there anybody iterested that can suggest me the correct piping command in order to see a line drawed after each "enter"? |
|
|||
When you pipe a.out into gs, a.out sends all it's output to gs and stops running. I don't think you can pipe one line at a time.
When I use C, I use it in a combination with Lua language, because Lua is written as a C library and work perfectly together with C. Lua is designed to work with large amount of text and data and can be embedded in C and C++ programs. With Lua you would have os.execute() to call gs after each line. Free Lua book from Lua's author: https://www.lua.org/pil/contents.html |
|
|||
Thank you bsdun.
You are right, a.out writes all his output and, then, all the output is piped. I tested it with something like this Code:
$ ./a.out |cat > /dev/pts/2 Also with a fifo the behaviour is the same: On terminal window A Code:
$ mkfifo xxx $ ./a.out > xxx Code:
$ cat xxx Does this depend on a bufferization of the output? If yes, is it possible to eliminate bufferization? Thank you also for the interesting reference to LUA. I don't know it at all. I will read something about. |
|
|||
Maybe idOp.
Anyway, when one uses gs in interactive mode Code:
$ gs So gs would seem to have different behaviours according to wher the input comes from. Effectively, I have tried Code:
gs - Does this mean that gs waits for the command list to finish before executing them, or can stdin be bufferized too? Boh (italian expression to say "I don't know"). Thank you idOp |
|
||||
Quote:
Quote:
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
PDF/Postscript -> print filter -> Print Queue Filter | shep | Programming | 6 | 24th December 2018 03:33 PM |
building graphics/imlib2? | spiderpig | OpenBSD Packages and Ports | 1 | 26th January 2015 04:09 AM |
2D Graphics acceleration in X | virtuvoos | OpenBSD General | 10 | 18th October 2013 02:40 PM |
Intel graphics | tolstoi | NetBSD General | 5 | 20th February 2013 08:10 AM |
nwn failed to initialize graphics | maxrussell | FreeBSD General | 8 | 22nd November 2008 08:52 PM |