[Ecls-list] dpp.lisp : do we really nead the filename with the lineno directives?

Sean Champ schamp at users.sourceforge.net
Sun Mar 9 17:12:19 UTC 2003


Hi.

I started working on a lisp version of dpp today; encountered some problems,
thoguh, with how I was trying to do it.

Below, at the end of this email, is what I have so far. It's not much at
all; it's meant for illustrating the root of this question.

The main question I have is: when given this, from dpp.c


162: put_lineno(void)
163: {
164:	static int flag = 0;
165:	if (flag)
166:		fprintf(out, "#line %d\n", lineno);
167:	else {
168:		flag++;
169:		fprintf(out, "#line %d \"%s\"\n", lineno, filename);
170:	}
171: }


...do we really need the 'filename' part of
    fprintf(out, "#line %d \"%s\"\n", lineno, filename);
for anywhere but at the top of the generated file?


I haven't noticed the filename being used anywhere in what dpp puts out,
besides at the top of the file:

  #line 1 "/mnt/src/ecl/ecl/src/c/symbol.d"

so, everwhere else, can we just keep it at a simple
  (format output "#line ~d~%" lineno)
and move on? thank you.


--
sean
schamp at users.sourceforge.net





;; dpp.lisp -- incomplete, yet -- follows.


(defpackage dpp
    (:use :COMMON-LISP))

(in-package :dpp)

;;; Notes.

;; We don't need to worry about using a unique readtable.
;; We'll just scan for the special token '@' in the input.



;;; main operations

(defun process-file (input &optional (output *STANDARD-OUTPUT*))
  ;; This is a wrapper for PROCESS-STREAM
  ;;
  ;; This function opens INPUT and/or OUTPUT, when one or both is not a
  ;; stream. It then proceeds to use the INPUT and OUTPUT streams as the
  ;; arguments to PROCESS-STREAM. 
  
  (declare (type (or string pathname stream (member t nil)) input output))
  (let (innewp outnewp)
    (declare (type (member t nil) innewp outnewp))
    ;; innnewp and outnewp are 'flags', which indicate, respectively,
    ;; whether we've opened a new stream for INPUT or OUTPUT in the block of
    ;; this function.
    ;; we use those in deciding whether or not to close the stream before
    ;; return. 
    (unless (typep input stream)
      (setq input (open input :direction :input
			:if-does-not-exist :error)
	    innewp t))
    (unless (typep output stream)
      (setq output (open output :direction :output
			 :if-does-not-exist :create
			 :if-exists :error)
	    outnewp t))
    (unwind-protect
	 (process-stream input output)
      (when innewp (close input))
      (when outnewp (close output)))))


(defun process-stream (input &optional (output *STANDARD-OUTPUT*))
  (declare (type (or stream (member t nil)) input output))
  (let ((lineno 1) ;; starting at one ??
	(filename) ;; ??? 
	char)
    (loop
      (setq char (read-char input nil :EOF))
      (case char
	(:EOF (return))
	
	(#\Newline
	 (incf lineno)
	 (write-char char output))
	
	;; we need to write something like:
	;;  (format output "#line ~d~@[ ~s~]~%" lineno filename)
	;; but not on every single line...
	;; and do we really need the 'filename' ?

	(#\@
	 ;; here's where the work needs to be completed
	 )
	
	(t (write-char char output))))))





More information about the ecl-devel mailing list