Exemple #1
0
static void printuint(unsigned int num)
{
	if (num >= 10)
	{
		printuint(num / 10);
	}
	putchar('0' + (num % 10));
}
Exemple #2
0
static void printint(int num)
{
	if (num < 0)
	{
		putchar('-');
		num *= -1;
	}
	printuint(num);
}	
Exemple #3
0
void
runtime·printint(int64 v)
{
	if(v < 0) {
		runtime·write(2, "-", 1);
		v = -v;
	}
	runtime·printuint(v);
}
Exemple #4
0
void
·printint(int64 v)
{
	if(v < 0) {
		write(fd, "-", 1);
		v = -v;
	}
	·printuint(v);
}
int simple_printf(char * fmt, ...)
{
  char * marker;
  int intArg;
  unsigned int uintArg;
  char * strArg;

  va_list args;

  va_start(args,fmt);

  marker = fmt;

  while (*fmt) {
    switch (*fmt)
      {
      case '%':
        if (fmt != marker) {
          char c = *fmt;
          *fmt = '\0';
          printstr(marker);
          *fmt = c;
        }
        fmt++;
	switch (*(fmt))
	  {
	  case 'd':
	    intArg = va_arg(args, int);
            printint(intArg);
            break;
	  case 'u':
	    uintArg = va_arg(args, int);
            printuint(uintArg);
            break;
	  case 'x':
	    uintArg = va_arg(args, int);
            printhex(uintArg);
	    break;
	  case 'c':
	    intArg = va_arg(args, int);
            printchar(intArg);
	    break;
	  case 's':
	    strArg = va_arg(args, char *);
            printstr(strArg);
	    break;
	  }
	fmt++;
	marker = fmt;
	break;
      default:
	fmt++;
      }
  }
  if (fmt != marker) {
    char c = *fmt;
    *fmt = '\0';
    printstr(marker);
    *fmt = c;
  }

  va_end(args);

  return 0;
}
Exemple #6
0
// Very simple printf.  Only for debugging prints.
// Do not add to this without checking with Rob.
static void
vprintf(int8 *s, byte *base)
{
	int8 *p, *lp;
	uintptr arg, narg;
	byte *v;

//	lock(&debuglock);

	lp = p = s;
	arg = 0;
	for(; *p; p++) {
		if(*p != '%')
			continue;
		if(p > lp)
			runtime·write(2, lp, p-lp);
		p++;
		narg = 0;
		switch(*p) {
		case 't':
			narg = arg + 1;
			break;
		case 'd':	// 32-bit
		case 'x':
			arg = runtime·rnd(arg, 4);
			narg = arg + 4;
			break;
		case 'D':	// 64-bit
		case 'U':
		case 'X':
		case 'f':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + 8;
			break;
		case 'C':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + 16;
			break;
		case 'p':	// pointer-sized
		case 's':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(uintptr);
			break;
		case 'S':	// pointer-aligned but bigger
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(String);
			break;
		case 'a':	// pointer-aligned but bigger
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Slice);
			break;
		case 'i':	// pointer-aligned but bigger
		case 'e':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Eface);
			break;
		}
		v = base+arg;
		switch(*p) {
		case 'a':
			runtime·printslice(*(Slice*)v);
			break;
		case 'd':
			runtime·printint(*(int32*)v);
			break;
		case 'D':
			runtime·printint(*(int64*)v);
			break;
		case 'e':
			runtime·printeface(*(Eface*)v);
			break;
		case 'f':
			runtime·printfloat(*(float64*)v);
			break;
		case 'C':
			runtime·printcomplex(*(Complex128*)v);
			break;
		case 'i':
			runtime·printiface(*(Iface*)v);
			break;
		case 'p':
			runtime·printpointer(*(void**)v);
			break;
		case 's':
			runtime·prints(*(int8**)v);
			break;
		case 'S':
			runtime·printstring(*(String*)v);
			break;
		case 't':
			runtime·printbool(*(bool*)v);
			break;
		case 'U':
			runtime·printuint(*(uint64*)v);
			break;
		case 'x':
			runtime·printhex(*(uint32*)v);
			break;
		case 'X':
			runtime·printhex(*(uint64*)v);
			break;
		}
		arg = narg;
		lp = p+1;
	}
	if(p > lp)
		runtime·write(2, lp, p-lp);

//	unlock(&debuglock);
}
Exemple #7
0
// Very simple printf.  Only for debugging prints.
// Do not add to this without checking with Rob.
static void
vprintf(int8 *s, byte *arg)
{
	int8 *p, *lp;
	byte *narg;

//	lock(&debuglock);

	lp = p = s;
	for(; *p; p++) {
		if(*p != '%')
			continue;
		if(p > lp)
			write(fd, lp, p-lp);
		p++;
		narg = nil;
		switch(*p) {
		case 't':
			narg = arg + 1;
			break;
		case 'd':	// 32-bit
		case 'x':
			arg = vrnd(arg, 4);
			narg = arg + 4;
			break;
		case 'D':	// 64-bit
		case 'U':
		case 'X':
		case 'f':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + 8;
			break;
		case 'p':	// pointer-sized
		case 's':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(uintptr);
			break;
		case 'S':	// pointer-aligned but bigger
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(String);
			break;
		case 'a':	// pointer-aligned but bigger
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Slice);
			break;
		case 'i':	// pointer-aligned but bigger
		case 'e':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Eface);
			break;
		}
		switch(*p) {
		case 'a':
			·printslice(*(Slice*)arg);
			break;
		case 'd':
			·printint(*(int32*)arg);
			break;
		case 'D':
			·printint(*(int64*)arg);
			break;
		case 'e':
			·printeface(*(Eface*)arg);
			break;
		case 'f':
			·printfloat(*(float64*)arg);
			break;
		case 'i':
			·printiface(*(Iface*)arg);
			break;
		case 'p':
			·printpointer(*(void**)arg);
			break;
		case 's':
			prints(*(int8**)arg);
			break;
		case 'S':
			·printstring(*(String*)arg);
			break;
		case 't':
			·printbool(*(bool*)arg);
			break;
		case 'U':
			·printuint(*(uint64*)arg);
			break;
		case 'x':
			·printhex(*(uint32*)arg);
			break;
		case 'X':
			·printhex(*(uint64*)arg);
			break;
		case '!':
			·panicl(-1);
		}
		arg = narg;
		lp = p+1;
	}
	if(p > lp)
		write(fd, lp, p-lp);

//	unlock(&debuglock);
}