svn_error_t * svn_editor_alter_file(svn_editor_t *editor, const char *relpath, svn_revnum_t revision, const svn_checksum_t *checksum, svn_stream_t *contents, apr_hash_t *props) { svn_error_t *err = SVN_NO_ERROR; SVN_ERR_ASSERT(svn_relpath_is_canonical(relpath)); SVN_ERR_ASSERT((checksum != NULL && contents != NULL) || (checksum == NULL && contents == NULL)); SVN_ERR_ASSERT(props != NULL || checksum != NULL); if (checksum) SVN_ERR_ASSERT(checksum->kind == SVN_EDITOR_CHECKSUM_KIND); SHOULD_NOT_BE_FINISHED(editor); SHOULD_ALLOW_ALTER(editor, relpath); VERIFY_PARENT_MAY_EXIST(editor, relpath); SVN_ERR(check_cancel(editor)); if (editor->funcs.cb_alter_file) { START_CALLBACK(editor); err = editor->funcs.cb_alter_file(editor->baton, relpath, revision, checksum, contents, props, editor->scratch_pool); END_CALLBACK(editor); } MARK_COMPLETED(editor, relpath); MARK_PARENT_STABLE(editor, relpath); svn_pool_clear(editor->scratch_pool); return svn_error_trace(err); }
void add_all_pixels(void) { struct _pics *pics; BYTE col[3]; int i, npix; register unsigned char byte; for (pics = pictures; pics; pics = pics->next) if (pics->bitmap != NULL && pics->numcols > 0) { /* now add each pixel to the sample list */ npix = pics->bit_size.x * pics->bit_size.y; for (i=0; i < npix; i++) { /* check if user pressed cancel button */ if (i%1000==0 && check_cancel()) return; byte = pics->bitmap[i]; col[N_RED] = pics->cmap[byte].red; col[N_GRN] = pics->cmap[byte].green; col[N_BLU] = pics->cmap[byte].blue; neu_pixel(col); } } }
static void msg_fetched( int sts, void *aux ) { copy_vars_t *vars = (copy_vars_t *)aux; DECL_SVARS; char *fmap, *buf; int i, len, extra, scr, tcr, lcrs, hcrs, bcrs, lines; int start, sbreak = 0, ebreak = 0; char c; switch (sts) { case DRV_OK: INIT_SVARS(vars->aux); if (check_cancel( svars )) { free( vars->data.data ); vars->cb( SYNC_CANCELED, 0, vars ); return; } vars->msg->flags = vars->data.flags; scr = (svars->drv[1-t]->flags / DRV_CRLF) & 1; tcr = (svars->drv[t]->flags / DRV_CRLF) & 1; if (vars->srec || scr != tcr) { fmap = vars->data.data; len = vars->data.len; extra = lines = hcrs = bcrs = i = 0; if (vars->srec) { nloop: start = i; lcrs = 0; while (i < len) { c = fmap[i++]; if (c == '\r') lcrs++; else if (c == '\n') { if (!memcmp( fmap + start, "X-TUID: ", 8 )) { extra = (sbreak = start) - (ebreak = i); goto oke; } lines++; hcrs += lcrs; if (i - lcrs - 1 == start) { sbreak = ebreak = start; goto oke; } goto nloop; } } /* invalid message */ warn( "Warning: message %d from %s has incomplete header.\n", vars->msg->uid, str_ms[1-t] ); free( fmap ); vars->cb( SYNC_NOGOOD, 0, vars ); return; oke: extra += 8 + TUIDL + 1 + (tcr && (!scr || hcrs)); } if (tcr != scr) { for (; i < len; i++) { c = fmap[i]; if (c == '\r') bcrs++; else if (c == '\n') lines++; } extra -= hcrs + bcrs; if (tcr) extra += lines; } vars->data.len = len + extra; buf = vars->data.data = nfmalloc( vars->data.len ); i = 0; if (vars->srec) { if (tcr != scr) { if (tcr) { for (; i < sbreak; i++) if ((c = fmap[i]) != '\r') { if (c == '\n') *buf++ = '\r'; *buf++ = c; } } else { for (; i < sbreak; i++) if ((c = fmap[i]) != '\r') *buf++ = c; } } else { memcpy( buf, fmap, sbreak ); buf += sbreak; } memcpy( buf, "X-TUID: ", 8 ); buf += 8; memcpy( buf, vars->srec->tuid, TUIDL ); buf += TUIDL; if (tcr && (!scr || hcrs)) *buf++ = '\r'; *buf++ = '\n'; i = ebreak; } if (tcr != scr) { if (tcr) { for (; i < len; i++) if ((c = fmap[i]) != '\r') { if (c == '\n') *buf++ = '\r'; *buf++ = c; } } else { for (; i < len; i++) if ((c = fmap[i]) != '\r') *buf++ = c; } } else memcpy( buf, fmap + i, len - i ); free( fmap ); } svars->drv[t]->store_msg( svars->ctx[t], &vars->data, !vars->srec, msg_stored, vars ); break; case DRV_CANCELED: vars->cb( SYNC_CANCELED, 0, vars ); break; case DRV_MSG_BAD: vars->cb( SYNC_NOGOOD, 0, vars ); break; default: vars->cb( SYNC_FAIL, 0, vars ); break; } }
void coopth_yield(void) { assert(_coopth_is_in_thread()); switch_state(COOPTH_YIELD); check_cancel(); }
void remap_imagecolors(void) { int i; /* if monochrome, return */ if (tool_cells <= 2 || appres.monochrome) return; npixels = 0; /* first see if there are enough colorcells for all image colors */ usenet = False; /* see if the total number of colors will fit without using the neural net */ ncolors = count_colors(); if (ncolors == 0) return; put_msg(REMAP_MSG); set_temp_cursor(wait_cursor); app_flush(); if (ncolors > appres.max_image_colors) { if (appres.DEBUG) fprintf(stderr,"More colors (%d) than allowed (%d), using neural net\n", ncolors,appres.max_image_colors); ncolors = appres.max_image_colors; usenet = True; } /* if this is the first image, allocate the number of colorcells we need */ if (num_oldcolors != ncolors) { if (num_oldcolors != -1) { unsigned long pixels[MAX_USR_COLS]; for (i=0; i<num_oldcolors; i++) pixels[i] = image_cells[i].pixel; if (tool_vclass == PseudoColor) XFreeColors(tool_d, tool_cm, pixels, num_oldcolors, 0); } alloc_imagecolors(ncolors); /* hmm, we couldn't get that number of colors anyway; use the net, Luke */ if (ncolors > avail_image_cols) { usenet = True; if (appres.DEBUG) fprintf(stderr,"More colors (%d) than available (%d), using neural net\n", ncolors,avail_image_cols); } num_oldcolors = avail_image_cols; if (avail_image_cols < 2 && ncolors >= 2) { file_msg("Cannot allocate even 2 colors for pictures"); reset_cursor(); num_oldcolors = -1; reset_cursor(); put_msg(REMAP_MSG2); app_flush(); return; } } reset_cursor(); if (usenet) { int stat; int mult = 1; /* check if user pressed cancel button (in file preview) */ if (check_cancel()) return; /* count total number of pixels in all the pictures */ npixels = count_pixels(); /* check if user pressed cancel button */ if (check_cancel()) return; /* initialize the neural network */ /* -1 means can't alloc memory, -2 or more means must have that many times as many pixels */ set_temp_cursor(wait_cursor); if ((stat=neu_init(npixels)) <= -2) { mult = -stat; npixels *= mult; /* try again with more pixels */ stat = neu_init2(npixels); } if (stat == -1) { /* couldn't alloc memory for network */ fprintf(stderr,"Can't alloc memory for neural network\n"); reset_cursor(); put_msg(REMAP_MSG2); app_flush(); return; } /* now add all pixels to the samples */ for (i=0; i<mult; i++) add_all_pixels(); /* make a new colortable with the optimal colors */ avail_image_cols = neu_clrtab(avail_image_cols); /* now change the color cells with the new colors */ /* clrtab[][] is the colormap produced by neu_clrtab */ for (i=0; i<avail_image_cols; i++) { image_cells[i].red = (unsigned short) clrtab[i][N_RED] << 8; image_cells[i].green = (unsigned short) clrtab[i][N_GRN] << 8; image_cells[i].blue = (unsigned short) clrtab[i][N_BLU] << 8; } YStoreColors(tool_cm, image_cells, avail_image_cols); reset_cursor(); /* check if user pressed cancel button */ if (check_cancel()) return; /* get the new, mapped indices for the image colormap */ remap_image_colormap(); } else { /* * Extract the RGB values from the image's colormap and allocate * the appropriate X colormap entries. */ scol = 0; /* global color counter */ set_temp_cursor(wait_cursor); extract_cmap(); for (i=0; i<scol; i++) { image_cells[i].flags = DoRed|DoGreen|DoBlue; } YStoreColors(tool_cm, image_cells, scol); scol = 0; /* global color counter */ readjust_cmap(); if (appres.DEBUG) fprintf(stderr,"Able to use %d colors without neural net\n",scol); reset_cursor(); } put_msg(REMAP_MSG2); app_flush(); }
int receive_ymodem_protocol(char *filename, int mode, int *last_file) { int result; int packetno = 0; int gotpacketno; char *buffer; FILE *fileptr = 0; unsigned long int curlength = 0; unsigned long int maxlength = 0; int flag = 1; int not_received; int not_got_mode_type = 1; int length; int attempts; int keep_packet; int ymodem_block0 = 1; #ifdef DEBUG char s[80]; #endif #ifdef DEBUG print_str_cr_to("Started protocol",0); #endif buffer = g_malloc(MAX_PROTO_BUFFER_SIZE,"RECVYMDM"); if (!buffer) { massive_cancel(); return (-1); } wait_for_sending_state(SMALL_TIMEOUT_TICKS,0); empty_inbuffer(tswitch); while (flag) { not_received = 1; attempts = 0; while (not_received && (attempts++ < 20)) { if (not_got_mode_type) { if (receiver_driven_start(mode)) { massive_cancel(); if (fileptr) g_fclose(fileptr); g_free(buffer); return (-1); } } result=recv_packet(buffer,&length,&gotpacketno,CRC_16); wait_for_sending_state(SMALL_TIMEOUT_TICKS,0); empty_inbuffer(tswitch); #ifdef DEBUG sprintf(s,"Received packet %03d result %03d",gotpacketno,result); print_str_cr_to(s,0); #endif switch (result) { case CAN_CHR: if (check_cancel()) { massive_cancel(); if (fileptr) g_fclose(fileptr); g_free(buffer); return (-1); } break; case ACK_CHR: if (((unsigned char)gotpacketno) == ((unsigned char)last_packet(packetno))) { keep_packet = 0; send_short(ACK_CHR); not_received = 0; } else if (((unsigned char)gotpacketno) == ((unsigned char)packetno)) { keep_packet = 1; send_short(ACK_CHR); not_received = 0; not_got_mode_type = 0; } else send_short(NAK_CHR); break; case NAK_CHR: if (!not_got_mode_type) { massive_cancel(); if (fileptr) g_fclose(fileptr); g_free(buffer); return (-1); } break; case EOT_CHR: flag = 0; keep_packet = 0; send_short(ACK_CHR); not_received = 0; break; case (-1): if (!not_got_mode_type) send_short(NAK_CHR); break; } } if (not_received) { massive_cancel(); if (fileptr) g_fclose(fileptr); g_free(buffer); return (-1); } if (keep_packet) { if (ymodem_block0) { ymodem_block0 = 0; decode_ymodem_block0(buffer,filename,&maxlength); #ifdef DEBUG sprintf(s,"Filename: %s length: %ld",filename,maxlength); print_str_cr_to(s,0); #endif *last_file = !(*filename); if (*last_file) flag = 0; if (*filename) { if (proto_open_file(filename,&fileptr,"wb")) { g_free(buffer); massive_cancel(); return (-1); } } not_got_mode_type = 1; } else { proto_write_buffer(fileptr,buffer,(int) ((maxlength-curlength)>(unsigned long int) length) ? (unsigned long int) length : (unsigned long int) (maxlength-curlength) ); curlength += length; } packetno++; } } if (fileptr) g_fclose(fileptr); g_free(buffer); return (0); }
int send_ymodem_protocol(char *filename, int mode) { int result; int packetno = 0; int attempts; int crc_type; char *buffer; FILE *fileptr; long int curlength = 0; long int maxlength; int blocklength; int not_got_sensible; int not_sent; int ymodem_block0 = 1; int lastpacket = 0; #ifdef DEBUG char s[80]; #endif #ifdef DEBUG print_str_cr_to("Started protocol",0); #endif result = sender_start(&crc_type); if ((result == -1) || (result == CAN_CHR)) { massive_cancel(); return (-1); } #ifdef DEBUG print_str_cr_to("Received start",0); #endif if (*filename) { if (proto_open_file(filename,&fileptr,"rb")) { massive_cancel(); return (-1); } } else fileptr = 0; #ifdef DEBUG print_str_cr_to("opened file",0); #endif buffer = g_malloc(MAX_PROTO_BUFFER_SIZE,"SNDYMDM"); if (!buffer) { massive_cancel(); if (fileptr) g_fclose(fileptr); return (-1); } if (fileptr) maxlength = 128 + proto_file_length(fileptr); else maxlength = 128; while (!lastpacket) { if (curlength >= maxlength) lastpacket = 1; if (!lastpacket) { if (ymodem_block0) { create_ymodem_block0(buffer,filename,maxlength-128); } else proto_read_buffer(fileptr,buffer,1024,&blocklength); } not_sent = 1; attempts = 0; while ((not_sent) && (attempts++ < 10)) { empty_inbuffer(tswitch); #ifdef DEBUG if (lastpacket) print_str_cr_to("Last packet",0); else { sprintf(s,"Sending packet %03d",packetno); print_str_cr_to(s,0); } #endif if (lastpacket) send_short(EOT_CHR); else { if (ymodem_block0) { send_packet(buffer,128,packetno,crc_type); if (!(*filename)) lastpacket = 1; } else send_packet(buffer,1024,packetno,crc_type); } not_got_sensible = 1; while (not_got_sensible) { result = time_char(); #ifdef DEBUG sprintf(s,"Received char %03d",result); print_str_cr_to(s,0); #endif switch (result) { case (-1): not_got_sensible = 0; break; case ACK_CHR: not_sent = 0; not_got_sensible = 0; break; case NAK_CHR: not_got_sensible = 0; break; case CAN_CHR: if (check_cancel()) { massive_cancel(); if (fileptr) g_fclose(fileptr); g_free(buffer); return (-1); } not_got_sensible = 0; break; } } } if (not_sent) { massive_cancel(); g_free(buffer); if (fileptr) g_fclose(fileptr); return (-1); } if (!lastpacket) { if (ymodem_block0) { curlength += 128; ymodem_block0 = 0; } else curlength += 1024; packetno++; } } if (fileptr) g_fclose(fileptr); g_free(buffer); return 0; }
void receive_xmodem_protocol(char *filename, int crc_type, int mode) { int result; int packetno = 1; int gotpacketno; char *buffer; FILE *fileptr; long int curlength = 0; int flag = 1; int not_received; int not_got_mode_type = 1; int length; int attempts; int keep_packet; #ifdef DEBUG char s[80]; #endif #ifdef DEBUG print_str_cr_to("Started protocol",0); #endif if (proto_open_file(filename,&fileptr,"wb")) { massive_cancel(); return; } buffer = g_malloc(MAX_PROTO_BUFFER_SIZE,"RCVXMDM"); if (!buffer) { massive_cancel(); g_fclose(fileptr); return; } #ifdef DEBUG print_str_cr_to("Opened file",0); #endif wait_for_sending_state(SMALL_TIMEOUT_TICKS,0); empty_inbuffer(tswitch); while (flag) { not_received = 1; attempts = 0; while (not_received && (attempts++ < 20)) { if (not_got_mode_type) { if (receiver_driven_start(mode)) { massive_cancel(); g_fclose(fileptr); g_free(buffer); return; } } result=recv_packet(buffer,&length,&gotpacketno,crc_type); wait_for_xmit(tswitch,20); wait_for_sending_state(SMALL_TIMEOUT_TICKS,0); empty_inbuffer(tswitch); #ifdef DEBUG sprintf(s,"Received packet %03d result %03d",gotpacketno,result); print_str_cr_to(s,0); #endif switch (result) { case CAN_CHR: if (check_cancel()) { massive_cancel(); g_fclose(fileptr); g_free(buffer); return; } break; case ACK_CHR: if (((unsigned char)gotpacketno) == ((unsigned char)last_packet(packetno))) { keep_packet = 0; send_short(ACK_CHR); not_received = 0; } else if (((unsigned char)gotpacketno) == ((unsigned char)packetno)) { keep_packet = 1; send_short(ACK_CHR); not_received = 0; not_got_mode_type = 0; } else send_short(NAK_CHR); break; case NAK_CHR: if (!not_got_mode_type) { send_short(NAK_CHR); } break; case EOT_CHR: flag = 0; keep_packet = 0; send_short(ACK_CHR); not_received = 0; break; case (-1): if (!not_got_mode_type) send_short(NAK_CHR); break; } } if (not_received) { massive_cancel(); g_fclose(fileptr); g_free(buffer); return; } if (keep_packet) { proto_write_buffer(fileptr,buffer,length); curlength += length; packetno++; } } g_fclose(fileptr); g_free(buffer); }
void send_xmodem_protocol(char *filename, int length) { int result; int packetno = 1; int attempts; int crc_type; char *buffer; FILE *fileptr; long int curlength = 0; long int maxlength; int blocklength; int not_got_sensible; int not_sent; #ifdef DEBUG char s[80]; #endif #ifdef DEBUG print_str_cr_to("Started protocol",0); #endif result = sender_start(&crc_type); if ((result == -1) || (result == CAN_CHR)) { massive_cancel(); return; } #ifdef DEBUG print_str_cr_to("Received start",0); #endif if (proto_open_file(filename,&fileptr,"rb")) { massive_cancel(); return; } #ifdef DEBUG print_str_cr_to("opened file",0); #endif buffer = g_malloc(MAX_PROTO_BUFFER_SIZE,"SNDXMDM"); if (!buffer) { massive_cancel(); g_fclose(fileptr); return; } maxlength = proto_file_length(fileptr); while (curlength < maxlength) { proto_read_buffer(fileptr,buffer,length,&blocklength); not_sent = 1; attempts = 0; while ((not_sent) && (attempts++ < 10)) { empty_inbuffer(tswitch); #ifdef DEBUG sprintf(s,"Sending packet %03d",packetno); print_str_cr_to(s,0); #endif send_packet(buffer,length,packetno,crc_type); not_got_sensible = 1; while (not_got_sensible) { result = time_char(); #ifdef DEBUG sprintf(s,"Received char %03d",result); print_str_cr_to(s,0); #endif switch (result) { case (-1): not_got_sensible = 0; break; case ACK_CHR: not_sent = 0; not_got_sensible = 0; break; case NAK_CHR: not_got_sensible = 0; break; case CAN_CHR: if (check_cancel()) { massive_cancel(); g_fclose(fileptr); g_free(buffer); return; } not_got_sensible = 0; break; } } } if (not_sent) { massive_cancel(); g_free(fileptr); g_fclose(fileptr); return; } curlength += length; packetno++; } send_short(EOT_CHR); delay(10); send_short(EOT_CHR); g_fclose(fileptr); g_free(fileptr); }