#include "int32.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define true (!false)
#define false 0
int32 coreleft(void)
{
	return 4000000l;
}
char *strlwr(char *s)
{
	char *ss=s;
	while (*s!=0) {*s = tolower(*s); s++;}
	return ss;
}
char *strupr(char *s)
{
	char *ss=s;
	while (*s!=0) {*s = toupper(*s); s++;}
	return ss;
}

trim_file(char *s)
{
	char *t;
	t = strchr(s,']');
	if (t!=NULL) memcpy(s,t+1,strlen(t));
	t = strchr(s,';');
	if (s!=NULL) *t = 0;
}
char *getsymbol(char *sym)
{
	static char mystr[200],*s;
	s = getenv(sym);
	if (s==NULL) s = "";
	strcpy(mystr,sym);
	return mystr;	
}

#ifndef DJ      /* a.r. */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#define false 0
#define true (!false)

FILE *wilddir;
struct ffblk {char *ff_name;};
findfirst(char *wild, struct ffblk *ffblk, int zz)
{
	static char buff[200];
	int op;
       #ifdef aix /* AIX with xlc != POSIX */
	union wait *status;
	int p;
       #else
	int status;
	pid_t p;	
       #endif

	p = fork();
	if (p==-1) {perror("Unable to fork ls command \n"); return true;}
	if (p==0) {
		strcpy(buff,"ls ");
		strcat(buff,wild);
		strcat(buff,">gledir.tmp");
		execlp("sh","sh","-c", buff,0);
		exit(1);
	}
       #ifdef aix
	waitpid(p,status,op);
       #else
	waitpid(p,&status,op);
       #endif

	wilddir = fopen("gledir.tmp","r");		
	if (wilddir==NULL) {printf("Fork ls failed \n"); return true;}
	if (feof(wilddir)) { fclose(wilddir); return true;}
	fgets(buff,100,wilddir);
	trimcr(buff);
	ffblk->ff_name = buff;
	return false;
}	
trimcr(char *s)
{
	s = strchr(s,'\n');
	if (s!=NULL) *s = 0;
}
findnext(struct ffblk *ffblk)
{
	static char buff[200];
	if (feof(wilddir)) { fclose(wilddir); return true;}
	fgets(buff,100,wilddir);
	trimcr(buff);
	ffblk->ff_name = buff;
	return false;
}
#endif
