/[zanavi_public1]/navit/navit/maptool/itembin.c
ZANavi

Diff of /navit/navit/maptool/itembin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 56 Revision 57
738 int j, k, count, rc = 0; 738 int j, k, count, rc = 0;
739 struct coord *c; 739 struct coord *c;
740 struct item_bin *ib; 740 struct item_bin *ib;
741 FILE *f; 741 FILE *f;
742 unsigned char *p, **idx, *buffer; 742 unsigned char *p, **idx, *buffer;
743
743 if (file_get_contents(in_file, &buffer, size)) 744 if (file_get_contents(in_file, &buffer, size))
744 { 745 {
745 ib = (struct item_bin *) buffer; 746 ib = (struct item_bin *) buffer;
746 p = buffer; 747 p = buffer;
747 count = 0; 748 count = 0;
749
748 while (p < buffer + *size) 750 while (p < buffer + *size)
749 { 751 {
750 count++; 752 count++;
751 p += (*((int *) p) + 1) * 4; 753 p += (*((int *) p) + 1) * 4;
752 } 754 }
755
756 // idx = malloc(count * sizeof(void *));
753 idx = malloc(count * sizeof(void *)); 757 idx = g_malloc(count * sizeof(void *));
754 dbg_assert(idx != NULL); 758 dbg_assert(idx != NULL);
759
755 p = buffer; 760 p = buffer;
756 for (j = 0; j < count; j++) 761 for (j = 0; j < count; j++)
757 { 762 {
758 idx[j] = p; 763 idx[j] = p;
759 p += (*((int *) p) + 1) * 4; 764 p += (*((int *) p) + 1) * 4;
760 } 765 }
766
761 qsort(idx, count, sizeof(void *), item_bin_sort_compare); 767 qsort(idx, count, sizeof(void *), item_bin_sort_compare);
762 f = fopen(out_file, "wb"); 768 f = fopen(out_file, "wb");
769
763 for (j = 0; j < count; j++) 770 for (j = 0; j < count; j++)
764 { 771 {
765 ib = (struct item_bin *) (idx[j]); 772 ib = (struct item_bin *) (idx[j]);
766 c = (struct coord *) (ib + 1); 773 c = (struct coord *) (ib + 1);
767 fwrite(ib, (ib->len + 1) * 4, 1, f); 774 fwrite(ib, (ib->len + 1) * 4, 1, f);
775
768 if (r) 776 if (r)
769 { 777 {
770 for (k = 0; k < ib->clen / 2; k++) 778 for (k = 0; k < ib->clen / 2; k++)
771 { 779 {
772 if (rc) 780 if (rc)
781 {
773 bbox_extend(&c[k], r); 782 bbox_extend(&c[k], r);
783 }
774 else 784 else
775 { 785 {
776 r->l = c[k]; 786 r->l = c[k];
777 r->h = c[k]; 787 r->h = c[k];
778 } 788 }
779 rc++; 789 rc++;
780 } 790 }
781 } 791 }
782 } 792 }
783 fclose(f); 793 fclose(f);
794 g_free(idx);
795
796
797 // not sure about this one ???????????? --------------
798 g_free(buffer);
799 // not sure about this one ???????????? --------------
800
801
784 return 1; 802 return 1;
785 } 803 }
786 return 0; 804 return 0;
787} 805}
788 806

Legend:
Removed from v.56  
changed lines
  Added in v.57

   
Visit the ZANavi Wiki