added make_user_path to compute path relative to user HOME directory
This commit is contained in:
parent
5c678f0236
commit
c1833a2f53
2 changed files with 23 additions and 2 deletions
3
qe.h
3
qe.h
|
|
@ -2,7 +2,7 @@
|
|||
* QEmacs, tiny but powerful multimode editor
|
||||
*
|
||||
* Copyright (c) 2000,2001 Fabrice Bellard.
|
||||
* Copyright (c) 2000-2008 Charlie Gordon.
|
||||
* Copyright (c) 2000-2013 Charlie Gordon.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -195,6 +195,7 @@ void find_file_close(FindFileState *s);
|
|||
int is_directory(const char *path);
|
||||
void canonicalize_path(char *buf, int buf_size, const char *path);
|
||||
void canonicalize_absolute_path(char *buf, int buf_size, const char *path1);
|
||||
char *make_user_path(char *buf, int buf_size, const char *path);
|
||||
char *reduce_filename(char *dest, int size, const char *filename);
|
||||
int match_extension(const char *filename, const char *extlist);
|
||||
int remove_slash(char *buf);
|
||||
|
|
|
|||
22
util.c
22
util.c
|
|
@ -2,7 +2,7 @@
|
|||
* Utilities for qemacs.
|
||||
*
|
||||
* Copyright (c) 2001 Fabrice Bellard.
|
||||
* Copyright (c) 2002-2008 Charlie Gordon.
|
||||
* Copyright (c) 2002-2013 Charlie Gordon.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
|
@ -280,6 +280,26 @@ void canonicalize_absolute_path(char *buf, int buf_size, const char *path1)
|
|||
canonicalize_path(buf, buf_size, path1);
|
||||
}
|
||||
|
||||
/* reduce path relative to homedir */
|
||||
char *make_user_path(char *buf, int buf_size, const char *path)
|
||||
{
|
||||
char *homedir;
|
||||
|
||||
homedir = getenv("HOME");
|
||||
if (homedir) {
|
||||
int len = strlen(homedir);
|
||||
|
||||
if (len && homedir[len - 1] == '/')
|
||||
len--;
|
||||
|
||||
if (!memcmp(path, homedir, len) && path[len] == '/') {
|
||||
pstrcpy(buf, buf_size, "~");
|
||||
return pstrcat(buf, buf_size, path + len);
|
||||
}
|
||||
}
|
||||
return pstrcpy(buf, buf_size, path);
|
||||
}
|
||||
|
||||
char *reduce_filename(char *dest, int size, const char *filename)
|
||||
{
|
||||
const char *base = get_basename(filename);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue