* Re: C-code : printing into a buffer
@ 2009-05-29 7:49 A. Soare
0 siblings, 0 replies; 6+ messages in thread
From: A. Soare @ 2009-05-29 7:49 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Emacs Dev [emacs-devel]
>
> "A. Soare" <alinsoar@voila.fr> writes:
>
> > My problem is to define a buffer in emacs such that in the moment when I call this function via a pointer, all its output to be discarged in that buffer, not in the terminal of emacs.
> >
> > Is that possible? Any ideas of how to solve it?
>
> Use sprintf instead.
>
No, printf is just an example. I want to do something such that the output from _all_ the functions of libc be redirected to a buffer of emacs, not just printf. Saying, temporary to define the terminal of emacs as a buffer of emacs.
Al.in
____________________________________________________
Découvrez le nouveau Voila.fr et apprenez à maîtriser le web 2.0 sur http://voila.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C-code : printing into a buffer
@ 2009-05-29 9:13 A. Soare
2009-06-01 1:57 ` Stephen J. Turnbull
2009-06-01 14:31 ` Stefan Monnier
0 siblings, 2 replies; 6+ messages in thread
From: A. Soare @ 2009-05-29 9:13 UTC (permalink / raw)
To: Stephen J. Turnbull; +Cc: Emacs Dev [emacs-devel]
IStreams, as far as I see, create a pipe, such that the lisp functions inside are redirected to a new-created stream. But the lisp functions print messages via a lisp function like (message), and this function know the pipe where to print.
If you call printf from the C-level of the emacs-lisp evaluator, printf does not know nothing about lisp level. So the problem would be beyond the lisp evaluator. The problem is about the linux system... and from the lisp code to redirect the printf output temporary to an emacs buf.
The Istreams concept is also explained in SICP. Nothing unusual.
Alin.
>
> A. Soare writes:
>
> > > > My problem is to define a buffer in emacs such that in the
> > > > moment when I call this function via a pointer, all its output
> > > > to be discarged in that buffer, not in the terminal of emacs.
>
> In XEmacs you could do this fairly straightforwardly with an lstream,
> I think (an lstream is the internal XEmacs primitive used to deal with
> anything that can be thought of as a sequence of bytes or characters).
>
> I don't think Emacs has a corresponding facility. If not, and you
> really need this badly, feel free to ask at xemacs-beta@xemacs.org.
>
>
>
____________________________________________________
Découvrez le nouveau Voila.fr et apprenez à maîtriser le web 2.0 sur http://voila.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C-code : printing into a buffer
2009-05-29 9:13 A. Soare
@ 2009-06-01 1:57 ` Stephen J. Turnbull
2009-06-01 14:31 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Stephen J. Turnbull @ 2009-06-01 1:57 UTC (permalink / raw)
To: alinsoar; +Cc: Emacs Dev [emacs-devel]
A. Soare writes:
> IStreams, as far as I see, create a pipe, such that the lisp
> functions inside are redirected to a new-created stream. But the
> lisp functions print messages via a lisp function like (message),
> and this function know the pipe where to print.
That's "L for Lisp" lstreams, and it works both ways. You can also
attach an lstream to a file descriptor and take input from it. It
sounds to me like that's exactly what you want, because an
fd-to-buffer lstream will handle all the mechanics of updating the
buffer gap, converting external encoding to Mule internal, and so on.
You just need to set up the pipeline and specify the coding system.
I'm sure it's also possible in Emacs with sufficient mucking about.
However in XEmacs (and derivatives such as XEmacs/CHISE and SXEmacs)
it's a standard (though internal) feature.
> The Istreams concept is also explained in SICP. Nothing unusual.
*shrug* It's *your* problem, and if you're not willing to study
available methods more carefully than that, you've going to do a lot
of redundant work. Of course, if your goal is to contribute them to
Emacs, reinventing them is not redundant because XEmacs's lstreams
aren't paper-trained, so Emacs can't port them.
OTOH, if you're mostly interested in achieving a solution with a
minimal amount of work, you can grit your teeth and use S?XEmacs, and
have it today. In fact, if you use SXEmacs, you may be able to do it
all from Lisp using their standard FFI interface.
> > A. Soare writes:
> >
> > > > > My problem is to define a buffer in emacs such that in the
> > > > > moment when I call this function via a pointer, all its output
> > > > > to be discarged in that buffer, not in the terminal of emacs.
> >
> > In XEmacs you could do this fairly straightforwardly with an lstream,
> > I think (an lstream is the internal XEmacs primitive used to deal with
> > anything that can be thought of as a sequence of bytes or characters).
> >
> > I don't think Emacs has a corresponding facility. If not, and you
> > really need this badly, feel free to ask at xemacs-beta@xemacs.org.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C-code : printing into a buffer
2009-05-29 9:13 A. Soare
2009-06-01 1:57 ` Stephen J. Turnbull
@ 2009-06-01 14:31 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2009-06-01 14:31 UTC (permalink / raw)
To: alinsoar; +Cc: Stephen J. Turnbull, Emacs Dev [emacs-devel]
> If you call printf from the C-level of the emacs-lisp evaluator,
> printf does not know nothing about lisp level. So the problem would be
> beyond the lisp evaluator. The problem is about the linux
> system... and from the lisp code to redirect the printf output
> temporary to an emacs buf.
If you want to `printf' to a buffer, what I recommend is to use a trick like:
- create a dummy Emacs process (start-process "lstream" <buffer> "cat").
- fprintf (XPROCESS (proc)->outfd, "toto %d titi", ...);
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* C-code : printing into a buffer
@ 2009-05-29 6:43 A. Soare
2009-05-29 7:16 ` Andreas Schwab
0 siblings, 1 reply; 6+ messages in thread
From: A. Soare @ 2009-05-29 6:43 UTC (permalink / raw)
To: Emacs Dev [emacs-devel]
Hi,
I have the following problem:
Supposing that
1. I call dlsym for the funtion X="printf" from emacs. No need for dlopen, because I suppose that X always belongs to libc.
2. I get the ADDRESS of X ( for ex. printf ).
3. I call printf from that address using a pointer of the form
(* (some_cast to a pointer to that function) (ADDRESS)) (str, ...);
My problem is to define a buffer in emacs such that in the moment when I call this function via a pointer, all its output to be discarged in that buffer, not in the terminal of emacs.
Is that possible? Any ideas of how to solve it?
Thanks in advance.
Alin.
____________________________________________________
Découvrez le nouveau Voila.fr et apprenez à maîtriser le web 2.0 sur http://voila.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C-code : printing into a buffer
2009-05-29 6:43 A. Soare
@ 2009-05-29 7:16 ` Andreas Schwab
0 siblings, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2009-05-29 7:16 UTC (permalink / raw)
To: alinsoar; +Cc: Emacs Dev [emacs-devel]
"A. Soare" <alinsoar@voila.fr> writes:
> My problem is to define a buffer in emacs such that in the moment when I call this function via a pointer, all its output to be discarged in that buffer, not in the terminal of emacs.
>
> Is that possible? Any ideas of how to solve it?
Use sprintf instead.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-06-01 14:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-29 7:49 C-code : printing into a buffer A. Soare
-- strict thread matches above, loose matches on Subject: below --
2009-05-29 9:13 A. Soare
2009-06-01 1:57 ` Stephen J. Turnbull
2009-06-01 14:31 ` Stefan Monnier
2009-05-29 6:43 A. Soare
2009-05-29 7:16 ` Andreas Schwab
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).