static int cmdreq(Dev *d, int type, int req, int value, int index, uchar *data, int count) { int ndata, n; uchar *wp; uchar buf[8]; char *hd, *rs; assert(d != nil); if(data == nil){ wp = buf; ndata = 0; }else{ ndata = count; wp = emallocz(8+ndata, 0); } wp[0] = type; wp[1] = req; PUT2(wp+2, value); PUT2(wp+4, index); PUT2(wp+6, count); if(data != nil) memmove(wp+8, data, ndata); if(usbdebug>2){ hd = hexstr(wp, ndata+8); rs = reqstr(type, req); fprint(2, "%s: %s val %d|%d idx %d cnt %d out[%d] %s\n", d->dir, rs, value>>8, value&0xFF, index, count, ndata+8, hd); free(hd); }
void zft_ftape_extract_file_marks(__u8* address) { int i; TRACE_FUN(ft_t_any); zft_eof_map = NULL; if (ft_format_code == fmt_var || ft_format_code == fmt_big) { __u8* end; __u8* start = ftape_find_end_of_bsm_list(address); zft_nr_eof_marks = 0; if (start) { start += 3; /* skip end of list mark */ end = find_end_of_eof_list(start, address + FT_SEGMENT_SIZE); if (end && end - start <= FT_FSL_SIZE) { zft_nr_eof_marks = ((end - start) / sizeof(eof_mark_union)); zft_eof_map = (eof_mark_union *)start; } else { TRACE(ft_t_err, "EOF Mark List is too long or damaged!"); } } else { TRACE(ft_t_err, "Bad Sector List is too long or damaged !"); } } else { zft_eof_map = (eof_mark_union *)&address[FT_FSL]; zft_nr_eof_marks = GET2(address, FT_FSL_CNT); } TRACE(ft_t_noise, "number of file marks: %d", zft_nr_eof_marks); if (ftape_fmt_version == 1) { TRACE(ft_t_info, "swapping version 1 fields"); /* version 1 format uses swapped sector and segment * fields, correct that ! */ for (i = 0; i < zft_nr_eof_marks; ++i) { __u16 tmp = GET2(&zft_eof_map[i].mark.segment,0); PUT2(&zft_eof_map[i].mark.segment, 0, GET2(&zft_eof_map[i].mark.date,0)); PUT2(&zft_eof_map[i].mark.date, 0, tmp); } } for (i = 0; i < zft_nr_eof_marks; ++i) { TRACE(ft_t_noise, "eof mark: %5d/%2d", GET2(&zft_eof_map[i].mark.segment, 0), GET2(&zft_eof_map[i].mark.date,0)); } TRACE_EXIT; }
/* -- write a title -- */ void write_title(struct SYMBOL *s) { char *p; p = &s->as.text[2]; while (isspace((unsigned char) *p)) p++; if (*p == '\0') return; p = trim_title(p, s == info['T' - 'A']); if (s == info['T' - 'A']) { bskip(cfmt.titlespace + cfmt.font_tb[TITLEFONT].size); set_font(TITLEFONT); } else { bskip(cfmt.subtitlespace + cfmt.font_tb[SUBTITLEFONT].size); set_font(SUBTITLEFONT); } if (cfmt.titleleft) PUT0("0 0 M("); else PUT1("%.1f 0 M(", 0.5 * ((cfmt.landscape ? cfmt.pageheight : cfmt.pagewidth) - cfmt.leftmargin - cfmt.rightmargin) / cfmt.scale); tex_str(p); PUT2("%s)show%s\n", tex_buf, cfmt.titleleft ? "" : "c"); }
void write_constant_pool (CPool *cpool, unsigned char *buffer, int length) { unsigned char *ptr = buffer; int i = 1; union cpool_entry *datap = &cpool->data[1]; PUT2 (cpool->count); for ( ; i < cpool->count; i++, datap++) { int tag = cpool->tags[i]; PUT1 (tag); switch (tag) { case CONSTANT_NameAndType: case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: case CONSTANT_Float: case CONSTANT_Integer: PUT4 (datap->w); break; case CONSTANT_Class: case CONSTANT_String: PUT2 (datap->w); break; break; case CONSTANT_Long: case CONSTANT_Double: PUT4(datap->w); i++; datap++; PUT4 (datap->w); break; case CONSTANT_Utf8: { tree t = datap->t; int len = IDENTIFIER_LENGTH (t); PUT2 (len); PUTN (IDENTIFIER_POINTER (t), len); } break; } } if (ptr != buffer + length) abort (); }
/* -- output a string, handling the font changes -- */ void str_out(char *p, int action) { if (curft <= 0) /* first call */ curft = defft; /* special case when font change at start of text */ /*---fixme: authorize 2 chars?*/ if (*p == '$' && isdigit((unsigned char) p[1]) && (unsigned) (p[1] - '0') < FONT_UMAX) { if (curft != p[1] - '0') { curft = p[1] - '0'; if (curft == 0) curft = defft; } p += 2; } /* direct output if no font change */ if (strchr(p, '$') == 0) { char *op; set_font(curft); if (action == A_CENTER) op = "c"; else if (action == A_RIGHT) op = "r"; else op = ""; PUT2("(%s)show%s ", p, op); return; } /* if not left aligned, build a PS function */ if (action == A_LEFT) strop = "show"; else { PUT0("/str{"); outft = -1; strop = "strop"; } str_ft_out(p, 1); /* output the string */ /* if not left aligned, call the PS function */ if (action == A_LEFT) return; PUT0("}def\n" "/strop/strw load def/w 0 def str w "); if (action == A_CENTER) PUT0("0.5 mul "); PUT0("neg 0 RM/strop/show load def str "); }
void zft_clear_ftape_file_marks(void) { TRACE_FUN(ft_t_flow); /* Clear failed sector log: remove all tape marks. We * don't use old ftape-style EOF-marks. */ TRACE(ft_t_info, "Clearing old ftape's eof map"); memset(zft_eof_map, 0, zft_nr_eof_marks * sizeof(__u32)); zft_nr_eof_marks = 0; PUT2(zft_hseg_buf, FT_FSL_CNT, 0); /* nr of eof-marks */ zft_header_changed = 1; zft_update_label(zft_hseg_buf); TRACE_EXIT; }
/* -- output one string -- */ static void str_ft_out1(char *p, int l) { if (curft != outft) { if (strtx) { PUT1(")%s ", strop); strtx = 0; } if (curft == 0) curft = defft; set_font(curft); } if (!strtx) { PUT0("("); strtx = 1; } PUT2("%.*s", l, p); }
static int miiwrite(Dev *d, int phy, int reg, int val) { int r; uchar v[2]; if(asixset(d, Cswmii, 0) < 0) return -1; r = Rh2d|Rvendor|Rdev; PUT2(v, val); if(usbcmd(d, r, Cwmii, phy, reg, v, 2) < 0){ deprint(2, "%s: miiwrite: %#x %#x %r\n", argv0, reg, val); return -1; } if(asixset(d, Chwmii, 0) < 0) return -1; return 0; }
uint convW2M(Wsysmsg *m, uchar *p, uint n) { int nn; nn = sizeW2M(m); if(n < nn || nn == 0 || n < 6) return 0; PUT(p, nn); p[4] = m->tag; p[5] = m->type; switch(m->type){ default: return 0; case Trdmouse: case Rbouncemouse: case Rmoveto: case Rcursor: case Trdkbd: case Rlabel: case Rinit: case Trdsnarf: case Rwrsnarf: case Ttop: case Rtop: case Rresize: break; case Rerror: PUTSTRING(p+6, m->error); break; case Rrdmouse: PUT(p+6, m->mouse.xy.x); PUT(p+10, m->mouse.xy.y); PUT(p+14, m->mouse.buttons); PUT(p+18, m->mouse.msec); p[19] = m->resized; break; case Tbouncemouse: PUT(p+6, m->mouse.xy.x); PUT(p+10, m->mouse.xy.y); PUT(p+14, m->mouse.buttons); break; case Tmoveto: PUT(p+6, m->mouse.xy.x); PUT(p+10, m->mouse.xy.y); break; case Tcursor: PUT(p+6, m->cursor.offset.x); PUT(p+10, m->cursor.offset.y); memmove(p+14, m->cursor.clr, sizeof m->cursor.clr); memmove(p+46, m->cursor.set, sizeof m->cursor.set); PUT(p+78, m->cursor2.offset.x); PUT(p+82, m->cursor2.offset.y); memmove(p+86, m->cursor2.clr, sizeof m->cursor2.clr); memmove(p+214, m->cursor2.set, sizeof m->cursor2.set); p[342] = m->arrowcursor; break; case Rrdkbd: PUT2(p+6, m->rune); break; case Tlabel: PUTSTRING(p+6, m->label); break; case Tinit: p += 6; p += PUTSTRING(p, m->winsize); p += PUTSTRING(p, m->label); break; case Rrdsnarf: case Twrsnarf: PUTSTRING(p+6, m->snarf); break; case Rrddraw: case Twrdraw: PUT(p+6, m->count); memmove(p+10, m->data, m->count); break; case Trddraw: case Rwrdraw: PUT(p+6, m->count); break; case Tresize: PUT(p+6, m->rect.min.x); PUT(p+10, m->rect.min.y); PUT(p+14, m->rect.max.x); PUT(p+18, m->rect.max.y); break; } return nn; }
/* -- write heading with format -- */ static void write_headform(float lwidth) { char *p, *q; struct SYMBOL *s; struct FONTSPEC *f; int align, i, j; float x, y, xa[3], ya[3], sz, yb[3]; char inf_nb[26]; INFO inf_s; char inf_ft[26]; float inf_sz[26]; char fmt[64]; memset(inf_nb, 0, sizeof inf_nb); memset(inf_ft, HISTORYFONT, sizeof inf_ft); inf_ft['A' - 'A'] = INFOFONT; inf_ft['C' - 'A'] = COMPOSERFONT; inf_ft['O' - 'A'] = COMPOSERFONT; inf_ft['P' - 'A'] = PARTSFONT; inf_ft['Q' - 'A'] = TEMPOFONT; inf_ft['R' - 'A'] = INFOFONT; inf_ft['T' - 'A'] = TITLEFONT; inf_ft['X' - 'A'] = TITLEFONT; memcpy(inf_s, info, sizeof inf_s); memset(inf_sz, 0, sizeof inf_sz); inf_sz['A' - 'A'] = cfmt.infospace; inf_sz['C' - 'A'] = cfmt.composerspace; inf_sz['O' - 'A'] = cfmt.composerspace; inf_sz['R' - 'A'] = cfmt.infospace; p = cfmt.titleformat; j = 0; for (;;) { while (isspace((unsigned char) *p)) p++; if (*p == '\0') break; i = *p - 'A'; if ((unsigned) i < 26) { inf_nb[i]++; switch (p[1]) { default: align = A_CENTER; break; case '1': align = A_RIGHT; p++; break; case '-': align = A_LEFT; p++; break; } if (j < sizeof fmt - 4) { fmt[j++] = i; fmt[j++] = align; } } else if (*p == ',') { if (j < sizeof fmt - 3) fmt[j++] = 126; /* next line */ } else if (*p == '+') { if (j > 0 && fmt[j - 1] < 125 && j < sizeof fmt - 3) fmt[j++] = 125; /* concatenate */ /*new fixme: add free text "..." ?*/ } p++; } fmt[j++] = 126; /* newline */ fmt[j] = 127; /* end of format */ ya[0] = ya[1] = ya[2] = cfmt.titlespace;; xa[0] = 0; xa[1] = lwidth * 0.5; xa[2] = lwidth; p = fmt; for (;;) { yb[0] = yb[1] = yb[2] = y = 0; q = p; for (;;) { i = *q++; if (i >= 126) /* if newline */ break; align = *q++; if (yb[align + 1] != 0) continue; s = inf_s[i]; if (s == 0 || inf_nb[i] == 0) continue; j = inf_ft[i]; f = &cfmt.font_tb[j]; sz = f->size * 1.1 + inf_sz[i]; if (y < sz) y = sz; yb[align + 1] = sz; /*fixme:should count the height of the concatenated field*/ if (*q == 125) q++; } for (i = 0; i < 3; i++) ya[i] += y - yb[i]; for (;;) { i = *p++; if (i >= 126) /* if newline */ break; align = *p++; s = inf_s[i]; if (s == 0 || inf_nb[i] == 0) continue; j = inf_ft[i]; str_font(j); x = xa[align + 1]; f = &cfmt.font_tb[j]; sz = f->size * 1.1 + inf_sz[i]; y = ya[align + 1] + sz; PUT2("%.1f %.1f M ", x, -y); if (*p == 125) { /* concatenate */ p++; /*fixme: do it work with different fields*/ if (*p == i && p[1] == align && s->next != 0) { char buf[256], *r; q = s->as.text; if (q[1] == ':') q += 2; while (isspace((unsigned char) *q)) q++; if (i == 'T' - 'A') q = trim_title(q, s == inf_s['T' - 'A']); strncpy(buf, q, sizeof buf - 1); buf[sizeof buf - 1] = '\0'; j = strlen(buf); if (j < sizeof buf - 1) { buf[j] = ' '; buf[j + 1] = '\0'; } s = s->next; q = s->as.text; if (q[1] == ':') q += 2; while (isspace((unsigned char) *q)) q++; if (s->as.text[0] == 'T' && s->as.text[1] == ':') q = trim_title(q, 0); r = buf + strlen(buf); strncpy(r, q, buf + sizeof buf - r - 1); tex_str(buf); str_out(tex_buf, align); PUT0("\n"); inf_nb[i]--; p += 2; } } else if (i == 'Q' - 'A') { /* special case for tempo */ if (align != A_LEFT) { float w; w = tempo_width(s); if (align == A_CENTER) PUT1("-%.1f 0 RM ", w * 0.5); else PUT1("-%.1f 0 RM ", w); } write_tempo(s, 0, 0.75); } else put_inf2r(s, 0, align); if (inf_s[i] == info['T' - 'A']) { inf_ft[i] = SUBTITLEFONT; str_font(SUBTITLEFONT); f = &cfmt.font_tb[SUBTITLEFONT]; inf_sz[i] = cfmt.subtitlespace; sz = f->size * 1.1 + inf_sz[i]; } s = s->next; if (inf_nb[i] == 1) { while (s != 0) { y += sz; PUT2("%.1f %.1f M ", x, -y); put_inf2r(s, 0, align); s = s->next; } } inf_s[i] = s; inf_nb[i]--; ya[align + 1] = y; } if (ya[1] > ya[0]) ya[0] = ya[1]; if (ya[2] > ya[0]) ya[0] = ya[2]; if (*p == 127) { bskip(ya[0]); break; } ya[1] = ya[2] = ya[0]; } }
/* -- add text to a block -- */ void add_to_text_block(char *s, int job) { float baseskip, lw; char *p, sep; struct FONTSPEC *f; /* if first line, set the fonts */ if (strtw < 0) { str_font(TEXTFONT); strlw = ((cfmt.landscape ? cfmt.pageheight : cfmt.pagewidth) - cfmt.leftmargin - cfmt.rightmargin) / cfmt.scale; } if (curft > 0) f = &cfmt.font_tb[curft]; else f = &cfmt.font_tb[defft]; baseskip = f->size * cfmt.lineskipfac; /* follow lines */ if (job == T_LEFT || job == T_CENTER || job == T_RIGHT) { if (*s != '\0') { bskip(baseskip); if (job == T_LEFT) { PUT0("0 0 M "); put_str(s, A_LEFT); } else if (job == T_CENTER) { PUT1("%.1f 0 M ", strlw * 0.5); put_str(s, A_CENTER); } else { PUT1("%.1f 0 M ", strlw); put_str(s, A_RIGHT); } } else { bskip(baseskip * 0.5); buffer_eob(); } strtw = 0; return; } /* fill or justify lines */ if (strtw < 0) { /* if first line */ curft = defft; bskip(baseskip); PUT0("0 0 M "); if (job == T_FILL) strop = "show"; else { PUT0("/str{"); outft = -1; strop = "strop"; } strns = 0; strtw = 0; } if (*s == '\0') { /* empty line */ if (strtx) { PUT1(")%s", strop); strtx = 0; } if (job == T_JUSTIFY) PUT0("}def\n" "/strop/show load def str\n"); else PUT0("\n"); bskip(f->size * cfmt.lineskipfac * 1.5); buffer_eob(); PUT0("0 0 M "); if (job == T_JUSTIFY) { PUT0("/str{"); outft = -1; } strns = 0; strtw = 0; return; } p = s; for (;;) { while (*p != ' ' && *p != '\0') p++; sep = *p; *p = '\0'; lw = tex_str(s); if (strtw + lw > strlw) { if (strtx) { PUT1(")%s ", strop); strtx = 0; } if (job == T_JUSTIFY) { if (strns == 0) strns = 1; PUT2("}def\n" "/strop/strw load def/w 0 def str" "/w %.1f w sub %d div def" "/strop/jshow load def str ", strlw, strns); strns = 0; } bskip(cfmt.font_tb[curft].size * cfmt.lineskipfac); PUT0("0 0 M "); if (job == T_JUSTIFY) { PUT0("/str{"); outft = -1; } strtw = 0; } if (strtw != 0) { str_ft_out(" ", 0); strtw += cwid(' ') * cfmt.font_tb[curft].swfac; strns++; } str_ft_out(tex_buf, 0); strtw += lw; *p = sep; while (*p == ' ') p++; if (*p == '\0') break; s = p; } }