Пример #1
0
void onEvent (ev_t ev)
{
    debug_event(ev);

    switch(ev)
    {
   
      // network joined, session established
      case EV_JOINED:
          debug_val("\r\nnetid = ", LMIC.netid);

          // immediately prepare next transmission
          debug_str("\r\nSending");
          LMIC.frame[0] = LMIC.snr;
          LMIC_setTxData2(1, LMIC.frame, 1, 0);	// schedule transmission (port 1, datalen 1, no ack requested)
    	  break;
        
      // scheduled data sent (optionally data received)
      case EV_TXCOMPLETE:
          if(LMIC.dataLen) { // data received in rx slot after tx
        	  debug_str("\r\nReceived:");
              debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
          }
          // immediately prepare next transmission
          LMIC.frame[0] = LMIC.snr;
          debug_val("\r\nSending:", LMIC.frame[0]);
			// schedule transmission (port 1, datalen 1, no ack requested)
          LMIC_setTxData2(1, LMIC.frame, 1, 0);
          break;
    }
}
Пример #2
0
Файл: mailmap.c Проект: 0369/git
static void free_mailmap_info(void *p, const char *s)
{
	struct mailmap_info *mi = (struct mailmap_info *)p;
	debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n",
		 s, debug_str(mi->name), debug_str(mi->email));
	free(mi->name);
	free(mi->email);
}
Пример #3
0
static void add_mapping(struct string_list *map,
			char *new_name, char *new_email,
			char *old_name, char *old_email)
{
	struct mailmap_entry *me;
	int index;

	if (old_email == NULL) {
		old_email = new_email;
		new_email = NULL;
	}

	if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) {
		/* mailmap entry exists, invert index value */
		index = -1 - index;
		me = (struct mailmap_entry *)map->items[index].util;
	} else {
		/* create mailmap entry */
		struct string_list_item *item;

		item = string_list_insert_at_index(map, index, old_email);
		me = xcalloc(1, sizeof(struct mailmap_entry));
		me->namemap.strdup_strings = 1;
		me->namemap.cmp = strcasecmp;
		item->util = me;
	}

	if (old_name == NULL) {
		debug_mm("mailmap: adding (simple) entry for %s at index %d\n",
			 old_email, index);
		/* Replace current name and new email for simple entry */
		if (new_name) {
			free(me->name);
			me->name = xstrdup(new_name);
		}
		if (new_email) {
			free(me->email);
			me->email = xstrdup(new_email);
		}
	} else {
		struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
		debug_mm("mailmap: adding (complex) entry for %s at index %d\n",
			 old_email, index);
		if (new_name)
			mi->name = xstrdup(new_name);
		if (new_email)
			mi->email = xstrdup(new_email);
		string_list_insert(&me->namemap, old_name)->util = mi;
	}

	debug_mm("mailmap:  '%s' <%s> -> '%s' <%s>\n",
		 debug_str(old_name), old_email,
		 debug_str(new_name), debug_str(new_email));
}
Пример #4
0
Файл: mailmap.c Проект: 0369/git
static void free_mailmap_entry(void *p, const char *s)
{
	struct mailmap_entry *me = (struct mailmap_entry *)p;
	debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n",
		 s, me->namemap.nr);
	debug_mm("mailmap: - simple: '%s' <%s>\n",
		 debug_str(me->name), debug_str(me->email));

	free(me->name);
	free(me->email);

	me->namemap.strdup_strings = 1;
	string_list_clear_func(&me->namemap, free_mailmap_info);
}
Пример #5
0
Файл: mailmap.c Проект: 0369/git
int map_user(struct string_list *map,
	     const char **email, size_t *emaillen,
	     const char **name, size_t *namelen)
{
	struct string_list_item *item;
	struct mailmap_entry *me;

	debug_mm("map_user: map '%.*s' <%.*s>\n",
		 (int)*namelen, debug_str(*name),
		 (int)*emaillen, debug_str(*email));

	item = lookup_prefix(map, *email, *emaillen);
	if (item != NULL) {
		me = (struct mailmap_entry *)item->util;
		if (me->namemap.nr) {
			/*
			 * The item has multiple items, so we'll look up on
			 * name too. If the name is not found, we choose the
			 * simple entry.
			 */
			struct string_list_item *subitem;
			subitem = lookup_prefix(&me->namemap, *name, *namelen);
			if (subitem)
				item = subitem;
		}
	}
	if (item != NULL) {
		struct mailmap_info *mi = (struct mailmap_info *)item->util;
		if (mi->name == NULL && mi->email == NULL) {
			debug_mm("map_user:  -- (no simple mapping)\n");
			return 0;
		}
		if (mi->email) {
				*email = mi->email;
				*emaillen = strlen(*email);
		}
		if (mi->name) {
				*name = mi->name;
				*namelen = strlen(*name);
		}
		debug_mm("map_user:  to '%.*s' <%.*s>\n",
			 (int)*namelen, debug_str(*name),
			 (int)*emaillen, debug_str(*email));
		return 1;
	}
	debug_mm("map_user:  --\n");
	return 0;
}
Пример #6
0
Файл: mailmap.c Проект: 0369/git
static void add_mapping(struct string_list *map,
			char *new_name, char *new_email,
			char *old_name, char *old_email)
{
	struct mailmap_entry *me;
	struct string_list_item *item;

	if (old_email == NULL) {
		old_email = new_email;
		new_email = NULL;
	}

	item = string_list_insert(map, old_email);
	if (item->util) {
		me = (struct mailmap_entry *)item->util;
	} else {
		me = xcalloc(1, sizeof(struct mailmap_entry));
		me->namemap.strdup_strings = 1;
		me->namemap.cmp = namemap_cmp;
		item->util = me;
	}

	if (old_name == NULL) {
		debug_mm("mailmap: adding (simple) entry for '%s'\n", old_email);

		/* Replace current name and new email for simple entry */
		if (new_name) {
			free(me->name);
			me->name = xstrdup(new_name);
		}
		if (new_email) {
			free(me->email);
			me->email = xstrdup(new_email);
		}
	} else {
		struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
		debug_mm("mailmap: adding (complex) entry for '%s'\n", old_email);
		if (new_name)
			mi->name = xstrdup(new_name);
		if (new_email)
			mi->email = xstrdup(new_email);
		string_list_insert(&me->namemap, old_name)->util = mi;
	}

	debug_mm("mailmap:  '%s' <%s> -> '%s' <%s>\n",
		 debug_str(old_name), old_email,
		 debug_str(new_name), debug_str(new_email));
}
/*********************************************************************
 * @fn      zcl_ProcessZDOMsgs
 *
 * @brief   Process response messages.
 *
 * @param   inMsg - ZDO response message.
 *
 * @return  none
 */
static void zcl_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) {
  uint8 response;
  
  switch( inMsg->clusterID ) {
    case End_Device_Bind_rsp:
      response = ZDO_ParseBindRsp( inMsg );
      if ( response == ZSuccess ) {
        debug_str( "Bind succeeded." );
#if DEV_TYPE != COORDINATOR
        zcl_SendDeviceData();
#endif
      }
      break;

#if DEV_TYPE == COORDINATOR      
    case Device_annce: {
      ZDO_DeviceAnnce_t msg;
      uint8 buffer[50];
      
      ZDO_ParseDeviceAnnce( inMsg, &msg );
      sprintf( ( char* )buffer, "New device joined, address: %d", msg.nwkAddr );
      zcl_SendBindRequest();
      }
      break;
#endif
  }
}
/*********************************************************************
 * @fn      zcl_ProcessZdoStateChange
 *
 * @brief   Handles state change OSAL message from ZDO.
 *
 * @param   pMsg - Message data
 *
 * @return  none
 */
static void zcl_ProcessZdoStateChange(osal_event_hdr_t *pMsg) {
  switch( ( devStates_t )pMsg->status ) {
    case DEV_ZB_COORD: case DEV_ROUTER: case DEV_END_DEVICE:
#if DEV_TYPE == COORDINATOR
      debug_str( "Successfully started network." );
#else
      debug_str( "Successfully connected to network." );
      zcl_SendBindRequest();
#endif
      break;
      
    case DEV_NWK_ORPHAN:
      debug_str( "Lost information about parent." );
      break;
  }
}
Пример #9
0
// initial job
static void initfunc (osjob_t* j) {

    LMIC_reset();	// reset MAC state

   LMIC_setSession(0x12345678, 0xB710566C, nwkKey, artKey);

   //LMIC_startJoining();	// start joining
   // init done - onEvent() callback will be invoked...

/*void LMIC_setSession (u4_t netid, devaddr_t(u4_t) devaddr, xref2u1_t nwkKey, xref2u1_t artKey) {
LMIC.netid = netid;
LMIC.devaddr = devaddr;
if( nwkKey != (xref2u1_t)0 )
os_copyMem(LMIC.nwkKey, nwkKey, 16);
if( artKey != (xref2u1_t)0 )
os_copyMem(LMIC.artKey, artKey, 16);*/

debug_str("\r\nSending");
// immediately prepare next transmission
LMIC.frame[0] = LMIC.snr;
// schedule transmission (port 1, datalen 1, no ack requested)
LMIC_setTxData2(1, LMIC.frame, 1, 0);
// (will be sent as soon as duty cycle permits)

LMIC_sendAlive();
}
Пример #10
0
void onEvent (ev_t ev) {
    debug_event(ev);

    switch(ev) {
   
      // network joined, session established
      case EV_JOINED:
          // enable tracking mode, start scanning...
          LMIC_enableTracking(0);
          debug_str("SCANNING...\r\n");
          break;

      // beacon found by scanning
      case EV_BEACON_FOUND:
          // switch LEN on
          debug_led(1);
          break;

      // beacon tracked at expected time
      case EV_BEACON_TRACKED:
          debug_val("GPS time = ", LMIC.bcninfo.time);
          // switch LEN on
          debug_led(1);
          break;

      // beacon missed at expected time
      case EV_BEACON_MISSED:
          // switch LEN off
          debug_led(0);
          break;
    }
}
Пример #11
0
void onEvent (ev_t ev) {
    debug_event(ev);

    switch(ev) {
   
      // network joined, session established
      case EV_JOINED:
          // enable pinging mode, start scanning...
          // (set local ping interval configuration to 2^1 == 2 sec)
          LMIC_setPingable(1);
          debug_str("SCANNING...\r\n");
          break;

      // beacon found by scanning
      case EV_BEACON_FOUND:
          // send empty frame up to notify server of ping mode and interval!
          LMIC_sendAlive();
          break;

      // data frame received in ping slot
      case EV_RXCOMPLETE:
          // log frame data
          debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
          if(LMIC.dataLen == 1) {
              // set LED state if exactly one byte is received
              debug_led(LMIC.frame[LMIC.dataBeg] & 0x01);
          }
          break;    
    }
}
Пример #12
0
/**************************************************************************************************
 * @fn      HalLcdWriteString
 *
 * @brief   Write a string to the LCD
 *
 * @param   str    - pointer to the string that will be displayed
 *          option - display options
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteString ( char *str, uint8 option)
{
#if (HAL_LCD == TRUE)
  uint8 strLen = 0;
  uint8 totalLen = 0;
  uint8 *buf;
  uint8 tmpLen;

  if ( Lcd_Line1 == NULL )
  {
    Lcd_Line1 = osal_mem_alloc( HAL_LCD_MAX_CHARS+1 );
    HalLcdWriteString( "TexasInstruments", 1 );
  }

  strLen = (uint8)osal_strlen( (char*)str );

  /* Check boundries */
  if ( strLen > HAL_LCD_MAX_CHARS )
    strLen = HAL_LCD_MAX_CHARS;

  if ( option == HAL_LCD_LINE_1 )
  {
    /* Line 1 gets saved for later */
    osal_memcpy( Lcd_Line1, str, strLen );
    Lcd_Line1[strLen] = '\0';
  }
  else
  {
    /* Line 2 triggers action */
    tmpLen = (uint8)osal_strlen( (char*)Lcd_Line1 );
    totalLen =  tmpLen + 1 + strLen + 1;
    buf = osal_mem_alloc( totalLen );
    if ( buf != NULL )
    {
      /* Concatenate strings */
      osal_memcpy( buf, Lcd_Line1, tmpLen );
      buf[tmpLen++] = ' ';
      osal_memcpy( &buf[tmpLen], str, strLen );
      buf[tmpLen+strLen] = '\0';

      /* Send it out */
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
      debug_str( (uint8*)buf );
#endif //ZTOOL_P1

      /* Free mem */
      osal_mem_free( buf );
    }
  }

  /* Display the string */
  HalLcd_HW_WriteLine (option, str);

#endif //HAL_LCD
}
Пример #13
0
void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData  )
{
  uint8 buf[32];
  uint8 *pBuf;
  uint8 tmpLen;
  uint8 sensorReading;

  if (command == SENSOR_REPORT_CMD_ID)
  {
    // Received report from a sensor
    sensorReading = pData[1];

    // If tool available, write to serial port

    tmpLen = (uint8)osal_strlen( (char*)strDevice );
    pBuf = osal_memcpy( buf, strDevice, tmpLen );
    _ltoa( source, pBuf, 16 );
    pBuf += 4;
    *pBuf++ = ' ';

    if ( pData[0] == BATTERY_REPORT )
    {
      tmpLen = (uint8)osal_strlen( (char*)strBattery );
      pBuf = osal_memcpy( pBuf, strBattery, tmpLen );

      *pBuf++ = (sensorReading / 10 ) + '0';    // convent msb to ascii
      *pBuf++ = '.';                            // decimal point ( battery reading is in units of 0.1 V
      *pBuf++ = (sensorReading % 10 ) + '0';    // convert lsb to ascii
      *pBuf++ = ' ';
      *pBuf++ = 'V';
    }
    else
    {
      tmpLen = (uint8)osal_strlen( (char*)strTemp );
      pBuf = osal_memcpy( pBuf, strTemp, tmpLen );

      *pBuf++ = (sensorReading / 10 ) + '0';    // convent msb to ascii
      *pBuf++ = (sensorReading % 10 ) + '0';    // convert lsb to ascii
      *pBuf++ = ' ';
      *pBuf++ = 'C';
    }

    *pBuf++ = '\r';
    *pBuf++ = '\n';
    *pBuf = '\0';

#if defined( MT_TASK )
    debug_str( (uint8 *)buf );
#endif

    // can also write directly to uart

  }
}
Пример #14
0
// initial job
static void initfunc (osjob_t* j) {
    // reset MAC state
    LMIC_reset();
    // start joining
    LMIC_setSession(0x12345678, 0xB710566C, nwkKey, artKey);
    // enable tracking mode, start scanning...
    LMIC_enableTracking(0);
    debug_str("SCANNING...\r\n");

    //LMIC_startJoining();
    // init done - onEvent() callback will be invoked...
}
Пример #15
0
void delay_us(unsigned count){
    unsigned startTime=ReadCoreTimer();
    unsigned endTime= startTime + (count* SYS_FREQ/1E6);
    if(endTime>UINT_MAX-100)// margin for safety. we don't want to wait a whole round
        endTime=0;
    debug_str("delay from ");
    debug_int_hex_16bit(startTime>>16);
    debug_int_hex_16bit(startTime>>00);
    debug_str("\r\nuntil      ");
    debug_int_hex_16bit(endTime>>16);
    debug_int_hex_16bit(endTime>>00);
    debug_nl();
    unsigned time;
    while((time=ReadCoreTimer())<endTime || (time>startTime && endTime<startTime) )//the second check is because the coreTimer regularly overflows
    {
        int c;
         for(c=0; c<10; c++)
            Nop();
    }
    debug_str(" done \r\n");

}
Пример #16
0
/**************************************************************************************************
 * @fn      HalLcdWriteString
 *
 * @brief   Write a string to the LCD
 *
 * @param   str    - pointer to the string that will be displayed
 *          line   - line number to display
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteString ( char *str, uint8 line)
{
#if (HAL_LCD == TRUE)
#if (defined HAL_IMG_AREA && (HAL_IMG_AREA == 3))
  line += 4;
#endif
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
#if defined (SERIAL_DEBUG_SUPPORTED)
  debug_str( (uint8*)str );
#endif
#endif
  HalLcd_HW_WriteLine (str, line - 1);
#endif
}
Пример #17
0
void debug_init () {
    // configure LED pin as output
    hw_cfg_pin(LED_PORT, LED_PIN, GPIOCFG_MODE_OUT | GPIOCFG_OSPEED_40MHz | GPIOCFG_OTYPE_PUPD | GPIOCFG_PUPD_PUP);
    debug_led(0);

    // configure USART1 (115200/8N1, tx-only)
    RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
    hw_cfg_pin(USART_TX_PORT, USART_TX_PIN, GPIOCFG_MODE_ALT|GPIOCFG_OSPEED_40MHz|GPIOCFG_OTYPE_PUPD|GPIOCFG_PUPD_PUP|GPIO_AF_USART1);
    USART1->BRR = 277; // 115200
    USART1->CR1 = USART_CR1_UE | USART_CR1_TE; // usart+transmitter enable

    // print banner
    debug_str("\r\n============== DEBUG STARTED ==============\r\n");
}
Пример #18
0
void gui_holder::draw_all_dx_dy(int8_t plane,float dx, float dy)
{
    for (uint32_t i=0; i<elmnt.size(); i++)
    {
        if (elmnt[i])
        {
            if (elmnt[i]->renderable)
                elmnt[i]->draw(dx,dy,plane);
#ifdef GUI_DEBUG
            char buf[32];
            sprintf(buf,"%d t%d",elmnt[i]->guid,elmnt[i]->get_type());
            debug_str(elmnt[i]->x+20,elmnt[i]->y,buf);
#endif // GUI_DEBUG
        }

    }
}
/*********************************************************************
 * @fn      zcl_SendData
 *
 * @brief   Send data to bound node.
 *
 * @param   none
 *
 * @return  none
 */
static void zcl_SendData( uint8 dataLength, uint8 *data, uint16 destShortAddr ) {
  afAddrType_t afDstAddr;
  ZStatus_t response;
  
  afDstAddr.addr.shortAddr = destShortAddr;
  afDstAddr.addrMode = ( afAddrMode_t )dstAddr.addrMode;
  afDstAddr.endPoint = ENDPOINT;
  
  response = zcl_SendCommand( ENDPOINT, &afDstAddr,
    ZCL_CLUSTER_ID_MS_ALL, COMMAND_OFF,
    TRUE, ZCL_FRAME_CLIENT_SERVER_DIR,
    FALSE, 0, 0,
    dataLength, data );
  
  if( response == ZSuccess ) {
    debug_str( "Successfully sent message." );
  }
}
/*********************************************************************
 * @fn      zclEnergyHarvester_HdlIncoming
 *
 * @brief   Callback from ZCL to process incoming Commands specific
 *          to this cluster library or Profile commands for attributes
 *          that aren't in the attribute list
 *
 * @param   pInMsg - pointer to the incoming message
 *
 * @return  ZStatus_t
 */
static ZStatus_t zclEnergyHarvester_HdlIncoming( zclIncoming_t *pInMsg ) {
#if DEV_TYPE==COORDINATOR
  uint8 buffer[50];
  uint8 temperatureLength;
  
  temperatureLength = strlen( ( char* )pInMsg->pData );
  sprintf( ( char* )buffer, "Node temperature: %s, Node battery voltage: %s.", pInMsg->pData, pInMsg->pData + temperatureLength + 1 );
  debug_str( buffer );
  
  zcl_SendAck( pInMsg->msg->srcAddr.addr.shortAddr );
#else
  if( strcmp( ( char* )pInMsg->pData, "SHUTDOWN" ) == 0 ) {
    SysCtrlDeepSleep();
    SysCtrlReset();
  }
#endif
  
  return ( ZSuccess );
}
Пример #21
0
void debug_init () {
    // configure LED pin as output
    
    NRF_GPIO->DIRSET = (1UL << LED_PIN);
    debug_led(0);

    // configure USART1 (115200/8N1, tx-only)
    NRF_GPIO->DIRSET = (1UL << USART_TX_PIN);
    //NRF_GPIO->DIRSET = (1UL << USART_RTS_PIN);

    NRF_UARTE0->CONFIG = (UART_CONFIG_HWFC_Disabled   << UART_CONFIG_HWFC_Pos) |
                         (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos); 
  
    NRF_UARTE0->BAUDRATE = UARTE_BAUDRATE_BAUDRATE_Baud115200 << UARTE_BAUDRATE_BAUDRATE_Pos;
    
    NRF_UARTE0->PSEL.TXD = USART_TX_PIN;
    
    NRF_UARTE0->ENABLE = UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos;

    // print banner
    debug_str("\r\n============== DEBUG STARTED ==============\r\n");
}
Пример #22
0
bool RiskMap::save(SaveType saveType, std::string path) {
	std::string extension = "";
	bool success = false;
	switch (saveType) {
		case MAP:
			extension = ".map";
			path.append(extension);
			success = this->saveMap(path);
			break;
		case XML:
			extension = ".xml";
			path.append(extension);
			success = this->saveXML(path);
			break;
		default:
			return false;
	}
	std::string debug_str("Saved map file to ");
	debug_str.append(path);
	debug(debug_str);

	return success;
}
Пример #23
0
void debug_init ()
{
	GPIO_PinModeSet(PORT_SPK, PIN_SPK, gpioModePushPull, 0);

	LEUART_Init_TypeDef init = LEUART_INIT_DEFAULT;

	CMU_ClockEnable(cmuClock_HFPER, true);
	CMU_ClockEnable(cmuClock_GPIO, true);

	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
	CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_1);
	CMU_ClockEnable(cmuClock_LEUART0, true);

	init.refFreq =  0; //14MHz / 2 pre-scaled by 4 = 1750000;
	init.enable =   leuartDisable;
	init.baudrate = 9600;
	init.databits = leuartDatabits8;
	init.parity =   leuartNoParity;
	init.stopbits = leuartStopbits1;

	// Reseting and initializing LEUART0
	LEUART_Reset(LEUART0);
	LEUART_Init(LEUART0, &init);

	GPIO_PinModeSet(PORT_TXD, PIN_TXD, gpioModePushPull, 1);
	GPIO_PinModeSet(PORT_RXD, PIN_RXD, gpioModeInput, 0);

	LEUART0->ROUTE = LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN | LEUART_ROUTE_LOCATION_LOC0;
	LEUART0->CMD = LEUART_CMD_TXDIS | LEUART_CMD_RXDIS | LEUART_CMD_CLEARTX | LEUART_CMD_CLEARRX;
	LEUART0->CMD = LEUART_CMD_TXEN | LEUART_CMD_RXEN;

	// Eventually enable UART
	LEUART_Enable(LEUART0, leuartEnable);

	// print banner
    debug_str("\r\n============= DEBUG STARTED =============\r\n");
}
Пример #24
0
ssize_t NEW(pread)(int fd, void *buf, size_t count, off_t offset)
{
    LOADSYM(pread);

    int ret = ORIG(pread)(fd, buf, count, offset);
    if (!must_fuzz_fd(fd))
        return ret;

    if (ret > 0)
    {
        long int curoff = _zz_getpos(fd);

        _zz_setpos(fd, offset);
        _zz_fuzz(fd, buf, ret);
        _zz_setpos(fd, curoff);
    }

    char tmp[128];
    debug_str(tmp, buf, ret, 8);
    debug("%s(%i, %p, %li, %li) = %i %s", __func__,
          fd, buf, (long int)count, (long int)offset, ret, tmp);

    return ret;
}
Пример #25
0
c_debug()
{
	register struct ww *w;

	if (!terse)
		wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin);
	wwcurtowin(cmdwin);
	while (wwpeekc() < 0)
		wwiomux();
	if (!terse)
		wwputc('\n', cmdwin);
	switch (wwgetc()) {
	case 'm':
		wwdumpsmap();
		break;
	case 'n':
		wwdumpns();
		break;
	case 'o':
		wwdumpos();
		break;
	case 's':
		debug_str();
		break;
	case 'v':
		if ((w = getwin()) != 0)
			wwdumpnvis(w);
		break;
	case 'w':
		if ((w = getwin()) != 0)
			wwdumpwin(w);
		break;
	default:
		wwbell();
	}
}
Пример #26
0
void debug_node(union node *node, int depth) {
    debug_unquoted("type", debug_nodes[node->id], depth);
    debug_space(depth);

    switch(node->id) {
    case N_SIMPLECMD:
        debug_ulong("bngd", node->ncmd.bgnd, depth);
        debug_space(depth);
        debug_sublist("rdir", node->ncmd.rdir, depth);
        debug_space(depth);
        debug_sublist("args", node->ncmd.args, depth);
        debug_space(depth);
        debug_sublist("vars", node->ncmd.vars, depth);
        break;

    case N_PIPELINE:
        debug_ulong("bgnd", node->npipe.bgnd, depth);
        debug_space(depth);
        debug_sublist("cmds", node->npipe.cmds, depth);
        debug_space(depth);
        debug_ulong("ncmd", node->npipe.ncmd, depth);
        break;

    case N_AND:
    case N_OR:
        debug_ulong("bgnd", node->nandor.bgnd, depth);
        debug_space(depth);
        debug_subnode("cmd0", node->nandor.cmd0, depth);
        debug_space(depth);
        debug_subnode("cmd1", node->nandor.cmd1, depth);
        break;

    case N_SUBSHELL:
    case N_CMDLIST:
        debug_sublist("rdir", node->ngrp.rdir, depth);
        debug_space(depth);
        debug_sublist("cmds", node->ngrp.cmds, depth);
        break;

    case N_FOR:
        debug_str("varn", node->nfor.varn, depth);
        debug_space(depth);
        debug_sublist("cmds", node->nfor.cmds, depth);
        debug_space(depth);
        debug_sublist("args", node->nfor.args, depth);
        break;

    case N_CASE:
        debug_ulong("bgnd", node->ncase.bgnd, depth);
        debug_space(depth);
        debug_sublist("rdir", node->ncase.rdir, depth);
        debug_space(depth);
        debug_sublist("list", node->ncase.list, depth);
        debug_space(depth);
        debug_sublist("word", node->ncase.word, depth);
        break;

    case N_CASENODE:
        debug_sublist("pats", node->ncasenode.pats, depth);
        debug_space(depth);
        debug_sublist("cmds", node->ncasenode.cmds, depth);
        break;

    case N_IF:
        debug_ulong("bgnd", node->nif.bgnd, depth);
        debug_space(depth);
        debug_sublist("rdir", node->nif.rdir, depth);
        debug_space(depth);
        debug_sublist("cmd0", node->nif.cmd0, depth);
        debug_space(depth);
        debug_sublist("cmd1", node->nif.cmd1, depth);
        debug_space(depth);
        debug_subnode("test", node->nif.test, depth);
        break;

    case N_WHILE:
    case N_UNTIL:
        debug_ulong("bgnd", node->nloop.bgnd, depth);
        debug_space(depth);
        debug_sublist("rdir", node->nif.rdir, depth);
        debug_space(depth);
        debug_sublist("cmds", node->nloop.test, depth);
        debug_space(depth);
        debug_subnode("test", node->nloop.test, depth);
        break;

    case N_FUNCTION:
        debug_sublist("cmds", node->nfunc.cmds, depth);
        debug_space(depth);
        debug_str("name", node->nfunc.name, depth);
        break;

    case N_ASSIGN:

    case N_ARG:
        debug_subst("flag", node->narg.flag, depth);
        debug_space(depth);
        debug_stralloc("stra", &node->narg.stra, depth);
        debug_space(depth);
        debug_sublist("list", node->narg.list, depth);
        break;

    case N_REDIR:
        debug_redir("flag", node->nredir.flag, depth);
        debug_space(depth);
        debug_sublist("list", node->nredir.list, depth);
        debug_space(depth);
        debug_sublist("data", node->nredir.data, depth);
        debug_space(depth);
        debug_ulong("fdes", node->nredir.fdes, depth);
        break;

    case N_ARGSTR:
        debug_subst("flag", node->nargstr.flag, depth);
        debug_space(depth);
        debug_stralloc("stra", &node->nargstr.stra, depth);
        break;

    case N_ARGPARAM:
        debug_subst("flag", node->nargparam.flag, depth);
        debug_space(depth);
        debug_str("name", node->nargparam.name, depth);
        debug_space(depth);
        debug_sublist("word", node->nargparam.word, depth);
        debug_space(depth);
        debug_ulong("numb", node->nargparam.numb, depth);
        break;

    case N_ARGCMD:
    case N_ARGARITH:
        debug_subst("flag", node->nargcmd.flag, depth);
        debug_space(depth);
        debug_sublist("list", node->nargcmd.list, depth);
        break;

    case N_NOT:
        debug_sublist("cmds", node->nandor.cmd0, depth);
        break;
    }
}
Пример #27
0
void action_state_t::debug()
{
    std::ostringstream s;
    action -> sim -> out_debug.printf( "%s", debug_str( s ).str().c_str() );
}
Пример #28
0
 std::string Symbol::debug_str(STATE) {
   return debug_str(state->shared());
 }
Пример #29
0
/**
 * @brief Parses the Conquest .map map file in the path indicated to populate the instance
 */
void RiskMap::loadMap(const std::string& path) {
	std::ifstream infile(path);
	std::string line;
	int mode = 0;

	while (std::getline(infile, line))
	{
		std::string debug_str("Read line: ");
		debug_str.append(line);
		debug(debug_str);
		// Windows prefers /r/n, but getline() breaks only on \n.
		if (line.size() > 0 && line[line.size() - 1] == '\r') {
			line.resize(line.size() - 1);
		}

		// Set the mode for how we should process lines based on section headers
		if (line.compare("[Map]") == 0) {
			mode = MAP_PARSE_MODE_MAP;
			debug("  Parsing map metadata");
			continue;
		}
		if (line.compare("[Continents]") == 0) {
			mode = MAP_PARSE_MODE_CONTINENTS;
			debug("  Parsing continents");
			continue;
		}
		if (line.compare("[Territories]") == 0) {
			mode = MAP_PARSE_MODE_COUNTRIES;
			debug("  Parsing countries");
			continue;
		}

		// Process lines per the current mode.
		std::string item;
		std::stringstream line_stream(line);
		std::vector<std::string> values;
		if (mode == MAP_PARSE_MODE_MAP || line.length() == 0) {
			debug_str = "  Skipping: ";
			debug_str.append(line);
			debug(debug_str);
			continue;
		}
		else if (mode == MAP_PARSE_MODE_CONTINENTS) {
			while (std::getline(line_stream, item, '=')) {
				values.push_back(item);
			}
			debug_str = "  Adding continent: ";
			debug_str.append(values[0]);
			debug(debug_str);

			Continent continent(values[0]);
			continent.setReinforcementBonus(atoi(values[1].c_str()));
			this->addContinent(continent);
		}
		else if (mode == MAP_PARSE_MODE_COUNTRIES) {
			while (std::getline(line_stream, item, ',')) {
				values.push_back(item);
			}
			std::string continentName(values[3]);

			debug_str = "  Adding country: ";
			debug_str.append(values[0]);
			debug_str.append(" in continent ");
			debug_str.append(continentName);
			debug(debug_str);

			Country country(values[0]);
			country.setPositionX(atoi(values[1].c_str()));
			country.setPositionY(atoi(values[2].c_str()));
			country.setArmies(0);
			this->addCountry(country, continentName);
		}
		else {
			debug("Error parsing line: " + line);
			return;
		}
	}

	debug("Parsing file again to configure adjacencies");
	infile.clear();
	infile.seekg(0, std::ios_base::beg);
	while (std::getline(infile, line))
	{
		std::string debug_str("Read line: ");
		debug_str.append(line);
		debug(debug_str);
		// Windows prefers /r/n, but getline() breaks only on \n.
		if (line.size() > 0 && line[line.size() - 1] == '\r') {
			line.resize(line.size() - 1);
		}

		// Set the mode for how we should process lines based on section headers
		if (line.compare("[Map]") == 0) {
			mode = MAP_PARSE_MODE_MAP;
			debug("  Parsing map metadata");
			continue;
		}
		if (line.compare("[Continents]") == 0) {
			mode = MAP_PARSE_MODE_CONTINENTS;
			debug("  Parsing continents");
			continue;
		}
		if (line.compare("[Territories]") == 0) {
			mode = MAP_PARSE_MODE_COUNTRIES;
			debug("  Parsing countries");
			continue;
		}

		// Process lines per the current mode.
		std::string item;
		std::stringstream line_stream(line);
		std::vector<std::string> values;
		if (mode != MAP_PARSE_MODE_COUNTRIES || line.length() == 0) {
			debug_str = "  Skipping: ";
			debug_str.append(line);
			debug(debug_str);
			continue;
		}
		else if (mode == MAP_PARSE_MODE_COUNTRIES) {
			while (std::getline(line_stream, item, ',')) {
				values.push_back(item);
			}
			Country* country = this->getCountry(values[0]);
			std::vector<std::string>::iterator iter;
			for (iter = values.begin() + 4; iter < values.end(); iter++) {
				Country* neighbour = this->getCountry(*iter);
				this->addNeighbour(country->getName(), neighbour->getName());

				debug_str = "  ";
				debug_str.append(country->getName());
				debug_str.append(" touches ");
				debug_str.append(neighbour->getName());
				debug(debug_str);
			}
		}
		else {
			debug("Error parsing line: " + line);
			return;
		}
	}

	debug("Finished parsing: " + path);
}