Пример #1
0
void Settings::set_to_gui (Builder &builder, int i)
{
  const char *glade_name = settings[i].glade_name;

  if (!glade_name)
        return;

  switch (settings[i].type) {
  case T_BOOL: {
    Gtk::CheckButton *check = NULL;
    builder->get_widget (glade_name, check);
    if (!check)
      std::cerr << "Missing boolean config item " << glade_name << "\n";
    else
      check->set_active (*PTR_BOOL(this, i));
    break;
  }
  case T_INT:
  case T_FLOAT: {
    Gtk::Widget *w = NULL;
    builder->get_widget (glade_name, w);
    if (!w) {
      std::cerr << "Missing user interface item " << glade_name << "\n";
      break;
    }

    Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w);
    if (spin) {
      if (settings[i].type == T_INT)
          spin->set_value (*PTR_INT(this, i));
      else
          spin->set_value (*PTR_FLOAT(this, i));
      break;
    }
    Gtk::Range *range = dynamic_cast<Gtk::Range *>(w);
    if (range) {
      if (settings[i].type == T_INT)
        range->set_value (*PTR_INT(this, i));
      else
        range->set_value (*PTR_FLOAT(this, i));
    }
    break;
  }
  case T_STRING: {
    Gtk::Entry *e = NULL;
    builder->get_widget (glade_name, e);
    if (!e) {
      std::cerr << "Missing user interface item " << glade_name << "\n";
      break;
    }
    e->set_text(*PTR_STRING(this, i));
    break;
  }
  case T_COLOUR_MEMBER:
    break; // Ignore, Colour members are special 
  default:
    std::cerr << "corrupt setting type\n";
    break;
  }
}
Пример #2
0
static void libmpq_huff_insert_item(struct huffman_tree_item **p_item, struct huffman_tree_item *item, unsigned long where, struct huffman_tree_item *item2) {
	struct huffman_tree_item *next = item->next;	/* EDI - next to the first item */
	struct huffman_tree_item *prev = item->prev;	/* ESI - prev to the first item */
	struct huffman_tree_item *prev2;		/* Pointer to previous item */
	long next2;					/* Pointer to the next item */

	/* The same code like in mpq_huff_remove_item(); */
	if (next != 0) {				/* If the first item already has next one */
		if (PTR_INT(prev) < 0) {
			prev = PTR_NOT(prev);
		} else {
			prev += (item - next->prev);
		}

		/*
		 * 150083C1
		 * Remove the item from the tree
		 */
		prev->next = next;
		next->prev = prev;

		/* Invalidate 'prev' and 'next' pointer */
		item->next = 0;
		item->prev = 0;
	}

	if (item2 == NULL) {				/* EDX - If the second item is not entered, */
		item2 = PTR_PTR(&p_item[1]);		/* take the first tree item */
	}

	switch (where) {
		case SWITCH_ITEMS:			/* Switch the two items */
			item->next  = item2->next;	/* item2->next (Pointer to pointer to first) */
			item->prev  = item2->next->prev;
			item2->next->prev = item;
			item2->next = item;		/* Set the first item */
			return;
		case INSERT_ITEM:			/* Insert as the last item */
			item->next = item2;		/* Set next item (or pointer to pointer to first item) */
			item->prev = item2->prev;	/* Set prev item (or last item in the tree) */
			next2 = PTR_INT(p_item[0]);	/* Usually NULL */
			prev2 = item2->prev;		/* Prev item to the second (or last tree item) */
			if (PTR_INT(prev2) < 0) {
				prev2 = PTR_NOT(prev);
				prev2->next = item;
				item2->prev = item;	/* Next after last item */
				return;
			}
			if (next2 < 0) {
				next2 = item2 - item2->next->prev;
			}
			prev2 += next2;
			prev2->next = item;
			item2->prev = item;		/* Set the next/last item */
			return;
		default:
			return;
	}
}
Пример #3
0
extern  pointer LkAddBack( sym_handle sym, pointer curr_back ) {
/**************************************************************/

    b   *bk;

    if( curr_back == NULL ) {
        NewBackReturn = RETURN_NULL;
    } else {
        NewBackReturn = (pointer)( PTR_INT( curr_back ) | FAKE_BACK );
    }
    bk = FEBack( sym );
    NewBackReturn = RETURN_NORMAL;
    return( (pointer)( PTR_INT( bk ) & ~FAKE_BACK ) );
}
Пример #4
0
static void match_dma_func(const char *fn, struct expression *expr, void *param)
{
	struct expression *arg;
	struct symbol *sym;
	char *name;

	arg = get_argument_from_call_expr(expr->args, PTR_INT(param));
	arg = strip_expr(arg);
	if (!arg)
		return;
	if (arg->type == EXPR_PREOP && arg->op == '&') {
		if (arg->unop->type != EXPR_SYMBOL)
			return;
		name = expr_to_str(arg);
		sm_msg("error: doing dma on the stack (%s)", name);
		free_string(name);
		return;
	}
	if (arg->type != EXPR_SYMBOL)
		return;
	sym = get_type(arg);
	if (!sym || sym->type != SYM_ARRAY)
		return;
	name = expr_to_var(arg);
	sm_msg("error: doing dma on the stack (%s)", name);
	free_string(name);
}
Пример #5
0
void Settings::save_settings(Glib::RefPtr<Gio::File> file)
{
  Glib::KeyFile cfg;

  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    Glib::ustring group, key;

    if (!get_group_and_key (i, group, key))
      continue;

    switch (settings[i].type) {
    case T_BOOL:
      cfg.set_boolean (group, key, *PTR_BOOL(this, i));
      break;
    case T_INT:
      cfg.set_integer (group, key, *PTR_INT(this, i));
      break;
    case T_FLOAT:
    case T_COLOUR_MEMBER:
      cfg.set_double (group, key, *PTR_FLOAT(this, i));
      break;
    case T_STRING:
      cfg.set_string (group, key, *PTR_STRING(this, i));
      break;
    default:
      std::cerr << "Can't save setting of unknown type\n";
      break;
    };
  }

  GCode.m_impl->saveSettings (cfg);

  Glib::ustring contents = cfg.to_data();
  Glib::file_set_contents (file->get_path(), contents);
}
Пример #6
0
void Settings::set_defaults ()
{
  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    switch (settings[i].type) {
    case T_BOOL:
      *PTR_BOOL(this, i) = settings[i].def_double != 0.0;
      break;
    case T_INT:
      *PTR_INT(this, i) = settings[i].def_double;
      break;
    case T_FLOAT:
    case T_COLOUR_MEMBER:
      *PTR_FLOAT(this, i) = settings[i].def_double;
      break;
    case T_STRING:
      *PTR_STRING(this, i) = std::string (settings[i].def_string);
      break;
    default:
      std::cerr << "corrupt setting type\n";
      break;
    }
  }

  Slicing.ShrinkQuality = SHRINK_FAST;

  GCode.m_impl->setDefaults();

  // The vectors map each to 3 spin boxes, one per dimension
  Hardware.Volume = vmml::Vector3f (200,200,140);
  Hardware.PrintMargin = vmml::Vector3f (10,10,0);
}
Пример #7
0
/* Gets previous Huffman tree item (?) */
struct huffman_tree_item *libmpq_huff_get_prev_item(struct huffman_tree_item *hi, long value) {
	if (PTR_INT(hi->prev) < 0) {
		return PTR_NOT(hi->prev);
	}
	if (value < 0) {
		value = hi - hi->next->prev;
	}
	return hi->prev + value;
}
Пример #8
0
static int param_caps_return(struct expression *call, void *_arg, struct range_list **res)
{
	int arg = PTR_INT(_arg);
	struct expression *expr;
	struct range_list *rl;

	expr = get_argument_from_call_expr(call->args, arg);
	if (get_implied_rl(expr, &rl) && rl_max(rl).value != 0)
		*res = alloc_rl(sval_type_val(rl_type(rl), 0), rl_max(rl));
	return 1;
}
Пример #9
0
void Settings::load_settings (Glib::RefPtr<Gio::File> file)
{
  Glib::KeyFile cfg;

  set_defaults();

  try {
    if (!cfg.load_from_file (file->get_path())) {
      std::cout << "Failed to load settings from file '" << file->get_path() << "\n";
      return;
    }
  } catch (const Glib::KeyFileError &err) {
    std::cout << "Exception " << err.what() << " loading settings from file '" << file->get_path() << "\n";
    return;
  }

  std::cout << "parsing config from '" << file->get_path() << "\n";

  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    Glib::ustring group, key;

    if (!get_group_and_key (i, group, key))
      continue;

    if (!cfg.has_key (group, key))
      continue;

    // group & string ...
    switch (settings[i].type) {
    case T_BOOL:
      *PTR_BOOL(this, i) = cfg.get_boolean (group, key);
      break;
    case T_INT:
      *PTR_INT(this, i) = cfg.get_integer (group, key);
      break;
    case T_FLOAT:
    case T_COLOUR_MEMBER:
      *PTR_FLOAT(this, i) = cfg.get_double (group, key);
      break;
    case T_STRING:
      *PTR_STRING(this, i) = cfg.get_string (group, key);
      break;
    default:
      std::cerr << "corrupt setting type\n";
      break;
    }
  }

  GCode.m_impl->loadSettings (cfg);

  m_signal_visual_settings_changed.emit();
  m_signal_update_settings_gui.emit();
}
Пример #10
0
static void match_calloc(const char *fn, struct expression *expr, void *_arg_nr)
{
	int arg_nr = PTR_INT(_arg_nr);
	struct expression *call = strip_expr(expr->right);
	struct expression *arg;
	int ptr_size;

	ptr_size = get_data_size(expr->left);
	if (!ptr_size)
		return;

	arg = get_argument_from_call_expr(call->args, arg_nr);
	check_size_matches(ptr_size, arg);
}
Пример #11
0
/* 1500BC90 */
static void libmpq_huff_remove_item(struct huffman_tree_item *hi) {
	struct huffman_tree_item *temp;			/* EDX */

	if (hi->next != NULL) {
		temp = hi->prev;
		if (PTR_INT(temp) <= 0) {
			temp = PTR_NOT(temp);
		} else {
			temp += (hi - hi->next->prev);
		}
		temp->next          = hi->next;
		hi->next->prev      = hi->prev;
		hi->next = hi->prev = NULL;
	}
}
Пример #12
0
static void match_resource(const char *fn, struct expression *expr, void *_arg_no)
{
	struct expression *arg_expr;
	int arg_no = PTR_INT(_arg_no);

	arg_expr = get_argument_from_call_expr(expr->args, arg_no);
	arg_expr = strip_expr(arg_expr);
	if (!arg_expr)
		return;

	if (arg_expr->type == EXPR_SYMBOL) {
		handle_assigned_expr(arg_expr);
		return;
	}
	verify_size_expr(arg_expr);
}
Пример #13
0
static int match_sprintf(struct expression *call, void *_arg, struct range_list **rl)
{
	int str_arg = PTR_INT(_arg);
	int size;

	size = get_formatted_string_size(call, str_arg);
	if (size <= 0) {
		*rl = alloc_whole_rl(&ulong_ctype);
	} else {
		/* FIXME:  This is bogus.  get_formatted_string_size() should be
		   returning a range_list.  Also it should not add the NUL. */
		size--;
		*rl = alloc_rl(ll_to_sval(0), ll_to_sval(size));
	}
	return 1;
}
Пример #14
0
static void match_call(const char *fn, struct expression *expr, void *_arg_no)
{
	struct expression *arg_expr;
	int arg_no = PTR_INT(_arg_no);
	sval_t sval;
	char *name;

	arg_expr = get_argument_from_call_expr(expr->args, arg_no);
	if (positions_eq(expr->pos, arg_expr->pos))
		return;
	name = pos_ident(arg_expr->pos);
	if (!name)
		return;
	if (!get_value(arg_expr, &sval))
		return;
	sm_msg("info: bit shifter '%s' '%s'", name, sval_to_str(sval));
}
Пример #15
0
/* get previous huffman tree item. */
struct huffman_tree_item_s *libmpq__huffman_previous_item(struct huffman_tree_item_s *hi, long value) {

    /* check if previous item exist. */
    if (PTR_INT(hi->prev) < 0) {

        /* return previous item. */
        return PTR_NOT(hi->prev);
    }

    /* check if something else should returned. */
    if (value < 0) {

        /* fetch previous item of next item. */
        value = hi - hi->next->prev;
    }

    /* return previous item with value. */
    return hi->prev + value;
}
Пример #16
0
/* 1500BC90 - remove item from huffman tree.*/
void libmpq__huffman_remove_item(struct huffman_tree_item_s *hi) {

    /* EDX - some common variables. */
    struct huffman_tree_item_s *temp;

    /* check if next item is not empty. */
    if (hi->next != NULL) {

        /* fetch previous item. */
        temp = hi->prev;

        /* check if previous item is a pointer. */
        if (PTR_INT(temp) <= 0) {
            temp = PTR_NOT(temp);
        } else {
            temp += (hi - hi->next->prev);
        }

        /* reorganize tree. */
        temp->next     = hi->next;
        hi->next->prev = hi->prev;
        hi->next       = hi->prev = NULL;
    }
}
Пример #17
0
// Inserts item into the tree (?)
static void InsertItem(THTreeItem ** itemPtr, THTreeItem * item, unsigned long nWhere, THTreeItem * item2)
{
    THTreeItem * next = item->next;     // EDI - next to the first item
    THTreeItem * prev = item->prev;     // ESI - prev to the first item
    THTreeItem * prev2;                 // Pointer to previous item
    LONG_PTR next2;                     // Pointer to the next item

    // The same code like in RemoveItem(item);
    if(next != 0)                       // If the first item already has next one
    {
        if(PTR_INVALID(prev))
            prev = PTR_NOT(prev);
        else
            prev += (item - next->prev);

        // 150083C1
        // Remove the item from the tree
        prev->next = next;
        next->prev = prev;

        // Invalidate 'prev' and 'next' pointer
        item->next = 0;
        item->prev = 0;
    }

    if(item2 == NULL)                   // EDX - If the second item is not entered,
        item2 = PTR_PTR(&itemPtr[1]);   // take the first tree item

    switch(nWhere)
    {
        case SWITCH_ITEMS :             // Switch the two items
            item->next  = item2->next;  // item2->next (Pointer to pointer to first)
            item->prev  = item2->next->prev;
            item2->next->prev = item;
            item2->next = item;         // Set the first item
            return;

        case INSERT_ITEM:               // Insert as the last item
            item->next = item2;         // Set next item (or pointer to pointer to first item)
            item->prev = item2->prev;   // Set prev item (or last item in the tree)

            next2 = PTR_INT(itemPtr[0]);// Usually NULL
            prev2 = item2->prev;        // Prev item to the second (or last tree item)

            if(PTR_INVALID(prev2))
            {
                prev2 = PTR_NOT(prev);

                prev2->next = item;
                item2->prev = item;     // Next after last item
                return;
            }

            if(PTR_INVALID(next2))
                next2 = (LONG_PTR)(item2 - item2->next->prev);
//              next2 = (THTreeItem *)(unsigned long)((unsigned char *)item2 - (unsigned char *)(item2->next->prev));

//          prev2 = (THTreeItem *)((char *)prev2 + (unsigned long)next2);// ???
            prev2 += next2;
            prev2->next = item;
            item2->prev = item;         // Set the next/last item
            return;

        default:
            return;
    }
}
Пример #18
0
//=============================================================================
  int GUI_DialogEntry (char* label, char *entry, int eSiz,
                        char *buttons[], int border) {
//=============================================================================
/// \code
/// GUI_DialogEntry       text, 1-n buttons; entry optional; waits for return.
///
/// Input
///   label       text
///   entry       userinput - defaultText;  NULL = no userinput (only buttons)
///   eSiz        size of inputfield entry (max. nr of chars)
///   buttons     pointerarray of buttontext, NULL-terminated.
///   border      size around button
/// Output:
///   entry       content of inputfield on exit
///   eSiz        nr of chars in inputfield entry
/// RetCod        nr of button pressed or -1 = dialog cancelled
///               0 means first button pressed, 1=second ..
///
/// Example without entry:
///   char   *buttons[]={"YES","NO","Cancel",NULL}, s1[256];
///   irc = GUI_DialogEntry ("Save model -", NULL, 0, buttons, 2);
///   // YES returns 0, NO returns 1, Cancel returns 2; X returns UI_FuncKill.
///
/// Example with entry:
///  strcpy (s1, "myName");
///  irc = GUI_DialogEntry ("GUI_DialogEntry", s1, 250, buttons, 2);
///
/// \endcode

//    int    irc, sizText;
//    char   sLabel[200], *buttons[4], sbt[3][64];
//    sprintf(sbt[0], "Cancel");
//    sprintf(sbt[1], "NO");
//    sprintf(sbt[2], "YES");
//    buttons[0] = sbt[0];
//    buttons[1] = sbt[1];
//    buttons[2] = sbt[2];
//    buttons[3] = NULL;
//    irc = GUI_DialogEntry ("Save model -", NULL, NULL, buttons);


  MemObj    box0, box1, w_entry, mo1;
  void      *wo;

  int        i1, irc, *ia, bNr;
  // GtkWidget  *box1, *w_entry;
  char       fn[240], *p1;


  // printf("GUI_DialogEntry |%s|\n",label);
  // if(entry)printf(" DW entry |%s| %d\n",entry,eSiz);
  // i1=0;while(buttons[i1]){printf(" DW butt[%d]=|%s|\n",i1,buttons[i1]);++i1;}


  // not necessary if modal ..
  // // if(UI_DialogEntryWin) {
  // if(UI_DialogEntryWin.mbID > 0) {
    // // gdk_window_raise (GDK_WINDOW(UI_DialogEntryWin));
      // printf(" GUI_DialogEntry already exists ..\n");
    // return 0;
  // }


  UI_DialogEntryWin = GUI_Win__ ("", GUI_DialogEntryCB, "");
  // box0 = GUI_box__ (&UI_DialogEntryWin, 1, 0, 0);
  box0 = GUI_box_v (&UI_DialogEntryWin, "");
  GUI_spc__ (&box0, 1, 4);
  GUI_label__ (&box0, label, "");


  // create entry .....................
  if(entry) {
    // i1 = strlen(entry) + 10;
    w_entry = GUI_entry__ (&box0, NULL, entry, NULL, NULL, "e");
      // printf("GUI_DialogEntry |%s| %d\n",entry,eSiz);
  }

  // create buttons .....................
  GUI_sep__ (&box0, 0, 4);
  // box1 = GUI_box__ (&box0, 0,  0, 0);
  box1 = GUI_box_h (&box0, "");


  // get i1 = nr of buttons;
  bNr = 0;
  while(buttons[bNr]) ++bNr;
    printf(" bNr=%d\n",bNr);


  // get static list of integers for user-data
  ia = MEM_alloc_tmp (sizeof(int) * bNr);

  for(i1=0; i1<bNr; ++i1) {
    if(border > 0) GUI_spc__ (&box1, 0, border);
      printf(" butt[%d]=|%s|\n",i1,buttons[i1]);
    ia[i1] = i1;   // the id must be static !
    GUI_button__ (&box1, buttons[i1], GUI_DialogEntryCB, PTR_INT(ia[i1]), "e");
  }

  if(border > 0) GUI_spc__ (&box1, 0, border);


  GUI_Win_go (&UI_DialogEntryWin);
  GUI_Win_up (NULL, &UI_DialogEntryWin, 1);
  // GUI_update__ ();


  // wait ..
  OS_file_sig_wait (2, (void*)&irc);
    printf(" irc=%d\n",irc);


  // get entry back
  // if(GTK_IS_WINDOW(UI_DialogEntryWin)) {        // delete destroys win0 
  if(irc >= 0) {
    if(entry) {
      p1 = GUI_entry_get (&w_entry);
      i1 = eSiz - 1;
      eSiz = IMIN (strlen(p1), i1);
      strncpy(entry, p1, eSiz);
      entry[eSiz] = '\0';
        printf(" entry: |%s| %d\n",entry,eSiz);
    }

    GUI_Win_kill (&UI_DialogEntryWin);
  }     


  return irc;

}
Пример #19
0
/* this function build a huffman tree, called with the first 8 bits loaded from input stream. */
void libmpq__huffman_tree_build(struct huffman_tree_s *ht, uint32_t cmp_type) {

    /* [ESP+10] - the greatest character found in table. */
    uint32_t max_byte;

    /* [ESP+1C] - pointer to uint8_t in table_1502A630. */
    const uint8_t *byte_array;

    /* thats needed to replace the goto stuff from original source. :) */
    uint32_t found;

    /* [ESP+14] - Pointer to Huffman tree item pointer array. */
    struct huffman_tree_item_s **p_item;
    struct huffman_tree_item_s *child1;

    /* some common variables. */
    uint32_t i;

    /* ESI - loop while pointer has a negative value (last entry). */
    while (PTR_INT(ht->last) > 0) {

        /* EAX */
        struct huffman_tree_item_s *temp;

        /* ESI->next */
        if (ht->last->next != NULL) {
            libmpq__huffman_remove_item(ht->last);
        }

        /* [EDI+4] */
        ht->item3058   = PTR_PTR(&ht->item3054);

        /* EAX */
        ht->last->prev = ht->item3058;
        temp           = libmpq__huffman_previous_item(PTR_PTR(&ht->item3054), PTR_INT(&ht->item3050));
        temp->next     = ht->last;
        ht->item3054   = ht->last;
    }

    /* clear all pointers in huffman tree item array. */
    memset(ht->items306C, 0, sizeof(ht->items306C));

    /* greatest character found init to zero. */
    max_byte    = 0;

    /* pointer to current entry in huffman tree item pointer array. */
    p_item      = (struct huffman_tree_item_s **)&ht->items306C;

    /* ensure we have low 8 bits only. */
    cmp_type   &= 0xFF;

    /* EDI also. */
    byte_array  = table_1502A630 + cmp_type * 258;

    /* loop to build huffman tree. */
    for (i = 0; i < 0x100; i++, p_item++) {

        /* item to be created. */
        struct huffman_tree_item_s *item    = ht->item3058;
        struct huffman_tree_item_s *p_item3 = ht->item3058;
        uint8_t one_byte                  = byte_array[i];

        /* skip all the bytes which are zero. */
        if (byte_array[i] == 0) {
            continue;
        }

        /* if not valid pointer, take the first available item in the array. */
        if (PTR_INT(item) <= 0) {
            item = &ht->items0008[ht->items++];
        }

        /* insert this item as the top of the tree. */
        libmpq__huffman_insert_item(&ht->item305C, item, SWITCH_ITEMS, NULL);

        /* invalidate child and parent. */
        item->parent     = NULL;
        item->child      = NULL;

        /* store pointer into pointer array. */
        *p_item          = item;

        /* store counter. */
        item->dcmp_byte  = i;

        /* store byte value. */
        item->byte_value = one_byte;

        /* check if byte is to big. */
        if (one_byte >= max_byte) {

            /* set max byte to highest value. */
            max_byte = one_byte;

            /* continue loop. */
            continue;
        }

        /* find the first item which has byte value greater than current one byte. */
        found = 0;

        /* EDI - Pointer to the last item. */
        if (PTR_INT((p_item3 = ht->last)) > 0) {

            /* 15006AF7 */
            if (p_item3 != NULL) {

                /* 15006AFB */
                do {

                    /* check if we found item. */
                    if (p_item3->byte_value >= one_byte) {
                        found = 1;
                        break;
                    }

                    /* switch to previous item. */
                    p_item3 = p_item3->prev;
                } while (PTR_INT(p_item3) > 0);
            }
        }

        /* check if item was not found. */
        if (found == 0) {
            p_item3 = NULL;
        }

        /* 15006B09 */
        if (item->next != NULL) {
            libmpq__huffman_remove_item(item);
        }

        /* 15006B15 */
        if (p_item3 == NULL) {
            p_item3 = PTR_PTR(&ht->first);
        }

        /* 15006B1F */
        item->next          = p_item3->next;
        item->prev          = p_item3->next->prev;
        p_item3->next->prev = item;
        p_item3->next       = item;
    }

    /* 15006B4A */
    for (; i < 0x102; i++) {

        /* EDI */
        struct huffman_tree_item_s **p_item2 = &ht->items306C[i];

        /* 15006B59 - ESI */
        struct huffman_tree_item_s *item2 = ht->item3058;

        /* check if item is a valid pointer. */
        if (PTR_INT(item2) <= 0) {
            item2 = &ht->items0008[ht->items++];
        }

        /* insert the item into tree. */
        libmpq__huffman_insert_item(&ht->item305C, item2, INSERT_ITEM, NULL);

        /* 15006B89 */
        item2->dcmp_byte  = i;
        item2->byte_value = 1;
        item2->parent     = NULL;
        item2->child      = NULL;
        *p_item2++        = item2;
    }

    /* 15006BAA - EDI - last item (first child to item). */
    if (PTR_INT((child1 = ht->last)) > 0) {

        /* EBP */
        struct huffman_tree_item_s *child2;

        /* ESI */
        struct huffman_tree_item_s *item;

        /* 15006BB8 */
        while (PTR_INT((child2 = child1->prev)) > 0) {
            if (PTR_INT((item = ht->item3058)) <= 0) {
                item = &ht->items0008[ht->items++];
            }

            /* 15006BE3 */
            libmpq__huffman_insert_item(&ht->item305C, item, SWITCH_ITEMS, NULL);

            /* 15006BF3 */
            item->parent = NULL;
            item->child  = NULL;

            /*
             * EDX = child2->byte_value + child1->byte_value;
             * EAX = child1->byte_value;
             * ECX = max_byte; (the greatest character (0xFF usually))
             *       item->byte_value (0x02 usually)
             */
            item->byte_value = child1->byte_value + child2->byte_value;

            /* previous item in the tree. */
            item->child      = child1;
            child1->parent   = item;
            child2->parent   = item;

            /* EAX = item->byte_value */
            if (item->byte_value >= max_byte) {
                max_byte = item->byte_value;
            } else {

                /* EDI */
                struct huffman_tree_item_s *p_item2 = child2->prev;
                found = 0;

                /* check if item is a valid pointer. */
                if (PTR_INT(p_item2) > 0) {

                    /* 15006C2D */
                    do {

                        /* check if we found item. */
                        if (p_item2->byte_value >= item->byte_value) {
                            found = 1;
                            break;
                        }

                        /* switch to previous item. */
                        p_item2 = p_item2->prev;
                    } while (PTR_INT(p_item2) > 0);
                }

                /* check if item was not found. */
                if (found == 0) {
                    p_item2 = NULL;
                }

                /* check if next item exist. */
                if (item->next != 0) {

                    /* some common variables. */
                    struct huffman_tree_item_s *temp4 = libmpq__huffman_previous_item(item, -1);

                    /* zhe first item changed. */
                    temp4->next                     = item->next;

                    /* first->prev changed to negative value. */
                    item->next->prev                = item->prev;
                    item->next                      = NULL;
                    item->prev                      = NULL;
                }

                /* 15006C62 */
                if (p_item2 == NULL) {
                    p_item2 = PTR_PTR(&ht->first);
                }

                /* set item with 0x100 byte value. */
                item->next          = p_item2->next;

                /* set item with 0x17 byte value. */
                item->prev          = p_item2->next->prev;

                /* changed prev of item with. */
                p_item2->next->prev = item;
                p_item2->next       = item;
            }

            /* 15006C7B */
            if (PTR_INT((child1 = child2->prev)) <= 0) {
                break;
            }
        }
    }

    /* 15006C88 */
    ht->offs0004 = 1;
}
Пример #20
0
/* return struct for 1500E820. */
void libmpq__huffman_call_1500E820(struct huffman_tree_s *ht, struct huffman_tree_item_s *p_item) {

    /* EDI */
    struct huffman_tree_item_s *p_item1;

    /* EAX */
    struct huffman_tree_item_s *p_item2 = NULL;

    /* EDX */
    struct huffman_tree_item_s *p_item3;

    /* EBX */
    struct huffman_tree_item_s *p_prev;

    /* loop through parent items. */
    for (; p_item != NULL; p_item = p_item->parent) {

        /* increase byte counter. */
        p_item->byte_value++;

        /* loop through previous items. */
        for (p_item1 = p_item; ; p_item1 = p_prev) {

            /* set previous item. */
            p_prev = p_item1->prev;

            /* check if pointer is valid. */
            if (PTR_INT(p_prev) <= 0) {
                p_prev = NULL;
                break;
            }

            /* check if byte value of previous item is higher than actual item. */
            if (p_prev->byte_value >= p_item->byte_value) {
                break;
            }
        }

        /* check if previous item is same like actual item. */
        if (p_item1 == p_item) {
            continue;
        }

        /* check if next item is not empty, */
        if (p_item1->next != NULL) {

            /* fill values. */
            p_item2             = libmpq__huffman_previous_item(p_item1, -1);
            p_item2->next       = p_item1->next;
            p_item1->next->prev = p_item1->prev;
            p_item1->next       = NULL;
            p_item1->prev       = NULL;
        }

        /* fill values. */
        p_item2       = p_item->next;
        p_item1->next = p_item2;
        p_item1->prev = p_item2->prev;
        p_item2->prev = p_item1;
        p_item->next  = p_item1;

        /* check if both items are not empty. */
        if ((p_item2 = p_item1) != NULL) {

            /* fill values. */
            p_item2            = libmpq__huffman_previous_item(p_item, -1);
            p_item2->next      = p_item->next;
            p_item->next->prev = p_item->prev;
            p_item->next       = NULL;
            p_item->prev       = NULL;
        }

        /* check if previous item is empty. */
        if (p_prev == NULL) {
            p_prev = PTR_PTR(&ht->first);
        }

        /* fill values. */
        p_item2       = p_prev->next;
        p_item->next  = p_item2;
        p_item->prev  = p_item2->prev;
        p_item2->prev = p_item;
        p_prev->next  = p_item;
        p_item3       = p_item1->parent->child;
        p_item2       = p_item->parent;

        /* check if child item and parent item match. */
        if (p_item2->child == p_item) {
            p_item2->child = p_item1;
        }

        /* check if items match. */
        if (p_item3 == p_item1) {
            p_item1->parent->child = p_item;
        }

        /* fill values. */
        p_item2         = p_item->parent;
        p_item->parent  = p_item1->parent;
        p_item1->parent = p_item2;

        /* increase counter. */
        ht->offs0004++;
    }
}
Пример #21
0
/* return struct for 1500E740. */
struct huffman_tree_item_s *libmpq__huffman_call_1500E740(struct huffman_tree_s *ht) {

    /* EDX */
    struct huffman_tree_item_s *p_item1 = ht->item3058;

    /* EAX */
    struct huffman_tree_item_s *p_item2;

    /* some common variables. */
    struct huffman_tree_item_s *p_next;
    struct huffman_tree_item_s *p_prev;
    struct huffman_tree_item_s **pp_item;

    /* check if item is empty. */
    if (PTR_INT(p_item1) <= 0 || (p_item2 = p_item1) == NULL) {

        /* check if item is not empty. */
        if ((p_item2 = &ht->items0008[ht->items++]) != NULL) {
            p_item1 = p_item2;
        } else {
            p_item1 = ht->first;
        }
    } else {
        p_item1 = p_item2;
    }

    /* set next item. */
    p_next = p_item1->next;

    /* check if next item is not empty. */
    if (p_next != NULL) {

        /* set previous item. */
        p_prev = p_item1->prev;

        /* check if previous item is a valid pointer. */
        if (PTR_INT(p_prev) <= 0) {
            p_prev = PTR_NOT(p_prev);
        } else {
            p_prev += (p_item1 - p_item1->next->prev);
        }

        /* fill values. */
        p_prev->next  = p_next;
        p_next->prev  = p_prev;
        p_item1->next = NULL;
        p_item1->prev = NULL;
    }

    /* ESI */
    pp_item       = &ht->first;
    p_item1->next = (struct huffman_tree_item_s *)pp_item;
    p_item1->prev = pp_item[1];

    /* EDI = ht->item305C - ECX */
    p_prev = pp_item[1];

    /* check if previous pointer is valid. */
    if (p_prev <= 0) {

        /* fill values. */
        p_prev          = PTR_NOT(p_prev);
        p_prev->next    = p_item1;
        p_prev->prev    = p_item2;
        p_item2->parent = NULL;
        p_item2->child  = NULL;
    } else {

        /* check if pointer is valid. */
        if (PTR_INT(ht->item305C) < 0) {
            p_prev += (struct huffman_tree_item_s *)pp_item - (*pp_item)->prev;
        } else {
            p_prev += PTR_INT(ht->item305C);
        }

        /* fill values. */
        p_prev->next    = p_item1;
        pp_item[1]      = p_item2;
        p_item2->parent = NULL;
        p_item2->child  = NULL;
    }

    /* return item. */
    return p_item2;
}
Пример #22
0
/* this function insert an item to a huffman tree. */
void libmpq__huffman_insert_item(struct huffman_tree_item_s **p_item, struct huffman_tree_item_s *item, uint32_t where, struct huffman_tree_item_s *item2) {

    /* EDI - next to the first item. */
    struct huffman_tree_item_s *next = item->next;

    /* ESI - prev to the first item. */
    struct huffman_tree_item_s *prev = item->prev;

    /* pointer to previous item. */
    struct huffman_tree_item_s *prev2;

    /* pointer to next item. */
    long next2;

    /* check the first item already has next one. */
    if (next != 0) {

        /* check if previous item exist. */
        if (PTR_INT(prev) < 0) {

            /* return previous item. */
            prev = PTR_NOT(prev);
        } else {

            /* add item. */
            prev += (item - next->prev);
        }

        /* 150083C1 - remove the item from the tree. */
        prev->next = next;
        next->prev = prev;

        /* invalidate prev and next pointer. */
        item->next = 0;
        item->prev = 0;
    }

    /* EDX - check if the second item is not entered. */
    if (item2 == NULL) {

        /* take the first tree item. */
        item2 = PTR_PTR(&p_item[1]);
    }

    /* check if items should be switched or new one inserted. */
    switch (where) {
        case SWITCH_ITEMS:

            /* item2->next (pointer to pointer to first). */
            item->next        = item2->next;
            item->prev        = item2->next->prev;
            item2->next->prev = item;

            /* set the first item. */
            item2->next       = item;

            /* return from function. */
            return;
        case INSERT_ITEM:

            /* set next item (or pointer to pointer to first item) - insert as last item. */
            item->next = item2;

            /* set previous item (or last item in the tree). */
            item->prev = item2->prev;

            /* usually NULL. */
            next2      = PTR_INT(p_item[0]);

            /* previous item to the second (or last tree item). */
            prev2      = item2->prev;

            /* check if previous item is a valid pointer. */
            if (PTR_INT(prev2) < 0) {

                /* set values. */
                prev2       = PTR_NOT(prev);
                prev2->next = item;

                /* next after last item. */
                item2->prev = item;

                /* return from function. */
                return;
            }

            /* check if next item is empty. */
            if (next2 < 0) {

                /* set next item. */
                next2 = item2 - item2->next->prev;
            }

            /* add next item to previous one. */
            prev2       += next2;
            prev2->next  = item;

            /* set the next and last item. */
            item2->prev  = item;

            /* return from function. */
            return;
        default:

            /* nothing to do, so return from function. */
            return;
    }
}
Пример #23
0
void Settings::get_from_gui (Builder &builder, int i)
{
  const char *glade_name = settings[i].glade_name;

  if (glade_name == NULL)
        return; /* Not an automatically connected setting */

  switch (settings[i].type) {
  case T_BOOL: {
    Gtk::CheckButton *check = NULL;
    builder->get_widget (glade_name, check);
    if (!check)
      std::cerr << "Missing boolean config item " << glade_name << "\n";
    else
      *PTR_BOOL(this, i) = check->get_active();
    break;
  }
  case T_INT:
  case T_FLOAT: {
    Gtk::Widget *w = NULL;
    builder->get_widget (glade_name, w);
    if (!w) {
      std::cerr << "Missing GUI element " << glade_name << "\n";
      break;
    }

    Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w);
    if (spin) {
      if (settings[i].type == T_INT)
          *PTR_INT(this, i) = spin->get_value();
      else
          *PTR_FLOAT(this, i) = spin->get_value();
      break;
    }

    Gtk::Range *range = dynamic_cast<Gtk::Range *>(w);
    if (range) {
      if (settings[i].type == T_INT)
          *PTR_INT(this, i) = range->get_value();
      else
          *PTR_FLOAT(this, i) = range->get_value();
    }
    break;
  }
  case T_STRING: {
    Gtk::Entry *e = NULL;
    builder->get_widget (glade_name, e);
    if (!e) {
      std::cerr << "Missing user interface item " << glade_name << "\n";
      break;
    }
    *PTR_STRING(this, i) = std::string(e->get_text());
    break;
  }
  case T_COLOUR_MEMBER:
    // Ignore, colour members are special
    break;
  default:
    std::cerr << "corrupt setting type\n";
    break;
  }

  if (settings[i].triggers_redraw)
    m_signal_visual_settings_changed.emit();
}
Пример #24
0
static struct huffman_tree_item *libmpq_huff_call1500E740(struct huffman_tree *ht, unsigned int value) {
	struct huffman_tree_item *p_item1 = ht->item3058;	/* EDX */
	struct huffman_tree_item *p_item2;			/* EAX */
	struct huffman_tree_item *p_next;
	struct huffman_tree_item *p_prev;
	struct huffman_tree_item **pp_item;

	if (PTR_INT(p_item1) <= 0 || (p_item2 = p_item1) == NULL) {
		if((p_item2 = &ht->items0008[ht->items++]) != NULL) {
			p_item1 = p_item2;
		} else {
			p_item1 = ht->first;
		}
	} else {
		p_item1 = p_item2;
	}

	p_next = p_item1->next;
	if (p_next != NULL) {
		p_prev = p_item1->prev;
		if (PTR_INT(p_prev) <= 0) {
			p_prev = PTR_NOT(p_prev);
		} else {
			p_prev += (p_item1 - p_item1->next->prev);
		}

		p_prev->next = p_next;
		p_next->prev = p_prev;
		p_item1->next = NULL;
		p_item1->prev = NULL;
	}
	pp_item = &ht->first;				/* ESI */
	if (value > 1) {

		/* ECX = ht->first->next; */
		p_item1->next = *pp_item;
		p_item1->prev = (*pp_item)->prev;

		(*pp_item)->prev = p_item2;
		*pp_item = p_item1;

		p_item2->parent = NULL;
		p_item2->child  = NULL;
	} else {
		p_item1->next = (struct huffman_tree_item *)pp_item;
		p_item1->prev = pp_item[1];
		/* EDI = ht->item305C; */
		p_prev = pp_item[1];			/* ECX */
		if (p_prev <= 0) {
			p_prev = PTR_NOT(p_prev);
			p_prev->next = p_item1;
			p_prev->prev = p_item2;

			p_item2->parent = NULL;
			p_item2->child  = NULL;
		} else {
			if (PTR_INT(ht->item305C) < 0) {
				p_prev += (struct huffman_tree_item *)pp_item - (*pp_item)->prev;
			} else {
				p_prev += PTR_INT(ht->item305C);
			}

			p_prev->next    = p_item1;
			pp_item[1]      = p_item2;
			p_item2->parent = NULL;
			p_item2->child  = NULL;
		}
	}
	return p_item2;
}
Пример #25
0
static void match_memcpy(const char *fn, struct expression *expr, void *arg)
{
	db_param_cleared(expr, PTR_INT(arg), (char *)"$$", (char *)"");
}
Пример #26
0
/* Builds Huffman tree. Called with the first 8 bits loaded from input stream. */
static void libmpq_huff_build_tree(struct huffman_tree *ht, unsigned int cmp_type) {
	unsigned long max_byte;				/* [ESP+10] - The greatest character found in table */
	unsigned char *byte_array;			/* [ESP+1C] - Pointer to unsigned char in table1502A630 */
	unsigned long i;				/* egcs in linux doesn't like multiple for loops without an explicit i */
	unsigned int found;				/* Thats needed to replace the goto stuff from original source :) */
	struct huffman_tree_item **p_item;		/* [ESP+14] - Pointer to Huffman tree item pointer array */
	struct huffman_tree_item *child1;

	/* Loop while pointer has a negative value. */
	while (PTR_INT(ht->last) > 0) {			/* ESI - Last entry */
		struct huffman_tree_item *temp;		/* EAX */
        
		if (ht->last->next != NULL) {		/* ESI->next */
			libmpq_huff_remove_item(ht->last);
		}
		ht->item3058   = PTR_PTR(&ht->item3054);/* [EDI+4] */
		ht->last->prev = ht->item3058;		/* EAX */
		temp           = libmpq_huff_get_prev_item(PTR_PTR(&ht->item3054), PTR_INT(&ht->item3050));
		temp->next     = ht->last;
		ht->item3054   = ht->last;
	}

	/* Clear all pointers in huffman tree item array. */
	memset(ht->items306C, 0, sizeof(ht->items306C));

	max_byte = 0;					/* Greatest character found init to zero. */
	p_item = (struct huffman_tree_item **)&ht->items306C;	/* Pointer to current entry in huffman tree item pointer array */

	/* Ensure we have low 8 bits only */
	cmp_type   &= 0xFF;
	byte_array  = table1502A630 + cmp_type * 258;	/* EDI also */

	for (i = 0; i < 0x100; i++, p_item++) {
		struct huffman_tree_item *item = ht->item3058;	/* Item to be created */
		struct huffman_tree_item *p_item3 = ht->item3058;
		unsigned char one_byte = byte_array[i];

		/* Skip all the bytes which are zero. */
		if (byte_array[i] == 0) {
			continue;
		}

		/* If not valid pointer, take the first available item in the array. */
		if (PTR_INT(item) <= 0) {
			item = &ht->items0008[ht->items++];
		}

		/* Insert this item as the top of the tree. */
		libmpq_huff_insert_item(&ht->item305C, item, SWITCH_ITEMS, NULL);

		item->parent    = NULL;			/* Invalidate child and parent */
		item->child     = NULL;
		*p_item         = item;			/* Store pointer into pointer array */

		item->dcmp_byte  = i;			/* Store counter */
		item->byte_value = one_byte;		/* Store byte value */
		if (one_byte >= max_byte) {
			max_byte = one_byte;
			continue;
		}

		/* Find the first item which has byte value greater than current one byte */
		found = 0;
		if (PTR_INT((p_item3 = ht->last)) > 0) {/* EDI - Pointer to the last item */

			/* 15006AF7 */
			if (p_item3 != NULL) {
				do {			/* 15006AFB */
					if (p_item3->byte_value >= one_byte) {
						found = 1;
						break;
					}
					p_item3 = p_item3->prev;
				} while (PTR_INT(p_item3) > 0);
			}
		}

		if (found == 0) {
			p_item3 = NULL;
		}

		/* 15006B09 */
		if (item->next != NULL) {
			libmpq_huff_remove_item(item);
		}

		/* 15006B15 */
		if (p_item3 == NULL) {
			p_item3 = PTR_PTR(&ht->first);
		}

		/* 15006B1F */
		item->next = p_item3->next;
		item->prev = p_item3->next->prev;
		p_item3->next->prev = item;
		p_item3->next = item;
	}

	/* 15006B4A */
	for (; i < 0x102; i++) {
		struct huffman_tree_item **p_item2 = &ht->items306C[i];	/* EDI */

		/* 15006B59  */
		struct huffman_tree_item *item2 = ht->item3058;	/* ESI */
		if (PTR_INT(item2) <= 0) {
			item2 = &ht->items0008[ht->items++];
		}
		libmpq_huff_insert_item(&ht->item305C, item2, INSERT_ITEM, NULL);

		/* 15006B89 */
		item2->dcmp_byte  = i;
		item2->byte_value = 1;
		item2->parent     = NULL;
		item2->child      = NULL;
		*p_item2++        = item2;
	}

	/* 15006BAA */
	if (PTR_INT((child1 = ht->last)) > 0) {		/* EDI - last item (first child to item */
		struct huffman_tree_item *child2;	/* EBP */
		struct huffman_tree_item *item;		/* ESI */

		/* 15006BB8 */
		while (PTR_INT((child2 = child1->prev)) > 0) {
			if (PTR_INT((item = ht->item3058)) <= 0) {
				item = &ht->items0008[ht->items++];
			}
			/* 15006BE3 */
			libmpq_huff_insert_item(&ht->item305C, item, SWITCH_ITEMS, NULL);

			/* 15006BF3 */
			item->parent = NULL;
			item->child  = NULL;

			/*
			 * EDX = child2->byte_value + child1->byte_value;
			 * EAX = child1->byte_value;
			 * ECX = max_byte;		The greatest character (0xFF usually)
			 */
			item->byte_value = child1->byte_value + child2->byte_value;	/* 0x02 */
			item->child      = child1;	/* Prev item in the */
			child1->parent   = item;
			child2->parent   = item;

			/* EAX = item->byte_value; */
			if (item->byte_value >= max_byte) {
				max_byte = item->byte_value;
			} else {
				struct huffman_tree_item *p_item2 = child2->prev;	/* EDI */
				found = 0;
				if (PTR_INT(p_item2) > 0) {

					/* 15006C2D */
					do {
						if (p_item2->byte_value >= item->byte_value) {
							found = 1;
							break;
						}
						p_item2 = p_item2->prev;
					} while (PTR_INT(p_item2) > 0);
				}
				if (found == 0) {
					p_item2 = NULL;
				}
				if (item->next != 0) {
					struct huffman_tree_item *temp4 = libmpq_huff_get_prev_item(item, -1);
					temp4->next      = item->next;	/* The first item changed */
					item->next->prev = item->prev;	/* First->prev changed to negative value */
					item->next = NULL;
					item->prev = NULL;
				}

				/* 15006C62 */
				if (p_item2 == NULL) {
					p_item2 = PTR_PTR(&ht->first);
				}
				item->next = p_item2->next;		/* Set item with 0x100 byte value */
				item->prev = p_item2->next->prev;	/* Set item with 0x17 byte value */
				p_item2->next->prev = item;		/* Changed prev of item with */
				p_item2->next = item;
			}

			/* 15006C7B */
			if (PTR_INT((child1 = child2->prev)) <= 0) {
				break;
			}
		}
	}

	/* 15006C88 */
	ht->offs0004 = 1;
}
Пример #27
0
// Builds Huffman tree. Called with the first 8 bits loaded from input stream
void THuffmannTree::BuildTree(unsigned int nCmpType)
{
    unsigned long   maxByte;                // [ESP+10] - The greatest character found in table
    THTreeItem   ** itemPtr;                // [ESP+14] - Pointer to Huffman tree item pointer array
    unsigned char * byteArray;              // [ESP+1C] - Pointer to unsigned char in Table1502A630
    THTreeItem    * child1;
    unsigned long   i;                      // egcs in linux doesn't like multiple for loops without an explicit i

    // Loop while pointer has a valid value
    while(PTR_VALID(pLast))                 // ESI - Last entry
    {
        THTreeItem * temp;                  // EAX

        if(pLast->next != NULL)             // ESI->next
            pLast->RemoveItem();
                                            // EDI = &offs3054
        pItem3058   = PTR_PTR(&pItem3054);  // [EDI+4]
        pLast->prev = pItem3058;            // EAX

        temp = PTR_PTR(&pItem3054)->GetPrevItem(PTR_INT(&pItem3050));

        temp->next = pLast;
        pItem3054  = pLast;
    }

    // Clear all pointers in HTree item array
    memset(items306C, 0, sizeof(items306C));

    maxByte = 0;                            // Greatest character found init to zero.
    itemPtr = (THTreeItem **)&items306C;    // Pointer to current entry in HTree item pointer array

    // Ensure we have low 8 bits only
    nCmpType &= 0xFF;
    byteArray  = Table1502A630 + nCmpType * 258; // EDI also

    for(i = 0; i < 0x100; i++, itemPtr++)
    {
        THTreeItem * item   = pItem3058;    // Item to be created
        THTreeItem * pItem3 = pItem3058;
        unsigned char         oneByte = byteArray[i];

        // Skip all the bytes which are zero.
        if(byteArray[i] == 0)
            continue;

        // If not valid pointer, take the first available item in the array
        if(PTR_INVALID_OR_NULL(item))
            item = &items0008[nItems++];

        // Insert this item as the top of the tree
        InsertItem(&pItem305C, item, SWITCH_ITEMS, NULL);

        item->parent    = NULL;                 // Invalidate child and parent
        item->child     = NULL;
        *itemPtr        = item;                 // Store pointer into pointer array

        item->dcmpByte  = i;                    // Store counter
        item->byteValue = oneByte;              // Store byte value
        if(oneByte >= maxByte)
        {
            maxByte = oneByte;
            continue;
        }

        // Find the first item which has byte value greater than current one byte
        if(PTR_VALID(pItem3 = pLast))           // EDI - Pointer to the last item
        {
            // 15006AF7
            if(pItem3 != NULL)
            {
                do  // 15006AFB
                {
                    if(pItem3->byteValue >= oneByte)
                        goto _15006B09;
                    pItem3 = pItem3->prev;
                }
                while(PTR_VALID(pItem3));
            }
        }
        pItem3 = NULL;

        // 15006B09
        _15006B09:
        if(item->next != NULL)
            item->RemoveItem();

        // 15006B15
        if(pItem3 == NULL)
            pItem3 = PTR_PTR(&pFirst);

        // 15006B1F
        item->next = pItem3->next;
        item->prev = pItem3->next->prev;
        pItem3->next->prev = item;
        pItem3->next = item;
    }

    // 15006B4A
    for(; i < 0x102; i++)
    {
        THTreeItem ** itemPtr = &items306C[i];  // EDI

        // 15006B59
        THTreeItem * item = pItem3058;          // ESI
        if(PTR_INVALID_OR_NULL(item))
            item = &items0008[nItems++];

        InsertItem(&pItem305C, item, INSERT_ITEM, NULL);

        // 15006B89
        item->dcmpByte   = i;
        item->byteValue  = 1;
        item->parent     = NULL;
        item->child      = NULL;
        *itemPtr++ = item;
    }

    // 15006BAA
    if(PTR_VALID(child1 = pLast))                   // EDI - last item (first child to item
    {
        THTreeItem * child2;                        // EBP
        THTreeItem * item;                          // ESI

        // 15006BB8
        while(PTR_VALID(child2 = child1->prev))
        {
            if(PTR_INVALID_OR_NULL(item = pItem3058))
                item = &items0008[nItems++];

            // 15006BE3
            InsertItem(&pItem305C, item, SWITCH_ITEMS, NULL);

            // 15006BF3
            item->parent = NULL;
            item->child  = NULL;

            //EDX = child2->byteValue + child1->byteValue;
            //EAX = child1->byteValue;
            //ECX = maxByte;                        // The greatest character (0xFF usually)

            item->byteValue = child1->byteValue + child2->byteValue; // 0x02
            item->child     = child1;                                // Prev item in the
            child1->parent  = item;
            child2->parent  = item;

            // EAX = item->byteValue;
            if(item->byteValue >= maxByte)
                maxByte = item->byteValue;
            else
            {
                THTreeItem * pItem2 = child2->prev;   // EDI

                // 15006C2D
                while(PTR_VALID(pItem2))
                {
                    if(pItem2->byteValue >= item->byteValue)
                        goto _15006C3B;
                    pItem2 = pItem2->prev;
                }
                pItem2 = NULL;

                _15006C3B:
                if(item->next != 0)
                {
                    THTreeItem * temp4 = item->GetPrevItem(-1);

                    temp4->next      = item->next;                 // The first item changed
                    item->next->prev = item->prev;                 // First->prev changed to negative value
                    item->next = NULL;
                    item->prev = NULL;
                }

                // 15006C62
                if(pItem2 == NULL)
                    pItem2 = PTR_PTR(&pFirst);

                item->next = pItem2->next;                           // Set item with 0x100 byte value
                item->prev = pItem2->next->prev;                     // Set item with 0x17 byte value
                pItem2->next->prev = item;                           // Changed prev of item with
                pItem2->next = item;
            }

            // 15006C7B
            if(PTR_INVALID_OR_NULL(child1 = child2->prev))
                break;
        }
    }
    // 15006C88
    offs0004 = 1;
}
Пример #28
0
static void libmpq_huff_call1500E820(struct huffman_tree *ht, struct huffman_tree_item *p_item) {
	struct huffman_tree_item *p_item1;		/* EDI */
	struct huffman_tree_item *p_item2 = NULL;	/* EAX */
	struct huffman_tree_item *p_item3;		/* EDX */
	struct huffman_tree_item *p_prev;		/* EBX */

	for (; p_item != NULL; p_item = p_item->parent) {
		p_item->byte_value++;

		for (p_item1 = p_item; ; p_item1 = p_prev) {
			p_prev = p_item1->prev;
			if (PTR_INT(p_prev) <= 0) {
				p_prev = NULL;
				break;
			}
			if (p_prev->byte_value >= p_item->byte_value) {
				break;
			}
		}

		if (p_item1 == p_item) {
			continue;
		}

		if (p_item1->next != NULL) {
			p_item2 = libmpq_huff_get_prev_item(p_item1, -1);
			p_item2->next = p_item1->next;
			p_item1->next->prev = p_item1->prev;
			p_item1->next = NULL;
			p_item1->prev = NULL;
		}
		p_item2 = p_item->next;
		p_item1->next = p_item2;
		p_item1->prev = p_item2->prev;
		p_item2->prev = p_item1;
		p_item->next = p_item1;
		if ((p_item2 = p_item1) != NULL) {
			p_item2 = libmpq_huff_get_prev_item(p_item, -1);
			p_item2->next = p_item->next;
			p_item->next->prev = p_item->prev;
			p_item->next = NULL;
			p_item->prev = NULL;
		}

		if (p_prev == NULL) {
			p_prev = PTR_PTR(&ht->first);
		}
		p_item2       = p_prev->next;
		p_item->next  = p_item2;
		p_item->prev  = p_item2->prev;
		p_item2->prev = p_item;
		p_prev->next  = p_item;

		p_item3 = p_item1->parent->child;
		p_item2 = p_item->parent;
		if (p_item2->child == p_item) {
			p_item2->child = p_item1;
		}

		if (p_item3 == p_item1) {
			p_item1->parent->child = p_item;
		}

		p_item2 = p_item->parent;
		p_item->parent  = p_item1->parent;
		p_item1->parent = p_item2;
		ht->offs0004++;
	}
}
Пример #29
0
THTreeItem * THuffmannTree::Call1500E740(unsigned int nValue)
{
    THTreeItem * pItem1 = pItem3058;    // EDX
    THTreeItem * pItem2;                // EAX
    THTreeItem * pNext;
    THTreeItem * pPrev;
    THTreeItem ** ppItem;

    if(PTR_INVALID_OR_NULL(pItem1) || (pItem2 = pItem1) == NULL)
    {
        if((pItem2 = &items0008[nItems++]) != NULL)
            pItem1 = pItem2;
        else
            pItem1 = pFirst;
    }
    else
        pItem1 = pItem2;

    pNext = pItem1->next;
    if(pNext != NULL)
    {
        pPrev = pItem1->prev;
        if(PTR_INVALID_OR_NULL(pPrev))
            pPrev = PTR_NOT(pPrev);
        else
            pPrev += (pItem1 - pItem1->next->prev);

        pPrev->next = pNext;
        pNext->prev = pPrev;
        pItem1->next = NULL;
        pItem1->prev = NULL;
    }

    ppItem = &pFirst;       // esi
    if(nValue > 1)
    {
        // ecx = pFirst->next;
        pItem1->next = *ppItem;
        pItem1->prev = (*ppItem)->prev;

        (*ppItem)->prev = pItem2;
        *ppItem = pItem1;

        pItem2->parent = NULL;
        pItem2->child  = NULL;
    }
    else
    {
        pItem1->next = (THTreeItem *)ppItem;
        pItem1->prev = ppItem[1];
        // edi = pItem305C;
        pPrev = ppItem[1];      // ecx
        if(PTR_INVALID_OR_NULL(pPrev))
        {
            pPrev = PTR_NOT(pPrev);
            pPrev->next = pItem1;
            pPrev->prev = pItem2;

            pItem2->parent = NULL;
            pItem2->child  = NULL;
        }
        else
        {
            if(PTR_INVALID(pItem305C))
                pPrev += (THTreeItem *)ppItem - (*ppItem)->prev;
            else
                pPrev += PTR_INT(pItem305C);

            pPrev->next    = pItem1;
            ppItem[1]      = pItem2;
            pItem2->parent = NULL;
            pItem2->child  = NULL;
        }
    }
    return pItem2;
}