mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
Merge branch 'android_branch' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_branch
This commit is contained in:
commit
efe6d6d95d
38 changed files with 377 additions and 257 deletions
|
@ -26,7 +26,6 @@
|
|||
>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
|
||||
|
|
BIN
xwords4/android/XWords4/assets/BasEnglish2to8.xwd
Normal file
BIN
xwords4/android/XWords4/assets/BasEnglish2to8.xwd
Normal file
Binary file not shown.
Binary file not shown.
|
@ -21,7 +21,6 @@ local_DEFINES += \
|
|||
-DPLATFORM_ANDROID \
|
||||
-DXWFEATURE_CROSSHAIRS \
|
||||
-DPOINTER_SUPPORT \
|
||||
-DXWFEATURE_RANDOM_VIA_UTILS \
|
||||
-DSCROLL_DRAG_THRESHHOLD=1 \
|
||||
-DDROP_BITMAPS \
|
||||
-DDISABLE_EMPTYTRAY_UNDO \
|
||||
|
|
|
@ -242,6 +242,15 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8* ptr, XP_U32 dictLength )
|
|||
XP_Bool isUTF8 = XP_FALSE;
|
||||
|
||||
flags = n_ptr_tohs( &ptr );
|
||||
if ( 0 != (DICT_HEADER_MASK & flags) ) {
|
||||
flags &= ~DICT_HEADER_MASK;
|
||||
XP_U16 headerLen = n_ptr_tohs( &ptr );
|
||||
if ( 4 <= headerLen ) { /* have word count? */
|
||||
ctxt->super.nWords = n_ptr_tohl( &ptr );
|
||||
headerLen -= 4; /* don't skip it */
|
||||
}
|
||||
ptr += headerLen;
|
||||
}
|
||||
|
||||
if ( flags == 0x0002 ) {
|
||||
nodeSize = 3;
|
||||
|
@ -432,7 +441,6 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
|
|||
anddict->bytes = localBytes;
|
||||
|
||||
parseDict( anddict, localBytes, len );
|
||||
setBlankTile( &anddict->super );
|
||||
|
||||
/* copy the name */
|
||||
if ( NULL != jname ) {
|
||||
|
|
|
@ -364,23 +364,6 @@ and_util_remSelected(XW_UtilCtxt* uc)
|
|||
UTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
static XP_U16
|
||||
and_util_rand( XW_UtilCtxt* uc )
|
||||
{
|
||||
jint result = 0;
|
||||
AndUtil* util = (AndUtil*)uc;
|
||||
JNIEnv* env = *util->env;
|
||||
if ( NULL != util->jutil ) {
|
||||
jmethodID mid = getMethodID( env, util->jutil, "rand", "()I" );
|
||||
result = (*env)->CallIntMethod( env, util->jutil, mid );
|
||||
} else {
|
||||
result = rand();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
and_util_setIsServer(XW_UtilCtxt* uc, XP_Bool isServer )
|
||||
{
|
||||
|
@ -473,9 +456,6 @@ makeUtil( MPFORMAL JNIEnv** envp, jobject jutil, CurGameInfo* gi,
|
|||
SET_PROC(warnIllegalWord);
|
||||
SET_PROC(showChat);
|
||||
SET_PROC(remSelected);
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
SET_PROC(rand);
|
||||
#endif
|
||||
SET_PROC(setIsServer);
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef XP_U32 XP_Time;
|
|||
#define XP_CR "\n"
|
||||
#define XP_LD "%ld"
|
||||
|
||||
/* #define XP_RANDOM() and_rand() */
|
||||
#define XP_RANDOM() and_rand()
|
||||
|
||||
#ifdef MEM_DEBUG
|
||||
# define XP_PLATMALLOC(nbytes) malloc(nbytes)
|
||||
|
|
|
@ -260,9 +260,9 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getInitialAddr
|
|||
setJAddrRec( env, jaddr, &addr );
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getLanguageCode
|
||||
(JNIEnv* env, jclass C, jbyteArray jDictBytes, jobject jniu )
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
|
||||
(JNIEnv* env, jclass C, jbyteArray jDictBytes, jobject jniu, jobject jinfo )
|
||||
{
|
||||
#ifdef MEM_DEBUG
|
||||
MemPoolCtx* mpool = mpool_make();
|
||||
|
@ -271,12 +271,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getLanguageCode
|
|||
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil,
|
||||
jDictBytes, NULL );
|
||||
jint code = dict_getLangCode( dict );
|
||||
jint nWords = dict_getWordCount( dict );
|
||||
dict_destroy( dict );
|
||||
destroyJNIUtil( &jniutil );
|
||||
|
||||
setInt( env, jinfo, "langCode", code );
|
||||
setInt( env, jinfo, "wordCount", nWords );
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
#endif
|
||||
return code;
|
||||
}
|
||||
|
||||
/* Dictionary methods: don't use gamePtr */
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<string name="title_create">Create game</string>
|
||||
<string name="title_edit">Edit game</string>
|
||||
<string name="title_games_list">Crosswords</string>
|
||||
<string name="title_dicts_list">Crosswords dictionaries</string>
|
||||
<string name="title_dicts_list">Dictionaries (language/wordcount)</string>
|
||||
<string name="title_game">Game</string>
|
||||
<string name="title_game_configf">%s settings</string>
|
||||
<string name="title_gamenet_configf">%s settings (networked)</string>
|
||||
|
|
|
@ -32,7 +32,6 @@ import android.view.Window;
|
|||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.content.Intent;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import android.net.Uri;
|
||||
import android.app.Dialog;
|
||||
|
@ -74,7 +73,6 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
|||
private String m_path;
|
||||
private int m_currentOrient;
|
||||
private Toolbar m_toolbar;
|
||||
private Random m_rgen;
|
||||
|
||||
private String m_dlgBytes = null;
|
||||
private EditText m_passwdEdit = null;
|
||||
|
@ -292,8 +290,6 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
|||
Utils.logf( "BoardActivity::onCreate()" );
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
m_rgen = new Random();
|
||||
|
||||
if ( CommonPrefs.getHideTitleBar( this ) ) {
|
||||
requestWindowFeature( Window.FEATURE_NO_TITLE );
|
||||
}
|
||||
|
@ -717,11 +713,6 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
|
|||
R.string.tiles_left_title );
|
||||
}
|
||||
|
||||
public int rand()
|
||||
{
|
||||
return m_rgen.nextInt();
|
||||
}
|
||||
|
||||
public void setIsServer( boolean isServer )
|
||||
{
|
||||
Utils.logf( "setIsServer(%s)", isServer?"true":"false" );
|
||||
|
|
|
@ -20,27 +20,23 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.UnresolvedAddressException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.Vector;
|
||||
import java.util.Iterator;
|
||||
import junit.framework.Assert;
|
||||
import android.telephony.SmsManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
import org.eehouse.android.xw4.jni.JNIThread.*;
|
||||
|
@ -70,20 +66,24 @@ public class CommsTransport implements TransportProcs {
|
|||
public int m_nMissing;
|
||||
}
|
||||
|
||||
private Selector m_selector;
|
||||
private SocketChannel m_socketChannel;
|
||||
private int m_jniGamePtr;
|
||||
private CommsAddrRec m_addr;
|
||||
private JNIThread m_jniThread;
|
||||
private CommsThread m_thread;
|
||||
private Handler m_handler;
|
||||
private boolean m_done = false;
|
||||
|
||||
private Socket m_socket;
|
||||
private ReaderThread m_reader;
|
||||
private WriterThread m_writer;
|
||||
BlockingQueue<byte[]> m_queue;
|
||||
private Vector<ByteBuffer> m_buffersOut;
|
||||
private ByteBuffer m_bytesOut;
|
||||
private ByteBuffer m_bytesIn;
|
||||
|
||||
private Context m_context;
|
||||
private ConnectivityManager m_connMgr;
|
||||
private BroadcastReceiver m_receiver;
|
||||
private boolean m_netAvail = false;
|
||||
|
||||
// assembling inbound packet
|
||||
private byte[] m_packetIn;
|
||||
private int m_haveLen = -1;
|
||||
|
||||
public CommsTransport( int jniGamePtr, Context context, Handler handler,
|
||||
DeviceRole role )
|
||||
|
@ -91,68 +91,116 @@ public class CommsTransport implements TransportProcs {
|
|||
m_jniGamePtr = jniGamePtr;
|
||||
m_context = context;
|
||||
m_handler = handler;
|
||||
|
||||
buildNetAvailReceiver();
|
||||
m_queue = new ArrayBlockingQueue<byte[]>(16);
|
||||
m_buffersOut = new Vector<ByteBuffer>();
|
||||
m_bytesIn = ByteBuffer.allocate( 2048 );
|
||||
}
|
||||
|
||||
public class WriterThread extends Thread {
|
||||
public class CommsThread extends Thread {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
DataOutputStream os;
|
||||
try {
|
||||
os = new DataOutputStream( m_socket.getOutputStream() );
|
||||
try {
|
||||
if ( Build.PRODUCT.contains("sdk") ) {
|
||||
System.setProperty("java.net.preferIPv6Addresses", "false");
|
||||
}
|
||||
|
||||
m_selector = Selector.open();
|
||||
|
||||
loop();
|
||||
|
||||
closeSocket();
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
return;
|
||||
Utils.logf( ioe.toString() );
|
||||
} catch ( UnresolvedAddressException uae ) {
|
||||
Utils.logf( "bad address: name: %s; port: %s; exception: %s",
|
||||
m_addr.ip_relay_hostName, m_addr.ip_relay_port,
|
||||
uae.toString() );
|
||||
}
|
||||
|
||||
for ( ; ; ) {
|
||||
m_thread = null;
|
||||
}
|
||||
|
||||
private void loop()
|
||||
{
|
||||
while ( !m_done ) {
|
||||
try {
|
||||
byte[] buf = m_queue.take(); // blocks
|
||||
synchronized( this ) {
|
||||
|
||||
os.writeShort( buf.length );
|
||||
os.write( buf );
|
||||
Utils.logf( "wrote %d bytes to socket", buf.length );
|
||||
} catch ( InterruptedException inte ) {
|
||||
Utils.logf( "%s", inte.toString() );
|
||||
break;
|
||||
} catch( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
break;
|
||||
// if we have data and no socket, try to connect.
|
||||
if ( null == m_socketChannel
|
||||
&& 0 < m_buffersOut.size() ) {
|
||||
try {
|
||||
m_socketChannel = SocketChannel.open();
|
||||
m_socketChannel.configureBlocking( false );
|
||||
Utils.logf( "connecting to %s:%d",
|
||||
m_addr.ip_relay_hostName,
|
||||
m_addr.ip_relay_port );
|
||||
InetSocketAddress isa
|
||||
= new InetSocketAddress( m_addr.ip_relay_hostName,
|
||||
m_addr.ip_relay_port );
|
||||
m_socketChannel.connect( isa );
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( null != m_socketChannel ) {
|
||||
int ops = figureOps();
|
||||
// Utils.logf( "calling with ops=%x", ops );
|
||||
m_socketChannel.register( m_selector, ops );
|
||||
}
|
||||
}
|
||||
m_selector.select();
|
||||
} catch ( ClosedChannelException cce ) {
|
||||
// we get this when relay goes down. Need to notify!
|
||||
m_jniThread.handle( JNICmd.CMD_TRANSFAIL );
|
||||
closeSocket();
|
||||
Utils.logf( "exiting: " + cce.toString() );
|
||||
break; // don't try again
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
closeSocket();
|
||||
Utils.logf( "exiting: " + ioe.toString() );
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
|
||||
Iterator<SelectionKey> iter = m_selector.selectedKeys().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
SelectionKey key = (SelectionKey)iter.next();
|
||||
SocketChannel channel = (SocketChannel)key.channel();
|
||||
iter.remove();
|
||||
try {
|
||||
if (key.isValid() && key.isConnectable()) {
|
||||
if ( !channel.finishConnect() ) {
|
||||
key.cancel();
|
||||
}
|
||||
}
|
||||
if (key.isValid() && key.isReadable()) {
|
||||
m_bytesIn.clear(); // will wipe any pending data!
|
||||
// Utils.logf( "socket is readable; buffer has space for "
|
||||
// + m_bytesIn.remaining() );
|
||||
int nRead = channel.read( m_bytesIn );
|
||||
if ( nRead == -1 ) {
|
||||
channel.close();
|
||||
} else {
|
||||
addIncoming();
|
||||
}
|
||||
}
|
||||
if (key.isValid() && key.isWritable()) {
|
||||
getOut();
|
||||
if ( null != m_bytesOut ) {
|
||||
int nWritten = channel.write( m_bytesOut );
|
||||
//Utils.logf( "wrote " + nWritten + " bytes" );
|
||||
}
|
||||
}
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
key.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // loop
|
||||
|
||||
}
|
||||
|
||||
public class ReaderThread extends Thread {
|
||||
public void run()
|
||||
{
|
||||
DataInputStream dis;
|
||||
try {
|
||||
dis = new DataInputStream( m_socket.getInputStream() );
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
return;
|
||||
}
|
||||
|
||||
for ( ; ; ) {
|
||||
try {
|
||||
Utils.logf( "ReaderThread: blocking inside readShort();" );
|
||||
short len = dis.readShort();
|
||||
Utils.logf( "ReaderThread: read length short: %d", len );
|
||||
byte[] buf = new byte[len];
|
||||
dis.readFully( buf );
|
||||
Utils.logf( "returned from readFully()" );
|
||||
m_jniThread.handle( JNICmd.CMD_RECEIVE, buf );
|
||||
} catch( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setReceiver( JNIThread jnit )
|
||||
{
|
||||
m_jniThread = jnit;
|
||||
|
@ -160,89 +208,105 @@ public class CommsTransport implements TransportProcs {
|
|||
|
||||
public void waitToStop()
|
||||
{
|
||||
if ( null != m_socket ) {
|
||||
m_done = true;
|
||||
if ( null != m_selector ) {
|
||||
m_selector.wakeup();
|
||||
}
|
||||
if ( null != m_thread ) { // synchronized this? Or use Thread method
|
||||
try {
|
||||
m_socket.close();
|
||||
m_socket = null;
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
m_thread.join(100); // wait up to 1/10 second
|
||||
} catch ( java.lang.InterruptedException ie ) {
|
||||
Utils.logf( "got InterruptedException: " + ie.toString() );
|
||||
}
|
||||
m_thread = null;
|
||||
}
|
||||
// destroyNetAvailReceiver();
|
||||
}
|
||||
|
||||
private void startThreadsIf()
|
||||
private synchronized void putOut( final byte[] buf )
|
||||
{
|
||||
if ( null == m_socket && m_netAvail ) {
|
||||
int len = buf.length;
|
||||
ByteBuffer netbuf = ByteBuffer.allocate( len + 2 );
|
||||
netbuf.putShort( (short)len );
|
||||
netbuf.put( buf );
|
||||
m_buffersOut.add( netbuf );
|
||||
Assert.assertEquals( netbuf.remaining(), 0 );
|
||||
|
||||
if ( null != m_selector ) {
|
||||
m_selector.wakeup(); // tell it it's got some writing to do
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void closeSocket()
|
||||
{
|
||||
if ( null != m_socketChannel ) {
|
||||
try {
|
||||
m_socket = new Socket( m_addr.ip_relay_hostName,
|
||||
m_addr.ip_relay_port );
|
||||
if ( null != m_socket ) {
|
||||
m_reader = new ReaderThread();
|
||||
m_reader.start();
|
||||
m_writer = new WriterThread();
|
||||
m_writer.start();
|
||||
}
|
||||
} catch ( java.net.UnknownHostException uhe ) {
|
||||
Utils.logf( "%s", uhe.toString() );
|
||||
m_socket = null;
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( "%s", ioe.toString() );
|
||||
m_socket = null; // need to notify user on some of these
|
||||
m_socketChannel.close();
|
||||
} catch ( Exception e ) {
|
||||
Utils.logf( "closing socket: %s", e.toString() );
|
||||
}
|
||||
m_socketChannel = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class CommsBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive( Context context, Intent intent )
|
||||
{
|
||||
Utils.logf( "CommsBroadcastReceiver::onReceive()" );
|
||||
if ( intent.getAction().
|
||||
equals( ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
private synchronized void getOut()
|
||||
{
|
||||
if ( null != m_bytesOut && m_bytesOut.remaining() == 0 ) {
|
||||
m_bytesOut = null;
|
||||
}
|
||||
|
||||
NetworkInfo ni = (NetworkInfo)intent.
|
||||
getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
|
||||
boolean netAvail = NetworkInfo.State.CONNECTED == ni.getState();
|
||||
if ( m_netAvail != netAvail ) {
|
||||
// Do something; it's a change
|
||||
m_netAvail = netAvail;
|
||||
if ( netAvail ) {
|
||||
startThreadsIf();
|
||||
// } else {
|
||||
// waitToStop();
|
||||
}
|
||||
}
|
||||
|
||||
Utils.logf( "CommsTransport::onReceive: m_netAvail=%s",
|
||||
m_netAvail?"true":"false" );
|
||||
}
|
||||
if ( null == m_bytesOut && m_buffersOut.size() > 0 ) {
|
||||
m_bytesOut = m_buffersOut.remove(0);
|
||||
m_bytesOut.flip();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildNetAvailReceiver()
|
||||
{
|
||||
m_connMgr = (ConnectivityManager)
|
||||
m_context.getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||
NetworkInfo ni = m_connMgr.getActiveNetworkInfo();
|
||||
m_netAvail = null != ni &&
|
||||
NetworkInfo.State.CONNECTED == ni.getState();
|
||||
Utils.logf( "CommsTransport::buildNetAvailReceiver: m_netAvail=%s",
|
||||
m_netAvail?"true":"false" );
|
||||
|
||||
m_receiver = new CommsBroadcastReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction( ConnectivityManager.CONNECTIVITY_ACTION );
|
||||
Intent intent = m_context.registerReceiver( m_receiver, filter );
|
||||
Utils.logf( "CommsTransport::registerReceiver->%s",
|
||||
intent==null?"null" : intent.toString() );
|
||||
private synchronized int figureOps() {
|
||||
int ops;
|
||||
if ( null == m_socketChannel ) {
|
||||
ops = 0;
|
||||
} else if ( m_socketChannel.isConnected() ) {
|
||||
ops = SelectionKey.OP_READ;
|
||||
if ( (null != m_bytesOut && m_bytesOut.hasRemaining())
|
||||
|| m_buffersOut.size() > 0 ) {
|
||||
ops |= SelectionKey.OP_WRITE;
|
||||
}
|
||||
} else {
|
||||
ops = SelectionKey.OP_CONNECT;
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
||||
private void destroyNetAvailReceiver()
|
||||
private void addIncoming( )
|
||||
{
|
||||
if ( null != m_receiver ) {
|
||||
m_context.unregisterReceiver( m_receiver );
|
||||
m_receiver = null;
|
||||
m_bytesIn.flip();
|
||||
|
||||
for ( ; ; ) {
|
||||
int len = m_bytesIn.remaining();
|
||||
if ( len <= 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( null == m_packetIn ) { // we're not mid-packet
|
||||
Assert.assertTrue( len > 1 ); // tell me if I see this case
|
||||
if ( len == 1 ) { // half a length byte...
|
||||
break; // can I leave it in the buffer?
|
||||
} else {
|
||||
m_packetIn = new byte[m_bytesIn.getShort()];
|
||||
m_haveLen = 0;
|
||||
}
|
||||
} else { // we're mid-packet
|
||||
int wantLen = m_packetIn.length - m_haveLen;
|
||||
if ( wantLen > len ) {
|
||||
wantLen = len;
|
||||
}
|
||||
m_bytesIn.get( m_packetIn, m_haveLen, wantLen );
|
||||
m_haveLen += wantLen;
|
||||
if ( m_haveLen == m_packetIn.length ) {
|
||||
// send completed packet
|
||||
m_jniThread.handle( JNICmd.CMD_RECEIVE, m_packetIn );
|
||||
m_packetIn = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,14 +327,12 @@ public class CommsTransport implements TransportProcs {
|
|||
|
||||
switch ( m_addr.conType ) {
|
||||
case COMMS_CONN_RELAY:
|
||||
startThreadsIf();
|
||||
try {
|
||||
// add(), not put(): don't block thread in comms if full
|
||||
m_queue.add( buf );
|
||||
nSent = buf.length;
|
||||
} catch ( IllegalStateException ise ) {
|
||||
Utils.logf( "%s", ise.toString() );
|
||||
putOut( buf ); // add to queue
|
||||
if ( null == m_thread ) {
|
||||
m_thread = new CommsThread();
|
||||
m_thread.start();
|
||||
}
|
||||
nSent = buf.length;
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
Assert.fail();
|
||||
|
|
|
@ -27,16 +27,37 @@ import java.util.HashMap;
|
|||
|
||||
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
|
||||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
import org.eehouse.android.xw4.jni.DictInfo;
|
||||
|
||||
public class DictLangCache {
|
||||
private static final HashMap<String,Integer> s_nameToLang =
|
||||
new HashMap<String,Integer>();
|
||||
private static final HashMap<String,DictInfo> s_nameToLang =
|
||||
new HashMap<String,DictInfo>();
|
||||
private static String[] s_langNames;
|
||||
|
||||
public static String annotatedDictName( Context context, final String name,
|
||||
boolean inclNWords )
|
||||
{
|
||||
int wordCount = 0;
|
||||
if ( inclNWords ) {
|
||||
DictInfo info = getInfo( context, name );
|
||||
wordCount = info.wordCount;
|
||||
}
|
||||
|
||||
String langName = getLangName( context, name );
|
||||
String result;
|
||||
if ( 0 == wordCount ) {
|
||||
result = String.format( "%s (%s)", name, langName );
|
||||
} else {
|
||||
result = String.format( "%s (%s/%d)", name, langName, wordCount );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String annotatedDictName( Context context,
|
||||
String name )
|
||||
{
|
||||
return name + " (" + getLangName( context, name ) + ")";
|
||||
return annotatedDictName( context, name, false );
|
||||
}
|
||||
|
||||
public static String annotatedDictName( Context context, String name,
|
||||
|
@ -82,15 +103,7 @@ public class DictLangCache {
|
|||
|
||||
public static int getLangCode( Context context, String name )
|
||||
{
|
||||
int code;
|
||||
if ( s_nameToLang.containsKey( name ) ) {
|
||||
code = s_nameToLang.get( name );
|
||||
} else {
|
||||
byte[] dict = GameUtils.openDict( context, name );
|
||||
code = XwJNI.dict_getLanguageCode( dict, JNIUtilsImpl.get() );
|
||||
s_nameToLang.put( name, new Integer(code) );
|
||||
}
|
||||
return code;
|
||||
return getInfo( context, name ).langCode;
|
||||
}
|
||||
|
||||
public static String getLangName( Context context, String name )
|
||||
|
@ -108,4 +121,18 @@ public class DictLangCache {
|
|||
return s_langNames;
|
||||
}
|
||||
|
||||
private static DictInfo getInfo( Context context, String name )
|
||||
{
|
||||
DictInfo info;
|
||||
if ( s_nameToLang.containsKey( name ) ) {
|
||||
info = s_nameToLang.get( name );
|
||||
} else {
|
||||
byte[] dict = GameUtils.openDict( context, name );
|
||||
info = new DictInfo();
|
||||
XwJNI.dict_getInfo( dict, JNIUtilsImpl.get(), info );
|
||||
s_nameToLang.put( name, info );
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
|
@ -65,7 +65,8 @@ public class DictsActivity extends XWListActivity
|
|||
// append language name
|
||||
view.setText( DictLangCache.
|
||||
annotatedDictName( DictsActivity.this,
|
||||
m_dicts[position] ) );
|
||||
m_dicts[position],
|
||||
true ) );
|
||||
if ( !GameUtils.dictIsBuiltin( DictsActivity.this,
|
||||
m_dicts[position] ) ) {
|
||||
view.setDeleteCallback( DictsActivity.this );
|
||||
|
|
|
@ -115,10 +115,12 @@ public class DlgDelegate {
|
|||
{
|
||||
boolean set = CommonPrefs.getPrefsBoolean( m_activity, prefsKey, false );
|
||||
if ( set ) {
|
||||
Utils.logf( "showNotAgainDlgThen: skipping message" );
|
||||
if ( null != proc ) {
|
||||
proc.run();
|
||||
}
|
||||
} else {
|
||||
Utils.logf( "showNotAgainDlgThen: setting message: %d", msgID );
|
||||
m_msgID = msgID;
|
||||
m_proc = proc;
|
||||
m_prefsKey = prefsKey;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/* -*- compile-command: "cd ../../../../../../; ant install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* 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 (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package org.eehouse.android.xw4.jni;
|
||||
|
||||
public class DictInfo {
|
||||
public int langCode;
|
||||
public int wordCount;
|
||||
};
|
|
@ -48,7 +48,6 @@ public interface UtilCtxt {
|
|||
|
||||
void requestTime();
|
||||
void remSelected();
|
||||
int rand();
|
||||
void setIsServer( boolean isServer );
|
||||
|
||||
static final int STRD_ROBOT_TRADED = 1;
|
||||
|
|
|
@ -208,5 +208,6 @@ public class XwJNI {
|
|||
// Dicts
|
||||
public static native boolean dict_tilesAreSame( int dictPtr1, int dictPtr2 );
|
||||
public static native String[] dict_getChars( int dictPtr );
|
||||
public static native int dict_getLanguageCode( byte[] dict, JNIUtils jniu );
|
||||
public static native void dict_getInfo( byte[] dict, JNIUtils jniu,
|
||||
DictInfo info );
|
||||
}
|
||||
|
|
|
@ -927,7 +927,7 @@ XP_U16
|
|||
comms_getChannelSeed( CommsCtxt* comms )
|
||||
{
|
||||
while ( comms->channelSeed == 0 ) {
|
||||
comms->channelSeed = util_rand(comms->util);
|
||||
comms->channelSeed = XP_RANDOM();
|
||||
XP_LOGF( "%s: channelSeed: %.4X", __func__, comms->channelSeed );
|
||||
}
|
||||
return comms->channelSeed;
|
||||
|
|
|
@ -437,6 +437,12 @@ dict_getLangCode( const DictionaryCtxt* dict )
|
|||
return dict->langCode;
|
||||
}
|
||||
|
||||
XP_U32
|
||||
dict_getWordCount( const DictionaryCtxt* dict )
|
||||
{
|
||||
return dict->nWords;
|
||||
}
|
||||
|
||||
#ifdef STUBBED_DICT
|
||||
|
||||
#define BLANK_FACE '\0'
|
||||
|
|
|
@ -35,6 +35,8 @@ extern "C" {
|
|||
/* cast to unsigned in case XP_UCHAR is signed */
|
||||
#define IS_SPECIAL(face) ((XP_U16)(face) < 0x0020)
|
||||
|
||||
#define DICT_HEADER_MASK 0x08
|
||||
|
||||
typedef XP_U8 XP_LangCode;
|
||||
|
||||
typedef enum {
|
||||
|
@ -78,6 +80,7 @@ struct DictionaryCtxt {
|
|||
|
||||
SpecialBitmaps* bitmaps;
|
||||
XP_UCHAR** chars;
|
||||
XP_U32 nWords;
|
||||
|
||||
XP_LangCode langCode;
|
||||
|
||||
|
@ -149,6 +152,7 @@ void dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile,
|
|||
XP_Bitmaps* bmps );
|
||||
|
||||
XP_LangCode dict_getLangCode( const DictionaryCtxt* dict );
|
||||
XP_U32 dict_getWordCount( const DictionaryCtxt* dict );
|
||||
|
||||
void dict_writeToStream( const DictionaryCtxt* ctxt, XWStreamCtxt* stream );
|
||||
void dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream );
|
||||
|
|
|
@ -309,7 +309,7 @@ newg_juggle( NewGameCtx* ngc )
|
|||
/* Get a randomly juggled array of numbers 0..nPlayers-1. Then the
|
||||
number at pos[n] inicates where the entry currently at n should
|
||||
be. */
|
||||
changed = randIntArray( ngc->util, pos, nPlayers );
|
||||
changed = randIntArray( pos, nPlayers );
|
||||
if ( changed ) {
|
||||
|
||||
/* Deep-copy off to tmp storage. But skip lines that won't be moved
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
/* #include <assert.h> */
|
||||
|
||||
#include "util.h"
|
||||
#include "pool.h"
|
||||
#include "dictnry.h"
|
||||
#include "xwstream.h"
|
||||
|
@ -28,7 +27,6 @@
|
|||
// #define BLANKS_FIRST 1
|
||||
|
||||
struct PoolContext {
|
||||
XW_UtilCtxt* util;
|
||||
XP_U8* lettersLeft;
|
||||
XP_U16 numTilesLeft;
|
||||
XP_U16 numFaces;
|
||||
|
@ -39,14 +37,13 @@ struct PoolContext {
|
|||
};
|
||||
|
||||
PoolContext*
|
||||
pool_make( MPFORMAL XW_UtilCtxt* uc )
|
||||
pool_make( MPFORMAL_NOCOMMA )
|
||||
{
|
||||
PoolContext* result = (PoolContext*)XP_MALLOC(mpool, sizeof(*result) );
|
||||
|
||||
if ( result != NULL ) {
|
||||
XP_MEMSET( result, 0, sizeof( *result ) );
|
||||
MPASSIGN(result->mpool, mpool);
|
||||
result->util = uc;
|
||||
|
||||
#ifdef BLANKS_FIRST
|
||||
result->blankIndex = -1;
|
||||
|
@ -69,9 +66,9 @@ pool_writeToStream( PoolContext* pool, XWStreamCtxt* stream )
|
|||
} /* pool_writeToStream */
|
||||
|
||||
PoolContext*
|
||||
pool_makeFromStream( MPFORMAL XW_UtilCtxt* uc, XWStreamCtxt* stream )
|
||||
pool_makeFromStream( MPFORMAL XWStreamCtxt* stream )
|
||||
{
|
||||
PoolContext* pool = pool_make( MPPARM(mpool) uc );
|
||||
PoolContext* pool = pool_make( MPPARM_NOCOMMA(mpool) );
|
||||
|
||||
pool->numTilesLeft = stream_getU16( stream );
|
||||
pool->numFaces = stream_getU16( stream );
|
||||
|
@ -136,9 +133,9 @@ getRandomTile( PoolContext* pool )
|
|||
#if defined PLATFORM_PALM && ! defined XW_TARGET_PNO
|
||||
XP_U16 rr = XP_RANDOM();
|
||||
#elif defined PLATFORM_ANDROID
|
||||
XP_U16 rr = util_rand(pool->util);
|
||||
XP_U16 rr = XP_RANDOM();
|
||||
#else
|
||||
XP_U16 rr = util_rand(pool->util);
|
||||
XP_U16 rr = (XP_U16)(XP_RANDOM()>>16);
|
||||
#endif
|
||||
XP_U16 index = rr % pool->numTilesLeft;
|
||||
Tile result = getNthPoolTile( pool, index );
|
||||
|
|
|
@ -32,13 +32,12 @@ void pool_removeTiles( PoolContext* pool, TrayTileSet* tiles );
|
|||
XP_U16 pool_getNTilesLeft( PoolContext* pool );
|
||||
XP_U16 pool_getNTilesLeftFor( PoolContext* pool, Tile tile );
|
||||
|
||||
PoolContext* pool_make( MPFORMAL XW_UtilCtxt* uc );
|
||||
PoolContext* pool_make( MPFORMAL_NOCOMMA );
|
||||
|
||||
void pool_destroy( PoolContext* pool );
|
||||
void pool_initFromDict( PoolContext* pool, DictionaryCtxt* dict );
|
||||
|
||||
void pool_writeToStream( PoolContext* pool, XWStreamCtxt* stream );
|
||||
PoolContext* pool_makeFromStream( MPFORMAL XW_UtilCtxt* uc,
|
||||
XWStreamCtxt* stream );
|
||||
PoolContext* pool_makeFromStream( MPFORMAL XWStreamCtxt* stream );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -315,7 +315,7 @@ server_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
|
|||
getNV( stream, &server->nv, nPlayers );
|
||||
|
||||
if ( stream_getBits(stream, 1) != 0 ) {
|
||||
server->pool = pool_makeFromStream( MPPARM(mpool) util, stream );
|
||||
server->pool = pool_makeFromStream( MPPARM(mpool) stream );
|
||||
}
|
||||
|
||||
for ( i = 0; i < nPlayers; ++i ) {
|
||||
|
@ -435,7 +435,7 @@ figureSleepTime( const ServerCtxt* server )
|
|||
XP_U16 max = server->nv.robotThinkMax;
|
||||
if ( min < max ) {
|
||||
int diff = max - min + 1;
|
||||
result = util_rand(server->vol.util) % diff;
|
||||
result = XP_RANDOM() % diff;
|
||||
}
|
||||
result += min;
|
||||
|
||||
|
@ -663,7 +663,7 @@ figureTargetScore( ServerCtxt* server, XP_U16 turn )
|
|||
}
|
||||
|
||||
result = (XP_S16)(highScore - model_getPlayerScore( model, turn )
|
||||
+ (FUDGE_RANGE-(util_rand(server->vol.util) % (FUDGE_RANGE*2))));
|
||||
+ (FUDGE_RANGE-(XP_RANDOM() % (FUDGE_RANGE*2))));
|
||||
if ( result < 0 ) {
|
||||
result = MINIMUM_SCORE;
|
||||
}
|
||||
|
@ -1155,8 +1155,7 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
}
|
||||
|
||||
XP_ASSERT( !server->pool );
|
||||
pool = server->pool = pool_make( MPPARM(server->mpool)
|
||||
server->vol.util );
|
||||
pool = server->pool = pool_make( MPPARM_NOCOMMA(server->mpool) );
|
||||
pool_initFromDict( server->pool, model_getDictionary(model));
|
||||
|
||||
/* now read the assigned tiles for each player from the stream, and
|
||||
|
@ -1625,7 +1624,7 @@ assignTilesToAll( ServerCtxt* server )
|
|||
XP_ASSERT( server->vol.gi->serverRole != SERVER_ISCLIENT );
|
||||
XP_ASSERT( model_getDictionary(model) != NULL );
|
||||
if ( server->pool == NULL ) {
|
||||
server->pool = pool_make( MPPARM(server->mpool) server->vol.util );
|
||||
server->pool = pool_make( MPPARM_NOCOMMA(server->mpool) );
|
||||
XP_STATUSF( "initing pool" );
|
||||
pool_initFromDict( server->pool, model_getDictionary(model));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
#include "strutils.h"
|
||||
#include "xwstream.h"
|
||||
#include "mempool.h"
|
||||
|
@ -207,7 +206,7 @@ emptyStringIfNull( XP_UCHAR* str )
|
|||
} /* emptyStringIfNull */
|
||||
|
||||
XP_Bool
|
||||
randIntArray( XW_UtilCtxt* util, XP_U16* rnums, XP_U16 count )
|
||||
randIntArray( XP_U16* rnums, XP_U16 count )
|
||||
{
|
||||
XP_Bool changed = XP_FALSE;
|
||||
XP_U16 i;
|
||||
|
@ -217,7 +216,7 @@ randIntArray( XW_UtilCtxt* util, XP_U16* rnums, XP_U16 count )
|
|||
}
|
||||
|
||||
for ( i = count; i > 0 ; ) {
|
||||
XP_U16 rIndex = util_rand(util) % i;
|
||||
XP_U16 rIndex = ((XP_U16)XP_RANDOM()) % i;
|
||||
if ( --i != rIndex ) {
|
||||
XP_U16 tmp = rnums[rIndex];
|
||||
rnums[rIndex] = rnums[i];
|
||||
|
|
|
@ -84,7 +84,7 @@ void p_replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc,
|
|||
XP_UCHAR* emptyStringIfNull( XP_UCHAR* str );
|
||||
|
||||
/* Produce an array of ints 0..count-1, juggled */
|
||||
XP_Bool randIntArray( XW_UtilCtxt* util, XP_U16* rnums, XP_U16 count );
|
||||
XP_Bool randIntArray( XP_U16* rnums, XP_U16 count );
|
||||
|
||||
#ifdef XWFEATURE_SMS
|
||||
void binToSms( XP_UCHAR* out, XP_U16* outlen, const XP_U8* in, XP_U16 inlen );
|
||||
|
|
|
@ -523,7 +523,7 @@ board_juggleTray( BoardCtxt* board )
|
|||
XP_U16 newT[MAX_TRAY_TILES];
|
||||
|
||||
/* loop until there'll be change */
|
||||
while ( !randIntArray( board->util, newT, nTiles ) ) {
|
||||
while ( !randIntArray( newT, nTiles ) ) {
|
||||
}
|
||||
|
||||
/* save copies of the tiles in juggled order */
|
||||
|
|
|
@ -157,10 +157,6 @@ typedef struct UtilVtable {
|
|||
|
||||
void (*m_util_remSelected)(XW_UtilCtxt* uc);
|
||||
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
XP_U16 (*m_util_rand)(XW_UtilCtxt* uc);
|
||||
#endif
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
void (*m_util_addrChange)( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
|
||||
const CommsAddrRec* newAddr );
|
||||
|
@ -261,11 +257,6 @@ struct XW_UtilCtxt {
|
|||
#define util_remSelected( uc ) \
|
||||
(uc)->vtable->m_util_remSelected((uc))
|
||||
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
# define util_rand( uc ) \
|
||||
(uc)->vtable->m_util_rand((uc))
|
||||
#endif
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
# define util_addrChange( uc, addro, addrn ) \
|
||||
(uc)->vtable->m_util_addrChange((uc), (addro), (addrn))
|
||||
|
|
1
xwords4/dawg/.gitignore
vendored
1
xwords4/dawg/.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
*.bin
|
||||
*.xwd
|
||||
*.pdb
|
||||
*.stamp
|
||||
*.dict.gz
|
||||
dict2dawg
|
||||
|
|
Binary file not shown.
|
@ -19,7 +19,7 @@ XWLANG=BasEnglish
|
|||
LANGCODE=en_US
|
||||
DICT2DAWGARGS = -r -nosort
|
||||
|
||||
TARGET_TYPE ?= PALM
|
||||
TARGET_TYPE ?= WINCE
|
||||
|
||||
include ../Makefile.2to8
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- mode: makefile; compile-command: "make -f Makefile.COSD"; -*-
|
||||
# -*- mode: makefile; compile-command: "make -f Makefile.CollegeEng"; -*-
|
||||
# Copyright 2002 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
|
|
|
@ -204,8 +204,8 @@ endif
|
|||
frankspecials.bin: ../frank_mkspecials.pl $(BMPFILES)
|
||||
$< $(BLANK_INFO) $(LANG_SPECIAL_INFO) > $@
|
||||
|
||||
$(XWLANG)%.$(FRANK_EXT): dawg$(XWLANG)%.stamp $(XWLANG)%_flags.bin charcount.bin table.bin values.bin frankspecials.bin
|
||||
cat $(XWLANG)$*_flags.bin charcount.bin table.bin values.bin \
|
||||
$(XWLANG)%.$(FRANK_EXT): dawg$(XWLANG)%.stamp $(XWLANG)%_flags.bin $(XWLANG)%_newheader.bin $(XWLANG)_charcount.bin table.bin values.bin frankspecials.bin
|
||||
cat $(XWLANG)$*_flags.bin $(XWLANG)$*_newheader.bin $(XWLANG)_charcount.bin table.bin values.bin \
|
||||
frankspecials.bin $(XWLANG)StartLoc.bin \
|
||||
$$(ls dawg$(XWLANG)$*_*.bin) > $@
|
||||
cp $@ saveme.bin
|
||||
|
@ -223,9 +223,9 @@ $(XWLANG)%.$(FRANK_EXT): dawg$(XWLANG)%.stamp $(XWLANG)%_flags.bin charcount.bin
|
|||
$(XWLANG)%_flags.bin: dawg$(XWLANG)%.stamp
|
||||
ifdef NEWDAWG
|
||||
if [ 3 = $$(cat $(XWLANG)$*_nodesize.bin) ] ; \
|
||||
then perl -e "print pack(\"n\",0x0004)" > $@; echo "flags=4"; \
|
||||
then perl -e "print pack(\"n\",0x000C)" > $@; echo "flags=4"; \
|
||||
elif [ 4 = $$(cat $(XWLANG)$*_nodesize.bin) ] ; \
|
||||
then perl -e "print pack(\"n\",0x0005)" > $@; echo "flags=5"; \
|
||||
then perl -e "print pack(\"n\",0x000D)" > $@; echo "flags=5"; \
|
||||
elif true; \
|
||||
then echo "Unexpected node size"; exit 1; \
|
||||
fi
|
||||
|
@ -247,7 +247,7 @@ dawg$(XWLANG)%.stamp: $(XWLANG)Main.dict.gz $(DICT2DAWG) table.bin ../Makefile.l
|
|||
touch $@
|
||||
|
||||
$(XWLANG)%_wordcount.bin: dawg$(XWLANG)%.stamp
|
||||
@echo
|
||||
@echo "got this rule"
|
||||
|
||||
# the files to export for byod
|
||||
allbins:
|
||||
|
@ -268,7 +268,7 @@ values.bin: ../xloc.pl
|
|||
# a binary file, two bytes, one giving the size of tiles data and the
|
||||
# other the number of tiles in the dict. Tiles data is utf-8 and so
|
||||
# number is not derivable from size.
|
||||
charcount.bin: table.bin ../xloc.pl
|
||||
$(XWLANG)_charcount.bin: table.bin ../xloc.pl
|
||||
SIZ=$$(ls -l $< | awk '{print $$5}'); \
|
||||
perl -e "print pack(\"c\",$$SIZ)" > $@
|
||||
TMP=/tmp/tmp$$$$; \
|
||||
|
@ -276,6 +276,11 @@ charcount.bin: table.bin ../xloc.pl
|
|||
cat $$TMP >> $@; \
|
||||
rm -f $$TMP
|
||||
|
||||
$(XWLANG)%_newheader.bin: $(XWLANG)%_wordcount.bin
|
||||
SIZ=$$(ls -l $< | awk '{print $$5}'); \
|
||||
perl -e "print pack(\"n\",$$SIZ)" > $@
|
||||
cat $< >> $@
|
||||
|
||||
%.dict: %.dict.gz
|
||||
zcat $< > $@
|
||||
|
||||
|
@ -289,4 +294,3 @@ clean_common:
|
|||
|
||||
help:
|
||||
@echo "make TARGET_TYPE=[FRANK|PALM]"
|
||||
|
||||
|
|
|
@ -156,9 +156,21 @@ sub readNodesToEnd($) {
|
|||
return @nodes;
|
||||
} # readNodesToEnd
|
||||
|
||||
sub nodeSizeFromFlags($) {
|
||||
my ( $flags ) = @_;
|
||||
if ( $flags == 4 ) {
|
||||
sub nodeSizeFromFlags($$) {
|
||||
my ( $fh, $flags ) = @_;
|
||||
|
||||
my $bitSet = $flags & 0x0008;
|
||||
if ( 0 != $bitSet ){
|
||||
$flags = $flags & ~0x0008;
|
||||
# need to skip header
|
||||
my $buf;
|
||||
2 == sysread( $fh, $buf, 2 ) || die "couldn't read length of header";
|
||||
my $len = unpack( "n", $buf );
|
||||
$len == sysread( $fh, $buf, $len ) || die "couldn't read header bytes";
|
||||
printf STDERR "skipped %d bytes of header\n", $len + 2;
|
||||
}
|
||||
|
||||
if ( $flags == 2 || $ flags == 4 ) {
|
||||
return 3;
|
||||
} elsif ( $flags == 5 ) {
|
||||
return 4;
|
||||
|
@ -186,7 +198,7 @@ sub prepXWD($$$$) {
|
|||
my $nRead = sysread( $fh, $buf, 2 );
|
||||
my $flags = unpack( "n", $buf );
|
||||
|
||||
$gNodeSize = nodeSizeFromFlags( $flags );
|
||||
$gNodeSize = nodeSizeFromFlags( $fh, $flags );
|
||||
|
||||
my $nSpecials;
|
||||
my $faceCount = readXWDFaces( $fh, $facRef, \$nSpecials );
|
||||
|
@ -270,7 +282,7 @@ sub prepPDB($$$$) {
|
|||
my $nChars = ($offsets[2] - $facesOffset) / 2;
|
||||
$nRead += sysread( $fh, $buf, $facesOffset - $nRead );
|
||||
my @tmp = unpack( 'Nc6n', $buf );
|
||||
$gNodeSize = nodeSizeFromFlags( $tmp[7] );
|
||||
$gNodeSize = nodeSizeFromFlags( 0, $tmp[7] );
|
||||
|
||||
my @faces;
|
||||
for ( my $i = 0; $i < $nChars; ++$i ) {
|
||||
|
|
|
@ -85,7 +85,6 @@ DEFINES += -DFEATURE_TRAY_EDIT
|
|||
#DEFINES += -DDRAW_WITH_PRIMITIVES
|
||||
DEFINES += -DXWFEATURE_CROSSHAIRS
|
||||
DEFINES += -DXWFEATURE_CHAT
|
||||
DEFINES += -DXWFEATURE_RANDOM_VIA_UTILS
|
||||
|
||||
ifdef CURSES_CELL_HT
|
||||
DEFINES += -DCURSES_CELL_HT=$(CURSES_CELL_HT)
|
||||
|
|
|
@ -209,11 +209,17 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
|||
XP_U16 facesSize;
|
||||
XP_U16 charSize;
|
||||
XP_Bool isUTF8 = XP_FALSE;
|
||||
XP_Bool hasHeader = XP_FALSE;
|
||||
|
||||
XP_ASSERT( dictF );
|
||||
if ( 1 == fread( &flags, sizeof(flags), 1, dictF ) ) {
|
||||
flags = ntohs(flags);
|
||||
XP_DEBUGF( "flags=0x%x", flags );
|
||||
XP_DEBUGF( "flags=0X%X", flags );
|
||||
hasHeader = 0 != (DICT_HEADER_MASK & flags);
|
||||
if ( hasHeader ) {
|
||||
flags &= ~DICT_HEADER_MASK;
|
||||
XP_DEBUGF( "has header!" );
|
||||
}
|
||||
#ifdef NODE_CAN_4
|
||||
if ( flags == 0x0001 ) {
|
||||
dctx->super.nodeSize = 3;
|
||||
|
@ -250,6 +256,24 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
|||
#endif
|
||||
|
||||
if ( formatOk ) {
|
||||
|
||||
if ( hasHeader ) {
|
||||
XP_U16 headerLen;
|
||||
if ( 1 != fread( &headerLen, sizeof(headerLen), 1, dictF ) ) {
|
||||
goto closeAndExit;
|
||||
}
|
||||
headerLen = ntohs( headerLen );
|
||||
XP_U32 wordCount;
|
||||
if ( headerLen != sizeof(wordCount) ) { /* the only case we know right now */
|
||||
goto closeAndExit;
|
||||
}
|
||||
if ( 1 != fread( &wordCount, sizeof(wordCount), 1, dictF ) ) {
|
||||
goto closeAndExit;
|
||||
}
|
||||
dctx->super.nWords = ntohl( wordCount );
|
||||
XP_DEBUGF( "dict contains %ld words", dctx->super.nWords );
|
||||
}
|
||||
|
||||
if ( isUTF8 ) {
|
||||
if ( 1 != fread( &numFaceBytes, sizeof(numFaceBytes), 1, dictF ) ) {
|
||||
goto closeAndExit;
|
||||
|
|
|
@ -175,17 +175,6 @@ linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
|
|||
}
|
||||
} /* linux_util_getUserString */
|
||||
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
static XP_U16
|
||||
linux_util_rand( XW_UtilCtxt* XP_UNUSED(util) )
|
||||
{
|
||||
XP_U16 result = 0;
|
||||
result = random() >> 16;
|
||||
LOG_RETURNF( "%d", result );
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
linux_util_vt_init( MPFORMAL XW_UtilCtxt* util )
|
||||
{
|
||||
|
@ -195,9 +184,7 @@ linux_util_vt_init( MPFORMAL XW_UtilCtxt* util )
|
|||
util->vtable->m_util_getSquareBonus = linux_util_getSquareBonus;
|
||||
util->vtable->m_util_getCurSeconds = linux_util_getCurSeconds;
|
||||
util->vtable->m_util_getUserString = linux_util_getUserString;
|
||||
#ifdef XWFEATURE_RANDOM_VIA_UTILS
|
||||
util->vtable->m_util_rand = linux_util_rand;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -102,7 +102,7 @@ extern void linux_debugf(const char*, ...)
|
|||
#define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len))
|
||||
#define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len))
|
||||
#define XP_STRCMP(s1,s2) strcmp((s1),(s2))
|
||||
/* #define XP_RANDOM() random() */
|
||||
#define XP_RANDOM() random()
|
||||
#define XP_SNPRINTF snprintf
|
||||
|
||||
#define XP_MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
|
Loading…
Add table
Reference in a new issue