#include <string.h>
static char space[15] [256];
static int point= -1;
 char *imp_concat(char *lhs,char *rhs)
{
    point=(point+1)&15;
    strcpy(space[point],lhs);
    strcat(space[point],rhs);
    return space[point];
}
int imp_resolve( char *origlhs, char * dest1, char * exp, char * dest2)
{
      int l1;
      char * s1, *lp;
      char lhs[256];
      strcpy(lhs,origlhs);
      s1=strstr(lhs,exp);
      if (s1==NULL) return 1;
      s1[0]=0;
      l1=strlen(lhs)+strlen(exp);
      if (dest1!=NULL) strcpy(dest1,lhs);
      lp=(char *)lhs+l1;
      if (dest2!=NULL) strcpy(dest2,lp);
      return 0;
}
 char * imp_tostring(int sym)
      {
      static char aa[2];
      aa[0]=sym;
      aa[1]=0;
      return aa;
}
void imp_stop()
{
      printf("\n\n IMP %%stop Called\n\n");
      exit(0);
}
char * imp_substring(char * source,int from,int to)
{
      static char lhs[256];
      int i,j;
      i=0;
      for (j=from; j<=to; j++) lhs[i++]=source[j];
      lhs[i]=0;
      return lhs;
}
 void imp_strjam(char * lhs,char * rhs,int max)
{
      lhs[0]=0;
      strncat(lhs,rhs,max);
}
void s__cstring(char * impstring, char * cstring)
{
      /* dummy version for when strings are already cstring */
     strcpy(cstring,impstring);
}
 char * itos(int val){
      static char sp[20];
      sprintf(sp,"%d",val);
      return sp;
}
void phex (int val)
{
      printf("%8x",val);
}
char * htos(int val,int places)
{
     char sp[9];
     switch (places) {
case 1:
      sprintf(sp,"%1x",val);
      break;
case 2:
      sprintf(sp,"%2x",val);
      break;
case 3:
      sprintf(sp,"%3x",val);
      break;
case 4:
      sprintf(sp,"%4x",val);
      break;
case 5:
      sprintf(sp,"%5x",val);
      break;
case 6:
      sprintf(sp,"%6x",val);
      break;
case 7:
      sprintf(sp,"%7x",val);
      break;
default:
      sprintf(sp,"%8x",val);
      break;
      }
      return sp;
}
