Пример #1
0
Файл: p008.c Проект: nunoi/euler
int get_product(int number)
{
    int i;
    int prod;

    prod = 1;
    for (i = 0; i < 5; i++) {
        int p;
        p = get_digit(number, i);
        prod = prod * p;
    }
    /*printf("digits %d - product %d\n", number, prod);*/
    return prod;
}
Пример #2
0
long double __octfloattofloattintpart(const char *buffer) {
  unsigned int c,i,pad ; /** c = exponent ; i = index ; (the string is reversed for pow(base,index)) */
  long double res ;
  pad=0 ;
  if ( buffer[0] == '-' ) {
    /** Case argument string is an negativ value we remember it for returning */
     pad=1 ;
   }
  res=0.0 ;
 
  for (c=0,i=strlen(buffer)-1; c < strlen(buffer)-pad ; c++,i--) {
    if ( ! c == 0 ) {
      res = res + (get_digit(buffer[i])*powl(8,c)) ; /** get the hexadecimal value from char */
    }
    else {
      /** Case for first digit */
      res = get_digit(buffer[i]) ; /** get the hexadecimal value from char */
    }
  }
 
 
  return res ;
 
}
Пример #3
0
int main(void)
{
	int a;

	printf("Ingrese entero positivo: ");
	scanf("%d", &a);

	if (a < 0) {
		printf("Error: el entero es negativo\n");
	}
	else {
		get_digit(a);
		printf("\n");
	}

	return 0;
}
Пример #4
0
int get_int(char * s)
{
    char n[CALC_SIZE];
    memset(n,'\0',CALC_SIZE);
    int k=0;
    for(int i=0; i<(strlen(s)); i+=3)
    {
        char ddd[4];
        ddd[0]=s[i];
        ddd[1]=s[i+1];
        ddd[2]=s[i+2];
        ddd[3]='\0';
        n[k]=(char)get_digit(ddd)+48;
        //printf("  ddd=%s\n",ddd);
        k++;
    }
    //printf("n=%s\n",n);
    return atoi(n);
}
Пример #5
0
bool is_dead_end(const board_t* board)
{
	size_t i, j;
	bool dead_end = false;
	for (i = 0; (i < NROWS) && (!dead_end); i++) {
		for (j = 0; (j < NCOLS) && (!dead_end); j++) {
			field_t value = get_digit(board, i, j);
			debugf("[%u,%u] == %d\n", i, j, value);
			if (EMPTY == value) {
				digits_t digits;
				count_digits(board, i, j, &digits);
				int n_possibilities = count_possibilities(&digits);
				if (0 == n_possibilities) {
					dead_end = true;
					debugf("[%lu,%lu] = %d, dead end\n", i, j, value);
				}
			}
		}
	}
	return dead_end;
}
Пример #6
0
/* Populate the hash table */
void fill_table ( char table[] )
{
	char ch;

	while ( get_digit ( &ch ) )
	{
		/* Create an index from the character */
		unsigned i = hash ( ch );

		if ( table[i] != 0 )
		{
			/* Duplicate indexes ae called collisions */
			printf ( "That index has been filled\n" );
		}
		else
		{
			/* The element is empty; fill it in */
			table[i] = ch;
		}
	}
}
Пример #7
0
unsigned char nav_datetime(unsigned char key)
{
   time_t t;
      switch (key)
      {
      case ENTER:
         t = mktime2(&tm4edit);
         /*
         if(t != -1)
         {
            tl = (unsigned long long)t * 1000;
            if(set_sys_time((uint64_t)tl) == 0)
            {
               char str[64];
               static struct tm tm1;
               t1 = sys_time();
               format_str(str, 64, "%ld, %llx, %llx", t, t1, tl);
               OLED_clrLine(4 * 9, 6 * 9);
               OLED_puts(0, 5 * 9, 0xff, font6x9, str);
               parse_time2(t, &tm1);
               format_str(str, 64, "%02u/%02u/%02u %02u:%02u:%02u", tm1.tm_mday, tm1.tm_mon + 1, getyear2(tm1.tm_year), tm1.tm_hour, tm1.tm_min,
                     tm1.tm_sec);
               OLED_puts(0, 4 * 9, 0xff, font6x9, str);
               //OLED_puts(0, 5 * 9, 0xff, font6x9, "set_sys_time failed");
               return 0;
            }
         }
         */
         set_sys_time((unsigned long long)t * 1000);
      case ESC:
         if (active.menu != &root_menu)
            active = *(--mstack_ptr);                // POP_MENU;
         set_statusbar_item(1, datime_prev_item, NULL);
         return MNU_CLR_ALL;
      default:
         (tm_edit.action)(get_digit(key));
         break;
      }
      return 0;
}
int main() {
    printf("Please enter a number in hex to convert to decimal: ");
    char line[BUFFER_SiZE];
    fgets(line, BUFFER_SiZE, stdin);

    size_t length = strlen(line);
    if (line[length - 1] == '\n') {
        line[length - 1] = '\0';
    }

    length = strlen(line);

    int i;
    long long sum = 0;
    for (i = length - 1; i >= 0; i--) {
        int coeff = get_digit(line[i]);
        sum += coeff * power(16, length - i - 1);
    }

    printf("%lld\n", sum);
    return 0;
}
Пример #9
0
int solve(int pos)
{
	if(pos == 1)
		return 1;
	int i, j, k = search_k(pos), mid;
	pos -= sk_sum[k-1];
	i = 1;
	j = k;
	while(i <= j)
	{
		mid = (i+j)/2;
		if(sk_len[mid] < pos)
			i = mid+1;
		else if(sk_len[mid] > pos)
			j = mid-1;
		else
		{
			i = mid;
			break;
		}
	}
	pos -= sk_len[i-1];
	return get_digit(i, pos);
}
Пример #10
0
/*
 * Handling keys.As we need to be a 'special mode', we have to do it ourselves
 * We cannot reuse the normal main loop code
 */
static void process_stopwatch_key(int key) {
	int max_registers=global_regs();
	switch(key)	{
			case STOPWATCH_RS: {
				toggle_running();
				break;
			}
			case STOPWATCH_EXIT: {
				KeyCallback=(int(*)(int))NULL;
				break;
			}
			case STOPWATCH_CLEAR: {
				if(StopWatchStatus.running)	{
					if(TotalFirstTicker==0) {
						TotalFirstTicker=FirstTicker;
					}
					FirstTicker=getTicker();
				} else {
					TotalFirstTicker=0;
					FirstTicker=0;
				}
				StopWatch=0;
				break;
			   }
			case STOPWATCH_EEX: {
				StopWatchStatus.display_tenths=!StopWatchStatus.display_tenths;
				break;
				}
			case STOPWATCH_STORE: {
				store_stopwatch_in_memory();
				break;
				}
			case STOPWATCH_STORE_ROUND: {
				store_stopwatch_in_memory();
				if(TotalFirstTicker==0) {
					TotalFirstTicker=FirstTicker;
				}
				FirstTicker=getTicker();
				break;
				}
			case STOPWATCH_SIGMA_PLUS_STORE_ROUND: {
				store_stopwatch_in_memory();
				stopwatch_sigma_plus();
				break;
			}
			case STOPWATCH_SIGMA_PLUS: {
				stopwatch_sigma_plus();
				break;
			}
			case STOPWATCH_UP: {
				if(StopWatchMemory<max_registers-1) {
					StopWatchMemory++;
				}
				break;
				}
			case STOPWATCH_DOWN: {
				if(StopWatchMemory>0) {
					StopWatchMemory--;
				}
				break;
				}
			case STOPWATCH_SHOW_MEMORY: {
				StopWatchStatus.show_memory=!StopWatchStatus.show_memory;
				break;
				}
			case STOPWATCH_RCL: {
				StopWatchStatus.rcl_mode=max_registers>0;
				StopWatchStatus.sigma_display_mode=0;
				StopWatchMemoryFirstDigit=-1;
				break;
				}
			default: {
				if (get_digit(key) >= 0) {
					//Digits
					StopWatchStatus.select_memory_mode=1;
					StopWatchMemoryFirstDigit=-1;
					StopWatchStatus.show_memory=1;
					process_select_memory_key(key);
				}
				break;
			  }
			}
}
Пример #11
0
 int BigInt::operator[](unsigned int position) {
   return get_digit(position);
 }
Пример #12
0
void njd_set_digit(NJD * njd)
{
   int i, j;
   NJDNode *s = NULL;
   NJDNode *e = NULL;
   NJDNode *node;
   int find = 0;

   /* convert digit sequence */
   for (node = njd->head; node != NULL; node = node->next) {
      if (find == 0 && strcmp(NJDNode_get_pos_group1(node), NJD_SET_DIGIT_KAZU) == 0)
         find = 1;
      if (get_digit(node, 1) >= 0) {
         if (s == NULL)
            s = node;
         if (node == njd->tail)
            e = node;
      } else {
         if (s != NULL)
            e = node->prev;
      }
      if (s != NULL && e != NULL) {
         convert_digit_sequence(s, e);
         s = e = NULL;
      }
   }
   if (find == 0)
      return;
   NJD_remove_silent_node(njd);
   if (njd->head == NULL)
      return;

   for (node = njd->head->next; node != NULL && node->next != NULL; node = node->next) {
      if (strcmp(NJDNode_get_string(node), "*") != 0
          && strcmp(NJDNode_get_string(node->prev), "*") != 0
          && (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_TEN1) == 0
              || strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_TEN2) == 0)
          && strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_DIGIT_KAZU) == 0
          && strcmp(NJDNode_get_pos_group1(node->next), NJD_SET_DIGIT_KAZU) == 0) {
         NJDNode_load(node, NJD_SET_DIGIT_TEN_FEATURE);
         NJDNode_set_chain_flag(node, 1);
         if (strcmp(NJDNode_get_string(node->prev), NJD_SET_DIGIT_ZERO1) == 0
             || strcmp(NJDNode_get_string(node->prev), NJD_SET_DIGIT_ZERO2) == 0) {
            NJDNode_set_pron(node->prev, NJD_SET_DIGIT_ZERO_BEFORE_DP);
            NJDNode_set_mora_size(node->prev, 2);
         } else if (strcmp(NJDNode_get_string(node->prev), NJD_SET_DIGIT_TWO) == 0) {
            NJDNode_set_pron(node->prev, NJD_SET_DIGIT_TWO_BEFORE_DP);
            NJDNode_set_mora_size(node->prev, 2);
         } else if (strcmp(NJDNode_get_string(node->prev), NJD_SET_DIGIT_FIVE) == 0) {
            NJDNode_set_pron(node->prev, NJD_SET_DIGIT_FIVE_BEFORE_DP);
            NJDNode_set_mora_size(node->prev, 2);
         }
      }
   }

   for (node = njd->head->next; node != NULL; node = node->next) {
      if (strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_DIGIT_KAZU) == 0) {
         if (strcmp(NJDNode_get_pos_group2(node), NJD_SET_DIGIT_JOSUUSHI) == 0
             || strcmp(NJDNode_get_pos_group1(node), NJD_SET_DIGIT_FUKUSHIKANOU) == 0) {
            /* convert digit pron */
            if (search_numerative_class(njd_set_digit_rule_numerative_class1b, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1b, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1c1, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1c1, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1c2, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1c2, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1d, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1d, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1e, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1e, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1f, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1f, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1g, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1g, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1h, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1h, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1i, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1i, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1j, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1j, node->prev);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class1k, node) == 1)
               convert_digit_pron(njd_set_digit_rule_conv_table1k, node->prev);
            /* convert numerative pron */
            if (search_numerative_class(njd_set_digit_rule_numerative_class2b, node) == 1)
               convert_numerative_pron(njd_set_digit_rule_conv_table2b, node->prev, node);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class2c, node) == 1)
               convert_numerative_pron(njd_set_digit_rule_conv_table2c, node->prev, node);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class2d, node) == 1)
               convert_numerative_pron(njd_set_digit_rule_conv_table2d, node->prev, node);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class2e, node) == 1)
               convert_numerative_pron(njd_set_digit_rule_conv_table2e, node->prev, node);
            else if (search_numerative_class(njd_set_digit_rule_numerative_class2f, node) == 1)
               convert_numerative_pron(njd_set_digit_rule_conv_table2f, node->prev, node);
            /* modify accent phrase */
            NJDNode_set_chain_flag(node->prev, 0);
            NJDNode_set_chain_flag(node, 1);
         }
      }
   }

   for (node = njd->head->next; node != NULL; node = node->next) {
      if (strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_DIGIT_KAZU) == 0) {
         if (strcmp(NJDNode_get_pos_group1(node), NJD_SET_DIGIT_KAZU) == 0
             && NJDNode_get_string(node->prev) != NULL && NJDNode_get_string(node) != NULL) {
            /* modify accent phrase */
            find = 0;
            for (i = 0; njd_set_digit_rule_numeral_list4[i] != NULL; i++) {
               if (strcmp(NJDNode_get_string(node->prev), njd_set_digit_rule_numeral_list4[i]) == 0) {
                  for (j = 0; njd_set_digit_rule_numeral_list5[j] != NULL; j++) {
                     if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_numeral_list5[j]) == 0) {
                        NJDNode_set_chain_flag(node->prev, 0);
                        NJDNode_set_chain_flag(node, 1);
                        find = 1;
                        break;
                     }
                  }
                  break;
               }
            }
            if (find == 0) {
               for (i = 0; njd_set_digit_rule_numeral_list5[i] != NULL; i++) {
                  if (strcmp(NJDNode_get_string(node->prev), njd_set_digit_rule_numeral_list5[i]) ==
                      0) {
                     for (j = 0; njd_set_digit_rule_numeral_list4[j] != NULL; j++) {
                        if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_numeral_list4[j]) ==
                            0) {
                           NJDNode_set_chain_flag(node, 0);
                           break;
                        }
                     }
                     break;
                  }
               }
            }
         }
         if (search_numerative_class(njd_set_digit_rule_numeral_list8, node) == 1)
            convert_digit_pron(njd_set_digit_rule_numeral_list9, node->prev);
         if (search_numerative_class(njd_set_digit_rule_numeral_list10, node) == 1)
            convert_digit_pron(njd_set_digit_rule_numeral_list11, node->prev);
         if (search_numerative_class(njd_set_digit_rule_numeral_list6, node) == 1)
            convert_numerative_pron(njd_set_digit_rule_numeral_list7, node->prev, node);
      }
   }

   for (node = njd->head; node != NULL; node = node->next) {
      if (node->next != NULL &&
          strcmp(NJDNode_get_string(node->next), "*") != 0 &&
          strcmp(NJDNode_get_pos_group1(node), NJD_SET_DIGIT_KAZU) == 0 &&
          (node->prev == NULL
           || strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_DIGIT_KAZU) != 0)
          && (strcmp(NJDNode_get_pos_group2(node->next), NJD_SET_DIGIT_JOSUUSHI) == 0
              || strcmp(NJDNode_get_pos_group1(node->next), NJD_SET_DIGIT_FUKUSHIKANOU) == 0)) {
         /* convert class3 */
         for (i = 0; njd_set_digit_rule_numerative_class3[i] != NULL; i += 2) {
            if (strcmp(NJDNode_get_string(node->next), njd_set_digit_rule_numerative_class3[i]) == 0
                && strcmp(NJDNode_get_read(node->next),
                          njd_set_digit_rule_numerative_class3[i + 1]) == 0) {
               for (j = 0; njd_set_digit_rule_conv_table3[j] != NULL; j += 4) {
                  if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_conv_table3[j]) == 0) {
                     NJDNode_set_read(node, (char *) njd_set_digit_rule_conv_table3[j + 1]);
                     NJDNode_set_pron(node, (char *) njd_set_digit_rule_conv_table3[j + 1]);
                     NJDNode_set_acc(node, atoi(njd_set_digit_rule_conv_table3[j + 2]));
                     NJDNode_set_mora_size(node, atoi(njd_set_digit_rule_conv_table3[j + 3]));
                     break;
                  }
               }
               break;
            }
         }
         /* person */
         if (strcmp(NJDNode_get_string(node->next), NJD_SET_DIGIT_NIN) == 0) {
            for (i = 0; njd_set_digit_rule_conv_table4[i] != NULL; i += 2) {
               if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_conv_table4[i]) == 0) {
                  NJDNode_load(node, (char *) njd_set_digit_rule_conv_table4[i + 1]);
                  NJDNode_set_pron(node->next, NULL);
                  break;
               }
            }
         }
         /* the day of month */
         if (strcmp(NJDNode_get_string(node->next), NJD_SET_DIGIT_NICHI) == 0
             && strcmp(NJDNode_get_string(node), "*") != 0) {
            if (node->prev != NULL
                && strstr(NJDNode_get_string(node->prev), NJD_SET_DIGIT_GATSU) != NULL
                && strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_ONE) == 0) {
               NJDNode_load(node, NJD_SET_DIGIT_TSUITACHI);
               NJDNode_set_pron(node->next, NULL);
            } else {
               for (i = 0; njd_set_digit_rule_conv_table5[i] != NULL; i += 2) {
                  if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_conv_table5[i]) == 0) {
                     NJDNode_load(node, (char *) njd_set_digit_rule_conv_table5[i + 1]);
                     NJDNode_set_pron(node->next, NULL);
                     break;
                  }
               }
            }
         } else if (strcmp(NJDNode_get_string(node->next), NJD_SET_DIGIT_NICHIKAN) == 0) {
            for (i = 0; njd_set_digit_rule_conv_table6[i] != NULL; i += 2) {
               if (strcmp(NJDNode_get_string(node), njd_set_digit_rule_conv_table6[i]) == 0) {
                  NJDNode_load(node, (char *) njd_set_digit_rule_conv_table6[i + 1]);
                  NJDNode_set_pron(node->next, NULL);
                  break;
               }
            }
         }
      }
   }

   for (node = njd->head; node != NULL; node = node->next) {
      if ((node->prev == NULL
           || strcmp(NJDNode_get_pos_group1(node->prev), NJD_SET_DIGIT_KAZU) != 0)
          && node->next != NULL && node->next->next != NULL) {
         if (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_TEN) == 0
             && strcmp(NJDNode_get_string(node->next), NJD_SET_DIGIT_FOUR) == 0) {
            if (strcmp(NJDNode_get_string(node->next->next), NJD_SET_DIGIT_NICHI) == 0) {
               NJDNode_load(node, NJD_SET_DIGIT_JUYOKKA);
               NJDNode_set_pron(node->next, NULL);
               NJDNode_set_pron(node->next->next, NULL);
            } else if (strcmp(NJDNode_get_string(node->next->next), NJD_SET_DIGIT_NICHIKAN) == 0) {
               NJDNode_load(node, NJD_SET_DIGIT_JUYOKKAKAN);
               NJDNode_set_pron(node->next, NULL);
               NJDNode_set_pron(node->next->next, NULL);
            }
         } else if (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_TWO) == 0
                    && strcmp(NJDNode_get_string(node->next), NJD_SET_DIGIT_TEN) == 0) {
            if (strcmp(NJDNode_get_string(node->next->next), NJD_SET_DIGIT_NICHI) == 0) {
               NJDNode_load(node, NJD_SET_DITIT_HATSUKA);
               NJDNode_set_pron(node->next, NULL);
               NJDNode_set_pron(node->next->next, NULL);
            } else if (strcmp(NJDNode_get_string(node->next->next), NJD_SET_DIGIT_NICHIKAN) == 0) {
               NJDNode_load(node, NJD_SET_DIGIT_HATSUKAKAN);
               NJDNode_set_pron(node->next, NULL);
               NJDNode_set_pron(node->next->next, NULL);
            } else if (strcmp(NJDNode_get_string(node->next->next), NJD_SET_DIGIT_FOUR) == 0
                       && node->next->next->next != NULL) {
               if (strcmp(NJDNode_get_string(node->next->next->next), NJD_SET_DIGIT_NICHI) == 0) {
                  NJDNode_load(node, NJD_SET_DIGIT_NIJU);
                  NJDNode_load(node->next, NJD_SET_DITIT_YOKKA);
                  NJDNode_set_pron(node->next->next, NULL);
                  NJDNode_set_pron(node->next->next->next, NULL);
               } else if (strcmp(NJDNode_get_string(node->next->next->next), NJD_SET_DIGIT_NICHIKAN)
                          == 0) {
                  NJDNode_load(node, NJD_SET_DIGIT_NIJU);
                  NJDNode_load(node->next, NJD_SET_DIGIT_YOKKAKAN);
                  NJDNode_set_pron(node->next->next, NULL);
                  NJDNode_set_pron(node->next->next->next, NULL);
               }
            }
         }
      }
   }

   NJD_remove_silent_node(njd);
   if (njd->head == NULL)
      return;
}
Пример #13
0
static void convert_digit_sequence(NJDNode * start, NJDNode * end)
{
   NJDNode *node;
   NJDNode *newnode;
   int digit;
   int place = 0;
   int index;
   int size = 0;
   int have = 0;

   for (node = start; node != end->next; node = node->next)
      size++;
   if (size <= 1)
      return;

   if (get_digit_sequence_score(start, end) < 0) {
      for (node = start, size = 0; node != end->next; node = node->next) {
         if (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_ZERO1) == 0
             || strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_ZERO2) == 0) {
            NJDNode_set_pron(node, NJD_SET_DIGIT_ZERO_AFTER_DP);
            NJDNode_set_mora_size(node, 2);
         } else if (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_TWO) == 0) {
            NJDNode_set_pron(node, NJD_SET_DIGIT_TWO_AFTER_DP);
            NJDNode_set_mora_size(node, 2);
         } else if (strcmp(NJDNode_get_string(node), NJD_SET_DIGIT_FIVE) == 0) {
            NJDNode_set_pron(node, NJD_SET_DIGIT_FIVE_AFTER_DP);
            NJDNode_set_mora_size(node, 2);
         }
         NJDNode_set_chain_rule(node, NULL);
         if (size % 2 == 0) {
            NJDNode_set_chain_flag(node, 0);
         } else {
            NJDNode_set_chain_flag(node, 1);
            NJDNode_set_acc(node->prev, 3);
         }
         size++;
      }
      return;
   }

   index = size % 4;
   if (index == 0)
      index = 4;
   if (size > index)
      place = (size - index) / 4;
   index--;
   if (place > 17)
      return;

   for (node = start; node != end->next; node = node->next) {
      digit = get_digit(node, 0);
      if (index == 0) {
         if (digit == 0) {
            NJDNode_set_pron(node, NULL);
            NJDNode_set_acc(node, 0);
            NJDNode_set_mora_size(node, 0);
         } else {
            have = 1;
         }
         if (have == 1) {
            if (place > 0) {
               newnode = (NJDNode *) calloc(1, sizeof(NJDNode));
               NJDNode_initialize(newnode);
               NJDNode_load(newnode, (char *) njd_set_digit_rule_numeral_list3[place]);
               node = NJDNode_insert(node, node->next, newnode);
            }
            have = 0;
         }
         place--;
      } else {
         if (digit <= 1) {
            NJDNode_set_pron(node, NULL);
            NJDNode_set_acc(node, 0);
            NJDNode_set_mora_size(node, 0);
         }
         if (digit > 0) {
            newnode = (NJDNode *) calloc(1, sizeof(NJDNode));
            NJDNode_initialize(newnode);
            NJDNode_load(newnode, (char *) njd_set_digit_rule_numeral_list2[index]);
            node = NJDNode_insert(node, node->next, newnode);
            have = 1;
         }
      }
      index--;
      if (index < 0)
         index = 4 - 1;
   }
}
Пример #14
0
static void convert_digit_sequence(NJDNode * start, NJDNode * end)
{
   NJDNode *node;
   NJDNode *newnode;
   int digit;
   int place = 0;
   int index;
   int size = 0;
   int have = 0;

   if (get_digit_sequence_score(start, end) < 0)
      return;

   for (node = start; node != end->next; node = node->next)
      size++;
   if (size <= 1)
      return;
   index = size % 4;
   if (index == 0)
      index = 4;
   if (size > index)
      place = (size - index) / 4;
   index--;
   if (place > 17)
      return;

   for (node = start; node != end->next; node = node->next) {
      digit = get_digit(node, 0);
      if (index == 0) {
         if (digit == 0) {
            NJDNode_set_pron(node, NULL);
            NJDNode_set_acc(node, 0);
            NJDNode_set_mora_size(node, 0);
         } else {
            have = 1;
         }
         if (have == 1) {
            if (place > 0) {
               newnode = (NJDNode *) calloc(1, sizeof(NJDNode));
               NJDNode_initialize(newnode);
               NJDNode_load(newnode, (char *) njd_set_digit_rule_numeral_list3[place]);
               node = NJDNode_insert(node, node->next, newnode);
            }
            have = 0;
         }
         place--;
      } else {
         if (digit <= 1) {
            NJDNode_set_pron(node, NULL);
            NJDNode_set_acc(node, 0);
            NJDNode_set_mora_size(node, 0);
         }
         if (digit > 0) {
            newnode = (NJDNode *) calloc(1, sizeof(NJDNode));
            NJDNode_initialize(newnode);
            NJDNode_load(newnode, (char *) njd_set_digit_rule_numeral_list2[index]);
            node = NJDNode_insert(node, node->next, newnode);
            have = 1;
         }
      }
      index--;
      if (index < 0)
         index = 4 - 1;
   }
}
Пример #15
0
void put_cmd(vararray* binary, line_t* cur_line, int j, vararray* labels, vararray* funcs, int step) {
    int i = j, argc = 0, to_push = 0, pos = 0;
    char cmd_num = 0;

    char* keyword = cur_line->words[j];
    char modif[4], words[2][MAX_WORD_LENGTH];
    memset(modif, 0, sizeof(modif));
    memset(words, 0, sizeof(words));

    for (i = j+1; i < cur_line->num; (argc++, i++)) {
        DBGPRINT("1/Argument %d: %s\n", 0, words[0]);//What's this debugoutput tell you?
        strcpy(words[argc], cur_line->words[i]);
        DBGPRINT("2/Argument %d: %s\n", 0, words[0]);
        DBGPRINT("Argument %d: %s\n", argc, words[argc]);//QUESTION: Why you repeat the same dbgoutput here
        modif[argc] = get_modif(words[argc]);
        DBGPRINT("Argument %d: %s\n", 0, words[0]);// and here?
    }

    DBGPRINT("Argument %d: %s\n", 0, words[0]);
    DBGPRINT("Pre-define: Number: %d, keyword: \"%s\" MODIF: \"%s\" argc: %d\n", cmd_num, keyword, modif, argc);

#define CMD_(number_, keyword_, argc_, modif_, code_)\
    if ((!strcmp(keyword, #keyword_)) && (modif_cmp(modif, modif_)) && (argc_ == argc)) {\
        strcpy(modif, modif_);\
        cmd_num = number_;\
    } else

#include "../s_common/s_cmdlist.h"

#undef CMD_
    USERERR("No command found for \"%s\"\n", cur_line->words[0]);


    DBGPRINT("Number: %d, keyword: \"%s\" MODIF: \"%s\" argc: %d\n", cmd_num, keyword, modif, argc);
    pos = binary->nmax;//QUESTION: What's purpose of it?

    var_push(binary, &cmd_num);
    for (i = 0; i < argc; i++) {
        switch (modif[i]) {
        case 'r': {
            DBGPRINT("Call of get_reg_num.\n");
            to_push = get_reg_num(words[i]);
            break;
        }
        case 'n': {
            to_push = get_digit(words[i]);
            break;
        }
        case 'f': {
            to_push = get_lf(words[i], funcs, pos, step);
            break;
        }
        case 'l': {
            to_push = get_lf(words[i], labels, pos, step);
            break;
        }

        default: {
            FATALERR("Modif failure. Act_modif: %s\n", modif);//I think it's debug error. User shouldn't know it
            break;
        }
        }
        DBGPRINT("ARGUMENT %d: %d\n", i, to_push);
        var_pushn(binary, &to_push, sizeof(int));
    }

    DBGPRINT("Num of elems in bin: %d;\n"\
             "-----------------------------\n", (int)binary->nmax);
}
Пример #16
0
void
printnumber(FILE *f, const struct number *b, u_int base)
{
	struct number	*int_part, *fract_part;
	int		digits;
	char		buf[11];
	size_t		sz;
	int		i;
	struct stack	stack;
	char		*p;

	charcount = 0;
	lastchar = -1;
	if (BN_is_zero(b->number))
		putcharwrap(f, '0');

	int_part = new_number();
	fract_part = new_number();
	fract_part->scale = b->scale;

	if (base <= 16)
		digits = 1;
	else {
		digits = snprintf(buf, sizeof(buf), "%u", base-1);
	}
	split_number(b, int_part->number, fract_part->number);

	i = 0;
	stack_init(&stack);
	while (!BN_is_zero(int_part->number)) {
		BN_ULONG rem = BN_div_word(int_part->number, base);
		stack_pushstring(&stack, get_digit(rem, digits, base));
		i++;
	}
	sz = i;
	if (BN_cmp(b->number, &zero) < 0)
		putcharwrap(f, '-');
	for (i = 0; i < sz; i++) {
		p = stack_popstring(&stack);
		if (base > 16)
			putcharwrap(f, ' ');
		printwrap(f, p);
		free(p);
	}
	stack_clear(&stack);
	if (b->scale > 0) {
		struct number	*num_base;
		BIGNUM		mult, stop;

		putcharwrap(f, '.');
		num_base = new_number();
		BN_set_word(num_base->number, base);
		BN_init(&mult);
		BN_one(&mult);
		BN_init(&stop);
		BN_one(&stop);
		scale_number(&stop, b->scale);

		i = 0;
		while (BN_cmp(&mult, &stop) < 0) {
			u_long	rem;

			if (i && base > 16)
				putcharwrap(f, ' ');
			i = 1;

			bmul_number(fract_part, fract_part, num_base);
			split_number(fract_part, int_part->number, NULL);
			rem = BN_get_word(int_part->number);
			p = get_digit(rem, digits, base);
			int_part->scale = 0;
			normalize(int_part, fract_part->scale);
			BN_sub(fract_part->number, fract_part->number,
			    int_part->number);
			printwrap(f, p);
			free(p);
			BN_mul_word(&mult, base);
		}
		free_number(num_base);
		BN_free(&mult);
		BN_free(&stop);
	}
	flushwrap(f);
	free_number(int_part);
	free_number(fract_part);
}
Пример #17
0
 digit_t operator[](std::size_t i) const { return get_digit(i); }
Пример #18
0
long double octfloattofloat(const char *float_string) {
  /* Convert an octal string from the given pointer in an float value ;
   ********************************************************************/
 
  if (float_string == NULL) {
    /** Invalid argument **/
    fprintf(stderr,"%s %s\n",__func__,strerror(EINVAL)) ;
    exit(EXIT_FAILURE) ;
  }
 
  if ( ! is_string_oct(float_string,true) ) {
    /** Invalid argument **/
    fprintf(stderr,"%s %s\n",__func__,strerror(EINVAL)) ;
    exit(EXIT_FAILURE) ;
  }
 
  if ( strchr(float_string,'.') == NULL) {
    /** Case argument string is not a float, return integer value (long double) cast */
    return __octfloattofloattintpart(float_string) ;
  }
  char *oct_float_str_saved=strdup(float_string) ;
  _Bool is_negativ=false ;
  if ( float_string[0] == '-' ) {
    /** Case argument string is an negativ value we remember it for returning */
    is_negativ=true ;
    int i,c ;
     for (i=1,c=0 ; i < (int) strlen(float_string) ; i++,c++) {
       oct_float_str_saved[c]=float_string[i] ;
     }
     oct_float_str_saved[c]='\0' ;
  }
  else {
    oct_float_str_saved=strdup(float_string) ;
  }
 
  /** variables for splitting in integer and float part */
 
  char *oct_int_part=malloc(64) ;
  char *oct_float_part=malloc(64) ;
  memset(oct_int_part,'\0',64) ;
  memset(oct_float_part,'\0',64) ;
 
  /** Perform splitting for getting float part we are interest */
  splitter(oct_float_str_saved,oct_int_part,oct_float_part) ;
 
  long double res_int = __octfloattofloattintpart(oct_int_part) ; /** value to return for the integer part */
 
  unsigned int c  ;           /** float part index */
  int cc ;                    /** float exponent value */
  long double res_float=0.0 ; /** variable for computing float part */
 
  for(c=0 ,cc=-1 ; c < (unsigned int) strlen(oct_float_part) ; c++,cc--) {
    res_float += (long double) get_digit(oct_float_part[c]) * powl(8,cc) ;
  }
 
  free(oct_int_part) ;
  free(oct_float_part) ;
  free(oct_float_str_saved) ;
 
  if ( is_negativ ) {
     return - (long double) (res_int + res_float) ;
   }
   else {
     return (long double) res_int + res_float ;
   }
}
Пример #19
0
static SANE_Byte
get_byte (Wire *w)
{
  return get_digit (w) << 4 | get_digit (w);
}