[Freeciv-Dev] Mac Port patches
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hi
Attached are a bunch of diff files. Please see if they break anything and
write them to the CVS server. They are all work that I've done on the mac
port to try to get things working. The server side is close (just need
work on the networking code), and the client is further away (major parts
have been worked on, but contain old code and incomplete functionality)
Andy Black
Mac Port Manager
Index: timing.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/timing.c,v
retrieving revision 1.2
diff -u -2 -r1.2 timing.c
--- timing.c 2000/01/22 17:00:28 1.2
+++ timing.c 2000/05/21 22:47:42
@@ -45,4 +45,7 @@
#endif
+#ifdef GENERATING_MAC
+#include <ansi_prefix.mac.h> /*needed in time.h*/
+#endif
#include <time.h>
#include <assert.h>
Index: sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.33
diff -u -2 -r1.33 sernet.c
--- sernet.c 2000/03/19 14:35:57 1.33
+++ sernet.c 2000/05/21 22:56:54
@@ -18,4 +18,7 @@
#include <stdlib.h>
#include <string.h>
+#ifdef GENERATING_MAC
+#include <ansi_prefix.mac.h> /*needed in time.h*/
+#endif
#include <time.h>
#include <errno.h>
@@ -63,4 +66,8 @@
#include <arpa/inet.h>
#endif
+#ifdef HAVE_OPENTRANSPORT
+#include <OpenTransport.h>
+#include <OpenTptInternet.h>
+#endif
#include "log.h"
@@ -79,7 +86,8 @@
struct connection connections[MAX_NUM_CONNECTIONS];
-#ifdef GENERATING_MAC /* mac network globals */
+#ifdef HAVE_OPENTRANSPORT /* mac network globals */
TEndpointInfo serv_info;
EndpointRef serv_ep;
+EndpointRef sock;
#else
static int sock;
@@ -88,9 +96,18 @@
extern int force_end_of_sniff;
+#ifdef HAVE_OPENTRANSPORT /* mac async notifier */
+pascal void NotifierRoutine(void* contextPtr, OTEventCode code,
+ OTResult result, void* cookie);
+#endif
/*****************************************************************************/
void close_connection(struct connection *pconn)
{
+#ifdef HAVE_OPENTRANSPORT
+ OTUnbind(pconn->sock);
+ OTCloseProvider(pconn->sock);
+#else
close(pconn->sock);
+#endif
pconn->used=0;
pconn->access_level=ALLOW_NONE;
@@ -107,5 +124,10 @@
}
}
+#ifdef HAVE_OPENTRANSPORT
+ OTUnbind(sock);
+ OTCloseProvider(sock);
+#else
close(sock);
+#endif
}
@@ -122,22 +144,28 @@
functions. That is, other functions should not need to do so. --dwp
*****************************************************************************/
+/* It looks like this only needs to do is handle stdin, force sniff,
+end of turn timeout on the mac. The reason is I'm fiddleing with Async
+conections. The bigest problem appears to be an operating system
restriction
+on not allocating (fc_maloc?) memory during interupt time. Does any one
know
+if the action handlers have this problem--AWB?*/
int sniff_packets(void)
{
int i;
+ static int year;
+ static time_t time_at_turn_end;
+#ifndef HAVE_OPENTRANSPORT
int max_desc;
fd_set readfs;
struct timeval tv;
- static time_t time_at_turn_end;
- static int year;
+#endif
#ifdef SOCKET_ZERO_ISNT_STDIN
char buf[BUF_SIZE+1];
char *bufptr = buf;
#endif
-
if(year!=game.year) {
time_at_turn_end = time(NULL) + game.timeout;
if (server_state == RUN_GAME_STATE) year=game.year;
}
-
+
while(1) {
con_prompt_on(); /* accepting new input */
@@ -149,6 +177,6 @@
}
+#ifndef HAVE_OPENTRANSPORT
tv.tv_sec=1; tv.tv_usec=0;
-
MY_FD_ZERO(&readfs);
FD_SET(0, &readfs);
@@ -172,4 +200,5 @@
return 0;
}
+#endif
#ifdef SOCKET_ZERO_ISNT_STDIN
if (feof(stdin))
@@ -178,11 +207,13 @@
}
+#ifndef HAVE_OPENTRANSPORT
if(FD_ISSET(sock, &readfs)) { /* new players connects */
freelog(LOG_VERBOSE, "got new connection");
if(server_accept_connection(sock)==-1)
freelog(LOG_NORMAL, "failed accepting connection");
- }
+ } else
+#endif
#ifndef SOCKET_ZERO_ISNT_STDIN
- else if(FD_ISSET(0, &readfs)) { /* input from server operator */
+ if(FD_ISSET(0, &readfs)) { /* input from server operator */
int didget;
char buf[BUF_SIZE+1];
@@ -197,5 +228,5 @@
}
#else
- else if(!feof(stdin)) { /* input from server operator */
+ if(!feof(stdin)) { /* input from server operator */
/* fetch chars until \n or run out of space in buffer */
while ((*bufptr=fgetc(stdin)) != EOF) {
@@ -211,4 +242,5 @@
}
#endif
+#ifndef HAVE_OPENTRANSPORT
else { /* input from a player */
for(i=0; i<MAX_NUM_CONNECTIONS; i++)
@@ -228,5 +260,13 @@
}
break;
+ for(i=0; i<MAX_NUM_CONNECTIONS; i++) {
+ if(connections[i].used) { /* if the conection is in use look at
it*/
+ FD_SET(connections[i].sock, &readfs);
+ }
+ max_desc=MAX(connections[i].sock, max_desc);
+ }
+ con_prompt_off(); /* output doesn't generate a new prompt */
}
+#endif
con_prompt_off();
@@ -364,8 +404,40 @@
void init_connections(void)
{
+#ifdef HAVE_OPENTRANSPORT
+ OSStatus err;
+#endif
int i;
for(i=0; i<MAX_NUM_CONNECTIONS; i++) {
connections[i].used=0;
connections[i].buffer.ndata=0;
+#ifdef HAVE_OPENTRANSPORT
+ OTAsyncOpenEndpoint(OTCreateConfiguration(kUDPName), 0,
&connections[i].info, NotifierRoutine, &connections[i]);
+#endif
+ }
+}
+
+/*
+OSStatus OTAsyncOpenEndpoint(OTCreateConfiguration(kUDPName), 0,
TEndpointInfo* info, NotifierRoutine, void* contextPtr)
+*/
+
+#ifdef HAVE_OPENTRANSPORT
+pascal void NotifierRoutine(void* contextPtr, OTEventCode code,
+ OTResult result, void* cookie)
+{
+ struct connection *conn=contextPtr;/*contextPtr=&connections[i]*/
+ switch(code)
+ {
+ case T_CONNECT:
+ OTRcvConnect(conn->sock, NULL);
+ break;
+ case T_DISCONNECT:
+ case T_DATA:
+ case T_REPLY:
+ case T_REQUEST:
+ case T_LISTEN:
+ break;
+ default:
+ break;
}
}
+#endif
\ No newline at end of file
Index: packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.64
diff -u -2 -r1.64 packets.h
--- packets.h 2000/05/21 13:20:37 1.64
+++ packets.h 2000/05/21 22:46:32
@@ -14,4 +14,9 @@
#define FC__PACKETS_H
+#ifdef HAVE_OPENTRANSPORT /* mac networking */
+#include <OpenTptInternet.h>
+#include <OpenTransport.h>
+#endif
+
#include "map.h"
#include "player.h"
@@ -764,7 +769,25 @@
};
+/*the ifedf-else-endif manuver could be avoided with the typedef pair in
gui_main_g.h
+The typedef pair should go somewhere else, but where? The best place
would
+be a new common code/header pair caled net.c/h. It's purpose would be
for all networking
+comon code, ex: opening sockets, closing sockets, init/destruct network
conection,
+read a socket, write a socket, scan opened sockets, et cetra.
+
+Alternativly, you could have each implmentation create a file called
something like
+*_net_com.c. (ex posix_net_com.c or ot_net_com.c) that implments the
function definitions
+described in net_com.h. This file would include the interface code that
the client uses
+
+In either case, you would probably need something the the typedef pair I
refered to.
+Andy Black, Mac port manager*/
struct connection {
- int sock, used;
+#ifdef HAVE_OPENTRANSPORT /* network protocol selector */
+ TEndpointInfo info;
+ EndpointRef sock;
+#else
+ int sock;
+#endif
+ int used;
int first_packet; /* check byte order on first packet */
int byte_swap; /* connection uses non-network byte order
*/
Index: packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.108
diff -u -2 -r1.108 packets.c
--- packets.c 2000/05/21 13:20:37 1.108
+++ packets.c 2000/05/21 22:44:45
@@ -3200,7 +3200,9 @@
struct socket_packet_buffer *buf)
{
- int start, nput, nblock;
+ int start, nput=0, nblock;
+ int error; /*for mode switching write errors(mac/standard)*/
for (start=0; start<buf->ndata;) {
+#ifndef GENERATING_MAC
fd_set writefs;
struct timeval tv;
@@ -3218,8 +3220,17 @@
return -1;
}
-
if (FD_ISSET(pc->sock, &writefs)) {
+#endif
nblock=MIN(buf->ndata-start, 4096);
+#ifdef HAVE_OPENTRANSPORT
+ /*if(OTStreamWrite(pc->sock, (const char *)buf->data+start,
nblock))!=0)
+ error =1;*/
+ error=OTStreamWrite(pc->sock, (const char *)buf->data+start,
nblock);
+ /*the reason for this is to keep the error generated around for
debuging, 0 is ok*/
+#else
if((nput=write(pc->sock, (const char *)buf->data+start, nblock)) ==
-1) {
+ error =1;}
+#endif
+ if (error) {
#ifdef NONBLOCKING_SOCKETS
if (errno == EWOULDBLOCK || errno == EAGAIN) {
@@ -3227,4 +3238,7 @@
}
#endif
+#ifdef HAVE_OPENTRANSPORT
+ freelog(LOG_DEBUG, "\tOpen transport error %d", error);
+#endif
buf->ndata -= start;
memmove(buf->data, buf->data+start, buf->ndata);
@@ -3232,5 +3246,7 @@
}
start += nput;
+#ifndef GENERATING_MAC
}
+#endif
}
Index: meta.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v
retrieving revision 1.30
diff -u -2 -r1.30 meta.c
--- meta.c 2000/03/05 13:28:45 1.30
+++ meta.c 2000/05/21 22:55:40
@@ -187,4 +187,6 @@
bad = ((serv_addr.fHost == 0) || (err1 != 0));
} else {
+ freelog(LOG_NORMAL, _("Error opening OpenTransport (Id: %n)"),
+ err1);
bad=true;
}
@@ -242,5 +244,5 @@
return;
}
-#ifndef GENERATINC_MAC
+#ifndef GENERATING_MAC
/* no, this is not weird, see man connect(2) --vasc */
if (connect(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr))==-1) {
Index: mem.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/mem.h,v
retrieving revision 1.2
diff -u -2 -r1.2 mem.h
--- mem.h 1999/05/01 03:57:23 1.2
+++ mem.h 2000/05/21 22:41:39
@@ -23,4 +23,5 @@
* a log message, possibly cleanup, and ending with exit(1)
*/
+/* or exit(error) for mac port--awb*/
#define fc_malloc(sz) fc_real_malloc((sz), "malloc", \
@@ -33,5 +34,13 @@
#define mystrdup(str) real_mystrdup((str), "strdup", \
__LINE__, __FILE__)
-
+
+/* failure_cleanup:
+ * used to do any cleanup functions for when things are spining out of
control.
+ * curently does nothing, but is referenced from the mac memeoy file in
the mac port.
+ * this function _does_not_ and _should_not_ call exit() or assert().
+ */
+
+void failure_cleanup(void);
+
/***********************************************************************/
Index: mem.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/mem.c,v
retrieving revision 1.2
diff -u -2 -r1.2 mem.c
--- mem.c 1999/10/04 13:36:18 1.2
+++ mem.c 2000/05/21 22:41:39
@@ -30,7 +30,19 @@
/**********************************************************************
+ A subroutine for any cleanup work. Curently does nothing
+**********************************************************************/
+
+void failure_cleanup(void)
+{
+ /*place all cleanup/safe-save code here*/
+}
+
+
+/**********************************************************************
Do whatever we should do when malloc fails.
At the moment this just prints a log message and calls exit(1)
-**********************************************************************/
+**********************************************************************/
+/* or an out of memory error code (in the mac port) */
+
static void handle_alloc_failure(size_t size, const char *called_as,
int line, const char *file)
@@ -41,5 +53,11 @@
* Do anything else here (cleanups? safe-save??)
*/
+ failure_cleanup(); /* a subroutine for cleanup purposes*/
+
+#ifdef GENERATING_MAC
+ exit(dsMemFullErr);
+#else
exit(1);
+#endif
}
@@ -122,4 +140,3 @@
strcpy(dest, str);
return dest;
-}
-
+}
\ No newline at end of file
Index: mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.51
diff -u -2 -r1.51 mapgen.c
--- mapgen.c 2000/01/31 17:04:36 1.51
+++ mapgen.c 2000/05/21 22:53:01
@@ -19,4 +19,7 @@
#include <string.h>
#include <assert.h>
+#ifdef GENERATING_MAC
+#include <ansi_prefix.mac.h> /*needed in time.h*/
+#endif
#include <time.h>
Index: gui_main_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/gui_main_g.h,v
retrieving revision 1.2
diff -u -2 -r1.2 gui_main_g.h
--- gui_main_g.h 1999/08/14 02:57:22 1.2
+++ gui_main_g.h 2000/05/21 22:40:26
@@ -14,7 +14,15 @@
#define FC__GUI_MAIN_G_H
+
+/*for the purpose of this see coment/comentary in packets.h*/
+#ifdef HAVE_OPENTRANSPORT
+typedef EndpointRef NET_SOCK;
+#else
+typedef int NET_SOCK;
+#endif
+
void ui_main(int argc, char *argv[]);
void enable_turn_done_button(void);
-void add_net_input(int);
+void add_net_input(NET_SOCK);
void remove_net_input(void);
Index: config.mac.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/config.mac.h,v
retrieving revision 1.7
diff -u -2 -r1.7 config.mac.h
--- config.mac.h 1999/10/03 09:41:57 1.7
+++ config.mac.h 2000/05/21 22:24:21
@@ -73,4 +73,5 @@
#undef PATCH_VERSION
#undef VERSION_LABEL
+#undef IS_DEVEL_VERSION
#undef IS_BETA_VERSION
#undef VERSION_STRING
@@ -100,8 +101,10 @@
#undef STRICT_CONTROLS/* copland Compatability (os x?), _MAC ONLY_
(pointless on other systems)*/
#define STRICT_CONTROLS 1 /* seq used to enable strict controls */
+#undef STRICT_MENUS/* copland Compatability? (os x?), _MAC ONLY_
(pointless on other systems)*/
+#define STRICT_MENUS 1 /* seq used to enable strict menus */
#define GENERATING_MAC /*use for mac native code*/
#define HAVE_OPENTRANSPORT /*used for OpenTransport Networking*/
#undef PATH_SEPARATOR
-#undef SOCKET_ZERO_ISNT_STDIN
+#define SOCKET_ZERO_ISNT_STDIN 1
/* Define if you have the __argz_count function. */
@@ -168,4 +171,10 @@
#define HAVE_STRERROR
+/* Define if you have the strlcat function. */
+#undef HAVE_STRLCAT
+
+/* Define if you have the strlcpy function. */
+#undef HAVE_STRLCPY
+
/* Define if you have the strstr function. */
#define HAVE_STRSTR
@@ -174,4 +183,7 @@
#undef HAVE_USLEEP
+/* Define if you have the vsnprintf function. */
+#undef HAVE_VSNPRINTF
+
/* Define if you have the <argz.h> header file. */
#undef HAVE_ARGZ_H
@@ -180,4 +192,7 @@
#undef HAVE_ARPA_INET_H
+/* Define if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
/* Define if you have the <limits.h> header file. */
#define HAVE_LIMITS_H
@@ -248,4 +263,5 @@
/* Version number of package */
#undef VERSION
+
#endif /* FC_CONFIG_H */
Index: clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.24
diff -u -2 -r1.24 clinet.c
--- clinet.c 2000/03/05 15:00:57 1.24
+++ clinet.c 2000/05/21 22:35:41
@@ -58,4 +58,8 @@
#include <arpa/inet.h>
#endif
+#ifdef HAVE_OPENTRANSPORT
+#include <OpenTransport.h>
+#include <OpenTptInternet.h>
+#endif
#include "capstr.h"
@@ -87,7 +91,18 @@
{
/* use name to find TCPIP address of server */
+#ifdef HAVE_OPENTRANSPORT
+ OSStatus err1;
+ OSErr err2;
+ InetSvcRef ref=OTOpenInternetServices(kDefaultInternetServicesPath, 0,
&err1);
+ InetHostInfo hinfo;
+ TEndpointInfo src_info;
+ EndpointRef src_ep;
+ InetAddress src_addr;
+ char *temperr="";
+#else
struct sockaddr_in src;
struct hostent *ph;
long address;
+#endif
struct packet_req_join_game req;
@@ -98,4 +113,29 @@
hostname="localhost";
+#ifdef HAVE_OPENTRANSPORT
+ if (err1!=0)
+ {
+ sprintf(temperr, _("Error opening OpenTransport (type: %n)"),err1);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return -1;
+ }
+ err1=OTInetStringToAddress(ref, hostname, &hinfo);
+ src_addr.fHost=hinfo.addrs[0];
+ if((src_addr.fHost == 0) || (err1 != 0))
+ {
+ sprintf(temperr, _("Error (type: %n) Failed looking up host %s"),
+ err1, hostname);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return -1;
+ }
+ src_ep=OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0, &src_info,
&err1);
+ if(err1 != 0){
+ sprintf(temperr, _("Error (type: %n) opening socket to %s"),
+ err1, hostname);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return -1;
+ }
+
+#else
if(isdigit((size_t)*hostname)) {
if((address = inet_addr(hostname)) == -1) {
@@ -117,4 +157,5 @@
src.sin_port = htons(port);
+
#ifdef HAVE_SIGPIPE
/* ignore broken pipes */
@@ -132,4 +173,5 @@
return -1;
}
+#endif
aconnection.buffer.ndata=0;
@@ -160,5 +202,9 @@
{
append_output_window(_("Disconnecting from server."));
+#ifdef HAVE_OPENTRANSPORT
+ OTUnbind(aconnection.sock);
+#else
close(aconnection.sock);
+#endif
remove_net_input();
set_client_state(CLIENT_PRE_GAME_STATE);
@@ -202,7 +248,21 @@
{
struct server_list *server_list;
+#ifdef HAVE_OPENTRANSPORT
+ OSStatus err1;
+ OSErr err2;
+ OTResult err3;
+ InetSvcRef ref=OTOpenInternetServices(kDefaultInternetServicesPath, 0,
&err1);
+ InetHostInfo hinfo;
+ TEndpointInfo info;
+ EndpointRef ep;
+ InetAddress addr;
+ TBind req;
+ OTFlags* flags=0;
+ char *temperr="";
+#else
struct sockaddr_in addr;
struct hostent *ph;
int s;
+#endif
FILE *f;
char *proxy_url;
@@ -261,4 +321,39 @@
}
+
+#ifdef HAVE_OPENTRANSPORT
+ if (err1!=0)
+ {
+ sprintf(temperr, _("Error opening OpenTransport (type: %n)"),err1);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+ err1=OTInetStringToAddress(ref, server, &hinfo);
+ addr.fHost=hinfo.addrs[0];
+ if((addr.fHost == 0) || (err1 != 0))
+ {
+ sprintf(temperr, _("Error (type: %n) Failed looking up host %s"),
+ err1, server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+ ep=OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0, &info, &err1);
+ if(err1 != 0){
+ sprintf(temperr, _("Error (type: %n) opening socket to %s"),
+ err1, server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+ req.addr.buf=(unsigned char *)server;
+ req.addr.len=strlen(server);
+ req.qlen=256;/*just a guess*/
+ err1=OTBind(ep, &req, NULL);
+ if(err1 != 0){
+ sprintf(temperr, _("Error (type: %n) opening socket to %s"),
+ err1, server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
if ((ph = gethostbyname(server)) == NULL) {
mystrlcpy(errbuf, _("Failed looking up host"), n_errbuf);
@@ -281,5 +376,5 @@
return NULL;
}
-
+#endif
#ifdef HAVE_FDOPEN
f=fdopen(s,"r+");
@@ -291,18 +386,87 @@
#else
{
- int i;
+ int i=0;
f=tmpfile();
+#ifdef HAVE_OPENTRANSPORT
+ err3=OTSnd(ep, "GET ", 4,T_MORE);
+/*T_MORE is used to (probably) send the whole request in one batch*/
+ if (err3<0)
+ {
+ sprintf(temperr, _("Error (type: %n) sending data to %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
send(s,"GET ",4,0);
- if(!proxy_url) send(s,"/",1,0);
+#endif
+ if(!proxy_url){
+#ifdef HAVE_OPENTRANSPORT
+ err3=OTSnd(ep,"/",1,T_MORE);
+ if (err3<0)
+ {
+ sprintf(temperr, _("Error (type: %n) sending data to %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
+ send(s,"/",1,0);
+#endif
+ }
+#ifdef HAVE_OPENTRANSPORT
+ err3=OTSnd(ep,urlpath,strlen(urlpath),T_MORE);
+ if (err3<0)
+ {
+ sprintf(temperr, _("Error (type: %n) sending data to %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
send(s,urlpath,strlen(urlpath),0);
- if(proxy_url) send(s,metaserver,strlen(metaserver),0);
+#endif
+ if(!proxy_url){
+#ifdef HAVE_OPENTRANSPORT
+ err3=OTSnd(ep,metaserver,strlen(metaserver),T_MORE);
+ if (err3<0)
+ {
+ sprintf(temperr, _("Error (type: %n) sending data to %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
+ send(s,metaserver,strlen(metaserver),0);
+#endif
+ }
+#ifdef HAVE_OPENTRANSPORT
+ err3=OTSnd(ep," HTTP/1.0\r\n\r\n", sizeof(" HTTP/1.0\r\n\r\n"),0);
+ if (err3<0)
+ {
+ sprintf(temperr, _("Error (type: %n) sending data to %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
send(s," HTTP/1.0\r\n\r\n", sizeof(" HTTP/1.0\r\n\r\n"),0);
-
+#endif
+#ifdef HAVE_OPENTRANSPORT
+ while ((err3 = OTRcv(ep, str, sizeof(str), flags)) > 0)
+ fwrite(str,1,i,f);
+ if (i<0)
+ {
+ sprintf(temperr, _("Error (type: %n) recieving data from %s"),err3,
server);
+ mystrlcpy(errbuf, temperr, n_errbuf);
+ return NULL;
+ }
+#else
while ((i = recv(s, str, sizeof(str), 0)) > 0)
fwrite(str,1,i,f);
+#endif
fflush(f);
-
+#ifdef HAVE_OPENTRANSPORT
+ OTUnbind(ep);
+ OTCloseEndpoint(ep);
+#else
close(s);
+#endif
fseek(f,0,SEEK_SET);
Index: civserver.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v
retrieving revision 1.160
diff -u -2 -r1.160 civserver.c
--- civserver.c 2000/05/18 18:45:07 1.160
+++ civserver.c 2000/05/21 22:48:38
@@ -20,4 +20,7 @@
#include <string.h>
#include <assert.h>
+#ifdef GENERATING_MAC
+#include <ansi_prefix.mac.h> /*needed in time.h*/
+#endif
#include <time.h>
Index: civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.78
diff -u -2 -r1.78 civclient.c
--- civclient.c 2000/04/30 13:15:37 1.78
+++ civclient.c 2000/05/21 22:34:11
@@ -15,4 +15,8 @@
#endif
+#ifdef GENERATING_MAC
+#include <ansi_prefix.mac.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
Index: aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.114
diff -u -2 -r1.114 aiunit.c
--- aiunit.c 2000/05/20 04:11:48 1.114
+++ aiunit.c 2000/05/21 22:31:57
@@ -671,8 +671,8 @@
int xx, yy, best_xx = punit->x, best_yy = punit->y;
int dist = 100;
- int far = real_map_distance( pc->x, pc->y, punit->x, punit->y );
+ int leng = real_map_distance( pc->x, pc->y, punit->x, punit->y );
- for( i = 1-far; i < far; i++ )
- for( j = 1-far; j < far; j++ ) {
+ for( i = 1-leng; i < leng; i++ )
+ for( j = 1-leng; j < leng; j++ ) {
xx = map_adjust_x(punit->x + i);
yy = map_adjust_y(punit->y + j);
Index: aitech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitech.c,v
retrieving revision 1.21
diff -u -2 -r1.21 aitech.c
--- aitech.c 1999/10/03 07:15:26 1.21
+++ aitech.c 2000/05/21 22:30:45
@@ -190,13 +190,37 @@
}
+#undef MEM_MODE
+#define MEM_MODE 0
+/**********************************************************************
+mem_mode 0 is the normal/origional behavior
+mem_mode 1 use maloc/free to allocate the memory for some large vars.
+ This method was created so this could compile on the mac w/ codewarior
10
+mem_mode 2 allocates the memory once for those variables and keeps it
around.
+ This is an alternate method to mode 1
+modes 1 and 2 have not been tested, use at your own risk-AWB
+***********************************************************************/
+
static void ai_select_tech(struct player *pplayer, struct ai_choice
*choice,
struct ai_choice *gol)
{
int i, j, k;
+#if defined (GENERATING_MAC) || MEM_MODE
+#if MEM_MODE=2
+ static int * values=(int *)fc_malloc(sizeof(char)*game.num_tech_types);
+ static int *goal_values=(int
*)fc_malloc(sizeof(char)*game.num_tech_types);
+ static int *prereq=(int *)fc_malloc(sizeof(char)*game.num_tech_types);
+ static unsigned char **cache=(unsigned char
**)fc_malloc(sizeof(char)*game.num_tech_types*game.num_tech_types);
+#else
+ int * values=(int *)fc_malloc(sizeof(char)*game.num_tech_types);
+ int *goal_values=(int *)fc_malloc(sizeof(char)*game.num_tech_types);
+ int *prereq=(int *)fc_malloc(sizeof(char)*game.num_tech_types);
+ unsigned char **cache=(unsigned char
**)fc_malloc(sizeof(char)*game.num_tech_types*game.num_tech_types);
+#endif
+#else
int values[A_LAST];
int goal_values[A_LAST];
int prereq[A_LAST];
unsigned char cache[A_LAST][A_LAST];
-
+#endif
int c = MAX(1, city_list_size(&pplayer->cities));
memset(values, 0, sizeof(values));
@@ -262,7 +286,18 @@
advances[gol->choice].name, gol->want, goal_values[k], c);
}
+#if (defined (GENERATING_MAC)&&(MEM_MODE!=2)) || MEM_MODE==1
+ /*always cleanup your allocated memory, unless it's static.
+ if you cleaned up your static memory, it would make the static
pointless,
+ and create the scary situation of possibly writing over alocated
memory blocks-AWB*/
+ free(values);
+ free(goal_values);
+ free(prereq);
+ free(cache);
+#endif
return;
}
+#undef MEM_MODE
+
static void ai_select_tech_goal(struct player *pplayer, struct ai_choice
*choice)
{
@@ -336,3 +371,3 @@
choose_tech_goal(pplayer, gol.choice);
}
-}
+}
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Mac Port patches,
Andy Black <=
|
|