usr/src/grub/grub-0.95/stage2/char_io.c
changeset 6423 437422a29d3a
parent 3912 f6891a60bd72
child 6448 dfd58b2129f6
equal deleted inserted replaced
6422:d51a10d738ba 6423:437422a29d3a
   209 	  }
   209 	  }
   210     }
   210     }
   211 }
   211 }
   212 
   212 
   213 #ifndef STAGE1_5
   213 #ifndef STAGE1_5
   214 static int
       
   215 grub_vsprintf (char *buffer, const char *format, int *dataptr)
       
   216 {
       
   217   /* XXX hohmuth
       
   218      ugly hack -- should unify with printf() */
       
   219   char c, *ptr, str[16];
       
   220   char *bp = buffer;
       
   221   int len = 0;
       
   222 
       
   223   while ((c = *format++) != 0)
       
   224     {
       
   225       if (c != '%') {
       
   226 	if (buffer)
       
   227 	  *bp++ = c; /* putchar(c); */
       
   228         len++;
       
   229       } else {
       
   230 	switch (c = *(format++))
       
   231 	  {
       
   232 	  case 'd': case 'u': case 'x':
       
   233 	    *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
       
   234 
       
   235 	    ptr = str;
       
   236 
       
   237 	    while (*ptr) {
       
   238 	      if (buffer)
       
   239 	        *bp++ = *(ptr++); /* putchar(*(ptr++)); */
       
   240               else
       
   241 	        ptr++;
       
   242               len++;
       
   243             }
       
   244 	    break;
       
   245 
       
   246 	  case 'c':
       
   247             if (buffer)
       
   248               *bp++ = (*(dataptr++))&0xff;
       
   249             else
       
   250               dataptr++;
       
   251             len++;
       
   252 	    /* putchar((*(dataptr++))&0xff); */
       
   253 	    break;
       
   254 
       
   255 	  case 's':
       
   256 	    ptr = (char *) (*(dataptr++));
       
   257 
       
   258 	    while ((c = *ptr++) != 0) {
       
   259               if (buffer)
       
   260 	        *bp++ = c; /* putchar(c); */
       
   261               len++;
       
   262             }
       
   263 	    break;
       
   264 	  }
       
   265        }
       
   266     }
       
   267 
       
   268   *bp = 0;
       
   269   return (len);
       
   270 }
       
   271 
       
   272 int
       
   273 grub_sprintf (char *buffer, const char *format, ...)
       
   274 {
       
   275   int *dataptr = (int *) &format;
       
   276   dataptr++;
       
   277 
       
   278   return (grub_vsprintf (buffer, format, dataptr));
       
   279 }
       
   280 
       
   281 void
   214 void
   282 init_page (void)
   215 init_page (void)
   283 {
   216 {
   284   cls ();
   217   cls ();
   285 
   218 
   941 
   874 
   942   return 1;
   875   return 1;
   943 }
   876 }
   944 #endif /* STAGE1_5 */
   877 #endif /* STAGE1_5 */
   945 
   878 
       
   879 #if !defined(STAGE1_5) || defined(FSYS_ZFS)
       
   880 static int
       
   881 grub_vsprintf (char *buffer, const char *format, int *dataptr)
       
   882 {
       
   883   /* XXX hohmuth
       
   884      ugly hack -- should unify with printf() */
       
   885   char c, *ptr, str[16];
       
   886   char *bp = buffer;
       
   887   int len = 0;
       
   888 
       
   889   while ((c = *format++) != 0)
       
   890     {
       
   891       if (c != '%') {
       
   892 	if (buffer)
       
   893 	  *bp++ = c; /* putchar(c); */
       
   894         len++;
       
   895       } else {
       
   896 	switch (c = *(format++))
       
   897 	  {
       
   898 	  case 'd': case 'u': case 'x':
       
   899 	    *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
       
   900 
       
   901 	    ptr = str;
       
   902 
       
   903 	    while (*ptr) {
       
   904 	      if (buffer)
       
   905 	        *bp++ = *(ptr++); /* putchar(*(ptr++)); */
       
   906               else
       
   907 	        ptr++;
       
   908               len++;
       
   909             }
       
   910 	    break;
       
   911 
       
   912 	  case 'c':
       
   913             if (buffer)
       
   914               *bp++ = (*(dataptr++))&0xff;
       
   915             else
       
   916               dataptr++;
       
   917             len++;
       
   918 	    /* putchar((*(dataptr++))&0xff); */
       
   919 	    break;
       
   920 
       
   921 	  case 's':
       
   922 	    ptr = (char *) (*(dataptr++));
       
   923 
       
   924 	    while ((c = *ptr++) != 0) {
       
   925               if (buffer)
       
   926 	        *bp++ = c; /* putchar(c); */
       
   927               len++;
       
   928             }
       
   929 	    break;
       
   930 	  }
       
   931        }
       
   932     }
       
   933 
       
   934   *bp = 0;
       
   935   return (len);
       
   936 }
       
   937 
       
   938 int
       
   939 grub_sprintf (char *buffer, const char *format, ...)
       
   940 {
       
   941   int *dataptr = (int *) &format;
       
   942   dataptr++;
       
   943 
       
   944   return (grub_vsprintf (buffer, format, dataptr));
       
   945 }
       
   946 
       
   947 #endif /* !defined(STAGE1_5) || defined(FSYS_ZFS) */
       
   948 
   946 void
   949 void
   947 noisy_printf (const char *format,...)
   950 noisy_printf (const char *format,...)
   948 {
   951 {
   949 	int *dataptr = (int *) &format;
   952 	int *dataptr = (int *) &format;
   950 	dataptr++;
   953 	dataptr++;
  1246       s1++;
  1249       s1++;
  1247     }
  1250     }
  1248 
  1251 
  1249   return 0;
  1252   return 0;
  1250 }
  1253 }
       
  1254 
       
  1255 int
       
  1256 grub_strlen (const char *str)
       
  1257 {
       
  1258   int len = 0;
       
  1259 
       
  1260   while (*str++)
       
  1261     len++;
       
  1262 
       
  1263   return len;
       
  1264 }
  1251 #endif /* !defined(STAGE1_5) || defined(FSYS_ZFS) */
  1265 #endif /* !defined(STAGE1_5) || defined(FSYS_ZFS) */
  1252 
  1266 
  1253 #ifndef STAGE1_5
  1267 #ifndef STAGE1_5
  1254 /* Terminate the string STR with NUL.  */
  1268 /* Terminate the string STR with NUL.  */
  1255 int
  1269 int
  1261     str++;
  1275     str++;
  1262 
  1276 
  1263   ch = *str;
  1277   ch = *str;
  1264   *str = 0;
  1278   *str = 0;
  1265   return ch;
  1279   return ch;
  1266 }
       
  1267 
       
  1268 int
       
  1269 grub_strlen (const char *str)
       
  1270 {
       
  1271   int len = 0;
       
  1272 
       
  1273   while (*str++)
       
  1274     len++;
       
  1275 
       
  1276   return len;
       
  1277 }
  1280 }
  1278 #endif /* ! STAGE1_5 */
  1281 #endif /* ! STAGE1_5 */
  1279 
  1282 
  1280 int
  1283 int
  1281 memcheck (unsigned long addr, unsigned long len)
  1284 memcheck (unsigned long addr, unsigned long len)