From b77cd310cba024bf2ceb591bb107b204ac039b7e Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 17 Dec 2001 19:29:25 +0000 Subject: Added expandFilename --- src/misc.cc | 17 +++++++++++++++++ src/misc.hh | 1 + 2 files changed, 18 insertions(+) diff --git a/src/misc.cc b/src/misc.cc index 728c5ae..809dc24 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -27,6 +27,7 @@ #include #include #include + using namespace std; //------- strdup ------------------------ @@ -39,6 +40,22 @@ char *Misc::strdup(const char *s) { return n; } +//------------- expandFilename ---------------------- +// if ~ then expand it to home of user +// returns expanded filename +// (note: the function creates new memory for the string) +//--------------------------------------------------- +char *Misc::expandFilename(const char *filename) { + char retval[strlen(filename)+strlen(getenv("HOME"))+2]; //2 extra byte just to be safe + retval[0]=0; //mark end + if (filename[0]=='~') { + strcat(retval, getenv("HOME")); + strcat(retval, &filename[1]); + } else + return Misc::strdup(filename); //return unmodified value + + return Misc::strdup(retval); //return modified value +} // ---------------------------------------------------------------------- // xvertext, Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) diff --git a/src/misc.hh b/src/misc.hh index b0593da..6d3a66c 100644 --- a/src/misc.hh +++ b/src/misc.hh @@ -43,6 +43,7 @@ public: } Font; static char *strdup(const char *); +static char *expandFilename(const char *filename); static void DrawString(Display *display, Window w, GC gc, Misc::Font *font, unsigned int text_w, unsigned int size_w, -- cgit v0.11.2