Jump to content

Parsing a CSV instead of ASCII dos text file.


Michael Richards

Recommended Posts

(defun PARSEFILE ()
  (setq NOTEFILE (open LIB1 "rt"))
  (if NOTEFILE
    (progn
      (princ "\nReading note file. ")
      (setq WORKINGNOTE nil)
      (while (setq NEWLINE (read-line NOTEFILE))
	(progn
	  ;
	  ;delete trailing spaces
	  ;
	  (while (and (> (strlen NEWLINE) 0) (= (substr NEWLINE (strlen NEWLINE)) " "))
	    (setq NEWLINE (substr NEWLINE 1 (1- (strlen NEWLINE))))
	  );end while  
	  (if (/= NEWLINE "")
	    (progn
	      ;
	      ;find keynote number
	      ;
	      (setq I 1)
              (while (and (< I (strlen NEWLINE)) (/= (substr NEWLINE I 1) " "))
                (setq I (+ I 1))
              );end while
	      (if (> I 1)
	        (progn
	          (setq WORKINGNOTE (substr NEWLINE 1 (1- I)))
	          (setq WORKINGNOTE (strcase WORKINGNOTE))
	          (if (not (member WORKINGNOTE IDlist))
		    (setq WORKINGNOTE nil)
	          );end if
	          (setq NEWLINE (substr NEWLINE I))
	        );end progn  
	      );end if
	      ;
	      ;delete leading spaces
	      ;
	      (setq I 1)
	      (while (= (substr NEWLINE I 1) " ")
                (setq I (+ I 1))
              );end while
	      (setq NEWLINE (substr NEWLINE I))
	    );end progn    
	  );end if    
	  (if WORKINGNOTE
	    (progn
	      (setq FOUND "F")
	      (setq TEMPLIST NOTELIST)
	      (setq NOTELIST nil)
	      (foreach THISNOTE TEMPLIST
		(progn
		  (if (and (= FOUND "F") (= WORKINGNOTE (car THISNOTE)))
		    (progn
		      (setq THISNOTE (append THISNOTE (list NEWLINE)))
		      (setq FOUND "T")
		    );end progn
		  );end if
		  (setq NOTELIST (cons THISNOTE NOTELIST))
		);end progn  
	      );end foreach
	      (setq NOTELIST (reverse NOTELIST))
	      (setq TEMPLIST nil)
	    );end progn
	  );end if
	);end progn
      );end while
      (close NOTEFILE)
      ;
      ;delete trailing lines
      ;
      (setq TEMPLIST NOTELIST)
      (setq NOTELIST nil)
      (foreach THISNOTE TEMPLIST
	(progn
	  (setq THISNOTE (reverse THISNOTE))
	  (while (= (car THISNOTE) "")
	    (setq THISNOTE (cdr THISNOTE))
	  );end while
	  (setq THISNOTE (reverse THISNOTE))
	  (setq NOTELIST (cons THISNOTE NOTELIST))
	);end progn
      );end foreach
      (setq NOTELIST (reverse NOTELIST))
      (setq TEMPLIST nil)
      (princ " Done.")
    );end progn
  );end if
);end defun PARSEFILE

This is a small part of a larger routine that was used with wordperfect ascii dos txt files and I am having difficulty changing this function to read and use a csv file

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...