🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
1 messages
1 total messages Started by John E. Davis Mon, 27 Apr 1998 00:00
Re: slrn: Parsing variables ?
#40457
Author: 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

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads