Example #1
0
/* 
	The current song or the playlistlength (or both) has changed.
	Redraw the caption window
*/
void
view_pos_changed(){
	char newstr[30];
	char number[20];
	char *numstr;
	int cur_song, pl_length;		
	
	cur_song = mpd_get_pos();
	if (cur_song == SONG_UNKNOWN) {
		win_new_text(&caption_win,"");
		return;
	};
	
	if (cur_song == NO_SONG){
		win_new_text(&caption_win,"No current song");
		return;
	};

	if (is_stream() == 1)
		strlcpy(newstr, "Station ", sizeof(newstr));
	else
		strlcpy(newstr, "Song ", sizeof(newstr));
	
	numstr = get_digits(cur_song + 1, number, 0); 			// user readable song pos starts with 1, not 0
	strlcat(newstr, numstr, sizeof(newstr));
	
	pl_length = mpd_get_pl_length();
	if (pl_length >= 0){
		strlcat(newstr, " of ", sizeof(newstr));
		numstr = get_digits(pl_length, number, 0); 
		strlcat(newstr, numstr, sizeof(newstr));
	};
	win_new_text(&caption_win, newstr);
};
Example #2
0
void show_alarm_text(void)
{
	if (get_digits() == 8)
		set_string("Alarm   ");
	else if (get_digits() == 6)
		set_string("Alarm");
	else
		set_string("Alrm");
}
Example #3
0
void show_set_alarm(void)
{
	if (get_digits() == 8)
		set_string("Set Alrm");
	else if (get_digits() == 6)
		set_string("Alarm");
	else
		set_string("Alrm");
}
Example #4
0
void show_set_time(void)
{
	if (get_digits() == 8)
		set_string("Set Time");
	else if (get_digits() == 6)
		set_string(" Time ");
	else
		set_string("Time");
}
Example #5
0
static int
show_range (CmdConfig *cmd_config, CameraWidget *range)
{
	float min, max, increment;

	CHECK (gp_widget_get_range (range, &min, &max, &increment));

	if (!get_digits (increment) && !get_digits (min) && !get_digits (max))
		return (show_range_int (cmd_config, range));
	else
		return (show_range_float (cmd_config, range));
}
int main (void) {
    int i, j, k, n, pos, p_len;
    int p[MAX_LENGTH];
    int base, circular;
    int total = 0;

    gen_primes ();
    for (i = 0; i < PRIME_COUNT; i++) {
        circular = true;
        p_len = log10 (prime[i]) + 1;
        get_digits (prime[i], &p[0], p_len);

        for (j = 1; j < p_len; j++) { /* form a new no. from a new start pos */
            base = pow (10, p_len - 1);
            pos = j;
            n = 0; k = 0;
            do {
                if (pos >= p_len) pos = 0;
                n += p[pos++] * base;
                base /= 10;
            } while (k++ < p_len);
            /* printf ("%d\n", n);  */
            if (!bsearch (&n, &prime[0], PRIME_COUNT, (int) sizeof (int), &compare))
                circular = false;
        }
        /* printf ("%d,", prime[i]);  */
        if (circular) {
            printf ("%d\n", prime[i]);
            total++;
        }
    }
    printf ("total=%d\n", total);
}
Example #7
0
/* The volume has changed. Show new value. */
void
view_volume_changed(int vol){
	char newstr[VOLSTR_SIZE];
	char number[20];
	char *numstr;
		
	if (vol > 0)
		win_new_text(&speaker_win, "\xB8");	// speaker icon on
	else
		win_new_text(&speaker_win, "\xB9");	//speaker off	
	
	strlcpy (newstr, "", sizeof(newstr));
	if (vol < 0)
		strlcat(newstr, "?? \n", sizeof(newstr));
	else {
		numstr = get_digits(vol, number, 0); 
		strlcat(newstr, numstr, sizeof(newstr));
		strlcat(newstr, " %\n", sizeof(newstr));
	};
	win_new_text(&volume_win, newstr);	

	if (vol >= 0){
		if ((win->flags & WINFLG_VISIBLE)) 
			draw_trianglebar( vol_ramp_win.start_row+1, vol_ramp_win.start_col+1, vol_ramp_win.width-2,
						  vol_ramp_win.height-2, vol_ramp_win.fg_color, vol_ramp_win.bg_color, vol_ramp_win.cur_char, vol/2 );
			vol_ramp_win.cur_char = vol/2;
	};
};
Example #8
0
char	*ft_itoa_base(int value, int base)
{
	char *str;
	int is_neg = 0;
	int len;
	if(value < 0)
	{
		if(base==10)
		{
			if(value == -2147483648)
				return ft_strdup("-2147483648", 11);
			is_neg = 1;
		}
		value = -value;
	}
	len = get_digits(value, base) + is_neg + 1;
	str = malloc(len);
	str[--len] = '\0';
	while(len--)
	{
		str[len] =  hex[value % base];
		value /= base;
	}
	if(is_neg)
		str[0] = '-';
	return str;
}
Example #9
0
int deserialize_mpi(gcry_mpi_t *x, enum disp_format df, const char *buf, 
		    int inlen)
{
  switch(df) {
  case DF_BIN:
    gcry_mpi_scan(x, GCRYMPI_FMT_USG, buf, inlen, NULL);
    gcry_mpi_set_flag(*x, GCRYMPI_FLAG_SECURE);
    break;
  case DF_COMPACT:
  case DF_BASE36:
    do {
    const char *digits = get_digits(df);
    unsigned int digit_count = get_digit_count(df);
    char *d;
    int i;
    *x = gcry_mpi_snew(0);
    for(i = 0; i < inlen; i++) {
        if (! (d = memchr(digits, buf[i], digit_count))) {
          gcry_mpi_release(*x);
          return 0;
        }
        gcry_mpi_mul_ui(*x, *x, digit_count);
        gcry_mpi_add_ui(*x, *x, d - digits);
    }
    } while (0);
    break;
  default: 
    assert(0);
  }
  return 1;
}
Example #10
0
File: address.c Project: ninux/mc
static int get_entry_length(entry_ptr_t ent)
{
	int length;

	length = 0;

	length += strlen(ent->data->firstname);
	length += strlen(ent->data->lastname);
	length += strlen(ent->data->street);
	length += get_digits(*(ent->data->number));
	length += get_digits(*(ent->data->zipcode));
	length += strlen(ent->data->city);

	_dbgmsg("calculated %i characters for the entry", length);
	return length;
}
/*
 * This Function recives the address of an array 
 * and the number of elements given in that array. 
 * then it calculates the length of each array value, 
 * it also calculates the exponent. After that it 
 * prints each character. 
 */
void print_array(int *a, int n)
{
  int i;
/*Selects each value of the array*/
  for (i = 0; i < n; i++)
    {
      int s = a[i];
/*Handles negative numbers*/
      if (s < 0)
      {print_char('-');
        s = s*(-1); 

      }
/*Calls the functions if the array is within bounds*/
      if (i < n) 
	{     
	  int length = get_the_length(s);
	  int p = get_the_power(length); 
	  get_digits(s, p, length);
	}
/*prints ',' and ' ' if the array is within bounds and is not the last array value*/
      if (i < n-1)
	{
	  print_char(',');
	  print_char(' ');
	}
/*prints a new line if is the end of the array*/
      else
	{
	  print_char('\n');
	}   
    }
}
/* takes an integer in parameter and prints it */
void print_number(int n)
{
  int min = 0;

  if (n < 0)
    {
      /* take care of INT_MIN scenario */
      if (n == -2147483648)
	{
	  n = -214748364;
	  min = 1;
	}
      n = n * -1;
      print_char('-');
    }

  digits = get_digits(n);
  digitRetainer = digits;
  ten_power = get_power();

  if (n == 0)
    {
      print_char('0');
    }
  else
    {
      print_digits(n);

      if (min == 1) {
	print_char(8 + '0');
      }
    }
}
Example #13
0
int min_clicks() {
    int i;
    mclicks+=get_digits(clist[0]);     /*for the first channel, you will always key in the digits*/
    curr_ch=clist[0];
    for(i=1;i<=cnum;i++){               /*run loop from second channel to cnum*/
      init(clicks,8);                   /*initialize clicks to 0 at the beginning of every iteration*/

      clicks[0]=get_digits(clist[i]);
      /*end of part 1 - directly key in the digits*/

      curr_ch=clist[i-1];
      channel_up(i,1);
      /*end of part 2 - keep pressing up*/

      curr_ch=clist[i-1];
      channel_down(i,2);
      /*end of part 3 - keep pressing down*/

      curr_ch=low;
      clicks[3]+=get_digits(low);
      channel_down(i,3);
      /*end of part 4 - key in min value and go back*/

      curr_ch=high;
      clicks[4]+=get_digits(high);
      channel_up(i,4);
      /*end of part 5 - key in max value and go forward*/

     if(i>1){
      curr_ch=clist[i-2];
      clicks[5]++;
      channel_up(i,5);
     } else clicks[5]=10000;
      /*end of part 6 - press back and then keep pressing down*/

     if(i>1) {
      curr_ch=clist[i-2];
      clicks[6]++;
      channel_down(i,6);
     } else clicks[6]=10000;
      /*end of part 7 - press back and then keep pressing up*/

      mclicks+=min_val(clicks,7); /*increment minclicks by the min value among the procedures followed for current channel*/
    }
  return mclicks;
}
Example #14
0
void show_alarm_off(void)
{
	if (get_digits() == 8) {
		set_string("Alrm off");
	}
	else {
		set_string(" off");
	}
}
Example #15
0
void show_setting_int(char* short_str, char* long_str, int value, bool show_setting)
{
	data[0] = data[1] = data[2] = data[3] = data[4] = data[5] = data[6] = data[7] = ' ';

	if (get_digits() == 8) {
		set_string(long_str);
		print_digits(value, 6);
	}
	else if (get_digits() == 6) {
		set_string(long_str);
		print_digits(value, 4);
	}
	else {
		if (show_setting)
			print_digits(value, 2);
		else
			set_string(short_str);
	}
}
Example #16
0
int
is_candidate(int num)
{
	int a[SIZE], b[SIZE];
	int i, k, l1, l2;

	l1 = get_digits(a, num);
	k = num;
	for (i = 0; i < 5; i++) {
		k += num;
		l2 = get_digits(b, k);
		if (l1 != l2) {
			return (0);
		}
		if (!same_digits(a, b, l1)) {
			return (0);
		}
	}
	return (1);
}
int main(int argc, char **argv) {
  int j, k, digits;

  for (j = 1488; j < 10000; j++) {
    if (!is_prime(j))
      continue;
    digits = get_digits(j);
    for (k = j + 1; k + k - j < 10000; k++) {
      if (digits == get_digits(k) && digits == get_digits(k + k - j) &&
          is_prime(k) && is_prime(k + k - j)) {
        printf("%d%d%d\n", j, k, k + k - j);
        goto found_numbers;
      }
    }
  }

found_numbers:

  return 0;
}
/* print an integer digit-by-digit */
void print_number(int num)
{
  int digit;
  int digits = get_digits(num); 
  int power = get_power(digits);
  
  for (; digits > 0; digits--)
    {
      digit = num / power;
      print_char(digit + '0');
      num = num % power;
      power = power / 10;
    }
}
Example #19
0
File: address.c Project: ninux/mc
static int address_to_data(entry_ptr_t ent)
{
	int length;
	int offset;

	int son = get_digits(*(ent->data->number))+1;
	int soz = get_digits(*(ent->data->zipcode))+1;

	char nr[son];
	char zip[soz];

	offset = 5*(strlen(DATA_SEPARATOR)) + strlen(DATA_END);
	length = get_entry_length(ent) + offset;

	char line[length];
	_dbgmsg("reserved %i characters for the line", length);

	strcpy(line, ent->data->firstname);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->lastname);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->street);
	strcat(line, DATA_SEPARATOR);
	sprintf(nr, "%i", *(ent->data->number));
	strcat(line, nr);
	strcat(line, DATA_SEPARATOR);
	sprintf(zip, "%i", *(ent->data->zipcode));
	strcat(line, zip);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->city);
	strcat(line, DATA_END);

	_dbgmsg("created line \"%s\"", line);
	write_address(line);

	return 0;
}
static void get_microseconds(ulong *val, MYSQL_TIME_STATUS *status,
                             uint *number_of_fields,
                             const char **str, const char *end)
{
  const char *start= *str;
  uint tmp= 0; /* For the case '10:10:10.' */
  if (get_digits(&tmp, number_of_fields, str, end, 6))
    status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
  if ((status->precision= (*str - start)) < 6)
    *val= tmp * log_10_int[6 - (*str - start)];
  else
    *val= tmp;
  if (skip_digits(str, end))
    status->warnings|= MYSQL_TIME_NOTE_TRUNCATED;
}
Example #21
0
void show_alarm_time(uint8_t hour, uint8_t min, uint8_t sec)
{
	if (get_digits() == 8) {
		dots = 1<<2;
		uint8_t offset = 4;

		data[0] = 'A';
		data[1] = 'l';
		data[2] = 'r';
		data[3] = ' ';
		offset = print_digits(hour, offset);
		offset = print_digits(min, offset);		
	}
	else {
		show_time_setting(hour, min, 0);
	}
}
Example #22
0
int is_possible_prime_palindrome(int n) {
    // checks for palindrome and odd number of digits.
    int digits = get_digits(n);
    int i;
    if(digits % 2 == 0)
        return 0;
    else {
        for(i = digits-1; i> 0; i-=2) {
            if((n/(int)(pow(10,i))) != (n % 10)) {
                return 0;
            }
            n = n % (int)pow(10,i);
            n = n / 10;
        }
        return 1;
    }
}
/* takes an integer in parameter and prints it */
void print_number(int n)
{
  if (n < 0)
    {
      n = n * -1;
      print_char('-');
    }
  
  digits = get_digits(n);
  digitRetainer = digits;
  power = get_power();    

if (n == 0)
    {
      print_char('0');
    }
  else
    {
      print_digits(n);
    }
}
Example #24
0
void 
view_results_changed(int num){
	char newstr[50];
	char number[20];
	char *numstr;
	
	strlcpy (newstr, "Results:  ", sizeof(newstr));
	if (num > 30)
		strlcat(newstr, "> 50\n", sizeof(newstr));
	else {
		numstr = get_digits(num, number, 0); 
		strlcat(newstr, numstr, sizeof(newstr));
		strlcat(newstr, "\n", sizeof(newstr));
	};
	if (num_results_win.bg_color == DARK_GREY)
		num_results_win.bg_color = LIGHT_GREY;	
	else
		num_results_win.bg_color = DARK_GREY;	

	win_new_text(&num_results_win, newstr);	
};
Example #25
0
int is_ok(int n) {
  int digits[10];
  int digits2[10];
  get_digits(n, digits);
  get_digits(n*2, digits2);
  if (!compare_digits(digits, digits2)) return 0;
  get_digits(n*3, digits2);
  if (!compare_digits(digits, digits2)) return 0;
  get_digits(n*4, digits2);
  if (!compare_digits(digits, digits2)) return 0;
  get_digits(n*5, digits2);
  if (!compare_digits(digits, digits2)) return 0;
  get_digits(n*6, digits2);
  if (!compare_digits(digits, digits2)) return 0;
  return 1;
}
Example #26
0
void serialize_mpi(char *outbuf, int outlen, enum disp_format df, 
		   const gcry_mpi_t x)
{
  switch(df) {
  case DF_BIN: do {
      int len = (gcry_mpi_get_nbits(x) + 7) / 8;
      assert(len <= outlen);
      memset(outbuf, 0, outlen - len);
      gcry_mpi_print(GCRYMPI_FMT_USG, (unsigned char*)outbuf + (outlen - len), 
		     len, NULL, x);
    } while (0);
    break;
    
  case DF_COMPACT:
  case DF_BASE36: do {
    const char *digits = get_digits(df);
    unsigned int digit_count = get_digit_count(df);
    gcry_mpi_t base, Q, R;
    int i;
    base = gcry_mpi_set_ui(NULL, digit_count);
    Q = gcry_mpi_copy(x);
    R = gcry_mpi_snew(0);
    for(i = outlen - 1; i >= 0; i--) {
        unsigned char digit = 0;
        gcry_mpi_div(Q, R, Q, base, 0);        
        gcry_mpi_print(GCRYMPI_FMT_USG, &digit, 1, NULL, R);
        assert(digit < digit_count);
        outbuf[i] = digits[digit];
    }    
    assert(! gcry_mpi_cmp_ui(Q, 0));
    gcry_mpi_release(base);
    gcry_mpi_release(Q);
    gcry_mpi_release(R);
    } while(0);
    break;
  default: 
    assert(0);
  }
}
Example #27
0
static int
show_range_float (CmdConfig *cmd_config, CameraWidget *range)
{
#ifdef HAVE_CDK_20010421
	return (show_range_int (cmd_config, range));
#else
        CDKFSCALE *fscale = NULL;
        float value, min, max, increment;
        const char *label;
        char title[1024];
        float selection;

        CHECK (gp_widget_get_value (range, &value));
        CHECK (gp_widget_get_label (range, &label));
        snprintf (title, sizeof (title), "<C></5>%s", label);
        CHECK (gp_widget_get_range (range, &min, &max, &increment));

        fscale = newCDKFScale (cmd_config->screen, CENTER, CENTER, title,
                               _("Value: "), A_STANDOUT,
                               50, value, min, max,
                               increment, 
			       MAX (increment, (max - min) / 20.0),
			       get_digits (increment),
			       TRUE, FALSE);
        if (!fscale)
                return (GP_ERROR);

	selection = activateCDKFScale (fscale, 0);
        if (fscale->exitType == vNORMAL) {
		value = selection;
                gp_widget_set_value (range, &value);
                set_config (cmd_config);
        }

        destroyCDKFScale (fscale);
        return (GP_OK);
#endif
}
Example #28
0
UBYTE *tokenize_word(register UBYTE  *line,/* (in)	-> current line position   */
					 register UBYTE  *word,/* (in)	-> output token buffer	   */
					 UBYTE	*qstring,	   /* (in)	-> quoted string o/p buffer*/
					 SHORT	*plen,		   /* (out) # of bytes put in word buf */
					 SHORT	*ttype, 	   /* (out) token type				   */
					 Boolean quote		   /* (in)	preserve quotes on string? */
				   )
{
UBYTE	*wrkptr;
UBYTE	*sword = word;
int 	toklen;
SHORT	toktype;
register unsigned int c;
UBYTE	c1;
UBYTE	c2;

/*----------------------------------------------------------------------------
 * Skip leading whitespace, get the first character, return NULL if no char.
 *--------------------------------------------------------------------------*/

	while (isspace(*line) )
		++line;

	if ('\0' == (c = *line))
		{
		line = NULL;
		goto OUT;
		}

/*----------------------------------------------------------------------------
 * Handle keywords, types, symbols
 *--------------------------------------------------------------------------*/

	if (iscsymf(c))
		{
		line = po_chop_csym(line, word, MAX_SYM_LEN-1, &wrkptr);
		word = wrkptr;
		toktype = TOK_UNDEF;
		}
#ifdef DEADWOOD
	else if (iscsymf(c))
		{
		toktype = TOK_UNDEF;
		*word++ = c;
		++line;
		toklen = MAX_SYM_LEN;
		for (;;)
			{
			c = *line;
			if (iscsym(c))
				{
				++line;
				if (toklen)
					{
					*word++ = c;
					--toklen;
					}
				 }
			else
				break;
			}
		}

#endif /* DEADWOOD */

/*----------------------------------------------------------------------------
 * Handle numeric constants
 *--------------------------------------------------------------------------*/

	else if (isdigit(c))
		{
		toklen = get_digits(line,word,&toktype);
		line  += toklen;
		word  += toklen;
		}

/*----------------------------------------------------------------------------
 * Handle C operators and string/char constants...
 * This processes non-alphanumeric characters.	Most will be passed through
 * as single character tokens.	Some, like ==, !=, >= and <= are easier to
 * handle here than in parser (which only has a one-token look-ahead).
 * Also, quoted strings and chars are now handled in this switch statement.
 *--------------------------------------------------------------------------*/

	else
		{

		c1 = line[1];		/* lookahead characters */
		c2 = line[2];

		switch (c)
			{

			case '"':                       /* note: a shortcut in this loop */
											/* assumes that a quoted string  */
				if (qstring != NULL)		/* could never be longer than	 */
					sword = word = qstring; /* SZTOKE-3 chars.				 */
				toktype = TOK_QUO;
				if (quote)
					*word++ = '"';
				++line;
				toklen = SZTOKE-3; /* room for nullterm and two quotes */
				while(--toklen)
					{
					c = *line++;
					if (c == 0)
						break;
					else if (c == '\\')
						{
						if (quote)
							{
							*word++  = c;
							*word++ = *line++;
							}
						else
							{
							wrkptr = line;
							*word++ = translate_escape(&wrkptr);
							line = wrkptr;
							}
						}
					else if (c == '\"')
						{
						break;
						}
					else
						{
						*word++ = c;
						}
					}
				if (quote)
					*word++ = '"';
				break;

			case '\'':

				if (quote)
					*word++ = '\'';
				toktype = TOK_SQUO;
				++line;
				for (;;)
					{
					c = *line++;
					if (c == 0)
						break;
					else if (c == '\\')
						{
						if (quote)
							{
							*word++  = c;
							*word++ = *line++;
							}
						else
							{
							wrkptr = line;
							*word++ = translate_escape(&wrkptr);
							line = wrkptr;
							}
						}
					else if (c == '\'')
						{
						break;
						}
					else
						{
						*word++ = c;
						}
					}
				if (quote)
					*word++ = '\'';
				break;

			case '.':

				if (c1 == '.' && c2 == '.')
					{
					toktype = TOK_UNDEF;
					goto THREECHAR;
					}
				else
					goto SIMPLE;

			case '%':

				if (c1 == '=') /* mod-equals */
					{
					toktype = TOK_MOD_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '/':

				if (c1 == '=') /* div-equals */
					{
					toktype = TOK_DIV_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '*':

				if (c1 == '=')
					{
					toktype = TOK_MUL_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '+':

				if (c1 == '+')
					{
					toktype = TOK_PLUS_PLUS;
					goto TWOCHAR;
					}
				else if (c1 == '=')
					{
					toktype = TOK_PLUS_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '-':

				if (c1 == '-')
					{
					toktype = TOK_MINUS_MINUS;
					goto TWOCHAR;
					}
				else if (c1 == '=')
					{
					toktype = TOK_MINUS_EQUALS;
					goto TWOCHAR;
					}
				else if (c1 == '>')
					{
					toktype = TOK_ARROW;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '=':

				if (c1 == '=') /* double equals */
					{
					toktype = TOK_EQ;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '!':

				if (c1 == '=') /* != */
					{
					toktype = TOK_NE;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '<':

				if (c1 == '=') /* <= */
					{
					toktype = TOK_LE;
					goto TWOCHAR;
					}
				else if (c1 == '<')    /* << */
					{
					if (c2 == '=')
						{
						toktype = TOK_LSHIFT_EQUALS;
						goto THREECHAR;
						}
					else
						{
						toktype = TOK_LSHIFT;
						goto TWOCHAR;
						}
					}
				else
					goto SIMPLE;

			case '>':

				if (c1 == '=') /* >= */
					{
					toktype = TOK_GE;
					goto TWOCHAR;
					}
				else if (c1 == '>')    /* >> */
					{
					if (c2 == '=')
						{
						toktype = TOK_RSHIFT_EQUALS;
						goto THREECHAR;
						}
					else
						{
						toktype = TOK_RSHIFT;
						goto TWOCHAR;
						}
					}
				else
					goto SIMPLE;

			case '&':

				if (c1 == '&') /* logical and - && */
					{
					toktype = TOK_LAND;
					goto TWOCHAR;
					}
				else if (c1 == '=')
					{
					toktype = TOK_AND_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '|':

				if (c1 == '|') /* logical or - || */
					{
					toktype = TOK_LOR;
					goto TWOCHAR;
					}
				else if (c1 == '=')
					{
					toktype = TOK_OR_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;

			case '^':

				if (c1 == '=')
					{
					toktype = TOK_XOR_EQUALS;
					goto TWOCHAR;
					}
				else
					goto SIMPLE;
			default:
	SIMPLE:
				toktype = *word++ = c;
				++line;
				break;
			}
		}

OUT:

	*ttype = toktype;
	*word = 0;
	if (plen != NULL)
		*plen = word - sword;
	return line;


TWOCHAR:

	*word++ = c;
	*word++ = c1;
	line += 2;
	goto OUT;

THREECHAR:

	*word++ = c;
	*word++ = c1;
	*word++ = c2;
	line += 3;
	goto OUT;

}
my_bool
str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
                ulonglong flags, MYSQL_TIME_STATUS *status)
{
  const char *end=str+length, *pos;
  uint number_of_fields= 0, digits, year_length, not_zero_date;
  DBUG_ENTER("str_to_datetime");
  bzero(l_time, sizeof(*l_time));

  if (flags & TIME_TIME_ONLY)
  {
    my_bool ret= str_to_time(str, length, l_time, flags, status);
    DBUG_RETURN(ret);
  }

  my_time_status_init(status);

  /* Skip space at start */
  for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++)
    ;
  if (str == end || ! my_isdigit(&my_charset_latin1, *str))
  {
    status->warnings= MYSQL_TIME_WARN_TRUNCATED;
    l_time->time_type= MYSQL_TIMESTAMP_NONE;
    DBUG_RETURN(1);
  }

  /*
    Calculate number of digits in first part.
    If length= 8 or >= 14 then year is of format YYYY.
    (YYYY-MM-DD,  YYYYMMDD, YYYYYMMDDHHMMSS)
  */
  pos= str;
  digits= skip_digits(&pos, end);

  if (pos < end && *pos == 'T') /* YYYYYMMDDHHMMSSThhmmss is supported too */
  {
    pos++;
    digits+= skip_digits(&pos, end);
  }
  if (pos < end && *pos == '.' && digits >= 12) /* YYYYYMMDDHHMMSShhmmss.uuuuuu is supported too */
  {
    pos++;
    skip_digits(&pos, end); // ignore the return value
  }

  if (pos == end)
  {
    /*
      Found date in internal format
      (only numbers like [YY]YYMMDD[T][hhmmss[.uuuuuu]])
    */
    year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2;
    if (get_digits(&l_time->year, &number_of_fields, &str, end, year_length) 
        || get_digits(&l_time->month, &number_of_fields, &str, end, 2)
        || get_digits(&l_time->day, &number_of_fields, &str, end, 2)
        || get_maybe_T(&str, end)
        || get_digits(&l_time->hour, &number_of_fields, &str, end, 2)
        || get_digits(&l_time->minute, &number_of_fields, &str, end, 2)
        || get_digits(&l_time->second, &number_of_fields, &str, end, 2))
     status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
  }
  else
  {
    const char *start= str;
    if (get_number(&l_time->year, &number_of_fields, &str, end))
      status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
    year_length= str - start;

    if (!status->warnings &&
        (get_punct(&str, end)
         || get_number(&l_time->month, &number_of_fields, &str, end)
         || get_punct(&str, end)
         || get_number(&l_time->day, &number_of_fields, &str, end)
         || get_date_time_separator(&number_of_fields, flags, &str, end)
         || get_number(&l_time->hour, &number_of_fields, &str, end)
         || get_punct(&str, end)
         || get_number(&l_time->minute, &number_of_fields, &str, end)
         || get_punct(&str, end)
         || get_number(&l_time->second, &number_of_fields, &str, end)))
      status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
  }

  /* we're ok if date part is correct. even if the rest is truncated */
  if (number_of_fields < 3)
  {
    l_time->time_type= MYSQL_TIMESTAMP_NONE;
    status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
    DBUG_RETURN(TRUE);
  }

  if (!status->warnings && str < end && *str == '.')
  {
    str++;
    get_microseconds(&l_time->second_part, status,
                     &number_of_fields, &str, end);
  }

  not_zero_date = l_time->year || l_time->month || l_time->day ||
                  l_time->hour || l_time->minute || l_time->second ||
                  l_time->second_part;

  if (year_length == 2 && not_zero_date)
    l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900);

  if (l_time->year > 9999 || l_time->month > 12 || l_time->day > 31 ||
      l_time->hour > 23 || l_time->minute > 59 || l_time->second > 59)
  {
    status->warnings|= MYSQL_TIME_WARN_TRUNCATED;
    goto err;
  }

  if (check_date(l_time, not_zero_date, flags, &status->warnings))
    goto err;

  l_time->time_type= (number_of_fields <= 3 ?
                      MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME);

  for (; str != end ; str++)
  {
    if (!my_isspace(&my_charset_latin1,*str))
    {
      status->warnings= MYSQL_TIME_WARN_TRUNCATED;
      break;
    }
  }

  DBUG_RETURN(FALSE);

err:
  bzero((char*) l_time, sizeof(*l_time));
  l_time->time_type= MYSQL_TIMESTAMP_ERROR;
  DBUG_RETURN(TRUE);
}
Example #30
0
int main()
{
    binary_numbers[0]=(char*)"0111111";
    binary_numbers[1]=(char*)"0001010";
    binary_numbers[2]=(char*)"1011101";
    binary_numbers[3]=(char*)"1001111";
    binary_numbers[4]=(char*)"1101010";
    binary_numbers[5]=(char*)"1100111";
    binary_numbers[6]=(char*)"1110111";
    binary_numbers[7]=(char*)"0001011";
    binary_numbers[8]=(char*)"1111111";
    binary_numbers[9]=(char*)"1101011";
    build_arrays();
    //print_arrays();
    
    while(1)
    {
        char calc[CALC_SIZE];
        memset(calc,'\0',CALC_SIZE);
        scanf("%s",calc);
        if(strcmp(calc,"BYE")==0)
        {
            return 0;
        }
        char number1[CALC_SIZE];
        char number2[CALC_SIZE];
        memset(number1,'\0',CALC_SIZE);
        memset(number2,'\0',CALC_SIZE);
        int count=0;
        while(1)
        {
            char c = calc[count];
            if(c=='+')   
                break;    
            
            number1[count]=calc[count];           
            count++;
        }
        count++;
        int count_n=0;
        while(1){
            char c = calc[count]; 
            if(c=='=')   
               break;    
            number2[count_n]=calc[count];
            count_n++; count++;    
        }
        
        
        
        //printf("number1=%s, get_int(number1)=%d\n",number1, get_int(number1));
        //printf("number2=%s, get_int(number2)=%d\n",number2, get_int(number2));
        //printf("\n\n");

        int total=get_int(number1)+get_int(number2);
        printf("%s%s\n", calc, get_digits(total));
        
        
        //printf("number 1=%s number2=%s\n",number1, number2);       
               
               
    }
}