File xjdic.patch of Package xjdic

--- xjdic-2.4/exjdxgen.c
+++ xjdic-2.4/exjdxgen.c
@@ -25,6 +25,7 @@
 /*#include <stdlib.h>*/
 #include <ctype.h>
 #include <string.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 #define TRUE 1
@@ -35,9 +36,9 @@
 unsigned char ENVname[50];
 unsigned char *dicenv;
 struct stat *buf;
-unsigned long dbyte;
-unsigned long  *jindex;
-unsigned long indptr,llone,charno,recpos,charnost;
+uint32_t dbyte;
+uint32_t *jindex;
+uint32_t indptr,llone,charno,recpos,charnost;
 int State;
 unsigned char Dname[80] = {"edictext"};
 unsigned char JDXname[80] = {"edictext.xjdx"};
@@ -45,8 +46,8 @@
 
 /*====== prototypes=================================================*/
 int stringcomp(unsigned char *s1, unsigned char *s2);
-void jqsort(long i, long j);
-int Kstrcmp(unsigned long lhs, unsigned long rhs);
+void jqsort(int32_t i, int32_t j);
+int Kstrcmp(uint32_t lhs, uint32_t rhs);
 /*====== end prototypes=================================================*/
 
 int stringcomp(unsigned char *s1, unsigned char *s2)
@@ -71,7 +72,7 @@
 unsigned char **argv;
 {
   FILE *fp,*fopen();
-  unsigned long schi,diclen,indlen;
+  uint32_t schi,diclen,indlen;
   int i,inwd,saving,nodread;
   unsigned char c;
   unsigned char **ap;
@@ -131,7 +132,7 @@
   db[0] = 10;
   printf("Dictionary size: %ld bytes.\n",dbyte);
   indlen = diclen / 2;
-  jindex = (unsigned long *)malloc(indlen);
+  jindex = (uint32_t *)malloc(indlen);
   if(jindex == NULL)
   {
 	  fprintf(stderr,"malloc() for index table failed.\n");
@@ -182,7 +183,7 @@
 			jindex[indptr] = charnost;
 			jindex[indptr+1] = recpos;
 			indptr+=2;
-			if (indptr > indlen/sizeof(long))
+			if (indptr > indlen/sizeof(int32_t))
 			{
 			  	printf("Index table overflow. Dictionary too large?\n");
 			  	exit(1);
@@ -227,15 +228,15 @@
     	exit(1);
     }
   jindex[0] = diclen+jiver;
-  fwrite(jindex,sizeof(long),indptr+2,fp);
+  fwrite(jindex,sizeof(int32_t),indptr+2,fp);
   fclose(fp);
 }
 /*======function to sort jindex table====================*/
 
-void jqsort(long lhsr, long rhsr)
+void jqsort(int32_t lhsr, int32_t rhsr)
 {
-	long i,last,midp,lhs,rhs;
-	unsigned long temp,temp2;
+	int32_t i,last,midp,lhs,rhs;
+	uint32_t temp,temp2;
 
 	lhs = ((lhsr-1)*2)+1;
 	rhs = ((rhsr-1)*2)+1;
@@ -275,7 +276,7 @@
 	jqsort((last/2)+2,(rhs/2)+1);
 }
 /*=====string comparison used by jqsort==========================*/
-int Kstrcmp(unsigned long lhs, unsigned long rhs)
+int Kstrcmp(uint32_t lhs, uint32_t rhs)
 {
 	int i,c1,c2;
 /* effectively does a strnicmp on two "strings" within the dictionary,
--- xjdic-2.4/xjdclient.c
+++ xjdic-2.4/xjdclient.c
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 #define CVERBOSE 0
@@ -55,17 +56,17 @@
 int curr_timer = TINITVAL;
 int rep_count;
 struct timezone tz;
-long timeofday_st,timeofday_en;
+int32_t timeofday_st,timeofday_en;
 fd_set fildesc;
 int nfds;
 unsigned char *sptr;
 int NoDics,CurrDic;
 char Dnamet[10][100];
 
-void xjdserver (int type, int dic_no, long index_posn, int sch_str_len,
-                unsigned char *sch_str, int *sch_resp, long *res_index, 
+void xjdserver (int type, int dic_no, int32_t index_posn, int sch_str_len,
+                unsigned char *sch_str, int *sch_resp, int32_t *res_index, 
                 int *hit_posn, int *res_len, unsigned char *res_str,
-                long *dic_loc );
+                int32_t *dic_loc );
 void DicSet();
 int connectsock(int portno, char *host);
 void reqchecksum();
@@ -77,7 +78,7 @@
 	the server. */
 
 	int i,schresp, dumint, trying,hullodic;
-	long dumlong,dumlong0 = 0;
+	int32_t dumlong,dumlong0 = 0;
 	char dummy[2],dnamelist[512];
 
 	connectsock(portno, host);
@@ -152,7 +153,7 @@
 
 int respchecksum()
 {
-	long temp;
+	int32_t temp;
 	int i;
 	char yn[5];
 
@@ -199,7 +200,7 @@
 
 void reqchecksum()
 {
-	long temp;
+	int32_t temp;
 	int i;
 
 	temp = ntohs(pdu_out.xjdreq_type);
@@ -212,10 +213,10 @@
 	pdu_out.xjdreq_checksum = htonl(temp);
 }
 
-void xjdserver (int type, int dic_no, long index_posn, int sch_str_len,
-                unsigned char *sch_str, int *sch_resp, long *res_index, 
+void xjdserver (int type, int dic_no, int32_t index_posn, int sch_str_len,
+                unsigned char *sch_str, int *sch_resp, int32_t *res_index, 
                 int *hit_posn, int *res_len, unsigned char *res_str,
-                long *dic_loc )
+                int32_t *dic_loc )
 {
 	int i, ares, sendit;
 
--- xjdic-2.4/xjdcomm.c
+++ xjdic-2.4/xjdcomm.c
@@ -30,6 +30,7 @@
 #ifdef MMAP
 #include <fcntl.h>
 #endif
+#include <stdint.h>
 #include "xjdic.h"
 
 #define FALSE 0
@@ -171,7 +172,7 @@
 #ifdef XJDDIC
 	extern unsigned char Dnamet[10][100],XJDXnamet[10][100];
 	extern unsigned char *dicbufft[10];
-	extern unsigned long diclent[10], indkent[10],indptrt[10];
+	extern uint32_t diclent[10], indkent[10],indptrt[10];
 	extern int NoDics;
 #endif
 	extern unsigned char ENVname[], KDNSlist[];
--- xjdic-2.4/xjdfrontend.c
+++ xjdic-2.4/xjdfrontend.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <errno.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 /*    Paul Burchard supplied a patch to provide BSD compatibility for xjdic
@@ -62,7 +63,7 @@
 extern unsigned char CBname[100];
 extern unsigned char Dnamet[10][100],XJDXnamet[10][100];
 extern unsigned char *dicbufft[10];
-extern unsigned long diclent[10], indkent[10],indptrt[10];
+extern uint32_t diclent[10], indkent[10],indptrt[10];
 extern int NoDics,CurrDic;
 int thisdic = 0;
 int gdicnos[10],gdicmax=0,GDmode=FALSE,gdiclen;
@@ -76,9 +77,9 @@
 #endif
 
 #ifdef XJDDIC
-extern unsigned long dichits[10],dicmiss[10];
-extern unsigned long indhits[10],indmiss[10];
-extern unsigned long vbkills;
+extern uint32_t dichits[10],dicmiss[10];
+extern uint32_t indhits[10],indmiss[10];
+extern uint32_t vbkills;
 #endif
 
 char DicDir[100];
@@ -92,12 +93,12 @@
 unsigned char kanatab[NRKANA*2][7];
 int Omode = 0,Smode = 0,Dmode = 0,AKanaMode;
 int DRow,DCol,MaxY=MAXLINES,MaxX=MAXCOLS-1,KFlushRes,nok;
-unsigned long hittab[NOHITS];
+uint32_t hittab[NOHITS];
 int verblen,DispHit,ksp,hitind,FirstKanj = 0,prieng = FALSE,Extopen=FALSE,NoSkip;
 int extlen,extjdxlen;
 unsigned char kmodes[2][10] = {"ON","OFF"};
 unsigned char kmodes_r[2][10] = {"OFF","ON"};
-unsigned long chline,chpos,it;
+uint32_t chline,chpos,it;
 unsigned char strfilt[10],tempout[80];
 unsigned char KSname[50] = {"kanjstroke"};
 unsigned char RKname[50] = {"radkfile"};
@@ -169,7 +170,7 @@
 int nodia;
 
 int DicNum;
-long DicLoc;
+int32_t DicLoc;
 
 /*====== Prototypes========================================================*/
 
@@ -183,10 +184,10 @@
 void RadLoad();
 void KSLoad();
 void DiaLoad();
-void xjdserver (int type, int dic_no, long index_posn, int sch_str_len, 
-		unsigned char *sch_str, int *sch_resp, long *res_index, 
+void xjdserver (int type, int dic_no, int32_t index_posn, int sch_str_len, 
+		unsigned char *sch_str, int *sch_resp, int32_t *res_index, 
 		int *hit_posn, int *res_len, unsigned char *res_str,
-		long *dic_loc );
+		int32_t *dic_loc );
 void OneShot();
 void RadSet();
 void Verbtoggle();
@@ -205,7 +206,7 @@
 void altdic(int dicincr);
 void DoKANJI();
 void DoJIS();
-int addhit(long spot);
+int addhit(int32_t spot);
 void GetEUC(unsigned char *eucline);
 void cbreakon();
 void cbreakoff();
@@ -803,7 +804,7 @@
 }
 
 /*======function to test if this entry has already been displayed=====*/
-int addhit(long spot)
+int addhit(int32_t spot)
 {
 	int i;
 
@@ -954,7 +955,7 @@
         	fex  = xfopen(EXTJDXname,"rb", &extjdxlen);
 		Extopen = TRUE;
 		extlen++;
-		fread(ejdxtest,sizeof(long),1,fex);
+		fread(ejdxtest,sizeof(int32_t),1,fex);
 		if (ejdxtest[0] != (extlen+jiver))
 		{
 			printf("\nEDICT Extension file & Index Mismatch! %ld %ld\n",ejdxtest[0],extlen+jiver);
@@ -963,15 +964,15 @@
 	}
 
 	lo = 0;
-	hi = (extjdxlen/(2*sizeof(long)))-1;
+	hi = (extjdxlen/(2*sizeof(int32_t)))-1;
 	while(TRUE)
 	{
 		mid = (lo+hi)/2;
 		seekoff = mid;
-		seekoff *= (2*sizeof(long));
-		seekoff+=sizeof(long);
+		seekoff *= (2*sizeof(int32_t));
+		seekoff+=sizeof(int32_t);
 		if((iores = fseek(fex,seekoff,SEEK_SET)) != 0)SeekErr(iores);
-		iores = fread(&extrec,sizeof(long),2,fex);
+		iores = fread(&extrec,sizeof(int32_t),2,fex);
 		seekoff = extrec[0];
 		if((iores = fseek(fe,seekoff,SEEK_SET)) != 0)SeekErr(iores);
 		iores = fread(&Ssch,sizeof(char),19,fe);
@@ -1130,10 +1131,10 @@
 
 	int xjresp,roff,rlen;
 	unsigned char repstr[RESPLEN];
-	long respos;
+	int32_t respos;
 	int hit,schix;
 	unsigned char khi,klo,cc,ops[4];
-	long it;
+	int32_t it;
 
 	DicNum = CurrDic;
 	khi = 0;
@@ -1313,14 +1314,14 @@
   	int EngFirst;
 	int slk,slen,slenx,i,srchlen,srchlenok;
   	unsigned int khi,klo,cc;
-  	unsigned long zz,bshit[20];
+  	uint32_t zz = 0, bshit[20];
   	unsigned char *kptr,*kptr2, k1,k2,kanj1,kanj2,kanj3;
 	int FiltOK;
 	unsigned char vlast[11],temp[11],ops[80];
 	int vi,vok,prevch,KDNSflag,KDskip,KTest;
 	int xjresp,roff,rlen;
 	unsigned char repstr[RESPLEN];
-	unsigned long respos;
+	uint32_t respos;
 
 	vlast[0] = 0;
 	KLcount = 0;
--- xjdic-2.4/xjdic.h
+++ xjdic-2.4/xjdic.h
@@ -50,22 +50,22 @@
 /*	PDU structures		*/
 
 typedef struct {
-	long	xjdreq_checksum;
+	int32_t	xjdreq_checksum;
 	short		xjdreq_type;
 	short		xjdreq_seq;
 	short		xjdreq_dicno;
-	long	xjdreq_indexpos;
+	int32_t	xjdreq_indexpos;
 	short		xjdreq_schlen;
 	unsigned char	xjdreq_schstr[21];
 	} REQ_PDU;
 
 typedef struct {
-	long	xjdrsp_checksum;
+	int32_t	xjdrsp_checksum;
 	short		xjdrsp_type;
 	short		xjdrsp_seq;
-	long	xjdrsp_resindex;
+	int32_t	xjdrsp_resindex;
 	short		xjdrsp_hitposn;
 	short		xjdrsp_reslen;
-	long	xjdrsp_dicloc;
+	int32_t	xjdrsp_dicloc;
 	unsigned char	xjdrsp_resstr[1024];
 	} RSP_PDU;
--- xjdic-2.4/xjdic24.inf
+++ xjdic-2.4/xjdic24.inf
@@ -1128,25 +1128,25 @@
 The format of the REQUEST and RESPONSE messages is shown below. 
 
         typedef struct {
-                long           xjdreq_checksum;
+                int32_t           xjdreq_checksum;
                 short          xjdreq_type;
                 short          xjdreq_seq;
                 short          xjdreq_dicno;
-                long           xjdreq_indexpos;
+                int32_t           xjdreq_indexpos;
                 short          xjdreq_schlen;
                 unsigned char  xjdreq_schstr[21]; } REQ_PDU;
 
         typedef struct {
-                long           xjdrsp_checksum;
+                int32_t        xjdrsp_checksum;
                 short          xjdrsp_type;
                 short          xjdrsp_seq;
-                long           xjdrsp_resindex;
+                int32_t        xjdrsp_resindex;
                 short          xjdrsp_hitposn;
                 short          xjdrsp_reslen;
-		long           xjdrsp_dicloc;
+		int32_t        xjdrsp_dicloc;
                 unsigned char  xjdrsp_resstr[512]; } RSP_PDU; 
          
-(All the short and long integer fields have their bytes in "network order.") 
+(All the short and int32_t integer fields have their bytes in "network order.") 
 
 The  check-sum  field consists simply of the arithmetic summation of all the 
 fields in the message,  except the check-sum itself.  If the server receives 
--- xjdic-2.4/xjdsa.c
+++ xjdic-2.4/xjdsa.c
@@ -28,29 +28,30 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 unsigned char Dnamet[10][100],XJDXnamet[10][100];
 unsigned char CBname[100];
 unsigned char *dicbufft[10];
-unsigned long diclent[10], indlent[10],indptrt[10];
+uint32_t     diclent[10], indlent[10],indptrt[10];
 int NoDics,CurrDic;
 int iterlimit;
 
 /* extern int TRIGGER; */
 
-void xjdserver (int type, int dic_no, long index_posn, int sch_str_len, 
-		unsigned char *sch_str, int *sch_resp, long *res_index, 
+void xjdserver (int type, int dic_no, int32_t index_posn, int sch_str_len, 
+		unsigned char *sch_str, int *sch_resp, int32_t *res_index, 
 		int *hit_posn, int *res_len, unsigned char *res_str,
-		long *dic_loc );
+		int32_t *dic_loc );
 
 
 /*===xjserver===front-end routine for the dictionary lookup engine========*/
 
-void xjdserver (int type, int dic_no, long index_posn, int sch_str_len, 
-		unsigned char *sch_str, int *sch_resp, long *res_index, 
+void xjdserver (int type, int dic_no, int32_t index_posn, int sch_str_len, 
+		unsigned char *sch_str, int *sch_resp, int32_t *res_index, 
 		int *hit_posn, int *res_len, unsigned char *res_str,
-		long *dic_loc )
+		int32_t *dic_loc )
 /*
 	This function handles all access to the dictionary files and indices.
 	The accesses have been consolidated here to cater for an alternative
@@ -66,8 +67,8 @@
 
 */
 {
-	long lo, hi, itok, lo2, hi2, schix, schiy;
-	extern long it;
+	int32_t lo, hi, itok, lo2, hi2, schix, schiy;
+	extern int32_t it;
 	int res, i;
 
 	hi = indptrt[dic_no];
--- xjdic-2.4/xjdservcomm.c
+++ xjdic-2.4/xjdservcomm.c
@@ -30,6 +30,7 @@
 #ifdef MMAP
 #include <sys/mman.h>
 #endif
+#include <stdint.h>
 #include "xjdic.h"
 
 #ifndef MAP_FILE
@@ -39,29 +40,29 @@
 #define MAP_FAILED (void *)-1
 #endif
 
-unsigned long dbyte;
+uint32_t dbyte;
 
 unsigned char Dnamet[10][100],XJDXnamet[10][100];
 unsigned char *dicbufft[10],dntemp[100];
-unsigned long *jdxbufft[10];
-unsigned long dichits[10],dicmiss[10];
-unsigned long indhits[10],indmiss[10];
-unsigned long vbkills=0;
-unsigned long diclent[10], indlent[10],indptrt[10];
+uint32_t      *jdxbufft[10];
+uint32_t      dichits[10],dicmiss[10];
+uint32_t      indhits[10],indmiss[10];
+uint32_t      vbkills=0;
+uint32_t      diclent[10], indlent[10],indptrt[10];
 int i,NoDics,CurrDic;
 int xfilelen;
 
 /*====== Prototypes========================================================*/
 FILE *xfopen (char *name, char *mode, int *xfilelen);
 int xopen (char *name, int *xfilelen);
-unsigned long jindex(unsigned long xit);
-unsigned char dbchar(unsigned long xit);
+uint32_t  jindex(uint32_t xit);
+unsigned  char dbchar(uint32_t xit);
 void DicSet  ();
 int Kstrcmp(int klen,unsigned char *str1);
 void DicLoad(int dn);
 unsigned char *DicName(int dn);
 void DicTest(int dn);
-void getvbuff (int *offp, FILE *fp, long vbo);
+void getvbuff (int *offp, FILE *fp, int32_t vbo);
 void SeekErr(int iores);
 
 #ifdef MMAP
@@ -79,7 +80,7 @@
 void *vbuffs[NOVB];
 void *vbres;
 int *vbptr[NOVB];
-long usebuff[NOVB], vbusage = 1;
+int32_t usebuff[NOVB], vbusage = 1;
 int *doffp[10],*joffp[10];
 int MAXDIC,MAXJDX;  /* formerly defines, now set dynamically */
 int MAXDICTAB,MAXJDXTAB; 
@@ -92,11 +93,11 @@
 
 /*=====dbchar====returns specified character from dictionary===============*/
 
-unsigned char dbchar(unsigned long it)
+unsigned char dbchar(uint32_t it)
 {
 	int vbo, vbc,ibuff;
 	char *myp;
-	long it2;
+	int32_t it2;
 	extern int DicNum;
 
 	it2 = it-1;
@@ -125,17 +126,17 @@
 
 /*======jindex  returns specified entry from .jdx file========*/
 
-unsigned long jindex(unsigned long it)
+uint32_t jindex(uint32_t it)
 {
 	int vbo, vbl,ibuff;
-	long *myp;
-	long it2;
+	int32_t *myp;
+	int32_t it2;
 	extern int DicNum;
 
 /* indordic=1; */
-	it2 = it*sizeof(long);
+	it2 = it*sizeof(int32_t);
 	vbo = it2/VBUFFSIZE;   /*page number*/
-	vbl = (it2 % VBUFFSIZE) / sizeof(long); /*offset within page  */
+	vbl = (it2 % VBUFFSIZE) / sizeof(int32_t); /*offset within page  */
 /* printf("jindex - DN: %d it: %ld vbo: %d vbl: %d\n",it,DicNum,vbo,vbl); */
 
 	if (joffp[DicNum][vbo] == -1)
@@ -156,10 +157,10 @@
 
 /*=====getvbuff===allocates a free virtual buffer and reads in the page===*/
 
-void getvbuff (int *offp, FILE *fp, long vbo)
+void getvbuff (int *offp, FILE *fp, int32_t vbo)
 {
 	int ibuff,i,iores;
-	long maxu,seekoff;
+	int32_t maxu,seekoff;
 	extern int DicNum;
 
 /* printf("getvbuff - DN: %d offp: %d vbo: %ld\n",DicNum,offp,vbo); */
@@ -232,7 +233,7 @@
 /*====DicTest check Dictionary and index files=======*/
 void DicTest(int dn)
 {
-	long testwd[1];
+	int32_t testwd[1];
 	int diclenx;
 
 	extern int jiver;
@@ -247,7 +248,7 @@
   	diclenx++;
   	fclose(fpd);
   	fpd = xfopen(XJDXnamet[dn],"rb", &xfilelen);
-	fread(&testwd[0],sizeof(long),1,fpd);
+	fread(&testwd[0],sizeof(int32_t),1,fpd);
 	if (testwd[0] != (diclenx+jiver))
 	{
 		printf ("The %s dictionary and index files do not match! \n",Dnamet[dn]);
@@ -289,16 +290,16 @@
   	dbyte = diclent[dn];
   	fpd = xfopen(XJDXnamet[dn],"rb", &xfilelen);
         indlent[dn] = xfilelen;
-        jdxbufft[dn] = (unsigned long *)malloc((indlent[dn]+1024) * sizeof(unsigned char));
+        jdxbufft[dn] = (uint32_t *)malloc((indlent[dn]+1024) * sizeof(unsigned char));
         if(jdxbufft[dn] == NULL)
         {
                 fprintf(stderr,"malloc() for index failed.\n");
                 fclose(fpd);
         exit(1);
         }
-	indptrt[dn] = indlent[dn]/sizeof(long)-1;
+	indptrt[dn] = indlent[dn]/sizeof(int32_t)-1;
         nodread = indlent[dn]/1024+1;
-	fread((long *)jdxbufft[dn],1024,nodread,fpd);
+	fread((int32_t *)jdxbufft[dn],1024,nodread,fpd);
 	if (jdxbufft[dn][0] != (diclent[dn]+jiver))
 	{
 		printf ("The dictionary and index files do not match! \n");
@@ -334,7 +335,7 @@
 
   	fpi[dn] = xfopen(XJDXnamet[dn],"rb", &xfilelen);
         indlent[dn] = xfilelen;
-	indptrt[dn] = indlent[dn]/sizeof(long)-1;
+	indptrt[dn] = indlent[dn]/sizeof(int32_t)-1;
 	len = (indlent[dn]/VBUFFSIZE)+1;
         joffp[dn] = (int *)malloc(len * sizeof(int));
         if(joffp[dn] == NULL)
@@ -366,8 +367,8 @@
   	diclent[dn]++;
   	fdi[dn] = xopen(XJDXnamet[dn],&xfilelen);
         indlent[dn] = xfilelen;
-	indptrt[dn] = indlent[dn]/sizeof(long)-1;
-	if ((jdxbufft[dn] = (long *) mmap(0, xfilelen, PROT_READ, MAP_FILE | MAP_SHARED, fdi[dn],0)) == MAP_FAILED)
+	indptrt[dn] = indlent[dn]/sizeof(int32_t)-1;
+	if ((jdxbufft[dn] = (int32_t *) mmap(0, xfilelen, PROT_READ, MAP_FILE | MAP_SHARED, fdi[dn],0)) == MAP_FAILED)
 	{
 		printf ("Unable to map %s.xjdx! [%s]\n",DicName(dn),strerror(errno));
 		exit(1);
@@ -379,7 +380,7 @@
 /* 	This routine looks funny, because it is the remnant of much more
 	complex code in JDIC/JREADER which did demand-paging at this point   */
 
-unsigned char dbchar(unsigned long xit)
+unsigned char dbchar(uint32_t xit)
 {
 	extern int DicNum;
 
@@ -392,10 +393,10 @@
 /* 	This routine looks funny, because it is the remnant of much more
 	complex code in JDIC/JREADER which did demand-paging at this point   */
 
-unsigned char dbchar(unsigned long xit)
+unsigned char dbchar(uint32_t xit)
 {
 	extern int DicNum;
-	long it2;
+	int32_t it2;
 
 	it2 = xit-1;
 	if ((it2 < 0)||(it2 > diclent[DicNum])) return(10);
@@ -406,7 +407,7 @@
 #if defined (RAM_LOAD) || defined (MMAP)
 /*======jindex  returns specified entry from .xjdx file========*/
 
-unsigned long jindex(unsigned long xit)
+uint32_t jindex(uint32_t xit)
 {
 	extern int DicNum;
 
@@ -422,7 +423,7 @@
 {
 	unsigned c1,c2;
 	int i,rc1,rc2;
-	extern long it;
+	extern int32_t it;
 
 /* effectively does a strnicmp on two "strings" 
    except it will make katakana and hiragana match (EUC A4 & A5) */
--- xjdic-2.4/xjdserver.c
+++ xjdic-2.4/xjdserver.c
@@ -28,6 +28,7 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 #define SVERBOSE 0
@@ -47,9 +48,9 @@
 struct sockaddr_in fsin;
 int sock;
 
-long lo, hi, itok, lo2, hi2, schix, schiy;
+int32_t lo, hi, itok, lo2, hi2, schix, schiy;
 int res, i;
-long it;
+int32_t it;
 unsigned char ENVname[50];
 unsigned char cl_rcfile[100];
 int jiver = 14; 
@@ -60,7 +61,7 @@
 
 extern unsigned char Dnamet[10][100],XJDXnamet[10][100];
 extern unsigned char *dicbufft[10];
-extern unsigned long diclent[10], indlent[10],indptrt[10];
+extern uint32_t diclent[10], indlent[10],indptrt[10];
 extern int NoDics,CurrDic;
 
 char DicDir[100];
@@ -97,7 +98,7 @@
 
 int checksum_in()
 {
-	long temp;
+	int32_t temp;
 
 	temp = ntohs(pdu_in.xjdreq_type);
 	temp+= ntohs(pdu_in.xjdreq_seq);
@@ -112,7 +113,7 @@
 
 void sendresponse()
 {
-	long temp;
+	int32_t temp;
 
 	temp = ntohs(pdu_out.xjdrsp_type);
 	temp+= ntohs(pdu_out.xjdrsp_seq);
--- xjdic-2.4/xjdxgen.c
+++ xjdic-2.4/xjdxgen.c
@@ -21,11 +21,12 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-
+#include <unistd.h>
 #include <stdio.h>
 /*#include <stdlib.h>*/
 #include <ctype.h>
 #include <string.h>
+#include <stdint.h>
 #include "xjdic.h"
 
 #define TRUE 1
@@ -38,9 +39,9 @@
 unsigned char ENVname[50];
 unsigned char *dicenv;
 struct stat *buf;
-unsigned long dbyte;
-unsigned long  *jindex;
-unsigned long indptr,llone;
+uint32_t dbyte;
+uint32_t *jindex;
+uint32_t indptr,llone;
 unsigned char ctl_file[80] = {".xjdicrc"};
 unsigned char Dname[80] = {"edict"};
 unsigned char JDXname[80] = {"edict.xjdx"};
@@ -52,8 +53,8 @@
 
 /*====== prototypes=================================================*/
 int stringcomp(unsigned char *s1, unsigned char *s2);
-void jqsort(long i, long j);
-int Kstrcmp(unsigned long lhs, unsigned long rhs);
+void jqsort(int32_t i, int32_t j);
+int Kstrcmp(uint32_t lhs, uint32_t rhs);
 void xjdicrc();
 int alphaoreuc(unsigned char x);
 
@@ -73,13 +74,16 @@
 	return (0);
 }
 
+extern char *getenv(const char *name);
+
+
 /*====function to Load Dictionary and load/create index table=======*/
-main(argc,argv)
+int main(argc,argv)
 int argc;
 unsigned char **argv;
 {
   FILE *fp,*fopen();
-  unsigned long possav,schi,diclen,indlen;
+  uint32_t possav,schi,diclen,indlen;
   int i,inwd,cstrp,saving,isc,nodread;
   int arg_c;
   unsigned char c;
@@ -154,8 +158,8 @@
   db[diclen] = 10;
   db[0] = 10;
   printf("Dictionary size: %ld bytes.\n",dbyte);
-  indlen = (diclen * sizeof(long))/4;
-  jindex = (unsigned long *)malloc(indlen);
+  indlen = (diclen * sizeof(uint32_t))/4;
+  jindex = (uint32_t *)malloc(indlen);
   if(jindex == NULL)
   {
 	  fprintf(stderr,"malloc() for index table failed.\n");
@@ -189,7 +193,7 @@
 			  {
 				  possav = jindex[indptr];
 				  indptr++;
-					if (indptr > indlen/sizeof(long))
+					if (indptr > indlen/sizeof(uint32_t))
 					{
 					printf("Index table overflow. Dictionary too large?\n");
 					exit(1);
@@ -203,7 +207,7 @@
 					{
 						jindex[indptr] = possav+i;
 						indptr++;
-                                  		if (indptr > indlen/sizeof(long))
+                                  		if (indptr > indlen/sizeof(uint32_t))
                                   		{
                                           		printf("Index table overflow. Dictionary too large?\n");
                                           		exit(1);
@@ -215,7 +219,7 @@
 			  if (saving && (currstr[0] < 127))
 			  {
 				  indptr++;
-				  if (indptr > indlen/sizeof(long))
+				  if (indptr > indlen/sizeof(uint32_t))
 				  {
 					  printf("Index table overflow. Dictionary too large?\n");
 					  exit(1);
@@ -226,7 +230,7 @@
 				  	jindex[indptr] = jindex[indptr-1]+1;
 				  	strcpy(currstr,currstr+1);
 				  	indptr++;
-				  	if (indptr > indlen/sizeof(long))
+				  	if (indptr > indlen/sizeof(uint32_t))
 				  	{
 					  	printf("Index table overflow. Dictionary too large?\n");
 					  	exit(1);
@@ -271,7 +275,7 @@
     exit(1);
   }
   jindex[0] = diclen+jiver;
-  fwrite(jindex,sizeof(long),indptr+1,fp);
+  fwrite(jindex,sizeof(uint32_t),indptr+1,fp);
   i = fclose(fp);
   if (i != 0)
   {
@@ -281,10 +285,10 @@
   exit (0);
 }
 /*======function to sort jindex table====================*/
-void jqsort(long lhs, long rhs)
+void jqsort(int32_t lhs, int32_t rhs)
 {
-	long i,last,midp;
-	unsigned long temp;
+	int32_t i,last,midp;
+	uint32_t temp;
 	if (lhs >= rhs) return;
 	/* Swap ( lhs , (lhs+rhs)/2);*/
 	midp = (lhs+rhs)/2;
@@ -311,9 +315,9 @@
 	jqsort(last+1,rhs);
 }
 /*=====string comparison used by jqsort==========================*/
-int Kstrcmp(unsigned long lhs, unsigned long rhs)
+int Kstrcmp(uint32_t lhs, uint32_t rhs)
 {
-	int i,c1,c2;
+	int i,c1 = 0, c2 = 0;
 /* effectively does a strnicmp on two "strings" within the dictionary,
    except it will make katakana and hirgana match (EUC A4 & A5) */