// Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator
// From input file "/usr/include/p2c/import/xdos.p"


#include <p2c/p2c.h>


#define XDOS_G
#include <p2c/xdos.h>


#include <dirent.h>
#include <stdlib.h>
#include <time.h>

struct DIR *dir;
struct dirent *entry;

time_t BaseTimeStamp;


#define GetEnv	getenv
/*
Char *GetEnv(Char *Result, Char *s)
{
//  Char H[256];
//  getenv
  return strcpy(Result, getenv(s));
}
*/

void FSplit(Char *f, Char *p, Char *n, Char *e)
{
  char *s,*s3,*s4;
  char s2[256];

  int i;

  strcpy(s2,f);
  s3=NULL;
  s4=NULL;

  i=strlen(s2);
  s=&s2[0];
  s=s+i;		// s points to last char in s2

  while (s != &s2[0]) 
    {
     s--;
#ifdef DEBUG
     fprintf(stderr,"%c",*s);  
#endif     
     
     if ((*s == '.') && (s3 == NULL))
        {
         s3=s + 1;
         *s='\0';
        }

     if ((*s == '/') && (s4 == NULL))
        {
         s4=s + 1;
         *s='\0';
        }
    }
  
  if (s3 != NULL)
//     strcpy(e,s3);  
     sprintf(e,".%s",s3); 
   else
     strcpy(e,"\0");  

  if (s4 != NULL)
    {
     strcpy(n,s4);  
//     strcpy(p,s2);
     sprintf(p,"%s/",s2);
    } 
   else
    {
     strcpy(n,s2);  
     strcpy(p,"\0");
    } 
 
#ifdef DEBUG
   fprintf(stderr,"\n FSplit(%s,%s,%s)\n",p,n,e);
#endif     
}

void FindFirst(Char *msk, int Attr, SearchRec *SR)
{
  if (dir!=NULL) 
     	closedir(dir);
  
  dir=opendir(msk);
  if (dir==NULL)
     {
      DosError=-1;
      return;
     } 
      
        
  entry=readdir(dir);
  if (entry==NULL)
     { 
      DosError=-2;
      return;
     } 
        
  strcpy(SR->Name,entry->d_name);      
}



void GetTime(int *hour, int *min, int *sec, int *hsec)
{
  time_t time_val = time(NULL);
  struct tm *time_rec = localtime(&time_val);

  *hour=time_rec->tm_hour;
  *min=time_rec->tm_min;
  *sec=time_rec->tm_sec;
  *hsec=time_val % 100;
}

void GetDate(int *year, int *month, int *day, int *dow)
{
  time_t time_val = time(NULL);
  struct tm *time_rec = localtime(&time_val);

  *year=time_rec->tm_year;
  *month=time_rec->tm_mon;
  *day=time_rec->tm_mday;
  *dow=time_rec->tm_wday;
}


void StartTimer()
{
  time(&BaseTimeStamp);
}


long ReadTimer()
{
  time_t TimeStamp;
  time(&TimeStamp);

  return (TimeStamp-BaseTimeStamp);
}

void FindNext(SearchRec *SR)
{
  if (dir==NULL)
     {
      DosError=-3;
      return;
     } 
        
  entry=readdir(dir);
  if (entry==NULL)
     {
      DosError=-2;
      return;
     } 

  strcpy(SR->Name,entry->d_name);      
}


void _xdos_init()
{
  static int _was_initialized = 0;
  if (_was_initialized++)
    return;
}
// p2c: Note: Remember to call _xdos_init() in main program [215]



// End.
