/*
 * Generated by P2C
 * Version 1.00 - Copyright (C) 2002, Benjamin Rosseaux
 */

#include "p2clib.h"

char _CURNAME[64];
int ioresult=0;

int round(float n) {
 return ((int)(n));
}

int trunc(float n) {
 return ((int)(n));
}

int pint(float n) {
 return ((int)(n));
}

void reset(text *fd) {
 *fd=fopen(_CURNAME,"r");
 ioresult=(*fd == NULL);
}

void rewrite(text *fd) {
 *fd=fopen(_CURNAME,"w");
 ioresult=(*fd==NULL);
}

void append(text *fd) {
 *fd=fopen(_CURNAME,"a");
 ioresult=(*fd == NULL);
}

charptr copy(charptr str,unsigned from,unsigned len) {
 static char buf[STRSIZ];
 buf[0]=0;
 if (from>strlen(str)) return buf;
 strcpy(buf,str+from-1);
 buf[len]=0;
 return buf;
}

charptr scat(charptr control, ...) {
 static char buf[STRSIZ];
 char buf2[STRSIZ];
 va_list args;
 va_start(args, control);
 vsprintf(buf2,control,args);
 va_end(args);
 strcpy(buf,buf2);
 return buf;
}
void sbld(charptr dest,charptr control, ...) {
 char buf[STRSIZ];
 va_list args;
 va_start(args, control);
 vsprintf(buf,control,args);
 va_end(args);
 strcpy(dest,buf);
}

int spos(charptr str1,charptr str2) {
 charptr res;
 res=strstr(str2,str1);
 if (res == NULL) return 0; else return res - str2 + 1;
}

int cpos(char c,charptr str2) {
 charptr res;
 res = strchr(str2,c);
if (res == NULL)  return 0; else return res - str2 + 1;
}

int fscanv(text fd, charptr control, ...) {
 va_list args;
 charptr arg1;
 int i;
 va_start(args, control);
 if (*control == '#') {
  arg1 = va_arg(args,charptr);
  fgets(arg1,STRSIZ,fd);
  arg1[strlen(arg1)-1] = 0;
  return 1;
 }
 i=vfscanf(fd,control,args);
 va_end(args);
 return i;
}


