HIARCS Chess Forums Forum Index HIARCS Chess Forums
World Championship winning computer chess software program & downloads for chess database, analysis and play on PC, Mac and iPhone
 
 QuestionsQuestions   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Private MessagesPrivate Messages   Log inLog in 

Using Windows UCI engines with HIARCS Mac Chess Explorer
Goto page Previous  1, 2
 
Post new topic   Reply to topic    HIARCS Chess Forums Forum Index -> Programming Discussions
View previous topic :: View next topic  
Author
Hasimir
Member


Joined: 29 Jun 2014
Posts: 62
Full Name: Ben
Location: Australia

PostPosted: Tue Sep 09, 2014 5:51 pm    Post subject: Re: Using Windows UCI engines with HIARCS Mac Chess Explorer Reply with quote

h.g.muller wrote:
If you would let your wrapper read the string it feeds to system() from a file with a fixed name (say wrapper.ini) in the current directory, people could use it without comiling anything. They would only have to prepare an ini file with the wine command in it. Of course you could have the wrapper also supply the path to wine by itself and just read the path to the engine from the file. Or, to accomodate even more lazy users, let it construct the engine path from the current directory and the .exe name read from the wrapper.ini file.


Okay, here's roughly how it's done in Python:

Code:

#!/usr/bin/env python

# Run this in the directory with the Win32 UCI .exe or a parent
# directory of it.
#
# Command: uciloader[.py] <win32_uci_exe_filename>

from distutils.spawn import find_executable
import os
import os.path
import subprocess
import sys

name = sys.argv[1]
curdir = os.path.abspath(".")

winexec = find_executable("wine")
winepath = os.path.abspath(winexec)

def uciengine(name, curdir):
    for root, dirs, files in os.walk(curdir):
        if name in files:
            return os.path.join(root, name)

# Need to update this to use subprocess instead of os.system:

os.system("{0} {1}".format(winepath, uciengine(name, curdir)))


There's no wrapper file there, instead it takes the name of the engine on the command line. When I remember how I last converted Python to C I'll add bits to take all this info, generate the C code on the fly and compile it. When that's done it should work for any platform with Python and a C compiler.
_________________
Website: Organised Adversary - ICCF: 30667
OpenPGP/GPG Key: 0x321E4E2373590E5D - BTC address: 18Ua6y7D65QatEDZ36dtWNWpG9Ttrd4eqy
Back to top
View user's profile Send private message Visit poster's website
h.g.muller
Member


Joined: 09 Jan 2009
Posts: 22

PostPosted: Tue Sep 09, 2014 9:02 pm    Post subject: Re: Using Windows UCI engines with HIARCS Mac Chess Explorer Reply with quote

Hasimir wrote:
Unfortunately that sample code there didn't compile for me, ...

I admit I did not test it. This one compiles for me on Linux with gcc. (It is C, not C++). I get a warning on get_current_dir_name(), though, like I did not #include the right header to declare it. The manual says it should be in unistd.h...

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
int main()
{
  FILE *f = fopen("wrapper.ini", "r");
  char buf[1024], exe_name[1024];
  if(!f) return -1;
  fscanf(f, "%[^\n]", exe_name); fclose(f);
  snprintf(buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name(), exe_name);
  system(buf);
  return 0;
}
Back to top
View user's profile Send private message
Hasimir
Member


Joined: 29 Jun 2014
Posts: 62
Full Name: Ben
Location: Australia

PostPosted: Wed Sep 10, 2014 4:06 am    Post subject: Re: Using Windows UCI engines with HIARCS Mac Chess Explorer Reply with quote

h.g.muller wrote:
Hasimir wrote:
Unfortunately that sample code there didn't compile for me, ...

I admit I did not test it. This one compiles for me on Linux with gcc. (It is C, not C++). I get a warning on get_current_dir_name(), though, like I did not #include the right header to declare it. The manual says it should be in unistd.h...

Code:
#include <stdio>
#include <stdlib>
#include <unistd>
 
int main()
{
  FILE *f = fopen("wrapper.ini", "r");
  char buf[1024], exe_name[1024];
  if(!f) return -1;
  fscanf(f, "%[^\n]", exe_name); fclose(f);
  snprintf(buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name(), exe_name);
  system(buf);
  return 0;
}


Yeah, that one compiles for me on a Slackware VM, but OS X hates it to the tune of:

Code:

bash-3.2$ gcc uciloader.c -o uciloader
uciloader.c:11:52: warning: implicit declaration of function
      'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]
  snprintf(buf, 1024, "/opt/local/bin/wine %s/%s", get_current_dir_name(...
                                                   ^
/usr/include/secure/_stdio.h:57:62: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
                                                             ^
uciloader.c:11:52: warning: format specifies type 'char *' but the argument has
      type 'int' [-Wformat]
  ...1024, "/opt/local/bin/wine %s/%s", get_current_dir_name(), exe_name);
                                ~~      ^~~~~~~~~~~~~~~~~~~~~~
                                %d
/usr/include/secure/_stdio.h:57:62: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
                                                             ^
2 warnings generated.
Undefined symbols for architecture x86_64:
  "_get_current_dir_name", referenced from:
      _main in uciloader-51d8f3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
bash-3.2$


Yes, I've got XCode and all the libs (I semi-regularly customise and compile my own copies of little things like GPG, OpenSSL and Tor).

Still, it's part of the way there and I'm all for solutions to help Linux along the way. Wink
_________________
Website: Organised Adversary - ICCF: 30667
OpenPGP/GPG Key: 0x321E4E2373590E5D - BTC address: 18Ua6y7D65QatEDZ36dtWNWpG9Ttrd4eqy
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    HIARCS Chess Forums Forum Index -> Programming Discussions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP