Changeset f36222f


Ignore:
Timestamp:
Dec 6, 2003, 9:13:39 PM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
88ca489
Parents:
a68f05d
Message:
Do ~ expansion in 'dump' command.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    ra68f05d rf36222f  
    88        Command line arg -D turns on debugging and deletes previous
    99          debugging file
     10        Do ~ expansion in 'dump' command.
    1011       
    11122.0.13
  • commands.c

    rc1be0c6 rf36222f  
    10831083char *owl_command_dump(int argc, char **argv, char *buff)
    10841084{
     1085  char *filename;
     1086 
    10851087  if (argc!=2) {
    10861088    owl_function_makemsg("usage: dump <filename>");
    10871089    return(NULL);
    10881090  }
    1089 
    1090   owl_function_dump(argv[1]);
     1091  filename=owl_util_makepath(argv[1]);
     1092  owl_function_dump(filename);
     1093  owl_free(filename);
    10911094  return(NULL);
    10921095}
  • functions.c

    rd9b0b972 rf36222f  
    31203120}
    31213121
     3122/* Dump messages in the current view to the file 'filename'. */
    31223123void owl_function_dump(char *filename)
    31233124{
     
    31263127  owl_view *v;
    31273128  FILE *file;
     3129
    31283130  /* struct stat sbuf; */
    31293131
     
    31523154  }
    31533155  fclose(file);
     3156  owl_function_makemsg("Messages dumped to %s", filename);
    31543157}
    31553158
  • util.c

    r12c35df rf36222f  
    44#include <unistd.h>
    55#include <ctype.h>
     6#include <pwd.h>
    67
    78static const char fileIdent[] = "$Id$";
     
    175176  }
    176177  return buff;
     178}
     179
     180/* Return a "nice" version of the path.  Tilde expansion is done, and
     181 * duplicate slashes are removed.  Caller must free the return.
     182 */
     183char *owl_util_makepath(char *in)
     184{
     185  int i, j, x;
     186  char *out, user[MAXPATHLEN];
     187  struct passwd *pw;
     188
     189  out=owl_malloc(MAXPATHLEN+1);
     190  out[0]='\0';
     191  j=strlen(in);
     192  x=0;
     193  for (i=0; i<j; i++) {
     194    if (in[i]=='~') {
     195      if ( (i==(j-1)) ||          /* last character */
     196           (in[i+1]=='/') ) {     /* ~/ */
     197        /* use my homedir */
     198        pw=getpwuid(getuid());
     199        if (!pw) {
     200          out[x]=in[i];
     201        } else {
     202          out[x]='\0';
     203          strcat(out, pw->pw_dir);
     204          x+=strlen(pw->pw_dir);
     205        }
     206      } else {
     207        /* another user homedir */
     208        int a, b;
     209        b=0;
     210        for (a=i+1; i<j; a++) {
     211          if (in[a]==' ' || in[a]=='/') {
     212            break;
     213          } else {
     214            user[b]=in[a];
     215            i++;
     216            b++;
     217          }
     218        }
     219        user[b]='\0';
     220        pw=getpwnam(user);
     221        if (!pw) {
     222          out[x]==in[i];
     223        } else {
     224          out[x]='\0';
     225          strcat(out, pw->pw_dir);
     226          x+=strlen(pw->pw_dir);
     227        }
     228      }
     229    } else if (in[i]=='/') {
     230      /* check for a double / */
     231      if (i<(j-1) && (in[i+1]=='/')) {
     232        /* do nothing */
     233      } else {
     234        out[x]=in[i];
     235        x++;
     236      }
     237    } else {
     238      out[x]=in[i];
     239      x++;
     240    }
     241  }
     242  out[x]='\0';
     243  return(out);
    177244}
    178245
Note: See TracChangeset for help on using the changeset viewer.