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


//$N+,E+


#include <p2c/p2c.h>


#define STRTYPE_G
#include <p2c/strtype.h>


Char *GetWord(Char *Result, Char *s, int MAX_s)
{
  uchar i = strpos2(s, "\t", 1);

  sprintf(Result, "%.*s", i - 1, s);
  strdelete(/*(void *)& */ s, 1, i);
  return Result;
}


Char *WToString(Char *Result, unsigned short Num)
{
  Char HStr[256];

  sprintf(HStr, "%u", Num);
  return strcpy(Result, HStr);
}


Char *IToString(Char *Result, int Num)
{
  Char HStr[256];

  sprintf(HStr, "%d", Num);
  return strcpy(Result, HStr);
}


Char *BToString(Char *Result, uchar Num)
{
  Char HStr[256];

  sprintf(HStr, "%d", Num);
  return strcpy(Result, HStr);
}


Char *BToUFHex(Char *Result, uchar Num)
{
  static Char charset[17] = "0123456789abcdef";

  sprintf(Result, "%c%c", charset[(Num & 240) >> 4], charset[Num & 15]);
  return Result;
}


Char *BToHex(Char *Result, uchar Num)
{
  Char STR1[256];

  sprintf(Result, " $%s", BToUFHex(STR1, Num));
  return Result;
}


Char *WToHex(Char *Result, unsigned short Num)
{
  static Char charset[17] = "0123456789abcdef";

  sprintf(Result, "%c%c%c%ch",
	  charset[((Num >> 8) & 240) >> 4], charset[(Num >> 8) & 15],
	  charset[(Num & 255 & 240) >> 4], charset[Num & 255 & 15]);
  return Result;
}


Char *BToFString(Char *Result, uchar Num, uchar c)
{
  Char HStr[256];
  Char STR1[256];

  sprintf(HStr, "%d", Num);
  while (strlen(HStr) < c)
    sprintf(HStr, " %s", strcpy(STR1, HStr));
  return strcpy(Result, HStr);
}


Char *BToNString(Char *Result, uchar Num, uchar c)
{
  Char HStr[256];
  Char STR1[256];

  sprintf(HStr, "%d", Num);
  while (strlen(HStr) < c)
    sprintf(HStr, "0%s", strcpy(STR1, HStr));
  return strcpy(Result, HStr);
}


Char *WToFString(Char *Result, unsigned short Num)
{
  Char HStr[256];
  Char STR1[256];

  sprintf(HStr, "%u", Num);
  while (strlen(HStr) < 5)
    sprintf(HStr, " %s", strcpy(STR1, HStr));
  return strcpy(Result, HStr);
}


Char *SToFString(Char *Result, short Num)
{
  Char HStr[256];
  Char STR1[256];

  sprintf(HStr, "%d", Num);
  while (strlen(HStr) < 4)
    sprintf(HStr, " %s", strcpy(STR1, HStr));
  return strcpy(Result, HStr);
}


Char *LToString(Char *Result, long Num)
{
  Char HStr[256];

  sprintf(HStr, "%ld", Num);
  return strcpy(Result, HStr);
}


Char *LToFString(Char *Result, long Num, uchar len)
{
  Char HStr[256];
  Char STR1[256];

  sprintf(HStr, "%ld", Num);
  while (strlen(HStr) < len)
    sprintf(HStr, " %s", strcpy(STR1, HStr));
  return strcpy(Result, HStr);
}


Char *RToString(Char *Result, float Num)
{
  Char HStr[256];

  sprintf(HStr, "%10.3f", Num);
  return strcpy(Result, HStr);
}


Char *RToFString(Char *Result, float Num, uchar n, uchar m)
{
  Char HStr[256];

  sprintf(HStr, "%*.*f", n, m, Num);
  return strcpy(Result, HStr);
}


Char *BoolToString(Char *Result, boolean Num)
{
  if (Num)
    return strcpy(Result, "  true ");
  else
    return strcpy(Result, " false ");
}


Char *BToBin(Char *Result, unsigned short by)
{
  Char he1[2];
  Char he8[256];

  *he8 = '\0';
  for (uchar count = 0; count <= 7; count++) {
    uchar go = (((by << count) & 255) << 1) >> 8;
    if (go == 1)
      strcpy(he1, "1");
    else
      strcpy(he1, "\371");
    strinsert(he1, /* (void *)& */ he8, strlen(he8) + 1);
  }
  return strcpy(Result, he8);
}




Static Char *EToFString(Char *Result, double Num, uchar n, uchar m)
{
  Char HStr[256];

  sprintf(HStr, "%*.*f", n, m, Num);
  return strcpy(Result, HStr);
}



Char *FormatHex(Char *Result, Char *hs)
{
  boolean h = false;
  Char s[256];
  Char STR1[256];

  strcpy(s, hs);

  if (strpos2(s, "0x0", 1) == 1) {
    strdelete(/* (void *)& */ s, 1, 3);
    h = true;
  }

  if (strpos2(s, "h", 1) == strlen(s)) {
    strdelete(/* (void *)& */ s, strlen(s), 1);
    h = true;
  }

  if (strpos2(s, "$", 1) == 0 && h)
    sprintf(s, "$0%s", strcpy(STR1, s));

  if (*hs != '\0')
    return strcpy(Result, s);
  else
    return strcpy(Result, "");
}


int ToInteger(Char *s)
{
  int i;
  int c = sscanf(s, "%d", &i) == 0;

  if (c == 0)
    return i;
  else
    return 0;
}


uchar ToByte(Char *s)
{
  uchar i;
  int c = sscanf(s, "%d", &i) == 0;

  if (c == 0)
    return i;
  else
    return 0;
}


unsigned short ToWord(Char *s)
{
  unsigned short i;
  int c = sscanf(s, "%d", &i) == 0;

  if (c == 0)
    return i;
  else
    return 0;
}


float ToReal(Char *s_)
{
  Char s[256];
  float i;

  strcpy(s, s_);
  int c = sscanf(s, "%lg", &i) == 0;

  while (c != 0) {
    strdelete(/* (void *)& */ s, c, 1);
    c = (sscanf(s, "%lg", &i) == 0);
  }

  if (c == 0)
    return i;
  else
    return 0.0;
}


double ToExtended(Char *s)
{
  double i;
  int c = sscanf(s, "%lg", &i) == 0;

  if (c == 0)
    return i;
  else
    return 0.0;
}





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



// End.
