2

I need to develop a script in gnuplot that is usable under both Windows and Linux.

To decide which OS I have, I wrote

OS=system("echo %OS%")
print "OS = ", OS
if (OS eq "Windows_NT") \
  ...; \
else \
  ...;

and it worked.

Is there an alternative way, native to gnuplot, which does not depend on environment variables?

  • Any reason why you don't want to use environment variables ? Because that's what they are for, aren't they ? – kebs Dec 06 '18 at 13:33
  • Because it depends on the variable `OS` (or the like) being set, and as far as I have observed, it is most often not default behaviour. Then, my script would not be very useful for distributing. – sancho.s ReinstateMonicaCellio Dec 10 '18 at 11:56

1 Answers1

2

you could use the internal variable GPVAL_SYSNAME:

gnuplot> print GPVAL_SYSNAME
Windows_NT-10.0

which is on Windows initialized in eval.c as:

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
snprintf(s, 30, "Windows_NT-%ld.%ld", osvi.dwMajorVersion, osvi.dwMinorVersion);
fill_gpval_string("GPVAL_SYSNAME", s);

In order to test if this string starts with "Windows", one could use the Gnuplot's internal strstrt function as:

if (strstrt(GPVAL_SYSNAME, "Windows") == 1) {
   ....
}

In addition, there is also GPVAL_MACHINE:

gnuplot> print GPVAL_MACHINE
x86_64
ewcz
  • 12,819
  • 1
  • 25
  • 47