⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 Embeded bootloader (rrload by ridgerun) for TI linux based platform v5.36
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (*fmt == '%') {  // switch() uses more space      fmt++;      if (*fmt == 'X') {        const long *lp = (const long *)dp;        register long h = *lp++;        dp = (const int *)lp;        *(buf++) = hex[(h>>28)& 0x0F];        *(buf++) = hex[(h>>24)& 0x0F];        *(buf++) = hex[(h>>20)& 0x0F];        *(buf++) = hex[(h>>16)& 0x0F];        *(buf++) = hex[(h>>12)& 0x0F];        *(buf++) = hex[(h>>8)& 0x0F];        *(buf++) = hex[(h>>4)& 0x0F];        *(buf++) = hex[h& 0x0F];      }      if (*fmt == 'x') {              register int h = *(dp++);        *(buf++) = hex[(h>>12)& 0x0F];        *(buf++) = hex[(h>>8)& 0x0F];        *(buf++) = hex[(h>>4)& 0x0F];        *(buf++) = hex[h& 0x0F];      }      if (*fmt == 'b') {        register int h = *(dp++);        *(buf++) = hex[(h>>4)& 0x0F];        *(buf++) = hex[h& 0x0F];      }      if ((*fmt == 'd') || (*fmt == 'i')) {        register int dec = *(dp++);        p = tmp;        if (dec < 0) {          *(buf++) = '-';          dec = -dec;        }        do {          *(p++) = '0' + (dec%10);          dec = dec/10;        } while(dec);        while ((--p) >= tmp) *(buf++) = *p;      }      if (*fmt == 'I') {        union {          long l;          unsigned char c[4];        } u;        const long *lp = (const long *)dp;        u.l = *lp++;        dp = (const int *)lp;        buf = do_sprintf(buf,"%d.%d.%d.%d",                         u.c[0], u.c[1], u.c[2], u.c[3]);      }      if (*fmt == 'c') {        *(buf++) = *(dp++);      }      if (*fmt == 's') {        p = (char *)*dp++;        while (*p) *(buf++) = *p++;      }    } else {      *(buf++) = *fmt;    }    fmt++;  }  *buf = 0;  return(buf);}/****************************** Routine: Description: ******************************/static char *do_sprintf(char *buf, const char *fmt, ...){  return do_printf(buf, fmt, ((const int *)&fmt)+1);}/****************************** Routine: Description: ******************************/int util_putchar(int c){  io_putchar((unsigned char) c);  return c;}/****************************** Routine: Description:   Note: See util.h for description. ******************************/void util_printf(const char *fmt, ...){  char buf[256],*p;  p = buf;  do_printf(buf, fmt, ((const int *)&fmt)+1);  while (*p) io_putchar(*p++);}/****************************** Routine: Description: ******************************/char *util_strchr(const char *s, int c){  while (*s)  {    if ( *s == (char) c )    {      return (char *)s;    }    s++;  }  return (void *) 0;}/****************************** Routine: Description: ******************************/int util_strlen(const char *s){   int len = 0;   while (*s++ != 0) len++;   return len;}/****************************** Routine: Description: ******************************/int util_strncmp(const char *s1, const char *s2, int len){  int i = 0;  int c1, c2;  if (s1 == NULL || s2 == NULL) return -1;  for (c1=s1[i], c2=s2[i]; i<len; c1=s1[i], c2=s2[i], i++) {    if (c1 < c2) return -1;    else if (c1 > c2) return 1;    else continue;  }  return 0;}/****************************** Routine: Description:   Note: See util.h for description. ******************************/int util_strcmp(const char *s1, const char *s2){  int len1 = util_strlen(s1);  int len2 = util_strlen(s2);  int l = (len1 < len2) ? len1 : len2;  int result = util_strncmp(s1, s2, l);  if (l == 0 && (len1 != len2)) {    if (len1 < len2) {      return -1;    }    else {      return 1;    }  } else {     return result;  }}/****************************** Routine: Description:   Note: See util.h for description. ******************************/char *util_strcpy(char *dest, const char *src){  char *retval = dest;  int count = util_strlen(src)+1;  while (count-- && (*dest++ = *src++) != 0);  return retval;}/****************************** Routine: Description:   Note: See util.h for description. ******************************/char *util_strncpy(char *dest, const char *src, int count){  char *retval = dest;  while (count-- && (*dest++ = *src++) != 0);  return retval;}/****************************** Routine: Description:   Note: See util.h for description. ******************************/int util_getchar(void){        return io_getchar_con();}/****************************** Routine: Description:   Note: See util.h for description. ******************************/void util_gets(char *s, int size){  #define BACKSPACE 0x08  #define DEL       0x7f  int i;  for (i=0; i<size; i++) {    s[i] = io_getchar_con();    if ('\r' == s[i]) {      io_putchar('\n');      s[i] = 0;      break;    }    if (i &&        ((BACKSPACE == s[i]) || (DEL == s[i]))) {      s[i] = 0;      i -= 2;      util_printf("\033[D"); // terminal backspace.      io_putchar(' '); // erase unwanted character from screen.      util_printf("\033[D"); // terminal backspace.    }    else {      io_putchar(s[i]); // echo char back to terminal window.    }  }}/****************************** Routine: Description:   Note: See util.h for description. ******************************/void util_strip_CRLF(char *s){  // examples:  //   if "foo\n"    then "foo"  //   if "foo\r"    then "foo"  //   if "foo\r\n"  then "foo"  while (*s != 0) {    if (('\r' == *s) || ('\n' == *s)) {      *s=0;      break;    }    s++;  }}/****************************** Routine: util_dump_memory Description: prints out the contents of memory On entry: - addr contains the starting address           - len is the number of bytes to print   Note: See util.h for description. ******************************/#ifdef BSPCONF_BTLDR_CS8900_DEBUGvoid util_dump_memory(unsigned int addr, int len){  util_printf("Memory dump\n");  util_printf("-----------\n");  while(len > 0) {    int rlen = (len < 16) ? len : 16;    len -= rlen;    util_printf("%X: ", addr);    while(rlen > 0) {      util_printf("%x ", *((unsigned short *)addr));      addr+=2;      rlen-=2;    }    util_printf("\n");  }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -