Exemplo n.º 1
0
/* Win32 file name restrictions suck... */
void fname_wtoa (unsigned char *ptr)
{
    unsigned char *lastslash = ptr;

    while (*ptr) {
	if (*ptr == '~') {
	    *ptr = hextol (ptr[1]) * 16 + hextol (ptr[2]);
	    strcpy (ptr + 1, ptr + 3);
	} else if (*ptr == '\\') {
	    if (checkspace (lastslash, ' ', 0xa0) && ptr - lastslash > 3 && lastslash[3] == 0xa0 && isillegal (lastslash)) {
		ptr--;
		strcpy (lastslash + 3, lastslash + 4);
	    }
	    *ptr = '/';
	    lastslash = ptr + 1;
	}
	ptr++;
    }

    if (checkspace (lastslash, ' ', 0xa0) && ptr - lastslash > 3 && lastslash[3] == 0xa0 && isillegal (lastslash))
	strcpy (lastslash + 3, lastslash + 4);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	uint32_t * map_base;
	FILE *f;
	int n, fd;
	uint32_t addr_base;
	uint16_t addr_offset;
	uint8_t dat;
        uint32_t dat0;
	if(argc!=3) {
		printf("regs_write 0x1fd011c0 0x0\r\n");
		return (-2);
	}
	addr_base=hextol(argv[1]);;
	addr_offset=addr_base&0xfff;
	addr_base=addr_base&0xfffff000;
	dat=hextol(argv[2]);

	fd = open("/dev/mem", O_RDWR|O_SYNC);
	if (fd == -1)  {
		return (-1);
	}
	/* 把xxxxx000开始0x1000字节,映射到map_base */
	map_base = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_base);

	if (map_base == 0)  {
		printf("NULL pointer!\n");
	}

        n=addr_offset%4;
        dat0=map_base[addr_offset/4];
        dat0&=~(0xff<<(n*8));
	map_base[addr_offset/4]=dat0|(uint32_t)(dat<<(n*8));

	close(fd);
	munmap(map_base, 0xff);
	return (0);
}
Exemplo n.º 3
0
/**
 * Returns the number of a string (constant numeric expression)
 *
 * type  <=0 = error
 *         1 = int32_t
 *         2 = double
 *
 * Warning: octals are different from C (QB compatibility: 009 = 9)
 */
char *get_numexpr(char *text, char *dest, int *type, var_int_t *lv, var_num_t *dv) {
  char *p = (char *) text;
  char *d = dest;
  char *epos = NULL;
  byte base = 10;
  byte dpc = 0, stupid_e_fmt = 0, eop = '+';
  int sign = 1;
  var_num_t power = 1.0;
  var_num_t num;

  *type = 0;
  *lv = 0;
  *dv = 0.0;

  if (p == NULL) {
    *dest = '\0';
    return NULL;
  }
  // spaces
  while (is_space(*p)) {
    p++;
  }
  // sign
  if ((*p == '-' || *p == '+') && strchr("0123456789.", *(p + 1)) &&
      *(p + 1) != '\0'){if (*p == '-') {
      sign = -1;
    }
    p++;                        // don't copy it
  }

  //
  // resolve the base (hex, octal and binary)
  //
  if ((*p == '&') || (*p == '0' && (*(p + 1) != '\0' && strchr("HXBO", to_upper(*(p + 1))) != NULL))) {

    p++;
    switch (*p) {
    case 'H':
    case 'h':
    case 'X':
    case 'x':
      base = 16;
      break;
    case 'O':
    case 'o':
      base = 8;
      break;
    case 'B':
    case 'b':
      base = 2;
      break;
    default:
      *type = -1;
      return p;                 // Unknown base
    }

    p++;
  }
  //
  // copy parts of number
  //
  if (base == 16) {
    // copy hex
    while (is_hexdigit(*p)) {
      *d = to_upper(*p);
      d++;
      p++;
    }
  } else if (base != 10) {
    // copy octal | bin
    while (is_digit(*p)) {
      *d++ = *p++;
    }
  } else if (is_digit(*p) || *p == '.') {
    // copy number (first part)
    while (is_digit(*p) || *p == '.') {
      if (*p == '.') {
        dpc++;
        if (dpc > 1) {
          *type = -2;           // DP ERROR
          break;
        }
      }

      *d++ = *p++;
    }

    // check second part
    if ((*p == 'E' || *p == 'e') && (*type == 0)) {
      epos = d;
      *d++ = *p++;              // E

      if (*p == '+' || *p == '-' || is_digit(*p) || *p == '.') {
        dpc = 0;

        // copy second part (power)
        if (*p == '+' || *p == '-') {
          *d++ = *p++;
          if (strchr("+-*/\\^", *p) != 0) { // stupid E format
            // (1E--9 ||
            // 1E++9)
            stupid_e_fmt = 1;
            eop = *p;
            *d++ = *p++;
            if (*p == '+' || *p == '-')
              *d++ = *p++;
          }
        }
        // power
        while (is_digit(*p) || *p == '.') {
          if (*p == '.') {
            dpc++;
            if (dpc > 1) {
              *type = -4;       // DP ERROR (second part)
              break;
            }
          }
          *d++ = *p++;
        }                       // after E

      }                         //
      else {
        *type = -3;             // E+- ERROR
      }
    }
  } else
    *type = -9;                 // NOT A NUMBER

  *d = '\0';

  //
  // finaly, calculate the number
  //
  if (*type == 0) {
    switch (base) {
    case 10:
      if (dpc || (epos != NULL) || (strlen(dest) > 8)) {
        *type = 2;              // double
        if (epos) {
          if (stupid_e_fmt) {
            int r_type = 1;

            *epos = '\0';
            num = sb_strtof(dest) * ((double) sign);
            *epos = 'E';        // restore E

            /*
             * if ( *p == 'E' || *p == 'e' ) { long r_lv; double r_dv;
             *
             * p = get_numexpr(epos_on_text+3, dest, &r_type, &r_lv, &r_dv);
             *
             * switch ( r_type ) { case 1: power = r_lv; break; case 2: power =
             * r_dv; break; default: // error *type = r_type; } } else
             */
            power = sb_strtof(epos + 3);

            if (r_type > 0) {
              switch (eop) {
              case '+':
                *dv = num + power;
                break;
              case '-':
                *dv = num - power;
                break;
              case '*':
                *dv = num * power;
                break;
              case '/':
                if (ABS(power) != 0.0)
                  *dv = num / power;
                else
                  *dv = 0;
                // else if(comp) sc_raise() else rt_raise
                break;
              case '\\':
                if ((long) power != 0) {
                  *type = 1;
                  *lv = num / (long) power;
                } else {
                  *type = 1;
                  *lv = 0;
                }
                // else if(comp) sc_raise() else rt_raise
                break;
              case '^':
                *dv = pow(num, power);
                break;
              }
            }
          } else {
            *epos = '\0';
            power = pow(10, sb_strtof(epos + 1));
            *dv = sb_strtof(dest) * ((double) sign) * power;
            *epos = 'E';
          }
        } else {
          *dv = sb_strtof(dest) * ((double) sign);
        }
      } else {
        // dpc = 0 && epos = 0
        *type = 1;              // int32_t
        *lv = xstrtol(dest) * sign;
      }
      break;
    case 16:
      *type = 1;                // int32_t
      *lv = hextol(dest);
      break;
    case 8:
      *type = 1;                // int32_t
      *lv = octtol(dest);
      break;
    case 2:
      *type = 1;                // int32_t
      *lv = bintol(dest);
      break;
    }
  }
  //
  if (is_alpha(*p)) {
    *type = -9;                 // ITS NOT A NUMBER
  }
  while (is_space(*p)) {
    p++;
  }
  return p;
}