🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #40457

Re: slrn: Parsing variables ?

#40457
From: John E. Davis
Date: Mon, 27 Apr 1998 00:00
61 lines
1831 bytes
On 27 Apr 1998 14:58:57 EDT, Vikas Agnihotri <vikasa@att.com>
wrote:
>I have
>set save_posts "mail/Usenet"
>
>How do I extract the string "Usenet" from the above variable using
>get_variable_value()? Sort of like the 'basename' command in shell
>scripting.

There are many ways.  Perhaps I should distribute a few macros for
these common tasks.  Here is a macro that may work:

% Usage: (dir, name, ext) = parse_filename (file);
define parse_filename (file)
{
   variable dir, name, ext;
   variable n;
   variable tmp;

   n = strchop (file, '/', 0);
   name = ();
   dir = "";
   loop (n - 1)
     {
	tmp = ();
	dir = tmp + "/" + dir;
     }

   ext = "";
   n = strchopr (name, '.', 0);
   name = ();
   loop (n - 2)
     {
	tmp = ();
	name += "." + tmp;
     }
   
   if (n > 1)
     {
	ext = ();
	ext = "." + ext;
     }
   
   return (dir, name, ext);
}
   
define basename (file)
{
   variable b;
   
   (,b,) = parse_filename (file);
   return b;
}

-- 
John E. Davis                   Center for Space Research/AXAF Science Center
617-258-8119                    One Hampshire St., Building NE80-6019
http://space.mit.edu/~davis     Cambridge, MA  02139-4307

Technical Details
Message-ID: <slrn6k9s2u.e4m.davis@aluche.mit.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <slrn6k9lbi.n5d.vikasa@8080b0da.ims.att.com>

Show Full Headers
Complete Article Headers
Message-ID: <slrn6k9s2u.e4m.davis@aluche.mit.edu>
Subject: Re: slrn: Parsing variables ?
Date: Mon, 27 Apr 1998 00:00:00 +0000
From: davis@space.mit.edu (John E. Davis)
References: <slrn6k9lbi.n5d.vikasa@8080b0da.ims.att.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 348194762
Organization: Center for Space Research
Reply-To: davis@space.mit.edu
Newsgroups: news.software.readers