Exemple #1
0
uint16_t chal_LookupReg(chal_t *cdev,char *name) {
	uint16_t rix;
	chal_Reg_t *cr;

	if (*name == '0' && *(name+1)=='x') {
			// Check if register number was specified
		rix = (uint16_t)mystrtoul(name,0,16);
		if (rix != 0) goto _exit;
	} 

	for (rix=0;rix<CHAL_MAXREG;++rix) {
		cr = cdev->reglist[rix];
		if (cr == NULL) continue;		// skip this register

		if (strcmp(name,(char *)cr->regname)==0) {
				// Match found
			break;
		}
	}

	if (rix == CHAL_MAXREG) {
		rix = CHAL_ERROR;
	}

  _exit:
    return rix;
}
Exemple #2
0
DWORD getNumber(int hex)
{
	char buffer[65];
	int amount;
	DWORD target;
	if(hex==0)
	{
		amount=InputNumericalString(buffer, 64);
		target=mystrtoul(buffer, 10);
	}
	else
	{
		amount=InputNumericalHex(buffer, 64);
		target=mystrtoul(buffer, 16);
	}

	return target;
}
Exemple #3
0
/**
 * vrrp_ctrl_cmd() - Interprete control fifo cmd
 */
static inline vrrp_event_t vrrp_ctrl_cmd(struct vrrp *vrrp,
        struct vrrp_net *vnet)
{
    int nword;

    nword =
        split_cmd(vrrp->ctrl.msg, vrrp->ctrl.cmd, CTRL_CMD_NTOKEN,
                  WHITESPACE);

    if (nword == 0)
        return INVALID;

    /*
     * control cmd stop
     */
    if (matches(vrrp->ctrl.cmd[0], "stop")) {
        log_notice("vrid %d :: control cmd stop, exiting", vrrp->vrid);
        set_bit(UVRRPD_RELOAD, &reg);
        clear_bit(KEEP_GOING, &reg);
        vrrp_ctrl_cmd_flush(&vrrp->ctrl);
        return CTRL_FIFO;
    }

    /*
     * control cmd reload
     */
    if (matches(vrrp->ctrl.cmd[0], "reload")) {
        set_bit(UVRRPD_RELOAD, &reg);
        vrrp_ctrl_cmd_flush(&vrrp->ctrl);
        return CTRL_FIFO;
    }

    /*
     * control cmd state || status
     */
    if (matches(vrrp->ctrl.cmd[0], "state")
            || matches(vrrp->ctrl.cmd[0], "status")) {

        set_bit(UVRRPD_DUMP, &reg);
        vrrp_ctrl_cmd_flush(&vrrp->ctrl);
        return CTRL_FIFO;
    }

    /*
     * control cmd prio
     */
    if (matches(vrrp->ctrl.cmd[0], "prio")) {
        if (nword != 2) {
            log_error
            ("vrid %d :: invalid syntax, control cmd prio <priority>",
             vrrp->vrid);

            vrrp_ctrl_cmd_flush(&vrrp->ctrl);
            return INVALID;
        }

        /* fetch priority */
        int err;
        unsigned long opt;
        err = mystrtoul(&opt, vrrp->ctrl.cmd[1], VRRP_PRIO_MAX);

        vrrp_ctrl_cmd_flush(&vrrp->ctrl);

        if (err == -ERANGE) {
            log_error
            ("vrid %d :: invalid control cmd prio, 0 < priority < 255",
             vrrp->vrid);
            return INVALID;
        }

        if (err == -EINVAL) {
            log_error
            ("vrid %d :: invalid control cmd prio, error parsing \"%s\" as a number",
             vrrp->vrid, vrrp->ctrl.cmd[1]);
            return INVALID;
        }

        /* change prio */
        if (vrrp->priority != (uint8_t) opt) {
            vrrp->priority = (uint8_t) opt;
            vrrp_adv_set_priority(vnet, vrrp->priority);
        }

        /* reload bit */
        set_bit(UVRRPD_RELOAD, &reg);

        return CTRL_FIFO;
    }

    vrrp_ctrl_cmd_flush(&vrrp->ctrl);

    return INVALID;
}
Exemple #4
0
void chal_Dump(chal_t *cdev,char *name) {
	uint16_t i,bit,rix,six,pix,rv,regval,*regaddr,isdir;
	uint16_t startrix=0,endrix=0,printbit=0;
	chal_Reg_t *cr;
	chal_Pin_t cpin;
	char *color;

	_printf(_T("%sCONFIGURATION MAPPING - BASEADDR=0x%08X%s\r\n"),
		GREEN,(unsigned)cdev->baseaddr,DEFAULT_COLOR);

		// no args, print only registers and their 16-bit values
	if (name == NULL) {
		startrix=0;
		endrix 	=CHAL_MAXREG;
		printbit=_PRINT_NONE;
		goto _doprint;
	}

		// 'all': print all registers and all signals
	if (strcmp(name,"all") == 0) {
		startrix=0;
		endrix 	=CHAL_MAXREG;
		printbit=_PRINT_ALL;
		goto _doprint;
	}

		// pix: print only register and one signal
		// pix is always specified in decimal, so check that
		// it is not hex first
	if ((*name >= '0' && *name <= '9') && !(*name=='0' && *(name+1)=='x')) {
		pix = (uint16_t)mystrtoul(name,0,10);
		if (pix != 0) {
			chal_LookupByPix(cdev,pix,&cpin);
			startrix = cpin.rix;
			endrix   = cpin.rix+1;
			printbit = cpin.six;
			goto _doprint;
		}
	}

		// signal name: print only register and one signal
	rv = chal_LookupByName(cdev,name,&cpin);
	if (rv != CHAL_ERROR) {
			// name is a signal
		startrix = cpin.rix;
		endrix   = cpin.rix+1;
		printbit = cpin.six;
		goto _doprint;
	}

		// register name: print register and all its signals
	rix = chal_LookupReg(cdev,name);
	if (rix != CHAL_ERROR) {
		startrix = rix;
		endrix   = rix+1;
		printbit = _PRINT_ALL;
		DEBUG_WHERE(CYAN);
		goto _doprint;
	}

		// If we get this far, then bad argument.
	_printf(_T("%sCannot find Signal or Register %s\r\n"),RED,name);
	goto _exit;

  _doprint:

	if ( endrix > CHAL_MAXREG ) {
		endrix = CHAL_MAXREG;
	}

	for (rix=startrix;rix<endrix;++rix) {
		cr = cdev->reglist[rix];
		if (cr == NULL) continue;		// skip this register

		regaddr=(uint16_t *)( (unsigned)cdev->baseaddr+cr->offset );
		regval=*regaddr;

			// isdir used to select printing "in/out" rather than HI/LO
		isdir = (cr->type == CHAL_dir)? 2 : 0;

		_printf(_T("%s%3s REG_%s%02X [0x%08X] "),
			DEFAULT_COLOR,
			chal_Type[cr->type],
			AMBER,rix,(unsigned)cdev->baseaddr+cr->offset);

		if (regval == 0x0000 || regval == 0xFFFF) {
			color=FOREST;
		} else {
			color=GREEN;
		}
		_printf(_T("%s0x%04X%s "), color,regval,DEFAULT_COLOR);

		for (i=0;i<CHAL_NRALIAS;++i) {
			if (cr->regname[i] != 0) {
				_printf(fmt16hs,CYAN,cr->regname[i]);
			}
		}
		_printf(_T("\r\n"));

		if (printbit == _PRINT_NONE) continue;

		for (six=0;six<16;++six) {
			bit = regval & 0x1;
			regval >>= 1;
			if (*cr->signame[six][0] == 0) continue;	// skip this bit
			if (!(printbit==_PRINT_ALL || printbit==six)) continue;
			
			pix = CHAL_PIX(rix,six);
			_printf(_T("\t%s PIX_%04d (Bit_%02d) "),
				chal_Val[isdir + bit],pix,six);
			for (i=0;i<CHAL_NSALIAS;++i) {
				if (*cr->signame[six][i] != '-') {
					_printf(fmths,YELLOW,cr->signame[six][i]);
				}
			}
			_printf(_T("\r\n"));
		}
		_printf(_T("\r\n"));
	}

  _exit:
	_printf(_T("%hs\r\n"),DEFAULT_COLOR);
    return;
}
Exemple #5
0
char *processEscChars(char *line)
{
  char *src = line;
  char *dst = line; /* possible as dst is shorter than src */

  /* used when converting \xdd and \ddd (hex or octal) characters */
  char ch;

  if (line == NULL)
    return line;

  /* cycle through copying characters, except when a \ is encountered. */
  while (*src != '\0') {
    ch = *src;
    src++;

    if (ch == '\\') {
      ch = *src; /* what follows slash? */
      src++;

      switch (ch) {
        case '\\': /* a single slash */
          *dst = '\\';
          dst++;
          break;
        case 'n': /* a newline (linefeed) */
          *dst = '\n';
          dst++;
          break;
        case 'r': /* a carriage return */
          *dst = '\r';
          dst++;
          break;
        case 't': /* a horizontal tab */
          *dst = '\t';
          dst++;
          break;
        case 'v': /* a vertical tab */
          *dst = '\v';
          dst++;
          break;
        case 'b': /* a backspace */
          *dst = '\b';
          dst++;
          break;
        case 'a': /* alert */
          *dst = '\a';
          dst++;
          break;
        case 'f': /* formfeed */
          *dst = '\f';
          dst++;
          break;
        case 'x': /* extension supporting hex numbers \xdd or \x0dd */
          {
            int chx = mystrtoul(src, 16, 2); /* get value */
            if (chx >= 0) { /* store character */
               *dst = chx;
               dst++;
               src += 2;
            } else /* error so just store x (loose slash) */
            {
              *dst = *src;
              dst++;
            }
          }
          break;
        default: /* just store letter (loose slash) or handle octal */
          {
            int chx = mystrtoul(src, 8, 3); /* get value */
            if (chx >= 0) {/* store character */
               *dst = chx;
               dst++;
               src += 3;
            } else
            {
               *dst = *src;
               dst++;
            }
          }
          break;
      } /* switch */
    } /* if backslash */
      else
    {
      *dst = ch;
      dst++;
    }
  } /* while */

  /* ensure '\0' terminated */
  *dst = '\0';

  return line;
}
Exemple #6
0
int catread (char *catfile)
{
  int   file;                           /* pointer to the catfile */
  unsigned int   i;
  char  *where;
  char  *tok;

  /* Get the whole catfile into a buffer and parse it */

  //file = _dos_open (catfile, O_RDONLY | O_TEXT, &file);
  file = open (catfile, O_RDONLY | O_TEXT);
  if (file < 0)
      /* Cannot open the file.  Return failure */
      return 0;

  for (i=0; i<128; i++)
    catpoints[i].text = NULL;

  for (i=0; i<sizeof(catcontents); i++)
    catcontents[i] = '\0';

  /* Read the file into memory */
  //_dos_read (file, catcontents, sizeof(catcontents)-1, &i);
  i = read (file, catcontents, sizeof(catcontents)-1);

  if ((i == sizeof(catcontents)-1) || (i < 1))
      return 0; /* file was too big or too small */

  where = catcontents;
  i = 0; /* catpoints entry */

  do {
    char *msg;
    char *key;
    int key1 = 0;
    int key2 = 0;

    tok = strchr(where, '\n');

    if (tok == NULL) { /* done? */
      //_dos_close(file);
      close(file);
      return 1; /* success */
    }

    tok[0] = '\0'; /* terminate here */
    tok--; /* guess: \r before \n */
    if (tok[0] != '\r')
      tok++; /* if not, go back */
    else {
      tok[0] = '\0'; /* terminate here already */
      tok++;
    }
    tok++; /* this is where the next line starts */

    if ( (where[0] >= '0') && (where[0] <= '9') &&
         ( (msg = strchr(where,':')) != NULL) ) {
      /* Skip everything which starts with # or with no digit */
      /* Entries look like "1.2:This is a message" */

      msg[0] = '\0'; /* remove : */
      msg++; /* go past the : */

      if ((key = strchr (where, '.')) != NULL)  {
        key[0] = '\0'; /* turn . into terminator */
        key++; /* go past the . */
        key1 = mystrtoul(where, 10, strlen(where));
        key2 = mystrtoul(key, 10, strlen(key));

        if ((key1 >= 0) && (key2 >= 0)) {
          catpoints[i].key1 = key1;
          catpoints[i].key2 = key2;
          catpoints[i].text = processEscChars(msg);
          if (catpoints[i].text == NULL) /* ESC parse error */
            catpoints[i].text = msg;
          i++; /* next entry! */
        } /* valid keys */

      } /* . found */

    } /* : and digit found */

    where = tok; /* go to next line */

  } while (1);
}
Exemple #7
0
char *processEscChars(char *line)
{
  register char *src = line, *dst = line;

  /* used when converting \xdd and \ddd (hex or octal) characters */
  char ch;

  if (line == NULL) return NULL;

  /* cycle through copying characters, except when a \ is encountered. */
  for ( ; *src != '\0'; src++, dst++)
    {
      ch = *src;
    
      if (ch == '\\')
	{           
	  src++; /* point to char following slash */
	  switch (ch = *src)
	    {
	    case '\\': /* a single slash */
	      ch = '\\';
	      break;
	    case 'n': /* a newline (linefeed) */
	      ch = '\n';
	      break;
	    case 'r': /* a carriage return */
	      ch = '\r';
	      break;
	    case 't': /* a horizontal tab */
	      ch = '\t';
	      break;
	    case 'v': /* a vertical tab */
	      ch = '\v';
	      break;
	    case 'b': /* a backspace */
	      ch = '\b';
	      break;
	    case 'a': /* alert */
	      ch = '\a';
	      break;
	    case 'f': /* formfeed */
	      ch = '\f';
	      break;
	    case 'x': /* extension supporting hex numbers \xdd or \x0dd */
	      {
		int error;
		ch  = mystrtoul(src+1,16,2, &error); /* get value */
		if (!error) /* store character */
		  {
		    src += 2;
		  }
		else /* error so just store x (loose slash) */
		  {
		    ch = *src;
		  }
	      }

	      break;
	    default: /* just store letter (loose slash) or handle octal */
	  
	      {
		int error;
		ch  = mystrtoul(src,8,3, &error); /* get value */
		if (!error) /* store character */
		  {
		    src += 3;
		  }
		else
		  ch = *src;
	      }  
	  
	      break;
	    }
	}

      *dst = ch;
    }

  /* ensure '\0' terminated */
  *dst = '\0';

  return line;
}