clienttypes.el 18.7 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
Linus Tolke Y's avatar
Linus Tolke Y committed
2 3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
5 6 7 8 9
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
10
;;;;; the Free Software Foundation; either version 2, or (at your option) 
Linus Tolke Y's avatar
Linus Tolke Y committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
Per Cederqvist's avatar
.  
Per Cederqvist committed
26 27 28 29 30 31 32 33 34 35 36 37
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: clienttypes.el
;;;;
;;;; This file contains primitives for the different data types
;;;; in the lyskom elisp client. The types in here are only used
;;;; within this lyskom client.
;;;;
;;;; Authors: Linus Tolke and Inge Wallin
;;;;

38 39 40 41 42
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))


Per Cederqvist's avatar
.  
Per Cederqvist committed
43 44 45 46 47 48 49 50 51
;;; ================================================================
;;;                            read-info

;;; A read-info is used by to tell the client which text to 
;;; show next and in which order to step through the conferences 
;;; with unread texts. New read-infos are created and deleted
;;; all the time within a session.
;;;
;;; The type is one of the following:
Linus Tolke Y's avatar
Linus Tolke Y committed
52 53 54 55 56 57 58 59
;;;   REVIEW      - Default review type, created by the kom-review-by-to
;;;		    and the kom-review-comments
;;;   REVIEW-TREE - List of texts created by one of the tree-reading 
;;;		    commands: kom-find-root-review, kom-review-tree
;;;   REVIEW-MARK - List of texts created by the review-mark command
;;;   COMM-IN     - Type containing the list of comments to a text
;;;   FOOTN-IN    - Type containing the list of footnotes to a text
;;;   CONF        - Basic type of unread in a conf.
David Byers's avatar
David Byers committed
60
;;;   RE-EDIT-TEXT - Re-edit a failed submission. Buffer is in misc.
61
;;;   PRI-SESSION - Go to prioritized session.
Linus Tolke Y's avatar
Linus Tolke Y committed
62 63 64 65 66 67
;;;
;;;   The types REVIEW-TREE, COMM-IN and FOOTN-IN are created for new for
;;;   every text read (recursively) when appropriate.
;;;
;;;   The difference between REVIEW and REVIEW-MARK is just that there
;;;   generate different prompts and different text from kom-review-stack.
Per Cederqvist's avatar
.  
Per Cederqvist committed
68 69 70 71 72
;;;


;;; read-info

David Kågedal's avatar
David Kågedal committed
73
(defsubst lyskom-create-read-info (type
Per Cederqvist's avatar
.  
Per Cederqvist committed
74 75 76
				conf-stat
				priority
				text-list
David Byers's avatar
David Byers committed
77
				&optional comm-to forward misc)
Per Cederqvist's avatar
.  
Per Cederqvist committed
78 79 80 81 82 83 84
  "Create a read-info from all parameters."
  ;; The last nil is for the unfetched-texts pair (first . last)
  ;; This field is only applicable in read-infos of type CONF where
  ;; it shows which part of the map for this conference that has not
  ;; yet been fetched.
  (cons
   'READ-INFO
David Byers's avatar
David Byers committed
85
   (vector type conf-stat priority text-list comm-to forward nil misc)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
86

David Kågedal's avatar
David Kågedal committed
87
(defsubst read-info->type (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
88 89 90
  "Get type from read-info."
  (elt (cdr read-info) 0))

David Kågedal's avatar
David Kågedal committed
91
(defsubst read-info->conf-stat (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
92 93 94
  "Get conf-stat from read-info."
  (elt (cdr read-info) 1))

David Kågedal's avatar
David Kågedal committed
95
(defsubst read-info->priority (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
96 97 98
  "Get priority from read-info."
  (elt (cdr read-info) 2))

David Kågedal's avatar
David Kågedal committed
99
(defsubst read-info->text-list (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
100 101 102
  "Get text-list from read-info."
  (elt (cdr read-info) 3))

David Kågedal's avatar
David Kågedal committed
103
(defsubst read-info->comm-to (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
104 105 106
  "Get comm-to from read-info."
  (elt (cdr read-info) 4))

David Kågedal's avatar
David Kågedal committed
107
(defsubst read-info->forward (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
108 109 110
  "Get forward from read-info."
  (elt (cdr read-info) 5))

David Kågedal's avatar
David Kågedal committed
111
(defsubst read-info->unfetched-texts (read-info)
Per Cederqvist's avatar
.  
Per Cederqvist committed
112 113 114
  "Get forward from read-info."
  (elt (cdr read-info) 6))

David Byers's avatar
David Byers committed
115 116 117 118
(defsubst read-info->misc (read-info)
  "Get forward from read-info."
  (elt (cdr read-info) 7))

David Kågedal's avatar
David Kågedal committed
119
(defsubst set-read-info->type (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
120 121 122
  "Set type in read-info to NEWVAL."
  (aset (cdr read-info) 0 newval))

David Kågedal's avatar
David Kågedal committed
123
(defsubst set-read-info->conf-stat (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
124 125 126
  "Set conf-stat in read-info to NEWVAL."
  (aset (cdr read-info) 1 newval))

David Kågedal's avatar
David Kågedal committed
127
(defsubst set-read-info->priority (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
128 129 130
  "Set priority in read-info to NEWVAL."
  (aset (cdr read-info) 2 newval))

David Kågedal's avatar
David Kågedal committed
131
(defsubst set-read-info->text-list (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
132 133 134
  "Set text-list in read-info to NEWVAL."
  (aset (cdr read-info) 3 newval))

David Kågedal's avatar
David Kågedal committed
135
(defsubst set-read-info->comm-to (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
136 137 138
  "Set comm-to in read-info to NEWVAL."
  (aset (cdr read-info) 4 newval))

David Kågedal's avatar
David Kågedal committed
139
(defsubst set-read-info->forward (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
140 141 142
  "Set forward in read-info to NEWVAL."
  (aset (cdr read-info) 5 newval))

David Kågedal's avatar
David Kågedal committed
143
(defsubst set-read-info->unfetched-texts (read-info newval)
Per Cederqvist's avatar
.  
Per Cederqvist committed
144 145 146
  "Set forward in read-info to NEWVAL."
  (aset (cdr read-info) 6 newval))

David Byers's avatar
David Byers committed
147 148 149 150
(defsubst set-read-info->misc (read-info newval)
  "Set forward in read-info to NEWVAL."
  (aset (cdr read-info) 7 newval))

Per Cederqvist's avatar
.  
Per Cederqvist committed
151

David Kågedal's avatar
David Kågedal committed
152
(defsubst lyskom-read-info-p (object)
Per Cederqvist's avatar
.  
Per Cederqvist committed
153 154 155 156
  "Return t if OBJECT is a read-info."
  (eq (car-safe object) 'READ-INFO))


157
(defsubst read-info-append-text-list (read-info texts)
158
  (text-list->append (read-info->text-list read-info) texts))
159 160 161 162

(defsubst read-info-enter-text-last (read-info text-no)
  (read-info-append-text-list read-info (list text-no)))

Per Cederqvist's avatar
.  
Per Cederqvist committed
163 164 165 166 167 168 169
				   
;;; ================================================================
;;;                          read-list


;;; Constructor:

David Kågedal's avatar
David Kågedal committed
170
(defsubst lyskom-create-read-list ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
171 172 173 174 175 176
  "Create an empty read-list."
  (cons 'READ-LIST nil))


;;; Predicates:

David Kågedal's avatar
David Kågedal committed
177
(defsubst read-list-isempty (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
178 179 180 181 182 183
  "Return t if READ-LIST is empty, otherwise return nil."
  (null (cdr read-list)))


;;; Selectors:

David Kågedal's avatar
David Kågedal committed
184
(defsubst read-list->first (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
185 186 187 188
  "Return the first entry in READ-LIST, or nil if empty."
  (car-safe (cdr read-list)))


David Kågedal's avatar
David Kågedal committed
189
(defsubst read-list->nth (read-list n)
Per Cederqvist's avatar
.  
Per Cederqvist committed
190 191 192 193 194 195
  "Args: READ-LIST N
Return element N in READ-LIST or nil if outside the range.
The range of valid values for N is [0, num-entries - 1]."
  (elt (cdr read-list) n))


David Kågedal's avatar
David Kågedal committed
196
(defsubst read-list->all-entries (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
197 198 199 200 201 202
  "Return a list of all entries in READ-LIST."
  (cdr read-list))


;;; Other functions:

David Kågedal's avatar
David Kågedal committed
203
(defsubst read-list-length (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
204 205 206 207 208 209
  "Return the number of entries in READ-LIST."
  (1- (length read-list)))


;;; Modifiers:

David Kågedal's avatar
David Kågedal committed
210
(defsubst set-read-list-empty (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
211 212 213 214
  "Empty READ-LIST destructively."
  (setcdr read-list nil))


David Kågedal's avatar
David Kågedal committed
215
(defsubst set-read-list-del-first (read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
216 217 218 219 220
  "Delete the first entry of READ-LIST if there is one."
  (if (cdr read-list)
      (setcdr read-list (cdr (cdr read-list)))))


David Kågedal's avatar
David Kågedal committed
221
(defsubst read-list-enter-first (read-info read-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  "Enter READ-INFO first into READ-LIST."
  (setcdr read-list (cons read-info (cdr read-list))))


(defun read-list-enter-text (text-no recipient rlist)
  "Args: TEXT-NO RECIPIENT RLIST.
Add the new text TEXT-NO to any RECIPIENT found in RLIST.
RECIPIENT is a conf-stat.
Returns t if there was a conference to insert this text into."
  (let ((inserted nil))
    (lyskom-traverse
     read-info (cdr rlist)
     (cond
      ((and (eq 'CONF (read-info->type read-info))
	    (= (conf-stat->conf-no recipient)
	       (conf-stat->conf-no (read-info->conf-stat read-info))))
238
       (read-info-enter-text-last read-info text-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
239 240 241 242 243 244 245 246 247
       (setq inserted t))))
    inserted))


(defun read-list-delete-text (text-no rlist)
  "Destructively delete all occurances of TEXT-NO from RLIST.
RLIST is a list of read-info.
Entries of the type REVIEW, REVIEW-TREE or REVIEW-MARK are not changed
except if they were empty in which case they are removed.
248
Returns the modified RLIST.
Linus Tolke Y's avatar
Linus Tolke Y committed
249
TEXT-NO may be nil, in which case only empty read-infos on RLIST are removed."
Per Cederqvist's avatar
.  
Per Cederqvist committed
250 251 252
  (let* ((prev rlist)			;"Previous" cons-celll
	 (curr (cdr rlist)))		;Current cons-cell
    (while curr
253 254 255 256 257 258 259 260
      (if text-no
	  (cond
	   ((let ((type (read-info->type (car curr)))) 
	      (or (eq type 'REVIEW)	; Don't change REVIEW et c.
		  (eq type 'REVIEW-TREE)
		  (eq type 'REVIEW-MARK))))
	   (t				; Do change all other entries.
	    (let ((tl  (read-info->text-list (car curr))))
261 262
	      (text-list->delq tl text-no)))))
      
Per Cederqvist's avatar
.  
Per Cederqvist committed
263
      ;; Delete this element from RLIST if the text-list became or was empty.
264 265
      
      (if (text-list->empty (read-info->text-list (car curr)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
266 267 268 269 270 271 272 273 274 275 276 277 278
	  (setcdr prev (cdr curr))
	(setq prev curr))
      (setq curr (cdr curr))))
  rlist)


(defun read-list-enter-read-info (read-info rlist &optional before)
  "Destructively insert READ-INFO in RLIST, sorted by priority.
RLIST is a list of read-info.
Args: READ-INFO RLIST &optional BEFORE.
A new item with the same priority as an item that is alreay on the list
will nomally be inserted after the old one, but if BEFORE is non-nil it
will be inserted before it."
279 280
  (let ((pri (+ (if before 0 -1)
		(read-info->priority read-info)))
281 282 283
	(continue t)
	(conf-stat (read-info->conf-stat read-info))
	(type (read-info->type read-info)))
284 285
    (while continue
      (cond
286 287 288 289 290 291 292 293 294 295 296 297
       ;; This case was added by davidk 960925. It is not used from
       ;; everywhere, but at least lyskom-enter-map-in-to-do-list
       ;; should become more efficient.
       ((and (eq type 'CONF)
	     (eq (read-info->type (car (cdr rlist))) 'CONF)
	     (eq conf-stat (read-info->conf-stat (car (cdr rlist)))))
	(read-info-append-text-list
	 (car (cdr rlist))
	 (text-list->texts (read-info->text-list read-info)))
	(setq continue nil)) 
       
       ((null (cdr rlist)) 
298 299 300 301 302 303 304 305
	(setcdr rlist (list read-info))
	(setq continue nil))
       ((>= pri (read-info->priority (car (cdr rlist))))
	(setcdr rlist (cons read-info (cdr rlist)))
	(setq continue nil))
       (t 
	(setq rlist (cdr rlist)))))))

Per Cederqvist's avatar
.  
Per Cederqvist committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
(defun read-list-delete-read-info (conf-no rlist)
  "Destructively removes all the entries for the conf CONF-NO in RLIST.
RLIST is a list of read-info."
  (while (cdr rlist)
    (if (eq (conf-stat->conf-no (read-info->conf-stat
				      (car (cdr rlist))))
	    conf-no)
	(setcdr rlist (cdr (cdr rlist)))
      (setq rlist (cdr rlist)))))
 
	  
(defun read-list-rotate (read-list)
  "Put the first element of READ-LIST last in the same list. The second
element will be the new first element."
  (if (> (length read-list) 2)
      (let ((first (cdr read-list))
	    (last  (cdr read-list)))
	(while (cdr last)
	  (setq last (cdr last)))
	(setcdr last first)
	(setcdr read-list (cdr first))
	(setcdr first nil)))
  read-list)    
	  

;;; ================================================================
;;;                      A simple queue

;;;
;;; This is a simple implementation of a queue.  The only thing you
;;; can do with it is stuff things at the back of it and remove
;;; things from the front of it.  (...and of course do a few tests)
;;;

;;; Author: Inge Wallin


(defun lyskom-queue-create ()
  "Create an empty queue."
  (cons 'QUEUE (cons nil nil)))


David Byers's avatar
David Byers committed
348
(defsubst lyskom-queue-enter (queue element)
Linus Tolke Y's avatar
Linus Tolke Y committed
349
  "Enter last into the queue QUEUE the ELEMENT."
Per Cederqvist's avatar
.  
Per Cederqvist committed
350 351 352 353 354 355 356 357 358 359 360 361
  (let ((elementcell (cons element nil)))
    (if (null (car (cdr queue)))
	; QUEUE is empty
	(setcar (cdr queue)
		(setcdr (cdr queue) 
			elementcell))
      (setcdr (cdr (cdr queue))
	      elementcell)
      (setcdr (cdr queue)
	      elementcell))))


David Byers's avatar
David Byers committed
362
(defsubst lyskom-queue-p (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
363 364 365 366
  "Return t if QUEUE is a queue, otherwise return nil."
  (eq (car-safe queue) 'QUEUE))


David Byers's avatar
David Byers committed
367
(defsubst lyskom-queue-isempty (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
368 369 370 371
  "Return t if QUEUE is empty, otherwise return nil."
  (null (car (cdr queue))))


David Byers's avatar
David Byers committed
372
(defsubst lyskom-queue->first (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
373 374 375 376
  "Return the first element of QUEUE or nil if it is empty."
  (car-safe (car (cdr queue))))


David Byers's avatar
David Byers committed
377
(defsubst lyskom-queue->all-entries (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
378 379 380 381
  "Return all elements of QUEUE (nil if it is empty)."
  (car-safe (cdr queue)))


David Byers's avatar
David Byers committed
382
(defsubst lyskom-queue->last (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
383 384 385 386
  "Return the lastelement of QUEUE or nil if it is empty."
  (car-safe (cdr (cdr queue))))


David Byers's avatar
David Byers committed
387
(defsubst lyskom-queue-make-empty (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
388 389 390 391
  "Make the queue QUEUE empty."
  (setcdr queue (cons nil nil)))


David Byers's avatar
David Byers committed
392
(defsubst lyskom-queue-delete-first (queue)
Per Cederqvist's avatar
.  
Per Cederqvist committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
  "Delete the first element of QUEUE and return it. If QUEUE is empty
return nil and do nothing."
  (if (lyskom-queue-isempty queue)
      nil
    (prog1
	(lyskom-queue->first queue)
      (setcar (cdr queue)
	      (cdr (car (cdr queue))))
      (if (null (car (cdr queue)))
	  (setcdr (cdr queue) nil)))))


;;; ================================================================
;;;                           A simple stack

;;; 
;;; This is an implementation of a simple stack.
;;;

;;; Author: Inge Wallin


(defun lyskom-stack-create ()
  "Create an empty stack"
  (cons 'STACK nil))


(defun lyskom-stack-p (stack)
  "Return t if STACK is a lyskom-stack, otherwise return nil."
  (eq (car-safe stack) 'STACK))


(defun lyskom-stack-push (stack element)
  "Push the second arg ELEMENT onto the first arg STACK"
  (setcdr stack (cons element (cdr stack))))


(defun lyskom-stack-pop (stack)
  "Remove the topmost element from STACK and return it. If the stack
is empty, return nil"
  (prog1
      (car-safe (cdr stack))
    (setcdr stack (cdr-safe (cdr stack)))))


(defun lyskom-stack->top (stack)
  "Return the topmost element of STACK or nil if it is empty."
  (car-safe (cdr stack)))


(defun lyskom-stack->length (stack)
  "Return the number of elements on STACK."
  (length (cdr stack)))


(defun lyskom-stack->nth (stack n)
  "Return element no (second arg) N of the stack (first arg) STACK.
N counts from zero. If the length of STACK is less than N, nil is returned."
  (nth n (cdr stack)))


(defun lyskom-stack->all-entries (stack)
  "Return a list of all entries in STACK.
The element last pushed is first in the list."
  (cdr stack))


David Byers's avatar
David Byers committed
460
(defsubst lyskom-stack-isempty (stack)
Linus Tolke Y's avatar
Linus Tolke Y committed
461 462 463 464
  "Returns non-nil if the STACK is empty."
  (not (cdr stack)))


Per Cederqvist's avatar
.  
Per Cederqvist committed
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
;;; ================================================================
;;;                          who-buffer-info

;;; Author: Inge Wallin


;;; Constructor:

(defun lyskom-create-who-buffer-info (info
				      start-marker
				      end-marker)
  "Create a who-buffer-info from all parameters."
  (cons
   'WHO-BUFFER-INFO
   (vector info start-marker end-marker )))


;;; Selectors:

(defun who-buffer-info->info (who-buffer-info)
  "Get info from who-buffer-info."
  (elt (cdr who-buffer-info) 0))

(defun who-buffer-info->start-marker (who-buffer-info)
  "Get start-marker from who-buffer-info."
  (elt (cdr who-buffer-info) 1))

(defun who-buffer-info->end-marker (who-buffer-info)
  "Get end-marker from who-buffer-info."
  (elt (cdr who-buffer-info) 2))


;;; Modifiers:

(defun set-who-buffer-info->info (who-buffer-info newval)
  "Set info in who-buffer-info to NEWVAL."
  (aset (cdr who-buffer-info) 0 newval))

(defun set-who-buffer-info->start-marker (who-buffer-info newval)
  "Set start-marker in who-buffer-info to NEWVAL."
  (aset (cdr who-buffer-info) 1 newval))

(defun set-who-buffer-info->end-marker (who-buffer-info newval)
  "Set end-marker in who-buffer-info to NEWVAL."
  (aset (cdr who-buffer-info) 2 newval))



;;; Predicate:

(defun lyskom-who-buffer-info-p (object)
  "Return t if OBJECT is a who-buffer-info."
  (eq (car-safe object) 'WHO-BUFFER-INFO))


;;; ================================================================
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
;;;			format-props

(defun make-format-props (arg propl)
  (cons 'format-props (vector arg propl)))

(defsubst format-props-p (arg)
  (eq 'format-props (car-safe arg)))

(defsubst format-props->arg (arg)
  (elt (cdr arg) 0))

(defsubst format-props->propl (arg)
  (elt (cdr arg) 1))

;;;
;;;	Help functions
;;;



;;; ================================================================
;;;			format-state

(defun make-format-state (format-string
			  start
			  argl
547
			  result)
548
  (cons 'format-state
549
	(vector format-string start argl (length argl) result nil nil)))
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

(defsubst format-state-p (arg)
  (eq 'format-state (car-safe arg)))

(defsubst format-state->format-string (arg)
  (elt (cdr arg) 0))

(defsubst set-format-state->format-string (arg str)
  (aset (cdr arg) 0 str))

(defsubst format-state->start (arg)
  (elt (cdr arg) 1))

(defsubst set-format-state->start (arg pos)
  (aset (cdr arg) 1 pos))

(defsubst format-state->args (arg)
  (elt (cdr arg) 2))

(defsubst set-format-state->args (arg argl)
  (aset (cdr arg) 2 argl)
  (aset (cdr arg) 3 (length argl)))

(defsubst format-state->args-length (arg)
  (elt (cdr arg) 3))

(defsubst format-state->result (arg)
  (elt (cdr arg) 4))

(defsubst set-format-state->result (arg output-list)
  (aset (cdr arg) 4 output-list))

(defsubst format-state->delayed-propl (arg)
  (elt (cdr arg) 5))

(defsubst set-format-state->delayed-propl (arg propl)
  (aset (cdr arg) 5 propl))

588 589 590 591 592 593
(defsubst format-state->delayed-content (arg)
  (elt (cdr arg) 6))

(defsubst set-format-state->delayed-content (arg string)
  (aset (cdr arg) 6 string))

594
;;; ================================================================
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653


;;; ======================================================================
;;;
;;; collector
;;;

;;; A collector is used when a handler needs to pass information
;;; back to a function using asynchronous calls. You could use
;;; dynamically scoped variables, but that causes problems when
;;; the user quits before all handlers have been called since the
;;; result variable will be out of scope for the remaining handlers.
;;; The best-case scenario will be a crash. The worst-case scenario
;;; is when the handler clobbers another variable with the same name
;;; that has come into scope.
;;;
;;; So, so collect a number of results, do the following:
;;;
;;;    (setq <result> (make-collector))
;;;    (<loop-function>
;;;        (initiate-<någonting> '<queue> <function> <argl> <result>))
;;;    (lyskom-wait-queue '<queue>)
;;;    (<use> (collector->value <result>))
;;;
;;; where function is something like this:
;;;
;;;    (defun <funktion> (data-från-servern collector)
;;;        (set-collector->value collector
;;;                              (cons (<behandla> data-från-servern)
;;;                                    (collector->value collector))))
;;;
;;; or shorter,
;;;
;;;    (defun <funktion> (data-från-servern collector)
;;;        (collector-push (<behandla> data-från-servern)))
;;;
;;; This sidestepping protects the handler from scope changes.
;;;


(defun make-collector ()
  "Create a data type for collecting asynchronous results safely"
  (cons 'COLLECTOR nil))

(defsubst collector->value (collector)
  "Get the current value of a collector"
  (cdr collector))

(defsubst set-collector->value (collector value)
  "Set the calue of a collector"
  (setcdr collector value))

(defun set-value-of-collector (value collector)
  "For use with lyskom handlers. In other cases, use set-collector->value"
  (set-collector->value collector value))

(defun collector-push (value collector)
  "Push VALUE onto the front of COLLECTOR's value"
  (setcdr collector (cons value (cdr collector))))
David Kågedal's avatar
David Kågedal committed
654 655


656
(eval-and-compile (provide 'lyskom-clienttypes))
David Kågedal's avatar
David Kågedal committed
657 658

;;; clienttypes.el ends here