1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-09 15:24:12 +01:00

changed indentation to use spaces only

This commit is contained in:
dan
2004-10-12 21:28:27 +00:00
parent 5912898b06
commit 6830b05716
240 changed files with 35951 additions and 35773 deletions

View File

@@ -1,8 +1,8 @@
/* wmsetup.c- create wmaker config file dir structure and copy default
* config files.
*
*
* Copyright (c) 2000-2003 Alfredo K. Kojima
*
*
* 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
* the Free Software Foundation; either version 2 of the License, or
@@ -41,25 +41,25 @@ main()
char *RequiredDirectories[] = {
"/Defaults",
"/.AppInfo",
"/Library",
"/Library/Icons",
"/Library/WindowMaker",
"/Library/WindowMaker/Backgrounds",
"/Library/WindowMaker/IconSets",
"/Library/WindowMaker/Pixmaps",
"/Library/WindowMaker/SoundSets",
"/Library/WindowMaker/Sounds",
"/Library/WindowMaker/Styles",
"/Library/WindowMaker/Themes",
NULL
"/.AppInfo",
"/Library",
"/Library/Icons",
"/Library/WindowMaker",
"/Library/WindowMaker/Backgrounds",
"/Library/WindowMaker/IconSets",
"/Library/WindowMaker/Pixmaps",
"/Library/WindowMaker/SoundSets",
"/Library/WindowMaker/Sounds",
"/Library/WindowMaker/Styles",
"/Library/WindowMaker/Themes",
NULL
};
char *RequiredFiles[] = {
"/Defaults/WindowMaker",
"/Defaults/WMWindowAttributes",
NULL
"/Defaults/WMWindowAttributes",
NULL
};
@@ -72,7 +72,7 @@ WMScreen *scr;
#if 0
void
void
wlog(const char *msg, ...)
{
va_list args;
@@ -88,7 +88,8 @@ wlog(const char *msg, ...)
#endif
void alert(const char *msg, ...)
void
alert(const char *msg, ...)
{
va_list args;
char buffer[2048];
@@ -96,17 +97,16 @@ void alert(const char *msg, ...)
va_start(args, msg);
vsprintf(buf, msg, args);
WMRunAlertPanel(scr, NULL, _("Error"),
buffer, _("OK"), NULL, NULL);
buffer, _("OK"), NULL, NULL);
va_end(args);
}
Bool ask(char *title, char *yes, char *no, const char *msg, ...)
Bool
ask(char *title, char *yes, char *no, const char *msg, ...)
{
va_list args;
char buffer[2048];
@@ -114,140 +114,144 @@ Bool ask(char *title, char *yes, char *no, const char *msg, ...)
va_start(args, msg);
vsprintf(buf, msg, args);
WMRunAlertPanel(scr, NULL, title,
buffer, yes, no, NULL);
buffer, yes, no, NULL);
va_end(args);
}
char *renameName(char *path)
char*
renameName(char *path)
{
char *buf = wmalloc(strlen(path)+8);
int i;
sprintf(buf, "%s~", path);
if (access(buf, F_OK) < 0) {
return buf;
return buf;
}
for (i = 0; i < 10; i++) {
sprintf(buf, "%s~%i", path, i);
if (access(buf, F_OK) < 0) {
return buf;
}
sprintf(buf, "%s~%i", path, i);
if (access(buf, F_OK) < 0) {
return buf;
}
}
sprintf(buf, "%s~", path);
return buf;
}
void showFileError(int error, Bool directory, char *path)
void
showFileError(int error, Bool directory, char *path)
{
switch (error) {
case EACCESS:
if (directory) {
alert(_("The directory %s needs to be fully accessible, but is\n"
"not. Make sure all of it's parent directories have\n"
"read and execute permissions set."), path);
} else {
alert(_("The file %s needs to be fully accessible, but is not.\n"
"Make sure it has read and write permissions set and\n"
"all of it's parent directories have read and execute\n"
"permissions."), path);
}
break;
case EROFS:
alert(_("The %s %s is in a read-only file system, but it needs to be\n"
"writable. Start wmaker with the --static command line option."),
directory ? _("directory") : _("file"), path);
break;
default:
alert(_("An error occurred while accessing the %s %s. Please make sure\n"
"it exists and is accessible.\n%s"),
directory ? _("directory") : _("file"), path,
wstrerror(error));
break;
case EACCESS:
if (directory) {
alert(_("The directory %s needs to be fully accessible, but is\n"
"not. Make sure all of it's parent directories have\n"
"read and execute permissions set."), path);
} else {
alert(_("The file %s needs to be fully accessible, but is not.\n"
"Make sure it has read and write permissions set and\n"
"all of it's parent directories have read and execute\n"
"permissions."), path);
}
break;
case EROFS:
alert(_("The %s %s is in a read-only file system, but it needs to be\n"
"writable. Start wmaker with the --static command line option."),
directory ? _("directory") : _("file"), path);
break;
default:
alert(_("An error occurred while accessing the %s %s. Please make sure\n"
"it exists and is accessible.\n%s"),
directory ? _("directory") : _("file"), path,
wstrerror(error));
break;
}
}
Bool checkDir(char *path, Bool fatal)
Bool
checkDir(char *path, Bool fatal)
{
if (access(path, F_OK) < 0) {
if (mkdir(path, 0775) < 0) {
alert(_("could not create directory %s\n%s"), path,
wstrerror(errno));
return False;
} else {
wlog(_("created directory %s"), path);
}
if (mkdir(path, 0775) < 0) {
alert(_("could not create directory %s\n%s"), path,
wstrerror(errno));
return False;
} else {
wlog(_("created directory %s"), path);
}
}
if (access(path, R_OK|W_OK|X_OK) == 0) {
return True;
return True;
}
wsyserror("bad access to directory %s", path);
if (!fatal) {
struct stat buf;
if (stat(path, &buf) < 0) {
alert(_("The directory %s could not be stat()ed. Please make sure\n"
"it exists and is accessible."), path);
return False;
}
if (!S_ISDIR(buf)) {
char *newName = renameName(path);
struct stat buf;
if (ask(_("Rename"), _("OK"), _("Cancel"),
_("A directory named %s needs to be created but a file with\n"
"the same name already exists. The file will be renamed to\n"
"%s and the directory will be created."),
path, newName)) {
if (rename(path, newName) < 0) {
alert(_("Could not rename %s to %s:%s"),
path, newName, wstrerror(errno));
}
}
wfree(newName);
return False;
}
if (!(buf.st_mode & S_IRWXU)) {
if (chmod(path, (buf.st_mode & 00077)|7) < 0) {
return False;
}
}
if (stat(path, &buf) < 0) {
alert(_("The directory %s could not be stat()ed. Please make sure\n"
"it exists and is accessible."), path);
return False;
}
return checkDir(path, True);
if (!S_ISDIR(buf)) {
char *newName = renameName(path);
if (ask(_("Rename"), _("OK"), _("Cancel"),
_("A directory named %s needs to be created but a file with\n"
"the same name already exists. The file will be renamed to\n"
"%s and the directory will be created."),
path, newName)) {
if (rename(path, newName) < 0) {
alert(_("Could not rename %s to %s:%s"),
path, newName, wstrerror(errno));
}
}
wfree(newName);
return False;
}
if (!(buf.st_mode & S_IRWXU)) {
if (chmod(path, (buf.st_mode & 00077)|7) < 0) {
return False;
}
}
return checkDir(path, True);
}
showFileError(errno, True, path);
return False;
}
Bool checkFile(char *path)
Bool
checkFile(char *path)
{
if (access(path, F_OK|R_OK|W_OK) == 0) {
return True;
}
return True;
}
showFileError(errno, False, path);
return False;
@@ -255,29 +259,30 @@ Bool checkFile(char *path)
Bool checkCurrentSetup(char *home)
Bool
checkCurrentSetup(char *home)
{
char path[1024];
char *p;
if (!checkDir(home, False)) {
wlog("couldnt make directory %s", home);
return False;
wlog("couldnt make directory %s", home);
return False;
}
for (p = RequiredDirectories; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkDir(p, False)) {
wlog("couldnt make directory %s", p);
return False;
}
sprintf(path, "%s%s", home, p);
if (!checkDir(p, False)) {
wlog("couldnt make directory %s", p);
return False;
}
}
for (p = RequiredFiles; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkFile(p, False)) {
return False;
}
sprintf(path, "%s%s", home, p);
if (!checkFile(p, False)) {
return False;
}
}
return True;
@@ -285,7 +290,8 @@ Bool checkCurrentSetup(char *home)
Bool copyAllFiles(char *gsdir)
Bool
copyAllFiles(char *gsdir)
{
FILE *f;
char path[2048];
@@ -295,80 +301,82 @@ Bool copyAllFiles(char *gsdir)
/* copy misc data files */
sprintf(path, "%s/USER_FILES", DATADIR);
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(file, 255, f)) {
break;
}
sprintf(path, "%s/%s", DATADIR, file);
sprintf(target, "%s/Library/WindowMaker/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
if (!fgets(file, 255, f)) {
break;
}
sprintf(path, "%s/%s", DATADIR, file);
sprintf(target, "%s/Library/WindowMaker/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
/* copy auto{start,finish} scripts */
/* select and copy menu */
/* copy Defaults stuff */
sprintf(path, "%s/USER_FILES", ETCDIR);
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(path, 255, f)) {
break;
}
sprintf(path, "%s/%s", ETCDIR, file);
sprintf(target, "%s/Defaults/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
if (!fgets(path, 255, f)) {
break;
}
sprintf(path, "%s/%s", ETCDIR, file);
sprintf(target, "%s/Defaults/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
/* setup .xinitrc */
}
void showFinishSplash(char *gsdir)
void
showFinishSplash(char *gsdir)
{
#if 0
WMWindow *win;
win = WMCreateWindow(scr, "finished");
#endif
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
Display *dpy;
char *gsdir;
int i;
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-display")==0) {
i++;
if (i>=argc) {
wwarning(_("too few arguments for %s"), argv[i-1]);
exit(0);
}
DisplayName = argv[i];
} else if (strcmp(argv[i], "-version")==0
|| strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
}
if (strcmp(argv[i], "-display")==0) {
i++;
if (i>=argc) {
wwarning(_("too few arguments for %s"), argv[i-1]);
exit(0);
}
DisplayName = argv[i];
} else if (strcmp(argv[i], "-version")==0
|| strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
}
}
WMInitializeApplication("WMSetup", &argc, argv);
dpy = XOpenDisplay("");
@@ -376,36 +384,36 @@ int main(int argc, char **argv)
printf("could not open display\n");
exit(1);
}
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
gsdir = wusergnusteppath();
/* check directory structure and copy files */
if (access(gsdir, F_OK) != 0) {
if (!ask(_("Window Maker"), _("OK"), _("Cancel"),
_("Window Maker will create a directory named %s, where\n"
"it will store it's configuration files and other data."),
gsdir)) {
alert(_("Window Maker will be started in 'static' mode, where\n"
"it will use default configuration and will not write\n"
"any information to disk."));
return 1;
}
if (!ask(_("Window Maker"), _("OK"), _("Cancel"),
_("Window Maker will create a directory named %s, where\n"
"it will store it's configuration files and other data."),
gsdir)) {
alert(_("Window Maker will be started in 'static' mode, where\n"
"it will use default configuration and will not write\n"
"any information to disk."));
return 1;
}
}
if (checkCurrentSetup(gsdir)) {
printf(_("%s: wmaker configuration files already installed\n"),
argv[0]);
return 0;
printf(_("%s: wmaker configuration files already installed\n"),
argv[0]);
return 0;
}
if (!copyAllFiles(gsdir)) {
alert(_("An error occurred while doing user specific setup of\n"
"Window Maker. It will be started in 'static' mode, where\n"
"the default configuration will be used and it will not write\n"
"any information to disk."));
return 1;
alert(_("An error occurred while doing user specific setup of\n"
"Window Maker. It will be started in 'static' mode, where\n"
"the default configuration will be used and it will not write\n"
"any information to disk."));
return 1;
}
showFinishSplash(gsdir);
@@ -413,3 +421,4 @@ int main(int argc, char **argv)
return 0;
}
#endif