1/* Create new subsection section in given section. 2 Copyright (C) 2002 Red Hat, Inc. 3 Written by Ulrich Drepper <drepper@redhat.com>, 2002. 4 5 This program is Open Source software; you can redistribute it and/or 6 modify it under the terms of the Open Software License version 1.0 as 7 published by the Open Source Initiative. 8 9 You should have received a copy of the Open Software License along 10 with this program; if not, you may obtain a copy of the Open Software 11 License version 1.0 from http://www.opensource.org/licenses/osl.php or 12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq., 13 3001 King Ranch Road, Ukiah, CA 95482. */ 14 15#ifdef HAVE_CONFIG_H 16# include <config.h> 17#endif 18 19#include <stdlib.h> 20 21#include <libasmP.h> 22#include <system.h> 23 24 25AsmScn_t * 26asm_newsubscn (asmscn, nr) 27 AsmScn_t *asmscn; 28 unsigned int nr; 29{ 30 AsmScn_t *runp; 31 AsmScn_t *newp; 32 33 /* Just return if no section is given. The error must have been 34 somewhere else. */ 35 if (asmscn == NULL) 36 return NULL; 37 38 /* Determine whether there is already a subsection with this number. */ 39 runp = asmscn->subsection_id == 0 ? asmscn : asmscn->data.up; 40 while (1) 41 { 42 if (runp->subsection_id == nr) 43 /* Found it. */ 44 return runp; 45 46 if (runp->subnext == NULL || runp->subnext->subsection_id > nr) 47 break; 48 49 runp = runp->subnext; 50 } 51 52 newp = (AsmScn_t *) malloc (sizeof (AsmScn_t)); 53 if (newp == NULL) 54 return NULL; 55 56 /* Same assembler context than the original section. */ 57 newp->ctx = runp->ctx; 58 59 /* User provided the subsectio nID. */ 60 newp->subsection_id = nr; 61 62 /* Inherit the parent's type. */ 63 newp->type = runp->type; 64 65 /* Pointer to the zeroth subsection. */ 66 newp->data.up = runp->subsection_id == 0 ? runp : runp->data.up; 67 68 /* We start at offset zero. */ 69 newp->offset = 0; 70 /* And generic alignment. */ 71 newp->max_align = 1; 72 73 /* No output yet. */ 74 newp->content = NULL; 75 76 /* Inherit the fill pattern from the section this one is derived from. */ 77 newp->pattern = asmscn->pattern; 78 79 /* Enqueue at the right position in the list. */ 80 newp->subnext = runp->subnext; 81 runp->subnext = newp; 82 83 return newp; 84} 85