示例#1
0
main(int argc, char *argv[])
{
      int Day;
      void usage(void);
      unsigned d, m, y, days[] = {31, 29, 31, 30, 31, 30,
                                  31, 31, 30, 31, 30, 31};
      char *day[2][7] = {
            {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"},
            {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
      };
      char *month[]  = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",};
      

      if (4 > argc)
            usage();
      y = atoi(argv[1]);
      m = atoi(argv[2]);
      d = atoi(argv[3]);
      if (!m || m > 12)
            usage();
      if (!d || d > days[m - 1])
            usage();
      if (y < 100)
            y += 1900;
      Day = DOW(y, m, d);
      printf("DOW(ISO_CAL=%d) returned %d, so %d %s %d is a %s\n",
            ISO_CAL, Day, d, month[m - 1], y, day[ADJ - 5][Day]);
      return 0;
}
示例#2
0
/*!
  \param Func
*/
xbShort xbExpn::ProcessFunction( char * Func )
{
/* 1 - pop function from stack
   2 - verify function name and get no of parms needed 
   3 - verify no of parms >= remainder of stack
   4 - pop parms off stack
   5 - execute function
   6 - push result back on stack
*/


  char   *buf = 0;
  xbExpNode *p1, *p2, *p3, *WorkNode, *FuncNode;
  xbShort  ParmsNeeded,len;
  char   ptype = 0;  /* process type s=string, l=logical, d=double */
  xbDouble DoubResult = 0;
  xbLong   IntResult = 0;
  FuncNode = (xbExpNode *) Pop();

  ParmsNeeded = GetFuncInfo( Func, 1 );

  if( ParmsNeeded == -1 ) {
    return XB_INVALID_FUNCTION;
  }
  else {
    ParmsNeeded = 0;
    if( FuncNode->Sibling1 ) ParmsNeeded++;
    if( FuncNode->Sibling2 ) ParmsNeeded++;
    if( FuncNode->Sibling3 ) ParmsNeeded++;
  }

  if( ParmsNeeded > GetStackDepth())
    return XB_INSUFFICIENT_PARMS;

  p1 = p2 = p3 = NULL;
  if( ParmsNeeded > 2 ) p3 = (xbExpNode *) Pop(); 
  if( ParmsNeeded > 1 ) p2 = (xbExpNode *) Pop(); 
  if( ParmsNeeded > 0 ) p1 = (xbExpNode *) Pop(); 
  memset( WorkBuf, 0x00, WorkBufMaxLen+1);

  if( strncmp( Func, "ABS", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = ABS( GetDoub( p1 ));
  }
  else if( strncmp( Func, "ASC", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = ASC( p1->StringResult );
  }
  else if( strncmp( Func, "AT", 2 ) == 0 ) {  
    ptype = 'd';
    DoubResult = AT( p1->StringResult, p2->StringResult );
  }
  else if( strncmp( Func, "CDOW", 4 ) == 0 ) {  
    ptype = 's';
    buf = CDOW( p1->StringResult );
  }
  else if( strncmp( Func, "CHR", 3 ) == 0 ) {  
    ptype = 's';
    buf = CHR( GetInt( p1 ));
  }
  else if( strncmp( Func, "CMONTH", 6 ) == 0 ) {  
    ptype = 's';
    buf = CMONTH( p1->StringResult );
  }
  else if( strncmp( Func, "CTOD", 4 ) == 0 ) {  
    ptype = 's';
    buf = CTOD( p1->StringResult );
  }
  else if( strncmp( Func, "DATE", 4 ) == 0 ) {  
    ptype = 's';
    buf = DATE();
  }
  else if( strncmp( Func, "DAY", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = DAY( p1->StringResult );
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'C' ) {  
    ptype = 's';
    buf = DESCEND( p1->StringResult.c_str() );
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'N' ) {  
    ptype = 'd';
    DoubResult = DESCEND( GetDoub( p1 ));
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'D' ) {  
    xbDate d( p1->StringResult );
    ptype = 'd';
    DoubResult = DESCEND( d );
  }
  else if( strncmp( Func, "DOW", 3 ) == 0 ) {
    ptype = 'd';
    DoubResult = DOW( p1->StringResult );
  }
  else if( strncmp( Func, "DTOC", 4 ) == 0 ) {  
    ptype = 's';
    buf = DTOC( p1->StringResult );
  }
  else if( strncmp( Func, "DTOS", 4 ) == 0 ) {  
    ptype = 's';
    buf = DTOS( p1->StringResult );
  }
  else if( strncmp( Func, "EXP", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = EXP( GetDoub( p1 ));
  }
  else if( strncmp( Func, "IIF", 3 ) == 0 ){
    ptype = 's';
    buf = IIF( p1->IntResult, p2->StringResult, p3->StringResult );
  }
  else if( strncmp( Func, "INT", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = INT( GetDoub( p1 ));
  }
  else if( strncmp( Func, "ISALPHA", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISALPHA( p1->StringResult );
  }
  else if( strncmp( Func, "ISLOWER", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISLOWER( p1->StringResult );
  }
  else if( strncmp( Func, "ISUPPER", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISUPPER( p1->StringResult );
  }
  else if( strncmp( Func, "LEN", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = LEN( p1->StringResult );
  }
  else if( strncmp( Func, "LEFT", 4 ) == 0 ) {  
    ptype = 's';
    buf = LEFT( p1->StringResult, INT( p2->DoubResult ));
  }
  else if( strncmp( Func, "LTRIM", 5 ) == 0 ) {  
    ptype = 's';
    buf = LTRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "LOG", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = LOG( GetDoub( p1 ));
  }  
  else if( strncmp( Func, "LOWER", 5 ) == 0 ) {  
    ptype = 's';
    buf = LOWER( p1->StringResult );
  }  
  else if( strncmp( Func, "MAX", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MAX( GetDoub( p1 ), GetDoub( p2 ));
  }  
  else if( strncmp( Func, "MIN", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MIN( GetDoub( p1 ), GetDoub( p2 ));
  }  
  else if( strncmp( Func, "MONTH", 5 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MONTH( p1->StringResult );
  } 

  else if( strncmp( Func, "RECNO", 5 ) == 0 )
  {
    ptype = 'd';
    DoubResult = RECNO( FuncNode->dbf );
  }

  else if( strncmp( Func, "REPLICATE", 9 ) == 0 ) {
    ptype = 's';
    buf = REPLICATE( p1->StringResult, GetInt( p2 ));
  }
  else if( strncmp( Func, "RIGHT", 5 ) == 0 ) {
    ptype = 's';
    buf = RIGHT( p1->StringResult, GetInt( p2 ));
  }
  else if( strncmp( Func, "RTRIM", 5 ) == 0 ) {  
    ptype = 's';
    buf = RTRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "SPACE", 5 ) == 0 ) {  
    ptype = 's';
    buf = SPACE( INT( GetDoub( p1 )));
  }
  else if( strncmp( Func, "SQRT", 4 ) == 0 ) {  
    ptype = 'd';
    DoubResult = SQRT( GetDoub( p1 ));
  }
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 1 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult );
  }   
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 2 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult, GetInt( p2 ));
  }   
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 3 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult, GetInt( p2 ), GetInt( p3 ));
  }   

  else if( strncmp( Func, "STR", 3 ) == 0 && p3 ) {
    ptype = 's';
    if(p1->ExpressionType == 'N')
      buf = STR( p1->DoubResult, GetInt( p2 ), GetInt( p3 ));
    else
      buf = STR( p1->StringResult, GetInt( p2 ), GetInt( p3 ));
  }   

  else if( strncmp( Func, "STR", 3 ) == 0 && p2 ) {
    ptype = 's';
    buf = STR( p1->StringResult, GetInt( p2 ));
  }

  else if( strncmp( Func, "STR", 3 ) == 0 && p1 ) {
    ptype = 's';
    buf = STR( p1->StringResult );
  }
   
  else if( strncmp( Func, "SUBSTR", 6 ) == 0 ) {
    ptype = 's';
    buf = SUBSTR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); 
  }
  else if( strncmp( Func, "TRIM", 4 ) == 0 ) {  
    ptype = 's';
    buf = TRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "UPPER", 5 ) == 0 ) {  
    ptype = 's';
    buf = UPPER( p1->StringResult );
  }  
  else if( strncmp( Func, "VAL", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = VAL( p1->StringResult );
  }  
  else if( strncmp( Func, "YEAR", 4 ) == 0 ) {  
    ptype = 'd';
    DoubResult = YEAR( p1->StringResult );
  }  
  if( p1 && !p1->InTree ) delete p1;
  if( p2 && !p2->InTree ) delete p2;
  if( p3 && !p3->InTree ) delete p3;
  if( !FuncNode->InTree ) delete FuncNode;
  if( buf ){
    len = strlen( buf );
    WorkNode = new xbExpNode;
    if( !WorkNode )
      return XB_NO_MEMORY;
    WorkNode->ResultLen = len + 1;
    
  } else {    
    len = 0;
    WorkNode = new xbExpNode;
    if( !WorkNode )
      return XB_NO_MEMORY;
    WorkNode->ResultLen = 0;
  }

  switch( ptype ){
   case 's':                               /* string or char result */
    WorkNode->DataLen = len;
    WorkNode->ExpressionType = 'C';
    WorkNode->Type = 's';
    WorkNode->StringResult = buf;
    break;
   case 'd':                               /* numeric result */
    WorkNode->DataLen = 0;
    WorkNode->ExpressionType = 'N';
    WorkNode->Type = 'd';
    WorkNode->DoubResult = DoubResult;
    break;
   case 'l':                               /* logical result */
    WorkNode->DataLen = 0;
    WorkNode->ExpressionType = 'L';
    WorkNode->Type = 'l';
    WorkNode->IntResult = IntResult;
    break;
   default:
    std::cout << "\nInternal error. " << ptype;
    break;
  }
  Push(WorkNode);
  return XB_NO_ERROR;
}
示例#3
0
文件: RTC.c 项目: lieb005/PICProjects
void printRTC(uint8_t digits)
{
	// 8 chars, X decimal points, and \0 at the end
	static char str[BUF_SIZE];
	uint8_t cnt = 0;

	uint8_t bits = countBits(digits);

	uint8_t i;

menu_loop:

	switch (bits)
	{
	case 8:
		switch (rtcMenu.state)
		{
		case ddd_hhmm:
			sprintf(str, "%s %02d.%02d", dow[date.dow], date.hour, date.minute);
			break;
		case DD_MM_YY:
			sprintf(str, "%02d-%02d-%02d", date.day, date.month, date.year % 100);
			break;
		case hhmmss:
			sprintf(str, "  %02d.%02d.%02d", date.hour, date.minute, date.second);
			break;
			/*case dd_hhmm:
				sprintf(str, " %c%c %02d.%02d", DOW(date.dow)[0], DOW(date.dow)[1], date.hour, date.minute);
				break;*/
			/*case DDMMYY:
				sprintf(str, "  %02d.%02d.%02d", date.day, date.month, date.year % 100);
				break;*/
			/*case hhmm:
				sprintf(str, "    %02d.%02d", date.hour, date.minute);
				break;
			case DDMM:
				sprintf(str, "    %02d.%02d", date.day, date.month);
				break;*/
		default:
			i = BUF_SIZE;
			while (--i)
				str[i-1] = '\0';
			break;
		}
		break;
	case 6 ... 7:
		switch (rtcMenu.state)
		{
		case hhmmss:
			sprintf(str, "%02d.%02d.%02d", date.hour, date.minute, date.second);
			break;
		case dd_hhmm:
			sprintf(str, "%c%c %02d.%02d", DOW(date.dow)[0], DOW(date.dow)[1], date.minute, date.second);
			break;
		case DDMMYY:
			sprintf(str, "%02d.%02d.%02d", date.day, date.month, date.year % 100);
			break;
			/*case hhmm:
				sprintf(str, "  %02d.%02d", date.hour, date.minute);
				break;
			case DDMM:
				sprintf(str, "  %02d.%02d", date.day, date.month);
				break;*/
		default:
			i = BUF_SIZE;
			while (--i)
				str[i - 1] = '\0';
			break;
		}
		break;
	case 4 ... 5:
		switch (rtcMenu.state)
		{
		case hhmm:
			sprintf(str, "%02d.%02d", date.hour, date.minute);
			break;
		case DDMM:
			sprintf(str, "%02d.%02d", date.day, date.month);
			break;
		default:
			i = BUF_SIZE;
			while (--i)
				str[i - 1] = '\0';
			break;
		}
		break;
	case 3:
		switch (rtcMenu.state)
		{
		case ddd:
			sprintf(str, "%02d.%02d", date.hour, date.minute);
			break;
		}
		break;
	case 2:
		switch (rtcMenu.state)
		{
		case dd:
			sprintf(str, "%c%c", date.hour, date.minute);
			break;
		default:
			i = BUF_SIZE;
			while (--i)
				str[i - 1] = '\0';
			break;
		}
		break;
	case 0 ... 1:
		sprintf(str, "    ");
		break;
	}
	if (*str == 0)
	{
		cnt++;
		advState();
		if (cnt < DATEVIEWS)
		{
			goto menu_loop;
		}
		else
		{
			sprintf(str, "ERR");
		}
	}

	writeString(digits, str);
	screen.changed |= digits;
}