1 /* emacs-eval.c - send an s-expression to XEmacs for evaluation via ToolTalk */
3 /* See `tooltalk-eval-handler' in the file lisp/tooltalk/tooltalk-init.el for
6 #include <desktop/tt_c.h>
13 #define exit_err_ptr(ptr) \
14 if ((tter = tt_ptr_error(ptr)) != TT_OK) \
15 { fprintf(stderr, "%d:%s\n", __LINE__, tt_status_message(tter)); exit(1); }
17 #define exit_err(stat) \
18 if ((tter = stat) != TT_OK) \
19 { fprintf(stderr, "%d:%s\n", __LINE__, tt_status_message(tter)); exit(1); }
21 Tt_callback_action callback_fn(Tt_message msg, Tt_pattern pat);
22 static Tt_message create_new_message(char *s_expression);
23 static int initialize_tooltalk(void);
24 static void usage(void);
26 static char* tt_procid;
29 callback_fn(Tt_message msg, Tt_pattern pat)
31 tt_message_destroy(msg);
32 return TT_CALLBACK_PROCESSED;
36 create_new_message(char *s_expression)
40 msg = tt_message_create();
43 exit_err(tt_message_address_set (msg, TT_PROCEDURE));
44 exit_err(tt_message_class_set (msg, TT_REQUEST));
45 exit_err(tt_message_scope_set (msg, TT_SESSION));
46 exit_err(tt_message_op_set (msg, "emacs-eval"));
47 exit_err(tt_message_arg_add (msg, TT_IN, "string", s_expression));
48 exit_err(tt_message_callback_add(msg, callback_fn));
54 initialize_tooltalk(void) {
57 tt_procid = tt_open();
58 if ((rcode = tt_ptr_error(tt_procid)) != TT_OK) {
62 if ((rcode = tt_session_join(tt_default_session())) != TT_OK) {
72 "Usage: emacs-eval \"<s-expression>\"\n\n");
88 exit_err(initialize_tooltalk());
90 msg = create_new_message(argv[1]);
92 exit_err(tt_message_send(msg));