1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* +-------------------------------------------------------+
* | |
* | videogen |
* | |
* | a simple XFree86 Modeline calculator |
* | (c) 1997-2002, Szabolcs Rumi |
* | |
* | http://www.rtfm.hu/videogen |
* | |
* | the videogen package is distributed under the |
* | GNU General Public License Version 2 (GPLv2) |
* | |
* +-------------------------------------------------------+
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include "config.h"
#include "videogen.h"
int
pmsg (int vlevel, char *fmt, ...)
{
va_list vl;
int printed = 0;
va_start (vl, fmt);
if (vlevel <= verbose)
printed = vfprintf (stderr, fmt, vl);
#ifdef DEBUG
if (vlevel == 2)
printed = vfprintf (stderr, fmt, vl);
#endif
va_end (vl);
return (printed);
}
char *
tpathexp (char *tpath, char *expath)
{
char uname[16];
unsigned int pos = 0;
struct passwd *pw;
if ((tpath == NULL) || (strlen (tpath) == 0) || (tpath[0] != '~'))
strcpy (expath, tpath);
else
{
while ((tpath[1 + pos] != '\0') && (tpath[1 + pos] != '/'))
{
uname[pos] = tpath[1 + pos];
pos++;
}
uname[pos] = '\0';
if (pos > 0)
{
if ((pw = getpwnam ((char *)&uname)) == NULL)
strcpy (expath, tpath);
else
{
strcpy (expath, pw->pw_dir);
strcat (expath, (char *)(tpath + pos + 1));
}
}
else
{
if ((pw = getpwuid (getuid ())) == NULL)
strcpy (expath, tpath);
else
{
strcpy (expath, pw->pw_dir);
strcat (expath, (char *)(tpath + pos + 1));
}
}
}
return (expath);
}
/* EOF */
|