TIP: Click on subject to list as thread! ANSI
echo: qedit
to: ALL
from: `Y.T.LIM`
date: 1997-10-07 11:25:00
subject: Re: Macro Help

From: "Y.T.Lim" 
Hi MingFang,
Try the following. I hope it works for you.
/Y.T.
// -------------------------- cut here
----------------------------------------
/*
 *   Input File  :  current file
 *   Output File :  ##buffer##
 *
 *   Procedure   : 1) compile the macro and execute it, it'll be attached
to
 *                     (modified if needed)
 *                 2) load the file to be processed
 *                 3) press  to execute the macro, the processed
data
 *                    will be stored in buffer named "##buffer##". Use
SaveAs
 *                    to save the file
 *
 */
integer proc InsertAuthors(string s)
	integer p = 0, n = 0
        string t[128] = s
        while (1)
                p = pos(";",t)
                if (p == 0)
                        break
                endif
		InsertText(SubStr(t, 1, p-1))
                BegLine() AddLine()
		n = n + 1  // increment author count
		t = SubStr(t, p+2, length(t))  // truncate first author
        endwhile
	return(n)  // n contains number of authors
end InsertAuthors
proc ParseName()
	integer NumAuthors
        integer CurrId, NewId
	string s[128]  // for AUTHORS
	string d[80]   // for DATE
	string y[5]    // for year
        string buffer[15] = "##buffer##"
        string LineId[15]
        Set(BREAK, ON)
        CurrId = GetBufferId()
        NewId = CreateBuffer(buffer)
        GotoBufferId(CurrId) // return to original file
        BegFile()
       	repeat
       		LineId = GetText(1,6)
       		// handle authors
       		if (LineId == "[AUTHO")
       			s = GetText(11,CurrLineLen()) + ";"
       			GotoBufferId(NewId) // goto output file
       			InsertText("[AUTHORS] ")
       			NumAuthors = InsertAuthors(s)
       		// now handle date
       		elseif (LineId == "[DATE]")
       			EndLine() WordLeft()
       			y = GetWord()
       			d = GetText(1, CurrLineLen())
       			GotoBufferId(NewId) // goto output file
       			InsertText(d)
       			EndLine() WordLeft() WordLeft() EndWord()
       			InsertText(",")
       			BegLine() AddLine()
       			InsertText("[NEWFIELD] ")
       			case NumAuthors
       				when 0 // this should not happen
       					warn("Error: no AUTHORS before DATE")
       				when 1 // 1 author
       					InsertText(SubStr(s, 1, pos(",",s)) + " " + y)
       				when 2 // 2 authors
       					InsertText(SubStr(s, 1, pos(",",s) - 1) + " & ")
       					s = SubStr(s, pos(";", s) + 2, length(s))
       					InsertText(SubStr(s, 1, pos(",",s)) + " " + y)
       				when 3 // 3 authors
       					InsertText(SubStr(s, 1, pos(",", s)) + " ")
       					s = SubStr(s, pos(";", s) + 2, length(s))
       					InsertText(SubStr(s, 1, pos(",",s) - 1) + " & ")
       					s = SubStr(s, pos(";", s) + 2, length(s))
       					InsertText(SubStr(s, 1, pos(",",s)) + " " + y)
       				otherwise  // more than 3 authors
       					InsertText(SubStr(s, 1, pos(",",s)) + " et al., " + y)
       			endcase
       			BegLine() AddLine()
       		endif
       		GotoBufferId(CurrId)  // return to original file to get more text
       	until NOT down()
        GotoBufferId(NewId)  // let's look at the result!
        DelLine()
        BegFile()
end
 ParseName()
// -------------------------- cut here
----------------------------------------
> Hello,
> 
> I am writing to seek assitance in macro for the following tasks. Given my
> limited knowledge of SAL, I'd appreciate any suggestion the TSE community
> can offer.
> 
> A portion of the text would look as follows:
> 
> ...
> [AUTHORS] LastName1, FirstName1; LastName2, FirstName2; LastName3,
FirstName3
> [DATE] August 1997
> ...
> 
> The first task is to move the second and third names to new lines and
> delete the "; ", and the second task is to grab the last names and year
> information from the DATE field to form a new field, so:
> 
> [AUTHORS] LastName1, FirstName1
> LastName2, FirstName2
> LastName3, FirstName3
> [DATE] August, 1997
> [NEWFIELD] LastName1, LastName2 & LastName3, 1997
> 
> Another added complexity is that the number of authors will differ, for
> example, one, two, three, or more than three, the [NEWFIELD] will
therefore
> be different:
> 
> One author: LastName1, 1997
> Two authors: LastName1 & LastName2, 1997
> Three authors: LastName1, LastName2 & LastName3, 1997
> More than three: LastName1, et al., 1997
> 
> Again, I would very much appreciate help on this.
> 
> Thanks in advance.
> 
> Mingfang Li
> 
> =======================================================================
> Mingfang Li, Ph.D.                                  mailto:mli@csun.edu
> Department of Management                           (818) 677-4903 (Fax)
> California State University, Northridge         (818) 677-2421 (Office)
> Northridge, CA 91330-8245 USA                 http://www.csun.edu/~mli/
> ========================================================================
> 
---
---------------
* Origin: apana>>>>>fidonet [sawasdi.apana.org.au] (3:800/846.13)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.