void setFontValues(struct Tracker_Windows *window){ double width3 = R_MAX(get_text_width("D#6"), R_MAX(get_text_width("MUL"), get_text_width("STP"))); window->fontwidth = (int)ceil(width3/3.0); window->fontheight = get_text_height("D#6"); //window->fontheight = pango_font_description_get_size(font_description)/PANGO_SCALE; window->org_fontheight = window->fontheight; }
float TRACK_get_max_pitch(const struct Tracks *track){ float max_pitch = -1; int num_pitches = 0; { struct Notes *note = track->notes; while(note!=NULL){ max_pitch = R_MAX(note->note, max_pitch); num_pitches ++; struct Pitches *pitch = note->pitches; while(pitch != NULL){ max_pitch = R_MAX(pitch->note, max_pitch); num_pitches ++; pitch = NextPitch(pitch); } note = NextNote(note); } } if (num_pitches==0) return -1; else return max_pitch; }
// Eugene W. Myers' O(ND) diff algorithm // Returns edit distance with costs: insertion=1, deletion=1, no substitution R_API bool r_diff_buffers_distance_myers(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { const bool verbose = diff ? diff->verbose: false; if (!a || !b) { return false; } const ut32 length = la + lb; const ut8 *ea = a + la, *eb = b + lb; // Strip prefix for (; a < ea && b < eb && *a == *b; a++, b++) {} // Strip suffix for (; a < ea && b < eb && ea[-1] == eb[-1]; ea--, eb--) {} la = ea - a; lb = eb - b; ut32 *v0, *v; st64 m = (st64)la + lb, di = 0, low, high, i, x, y; if (m + 2 > SIZE_MAX / sizeof (st64) || !(v0 = malloc ((m + 2) * sizeof (ut32)))) { return false; } v = v0 + lb; v[1] = 0; for (di = 0; di <= m; di++) { low = -di + 2 * R_MAX (0, di - (st64)lb); high = di - 2 * R_MAX (0, di - (st64)la); for (i = low; i <= high; i += 2) { x = i == -di || (i != di && v[i-1] < v[i+1]) ? v[i+1] : v[i-1] + 1; y = x - i; while (x < la && y < lb && a[x] == b[y]) { x++; y++; } v[i] = x; if (x == la && y == lb) { goto out; } } if (verbose && di % 10000 == 0) { eprintf ("\rProcessing dist %" PFMT64d " of max %" PFMT64d "\r", di, m); } } out: if (verbose) { eprintf ("\n"); } free (v0); //Clean up output on loop exit (purely aesthetic) if (distance) { *distance = di; } if (similarity) { *similarity = length ? 1.0 - (double)di / length : 1.0; } return true; }
bool SetCursorPosConcrete( struct Tracker_Windows *window, struct WBlocks *wblock, NInt tracknum, int subtrack ){ struct WTracks *wtrack; int ret=0,tempret; if(tracknum>=wblock->block->num_tracks || tracknum<TEMPOTRACK) return false; if(tracknum<0){ if(tracknum==window->curr_track) return true; if(tracknum>window->curr_track){ while(window->curr_track!=tracknum){ tempret=CursorRight(window,wblock); ret=R_MAX(tempret,ret); } }else{ while(window->curr_track!=tracknum){ tempret=CursorLeft(window,wblock); ret=R_MAX(tempret,ret); } } }else{ wtrack=ListFindElement1(&wblock->wtracks->l,tracknum); int num_subtracks = GetNumSubtracks(wtrack); subtrack=R_MIN(num_subtracks-1,subtrack); if(tracknum==window->curr_track && subtrack==window->curr_track_sub) return 0; if(tracknum>window->curr_track || (tracknum==window->curr_track && subtrack>window->curr_track_sub)){ while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){ tempret=CursorRight(window,wblock); //printf("wtrack->num: %d, curr_track: %d, num_tracks: %d\n",wtrack->l.num, window->curr_track,wblock->block->num_tracks); ret=R_MAX(tempret,ret); } }else{ while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){ tempret=CursorLeft(window,wblock); ret=R_MAX(tempret,ret); } } } return true; }
void InsertLines_notes( void *tonote, struct ListHeader3 *l, int line, int toinsert ){ struct Notes *note=(struct Notes *)l; struct Blocks *block=blocktobelongtoforinsertlines_notes_a_terrible_hack; Place p2; PlaceSetLastPos(block,&p2); // p2.line-=toinsert; // printf("toinsert: %d, note->end.line: %d, p2->line: %d\n",toinsert,note->end.line,p2.line); if(note->end.line>=line){ // printf("block: %d, note->end.line: %d, p2->line: %d\n",block->l.num,note->end.line,p2.line); if(PlaceGreaterOrEqual(¬e->end,&p2) && note->l.p.line<line){ PlaceSetLastPos(block,&p2); PlaceCopy(¬e->end,&p2); note->noend=1; }else{ note->end.line+=toinsert; note->end.line=R_MAX(note->end.line,line); } List_InsertLines3(¬e->velocities,¬e->velocities->l,line,toinsert,NULL); List_InsertLines3(¬e->pitches,¬e->pitches->l,line,toinsert,NULL); } }
// TODO: return false if array length != fmt length SDB_API int sdb_fmt_tobin(const char *_str, const char *fmt, void *stru) { int n, idx = 0; char *next, *str, *ptr, *word, *e_str; if (!_str || !*_str || !fmt) return 0; str = ptr = strdup (_str); for (; *fmt; fmt++) { word = sdb_anext (ptr, &next); if (!word || !*word) break; n = 4; // ALIGN switch (*fmt) { case 'b': *((ut8*)(stru + idx)) = (ut8)sdb_atoi (word); break; case 'd': *((int*)(stru + idx)) = (int)sdb_atoi (word); break; case 'q': *((ut64*)(stru + idx)) = sdb_atoi (word); n=8; break; case 'h': *((short*)(stru + idx)) = (short)sdb_atoi (word); break; case 's': e_str = (char*)sdb_decode (word, 0); *((char**)(stru + idx)) = (char*)strdup (e_str?e_str:word); free (e_str); break; case 'z': *((char**)(stru + idx)) = (char*)strdup (word); break; case 'p': *((void**)(stru + idx)) = (void*)(size_t)sdb_atoi (word); break; } idx += R_MAX((long)sizeof (void*), n); // align if (!next) break; ptr = next; } free (str); return 1; }
void AddStopsElements( struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack ){ int realline = 0; struct Stops *stop=wtrack->track->stops; while(stop!=NULL){ realline=FindRealLineFor(wblock,R_MAX(stop->Tline,realline),&stop->l.p); int subrealline=FindSubRealLine(window,wblock,realline,&stop->l.p); InsertTRLElementS( wtrack, NULL, realline, TRE_STOPLINE,0, (float)subrealline,(float)subrealline,0.0f,(float)(wtrack->fxwidth-2), stop ); if(wtrack->trackreallines[realline].note!=0){ wtrack->trackreallines[realline].note=NOTE_MUL; }else{ wtrack->trackreallines[realline].note=NOTE_STP; } wtrack->trackreallines[realline].dasnote=NULL; stop=NextStop(stop); } }
// TODO: deprecate list/iterate functions from core apis? keep them for easiness? R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) { RList *list; RListIter *iter; RDebugPid *p; if (dbg && dbg->h && dbg->h->pids) { list = dbg->h->pids (R_MAX (0, pid)); if (list == NULL) return R_FALSE; if (fmt == 'j') dbg->cb_printf ("["); r_list_foreach (list, iter, p) { switch (fmt) { case 'j': dbg->cb_printf ("{\"pid\":%d," "\"status\":\"%c\"," "\"path\":\"%s\"}%s", p->pid, p->status, p->path, iter->n?",":""); break; default: dbg->cb_printf (" %c %d %c %s\n", dbg->pid==p->pid?'*':'-', p->pid, p->status, p->path); break; } } if (fmt == 'j') dbg->cb_printf ("]\n"); r_list_free (list); }
void Invert_notes( struct Notes *note, Place *p1, Place *p2, bool firsttime, int last ){ int next=0; if(note==NULL) return; if(PlaceGreaterOrEqual(¬e->l.p,p1)){ if(PlaceGreaterOrEqual(¬e->l.p,p2)) return; next=note->note; if(firsttime==false){ note->note=R_MAX(1,R_MIN(127,2*last-note->note)); }else{ firsttime=false; } } Invert_notes(NextNote(note),p1,p2,firsttime,next); }
bool TRACK_get_min_and_max_pitches(const struct Tracks *track, float *ret_min_pitch, float *ret_max_pitch){ float min_pitch = 10000.0f; float max_pitch = -10000.0f; int num_pitches = 0; // find min_pitch and max_pitch { struct Notes *note = track->notes; while(note!=NULL){ min_pitch = R_MIN(note->note, min_pitch); max_pitch = R_MAX(note->note, max_pitch); num_pitches ++; struct Pitches *pitch = note->pitches; while(pitch != NULL){ min_pitch = R_MIN(pitch->note, min_pitch); max_pitch = R_MAX(pitch->note, max_pitch); num_pitches ++; pitch = NextPitch(pitch); } note = NextNote(note); } float pitch_range = max_pitch - min_pitch; min_pitch = min_pitch - pitch_range/8.0f; if(min_pitch < 0) min_pitch = 0; max_pitch = max_pitch + pitch_range/8.0f; if(max_pitch >127) max_pitch = 127; } if(min_pitch == 10000.0f) return false; else { if (num_pitches>3) { *ret_min_pitch = min_pitch; *ret_max_pitch = max_pitch; } else { *ret_min_pitch = 0; *ret_max_pitch = 128; } return true; } }
void setFontValues(struct Tracker_Windows *tvisual){ EditorWidget *editor=(EditorWidget *)tvisual->os_visual.widget; editor->cursorbuffer_painter->setFont(editor->font); //editor->paintbuffer_painter->setFont(editor->font); GE_set_font(editor->font); const QFont &font=editor->font; QFontMetrics fm(font); double width3 = R_MAX(fm.width("D#6"), R_MAX(fm.width("MUL"), fm.width("STP"))); tvisual->fontwidth = (int)(width3/3.0) + 1; tvisual->org_fontheight = fm.height() - 1; tvisual->fontheight = tvisual->org_fontheight; }
void setSize(int size){ size = R_MAX(0, R_MIN(buffer_size-1, size)); if (size != iHslider0) { iHslider0 = size; if (can_pipe_instead == true) can_pipe_instead = false; } }
void *create_plugin_data(const SoundPluginType *plugin_type, struct SoundPlugin *plugin, hash_t *state, float sample_rate, int block_size, bool is_loading){ const char *input_portnames[R_MAX(1, plugin_type->num_outputs)]; // R_MAX is here to make the undefined sanitizer be quiet const char *output_portnames[R_MAX(1, plugin_type->num_inputs)]; // R_MAX is here to make the undefined sanitizer be quiet int i; for(i=0;i<plugin_type->num_outputs;i++) input_portnames[i] = state==NULL ? NULL : HASH_get_chars_at(state, "input_portname",i); for(i=0;i<plugin_type->num_inputs;i++) output_portnames[i] = state==NULL ? NULL : HASH_get_chars_at(state, "output_portname",i); return create_data(plugin_type, (jack_client_t*)plugin_type->data, plugin_type->num_inputs, plugin_type->num_outputs, input_portnames, output_portnames ); }
int gdbr_write_memory(libgdbr_t *g, ut64 address, const uint8_t *data, ut64 len) { int ret = 0; int command_len, pkt, max_cmd_len = 64; ut64 num_pkts, last, data_sz; char *tmp; if (!g || !data) { return -1; } g->stub_features.pkt_sz = R_MAX (g->stub_features.pkt_sz, 64); data_sz = g->stub_features.pkt_sz / 2; if (data_sz < 1) { return -1; } num_pkts = len / data_sz; last = len % data_sz; if (!(tmp = calloc (max_cmd_len + g->stub_features.pkt_sz, sizeof (char)))) { return -1; } for (pkt = num_pkts - 1; pkt >= 0; pkt--) { if ((command_len = snprintf (tmp, max_cmd_len, "%s%016"PFMT64x ",%"PFMT64x ":", CMD_WRITEMEM, address + (pkt * data_sz), data_sz)) < 0) { goto fail; } pack_hex ((char *) data + (pkt * data_sz), data_sz, (tmp + command_len)); if ((ret = send_msg (g, tmp)) < 0) { goto fail; } if ((ret = read_packet (g)) < 0) { goto fail; } if ((ret = handle_M (g)) < 0) { goto fail; } } if (last) { if ((command_len = snprintf (tmp, max_cmd_len, "%s%016"PFMT64x ",%"PFMT64x ":", CMD_WRITEMEM, address + (num_pkts * data_sz), last)) < 0) { goto fail; } pack_hex ((char *) data + (num_pkts * data_sz), last, (tmp + command_len)); if ((ret = send_msg (g, tmp)) < 0) { goto fail; } if ((ret = read_packet (g)) < 0) { goto fail; } if ((ret = handle_M (g)) < 0) { goto fail; } } free (tmp); return 0; fail: free (tmp); return -1; }
static void RT_process_between(Voice *voice, float **inputs, float **outputs, int start, int end){ if(end==start) return; int num_inputs = voice->dsp_instance->getNumInputs(); float *offsetted_inputs[R_MAX(1, num_inputs)]; for(int ch=0;ch<num_inputs; ch++) offsetted_inputs[ch] = &inputs[ch][start]; int num_outputs = voice->dsp_instance->getNumOutputs(); float *offsetted_outputs[R_MAX(1, num_outputs)]; for(int ch=0;ch<num_outputs; ch++) offsetted_outputs[ch] = &outputs[ch][start]; //printf("Computing Delta start / end: %d / %d\n",start,end); voice->dsp_instance->compute(end-start, offsetted_inputs, offsetted_outputs); }
int CursorNextTrack(struct Tracker_Windows *window,struct WBlocks *wblock){ int curr_track=window->curr_track; int ret=0,tempret; while(curr_track==window->curr_track){ tempret=CursorRight(window,wblock); ret=R_MAX(tempret,ret); } return ret; }
R_API bool r_diff_buffers_distance_original(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { if (!a || !b) { return false; } const bool verbose = diff ? diff->verbose : false; const ut32 length = R_MAX (la, lb); const ut8 *ea = a + la, *eb = b + lb, *t; ut32 *d, i, j; // Strip prefix for (; a < ea && b < eb && *a == *b; a++, b++) {} // Strip suffix for (; a < ea && b < eb && ea[-1] == eb[-1]; ea--, eb--) {} la = ea - a; lb = eb - b; if (la < lb) { i = la; la = lb; lb = i; t = a; a = b; b = t; } if (sizeof (ut32) > SIZE_MAX / (lb + 1) || !(d = malloc ((lb + 1) * sizeof (ut32)))) { return false; } for (i = 0; i <= lb; i++) { d[i] = i; } for (i = 0; i < la; i++) { ut32 ul = d[0]; d[0] = i + 1; for (j = 0; j < lb; j++) { ut32 u = d[j + 1]; d[j + 1] = a[i] == b[j] ? ul : R_MIN (ul, R_MIN (d[j], u)) + 1; ul = u; } if (verbose && i % 10000 == 0) { eprintf ("\rProcessing %" PFMT32u " of %" PFMT32u "\r", i, la); } } if (verbose) { eprintf ("\n"); } if (distance) { *distance = d[lb]; } if (similarity) { *similarity = length ? 1.0 - (double)d[lb] / length : 1.0; } free (d); return true; }
// XXX: redesign ? :) R_API char *r_print_hexpair(RPrint *p, const char *str, int n) { const char *s, *lastcol = Color_WHITE; char *d, *dst = (char *)malloc ((strlen (str)+2)*32); int colors = p->flags & R_PRINT_FLAGS_COLOR; /* XXX That's hacky as shit.. but partially works O:) */ /* TODO: Use r_print_set_cursor for win support */ int cur = R_MIN (p->cur, p->ocur); int ocur = R_MAX (p->cur, p->ocur); int ch, i; if (p->cur_enabled && cur==-1) cur = ocur; ocur++; #if CURDBG sprintf (dst, "(%d/%d/%d/%d)", p->cur_enabled, cur, ocur, n); d = dst+ strlen(dst); #else d = dst; #endif // XXX: overflow here // TODO: Use r_cons primitives here #define memcat(x,y) { memcpy(x,y,strlen(y));x+=strlen(y); } //for (s=str, d=dst; *s; s+=2, d+=2, i++) { for (s=str, i=0 ; *s; s+=2, d+=2, i++) { if (p->cur_enabled) { if (i==ocur-n) //memcat (d, "\x1b[27;47;30m"); //memcat (d, "\x1b[0m");//27;47;30m"); memcat (d, "\x1b[0m"); memcat (d, lastcol); if (i>=cur-n && i<ocur-n) memcat (d, "\x1b[7m"); } if (colors) { if (s[0]=='0' && s[1]=='0') lastcol = Color_GREEN; else if (s[0]=='7' && s[1]=='f') lastcol = Color_YELLOW; else if (s[0]=='f' && s[1]=='f') lastcol = Color_RED; else { ch = r_hex_pair2bin(s); //sscanf (s, "%02x", &ch); // XXX can be optimized if (IS_PRINTABLE (ch)) lastcol = Color_MAGENTA; } memcat (d, lastcol); } memcpy (d, s, 2); } if (colors || p->cur_enabled) memcpy (d, Color_RESET, strlen (Color_RESET)+1); else *d = 0; return dst; }
int FindNumberOfFreeReallinesDown(struct WBlocks *wblock,struct WTracks *wtrack,int realline){ int done=0; int free=realline+1; while(0==done && free<wblock->num_reallines){ done=FindNumberOfNotesOnTrackRealline(wtrack->trackreallines[free].trackreallineelements); free++; } return R_MAX(0,free-realline-2); /* The use of 'max' is just a hack here I did to get it to work. I don't know if this allways works as I haven't thought this function thru. ...After thinking a bit more, I think it is correct.*/ }
static int r_print_format_disasm(const RPrint* p, ut64 seeki, int size) { ut64 prevseeki = seeki; if (!p->disasm || !p->user) return 0; size = R_MAX (1, size); while (size-- > 0) { seeki += p->disasm (p->user, seeki); } return seeki - prevseeki; }
static ut64 getNextValid(RIO *io, RIODesc *fd, ut64 addr) { struct vm_region_submap_info_64 info; vm_address_t address = MACH_VM_MIN_ADDRESS; vm_size_t size = (vm_size_t) 0; vm_size_t osize = (vm_size_t) 0; natural_t depth = 0; kern_return_t kr; int tid = RIOMACH_PID (fd->data); task_t task = pid_to_task (tid); ut64 lower = addr; #if __arm64__ || __aarch64__ size = osize = 16384; // acording to frida #else size = osize = 4096; #endif if (the_lower != UT64_MAX) { return R_MAX (addr, the_lower); } for (;;) { mach_msg_type_number_t info_count; info_count = VM_REGION_SUBMAP_INFO_COUNT_64; memset (&info, 0, sizeof (info)); kr = vm_region_recurse_64 (task, &address, &size, &depth, (vm_region_recurse_info_t) &info, &info_count); if (kr != KERN_SUCCESS) { break; } if (lower == addr) { lower = address; } if (info.is_submap) { depth++; continue; } if (addr >= address && addr < address + size) { return addr; } if (address < lower) { lower = address; } if (size < 1) { size = osize; // f**k } address += size; size = 0; } the_lower = lower; return lower; }
static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { int copy_size; int buflen = 0; check_connection (dbg); gdbr_read_registers (desc); if (!desc) { return -1; } // read the len of the current area free (r_reg_get_bytes (dbg->reg, type, &buflen)); if (size < desc->data_len) { eprintf ("r_debug_gdb_reg_read: small buffer %d vs %d\n", (int)size, (int)desc->data_len); // return -1; } copy_size = R_MIN (desc->data_len, size); buflen = R_MAX (desc->data_len, buflen); if (reg_buf) { // if (buf_size < copy_size) { //desc->data_len) { if (buflen > buf_size) { //copy_size) { ut8* new_buf = realloc (reg_buf, buflen); if (!new_buf) { return -1; } reg_buf = new_buf; buf_size = buflen; } } else { reg_buf = calloc (buflen, 1); if (!reg_buf) { return -1; } buf_size = buflen; } memset ((void*)(volatile void*)buf, 0, size); memcpy ((void*)(volatile void*)buf, desc->data, R_MIN (copy_size, size)); memset ((void*)(volatile void*)reg_buf, 0, buflen); memcpy ((void*)(volatile void*)reg_buf, desc->data, copy_size); #if 0 int i; //for(i=0;i<168;i++) { for(i=0;i<copy_size;i++) { if (!(i%16)) printf ("\n0x%08x ", i); printf ("%02x ", buf[i]); //(ut8)desc->data[i]); } printf("\n"); #endif return desc->data_len; }
void AddPitchElements( struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack ){ float min_pitch = 10000.0f; float max_pitch = -10000.0f; TRACK_get_min_and_max_pitches(wtrack->track,&min_pitch, &max_pitch); struct Notes *note=wtrack->track->notes; while(note!=NULL){ struct Pitches *pitch=note->pitches; int realline = 0; while(pitch!=NULL){ realline=FindRealLineFor(wblock,R_MAX(pitch->Tline,realline),&pitch->l.p); int subrealline=FindSubRealLine(window,wblock,realline,&pitch->l.p); InsertTRLElementS( wtrack, note, realline, TRE_THISPITCHLINES,0, (float)subrealline,(float)subrealline,0.0f,(float)(wtrack->fxwidth-2), pitch ); if (wtrack->trackreallines[realline].note!=0) { wtrack->trackreallines[realline].note=NOTE_MUL; wtrack->trackreallines[realline].dasnote=NULL; } else { wtrack->trackreallines[realline].note=pitch->note; wtrack->trackreallines[realline].daspitch=pitch; } pitch=NextPitch(pitch); } #if !USE_OPENGL UpdateWPitches(window, wblock, wtrack, note, min_pitch, max_pitch); #endif note=NextNote(note); } }
R_API void *r_vector_insert_range(RVector *vec, size_t index, void *first, size_t count) { if (vec->len + count > vec->capacity) { RESIZE_OR_RETURN_NULL (R_MAX (NEXT_VECTOR_CAPACITY, vec->len + count)); } size_t sz = count * vec->elem_size; void *p = r_vector_index_ptr (vec, index); if (index < vec->len) { memmove ((char *)p + sz, p, vec->elem_size * (vec->len - index)); } vec->len += count; if (first) { memcpy (p, first, sz); } return p; }
/******************************************************************* FUNCTION Set Maximum number of velocitylines showed simultaniously on track (i.e wtrack->num_vel). wtrack->num_vel is the same as maximum polyphony for track. The next three procedures are to be viewed as one function. *******************************************************************/ static void SetNum_Vel_set( struct WTracks *wtrack, struct FindNum_Velstruct **velroot ){ struct FindNum_Velstruct *velstruct=*velroot; int num_vel=0; wtrack->num_vel=0; while(velstruct!=NULL){ num_vel+=velstruct->startstop; if(num_vel>wtrack->num_vel) wtrack->num_vel=num_vel; velstruct=NextFindNum_Velstruct(velstruct); } wtrack->num_vel=R_MAX(1,wtrack->num_vel); }
SDB_API void sdb_fmt_free (void *stru, const char *fmt) { int n, len = 0; for (; *fmt; fmt++) { n = 4; switch (*fmt) { case 'p': // TODO: leak or wat case 'b': case 'h': case 'd': break; case 'q': n = 8; break; case 'z': case 's': free ((void*)*((char**)(stru+len))); break; } len += R_MAX ((long)sizeof (void*), n); // align } }
void GFX_Point( struct Tracker_Windows *window, int color, int brightness, int x,int y, int where ) { if(where==PAINT_DIRECTLY){ RError("GFX_Point can not be called with where==PAINT_DIRECTLY"); return; } if(color>=16 || color<0){ RError("Illegal color: %d",color); color = R_ABS(color) % 16; } brightness = R_BOUNDARIES(0, brightness, MAX_BRIGHTNESS); #if 0 OS_GFX_Point(window,color,brightness,x,y,where); return; #endif struct Points *point=points[color][brightness]; if(point==NULL) points[color][brightness] = point = calloc(1,sizeof(struct Points)); int pos = point->pos; if(point->pos==point->size){ point->size = R_MAX(128,point->size*2); point->x=realloc(point->x,point->size*sizeof(uint16_t)); point->y=realloc(point->y,point->size*sizeof(uint16_t)); } point->x[pos] = x; point->y[pos] = y; point->pos = pos+1; is_dirty=true; }
/* const char *fn: list of magic files and directories */ struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) { char *p, *mfn; int file_err, errs = -1; struct mlist *mlist; init_file_tables (); if (!fn) fn = getenv ("MAGIC"); if (!fn) fn = MAGICFILE; if (!(mfn = strdup (fn))) { file_oomem (ms, strlen (fn)); return NULL; } fn = mfn; if (!(mlist = malloc (sizeof (*mlist)))) { free (mfn); file_oomem (ms, sizeof (*mlist)); return NULL; } mlist->next = mlist->prev = mlist; while (fn) { p = strchr (fn, PATHSEP); if (p) *p++ = '\0'; if (*fn == '\0') break; file_err = apprentice_1 (ms, fn, action, mlist); errs = R_MAX (errs, file_err); fn = p; } if (errs == -1) { free (mfn); free (mlist); mlist = NULL; file_error (ms, 0, "could not find any magic files!"); return NULL; } free (mfn); return mlist; }
int gdbr_read_file(libgdbr_t *g, ut8 *buf, ut64 max_len) { int ret, ret1; char command[64]; ut64 data_sz; if (!g || !buf || !max_len) { return -1; } if (max_len >= INT32_MAX) { eprintf ("%s: Too big a file read requested: %"PFMT64d, __func__, max_len); return -1; } if (g->remote_file_fd < 0) { eprintf ("%s: No remote file opened\n", __func__); return -1; } g->stub_features.pkt_sz = R_MAX (g->stub_features.pkt_sz, 64); data_sz = g->stub_features.pkt_sz / 2; ret = 0; while (ret < max_len) { if ((ret1 = snprintf (command, sizeof (command) - 1, "vFile:pread:%x,%"PFMT64x",%"PFMT64x, (int)g->remote_file_fd, (ut64)R_MIN(data_sz, max_len - ret), (ut64)ret)) < 0) { return -1; } if (send_msg (g, command) < 0) { return -1; } if (read_packet (g) < 0) { return -1; } if ((ret1 = handle_vFile_pread (g, buf + ret)) < 0) { return -1; } if (ret1 == 0) { return ret; } ret += ret1; } return ret; }
void GFXST_TextType( void (*GFX_OSFunc)( struct Tracker_Windows *window, enum ColorNums color,const char *text, int x,int y, int width, int flags, int where ), struct Tracker_Windows *window, enum ColorNums color,const char *text, int x,int y, int width, int flags, int where ) { if(flags & TEXT_NOTEXT){ int minx=getMinX(window); GFXS_TextType(GFX_OSFunc,window,color,text,R_MAX(minx,x),y,width,flags,where); }else{ int minx=getMinX(window); if(GFX_OSFunc==QUEUE_GFX_Text){ if(x<minx){ x=minx; //char temp[600]; //sprintf(temp,"<--%s",text); //GFXS_TextType(GFX_OSFunc,window,color,temp,x,y,width,flags,where); }else GFXS_TextType(GFX_OSFunc,window,color,text,x,y,width,flags,where); }else{ if(x<minx){ if((strlen(text)+1)*window->fontwidth<minx) return; text+=(minx-x)/window->fontwidth; x=minx; } GFXS_TextType(GFX_OSFunc,window,color,text,x,y,width,flags,where); } } }