Esempio n. 1
0
cassys_tokens_list *cassys_load_text(const char *tokens_text_name, const char *text_cod_name, struct text_tokens **tokens){

	int mask_encoding_compatibility_input = DEFAULT_MASK_ENCODING_COMPATIBILITY_INPUT;

	*tokens = load_text_tokens(tokens_text_name,mask_encoding_compatibility_input);

	U_FILE *f = u_fopen(BINARY, text_cod_name,U_READ);
	if( f == NULL){
		perror("fopen\n");
		fprintf(stderr,"Cannot open file  %s\n",text_cod_name);
		exit(1);
	}

	cassys_tokens_list *list = NULL;
	cassys_tokens_list *temp = list;

	int token_id;
	int char_read = (int)fread(&token_id,sizeof(int),1,f);
	while(char_read ==1){
		if(list==NULL){
			list = new_element((*tokens)->token[token_id],0);
			temp = list;
		}
		else {
			temp ->next_token = new_element((*tokens)->token[token_id],0);
			temp = temp -> next_token;
		}

		char_read = (int)fread(&token_id,sizeof(int),1,f);
	}
	u_fclose(f);

	return list;
}
Esempio n. 2
0
// init routine to reset variables
void tetris::init(){
	// clear area
	for(unsigned int i=0;i<sizeof(area)/sizeof(area[0]);i++){
		area[i]=0b0000000000000000;
	};
	// reset vars
	lines=0;
	last_update=millis();
	time_between_steps=999;
	you_loose=false;
	// load last element
	new_element();
	// load this element
	new_element();
	pSpeedo->reset_bak();
};
Esempio n. 3
0
/* Process the destination of the menu entry, and start a menu entry 
   description.  */
ELEMENT *
enter_menu_entry_node (ELEMENT *current)
{
  ELEMENT *description, *preformatted;

  description = new_element (ET_menu_entry_description);
  add_to_element_args (current, description);
  register_extra_menu_entry_information (current);
  current->line_nr = line_nr;
  current = description;

  preformatted = new_element (ET_preformatted);
  add_to_element_contents (current, preformatted);
  current = preformatted;
  push_context (ct_preformatted);
  return current;
}
Esempio n. 4
0
/* 835 */
ELEMENT *
parse_texi_file (char *filename)
{
  char *linep, *line = 0;
  ELEMENT *root = new_element (ET_text_root);
  ELEMENT *preamble = 0;

  input_push_file (filename);

  /* Check for preamble. */
  do
    {
      ELEMENT *l;

      /* FIXME: _next_text isn't used in Perl. */
      line = next_text ();
      if (!line)
        abort (); /* Empty file? */

      linep = line; 
      linep += strspn (linep, whitespace_chars);
      if (*linep && !looking_at (linep, "\\input"))
        {
          /* This line is not part of the preamble.  Shove back
             into input stream. */
          input_push_text (line);
          break;
        }

      if (!preamble)
        preamble = new_element (ET_preamble);

      l = new_element (ET_preamble_text);
      text_append (&l->text, line);
      add_to_element_contents (preamble, l);
    }
  while (1);

  if (preamble)
    add_to_element_contents (root, preamble);

  root = parse_texi (root);
  return root;
} /* 916 */
Esempio n. 5
0
void JsonDb::SetArray(TransactionHandle &transaction, std::string const &path, size_t total_elements, bool create_if_not_exists)
{
	ValueArray::Type elements(total_elements);
	for(ValueArray::Type::iterator i = elements.begin(); i != elements.end(); ++i)
	{
		ValuePointer new_element(new ValueNull(transaction->GenerateKey()));
		*i = new_element->GetKey();
		transaction->Store(new_element->GetKey(), new_element);
	}

	Set(transaction, path, ValuePointer(new ValueArray(null_key, elements)), create_if_not_exists);
}
Esempio n. 6
0
int main()
{
    list* init = NULL;
    
    // On a list you add elements on one side 
    enqueue(&init, new_element(21));
    enqueue(&init, new_element(39));
    enqueue(&init, new_element(7));
    enqueue(&init, new_element(90));

    print_list(init);
    
    // ... and remove the element on the opposite side
    list* removed = dequeue(&init);
    printf("\nREMOVED ELEMENT: %d", removed->id);
    free(removed);

    removed = dequeue(&init);
    printf("\nREMOVED ELEMENT: %d", removed->id);
    free(removed);

    return 0;
}
Esempio n. 7
0
/* Pushes a string str onto stack s
 * Input: An existing stack to push onto
 * 	  A preallocated and properly formed string.
 * Output: 0 if success
 * 	   1 if failure
 * Errors: if s is NULL or if new element creation fails, push cannot complete
 */
int push(Stack s, char *str)
{
	int result = 0;

	if(s == NULL) /* fail early */
	{
		return 1;
	}

	if(s->tail == NULL)
	{
		/* if there is no tail, this element will be it.
		   populate it with str, and
		   set its prev and next to NULL
		*/
		result = new_element(&(s->tail), str, NULL, NULL);
	}
	else
	{
		/* insert new element at tail->next,
		   populate it with str, and
		   set prev to tail, next to NULL
		*/
		result = new_element(&(s->tail->next), str, s->tail, NULL);
		s->tail = s->tail->next;
	}

	if(result == 1) /* if create failed */
	{
		return 1;
	}

	/* increment # of elements */
	(s->size)++; 

	return 0;
}
Esempio n. 8
0
void
start_empty_line_after_command (ELEMENT *current, char **line_inout)
{
  char *line = *line_inout;
  ELEMENT *e;
  int len;

  len = strspn (line, whitespace_chars_except_newline);
  e = new_element (ET_empty_line_after_command);
  add_to_element_contents (current, e);
  text_append_n (&e->text, line, len);
  line += len;

  *line_inout = line;
}
Esempio n. 9
0
int
sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
{
  sandbox_cfg_t *elem = NULL;

  elem = new_element(SCMP_SYS(openat), file);
  if (!elem) {
    log_err(LD_BUG,"(Sandbox) failed to register parameter!");
    return -1;
  }

  elem->next = *cfg;
  *cfg = elem;

  return 0;
}
Esempio n. 10
0
int
sandbox_cfg_allow_execve(sandbox_cfg_t **cfg, const char *com)
{
  sandbox_cfg_t *elem = NULL;

  elem = new_element(SCMP_SYS(execve), com);
  if (!elem) {
    log_err(LD_BUG,"(Sandbox) failed to register parameter!");
    return -1;
  }

  elem->next = *cfg;
  *cfg = elem;

  return 0;
}
Esempio n. 11
0
/* *LINEP is a pointer into the line being processed.  It is advanced past any
   bytes processed.  Return 0 when we need to read a new line. */
int
big_loop (ELEMENT **current_inout, char **line_inout)
{
  ELEMENT *current = *current_inout;
  char *line = *line_inout;
  int retval = 1; /* Return value of function */
  enum command_id end_cmd;

  char *command = 0;
  enum command_id cmd_id = CM_NONE;

  /* We could be after a @macro line.  See comment in handle_block_command 
     4640. */
  if (!*line)
    {
      retval = 0;
      goto funexit;
    }

  /* If in raw block, or ignored conditional block. */
  // 3727
  if (command_flags(current) & CF_block
      && (command_data(current->cmd).data == BLOCK_raw
          || command_data(current->cmd).data == BLOCK_conditional))
    { /* 3730 */
#if 0
      /* Check if we are using a macro within a macro. */
      if (...)
        {
          ELEMENT *e = new_element ();
          /* ... */

          current = current->contents.list[number];
          break;
        }

      /* Else check for nested ifclear */
      else if (...)
        {
          /* ... */
          current = current->contents.list[number];
          break;
        }
      else
#endif
      /* 3755 Else check if line is "@end ..." for current command. */
      if (is_end_current_command (current, &line, &end_cmd))
Esempio n. 12
0
int
sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file, int fr)
{
  sandbox_cfg_t *elem = NULL;

  elem = new_element(SCMP_stat, 0, (intptr_t)(void*) tor_strdup(file));
  if (!elem) {
    log_err(LD_BUG,"(Sandbox) failed to register parameter!");
    return -1;
  }

  elem->next = *cfg;
  *cfg = elem;

  if (fr) tor_free(file);
  return 0;
}
Esempio n. 13
0
int main()
{
  long n;
   int size;
   TCB_t *list;
   TCB_t *list2;

  size = MAX_SIZE;
  list = malloc(MAX_SIZE * sizeof( TCB_t));

  for(n=0;n<MAX_SIZE;n++)
  {
    list[n].credReal = n;
    if (n == 0)
    {
      list[n].prev = NULL;
      list[n].next = &list[n+1];
    }
    else if (n == 9)
    {
      list[n].prev = &list[n-1];
      list[n].next = NULL;
    }
    else
    {
      list[n].prev = &list[n-1];
      list[n].next = &list[n+1];
    }
  }

  print_list(list);

  printf("sizeof(list) = %d\n",sizeof(list));

  getchar();
  list2 = malloc(MAX_SIZE * sizeof( TCB_t));
  new_element(&list[5],77);

  print_list(list);
  printf("sizeof(list) = %d\n",sizeof(list));

  free(list);
  free(list2);
  //clean_list(list);
  return(0);
}
Esempio n. 14
0
/* If in a context where paragraphs are to be started, start a new 
   paragraph.  */
ELEMENT *
begin_paragraph (ELEMENT *current)
{
  if (begin_paragraph_p (current))
    {
      ELEMENT *e;
      int indent = 0;

      /* Check if an @indent precedes the paragraph (to record it
         in the 'extra' key). */

      e = new_element (ET_paragraph);
      add_to_element_contents (current, e);
      current = e;

      debug ("PARAGRAPH");
    }
  return current;
}
Esempio n. 15
0
// 1190
ELEMENT *
begin_preformatted (ELEMENT *current)
{
  if (current_context() == ct_preformatted
      || current_context() == ct_rawpreformatted)
    {
      ELEMENT *e;
      enum element_type et;

      if (current_context() == ct_preformatted)
        et = ET_preformatted;
      else
        et = ET_rawpreformatted;
      e = new_element (et);
      add_to_element_contents (current, e);
      current = e;
      debug ("PREFORMATTED %s", et == ET_preformatted ? "preformatted"
                                                      : "rawpreformatted");
    }
  return current;
}
Esempio n. 16
0
int main(){
	int i, sum;
	int num, el;
	list abundant = NULL;
	list travel;
	int * array = (int *) malloc(sizeof(int)*(MAXIMO+1));
	for(i = 0 ; i <= MAXIMO ; i++){
		array[i] = i;
	}

	for(i = 0 ; i <= MAXIMO ; i++){
		if(isAbundant(i)){
			abundant = add_element(abundant, new_element(i));
		}
	}
	for(travel = abundant ; travel != NULL ; travel = travel->next){
		num = get_element(travel, true);
		for(el = num ; el != -1 ; el = get_element(travel, false)){
			if(num + el <= MAXIMO)
				array[num+el] = -1;
		}
	}

//	print_list(abundant);
//	for(i = 0, sum = 0 ; i <= MAXIMO ; i++){
//		printf("%d\n", array[i]);
//	}

	for(i = 0, sum = 0 ; i <= MAXIMO ; i++){
		if(array[i] != -1)
			sum += array[i];
	}
	printf("Answer: %d\n", sum);

	delete_list(abundant);
	free(array);
	return 0;
}
Esempio n. 17
0
/* creates a minimax node and element for each child-state 
 * (game_state and move), and adds to list. 
 * 0 on success, on failure returns -1*/
int add_to_children_list_C4(linked_list list, int* game_state, int col, int player)
{
	int move=col;
	int* moved;
	element new_elem_mv;
	vertex node_mv;
	moved = copy_and_make_move_C4(game_state,move - 1, player);
	if (moved == NULL){
		return -1;
	}
	// create new node
	node_mv = make_node(move, moved, get_state_score_C4(moved));
	if (node_mv == NULL){
		free(moved);
		return -1;
	}
	new_elem_mv = new_element();
	if (new_elem_mv == NULL){
		free(moved);
		free(node_mv);
	return -1;
	}
	new_elem_mv->node = node_mv;

	if (list->head == NULL)
	{	//if the list is empty the add new_elem_mv to list
		list->head=new_elem_mv;
		list->tail=new_elem_mv;
	}
	else
	{	//if list not empty,set new element as tail
		element prevTail=list->tail;
		prevTail->next = new_elem_mv;
		new_elem_mv->prev = prevTail;
		list->tail=new_elem_mv;
	}
	return 1;
}
Esempio n. 18
0
/* Add TEXT to the contents of CURRENT, maybe starting a new paragraph. */
ELEMENT *
merge_text (ELEMENT *current, char *text)
{
  int no_merge_with_following_text = 0;
  int leading_spaces = strspn (text, whitespace_chars);
  ELEMENT *last_child = last_contents_child (current);

  /* Is there a non-whitespace character in the line? */
  if (text[leading_spaces])
    {
      char *additional = 0;

      if (last_child
          && (last_child->type == ET_empty_line_after_command
              || last_child->type == ET_empty_line_after_command
              || last_child->type == ET_empty_spaces_before_argument
              || last_child->type == ET_empty_spaces_after_close_brace))
        {
          no_merge_with_following_text = 1;
        }

      if (leading_spaces)
        {
          additional = malloc (leading_spaces + 1);
          if (!additional)
            abort ();
          memcpy (additional, text, leading_spaces);
          additional[leading_spaces] = '\0';
        }

      if (abort_empty_line (&current, additional))
        text += leading_spaces;

      free (additional);

      current = begin_paragraph (current);
    }

  if (last_contents_child (current)
      /* There is a difference between the text being defined and empty,
         and not defined at all.  The latter is true for 'brace_command_arg'
         elements.  We need to make sure that we initialize all elements with
         text_append (&e->text, "") where we want merging with following
         text. */
      && last_contents_child (current)->text.space > 0
      && !strchr (last_contents_child (current)->text.text, '\n')
      && !no_merge_with_following_text)
    {
      /* Append text to contents */
      ELEMENT *last_child = last_contents_child (current);
      text_append (&last_child->text, text);
      debug ("MERGED TEXT: %s|||", text);
    }
  else
    {
      ELEMENT *e = new_element (ET_NONE);
      text_append (&e->text, text);
      add_to_element_contents (current, e);
      debug ("NEW TEXT: %s|||", text);
    }

  return current;
}
Esempio n. 19
0
void tetris::check_stack(){
	bool stacked=false;
	bool stop_me=false;

	for(int y=0;y<3 && !stop_me;y++){
		for(int x=0;x<3 && !stop_me;x++){
			if(active_element[x][y] && (area[active_y+y+1] & (1 << (COLS-active_x-x)))){
				stacked=true;
			}
			if(active_element[x][y] && (active_y+y==(LINES-1))){
				stacked=true;
			}
			if(stacked){
				//show_grid_on_serial();
				/////////////// copy element to grid ///////////////////
				for(int copy_x=0;copy_x<3;copy_x++){
					for(int copy_y=0;copy_y<3;copy_y++){
						if(active_element[copy_x][copy_y]){
							// area[13]=area[15-2+0]
							// area[14]=area[15-2+1]
							// area[15]=area[15-2+2]
							area[active_y+copy_y] |= (1<<(COLS-active_x-copy_x));
						};
						active_element[copy_x][copy_y]=false;
					};
				};


				// check if any line is completed
				for(int line=0;line<LINES;line++){
					if(area[line]==8190){
						// blinken lassen
						pOLED->filled_rect(12,line*4,12*4,4,0);
						_delay_ms(125);
						pOLED->filled_rect(12,line*4,12*4,4,6);
						_delay_ms(125);
						pOLED->filled_rect(12,line*4,12*4,4,0);
						_delay_ms(125);
						pOLED->filled_rect(12,line*4,12*4,4,6);
						// felder verschieben
						for(int upper_line=line;upper_line>0;upper_line--){
							area[upper_line]=area[upper_line-1];
							// alle linien drüber neu zeichnen
							for(int copy_x=0;copy_x<COLS;copy_x++){
								unsigned char color=0x00;
								if(area[upper_line] & (1<<(COLS-copy_x))){
									color=0x06;
								}
								pOLED->filled_rect(12+copy_x*4,upper_line*4,4,4,color);
							}
						}
						// letzte feld löschen
						area[0]=0b0000000000000000;
						pOLED->filled_rect(12,0,48,4,0);

						// lines hochzählen
						lines++;
						// level schwerer machen :D
						if(lines%10==0){
							time_between_steps=4*time_between_steps/5;
							// 1000
							// 800
							// 640
							// 512
							// 409
							// 327
							// 261
							// 208
							// 166
							// 132
							// 105
							// 084
							// 067
							// 053
						}
						char temp[3];
						sprintf(temp,"%2i",int(floor(lines/10)));
						pOLED->string(pSpeedo->default_font,temp,19,6,0,15,0);
						sprintf(temp,"%2i",lines);
						pOLED->string(pSpeedo->default_font,temp,19,7,0,15,0);
					}
				}

				if(area[0]!=0){
					you_loose=true;
				}

				updateField();

				//show_grid_on_serial();
				new_element();
				stop_me=true;
			};
		}
	}
};
Esempio n. 20
0
/* Called from 'big_loop' in parser.c.  Return 1 if we find menu syntax to 
   process, otherwise return 0. */
int
handle_menu (ELEMENT **current_inout, char **line_inout)
{
  ELEMENT *current = *current_inout;
  char *line = *line_inout;
  int retval = 1;

  // 4052
  /* A "*" at the start of a line beginning a menu entry. */
  if (*line == '*'
      && current->type == ET_preformatted
      && (current->parent->type == ET_menu_comment
          || current->parent->type == ET_menu_entry_description)
      && current->contents.number > 0
      && last_contents_child(current)->type == ET_empty_line)
    {
      ELEMENT *star;

      debug ("MENU STAR");
      abort_empty_line (&current, 0);
      line++; /* Past the '*'. */

      star = new_element (ET_menu_star);
      text_append (&star->text, "*");
      add_to_element_contents (current, star);

      /* The ET_menu_star element won't appear in the final tree. */
    }
  // 4067
  /* A space after a "*" at the beginning of a line. */
  else if (strchr (whitespace_chars, *line)
           && current->contents.number > 0
           && last_contents_child(current)->type == ET_menu_star)
    {
      ELEMENT *menu_entry, *leading_text, *entry_name;
      int leading_spaces;

      debug ("MENU ENTRY (certainly)");
      leading_spaces = strspn (line, whitespace_chars);

      destroy_element (pop_element_from_contents (current));

      if (current->type == ET_preformatted
          && current->parent->type == ET_menu_comment)
        {
          ELEMENT *menu = current->parent->parent;

          /* Remove an empty ET_preformatted, and an empty ET_menu_comment. */
          if (current->contents.number == 0)
            {
              pop_element_from_contents (current->parent);
              if (current->parent->contents.number == 0)
                {
                  pop_element_from_contents (menu);
                  destroy_element (current->parent);
                }
              destroy_element (current);
            }

          current = menu;
        }
      else
        {
          /* current should be ET_preformatted,
             1st parent ET_menu_entry_description,
             2nd parent ET_menu_entry,
             3rd parent @menu. */
          current = current->parent->parent->parent;
        }

      if (pop_context () != ct_preformatted)
        abort (); // bug

      menu_entry = new_element (ET_menu_entry);
      leading_text = new_element (ET_menu_entry_leading_text);
      entry_name = new_element (ET_menu_entry_name);
      add_to_element_contents (current, menu_entry);
      add_to_element_args (menu_entry, leading_text);
      add_to_element_args (menu_entry, entry_name);
      current = entry_name;

      text_append (&leading_text->text, "*");
      text_append_n (&leading_text->text, line, leading_spaces);
      line += leading_spaces;
    }
  // 4116
  /* A "*" followed by anything other than a space. */
  else if (current->contents.number > 0
           && last_contents_child(current)->type == ET_menu_star)
    {
      debug ("ABORT MENU STAR");
      destroy_element (pop_element_from_contents (current));
    }
  // 4122
  /* After a separator in a menu. */
  else if (current->args.number > 0
           && last_args_child (current)->type == ET_menu_entry_separator)
    {
      ELEMENT *last_child;
      char *separator;

      last_child = last_args_child (current);
      separator = last_child->text.text;

      /* Separator is "::". */
      if (!strcmp (separator, ":") && *line == ':')
        {
          text_append (&last_child->text, ":");
          line++;
          /* Whitespace following the "::" is subsequently appended to
             the separator element. */
        }
      /* A "." not followed by a space.  Not a separator. */
      else if (!strcmp (separator, ".") && !strchr (whitespace_chars, *line))
        {
          pop_element_from_args (current);
          current = last_args_child (current);
          merge_text (current, last_child->text.text);
          destroy_element (last_child);
        }
      else if (strchr (whitespace_chars_except_newline, *line))
        {
          int n;

          n = strspn (line, whitespace_chars_except_newline);
          text_append_n (&last_child->text, line, n);
          line += n;
        }
      else if (!strncmp (separator, "::", 2))
        {
          ELEMENT *entry_name;

          debug ("MENU NODE no entry %s", separator);
          entry_name = args_child_by_index (current, -2);

          /* Change it from ET_menu_entry_name (i.e. the label). */
          entry_name->type = ET_menu_entry_node;
          current = enter_menu_entry_node (current);
        }
      /* End of the label.  Begin the element for the destination. */
      else if (*separator == ':')
        {
          ELEMENT *entry_node;

          debug ("MENU ENTRY %s", separator);
          entry_node = new_element (ET_menu_entry_node);
          add_to_element_args (current, entry_node);
          current = entry_node;
        }
      else
        {
          debug ("MENU NODE");
          current = enter_menu_entry_node (current);
        }
    }
  else
    retval = 0;

  *current_inout = current;
  *line_inout = line;

  return retval;
}
// read from gw_ini_cmds.ini file
// initialising for target = all and when = dev_init
bool GatewayConfig::InitGwCmds()
{
    WHartUniqueID devUniqueID;
    m_oDeviceInitCmds.clear();
    m_oDeviceTargetedCmds.clear();
    CIniParser gw_commands_parser;

    if (!gw_commands_parser.Load(FILE_PATH))
    {
        return 0;
    }

    for (int i = 0; gw_commands_parser.FindGroup("command", i); i++)
    {
        char target[255];
        char when[255];
        int target_len;
        int cmd_id;
        unsigned char cmd_data[256];
        int cmd_len;
        uint8_t output[5];

        if (gw_commands_parser.GetVar(NULL, "when", when, sizeof(when)) <= 0)
            continue;

        if (strcmp(when, "dev_init") != 0)
        {
            continue;
        }

        if (gw_commands_parser.GetVar(NULL, "target", target, sizeof(target)) <= 0)
            continue;

        if (!gw_commands_parser.GetVar(NULL, "cmd_id", &cmd_id))
            continue;

        if ((cmd_len = gw_commands_parser.GetVar(NULL, "cmd_data", cmd_data, sizeof(cmd_data))) < 0)
            continue;

        if (strcmp(target, "all") == 0)
        {
            // new element in Cmds List
            CHartCmdWrapper::Ptr new_element(new CHartCmdWrapper);

            new_element->LoadRaw((uint16_t) cmd_id, cmd_len, cmd_data);
            m_oDeviceInitCmds.push_back(new_element);
        }
        else
        {
            target_len = Hex2Bin(target, (char *) output);

            if (target_len != sizeof(devUniqueID.bytes))
            {
                LOG_INFO("target=" << target << " inavlid len=" << target_len);
                continue;
            }

            memcpy(devUniqueID.bytes, output, target_len);

            CHartCmdWrapper::Ptr new_element(new CHartCmdWrapper);
            new_element->LoadRaw((uint16_t) cmd_id, cmd_len, cmd_data);

            m_oDeviceTargetedCmds[devUniqueID].push_back(new_element);
        }
        LOG(" target=%s cmdId=%d  data=%s", target, cmd_id, GetHex(cmd_data, cmd_len, ' '));

    }

    return true;
}
Esempio n. 22
0
int main(int argc, char *argv[])
{
	Array *myArray = array_init();
	Element *p;

	assert(myArray);
	size_t size = array_get_size(myArray);

	assert(size == 0);
	int i;

	for (i = 0; i < 1000; ++i) {
		Element *p = new_element(i);

		array_append_element(myArray, p);
		free(p);
	}
	p = new_element(10);
	array_add_element(myArray, 0, p);
	assert(myArray->size == 1001);
	free(p);
	assert(strcmp(myArray->elem[0].test, "ms0:/music/test10.mp3") == 0);
	assert(strcmp(myArray->elem[1].test, "ms0:/music/test0.mp3") == 0);
	assert(strcmp(myArray->elem[10].test, "ms0:/music/test9.mp3") == 0);
	assert(strcmp(myArray->elem[1000].test, "ms0:/music/test999.mp3") == 0);
	assert(myArray->size <= myArray->capable);
	array_del_element(myArray, 0);
	assert(strcmp(myArray->elem[0].test, "ms0:/music/test0.mp3") == 0);
	array_del_element(myArray, 1);
	assert(strcmp(myArray->elem[1].test, "ms0:/music/test2.mp3") == 0);
	array_del_element(myArray, 998);
	assert(strcmp
		   (myArray->elem[array_get_size(myArray) - 1].test,
			"ms0:/music/test998.mp3") == 0);

	while (array_get_size(myArray)) {
		array_del_element(myArray, 0);
	}
	assert(myArray->size == 0);

	int findpos = array_find_element_by_func(myArray, find_path_name,
											 "ms0:/music/test445.mp3");

	assert(findpos < 0);

	for (i = 0; i < 1000; ++i) {
		Element *p = new_element(i);

		array_append_element(myArray, p);
		free(p);
	}

	findpos =
		array_find_element_by_func(myArray, find_path_name,
								   "ms0:/music/test445.mp3");
	assert(findpos == 445);

	array_swap_element(myArray, 0, 1);
	assert(strcmp(myArray->elem[0].test, "ms0:/music/test1.mp3") == 0);
	assert(strcmp(myArray->elem[1].test, "ms0:/music/test0.mp3") == 0);

	assert(array_swap_element(myArray, 0, 1000) == 0);

	array_free(myArray);
	return 0;
}
Esempio n. 23
0
/* 2149 */
void
isolate_last_space (ELEMENT *current, enum element_type element_type)
{
  ELEMENT *last = last_contents_child (current);

  if (!element_type)
    element_type = ET_spaces_at_end;

  if (last)
    {
      int index = -1;
      ELEMENT *indexed_elt;

      /* Ignore space before a misc command that is last on line.  (I don't 
         understand this. ) */
      if (element_contents_number (current) > 1)
        {
          if (last->cmd)
            {
              if (command_flags(last) & CF_misc)
                index = -2;
            }
        }

      indexed_elt = contents_child_by_index (current, index);
      if (indexed_elt)
        {
          char *text = element_text (indexed_elt);
          if (!text || !*text)
            return;

          if (indexed_elt->type == ET_NONE)
            {
              int text_len = strlen (text);
              /* 2170 */
              /* Does the text end in whitespace? */
              if (strchr (whitespace_chars, text[text_len - 1]))
                {
                  /* If text all whitespace */
                  if (text[strspn (text, whitespace_chars)] == '\0')
                    indexed_elt->type = element_type;
                  else
                    {
                      /* 2173 */
                      ELEMENT *new_spaces;
                      int i, trailing_spaces;

                      /* "strrcspn" */
                      trailing_spaces = 0;
                      for (i = strlen (text) - 1;
                           i > 0 && strchr (whitespace_chars, text[i]);
                           i--)
                        trailing_spaces++;
                      
                      new_spaces = new_element (element_type);
                      text_append_n (&new_spaces->text,
                                     text + text_len - trailing_spaces,
                                     trailing_spaces);
                      text[text_len - trailing_spaces] = '\0';

                      if (index == -1)
                        add_to_element_contents (current, new_spaces);
                      else
                        insert_into_contents (current, new_spaces, -1);
                    }
                }
            }
        }
    }
}
Esempio n. 24
0
/* Actions to be taken when a whole line of input has been processed */
ELEMENT *
end_line (ELEMENT *current)
{
  char *end_command = 0;
  enum command_id end_id;

  // 2621
  /* If empty line, start a new paragraph. */
  if (last_contents_child (current)
      && last_contents_child (current)->type == ET_empty_line)
    {
      debug ("END EMPTY LINE");
      if (current->type == ET_paragraph) /* 2625 */
        {
          ELEMENT *e;
          /* Remove empty_line element. */
          e = pop_element_from_contents (current);

          current = end_paragraph (current);

          /* Add empty_line to higher-level element. */
          add_to_element_contents (current, e);
        }
      //else if () // in menu_entry_description
      else if (!in_no_paragraph_contexts (current_context ()))
        {
          current = end_paragraph (current);
        }
    }

  // 2667
  /* The end of the line of a menu. */
  else if (current->type == ET_menu_entry_name
           || current->type == ET_menu_entry_node)
    {
      ELEMENT *end_comment;
      int empty_menu_entry_node = 0;

      if (current->type == ET_menu_entry_node)
        {
          ELEMENT *last = last_contents_child (current);

          if (current->contents.number > 0
              && (last->cmd == CM_c || last->cmd == CM_comment))
            {
              end_comment = pop_element_from_contents (current);
            }

          /* If contents empty or is all whitespace. */
          if (current->contents.number == 0
              || (current->contents.number == 1
                  && last->text.end > 0
                  && !last->text.text[strspn (last->text.text, 
                                              whitespace_chars)]))
            {
              empty_menu_entry_node = 1;
              if (end_comment)
                add_to_element_contents (current, end_comment);
            }
        }

      // 2689
      /* Abort the menu entry if there is no destination node given. */
      if (empty_menu_entry_node || current->type == ET_menu_entry_name)
        {
        }
      else // 2768
        {
          debug ("MENU ENTRY END LINE");
          current = current->parent;
          current = enter_menu_entry_node (current);
          if (end_comment)
            add_to_element_contents (current, end_comment);
        }
    }

  /* Is it a def line 2778 */
  else if (current->parent && current->parent->type == ET_def_line)
    {
      enum element_type def_command;

      if (pop_context () != ct_def)
        {
          abort ();
        }

#if 0
      /* current->parent is a ET_def_line, and current->parent->parent
         the def command. */
      def_command = current->parent->parent->cmd;
      // strip a trailing x
      parse_def (def_command, current->contents);
#endif

      current = current->parent->parent;
      current = begin_preformatted (current);

    }

  // 2872
  /* End of a line starting a block. */
  else if (current->type == ET_block_line_arg)
    {
      enum context c;
      // pop and check context_stack
      c = pop_context ();
      if (c != ct_line)
        {
          // bug
          abort ();
        }

      // 2881
      if (current->parent->cmd == CM_multitable)
        {
          /* Parse prototype row */
          // But not @columnfractions, I assume?
        }

      if (current->parent->cmd == CM_float) // 2943
        {
        }
      current = current->parent; //2965

      /* Don't consider empty argument of block @-command as argument,
         reparent them as contents. */
      if (current->args.list[0]->contents.number > 0
          && current->args.list[0]->contents.list[0]->type
             == ET_empty_line_after_command)
        {
          ELEMENT *e;
          e = current->args.list[0]->contents.list[0];
          insert_into_contents (current, e, 0);
          // TODO: Free lists?
          current->args.number = 0;
        }

      if (command_flags(current) & CF_blockitem) // 2981
        {
          if (current->cmd == CM_enumerate)
            {
            }
          else if (item_line_command (current->cmd)) // 3002
            {
              // check command_as_argument registered in 'extra', and
              // that it accepts arguments in braces
            }

          if (current->cmd == CM_itemize) // 3019
            {
              // check that command_as_argument is alone on the line
            }

          // check if command_as_argument isn't an accent command

          /* 3052 - if no command_as_argument given, default to @bullet for
             @itemize, and @asis for @table. */

          {
            ELEMENT *bi = new_element (ET_before_item);
            add_to_element_contents (current, bi);
            current = bi;
          }
        } /* CF_blockitem */

      // 3077
      if (command_flags(current) & CF_menu)
        {
          /* Start reading a menu.  Processing will continue in
             handle_menu in menus.c. */

          ELEMENT *menu_comment = new_element (ET_menu_comment);
          add_to_element_contents (current, menu_comment);
          current = menu_comment;
          debug ("MENU COMMENT OPEN");
          push_context (ct_preformatted);
        }
      current = begin_preformatted (current);
    }

  /* after an "@end verbatim" 3090 */
  else if (current->contents.number
           && last_contents_child(current)->type == ET_empty_line_after_command
    /* The Perl version gets the command with the 'command' key in 'extra'. */
           && contents_child_by_index(current, -2)
           && contents_child_by_index(current, -2)->cmd == CM_verbatim)
    {
      // I don't know what this means.  raw command is @html etc.?
      /*
     if we are after a @end verbatim, we must restart a preformatted if needed,
     since there is no @end command explicitly associated to raw commands
     it won't be done elsewhere.
      */

      current = begin_preformatted (current);
    }


  /* if it's a misc line arg 3100 */
  else if (current->type == ET_misc_line_arg)
    {
      int cmd_id, arg_type;
      enum context c;

      isolate_last_space (current, 0);

      current = current->parent;
      cmd_id = current->cmd;
      if (!cmd_id)
        abort ();

      arg_type = command_data(cmd_id).data;
       
      /* Check 'line' is top of the context stack */
      c = pop_context ();
      if (c != ct_line)
        {
          /* error */
          abort ();
        }

      // 3114
      debug ("MISC END %s", command_data(cmd_id).cmdname);

      if (arg_type > 0)
        {
          /* arg_type is number of args */
          // parse_line_command_args
          // save in 'misc_args' extra key
        }
      else if (arg_type == MISC_text) /* 3118 */
        {
          char *text;
         
          /* argument string has to be parsed as Texinfo. This calls convert in 
             Common/Text.pm on the first element of current->args. */
          /* however, this makes it impossible to decouple the parser and 
             output stages...  Any use of Texinfo::Convert is problematic. */

          if (current->args.number > 0)
            text = text_convert (current->args.list[0]);
          else
            text = "foo";

          if (!strcmp (text, ""))
            {
              /* 3123 warning - missing argument */
              abort ();
            }
          else
            {
              if (current->cmd == CM_end) /* 3128 */
                {
                  char *line = text;

                  /* Set end_command - used below. */
                  end_command = read_command_name (&line);

                  /* Check argument meets format of a Texinfo command
                     (alphanumberic character followed by alphanumeric 
                     characters or hyphens. */

                  /* Check if argument is a block Texinfo command. */
                  end_id = lookup_command (end_command);
                  if (end_id == -1 || !(command_data(end_id).flags & CF_block))
                    {
                      /* error - unknown @end */
                    }
                  else
                    {
                      debug ("END BLOCK %s", end_command);
                      /* 3140 Handle conditional block commands (e.g.  
                         @ifinfo) */

                      /* If we are in a non-ignored conditional, there is not
                         an element for the block in the tree; it is recorded 
                         in the conditional stack.  Pop it and check it is the 
                         same as the one given in the @end line. */

                      if (command_data(end_id).data == BLOCK_conditional)
                        {
                          if (conditional_number > 0)
                            {
                              enum command_id popped;
                              popped = pop_conditional_stack ();
                              if (popped != end_id)
                                abort ();
                            }
                        }
                    }
                }
              else if (current->cmd == CM_include) /* 3166 */
                {
                  debug ("Include %s", text);
                  input_push_file (text);
                }
              else if (current->cmd == CM_documentencoding)
                /* 3190 */
                {
                }
              else if (current->cmd == CM_documentlanguage)
                /* 3223 */
                {
                }
            }
        }
      else if (current->cmd == CM_node) /* 3235 */
        {
          int i;
          ELEMENT *arg;
          ELEMENT *first_arg;
          /* Construct 'nodes_manuals' array.  This would be an 'extra' 
             reference to an array that doesn't exist anywhere else. */

          /* This sets the 'node_content' and 'normalized' keys on each element 
             in 'nodes_manuals'. */
          //parse_node_manual ();
          
          /* In Perl a copy of the argument list is taken and the empty space 
             arguments are removed with trim_spaces_comment_from_content. */
          first_arg = current->args.list[0];
          arg = new_element (ET_NONE);
          arg->parent_type = route_not_in_tree;
          for (i = 0; i < first_arg->contents.number; i++)
            {
              if (first_arg->contents.list[i]->type
                    != ET_empty_spaces_after_command
                  && first_arg->contents.list[i]->type != ET_spaces_at_end)
                {
                  /* FIXME: Is this safe to serialize? */
                  /* For example, if there are extra keys in the elements under 
                     each argument?  They may not be set in a copy.
                     Hopefully there aren't many extra keys set on commands in 
                     node names. */
                  add_to_element_contents (arg, first_arg->contents.list[i]);
                }
            }
          add_extra_key_contents (current, "node_content", arg);

          /* Also set 'normalized' here.  The normalized labels are actually 
             the keys of "labels_information($parser)". */

          /*Check that the node name doesn't have a filename element for 
            referring to an external manual (_check_internal_node), and that it 
            is not empty (_check_empty_node).  */
          //check_node_label ();

          /* This sets 'node_content' and 'normalized' on the node, among
             other things (which were already set in parse_node_manual). */
          register_label (current, arg);

          current_node = current;
        }
      else if (current->cmd == CM_listoffloats) /* 3248 */
        {
        }
      else
        {
          /* All the other "line" commands" */
        }

      current = current->parent; /* 3285 */
      if (end_command) /* Set above */
        {
          /* more processing of @end */
          ELEMENT *end_elt;

          debug ("END COMMAND %s", end_command);

          /* Reparent the "@end" element to be a child of the block element. */
          end_elt = pop_element_from_contents (current);

          /* 3289 If not a conditional */
          if (command_data(end_id).data != BLOCK_conditional)
            {
              ELEMENT *closed_command;
              /* This closes tree elements (e.g. paragraphs) until we reach
                 end_command.  It can print an error if another block command
                 is found first. */
              current = close_commands (current, end_id,
                              &closed_command, 0); /* 3292 */
              if (!closed_command)
                abort (); // 3335

              close_command_cleanup (closed_command);
              // 3301 INLINE_INSERTCOPYING
              add_to_element_contents (closed_command, end_elt); // 3321
              // 3324 ET_menu_comment
              if (close_preformatted_command (end_id))
                current = begin_preformatted (current);
            }
        } /* 3340 */
      else
        {
          if (close_preformatted_command (cmd_id))
            current = begin_preformatted (current);
        }

      /* 3346 included file */

      /* 3350 */
      if (cmd_id == CM_setfilename && (current_node || current_section))
        {
          /* warning */
          abort ();
        }
      /* 3355 columnfractions */
      else if (cmd_id == CM_columnfractions)
        {
          ELEMENT *before_item;
          // check if in multitable

          // pop and check context stack

          current = current->parent;
          before_item = new_element (ET_before_item);
          add_to_element_contents (current, before_item);
          current = before_item;
        }
      else if (command_data(cmd_id).flags & CF_root) /* 3380 */
        {
          current = last_contents_child (current);
          
          /* 3383 Destroy all contents (why do we do this?) */
          while (last_contents_child (current))
            destroy_element (pop_element_from_contents (current));

          /* Set 'associated_section' extra key for a node. */
          if (cmd_id != CM_node && cmd_id != CM_part)
            {
              if (current_node)
                {
                  if (!lookup_extra_key (current_node, "associated_section"))
                    {
                      add_extra_key_element
                        (current_node, "associated_section", current);
                      add_extra_key_element
                        (current, "associated_node", current_node);
                    }
                }

              // "current parts" - 3394

              current_section = current;
            }
        } /* 3416 */
    }


  // something to do with an empty line /* 3419 */

  //if () /* 'line' or 'def' at top of "context stack" */
    {
      /* Recurse. */
    }
  return current;
} /* end_line 3487 */