aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-05 14:04:01 +0100
committerJan200101 <sentrycraft123@gmail.com>2020-12-05 14:04:01 +0100
commit4dca2e233748eb386a0054170491697bcb0532ea (patch)
tree668e40827a3568399559255f7aa6897dd917e469
parent199d133a9c46a548e6e0e2a757aa81c955c137ce (diff)
downloadpolecat-4dca2e233748eb386a0054170491697bcb0532ea.tar.gz
polecat-4dca2e233748eb386a0054170491697bcb0532ea.zip
send warning and error msgs to stderr, output context messages if tty[…]
- a lot of puts and printf calls have been replaced with fprintf() to ensure the error or warning message reaches the end user - messages like "Installable wine versions:" are only output if we are in a TTY, this will using polecat in shell scripts easier
-rw-r--r--src/dxvk.c71
-rw-r--r--src/wine.c35
2 files changed, 53 insertions, 53 deletions
diff --git a/src/dxvk.c b/src/dxvk.c
index 59bb345..67e42aa 100644
--- a/src/dxvk.c
+++ b/src/dxvk.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <json.h>
#include <libgen.h>
+#include <unistd.h>
#include <linux/limits.h>
#include <dirent.h>
@@ -46,7 +47,7 @@ int dxvk_download(int argc, char** argv)
if (choice > json_object_array_length(runner) - 1 || choice < 0)
{
- printf("`%i' is not a valid ID\n\nrun `" NAME " dxvk list' to get a valid ID", choice);
+ fprintf(stderr, "`%i' is not a valid ID\n\nrun `" NAME " dxvk list' to get a valid ID", choice);
}
else
{
@@ -65,7 +66,7 @@ int dxvk_download(int argc, char** argv)
getDXVKDir(dxvkdir, sizeof(dxvkdir));
makeDir(dxvkdir);
- printf("Downloading %s\n", name);
+ fprintf(stderr, "Downloading %s\n", name);
archive = downloadToRam(json_object_get_string(assets));
if (archive)
@@ -75,7 +76,7 @@ int dxvk_download(int argc, char** argv)
}
else
{
- puts("Something went wrong. The archive went missing");
+ fprintf(stderr, "Something went wrong. The archive went missing\n");
}
free(archive->memory);
@@ -87,11 +88,32 @@ int dxvk_download(int argc, char** argv)
}
else
{
- puts(USAGE_STR " dxvk download <ID>\n\nIDs are obtained via `" NAME " dxvk list' ");
+ fprintf(stderr, USAGE_STR " dxvk download <ID>\n\nIDs are obtained via `" NAME " dxvk list'\n");
}
return 0;
}
+int dxvk_list(int argc, char** argv)
+{
+ struct json_object* runner = fetchJSON(DXVK_API);
+
+ if (runner)
+ {
+ if (isatty(STDOUT_FILENO)) puts("Installable DXVK versions:");
+
+ for (size_t i = 0; i < json_object_array_length(runner); ++i)
+ {
+ struct json_object* version = json_object_array_get_idx(runner, i);
+ struct json_object* name;
+
+ json_object_object_get_ex(version, "name", &name);
+ printf(" [%zu]\t%s\n", i, json_object_get_string(name));
+ }
+ }
+
+ return 0;
+}
+
int dxvk_install(int argc, char** argv)
{
if (argc > 1)
@@ -105,7 +127,7 @@ int dxvk_install(int argc, char** argv)
if (!isDir(dxvkpath))
{
- printf("`%s' is not an downloaded DXVK version\n", dxvkver);
+ fprintf(stderr, "`%s' is not an downloaded DXVK version\n", dxvkver);
return 0;
}
@@ -119,13 +141,13 @@ int dxvk_install(int argc, char** argv)
}
else
{
- printf("cannot find the setup script for `%s'\n", dxvkver);
+ fprintf(stderr, "cannot find the setup script for `%s'\n", dxvkver);
}
}
else
{
- printf("Specify a what DXVK version to install.\nUse `" NAME " dxvk list-installed' to list available versions\n");
+ fprintf(stderr, "Specify a what DXVK version to install.\nUse `" NAME " dxvk list-installed' to list available versions\n");
}
@@ -140,18 +162,17 @@ int dxvk_installed(int argc, char** argv)
DIR *dir;
struct dirent *ent;
- printf("Installed DXVK versions:\n");
+ int intty = isatty(STDOUT_FILENO);
+
+ if (intty) puts("Installed DXVK versions:");
if ((dir = opendir(dxvkdir)) != NULL)
{
while ((ent = readdir(dir)) != NULL)
{
- /*
- * WARNING: crusty
- * d_type is only specified on glibc (including musl) and BSD
- */
if (ent->d_name[0] != '.' && ent->d_type == DT_DIR)
{
- printf(" - %s\n", ent->d_name);
+ if (intty) printf(" - ");
+ printf("%s\n", ent->d_name);
}
}
closedir (dir);
@@ -160,31 +181,9 @@ int dxvk_installed(int argc, char** argv)
return 0;
}
-
-int dxvk_list(int argc, char** argv)
-{
- struct json_object* runner = fetchJSON(DXVK_API);
-
- if (runner)
- {
- puts("Installable DXVK versions:");
-
- for (size_t i = 0; i < json_object_array_length(runner); ++i)
- {
- struct json_object* version = json_object_array_get_idx(runner, i);
- struct json_object* name;
-
- json_object_object_get_ex(version, "name", &name);
- printf(" [%zu]\t%s\n", i, json_object_get_string(name));
- }
- }
-
- return 0;
-}
-
int dxvk_help(int argc, char** argv)
{
- puts(USAGE_STR " dxvk <command>\n\nList of commands:");
+ fprintf(stderr, USAGE_STR " dxvk <command>\n\nList of commands:\n");
print_help(dxvk_commands, ARRAY_LEN(dxvk_commands));
diff --git a/src/wine.c b/src/wine.c
index b19630a..f1827d8 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -23,6 +23,7 @@ const static struct Command wine_commands[] = {
{ .name = "list", .func = wine_list, .description = "list installable wine versions" },
{ .name = "run", .func = wine_run, .description = "run a installed wine version" },
{ .name = "list-installed", .func = wine_installed, .description = "list installed wine versions" },
+ { .name = "env", .func = wine_env, .description = "add a wine executable to your PATH"},
};
int wine(int argc, char** argv)
@@ -54,7 +55,7 @@ int wine_download(int argc, char** argv)
if (choice > json_object_array_length(versions) - 1 || choice < 0)
{
- printf("`%i' is not a valid ID\n\nrun `polecat wine list' to get a valid ID\n", choice);
+ fprintf(stderr, "`%i' is not a valid ID\n\nrun `polecat wine list' to get a valid ID\n", choice);
}
else
{
@@ -70,17 +71,17 @@ int wine_download(int argc, char** argv)
getWineDir(winedir, sizeof(winedir));
makeDir(winedir);
- printf("Downloading %s\n", name);
+ fprintf(stderr, "Downloading %s\n", name);
archive = downloadToRam(json_object_get_string(url));
if (archive)
{
- printf("Extracting %s\n", name);
+ fprintf(stderr, "Extracting %s\n", name);
extract(archive, winedir);
}
else
{
- puts("Something went wrong. The archive went missing");
+ fprintf(stderr, "Something went wrong. The archive went missing\n");
}
free(archive->memory);
@@ -92,7 +93,7 @@ int wine_download(int argc, char** argv)
}
else
{
- puts(USAGE_STR " wine download <ID>\n\nIDs are obtained via `" NAME " wine list' ");
+ fprintf(stderr, USAGE_STR " wine download <ID>\n\nIDs are obtained via `" NAME " wine list'\n");
}
return 0;
}
@@ -106,7 +107,7 @@ int wine_list(int argc, char** argv)
struct json_object* versions, *value, *val;
json_object_object_get_ex(runner, "versions", &versions);
- puts("Installable wine versions:");
+ if(isatty(STDOUT_FILENO)) puts("Installable wine versions:");
for (size_t i = 0; i < json_object_array_length(versions); ++i)
{
@@ -148,7 +149,7 @@ int wine_run(int argc, char** argv)
// if it still doesn't exist tell this wine version is not installed
if (!isDir(winepath))
{
- printf("`%s' is not an installed wine version\n", winever);
+ fprintf(stderr, "`%s' is not an installed wine version\n", winever);
return 0;
}
}
@@ -165,7 +166,7 @@ int wine_run(int argc, char** argv)
default:
#ifdef DEBUG
- printf("Couldn't find figure out if this `%s' is Wine or Proton, defaulting to Wine", winever);
+ fprintf(stderr, "Couldn't find figure out if this `%s' is Wine or Proton, defaulting to Wine", winever);
#endif
winebinloc = WINEBIN;
break;
@@ -186,13 +187,13 @@ int wine_run(int argc, char** argv)
}
else
{
- printf("cannot find wine for `%s'\n", winever);
+ fprintf(stderr, "cannot find wine for `%s'\n", winever);
}
}
else
{
- printf("Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n");
+ fprintf(stderr, "Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n");
}
@@ -207,18 +208,18 @@ int wine_installed(int argc, char** argv)
DIR *dir;
struct dirent *ent;
- printf("Installed wine versions:\n");
+ int intty = isatty(STDOUT_FILENO);
+
+ if (intty) puts("Installed wine versions:");
+
if ((dir = opendir(winedir)) != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
- /*
- * WARNING: crusty
- * d_type is only specified on glibc (including musl) and BSD
- */
if (ent->d_name[0] != '.' && ent->d_type == DT_DIR)
{
- printf(" - %s\n", ent->d_name);
+ if (intty) printf(" - ");
+ printf("%s\n", ent->d_name);
}
}
closedir (dir);
@@ -312,7 +313,7 @@ int wine_env(int argc, char** argv)
int wine_help(int argc, char** argv)
{
- puts(USAGE_STR " wine <command>\n\nList of commands:");
+ fprintf(stderr, USAGE_STR " wine <command>\n\nList of commands:\n");
print_help(wine_commands, ARRAY_LEN(wine_commands));