comparison src/tooltalk.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 8eaf7971accc
children 0e522484dd2a
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
39 39
40 #ifdef TT_DEBUG 40 #ifdef TT_DEBUG
41 static FILE *tooltalk_log_file; 41 static FILE *tooltalk_log_file;
42 #endif 42 #endif
43 43
44 static Lisp_Object 44 static Lisp_Object
45 Vtooltalk_message_handler_hook, 45 Vtooltalk_message_handler_hook,
46 Vtooltalk_pattern_handler_hook, 46 Vtooltalk_pattern_handler_hook,
47 Vtooltalk_unprocessed_message_hook; 47 Vtooltalk_unprocessed_message_hook;
48 48
49 static Lisp_Object 49 static Lisp_Object
50 Qtooltalk_message_handler_hook, 50 Qtooltalk_message_handler_hook,
51 Qtooltalk_pattern_handler_hook, 51 Qtooltalk_pattern_handler_hook,
52 Qtooltalk_unprocessed_message_hook; 52 Qtooltalk_unprocessed_message_hook;
53 53
54 static Lisp_Object 54 static Lisp_Object
55 Qreceive_tooltalk_message, 55 Qreceive_tooltalk_message,
56 Qtt_address, 56 Qtt_address,
57 Qtt_args_count, 57 Qtt_args_count,
58 Qtt_arg_bval, 58 Qtt_arg_bval,
59 Qtt_arg_ival, 59 Qtt_arg_ival,
76 Qtt_sender_ptype, 76 Qtt_sender_ptype,
77 Qtt_session, 77 Qtt_session,
78 Qtt_state, 78 Qtt_state,
79 Qtt_status, 79 Qtt_status,
80 Qtt_status_string, 80 Qtt_status_string,
81 Qtt_uid, 81 Qtt_uid,
82 Qtt_callback, 82 Qtt_callback,
83 Qtt_plist, 83 Qtt_plist,
84 Qtt_prop, 84 Qtt_prop,
85 85
86 Qtt_reject, /* return-tooltalk-message */ 86 Qtt_reject, /* return-tooltalk-message */
152 }; 152 };
153 153
154 static Lisp_Object mark_tooltalk_message (Lisp_Object, void (*) (Lisp_Object)); 154 static Lisp_Object mark_tooltalk_message (Lisp_Object, void (*) (Lisp_Object));
155 static void print_tooltalk_message (Lisp_Object, Lisp_Object, int); 155 static void print_tooltalk_message (Lisp_Object, Lisp_Object, int);
156 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-message", tooltalk_message, 156 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-message", tooltalk_message,
157 mark_tooltalk_message, print_tooltalk_message, 157 mark_tooltalk_message, print_tooltalk_message,
158 0, 0, 0, 158 0, 0, 0,
159 struct Lisp_Tooltalk_Message); 159 struct Lisp_Tooltalk_Message);
160 160
161 static Lisp_Object 161 static Lisp_Object
162 mark_tooltalk_message (Lisp_Object obj, void (*markobj) (Lisp_Object)) 162 mark_tooltalk_message (Lisp_Object obj, void (*markobj) (Lisp_Object))
168 static void 168 static void
169 print_tooltalk_message (Lisp_Object obj, Lisp_Object printcharfun, 169 print_tooltalk_message (Lisp_Object obj, Lisp_Object printcharfun,
170 int escapeflag) 170 int escapeflag)
171 { 171 {
172 struct Lisp_Tooltalk_Message *p = XTOOLTALK_MESSAGE (obj); 172 struct Lisp_Tooltalk_Message *p = XTOOLTALK_MESSAGE (obj);
173 173
174 char buf[200]; 174 char buf[200];
175 175
176 if (print_readably) 176 if (print_readably)
177 error ("printing unreadable object #<tooltalk_message 0x%x>", 177 error ("printing unreadable object #<tooltalk_message 0x%x>",
178 p->header.uid); 178 p->header.uid);
182 } 182 }
183 183
184 static Lisp_Object 184 static Lisp_Object
185 make_tooltalk_message (Tt_message m) 185 make_tooltalk_message (Tt_message m)
186 { 186 {
187 struct Lisp_Tooltalk_Message *message_ 187 struct Lisp_Tooltalk_Message *msg =
188 = alloc_lcrecord (sizeof (struct Lisp_Tooltalk_Message), 188 alloc_lcrecord_type (struct Lisp_Tooltalk_Message,
189 lrecord_tooltalk_message); 189 lrecord_tooltalk_message);
190 Lisp_Object val; 190 Lisp_Object val;
191 191
192 message_->m = m; 192 msg->m = m;
193 message_->callback = Qnil; 193 msg->callback = Qnil;
194 message_->plist_sym = Fmake_symbol (Tooltalk_Message_plist_str); 194 msg->plist_sym = Fmake_symbol (Tooltalk_Message_plist_str);
195 XSETTOOLTALK_MESSAGE (val, message_); 195 XSETTOOLTALK_MESSAGE (val, msg);
196 return val; 196 return val;
197 } 197 }
198 198
199 Tt_message 199 Tt_message
200 unbox_tooltalk_message (Lisp_Object message_) 200 unbox_tooltalk_message (Lisp_Object msg)
201 { 201 {
202 CHECK_TOOLTALK_MESSAGE (message_); 202 CHECK_TOOLTALK_MESSAGE (msg);
203 return XTOOLTALK_MESSAGE (message_)->m; 203 return XTOOLTALK_MESSAGE (msg)->m;
204 } 204 }
205 205
206 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, 1, 1, 0, /* 206 DEFUN ("tooltalk-message-p", Ftooltalk_message_p, 1, 1, 0, /*
207 Return non-nil if OBJECT is a tooltalk message. 207 Return non-nil if OBJECT is a tooltalk message.
208 */ 208 */
228 }; 228 };
229 229
230 static Lisp_Object mark_tooltalk_pattern (Lisp_Object, void (*) (Lisp_Object)); 230 static Lisp_Object mark_tooltalk_pattern (Lisp_Object, void (*) (Lisp_Object));
231 static void print_tooltalk_pattern (Lisp_Object, Lisp_Object, int); 231 static void print_tooltalk_pattern (Lisp_Object, Lisp_Object, int);
232 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-pattern", tooltalk_pattern, 232 DEFINE_LRECORD_IMPLEMENTATION ("tooltalk-pattern", tooltalk_pattern,
233 mark_tooltalk_pattern, print_tooltalk_pattern, 233 mark_tooltalk_pattern, print_tooltalk_pattern,
234 0, 0, 0, 234 0, 0, 0,
235 struct Lisp_Tooltalk_Pattern); 235 struct Lisp_Tooltalk_Pattern);
236 236
237 static Lisp_Object 237 static Lisp_Object
238 mark_tooltalk_pattern (Lisp_Object obj, void (*markobj) (Lisp_Object)) 238 mark_tooltalk_pattern (Lisp_Object obj, void (*markobj) (Lisp_Object))
244 static void 244 static void
245 print_tooltalk_pattern (Lisp_Object obj, Lisp_Object printcharfun, 245 print_tooltalk_pattern (Lisp_Object obj, Lisp_Object printcharfun,
246 int escapeflag) 246 int escapeflag)
247 { 247 {
248 struct Lisp_Tooltalk_Pattern *p = XTOOLTALK_PATTERN (obj); 248 struct Lisp_Tooltalk_Pattern *p = XTOOLTALK_PATTERN (obj);
249 249
250 char buf[200]; 250 char buf[200];
251 251
252 if (print_readably) 252 if (print_readably)
253 error ("printing unreadable object #<tooltalk_pattern 0x%x>", 253 error ("printing unreadable object #<tooltalk_pattern 0x%x>",
254 p->header.uid); 254 p->header.uid);
258 } 258 }
259 259
260 static Lisp_Object 260 static Lisp_Object
261 make_tooltalk_pattern (Tt_pattern p) 261 make_tooltalk_pattern (Tt_pattern p)
262 { 262 {
263 struct Lisp_Tooltalk_Pattern *pat 263 struct Lisp_Tooltalk_Pattern *pat =
264 = alloc_lcrecord (sizeof (struct Lisp_Tooltalk_Pattern), 264 alloc_lcrecord_type (struct Lisp_Tooltalk_Pattern,
265 lrecord_tooltalk_pattern); 265 lrecord_tooltalk_pattern);
266 Lisp_Object val; 266 Lisp_Object val;
267 267
268 pat->p = p; 268 pat->p = p;
269 pat->callback = Qnil; 269 pat->callback = Qnil;
270 pat->plist_sym = Fmake_symbol (Tooltalk_Pattern_plist_str); 270 pat->plist_sym = Fmake_symbol (Tooltalk_Pattern_plist_str);
271 271
272 XSETTOOLTALK_PATTERN (val, pat); 272 XSETTOOLTALK_PATTERN (val, pat);
273 return val; 273 return val;
274 } 274 }
275 275
276 static Tt_pattern 276 static Tt_pattern
289 } 289 }
290 290
291 291
292 292
293 293
294 static int 294 static int
295 tooltalk_constant_value (Lisp_Object s) 295 tooltalk_constant_value (Lisp_Object s)
296 { 296 {
297 if (INTP (s)) 297 if (INTP (s))
298 return XINT (s); 298 return XINT (s);
299 else if (SYMBOLP (s)) 299 else if (SYMBOLP (s))
416 tt_mode_symbol (Tt_mode n) 416 tt_mode_symbol (Tt_mode n)
417 { 417 {
418 switch (n) 418 switch (n)
419 { 419 {
420 case TT_MODE_UNDEFINED: return Q_TT_MODE_UNDEFINED; 420 case TT_MODE_UNDEFINED: return Q_TT_MODE_UNDEFINED;
421 case TT_IN: return Q_TT_IN; 421 case TT_IN: return Q_TT_IN;
422 case TT_OUT: return Q_TT_OUT; 422 case TT_OUT: return Q_TT_OUT;
423 case TT_INOUT: return Q_TT_INOUT; 423 case TT_INOUT: return Q_TT_INOUT;
424 case TT_MODE_LAST: return Q_TT_MODE_LAST; 424 case TT_MODE_LAST: return Q_TT_MODE_LAST;
425 default: return Qnil; 425 default: return Qnil;
426 } 426 }
427 } 427 }
428 428
429 static Lisp_Object 429 static Lisp_Object
430 tt_scope_symbol (Tt_scope n) 430 tt_scope_symbol (Tt_scope n)
431 { 431 {
432 switch (n) 432 switch (n)
433 { 433 {
434 case TT_SCOPE_NONE: return Q_TT_SCOPE_NONE; 434 case TT_SCOPE_NONE: return Q_TT_SCOPE_NONE;
546 Fget_tooltalk_message_attribute, 2, 3, 0, /* 546 Fget_tooltalk_message_attribute, 2, 3, 0, /*
547 Return the indicated Tooltalk message attribute. Attributes are 547 Return the indicated Tooltalk message attribute. Attributes are
548 identified by symbols with the same name (underscores and all) as the 548 identified by symbols with the same name (underscores and all) as the
549 suffix of the Tooltalk tt_message_<attribute> function that extracts the value. 549 suffix of the Tooltalk tt_message_<attribute> function that extracts the value.
550 String attribute values are copied, enumerated type values (except disposition) 550 String attribute values are copied, enumerated type values (except disposition)
551 are converted to symbols - e.g. TT_HANDLER is 'TT_HANDLER, uid and gid are 551 are converted to symbols - e.g. TT_HANDLER is 'TT_HANDLER, uid and gid are
552 represented by fixnums (small integers), opnum is converted to a string, 552 represented by fixnums (small integers), opnum is converted to a string,
553 and disposition is converted to a fixnum. We convert opnum (a C int) to a 553 and disposition is converted to a fixnum. We convert opnum (a C int) to a
554 string, e.g. 123 => \"123\" because there's no guarantee that opnums will fit 554 string, e.g. 123 => "123" because there's no guarantee that opnums will fit
555 within the range of Lisp integers. 555 within the range of Lisp integers.
556 556
557 Use the 'plist attribute instead of the C API 'user attribute 557 Use the 'plist attribute instead of the C API 'user attribute
558 for user defined message data. To retrieve the value of a message property 558 for user defined message data. To retrieve the value of a message property
559 specify the indicator for argn. For example to get the value of a property 559 specify the indicator for argn. For example to get the value of a property
567 (get-tooltalk-message-attribute message 'arg_ival 2) 567 (get-tooltalk-message-attribute message 'arg_ival 2)
568 568
569 As you can see, argument numbers are zero based. The type of each argument 569 As you can see, argument numbers are zero based. The type of each argument
570 can be retrieved with the 'arg_type attribute; however, Tooltalk doesn't 570 can be retrieved with the 'arg_type attribute; however, Tooltalk doesn't
571 define any semantics for the string value of 'arg_type. Conventionally 571 define any semantics for the string value of 'arg_type. Conventionally
572 \"string\" is used for strings and \"int\" for 32 bit integers. Note that 572 "string" is used for strings and "int" for 32 bit integers. Note that
573 Emacs Lisp stores the lengths of strings explicitly (unlike C) so treating the 573 Emacs Lisp stores the lengths of strings explicitly (unlike C) so treating the
574 value returned by 'arg_bval like a string is fine. 574 value returned by 'arg_bval like a string is fine.
575 */ 575 */
576 (message_, attribute, argn)) 576 (message_, attribute, argn))
577 { 577 {
578 Tt_message m = unbox_tooltalk_message (message_); 578 Tt_message m = unbox_tooltalk_message (message_);
579 int n = 0; 579 int n = 0;
580 580
581 CHECK_SYMBOL (attribute); 581 CHECK_SYMBOL (attribute);
582 if (EQ (attribute, (Qtt_arg_bval)) || 582 if (EQ (attribute, (Qtt_arg_bval)) ||
583 EQ (attribute, (Qtt_arg_ival)) || 583 EQ (attribute, (Qtt_arg_ival)) ||
584 EQ (attribute, (Qtt_arg_mode)) || 584 EQ (attribute, (Qtt_arg_mode)) ||
585 EQ (attribute, (Qtt_arg_type)) || 585 EQ (attribute, (Qtt_arg_type)) ||
586 EQ (attribute, (Qtt_arg_val))) 586 EQ (attribute, (Qtt_arg_val)))
587 { 587 {
588 CHECK_INT (argn); 588 CHECK_INT (argn);
589 n = XINT (argn); 589 n = XINT (argn);
590 } 590 }
664 else if (EQ (attribute, Qtt_status_string)) 664 else if (EQ (attribute, Qtt_status_string))
665 return tt_build_string (tt_message_status_string (m)); 665 return tt_build_string (tt_message_status_string (m));
666 666
667 else if (EQ (attribute, Qtt_uid)) 667 else if (EQ (attribute, Qtt_uid))
668 return make_int (tt_message_uid (m)); 668 return make_int (tt_message_uid (m));
669 669
670 else if (EQ (attribute, Qtt_callback)) 670 else if (EQ (attribute, Qtt_callback))
671 return XTOOLTALK_MESSAGE (message_)->callback; 671 return XTOOLTALK_MESSAGE (message_)->callback;
672 672
673 else if (EQ (attribute, Qtt_prop)) 673 else if (EQ (attribute, Qtt_prop))
674 return Fget (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, Qnil); 674 return Fget (XTOOLTALK_MESSAGE (message_)->plist_sym, argn, Qnil);
707 { 707 {
708 Tt_message m = unbox_tooltalk_message (message_); 708 Tt_message m = unbox_tooltalk_message (message_);
709 int n = 0; 709 int n = 0;
710 710
711 CHECK_SYMBOL (attribute); 711 CHECK_SYMBOL (attribute);
712 if (EQ (attribute, (Qtt_arg_bval)) || 712 if (EQ (attribute, (Qtt_arg_bval)) ||
713 EQ (attribute, (Qtt_arg_ival)) || 713 EQ (attribute, (Qtt_arg_ival)) ||
714 EQ (attribute, (Qtt_arg_val))) 714 EQ (attribute, (Qtt_arg_val)))
715 { 715 {
716 CHECK_INT (argn); 716 CHECK_INT (argn);
717 n = XINT (argn); 717 n = XINT (argn);
718 } 718 }
721 return Qnil; 721 return Qnil;
722 722
723 else if (EQ (attribute, Qtt_address)) 723 else if (EQ (attribute, Qtt_address))
724 { 724 {
725 CHECK_TOOLTALK_CONSTANT (value); 725 CHECK_TOOLTALK_CONSTANT (value);
726 tt_message_address_set (m, tooltalk_constant_value (value)); 726 tt_message_address_set (m, (Tt_address) tooltalk_constant_value (value));
727 } 727 }
728 else if (EQ (attribute, Qtt_class)) 728 else if (EQ (attribute, Qtt_class))
729 { 729 {
730 CHECK_TOOLTALK_CONSTANT (value); 730 CHECK_TOOLTALK_CONSTANT (value);
731 tt_message_class_set (m, tooltalk_constant_value (value)); 731 tt_message_class_set (m, (Tt_class) tooltalk_constant_value (value));
732 } 732 }
733 else if (EQ (attribute, Qtt_disposition)) 733 else if (EQ (attribute, Qtt_disposition))
734 { 734 {
735 CHECK_TOOLTALK_CONSTANT (value); 735 CHECK_TOOLTALK_CONSTANT (value);
736 tt_message_disposition_set (m, tooltalk_constant_value (value)); 736 tt_message_disposition_set (m, ((Tt_disposition)
737 tooltalk_constant_value (value)));
737 } 738 }
738 else if (EQ (attribute, Qtt_file)) 739 else if (EQ (attribute, Qtt_file))
739 { 740 {
740 CONST char *value_ext; 741 CONST char *value_ext;
741 CHECK_STRING (value); 742 CHECK_STRING (value);
778 tt_message_otype_set (m, value_ext); 779 tt_message_otype_set (m, value_ext);
779 } 780 }
780 else if (EQ (attribute, Qtt_scope)) 781 else if (EQ (attribute, Qtt_scope))
781 { 782 {
782 CHECK_TOOLTALK_CONSTANT (value); 783 CHECK_TOOLTALK_CONSTANT (value);
783 tt_message_scope_set (m, tooltalk_constant_value (value)); 784 tt_message_scope_set (m, (Tt_scope) tooltalk_constant_value (value));
784 } 785 }
785 else if (EQ (attribute, Qtt_sender_ptype)) 786 else if (EQ (attribute, Qtt_sender_ptype))
786 { 787 {
787 CONST char *value_ext; 788 CONST char *value_ext;
788 CHECK_STRING (value); 789 CHECK_STRING (value);
789 GET_C_STRING_OS_DATA_ALLOCA (value, value_ext); 790 GET_C_STRING_OS_DATA_ALLOCA (value, value_ext);
790 tt_message_sender_ptype_set (m, value_ext); 791 tt_message_sender_ptype_set (m, value_ext);
791 } 792 }
929 Append one new argument to the message. 930 Append one new argument to the message.
930 MODE must be one of TT_IN, TT_INOUT, or TT_OUT; VTYPE must be a string; 931 MODE must be one of TT_IN, TT_INOUT, or TT_OUT; VTYPE must be a string;
931 and VALUE can be a string or an integer. Tooltalk doesn't 932 and VALUE can be a string or an integer. Tooltalk doesn't
932 define any semantics for VTYPE, so only the participants in the 933 define any semantics for VTYPE, so only the participants in the
933 protocol you're using need to agree what types mean (if anything). 934 protocol you're using need to agree what types mean (if anything).
934 Conventionally \"string\" is used for strings and \"int\" for 32 bit integers. 935 Conventionally "string" is used for strings and "int" for 32 bit integers.
935 Arguments can initialized by providing a value or with 936 Arguments can initialized by providing a value or with
936 `set-tooltalk-message-attribute'. The latter is necessary if you 937 `set-tooltalk-message-attribute'. The latter is necessary if you
937 want to initialize the argument with a string that can contain 938 want to initialize the argument with a string that can contain
938 embedded nulls (use 'arg_bval). 939 embedded nulls (use 'arg_bval).
939 */ 940 */
1023 1024
1024 DEFUN ("add-tooltalk-pattern-attribute", Fadd_tooltalk_pattern_attribute, 3, 3, 0, /* 1025 DEFUN ("add-tooltalk-pattern-attribute", Fadd_tooltalk_pattern_attribute, 3, 3, 0, /*
1025 Add one value to the indicated pattern attribute. 1026 Add one value to the indicated pattern attribute.
1026 All Tooltalk pattern attributes are supported except 'user. The names 1027 All Tooltalk pattern attributes are supported except 'user. The names
1027 of attributes are the same as the Tooltalk accessors used to set them 1028 of attributes are the same as the Tooltalk accessors used to set them
1028 less the \"tooltalk_pattern_\" prefix and the \"_add\" ... 1029 less the "tooltalk_pattern_" prefix and the "_add" ...
1029 */ 1030 */
1030 (value, pattern, attribute)) 1031 (value, pattern, attribute))
1031 { 1032 {
1032 Tt_pattern p = unbox_tooltalk_pattern (pattern); 1033 Tt_pattern p = unbox_tooltalk_pattern (pattern);
1033 1034
1037 return Qnil; 1038 return Qnil;
1038 1039
1039 else if (EQ (attribute, Qtt_category)) 1040 else if (EQ (attribute, Qtt_category))
1040 { 1041 {
1041 CHECK_TOOLTALK_CONSTANT (value); 1042 CHECK_TOOLTALK_CONSTANT (value);
1042 tt_pattern_category_set (p, tooltalk_constant_value (value)); 1043 tt_pattern_category_set (p, ((Tt_category)
1044 tooltalk_constant_value (value)));
1043 } 1045 }
1044 else if (EQ (attribute, Qtt_address)) 1046 else if (EQ (attribute, Qtt_address))
1045 { 1047 {
1046 CHECK_TOOLTALK_CONSTANT (value); 1048 CHECK_TOOLTALK_CONSTANT (value);
1047 tt_pattern_address_add (p, tooltalk_constant_value (value)); 1049 tt_pattern_address_add (p, ((Tt_address)
1050 tooltalk_constant_value (value)));
1048 } 1051 }
1049 else if (EQ (attribute, Qtt_class)) 1052 else if (EQ (attribute, Qtt_class))
1050 { 1053 {
1051 CHECK_TOOLTALK_CONSTANT (value); 1054 CHECK_TOOLTALK_CONSTANT (value);
1052 tt_pattern_class_add (p, tooltalk_constant_value (value)); 1055 tt_pattern_class_add (p, (Tt_class) tooltalk_constant_value (value));
1053 } 1056 }
1054 else if (EQ (attribute, Qtt_disposition)) 1057 else if (EQ (attribute, Qtt_disposition))
1055 { 1058 {
1056 CHECK_TOOLTALK_CONSTANT (value); 1059 CHECK_TOOLTALK_CONSTANT (value);
1057 tt_pattern_disposition_add (p, tooltalk_constant_value (value)); 1060 tt_pattern_disposition_add (p, ((Tt_disposition)
1061 tooltalk_constant_value (value)));
1058 } 1062 }
1059 else if (EQ (attribute, Qtt_file)) 1063 else if (EQ (attribute, Qtt_file))
1060 { 1064 {
1061 CONST char *value_ext; 1065 CONST char *value_ext;
1062 CHECK_STRING (value); 1066 CHECK_STRING (value);
1085 tt_pattern_otype_add (p, value_ext); 1089 tt_pattern_otype_add (p, value_ext);
1086 } 1090 }
1087 else if (EQ (attribute, Qtt_scope)) 1091 else if (EQ (attribute, Qtt_scope))
1088 { 1092 {
1089 CHECK_TOOLTALK_CONSTANT (value); 1093 CHECK_TOOLTALK_CONSTANT (value);
1090 tt_pattern_scope_add (p, tooltalk_constant_value (value)); 1094 tt_pattern_scope_add (p, (Tt_scope) tooltalk_constant_value (value));
1091 } 1095 }
1092 else if (EQ (attribute, Qtt_sender)) 1096 else if (EQ (attribute, Qtt_sender))
1093 { 1097 {
1094 CONST char *value_ext; 1098 CONST char *value_ext;
1095 CHECK_STRING (value); 1099 CHECK_STRING (value);
1111 tt_pattern_session_add (p, value_ext); 1115 tt_pattern_session_add (p, value_ext);
1112 } 1116 }
1113 else if (EQ (attribute, Qtt_state)) 1117 else if (EQ (attribute, Qtt_state))
1114 { 1118 {
1115 CHECK_TOOLTALK_CONSTANT (value); 1119 CHECK_TOOLTALK_CONSTANT (value);
1116 tt_pattern_state_add (p, tooltalk_constant_value (value)); 1120 tt_pattern_state_add (p, (Tt_state) tooltalk_constant_value (value));
1117 } 1121 }
1118 else if (EQ (attribute, Qtt_callback)) 1122 else if (EQ (attribute, Qtt_callback))
1119 { 1123 {
1120 CHECK_SYMBOL (value); 1124 CHECK_SYMBOL (value);
1121 XTOOLTALK_PATTERN (pattern)->callback = value; 1125 XTOOLTALK_PATTERN (pattern)->callback = value;
1142 1146
1143 n = (Tt_mode) tooltalk_constant_value (mode); 1147 n = (Tt_mode) tooltalk_constant_value (mode);
1144 1148
1145 if (!VALID_TOOLTALK_PATTERNP (p)) 1149 if (!VALID_TOOLTALK_PATTERNP (p))
1146 return Qnil; 1150 return Qnil;
1147 1151
1148 { 1152 {
1149 CONST char *vtype_ext; 1153 CONST char *vtype_ext;
1150 1154
1151 GET_C_STRING_OS_DATA_ALLOCA (vtype, vtype_ext); 1155 GET_C_STRING_OS_DATA_ALLOCA (vtype, vtype_ext);
1152 if (NILP (value)) 1156 if (NILP (value))
1235 Return current default process identifier for your process. 1239 Return current default process identifier for your process.
1236 */ 1240 */
1237 ()) 1241 ())
1238 { 1242 {
1239 char *procid = tt_default_procid (); 1243 char *procid = tt_default_procid ();
1240 if (!procid) 1244 return procid ? build_string (procid) : Qnil;
1241 return Qnil;
1242 return build_string (procid);
1243 } 1245 }
1244 1246
1245 DEFUN ("tooltalk-default-session", Ftooltalk_default_session, 0, 0, 0, /* 1247 DEFUN ("tooltalk-default-session", Ftooltalk_default_session, 0, 0, 0, /*
1246 Return current default session identifier for the current default procid. 1248 Return current default session identifier for the current default procid.
1247 */ 1249 */
1248 ()) 1250 ())
1249 { 1251 {
1250 char *session = tt_default_session (); 1252 char *session = tt_default_session ();
1251 if (!session) 1253 return session ? build_string (session) : Qnil;
1252 return Qnil;
1253 return build_string (session);
1254 } 1254 }
1255 1255
1256 static void 1256 static void
1257 init_tooltalk (void) 1257 init_tooltalk (void)
1258 { 1258 {
1262 Lisp_Object fil; 1262 Lisp_Object fil;
1263 1263
1264 retval = tt_open (); 1264 retval = tt_open ();
1265 if (tt_ptr_error (retval) != TT_OK) 1265 if (tt_ptr_error (retval) != TT_OK)
1266 return; 1266 return;
1267 1267
1268 Vtooltalk_fd = make_int (tt_fd ()); 1268 Vtooltalk_fd = make_int (tt_fd ());
1269 1269
1270 tt_session_join (tt_default_session ()); 1270 tt_session_join (tt_default_session ());
1271 1271
1272 lp = connect_to_file_descriptor (build_string ("tooltalk"), Qnil, 1272 lp = connect_to_file_descriptor (build_string ("tooltalk"), Qnil,
1289 /* Apparently the tt_message_send_on_exit() function does not exist 1289 /* Apparently the tt_message_send_on_exit() function does not exist
1290 under SunOS 4.x or IRIX 5 or various other non-Solaris-2 systems. 1290 under SunOS 4.x or IRIX 5 or various other non-Solaris-2 systems.
1291 No big deal if we don't do the following under those systems. */ 1291 No big deal if we don't do the following under those systems. */
1292 { 1292 {
1293 Tt_message exit_msg = tt_message_create (); 1293 Tt_message exit_msg = tt_message_create ();
1294 1294
1295 tt_message_op_set (exit_msg, "emacs-aborted"); 1295 tt_message_op_set (exit_msg, "emacs-aborted");
1296 tt_message_scope_set (exit_msg, TT_SESSION); 1296 tt_message_scope_set (exit_msg, TT_SESSION);
1297 tt_message_class_set (exit_msg, TT_NOTICE); 1297 tt_message_class_set (exit_msg, TT_NOTICE);
1298 tt_message_send_on_exit (exit_msg); 1298 tt_message_send_on_exit (exit_msg);
1299 tt_message_destroy (exit_msg); 1299 tt_message_destroy (exit_msg);
1335 DEFSUBR (Fget_tooltalk_message_attribute); 1335 DEFSUBR (Fget_tooltalk_message_attribute);
1336 DEFSUBR (Fset_tooltalk_message_attribute); 1336 DEFSUBR (Fset_tooltalk_message_attribute);
1337 DEFSUBR (Fsend_tooltalk_message); 1337 DEFSUBR (Fsend_tooltalk_message);
1338 DEFSUBR (Freturn_tooltalk_message); 1338 DEFSUBR (Freturn_tooltalk_message);
1339 DEFSUBR (Fcreate_tooltalk_pattern); 1339 DEFSUBR (Fcreate_tooltalk_pattern);
1340 DEFSUBR (Fdestroy_tooltalk_pattern); 1340 DEFSUBR (Fdestroy_tooltalk_pattern);
1341 DEFSUBR (Fadd_tooltalk_pattern_attribute); 1341 DEFSUBR (Fadd_tooltalk_pattern_attribute);
1342 DEFSUBR (Fadd_tooltalk_pattern_arg); 1342 DEFSUBR (Fadd_tooltalk_pattern_arg);
1343 DEFSUBR (Fregister_tooltalk_pattern); 1343 DEFSUBR (Fregister_tooltalk_pattern);
1344 DEFSUBR (Funregister_tooltalk_pattern); 1344 DEFSUBR (Funregister_tooltalk_pattern);
1345 DEFSUBR (Ftooltalk_pattern_plist_get); 1345 DEFSUBR (Ftooltalk_pattern_plist_get);
1346 DEFSUBR (Ftooltalk_pattern_prop_set); 1346 DEFSUBR (Ftooltalk_pattern_prop_set);
1347 DEFSUBR (Ftooltalk_pattern_prop_get); 1347 DEFSUBR (Ftooltalk_pattern_prop_get);
1348 DEFSUBR (Ftooltalk_default_procid); 1348 DEFSUBR (Ftooltalk_default_procid);
1349 DEFSUBR (Ftooltalk_default_session); 1349 DEFSUBR (Ftooltalk_default_session);
1394 DEFVAR_LISP ("tooltalk-fd", &Vtooltalk_fd /* 1394 DEFVAR_LISP ("tooltalk-fd", &Vtooltalk_fd /*
1395 File descriptor returned by tt_initialize; nil if not connected to ToolTalk. 1395 File descriptor returned by tt_initialize; nil if not connected to ToolTalk.
1396 */ ); 1396 */ );
1397 Vtooltalk_fd = Qnil; 1397 Vtooltalk_fd = Qnil;
1398 1398
1399 DEFVAR_LISP ("tooltalk-message-handler-hook", 1399 DEFVAR_LISP ("tooltalk-message-handler-hook",
1400 &Vtooltalk_message_handler_hook /* 1400 &Vtooltalk_message_handler_hook /*
1401 List of functions to be applied to each ToolTalk message reply received. 1401 List of functions to be applied to each ToolTalk message reply received.
1402 This will always occur as a result of our sending a request message. 1402 This will always occur as a result of our sending a request message.
1403 Functions will be called with two arguments, the message and the 1403 Functions will be called with two arguments, the message and the
1404 corresponding pattern. This hook will not be called if the request 1404 corresponding pattern. This hook will not be called if the request
1405 message was created without a C-level callback function (see 1405 message was created without a C-level callback function (see
1406 `tooltalk-unprocessed-message-hook'). 1406 `tooltalk-unprocessed-message-hook').
1407 */ ); 1407 */ );
1408 Vtooltalk_message_handler_hook = Qnil; 1408 Vtooltalk_message_handler_hook = Qnil;
1409 1409
1410 DEFVAR_LISP ("tooltalk-pattern-handler-hook", 1410 DEFVAR_LISP ("tooltalk-pattern-handler-hook",
1411 &Vtooltalk_pattern_handler_hook /* 1411 &Vtooltalk_pattern_handler_hook /*
1412 List of functions to be applied to each pattern-matching ToolTalk message. 1412 List of functions to be applied to each pattern-matching ToolTalk message.
1413 This is all messages except those handled by `tooltalk-message-handler-hook'. 1413 This is all messages except those handled by `tooltalk-message-handler-hook'.
1414 Functions will be called with two arguments, the message and the 1414 Functions will be called with two arguments, the message and the
1415 corresponding pattern. 1415 corresponding pattern.
1422 Unprocessed messages are messages that didn't match any patterns. 1422 Unprocessed messages are messages that didn't match any patterns.
1423 */ ); 1423 */ );
1424 Vtooltalk_unprocessed_message_hook = Qnil; 1424 Vtooltalk_unprocessed_message_hook = Qnil;
1425 1425
1426 Tooltalk_Message_plist_str = build_string ("Tooltalk Message plist"); 1426 Tooltalk_Message_plist_str = build_string ("Tooltalk Message plist");
1427 Tooltalk_Pattern_plist_str = build_string ("Tooltalk Pattern plist"); 1427 Tooltalk_Pattern_plist_str = build_string ("Tooltalk Pattern p plist");
1428 1428
1429 #define MAKE_CONSTANT(name) do { \ 1429 #define MAKE_CONSTANT(name) do { \
1430 defsymbol (&Q_ ## name, #name); \ 1430 defsymbol (&Q_ ## name, #name); \
1431 Fset (Q_ ## name, make_int (name)); \ 1431 Fset (Q_ ## name, make_int (name)); \
1432 } while (0) 1432 } while (0)
1433 1433
1434 MAKE_CONSTANT (TT_MODE_UNDEFINED); 1434 MAKE_CONSTANT (TT_MODE_UNDEFINED);
1435 MAKE_CONSTANT (TT_IN); 1435 MAKE_CONSTANT (TT_IN);
1436 MAKE_CONSTANT (TT_OUT); 1436 MAKE_CONSTANT (TT_OUT);
1437 MAKE_CONSTANT (TT_INOUT); 1437 MAKE_CONSTANT (TT_INOUT);
1438 MAKE_CONSTANT (TT_MODE_LAST); 1438 MAKE_CONSTANT (TT_MODE_LAST);