static tsf_bool_t tear_down_mode(tsf_adpt_rdr_t *reader, uint8_t **spillover, uint32_t *spillover_len) { tsf_bool_t stillok=tsf_true; if (reader->mode==TSF_ZIP_ZLIB) { #ifdef HAVE_ZLIB inflateEnd(Cz(reader)); #endif } else if (reader->mode==TSF_ZIP_BZIP2) { #ifdef HAVE_BZIP2 BZ2_bzDecompressEnd(Cbz(reader)); #endif } if (reader->mode==TSF_ZIP_ZLIB || reader->mode==TSF_ZIP_BZIP2) { free(reader->stream); if (spillover!=NULL && spillover_len!=NULL) { *spillover=malloc(reader->abstract.avail_in); if (*spillover==NULL) { tsf_set_errno("Could not allocate spillover buffer"); stillok=tsf_false; } else { *spillover_len=reader->abstract.avail_in; memcpy(*spillover,reader->abstract.next_in,*spillover_len); } } } else if (reader->mode==TSF_ZIP_NONE) { if (spillover!=NULL && spillover_len!=NULL) { *spillover=malloc(reader->puti-reader->geti); if (*spillover==NULL) { tsf_set_errno("Could not allocate spillover buffer"); stillok=tsf_false; } else { *spillover_len=reader->puti-reader->geti; memcpy(*spillover,reader->buf+reader->geti,*spillover_len); } } } if (reader->mode!=TSF_ZIP_UNKNOWN) { free(reader->buf); } reader->stream=NULL; reader->buf=NULL; reader->buf_size=0; reader->mode=TSF_ZIP_UNKNOWN; return stillok; }
static tsf_bool_t tear_to_none(tsf_adpt_rdr_t *reader) { tsf_assert(reader->mode==TSF_ZIP_ZLIB || reader->mode==TSF_ZIP_BZIP2); if (reader->mode==TSF_ZIP_ZLIB) { #ifdef HAVE_ZLIB inflateEnd(Cz(reader)); #endif } else { #ifdef HAVE_BZIP2 BZ2_bzDecompressEnd(Cbz(reader)); #endif } free(reader->stream); reader->mode=TSF_ZIP_UNKNOWN; if (reader->nozip_buf_size==reader->buf_size) { reader->geti=reader->abstract.next_in-reader->buf; reader->puti=reader->geti+reader->abstract.avail_in; } else { uint8_t *buf; reader->buf_size=tsf_max(reader->nozip_buf_size, reader->abstract.avail_in); buf=malloc(reader->buf_size); if (buf==NULL) { tsf_set_errno("Could not allocate buffer in tear_to_none() in " "tsf_adaptive_reader.c"); free(reader->buf); /* oh man, this leaves the reader in a flaky state */ return tsf_false; } memcpy(buf, reader->abstract.next_in, reader->abstract.avail_in); free(reader->buf); reader->geti=0; reader->puti=reader->abstract.avail_in; reader->buf=buf; } reader->mode=TSF_ZIP_NONE; return tsf_true; }
main() { int x,y,cord; void outlin(struct node *h); void create(); void insert(struct node *h,int x,int y); void deletes(struct node *h,int x); struct node *MaxCompare(struct node *h); struct node *MinCompare(struct node *h); int delIterance(struct node *h); void batchInsert(struct node *h,int x); void batchDelete(struct node *h,int x,int y); void Cz(struct node* h); void Xg(struct node * h); printf("建立链表,输入-999完成链表: \n"); create(); i=j; outlin(head); do{ printf("\n 主菜单 \n"); printf(" 1 插入一个元素 \n"); printf(" 2 删除一个元素 \n"); printf(" 3 升序排序 \n"); printf(" 4 降序排序 \n"); printf(" 5 查找元素 \n"); printf(" 6 修改元素 \n"); printf(" 7 删除重复元素 \n"); printf(" 8 批量加入元素 \n"); printf(" 9 批量删除元素 \n"); printf(" 0 结束程序运行 \n"); printf("-----------------------------------------\n"); printf(" 请输入您的选择(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) "); scanf("%d",&cord); switch(cord) { case 1: { printf("请输入插入的位置 i: "); scanf("%d",&x); printf("请输入插入的数据 y: "); scanf("%d",&y); insert(head,x,y); i=j; outlin(head); }break; case 2: { printf("x=?"); scanf("%d",&x); deletes(head,x); i=j; outlin(head); }break; case 3: { printf("链表由大到小是"); s=MaxCompare(head); j=i; outlin(s); //outlin(head); }break; case 4: { printf("链表由大到小是"); s=MinCompare(head); j=i; outlin(s); }break; case 5: { Cz(head); outlin(head); }break; case 6: { Xg(head); outlin(head); }break; case 7: { k=delIterance(head); i=i-k; j=i; outlin(head); }break; case 8: { printf("请输入插入的位置 i: "); scanf("%d",&x); batchInsert(head,x); i=j; outlin(head); }break; case 9: { printf("请输入删除的起始位置 i: "); scanf("%d",&x); printf("请输入删除的结束位置 y: "); scanf("%d",&y); batchDelete(head,x,y); i=j; outlin(head); }break; case 0: { exit(0); }break; } }while(cord<=9&&cord>=0); }
static tsf_bool_t select_mode(tsf_adpt_rdr_t *reader, uint8_t *spillover, uint32_t spillover_len, tsf_bool_t free_spillover) { uint8_t magic[4]; uint32_t tocopy=tsf_min(4,spillover_len); void *tofree; if (free_spillover && spillover_len>0) { tofree=spillover; } else { tofree=NULL; } memcpy(magic,spillover,tocopy); spillover+=tocopy; spillover_len-=tocopy; if (tocopy<4) { tsf_assert(spillover_len==0); if (!tsf_full_read_of_partial(reader->reader,reader->reader_arg, magic+tocopy,4-tocopy)) { if (tofree!=NULL) free(tofree); return tsf_false; } } if (!memcmp(magic,TSF_SP_MAGIC_CODE,TSF_SP_MAGIC_LEN)) { reader->buf_size=tsf_max(reader->nozip_buf_size, spillover_len+TSF_SP_MAGIC_LEN); reader->buf=malloc(reader->buf_size); if (reader->buf==NULL) { tsf_set_errno("Could not allocate buffer"); if (tofree!=NULL) free(tofree); return tsf_false; } memcpy(reader->buf,spillover,spillover_len); memcpy(reader->buf+spillover_len,TSF_SP_MAGIC_CODE,TSF_SP_MAGIC_LEN); reader->puti=spillover_len+TSF_SP_MAGIC_LEN; reader->geti=0; if (tofree!=NULL) free(tofree); reader->mode=TSF_ZIP_NONE; } else if (!memcmp(magic,TSF_SP_BZIP2_MAGIC_CODE,TSF_SP_MAGIC_LEN) || !memcmp(magic,TSF_SP_ZLIB_MAGIC_CODE,TSF_SP_MAGIC_LEN)) { int res; if (!memcmp(magic,TSF_SP_ZLIB_MAGIC_CODE,TSF_SP_MAGIC_LEN)) { reader->buf_size=tsf_max(reader->attr.z.buf_size,spillover_len); } else { reader->buf_size=tsf_max(reader->attr.b.buf_size,spillover_len); } reader->buf=malloc(reader->buf_size); if (reader->buf==NULL) { tsf_set_errno("Could not allocate buffer"); if (tofree!=NULL) free(tofree); return tsf_false; } memcpy(reader->buf,spillover,spillover_len); if (tofree!=NULL) free(tofree); reader->abstract.next_in=reader->buf; reader->abstract.avail_in=spillover_len; if (!memcmp(magic,TSF_SP_ZLIB_MAGIC_CODE,TSF_SP_MAGIC_LEN)) { if (!reader->attr.z.allow) { tsf_set_error(TSF_E_PARSE_ERROR, "The stream is compressed using ZLib, but " "the given attributes specify that " "ZLib is not allowed"); if (tofree!=NULL) free(tofree); free(reader->buf); return tsf_false; } #ifdef HAVE_ZLIB reader->stream=malloc(sizeof(z_stream)); if (reader->stream==NULL) { tsf_set_errno("Could not malloc z_stream"); free(reader->buf); return tsf_false; } Cz(reader)->zalloc=NULL; Cz(reader)->zfree=NULL; Cz(reader)->opaque=NULL; if (reader->attr.z.advanced_init) { res=inflateInit2(Cz(reader), reader->attr.z.windowBits); } else { res=inflateInit(Cz(reader)); } if (res!=Z_OK) { tsf_set_zlib_error(res,Cz(reader)->msg, "Trying to initialize inflation in ZLib"); free(Cz(reader)); free(reader->buf); return tsf_false; } reader->mode=TSF_ZIP_ZLIB; #else tsf_set_error(TSF_E_NOT_SUPPORTED, "TSF_ZIP_ZLIB is not supported by " "tsf_zip_reader_create() because ZLib support " "was not configured into the TSF library"); if (tofree!=NULL) free(tofree); free(reader->buf); return tsf_false; #endif } else { if (!reader->attr.b.allow) { tsf_set_error(TSF_E_PARSE_ERROR, "The stream is compressed using libbzip2, but " "the given attributes specify that " "libbzip2 is not allowed"); if (tofree!=NULL) free(tofree); free(reader->buf); return tsf_false; } #ifdef HAVE_BZIP2 reader->stream=malloc(sizeof(bz_stream)); if (reader->stream==NULL) { tsf_set_errno("Could not malloc bz_stream"); free(reader->buf); return tsf_false; } Cbz(reader)->bzalloc=NULL; Cbz(reader)->bzfree=NULL; Cbz(reader)->opaque=NULL; res=BZ2_bzDecompressInit(Cbz(reader), reader->attr.b.verbosity, reader->attr.b.small); if (res!=BZ_OK) { tsf_set_libbzip2_error(res, "Trying to initialize decompression in libbzip2"); free(Cbz(reader)); free(reader->buf); return tsf_false; } reader->mode=TSF_ZIP_BZIP2; #else tsf_set_error(TSF_E_NOT_SUPPORTED, "TSF_ZIP_BZIP2 is not supported by " "tsf_zip_reader_create() because libbzip2 " "support was not configured into the TSF " "library"); free(reader->buf); if (tofree!=NULL) free(tofree); return tsf_false; #endif } } else { if (tofree!=NULL) free(tofree); tsf_set_error(TSF_E_PARSE_ERROR, "Not a valid magic code for any TSF stream file format"); return tsf_false; } return tsf_true; }