static void repaintmainmenu(int width, menu *mp) { int i; menu *p = mp; for (i = 0; p->func; i++, p++) mvwaddstr(wmain, 0, i * width, prepad(padstr(p->name, width - 1), 1)); touchwin(wmain); wrefresh(wmain); }
static void repainteditbox(WINDOW *win, int x, char *buf) { #ifndef PDCURSES int maxy; #endif int maxx; #ifdef PDCURSES maxx = getmaxx(win); #else getmaxyx(win, maxy, maxx); #endif werase(win); mvwprintw(win, 0, 0, "%s", padstr(buf, maxx)); wmove(win, 0, x); wrefresh(win); }
static void rmline(WINDOW *win, int nr) /* keeps box lines intact */ { mvwaddstr(win, nr, 1, padstr(" ", bw - 2)); wrefresh(win); }
void domenu(menu *mp) { int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0; bool stop = FALSE; WINDOW *wmenu; curs_set(0); getmenupos(&y, &x); menudim(mp, &nitems, &barlen); mheight = nitems + 2; mw = barlen + 2; wmenu = newwin(mheight, mw, y, x); colorbox(wmenu, SUBMENUCOLOR, 1); repaintmenu(wmenu, mp); key = ERR; while (!stop && !quit) { if (cur != old) { if (old != -1) mvwaddstr(wmenu, old + 1, 1, prepad(padstr(mp[old].name, barlen - 1), 1)); setcolor(wmenu, SUBMENUREVCOLOR); mvwaddstr(wmenu, cur + 1, 1, prepad(padstr(mp[cur].name, barlen - 1), 1)); setcolor(wmenu, SUBMENUCOLOR); statusmsg(mp[cur].desc); old = cur; wrefresh(wmenu); } switch (key = ((key != ERR) ? key : waitforkey())) { case '\n': /* menu item selected */ touchwin(wbody); wrefresh(wbody); setmenupos(y + 1, x + 1); rmerror(); key = ERR; curs_set(1); (mp[cur].func)(); /* perform function */ curs_set(0); repaintmenu(wmenu, mp); old = -1; break; case KEY_UP: cur = (cur + nitems - 1) % nitems; key = ERR; break; case KEY_DOWN: cur = (cur + 1) % nitems; key = ERR; break; case KEY_ESC: case KEY_LEFT: case KEY_RIGHT: if (key == KEY_ESC) key = ERR; /* return to prev submenu */ stop = TRUE; break; default: cur0 = cur; do { cur = (cur + 1) % nitems; } while ((cur != cur0) && (hotkey(mp[cur].name) != toupper((int)key))); key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR; } } rmerror(); delwin(wmenu); touchwin(wbody); wrefresh(wbody); }
void statusmsg(char *msg) { mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3)); wrefresh(wstat); }
void errormsg(char *msg) { beep(); mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3)); wrefresh(wstat); }
void titlemsg(char *msg) { mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3)); wrefresh(wtitl); }
static void mainmenu(menu *mp) { int nitems, barlen, old = -1, cur = 0, c, cur0; menudim(mp, &nitems, &barlen); repaintmainmenu(barlen, mp); while (!quit) { if (cur != old) { if (old != -1) { mvwaddstr(wmain, 0, old * barlen, prepad(padstr(mp[old].name, barlen - 1), 1)); statusmsg(mp[cur].desc); } else mainhelp(); setcolor(wmain, MAINMENUREVCOLOR); mvwaddstr(wmain, 0, cur * barlen, prepad(padstr(mp[cur].name, barlen - 1), 1)); setcolor(wmain, MAINMENUCOLOR); old = cur; wrefresh(wmain); } switch (c = (key != ERR ? key : waitforkey())) { case KEY_DOWN: case '\n': /* menu item selected */ touchwin(wbody); wrefresh(wbody); rmerror(); setmenupos(th + mh, cur * barlen); curs_set(1); (mp[cur].func)(); /* perform function */ curs_set(0); switch (key) { case KEY_LEFT: cur = (cur + nitems - 1) % nitems; key = '\n'; break; case KEY_RIGHT: cur = (cur + 1) % nitems; key = '\n'; break; default: key = ERR; } repaintmainmenu(barlen, mp); old = -1; break; case KEY_LEFT: cur = (cur + nitems - 1) % nitems; break; case KEY_RIGHT: cur = (cur + 1) % nitems; break; case KEY_ESC: mainhelp(); break; default: cur0 = cur; do { cur = (cur + 1) % nitems; } while ((cur != cur0) && (hotkey(mp[cur].name) != toupper(c))); if (hotkey(mp[cur].name) == toupper(c)) key = '\n'; } } rmerror(); touchwin(wbody); wrefresh(wbody); }
static void _kprintf(const char* fmt, va_list ap) { char buffer[BUFFER_LEN]; while (*fmt) { for (; *fmt && *fmt != '%'; ++fmt) { write_char(*fmt); } if (!*fmt) { return; } uint8_t leftadjust = 0; char padchar = ' '; int64_t width = 0; char ch = *(++fmt); if (ch == '-') { leftadjust = 1; ch = *(++fmt); } if (ch == '0') { padchar = '0'; ch = *(++fmt); } while (ch != '\0' && ch >= '0' && ch <= '9') { width *= 10; width += ch - '0'; ch = *(++fmt); } /* TODO - Probably print error instead */ if (!*fmt) return; ++fmt; switch (ch) { case 'c': case 'C': { uint64_t c = va_arg(ap, uint64_t); buffer[0] = c; padstr(buffer, 1, width, leftadjust, padchar); } break; case 'd': case 'D': { int64_t idx = convert_decimal(buffer, va_arg(ap, int64_t)); padstr(&buffer[idx], BUFFER_LEN-idx, width, leftadjust, padchar); } break; case 'u': case 'U': { int64_t idx = convert_radix(buffer, 10, va_arg(ap, uint64_t)); padstr(&buffer[idx], BUFFER_LEN-idx, width, leftadjust, padchar); } break; case 'l': case 'L': { // Read length uint64_t length = 0; char ch = *fmt; while (ch != '\0' && ch > '0' && ch < '9') { length *= 10; length += ch - '0'; ch = *(++fmt); } if (ch != 's') { panic("Invalid format specifier"); } const char* str = va_arg(ap, const char*); padstr(str, length, width, leftadjust, padchar); } break; case 's': case 'S': { const char* str = va_arg(ap, const char*); padstr(str, string_length(str), width, leftadjust, padchar); } break; case 'x': case 'X': { int64_t idx = convert_radix(buffer, 16, va_arg(ap, uint64_t)); padstr(&buffer[idx], BUFFER_LEN-idx, width, leftadjust, padchar); } break; case 'b': case 'B': { int64_t idx = convert_radix(buffer, 2, va_arg(ap, uint64_t)); padstr(&buffer[idx], BUFFER_LEN-idx, width, leftadjust, padchar); } break; case 'o': case 'O': { int64_t idx = convert_radix(buffer, 8, va_arg(ap, uint64_t)); padstr(&buffer[idx], BUFFER_LEN-idx, width, leftadjust, padchar); } break; case '%': { write_char('%'); } break; default: { write_char('B'); panic("kprintf: Bad format string"); } break; } } }
/******************************************************************************** * Handle completion of a command - pass results back through the CCB */ static void mly_cam_complete(struct mly_command *mc) { struct mly_softc *sc = mc->mc_sc; struct ccb_scsiio *csio = (struct ccb_scsiio *)mc->mc_private; struct scsi_inquiry_data *inq = (struct scsi_inquiry_data *)csio->data_ptr; struct mly_btl *btl; u_int8_t cmd; int bus, target; debug_called(2); csio->scsi_status = mc->mc_status; switch(mc->mc_status) { case SCSI_STATUS_OK: /* * In order to report logical device type and status, we overwrite * the result of the INQUIRY command to logical devices. */ bus = csio->ccb_h.sim_priv.entries[0].field; if (bus >= sc->mly_controllerinfo->physical_channels_present) { if (csio->ccb_h.flags & CAM_CDB_POINTER) { cmd = *csio->cdb_io.cdb_ptr; } else { cmd = csio->cdb_io.cdb_bytes[0]; } if (cmd == INQUIRY) { target = csio->ccb_h.target_id; btl = &sc->mly_btl[bus][target]; padstr(inq->vendor, mly_describe_code(mly_table_device_type, btl->mb_type), 8); padstr(inq->product, mly_describe_code(mly_table_device_state, btl->mb_state), 16); padstr(inq->revision, "", 4); } } debug(2, "SCSI_STATUS_OK"); csio->ccb_h.status = CAM_REQ_CMP; break; case SCSI_STATUS_CHECK_COND: debug(2, "SCSI_STATUS_CHECK_COND sense %d resid %d", mc->mc_sense, mc->mc_resid); csio->ccb_h.status = CAM_SCSI_STATUS_ERROR; bzero(&csio->sense_data, SSD_FULL_SIZE); bcopy(mc->mc_packet, &csio->sense_data, mc->mc_sense); csio->sense_len = mc->mc_sense; csio->ccb_h.status |= CAM_AUTOSNS_VALID; csio->resid = mc->mc_resid; /* XXX this is a signed value... */ break; case SCSI_STATUS_BUSY: debug(2, "SCSI_STATUS_BUSY"); csio->ccb_h.status = CAM_SCSI_BUSY; break; default: debug(2, "unknown status 0x%x", csio->scsi_status); csio->ccb_h.status = CAM_REQ_CMP_ERR; break; } xpt_done((union ccb *)csio); mly_release_command(mc); }