all repos — fluxbox @ b77cd310cba024bf2ceb591bb107b204ac039b7e

custom fork of the fluxbox windowmanager

Added expandFilename
fluxgen fluxgen
commit

b77cd310cba024bf2ceb591bb107b204ac039b7e

parent

dbd3dfac7eb1de576aa66e25a8c765588c29b493

2 files changed, 18 insertions(+), 0 deletions(-)

jump to
M src/misc.ccsrc/misc.cc

@@ -27,6 +27,7 @@ #include <string.h>

#include <stdio.h> #include <iostream> #include <X11/Xutil.h> + using namespace std; //------- strdup ------------------------

@@ -39,6 +40,22 @@ strncpy(n, s, l);

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)
M src/misc.hhsrc/misc.hh

@@ -43,6 +43,7 @@ FontJustify justify;

} 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,