[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgreek:00025] Re: More tlg utilities



>>>>> "Shinsuke" == Shinsuke Kawazoe <skawazoe@xxxxxxxxxxxxxxxxx> writes:

    Shinsuke> But, on *TLG Author List*, I couldn't open correctly
    Shinsuke> *Works in tlg0086.idt* buffer. by M-w. I got the
    Shinsuke> following messages in the buffer(my HOME directory is
    Shinsuke> "i:/");

    Shinsuke> 	2 elements left after parsing options: first
    Shinsuke> i:/tlg/tlg0693.idt Filename changed to
    Shinsuke> i:/tlg/tlg0693.idt lc_g2 changed to 243

This is output from tlgcites2emacs.  Though I directed this to stderr,
it is really just an informational message.  It occurs when tlgcites2emacs
finds command line options in the form that Takahashi's tlg2emacs
expects.  If you can redirect stderr to the Windows equivalent of
/dev/null, this message will disappear.  

There are two other fixes
possible.  First, you can make sure that tlgcites2emacs is always being
called with my syntax instead of Takahashi's.  That requires changing
these lines in cgreek-find-file-tlg-with-cites (my addition to
Takahashi's code):

 (shell-command
       (format "%s %s %d"     ;;;CHANGE THIS ONE
	       cgreek-tlg-cites-converter-program
	       filename
	       (charset-id 'cgreek))
       t))

Change the format string from "%s %s %s" to:
       "%s -f %s -l %d"

A more comlicated solution is to  modify
tlg-citations.lex as follows to kill the error message.  Look for these
lines (1508-1511 in the latest version):

   /* First consume a filename */
    if (argc-arg>0) {
      fprintf(stderr,"%d elements left after parsing options: first %s\n",argc-arg,argv[arg]);

      /* The next option MUST be a filename (including '|' for stdin). */

Then just comment out the code, i.e. do this:
/*    if (argc-arg>0) {   */
/*      fprintf(stderr,"%d elements left after parsing options: first %s\n",argc-arg,argv[arg]); */

Then do another "make tlgutil".  

    Shinsuke> and in the minibuffer;

    Shinsuke>        Symbol's value as variable is void: elements

Same problem: emacs is trying to evaluate the message.

    Shinsuke> Besides, while converting tlg file simply by

    Shinsuke> 	 cgreek-find-file-tlg-with-cites

    Shinsuke> I found the following message at the top of the buffer
    Shinsuke> for the converted text;

    Shinsuke> 	  2 elements left after parsing options: first
    Shinsuke> i:/tlg/tlg0086.txt Filename changed to
    Shinsuke> i:/tlg/tlg0086.txt lc_g2 changed to 243

The previously described fix will handle this.

    Shinsuke> and the citations symbols found at the left of the
    Shinsuke> buffer are utterly unreadable, though greek characters
    Shinsuke> are correctly converted.

Well, this is my fault.  I have temporarily neglected the use of
tlgcites2emacs for any purpose except providing input to tlg-open-single-work.
Those strings at the beginnings of lines are encoded citation values:
the format is 
  "<level n value>^N<level v>^V<level w>^W<level x>^X<level y>^Y^N<level z>^Z"
Not very imaginative.  I need to reinsert a command line flag to suppress this
output and print plain citations in the text.  (The code for this is still
in there, but it's currently bypassed).  I'll get a temporary repair out
today or tomorrow if I have the time.  The quickest fix would be do define
a little function (in cgreek-util) that does a regexp search-and-replace
on all these strings, though that's probably going to take a little time
to run on long files.  Here's a first trial (at least it works):

(defun tlg-replace-citation-strings ()
  "Replace cryptic citation strings in the output of tlgcites2emacs
with something readable by humans."
  (interactive)  
   (while (and (<= (point) (point-max)) 
	      (re-search-forward "^\\(.*\\)\\(.*\\)\\(.*\\)\\(.*\\)\\(.*\\)\\(.*\\)" (point-max) t))
      (let ((ref (concat  
                (buffer-substring (match-beginning 1) (match-end 1))
	        "." (buffer-substring (match-beginning 2) (match-end 2))
	        "." (buffer-substring (match-beginning 3) (match-end 3))
	        "." (buffer-substring (match-beginning 4) (match-end 4))
	        "." (buffer-substring (match-beginning 5) (match-end 5))
	        "." (buffer-substring (match-beginning 6) (match-end 6))
		"\t")
              ))
           (replace-match "")
	   (insert ref)))
   (goto-char (point-min))
  )

Add this to tlg-find-file-with-cites, preferably just before the
final (switch-to-buffer (buf)).  Just for clarity, these changes will 
leave tlg-find-file-with-cites looking like this:


(defun cgreek-find-file-tlg-with-cites (filename)
  "Open file FILENAME encoded in the TLG format.
Switch to a buffer visiting file FILENAME,
creating one if non already exists."
  (interactive "FFind file: ")
  (let ((buf (generate-new-buffer (file-name-nondirectory filename))))
    (set-buffer buf)
    (toggle-enable-multibyte-characters)
    (let ((coding-system-for-read 'no-conversion))
      (shell-command
       (format "%s -f %s -l %d"
	       cgreek-tlg-cites-converter-program
	       filename
	       (charset-id 'cgreek))
       t))
    (toggle-enable-multibyte-characters)
    (goto-char (point-min))
    (cgreek-tlg-replace-citation-strings)
    (switch-to-buffer buf)))


The output is not nicely formatted (just reference values separated
by dots, with two spaces at the end); better formatting should be possible.
It takes a little time (nearly 2 minutes of CPU time on my 400MHz PII to
do all of Aristotle).  But it does work.

My sincerest apologies for making this so hard. Then again,