///////////////////////////////////////////////////////////////////////////// // // only modifies *psource and *pdir on success // static int addarchive( struct PSF2FS *fs, const uint8_t *reserved_data, int reserved_size, struct SOURCE_FILE **psource, struct DIR_ENTRY **pdir ) { struct SOURCE_FILE *source = *psource; struct DIR_ENTRY *dir = *pdir; // these relate to the current file struct SOURCE_FILE *this_source = NULL; struct DIR_ENTRY *this_dir = NULL; // default to no error fs->adderror = 0; // create a source entry for this psf2 this_source = ( struct SOURCE_FILE * ) malloc( sizeof( struct SOURCE_FILE ) ); if(!this_source) goto outofmemory; this_source->reserved_data = ( uint8_t * ) malloc( reserved_size ); if(!this_source->reserved_data) goto outofmemory; memcpy(this_source->reserved_data, reserved_data, reserved_size); this_source->reserved_size = reserved_size; this_source->next = NULL; this_dir = makearchivedir(fs, 0, this_source); if(fs->adderror) goto error; // success // now merge everything *psource = mergesource(source, this_source); *pdir = mergedir(dir, this_dir); //success: return 0; outofmemory: goto error; error: if(dir) dir_cleanup_free(dir); if(source) source_cleanup_free(source); if(this_dir) dir_cleanup_free(this_dir); if(this_source) source_cleanup_free(this_source); return -1; }
static void addsrcspan( /* add new source span to our list */ struct srcspan *nss ) { struct source *last, *cs, *this; register struct srcspan *ss; cs = NULL; for (this = curlist; this != NULL; this = this->next) { for (ss = this->first; ss != NULL; ss = ss->next) { if (!vcont(nss->v, ss->v)) break; if (hcont(ss, nss)) { if (cs == NULL) cs = this; else { last->next = this->next; mergesource(cs, this); this = last; } break; } } last = this; } if (cs == NULL) { cs = (struct source *)malloc(sizeof(struct source)); if (cs == NULL) memerr("source records"); cs->dom = 0.0; cs->first = NULL; cs->next = curlist; curlist = cs; } nss->next = cs->first; cs->first = nss; }
extern void absorb_specks(void) /* eliminate too-small sources */ { struct source head, *buddy; register struct source *last, *this; if (verbose) fprintf(stderr, "%s: absorbing small sources...\n", progname); head.next = donelist; last = &head; for (this = head.next; this != NULL; this = this->next) if (TOOSMALL(this)) { last->next = this->next; buddy = findbuddy(this, head.next); if (buddy != NULL) mergesource(buddy, this); else absorb(this); this = last; } else last = this; donelist = head.next; }