wok rev 10876

syslinux: clarify ifmem.c32
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jun 21 00:45:23 2011 +0200 (2011-06-21)
parents 7aa32fb0fb80
children 84f8cd79ad7a
files syslinux/stuff/extra/ifmem.c
line diff
     1.1 --- a/syslinux/stuff/extra/ifmem.c	Mon Jun 20 13:24:19 2011 +0000
     1.2 +++ b/syslinux/stuff/extra/ifmem.c	Tue Jun 21 00:45:23 2011 +0200
     1.3 @@ -87,19 +87,18 @@
     1.4       __intcall(0x15, &ireg, &oreg);
     1.5       return ireg.eax.w[0];
     1.6    }
     1.7 -  return bytes / 1024;
     1.8 +  return bytes >> 10;
     1.9  }
    1.10  
    1.11  int main(int argc, char *argv[])
    1.12  {
    1.13    char *s;
    1.14 -  int i, j = 1;
    1.15 +  int i;
    1.16    unsigned long ram_size;
    1.17  
    1.18 -  for (s = argv[1]; *s && (*s < '0' || *s > '9'); s++);
    1.19 -
    1.20    openconsole(&dev_null_r, &dev_stdcon_w);
    1.21 -  if (argc < 4 || !*s) {
    1.22 +  
    1.23 +  if (argc < 4) {
    1.24      perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
    1.25      return 1;
    1.26    }
    1.27 @@ -107,43 +106,25 @@
    1.28    // find target according to ram size
    1.29    ram_size = memory_size();
    1.30    printf("Total memory found %luK.\n",ram_size);
    1.31 -  for (i = 1; i + 2 < argc; ) { 
    1.32 +  
    1.33 +  i = 1;
    1.34 +  s = argv[1];
    1.35 +  do { 
    1.36      char *p = s;
    1.37      unsigned long scale = 1;
    1.38      
    1.39 -    if (*p) while (p[1]) p++;
    1.40 +    while (*p >= '0' && *p <= '9') p++;
    1.41      switch (*p | 0x20) {
    1.42 -    case 'g': scale = 1024*1024; *p = 0; break;
    1.43 -    case 'm': scale = 1024;
    1.44 -    case 'k': *p = 0; break;
    1.45 +    case 'g': scale <<= 10;
    1.46 +    case 'm': scale <<= 10;
    1.47 +    default : *p = 0; break;
    1.48      }
    1.49 -    j = i++; // size
    1.50 +    i++; // size
    1.51      if (ram_size >= scale * strtoul(s, NULL, 0)) break;
    1.52      s = argv[++i];
    1.53 -  }
    1.54 +  } while (i + 1 < argc);
    1.55  
    1.56 -  // find and copy extra parameters to command line
    1.57 -  // assume the command line ends with two words (not number)
    1.58 -  for (s = argv[i++]; i < argc; i++) { 
    1.59 -	char c = *argv[i];
    1.60 -	if (c >= '0' && c <= '9') j = i;
    1.61 -	if (i - j > 2 && i < argc) {
    1.62 -#define SZ 4096
    1.63 -		static char cmdline[SZ];
    1.64 -		char *p = cmdline, *q = s;
    1.65 -		int j;
    1.66 -		for (j = i; j <= argc; j++) {
    1.67 -			while (*q && p < cmdline + SZ -1) *p++ = *q++;
    1.68 -			if (p < cmdline + SZ -1) *p++ = ' ';
    1.69 -			q = argv[j];
    1.70 -		}
    1.71 -		*p++ = 0;
    1.72 -		s = cmdline;
    1.73 -		break;
    1.74 -	}
    1.75 -  }
    1.76 -
    1.77 -  if (s) syslinux_run_command(s);
    1.78 +  if (i != argc) syslinux_run_command(argv[i]);
    1.79    else   syslinux_run_default();
    1.80    return -1;
    1.81  }