extern short putc();
extern short printf2();
extern short print_short();

short
print_short(number)
short number;
{
   short ret;
   short n;
   short byte_array[10];
   short buffer[10];
   short index;

   ret = 0;

   byte_array[0] = '0';
   byte_array[1] = '1';
   byte_array[2] = '2';
   byte_array[3] = '3';
   byte_array[4] = '4';
   byte_array[5] = '5';
   byte_array[6] = '6';
   byte_array[7] = '7';
   byte_array[8] = '8';
   byte_array[9] = '9';

   index = 0;
   while(number) {
      n = number % 10;
      number = number / 10;
      buffer[index] = byte_array[n];
      index++;
   }

   index--;
   while(index >= 0) {
      putc(buffer[index]);
      index--;
   }

   return ret;
}


short
printf2(fmt)
char * fmt;
{
   char * ptr;
   short * ptr0;
   short i;
   short ret;

   ret = 0;
   
   ptr = fmt;
   i = 2;

   while(*ptr) {
      if(*ptr == '%') {
         ptr++;
         if(*ptr == '%') {
            putc('%');
            ptr++;
         }
         else if(*ptr == 'x') {
            ptr0 = (&fmt) + i;
            tohex(*ptr0);
            i += 2;
            ptr++;
         }
         else if(*ptr == 'd') {
            ptr0 = &fmt + i;
            print_short(*ptr0);
            i += 2;
            ptr++;
         }
         else if(*ptr == 's') {
            ptr0 = (char*)(&fmt) + i;
            while(*ptr0) {
               putc(*ptr0);
               ptr0++;
            }
            i += 2;
            ptr++;
         }
         else {
            ptr++;
         }
      }
      else {
         putc(*ptr);
         ptr++;
      }
   }
   
   return 0;
}

short
main()
{
   printf2("Hello, World!\r\n");
   printf2("NUM=%d\r\n", 1234);
   return 0;
}