- {
- if (j < flush)
- {
- /* There is not enough room to write the new entry in this
- block or in a parent block. */
-
- if (j + 1 == level)
- {
- BFD_ASSERT (level < MAX_LEVEL);
-
- /* Need to create a parent. */
- if (abfd != NULL)
- {
- rblk[level] = bfd_malloc (sizeof (struct vms_indexdef));
- bfd_putl32 (*vbn, rblk[j]->parent);
- }
- blk[level].vbn = (*vbn)++;
- blk[level].len = 0;
- blk[level].lastlen = 0;
-
- level++;
- }
-
- /* Update parent block: write the new entry. */
- if (abfd != NULL)
- {
- struct vms_rfa *rfa;
-
- /* Copy the whole entry. */
- memcpy (rblk[j + 1]->keys + blk[j + 1].len,
- rblk[j]->keys + blk[j].len,
- blk[j].lastlen);
- /* Fix the entry (which in always the first field of an entry. */
- rfa = (struct vms_rfa *)(rblk[j + 1]->keys + blk[j + 1].len);
- bfd_putl32 (blk[j].vbn, rfa->vbn);
- bfd_putl16 (RFADEF__C_INDEX, rfa->offset);
- }
-
- if (j + 1 == flush)
- {
- /* And allocate it. Do it only on the block that won't be
- flushed (so that the parent of the parent can be
- updated too). */
- blk[j + 1].len += blk[j].lastlen;
- blk[j + 1].lastlen = 0;
- }
-
- /* Write this block on the disk. */
- if (abfd != NULL)
- {
- bfd_putl16 (blk[j].len + blk[j].lastlen, rblk[j]->used);
- if (vms_write_block (abfd, blk[j].vbn, rblk[j]) != TRUE)
- return FALSE;
- }
-
- /* Reset this block. */
- blk[j].len = 0;
- blk[j].lastlen = 0;
- blk[j].vbn = (*vbn)++;
- }
-
- /* Append it to the block. */
- if (j == 0)
- {
- blk[j].len += blk[j].lastlen;
-
- if (abfd != NULL)
- {
- struct vms_rfa *rfa;
-
- rfa = (struct vms_rfa *)(rblk[j]->keys + blk[j].len);
- bfd_putl32 ((idx->abfd->proxy_origin / VMS_BLOCK_SIZE) + 1,
- rfa->vbn);
- bfd_putl16
- ((idx->abfd->proxy_origin % VMS_BLOCK_SIZE)
- + (is_elfidx ? 0 : DATA__DATA),
- rfa->offset);
-
- if (is_elfidx)
- {
- /* Use elfidx format. */
- struct vms_elfidx *en = (struct vms_elfidx *)rfa;
-
- en->flags = 0;
- if (key_vbn != 0)
- {
- /* Long symbol name. */
- struct vms_kbn *k = (struct vms_kbn *)(en->keyname);
- bfd_putl16 (sizeof (struct vms_kbn), en->keylen);
- bfd_putl16 (idx->namlen, k->keylen);
- bfd_putl32 (key_vbn, k->rfa.vbn);
- bfd_putl16 (key_off, k->rfa.offset);
- en->flags |= ELFIDX__SYMESC;
- }
- else
- {
- bfd_putl16 (idx->namlen, en->keylen);
- memcpy (en->keyname, idx->name, idx->namlen);
- }
- }
- else
- {
- /* Use idx format. */
- struct vms_idx *en = (struct vms_idx *)rfa;
- en->keylen = idx->namlen;
- memcpy (en->keyname, idx->name, idx->namlen);
- }
- }
- }
-
- blk[j].lastlen = idxlen;
- }
+ {
+ if (j < flush)
+ {
+ /* There is not enough room to write the new entry in this
+ block or in a parent block. */
+
+ if (j + 1 == level)
+ {
+ BFD_ASSERT (level < MAX_LEVEL);
+
+ /* Need to create a parent. */
+ if (abfd != NULL)
+ {
+ rblk[level] = bfd_zmalloc (sizeof (struct vms_indexdef));
+ bfd_putl32 (*vbn, rblk[j]->parent);
+ }
+ blk[level].vbn = (*vbn)++;
+ blk[level].len = 0;
+ blk[level].lastlen = blk[j].lastlen;
+
+ level++;
+ }
+
+ /* Update parent block: write the last entry from the current
+ block. */
+ if (abfd != NULL)
+ {
+ struct vms_rfa *rfa;
+
+ /* Pointer to the last entry in parent block. */
+ rfa = (struct vms_rfa *)(rblk[j + 1]->keys + blk[j + 1].len);
+
+ /* Copy the whole entry. */
+ BFD_ASSERT (blk[j + 1].lastlen == blk[j].lastlen);
+ memcpy (rfa, rblk[j]->keys + blk[j].len, blk[j].lastlen);
+ /* Fix the entry (which in always the first field of an
+ entry. */
+ bfd_putl32 (blk[j].vbn, rfa->vbn);
+ bfd_putl16 (RFADEF__C_INDEX, rfa->offset);
+ }
+
+ if (j + 1 == flush)
+ {
+ /* And allocate it. Do it only on the block that won't be
+ flushed (so that the parent of the parent can be
+ updated too). */
+ blk[j + 1].len += blk[j + 1].lastlen;
+ blk[j + 1].lastlen = 0;
+ }
+
+ /* Write this block on the disk. */
+ if (abfd != NULL)
+ {
+ bfd_putl16 (blk[j].len + blk[j].lastlen, rblk[j]->used);
+ if (!vms_write_block (abfd, blk[j].vbn, rblk[j]))
+ return FALSE;
+ }
+
+ /* Reset this block. */
+ blk[j].len = 0;
+ blk[j].lastlen = 0;
+ blk[j].vbn = (*vbn)++;
+ }
+
+ /* Append it to the block. */
+ if (j == 0)
+ {
+ /* Keep the previous last entry. */
+ blk[j].len += blk[j].lastlen;
+
+ if (abfd != NULL)
+ {
+ struct vms_rfa *rfa;
+
+ rfa = (struct vms_rfa *)(rblk[j]->keys + blk[j].len);
+ bfd_putl32 ((idx->abfd->proxy_origin / VMS_BLOCK_SIZE) + 1,
+ rfa->vbn);
+ bfd_putl16
+ ((idx->abfd->proxy_origin % VMS_BLOCK_SIZE)
+ + (is_elfidx ? 0 : DATA__DATA),
+ rfa->offset);
+
+ if (is_elfidx)
+ {
+ /* Use elfidx format. */
+ struct vms_elfidx *en = (struct vms_elfidx *)rfa;
+
+ en->flags = 0;
+ if (key_vbn != 0)
+ {
+ /* Long symbol name. */
+ struct vms_kbn *k = (struct vms_kbn *)(en->keyname);
+ bfd_putl16 (sizeof (struct vms_kbn), en->keylen);
+ bfd_putl16 (idx->namlen, k->keylen);
+ bfd_putl32 (key_vbn, k->rfa.vbn);
+ bfd_putl16 (key_off, k->rfa.offset);
+ en->flags |= ELFIDX__SYMESC;
+ }
+ else
+ {
+ bfd_putl16 (idx->namlen, en->keylen);
+ memcpy (en->keyname, idx->name, idx->namlen);
+ }
+ }
+ else
+ {
+ /* Use idx format. */
+ struct vms_idx *en = (struct vms_idx *)rfa;
+ en->keylen = idx->namlen;
+ memcpy (en->keyname, idx->name, idx->namlen);
+ }
+ }
+ }
+ /* The last added key can now be the last one all blocks in the
+ path. */
+ blk[j].lastlen = idxlen;
+ }