Commit 3e62c2bd authored by Christoffer Ackelman's avatar Christoffer Ackelman

Added a helper function to co_dcli? that executes the first available flavour...

Added a helper function to co_dcli? that executes the first available flavour (wb_qt/wb_gtk/wb_motif) given a base executable (wb).
parent 41214c9d
......@@ -36,45 +36,20 @@
/* profinet_viewer.cpp Profinet viewer */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "pwr.h"
#include "co_dcli.h"
#include "co_string.h"
static void usage()
{
printf("\nUsage: profinet_viewer\n");
}
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: profinet_viewer [-f windowmgr]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found)
strcpy(wmg, "gtk");
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,47 +36,20 @@
/* wb.cpp -- graphical editor */
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("sev_xtt: Syntax error\n");
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: sev_xtt [-f windowmgr]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
struct stat st;
strcpy(file, "$pwr_exe/sev_xtt_gtk");
dcli_translate_filename(file, file);
if (stat(file, &st) == 0)
strcpy(wmg, "gtk");
else
strcpy(wmg, "motif");
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -40,6 +40,7 @@
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include "co_ccm.h"
#include "co_cdh.h"
......@@ -972,3 +973,24 @@ unsigned int dcli_random()
srand(itime);
return (unsigned int)(rand() / ((double)RAND_MAX + 1) * 999999);
}
void dcli_execute_flavour_if_exists(char* argv[], const char* flavour)
{
pwr_tFileName file;
if (argv[0][0] != '/') {
strcpy(file, "$pwr_exe/");
}
strcat(file, argv[0]);
strcat(file, "_");
strcat(file, flavour);
dcli_translate_filename(file, file);
execvp(file, argv); // execvp only return if the file doesn't exist
}
void dcli_execute_flavour(char* argv[])
{
const char* flavours[] = { "qt", "gtk", "motif" };
for (int i = 0; i < 3; i++) {
dcli_execute_flavour_if_exists(argv, flavours[i]);
}
}
......@@ -134,6 +134,10 @@ void dcli_readstruct_free(dcli_sStructElement* e_list);
int dcli_readstruct_get_message(char** message);
void dcli_execute_flavour_if_exists(char* argv[], const char* flavour);
void dcli_execute_flavour(char* argv[]);
#ifdef __cplusplus
}
#endif
......
......@@ -36,50 +36,20 @@
/* wb.cpp -- graphical editor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
// Wb::usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
// Wb::usage();
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char* flavours[] = { "qt", "gtk", "motif" };
for (int i = 0; i < 3; i++) {
strcpy(file, "$pwr_exe/wb_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -45,49 +45,29 @@
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
// Wb::usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
// Wb::usage();
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
}
if (!found) {
const char* flavours[] = { "qt", "gtk", "motif" };
for (int i = 0; i < 3; i++) {
strcpy(file, "$pwr_exe/wb_cmd_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
dcli_execute_flavour(argv);
strcpy(file, "$pwr_eexe/wb_cmd_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
const char* flavours[] = { "qt", "gtk", "motif" };
for (int i = 0; i < 3; i++) {
strcpy(file, "$pwr_eexe/wb_cmd_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
execvp(file, argv);
exit(0);
}
}
execvp(file, argv);
}
......@@ -36,50 +36,20 @@
/* co_help.cpp -- Help window */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("co_help: Syntax error\n");
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: co_help [-f windowmgr]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk"};
for (int i = 0; i < 2; i++) {
strcpy(file, "$pwr_exe/co_help_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,55 +36,20 @@
/* pwr_rtmonitor.cpp Runtime Monitor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
static void usage()
{
printf("\nUsage: pwr_rtmon [-f windowmgr]");
}
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: pwr_rtmon [-f windowmgr]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk"};
for (int i = 0; i < 2; i++) {
strcpy(file, "$pwr_exe/pwr_rtmon_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,55 +36,20 @@
/* rt_statusmon.cpp Status Monitor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
static void usage()
{
printf("\nUsage: rt_statusmon [-f windowmanager]");
}
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: rt_statusmon [-f windowmanager]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk"};
for (int i = 0; i < 2; i++) {
strcpy(file, "$pwr_exe/rt_statusmon_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,50 +36,20 @@
/* wb.cpp -- graphical editor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("rt_xtt: Syntax error\n");
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: rt_xtt [-f windowmanager]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk","motif"};
for (int i = 0; i < 3; i++) {
strcpy(file, "$pwr_exe/rt_xtt_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,50 +36,20 @@
/* wb.cpp -- graphical editor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("rt_xtt_cmd: Syntax error\n");
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: rt_xtt_cmd [-f windowmanager]");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk"};
for (int i = 0; i < 2; i++) {
strcpy(file, "$pwr_exe/rt_xtt_cmd_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
......@@ -36,55 +36,20 @@
/* wb_ge.c -- graphical editor */
#include <unistd.h>
#include <sys/stat.h>
#include "co_dcli.h"
#include "co_string.h"
static void usage()
{
printf("\nUsage: wb_ge [-f windowmanager] [-l language] [graphname]\n");
}
int main(int argc, char* argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
usage();
exit(0);
}
found = 1;
strcpy(wmg, argv[i + 1]);
i++;
for (int i = 1; i < argc; i++) {
if (streq(argv[i], "-f")) {
if (i + 1 >= argc) {
printf("\nUsage: wb_ge [-f windowmanager] [-l language] [graphname]\n");
exit(0);
}
dcli_execute_flavour_if_exists(argv, argv[i + 1]);
}
}
if (!found) {
const char *flavours[] = {"qt","gtk","motif"};
for (int i = 0; i < 3; i++) {
strcpy(file, "$pwr_exe/wb_ge_");
strcat(file, flavours[i]);
dcli_translate_filename(file, file);
struct stat st;
if (stat(file, &st) == 0) {
strcpy(wmg, flavours[i]);
break;
}
}
}
strcpy(file, argv[0]);
strcat(file, "_");
strcat(file, wmg);
execvp(file, argv);
dcli_execute_flavour(argv);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment