Text t_load_file(char *name) { Text t; Piece p = p_load_file(name, NULL, NULL); t.head = t.tail = p; t.len = 3; return t; }
int main(int argc, char *argv[]) { char *name = "as.txt"; Text text = t_load_file(name); Piece p = text.head; Piece p_2 = p_load_file("bs.txt", p, NULL); int in_i = file_size(p->file);; /* 4 into second */ t_print(text); Location location = p_location_of(text, in_i); Location d_loc = { .piece = p_2, .offset = 9 }; e_delete(d_loc); t_print(text); t_cleanup(text); return 0; }
/* ============================================================================ * p_movtar_encode * The main "productive" routine * movtar encoding of anim frames, based on the buz_tools' encoding routines. * (flattens the images if nedded) * Optional you can provide audio, too * (wav_audiofile must be provided in that case) * * returns value >= 0 if all went ok * (or -1 on error) * ============================================================================ */ static int p_movtar_encode(t_anim_info *ainfo_ptr, long range_from, long range_to, char *vidname, gint32 dont_recode_frames, char *wavname, gint32 auto_videoparam, char *videonorm, gint32 jpeg_interlaced, char *text_author, char *text_software, char *text_device, char *text_input, char *text_contdescription, char *text_contclassification, gint32 jpeg_quality ) { gint32 l_tmp_image_id = -1; gint32 l_layer_id = -1; GDrawable *l_drawable; long l_cur_frame_nr; long l_step, l_begin, l_end; int l_width, l_height; gint l_nlayers; gint32 *l_layers_list; gdouble l_percentage, l_percentage_step; int l_rc; FILE *movtar, *inwav = NULL; gint32 JPEG_size, datasize; gint32 audio_x100; char *buffer; static struct tarinfotype frameinfo; // static struct tarinfotype frcopyinfo; static struct tarinfotype audioinfo; gint32 wavsize; /* Data size of the wav file */ long audio_margin = 8192; long audio_filled_100 = 0; gchar databuffer[300000]; gchar *name_examine; l_rc = 0; l_layer_id = -1; l_width = 0; l_height = 0; movtar_init(FALSE); tarblock_makedefault(&frameinfo, "tja.jpeg", 1024); tarblock_makedefault(&audioinfo, "tja.raw", 1024); /* create file */ if (movtar_debug) printf("Creating movtar file.\n"); movtar = movtar_create(vidname); if (movtar == NULL) { perror("Creation of movtar file failed."); exit(1); } l_percentage = 0.0; if(ainfo_ptr->run_mode == RUN_INTERACTIVE) gimp_progress_init("Encoding movtar..."); l_begin = range_from; l_end = range_to; /* special setup (makes it possible to code sequences backwards) */ if(range_from > range_to) { l_step = -1; /* operate in descending (reverse) order */ l_percentage_step = 1.0 / ((1.0 + range_from) - range_to); if(range_to < ainfo_ptr->first_frame_nr) l_begin = ainfo_ptr->first_frame_nr; if(range_from > ainfo_ptr->last_frame_nr) l_end = ainfo_ptr->last_frame_nr; } else { l_step = 1; /* operate in ascending order */ l_percentage_step = 1.0 / ((1.0 + range_to) - range_from); if(range_from < ainfo_ptr->first_frame_nr) l_begin = ainfo_ptr->first_frame_nr; if(range_to > ainfo_ptr->last_frame_nr) l_end = ainfo_ptr->last_frame_nr; } /* start with the first frame to encode */ l_cur_frame_nr = l_begin; while(l_rc >= 0) { /* build the frame name */ if(ainfo_ptr->new_filename != NULL) g_free(ainfo_ptr->new_filename); /* Use the gap functions to generate the frame filename */ ainfo_ptr->new_filename = p_alloc_fname(ainfo_ptr->basename, l_cur_frame_nr, ainfo_ptr->extension); /* can't find the frame ? */ if(ainfo_ptr->new_filename == NULL) return -1; if(l_cur_frame_nr == l_begin) /* setup things first if this is the first frame */ { /* load current frame ... */ l_tmp_image_id = p_load_image(ainfo_ptr->new_filename); if(l_tmp_image_id < 0) return -1; /* to determine these parameters */ l_width = (int) gimp_image_width(l_tmp_image_id); l_height = (int) gimp_image_height(l_tmp_image_id); /* create the MOVTAR Info file, based on the information stored in the first JPEG */ inwav = p_make_movtar_info(movtar, wavname, l_width, l_height, auto_videoparam, videonorm, jpeg_interlaced, text_author, text_software, text_device, text_input, text_contdescription, text_contclassification, &audio_x100, &wavsize); /* destroy the tmp image, dont_recode doesn't need it */ if (dont_recode_frames) gimp_image_delete(l_tmp_image_id); } if (dont_recode_frames) { JPEG_size = p_get_filesize(ainfo_ptr->new_filename); buffer = p_load_file(ainfo_ptr->new_filename); if (buffer == NULL) { printf("gap_movtar: Failed opening encoded input frame %s.", ainfo_ptr->new_filename); return -1; } /* generate the file name for the frame to be stored */ /* store the compressed video frame */ /* A quick hack to replace the extension with raw */ strcpy(frameinfo.name, g_basename(ainfo_ptr->new_filename)); name_examine = frameinfo.name + strlen(frameinfo.name); while (frameinfo.name != name_examine && *name_examine != '.') { *name_examine = '\0'; name_examine--; } strcpy(name_examine, ".jpeg"); sprintf(frameinfo.size, "%o", JPEG_size); tarblock_create_checksum(&frameinfo); if (movtar_debug) printf("gap_movtar: Writing frame nr. %ld, size %d\n", l_cur_frame_nr, JPEG_size); if (movtar_write(movtar, buffer, JPEG_size, &frameinfo) != TRUE) { printf("gap_movtar: Failed in writing a frame."); return -1; } } else { if(l_cur_frame_nr != l_begin) /* frame has already been loaded if l_begin */ { /* load current frame */ l_tmp_image_id = p_load_image(ainfo_ptr->new_filename); if (l_tmp_image_id < 0) return -1; } /* Examine the layers of the picture */ l_layers_list = gimp_image_get_layers(l_tmp_image_id, &l_nlayers); if(l_layers_list != NULL) { l_layer_id = l_layers_list[0]; g_free (l_layers_list); } if(l_nlayers > 1 ) { if (movtar_debug) fprintf(stderr, "DEBUG: p_movtar_encode flatten tmp image'\n"); /* flatten current frame image (reduce to single layer) */ l_layer_id = gimp_image_flatten (l_tmp_image_id); } l_drawable = gimp_drawable_get (l_layer_id); if (movtar_debug) fprintf(stderr, "DEBUG: JPEG encoding frame %s\n", ainfo_ptr->new_filename); /* Compress the picture into a JPEG */ buffer = p_drawable_encode_jpeg(l_drawable, jpeg_interlaced, &JPEG_size, jpeg_quality, 0, FALSE, NULL, 0); if (movtar_debug) fprintf(stderr, "DEBUG: Ready with encoding, now saving %s\n", ainfo_ptr->new_filename); /* store the compressed video frame */ /* A quick hack to replace the extension with raw */ strcpy(frameinfo.name, g_basename(ainfo_ptr->new_filename)); name_examine = frameinfo.name + strlen(frameinfo.name); while (frameinfo.name != name_examine && *name_examine != '.') { *name_examine = '\0'; name_examine--; } strcpy(name_examine, ".jpeg"); sprintf(frameinfo.size, "%o", JPEG_size); tarblock_create_checksum(&frameinfo); if (movtar_debug) printf("gap_movtar: Writing frame nr. %ld, size %d\n", l_cur_frame_nr, JPEG_size); if (movtar_write(movtar, buffer, JPEG_size, &frameinfo) != TRUE) { printf("Failed in writing a frame."); return -1; } /* free the compressed JPEG data */ g_free(buffer); /* destroy the tmp image */ gimp_image_delete(l_tmp_image_id); } /* As long as there is a video frame, "fill" the fake audio buffer */ if (inwav) audio_filled_100 += audio_x100; /* Now "empty" the fake audio buffer, until it goes under the margin again */ while ((audio_filled_100 >= (audio_margin * 100)) && (wavsize > 0)) { if (wavsize >= audio_margin) { datasize = fread(databuffer, 1, audio_margin, inwav); if (datasize != audio_margin) { perror("Warning: Read from wav file failed. (non-critical)\n"); } wavsize -= audio_margin; } else { datasize = fread(databuffer, 1, wavsize, inwav); if (datasize != wavsize) { perror("Warning: Read from wav file failed. (non-critical)\n"); } wavsize = 0; } /* create a filename, with the sequence number and the timestamp info in brackets. Checksum the new tarheader. */ /* A quick hack to replace the extension with raw */ name_examine = frameinfo.name + strlen(frameinfo.name); while (frameinfo.name != name_examine && *name_examine != '.') { *name_examine = '\0'; name_examine--; } strcpy(name_examine, ".raw"); sprintf(frameinfo.size, "%o", datasize); tarblock_create_checksum(&frameinfo); if (movtar_debug) printf("Now saving audio frame %s\n", frameinfo.name); movtar_write(movtar, databuffer, datasize, &frameinfo); audio_filled_100 -= audio_margin * 100; } if(ainfo_ptr->run_mode == RUN_INTERACTIVE) { l_percentage += l_percentage_step; gimp_progress_update (l_percentage); } /* advance to next frame */ if((l_cur_frame_nr == l_end) || (l_rc < 0)) break; l_cur_frame_nr += l_step; } movtar_finish_close(movtar); return l_rc; }