lynx-dev
[Top][All Lists]
Advanced

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

Re: LYNX-DEV Lynx W32 bug report


From: Alan Cox
Subject: Re: LYNX-DEV Lynx W32 bug report
Date: Fri, 7 Mar 1997 10:39:31 +0000 (GMT)

>       ~buttles/       depends on server setting, eg, html docs directory?
>       ~/              UNIX convention for environment variable $HOME?
> 
> I'll try to do some study tonight or tomorrow morning.

Try the following code: The routine does the relevant expansion and provides
you with the expansion string and a pointer to the first character after the
expansion in the original.


/* (C) Copyright 1997, Alan Cox. All Rights Reserved
   This software is licensed under the GNU Public License.
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <pwd.h>

/*
 *      Given a string expands the ~ value returning the expansion string
 *      (read only will be destroyed by future calls) and setting *p to
 *      point to the character after the expansion. The original string is
 *      damaged but restored by the call. ie Dont feed it a const char *
 */

static char *twiddlet(char **p)
{
        char *s=*p;     /* String */
        char *e;
        struct passwd *pw;
        
        if(*s!='~')
                return "";
        
        /* Ok its ~.. */
        
        if(s[1]=='/'||s[1]=='\0')
        {
                char *t=getenv("HOME");
                if(t)
                {
                        *p=s+1;
                        return t;
                }
                return "";      /* Couldnt expand */
        }
        e=strchr(s,'/');
        if(e)
                *e=0;
        pw=getpwnam(s+1);
        if(e)
                *e='/';
        if(pw==NULL)
        {
                return "";
        }
        if(e)
                *p=e;   /* Go from the / onwards */
        else
                *p=s+strlen(s); /* Go from the string end */
        return pw->pw_dir;
}

                
void main()
{
        char buf[256];
        char *bp=buf;
        char *t;
        printf(">> ");
        gets(buf);
        t=twiddlet(&bp);
        printf("%s%s\n", t,bp);
}
;
; To UNSUBSCRIBE:  Send a mail message to address@hidden
;                  with "unsubscribe lynx-dev" (without the
;                  quotation marks) on a line by itself.
;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]