Function: eudc-ph-parse-query-result

eudc-ph-parse-query-result is a byte-compiled function defined in eudcb-ph.el.gz.

Signature

(eudc-ph-parse-query-result &optional FIELDS)

Documentation

Return a list of alists of key/values from in eudc-ph-process-buffer.

Fields not in FIELDS are discarded.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/eudcb-ph.el.gz
(defun eudc-ph-parse-query-result (&optional fields)
  "Return a list of alists of key/values from in `eudc-ph-process-buffer'.
Fields not in FIELDS are discarded."
  (let (record
	records
	line-regexp
	current-key
	key
	value
	ignore)
    (save-excursion
      (message "Parsing results...")
      (set-buffer eudc-ph-process-buffer)
      (goto-char (point-min))
      (while (re-search-forward "^\\(-[0-9]+\\):\\([0-9]+\\):" nil t)
	(catch 'ignore
	  (setq line-regexp (concat "^\\(-[0-9]+\\):" (match-string 2) ":[ \t]*\\([-a-zA-Z_]*\\)?:[ \t]*\\(.*\\)$"))
	  (beginning-of-line)
	  (setq record nil
		ignore nil
		current-key nil)
	  (while (re-search-forward line-regexp nil t)
	    (catch 'skip-line
	      (if (string= "-508" (match-string 1))
		  ;; A field is missing in this entry.  Skip it or skip the
		  ;; whole record (see `eudc-strict-return-matches')
		  (if (not eudc-strict-return-matches)
		      (throw 'skip-line t)
		    (while (re-search-forward line-regexp nil t))
		    (setq ignore t)
		    (throw 'ignore t)))
	      (setq key   (and (not (string= (match-string 2) ""))
			       (intern (match-string 2)))
		    value (match-string 3))
	      (if (and current-key
		       (eq key current-key))
		  (setq key nil)
		(setq current-key key))
	      (if (or (null fields)
		      (eq 'all fields)
		      (memq current-key fields))
		  (if key
		      (setq record (cons (cons key value) record)) ; New key
		    (setcdr (car record) (if (listp (cdar record))
					     (append (cdar record) (list value))
					   (list (cdar record) value))))))))
	(and (not ignore)
	     (or (null fields)
		 (eq 'all fields)
		 (setq record (nreverse record)))
	     (setq record (if (not (eq 'list eudc-duplicate-attribute-handling-method))
			      (eudc-filter-duplicate-attributes record)
			    (list record)))
	     (setq records (append record records)))))
    (message "Done")
    records))