mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-06 13:54:12 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
512
WINGs/findfile.c
512
WINGs/findfile.c
@@ -18,7 +18,6 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "wconfig.h"
|
||||
|
||||
#include "WUtil.h"
|
||||
@@ -33,155 +32,142 @@
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
|
||||
char*
|
||||
wgethomedir()
|
||||
char *wgethomedir()
|
||||
{
|
||||
char *home = getenv("HOME");
|
||||
struct passwd *user;
|
||||
char *home = getenv("HOME");
|
||||
struct passwd *user;
|
||||
|
||||
if (home)
|
||||
return home;
|
||||
if (home)
|
||||
return home;
|
||||
|
||||
user = getpwuid(getuid());
|
||||
if (!user) {
|
||||
wsyserror(_("could not get password entry for UID %i"), getuid());
|
||||
return "/";
|
||||
}
|
||||
if (!user->pw_dir) {
|
||||
return "/";
|
||||
} else {
|
||||
return user->pw_dir;
|
||||
}
|
||||
user = getpwuid(getuid());
|
||||
if (!user) {
|
||||
wsyserror(_("could not get password entry for UID %i"), getuid());
|
||||
return "/";
|
||||
}
|
||||
if (!user->pw_dir) {
|
||||
return "/";
|
||||
} else {
|
||||
return user->pw_dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
getuserhomedir(char *username)
|
||||
static char *getuserhomedir(char *username)
|
||||
{
|
||||
struct passwd *user;
|
||||
struct passwd *user;
|
||||
|
||||
user = getpwnam(username);
|
||||
if (!user) {
|
||||
wsyserror(_("could not get password entry for user %s"), username);
|
||||
return NULL;
|
||||
}
|
||||
if (!user->pw_dir) {
|
||||
return "/";
|
||||
} else {
|
||||
return user->pw_dir;
|
||||
}
|
||||
user = getpwnam(username);
|
||||
if (!user) {
|
||||
wsyserror(_("could not get password entry for user %s"), username);
|
||||
return NULL;
|
||||
}
|
||||
if (!user->pw_dir) {
|
||||
return "/";
|
||||
} else {
|
||||
return user->pw_dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char*
|
||||
wexpandpath(char *path)
|
||||
char *wexpandpath(char *path)
|
||||
{
|
||||
char buffer2[PATH_MAX+2];
|
||||
char buffer[PATH_MAX+2];
|
||||
int i;
|
||||
char buffer2[PATH_MAX + 2];
|
||||
char buffer[PATH_MAX + 2];
|
||||
int i;
|
||||
|
||||
memset(buffer, 0, PATH_MAX+2);
|
||||
memset(buffer, 0, PATH_MAX + 2);
|
||||
|
||||
if (*path=='~') {
|
||||
char *home;
|
||||
if (*path == '~') {
|
||||
char *home;
|
||||
|
||||
path++;
|
||||
if (*path=='/' || *path==0) {
|
||||
home = wgethomedir();
|
||||
strcat(buffer, home);
|
||||
} else {
|
||||
int j;
|
||||
j = 0;
|
||||
while (*path!=0 && *path!='/') {
|
||||
buffer2[j++] = *path;
|
||||
buffer2[j] = 0;
|
||||
path++;
|
||||
}
|
||||
home = getuserhomedir(buffer2);
|
||||
if (!home)
|
||||
return NULL;
|
||||
strcat(buffer, home);
|
||||
}
|
||||
}
|
||||
path++;
|
||||
if (*path == '/' || *path == 0) {
|
||||
home = wgethomedir();
|
||||
strcat(buffer, home);
|
||||
} else {
|
||||
int j;
|
||||
j = 0;
|
||||
while (*path != 0 && *path != '/') {
|
||||
buffer2[j++] = *path;
|
||||
buffer2[j] = 0;
|
||||
path++;
|
||||
}
|
||||
home = getuserhomedir(buffer2);
|
||||
if (!home)
|
||||
return NULL;
|
||||
strcat(buffer, home);
|
||||
}
|
||||
}
|
||||
|
||||
i = strlen(buffer);
|
||||
i = strlen(buffer);
|
||||
|
||||
while (*path!=0) {
|
||||
char *tmp;
|
||||
while (*path != 0) {
|
||||
char *tmp;
|
||||
|
||||
if (*path=='$') {
|
||||
int j = 0;
|
||||
path++;
|
||||
/* expand $(HOME) or $HOME style environment variables */
|
||||
if (*path=='(') {
|
||||
path++;
|
||||
while (*path!=0 && *path!=')') {
|
||||
buffer2[j++] = *(path++);
|
||||
buffer2[j] = 0;
|
||||
}
|
||||
if (*path==')')
|
||||
path++;
|
||||
tmp = getenv(buffer2);
|
||||
if (!tmp) {
|
||||
buffer[i] = 0;
|
||||
strcat(buffer, "$(");
|
||||
strcat(buffer, buffer2);
|
||||
strcat(buffer, ")");
|
||||
i += strlen(buffer2)+3;
|
||||
} else {
|
||||
strcat(buffer, tmp);
|
||||
i += strlen(tmp);
|
||||
}
|
||||
} else {
|
||||
while (*path!=0 && *path!='/') {
|
||||
buffer2[j++] = *(path++);
|
||||
buffer2[j] = 0;
|
||||
}
|
||||
tmp = getenv(buffer2);
|
||||
if (!tmp) {
|
||||
strcat(buffer, "$");
|
||||
strcat(buffer, buffer2);
|
||||
i += strlen(buffer2)+1;
|
||||
} else {
|
||||
strcat(buffer, tmp);
|
||||
i += strlen(tmp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buffer[i++] = *path;
|
||||
path++;
|
||||
}
|
||||
}
|
||||
if (*path == '$') {
|
||||
int j = 0;
|
||||
path++;
|
||||
/* expand $(HOME) or $HOME style environment variables */
|
||||
if (*path == '(') {
|
||||
path++;
|
||||
while (*path != 0 && *path != ')') {
|
||||
buffer2[j++] = *(path++);
|
||||
buffer2[j] = 0;
|
||||
}
|
||||
if (*path == ')')
|
||||
path++;
|
||||
tmp = getenv(buffer2);
|
||||
if (!tmp) {
|
||||
buffer[i] = 0;
|
||||
strcat(buffer, "$(");
|
||||
strcat(buffer, buffer2);
|
||||
strcat(buffer, ")");
|
||||
i += strlen(buffer2) + 3;
|
||||
} else {
|
||||
strcat(buffer, tmp);
|
||||
i += strlen(tmp);
|
||||
}
|
||||
} else {
|
||||
while (*path != 0 && *path != '/') {
|
||||
buffer2[j++] = *(path++);
|
||||
buffer2[j] = 0;
|
||||
}
|
||||
tmp = getenv(buffer2);
|
||||
if (!tmp) {
|
||||
strcat(buffer, "$");
|
||||
strcat(buffer, buffer2);
|
||||
i += strlen(buffer2) + 1;
|
||||
} else {
|
||||
strcat(buffer, tmp);
|
||||
i += strlen(tmp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buffer[i++] = *path;
|
||||
path++;
|
||||
}
|
||||
}
|
||||
|
||||
return wstrdup(buffer);
|
||||
return wstrdup(buffer);
|
||||
}
|
||||
|
||||
|
||||
/* return address of next char != tok or end of string whichever comes first */
|
||||
static char*
|
||||
skipchar(char *string, char tok)
|
||||
static char *skipchar(char *string, char tok)
|
||||
{
|
||||
while(*string!=0 && *string==tok)
|
||||
string++;
|
||||
while (*string != 0 && *string == tok)
|
||||
string++;
|
||||
|
||||
return string;
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/* return address of next char == tok or end of string whichever comes first */
|
||||
static char*
|
||||
nextchar(char *string, char tok)
|
||||
static char *nextchar(char *string, char tok)
|
||||
{
|
||||
while(*string!=0 && *string!=tok)
|
||||
string++;
|
||||
while (*string != 0 && *string != tok)
|
||||
string++;
|
||||
|
||||
return string;
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* findfile--
|
||||
@@ -197,173 +183,163 @@ nextchar(char *string, char tok)
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
char*
|
||||
wfindfile(char *paths, char *file)
|
||||
char *wfindfile(char *paths, char *file)
|
||||
{
|
||||
char *path;
|
||||
char *tmp, *tmp2;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
char *path;
|
||||
char *tmp, *tmp2;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
|
||||
if (!file)
|
||||
return NULL;
|
||||
if (!file)
|
||||
return NULL;
|
||||
|
||||
if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) {
|
||||
if (access(file, F_OK)<0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
if (*file == '/' || *file == '~' || *file == '$' || !paths || *paths == 0) {
|
||||
if (access(file, F_OK) < 0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
|
||||
if (access(fullpath, F_OK)<0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
if (access(fullpath, F_OK) < 0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
|
||||
flen = strlen(file);
|
||||
tmp = paths;
|
||||
while (*tmp) {
|
||||
tmp = skipchar(tmp, ':');
|
||||
if (*tmp==0)
|
||||
break;
|
||||
tmp2 = nextchar(tmp, ':');
|
||||
len = tmp2 - tmp;
|
||||
path = wmalloc(len+flen+2);
|
||||
path = memcpy(path, tmp, len);
|
||||
path[len]=0;
|
||||
if (path[len-1] != '/')
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
if (access(fullpath, F_OK)==0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
tmp = tmp2;
|
||||
}
|
||||
flen = strlen(file);
|
||||
tmp = paths;
|
||||
while (*tmp) {
|
||||
tmp = skipchar(tmp, ':');
|
||||
if (*tmp == 0)
|
||||
break;
|
||||
tmp2 = nextchar(tmp, ':');
|
||||
len = tmp2 - tmp;
|
||||
path = wmalloc(len + flen + 2);
|
||||
path = memcpy(path, tmp, len);
|
||||
path[len] = 0;
|
||||
if (path[len - 1] != '/')
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
if (access(fullpath, F_OK) == 0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
tmp = tmp2;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wfindfileinlist(char **path_list, char *file)
|
||||
char *wfindfileinlist(char **path_list, char *file)
|
||||
{
|
||||
int i;
|
||||
char *path;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
int i;
|
||||
char *path;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
|
||||
if (!file)
|
||||
return NULL;
|
||||
if (!file)
|
||||
return NULL;
|
||||
|
||||
if (*file=='/' || *file=='~' || !path_list) {
|
||||
if (access(file, F_OK)<0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
if (*file == '/' || *file == '~' || !path_list) {
|
||||
if (access(file, F_OK) < 0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
|
||||
if (access(fullpath, F_OK)<0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
if (access(fullpath, F_OK) < 0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
|
||||
flen = strlen(file);
|
||||
for (i=0; path_list[i]!=NULL; i++) {
|
||||
len = strlen(path_list[i]);
|
||||
path = wmalloc(len+flen+2);
|
||||
path = memcpy(path, path_list[i], len);
|
||||
path[len]=0;
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
/* expand tilde */
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
/* check if file exists */
|
||||
if (access(fullpath, F_OK)==0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
flen = strlen(file);
|
||||
for (i = 0; path_list[i] != NULL; i++) {
|
||||
len = strlen(path_list[i]);
|
||||
path = wmalloc(len + flen + 2);
|
||||
path = memcpy(path, path_list[i], len);
|
||||
path[len] = 0;
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
/* expand tilde */
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
/* check if file exists */
|
||||
if (access(fullpath, F_OK) == 0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char*
|
||||
wfindfileinarray(WMPropList *array, char *file)
|
||||
char *wfindfileinarray(WMPropList * array, char *file)
|
||||
{
|
||||
int i;
|
||||
char *path;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
int i;
|
||||
char *path;
|
||||
int len, flen;
|
||||
char *fullpath;
|
||||
|
||||
if (!file)
|
||||
return NULL;
|
||||
if (!file)
|
||||
return NULL;
|
||||
|
||||
if (*file=='/' || *file=='~' || !array) {
|
||||
if (access(file, F_OK)<0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
if (*file == '/' || *file == '~' || !array) {
|
||||
if (access(file, F_OK) < 0) {
|
||||
fullpath = wexpandpath(file);
|
||||
if (!fullpath)
|
||||
return NULL;
|
||||
|
||||
if (access(fullpath, F_OK)<0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
if (access(fullpath, F_OK) < 0) {
|
||||
wfree(fullpath);
|
||||
return NULL;
|
||||
} else {
|
||||
return fullpath;
|
||||
}
|
||||
} else {
|
||||
return wstrdup(file);
|
||||
}
|
||||
}
|
||||
|
||||
flen = strlen(file);
|
||||
for (i=0; i<WMGetPropListItemCount(array); i++) {
|
||||
WMPropList *prop;
|
||||
char *p;
|
||||
flen = strlen(file);
|
||||
for (i = 0; i < WMGetPropListItemCount(array); i++) {
|
||||
WMPropList *prop;
|
||||
char *p;
|
||||
|
||||
prop = WMGetFromPLArray(array, i);
|
||||
if (!prop)
|
||||
continue;
|
||||
p = WMGetFromPLString(prop);
|
||||
prop = WMGetFromPLArray(array, i);
|
||||
if (!prop)
|
||||
continue;
|
||||
p = WMGetFromPLString(prop);
|
||||
|
||||
len = strlen(p);
|
||||
path = wmalloc(len+flen+2);
|
||||
path = memcpy(path, p, len);
|
||||
path[len]=0;
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
/* expand tilde */
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
/* check if file exists */
|
||||
if (access(fullpath, F_OK)==0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
len = strlen(p);
|
||||
path = wmalloc(len + flen + 2);
|
||||
path = memcpy(path, p, len);
|
||||
path[len] = 0;
|
||||
strcat(path, "/");
|
||||
strcat(path, file);
|
||||
/* expand tilde */
|
||||
fullpath = wexpandpath(path);
|
||||
wfree(path);
|
||||
if (fullpath) {
|
||||
/* check if file exists */
|
||||
if (access(fullpath, F_OK) == 0) {
|
||||
return fullpath;
|
||||
}
|
||||
wfree(fullpath);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user