pvr@wang.com (Peter Reilley) (02/28/91)
#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 9 (of 11)." # Contents: random.c # Wrapped by pvr@elf on Wed Feb 27 14:16:50 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'random.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'random.c'\" else echo shar: Extracting \"'random.c'\" \(30672 characters\) sed "s/^X//" >'random.c' <<'END_OF_FILE' X/* X* Assorted commands. X* The file contains the command X* processors for a large assortment of unrelated X* commands. The only thing they have in common is X* that they are all command processors. X*/ X X#include "def.h" X Xchar backdel (); Xbool fill_out (); Xvoid bad_key (); X X X Xextern char MSG_sh_pos[]; Xextern char MSG_sh_pos1[]; Xextern char MSG_f_str[]; Xextern char MSG_3u[]; Xextern char MSG_5u[]; Xextern char MSG_lu[]; Xextern char MSG_03u[]; Xextern char MSG_05u[]; Xextern char MSG_010lu[]; Xextern char MSG_lnk[]; Xextern char MSG_unlink[]; Xextern char MSG_link[]; Xextern char MSG_bad_key[]; Xextern char MSG_esc[]; Xextern char MSG_ctl_x[]; Xextern char MSG_ctl[]; Xextern char MSG_key_code[]; Xextern char char_str[]; X X#if RUNCHK Xextern char ERR_rnd_1[]; Xextern char ERR_rnd_2[]; Xextern char ERR_rnd_3[]; Xextern char ERR_rnd_4[]; Xextern char MSG_rnd_5[]; Xextern char ERR_rnd_6[]; Xextern char ERR_rnd_7[]; X#endif X#include "lintfunc.dec" X Xextern ROW_FMT ascii_fmt; Xextern ROW_FMT ebcdic_fmt; Xextern ROW_FMT binary_8_fmt; Xextern ROW_FMT binary_16_fmt; Xextern ROW_FMT binary_32_fmt; Xextern ROW_FMT octal_8_fmt; Xextern ROW_FMT octal_16_fmt; Xextern ROW_FMT octal_32_fmt; Xextern ROW_FMT decimal_8_fmt; Xextern ROW_FMT decimal_16_fmt; Xextern ROW_FMT decimal_32_fmt; Xextern ROW_FMT hex_8_fmt; Xextern ROW_FMT hex_16_fmt; Xextern ROW_FMT hex_32_fmt; X Xextern bool read_pat_mode; Xextern bool dont_repeat; X Xchar dec_chr_ok (); Xulong get_long (); X X/* X* Display a bunch of useful information about X* the current location of dot and mark. X* The position of the dot and mark and the difference between them. X* The total buffer size is displayed. X* This is normally bound to "C-X =". X*/ Xbool showcpos (f, n, k) X{ X X A32 dotoff, X markoff, X fsize, X bsize; X char buf[80], buf1[80]; X X dotoff = curwp -> w_dotp -> l_file_offset; X dotoff += curwp -> w_doto; X X if (curwp -> w_markp != NULL) X { X markoff = curwp -> w_markp -> l_file_offset; X markoff += curwp -> w_marko; X } X X bsize = curwp -> w_bufp -> b_linep -> l_bp -> l_file_offset; X bsize += curwp -> w_bufp -> b_linep -> l_bp -> l_used; X fsize = curbp -> b_file_size; X X if (curwp -> w_markp != NULL) X { X /* build format string */ X sprintf (buf1, MSG_sh_pos, R_POS_FMT(curwp), R_POS_FMT(curwp), X R_POS_FMT(curwp), R_POS_FMT(curwp)); X sprintf (buf, buf1, dotoff, markoff, bsize, fsize); X } X else X { X /* build format string */ X sprintf (buf1, MSG_sh_pos1, R_POS_FMT(curwp), R_POS_FMT(curwp), X R_POS_FMT(curwp)); X sprintf (buf, buf1, dotoff, bsize, fsize); X } X X sprintf (&buf[strlen(buf)], MSG_f_str, curbp -> b_fname); X writ_echo (buf); X X return (TRUE); X} X X X/* X* Twiddle the two characters on either side of X* dot. If dot is at the end of the line twiddle the X* two characters before it. Return with an error if dot X* is at the beginning of line; it seems to be a bit X* pointless to make this work. This fixes up a very X* common typo with a single stroke. Normally bound X* to "C-T". This always works within a line, so X* "WFEDIT" is good enough. X*/ Xbool twiddle () X{ X X register LINE * dotp; X register short doto; X register int cl; X register int cr; X char b_per_u, X f_buf[4], X s_buf[4], X i; X X dotp = curwp -> w_dotp; X doto = curwp -> w_doto; X b_per_u = curwp -> w_fmt_ptr -> r_b_per_u; X /* try to move back one unit */ X if (!move_ptr (curwp, (long) - b_per_u, TRUE, TRUE, TRUE)) X { X curwp -> w_dotp = dotp; /* if fail then restore dot and quit */ X curwp -> w_doto = doto; X ttbeep (); X return (FALSE); X } X /* pick up first unit byte by byte */ X for (i = 0; i < b_per_u; i++) X { X f_buf[i] = DOT_CHAR(curwp); X move_ptr (curwp, 1L, TRUE, FALSE, TRUE); X } X /* move to the end of the second unit */ X if (!move_ptr (curwp, (long) (b_per_u - 1), TRUE, FALSE, TRUE)) X { X curwp -> w_dotp = dotp; /* if fail then restore dot and quit */ X curwp -> w_doto = doto; X ttbeep (); X return (FALSE); X } X /* pick up second unit (reverse order) and deposit second unit */ X for (i = 0; i < b_per_u; i++) X { X s_buf[i] = DOT_CHAR(curwp); X DOT_CHAR(curwp) = f_buf[b_per_u - 1 - i]; X move_ptr (curwp, -1L, TRUE, FALSE, TRUE); X } X /* deposit first unit */ X for (i = 0; i < b_per_u; i++) X { X DOT_CHAR(curwp) = s_buf[i]; X move_ptr (curwp, -1L, TRUE, FALSE, TRUE); X } X curwp -> w_dotp = dotp; X curwp -> w_doto = doto; X lchange (WFHARD); X return (TRUE); X} X X/* X* Quote the next character, and X* insert it into the buffer. All the characters X* are taken literally. X* The character X* is always read, even if it is inserted 0 times, for X* regularity. X*/ Xbool quote (f, n, k) X{ X X register int s; X register int c; X X if (kbdmop != NULL) X c = *kbdmop++; X else X { X c = ttgetc (); X if (kbdmip != NULL) X { X if (kbdmip > &kbdm[NKBDM - 4]) X { X ctrlg (FALSE, 0, KRANDOM); X return (ABORT); X } X X *kbdmip++ = c; X } X X } X X if (n < 0) X return (FALSE); X if (n == 0) X return (TRUE); X X return (linsert (n, c)); X} X X/* X* Toggle the insert mode. Insert mode is used only in ASCII or EBCDIC modes. X*/ Xbool insert_toggle () /* toggle routine for selfinsert */ X{ X register WINDOW * wp; X X if (curbp -> b_flag & BFSLOCK) X return (TRUE); X X if (read_pat_mode) X dont_repeat = TRUE; X X insert_mode = !insert_mode; X for (wp = wheadp; wp; wp = wp -> w_wndp) X wp -> w_flag |= WFMODE; /* force mode line update */ X return (TRUE); X} X X/* X* Ordinary text characters are bound to this function, X* which inserts them into the buffer. Characters marked as control X* characters (using the CTRL flag) may be remapped to their ASCII X* equivalent. This makes TAB (C-I) work right, and also makes the X* world look reasonable if a control character is bound to this X* this routine by hand. Any META or CTLX flags on the character X* are discarded. X* X* Edit the unit under the cursor. X* Check that the character is valid for the current display mode. X*/ X Xbool selfinsert (f, n, k) X{ X X register int c; X register int s; X char edt_buf[4], X i_chr, X b_per_u, X u_offs, X u_roffs, X bit_shf, X bit_mask, X i; X LINE * l_ptr; X short d_offs; X int bytes, X temp_int; X long dot_shf, X l_mask, X l_val; X char text_buf[12]; X static char max_dec_8[] = "255"; X static char max_dec_16[] = "65535"; X static char max_dec_32[] = "4294967295"; X int cur_col; X X bool intel; X X if (n < 0) X { X ttbeep (); X return (FALSE); X } X if (n == 0) X { X ttbeep (); X return (TRUE); X } X c = k & KCHAR; X if ((k & KCTRL) != 0 && c >= '@' && c <= '_')/* ASCII-ify. */ X c -= '@'; X b_per_u = curwp -> w_fmt_ptr -> r_b_per_u; X u_offs = curwp -> w_unit_offset; X u_roffs = curwp -> w_fmt_ptr -> r_chr_per_u - u_offs - 1; X intel = curwp -> w_intel_mode; X X cur_col = ttcol; X X switch (curwp -> w_fmt_ptr -> r_type) X { X case EBCDIC: X c = to_ebcdic (c); /* convert ASCII to EBCDIC */ X case ASCII: X if ((insert_mode) || (DOT_POS(curwp) == BUF_SIZE(curwp))) X { X s = linsert (n, c); X if (read_pat_mode) X forwchar (0, 1, KRANDOM);/* advance the cursor */ X } X else X s = lreplace (n, c); X break; X X case HEX: X if ((c >= '0') && (c <= '9')) X { X i_chr = c - '0';/* convert to binary */ X } X else X if ((c >= 'A') && (c <= 'F')) X { X i_chr = c - 'A' + 10;/* convert to binary */ X } X else X if ((c >= 'a') && (c <= 'f')) X { X i_chr = c - 'a' + 10;/* convert to binary */ X } X else X { X bad_key (k); X return (FALSE); X } X fill_out (); /* expand buffer if necessary */ X X /* position dot to byte to be altered */ X if (intel) X dot_shf = u_roffs >> 1; X else X dot_shf = u_offs >> 1; X X /* save dot position for later */ X l_ptr = curwp -> w_dotp; X d_offs = curwp -> w_doto; X move_ptr (curwp, dot_shf, TRUE, FALSE, TRUE); X X if (u_offs & 1) X { /* lower nibble in byte */ X i_chr &= 0x0f; X DOT_CHAR(curwp) &= 0xf0; X DOT_CHAR(curwp) |= i_chr; X } X else X { /* upper nibble in byte */ X i_chr <<= 4; X i_chr &= 0xf0; X DOT_CHAR(curwp) &= 0x0f; X DOT_CHAR(curwp) |= i_chr; X } X X /* restore dot position */ X curwp -> w_dotp = l_ptr; X curwp -> w_doto = d_offs; X forwchar (0, 1, KRANDOM);/* advance the cursor */ X break; X X case BINARY: X if ((c != '0') && (c != '1')) X { X bad_key (k); X return (FALSE); X } X X /* position dot to byte to be altered */ X if (intel) X dot_shf = u_roffs >> 3; X else X dot_shf = u_offs >> 3; X X fill_out (); /* expand buffer if necessary */ X X /* save dot position for later */ X l_ptr = curwp -> w_dotp; X d_offs = curwp -> w_doto; X move_ptr (curwp, dot_shf, TRUE, FALSE, TRUE); X X bit_shf = u_roffs & 0x07; X X if (c == '0') X { X DOT_CHAR(curwp) &= ~(1 << bit_shf); X } X else X { X DOT_CHAR(curwp) |= 1 << bit_shf; X } X X /* restore dot position */ X curwp -> w_dotp = l_ptr; X curwp -> w_doto = d_offs; X forwchar (0, 1, KRANDOM);/* advance the cursor */ X break; X X case OCTAL: X if (c < '0') X { X bad_key (k); X return (FALSE); X } X else X if ((c > '1') && (u_offs == 0) && X ((curwp -> w_fmt_ptr -> r_size) == WORDS)) X { X bad_key (k); X return (FALSE); X } X else X if ((c > '3') && (u_offs == 0)) X { X bad_key (k); X return (FALSE); X } X else X if (c > '7') X { X bad_key (k); X return (FALSE); X } X X dot_shf = (c - '0') & 7;/* get binary value */ X l_mask = 7; /* create bit mask */ X X dot_shf <<= (u_roffs * 3); X l_mask <<= (u_roffs * 3); X X fill_out (); /* expand buffer if necessary */ X X /* save dot position for later */ X l_ptr = curwp -> w_dotp; X d_offs = curwp -> w_doto; X X /* position dot to the byte to be altered */ X if (intel) X { X for (i = 0; i < b_per_u; i++) X { X DOT_CHAR(curwp) &= ~((D8) l_mask & 0xff); X DOT_CHAR(curwp) |= (D8) dot_shf & 0xff; X l_mask >>= 8; X dot_shf >>= 8; X move_ptr (curwp, 1L, TRUE, FALSE, TRUE); X } X } X else X { X move_ptr (curwp, (long) (b_per_u - 1), TRUE, FALSE, TRUE); X /* move to last byte */ X for (i = 0; i < b_per_u; i++) X { X DOT_CHAR(curwp) &= ~((D8) l_mask & 0xff); X DOT_CHAR(curwp) |= (D8) dot_shf & 0xff; X l_mask >>= 8; X dot_shf >>= 8; X move_ptr (curwp, -1L, TRUE, FALSE, TRUE);/* step back one byte */ X } X } X X /* restore dot position */ X curwp -> w_dotp = l_ptr; X curwp -> w_doto = d_offs; X forwchar (0, 1, KRANDOM);/* advance the cursor */ X break; X X case DECIMAL: X fill_out (); /* expand buffer if necessary */ X X /* save dot position for later */ X l_ptr = curwp -> w_dotp; X d_offs = curwp -> w_doto; X X bytes = fill_buf (curwp, l_ptr, d_offs, edt_buf, b_per_u); X /* if last unit is not full and must be extended */ X for (; bytes < b_per_u; bytes++) X { X edt_buf[3] = edt_buf[2];/* shuffle bytes down */ X edt_buf[2] = edt_buf[1]; X edt_buf[1] = edt_buf[0]; X edt_buf[0] = 0; X } X switch (curwp -> w_fmt_ptr -> r_size) X { X case BYTES: X sprintf (text_buf, MSG_03u, (int) (edt_buf[0] & 0xff)); X if (!dec_chr_ok (text_buf, max_dec_8, c, u_offs)) X { X bad_key (k); X return (TRUE); /* TRUE so that mask will be same len */ X } X sscanf (text_buf, MSG_3u, &i);/* convert back to binary */ X l_val = (long) i & 0xff; X break; X X case WORDS: X l_val = get_int (edt_buf);/* do intel swap */ X sprintf (text_buf, MSG_05u, (int) (l_val & 0xFFFF)); X if (!dec_chr_ok (text_buf, max_dec_16, c, u_offs)) X { X bad_key (k); X return (TRUE); /* TRUE so that mask will be same len */ X } X sscanf (text_buf, MSG_5u, &temp_int); X /* convert back to binary */ X l_val = get_int ((char *) & temp_int);/* do intel swap */ X break; X X case DWORDS: X l_val = get_long (edt_buf);/* do intel swap */ X sprintf (text_buf, MSG_010lu, l_val); X if (!dec_chr_ok (text_buf, max_dec_32, c, u_offs)) X { X bad_key (k); X return (TRUE); /* TRUE so that mask will be same len */ X } X sscanf (text_buf, MSG_lu, &l_val); X /* convert back to binary */ X l_val = get_long ((char *) & l_val);/* do intel swap */ X break; X#if RUNCHK X default: X writ_echo (ERR_rnd_2); X break; X#endif X } X DOT_CHAR(curwp) = (char) l_val & 0xff; X for (i = 1; i < b_per_u; i++) X { X l_val >>= 8; X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);/* step forward one byte */ X DOT_CHAR(curwp) = (char) l_val & 0xff; X } X X /* restore dot position */ X curwp -> w_dotp = l_ptr; X curwp -> w_doto = d_offs; X forwchar (0, 1, KRANDOM);/* advance the cursor */ X break; X X#if RUNCHK X default: X writ_echo (ERR_rnd_3); X break; X#endif X } X /* if cursor has wrapped to the next line then previous line X will not be refreshed with WFEDIT so do a WFHARD */ X if (cur_col > get_curcol(curwp)) X lchange (WFHARD); X else X lchange (WFEDIT); X X return (TRUE); X} X X/* X* Insert one unit of zeros at the current dot position. X*/ Xbool insertunit (f, n, k) X{ X lchange (WFEDIT); X linsert ((R_B_PER_U(curwp) * n), 0); X return (TRUE); X} X X/* X* Increase the size of the buffer if necessary. X* If dot is at the byte after the last full unit X* then add enough bytes to the buffer to create X* a full unit at the end. X*/ X Xbool fill_out () X{ X long buf_size, dot_pos, l_val, last_unit; X int b_per_u; X char stat, shift; X int insert_val; X X buf_size = BUF_SIZE(curwp); X dot_pos = DOT_POS(curwp); X b_per_u = R_B_PER_U(curwp); X shift = curwp -> w_disp_shift; X stat = TRUE; X insert_val = 0; X last_unit = buf_size & ~((long)(b_per_u - 1)); X /* there is an even number of units step back one */ X if (last_unit == buf_size) X last_unit -= b_per_u; X last_unit += shift; X X /* if dot is one byte past the end of the buffer */ X if (dot_pos > last_unit) X { X insert_val = b_per_u; X } X X /* if dot is pointed at the end of the buffer */ X else if (dot_pos == last_unit) X { X insert_val = b_per_u - (buf_size - last_unit); X } X X /* if insert is necessary then do it */ X if (insert_val != 0) X { X lchange (WFHARD); X move_ptr (curwp, buf_size, TRUE, FALSE, FALSE); /* move dot to end */ X stat = linsert (insert_val, 0); X move_ptr (curwp, dot_pos, TRUE, TRUE, FALSE); /* put dot back */ X } X return (stat); X} X X/* X* This checks that an entered character is ok X* for the position given. X*/ X Xchar dec_chr_ok (char_buf, max_str, chr, pos) X Xchar chr, X pos, X *char_buf, X *max_str; X X{ X char i; X X if ((chr < '0') || (chr > '9')) X return (FALSE); X X char_buf[pos] = chr; /* insert typed char */ X X /* check if number is too big */ X for (i = 0; max_str[i] != 0; i++) X { X if (char_buf[i] < max_str[i]) X break; /* if char is smaller then must be ok */ X X if (char_buf[i] > max_str[i]) X return (FALSE); /* val is too large; ERROR */ X } X return (TRUE); X} X X/* X* Set the rest of the variables for the mode change. X*/ Xvoid set_mode_vars () X{ X curwp -> w_disp_shift = 0; /* shift to 0 when changing mode */ X curwp -> w_unit_offset = 0; /* go to end of unit */ X /* if we are in the middle of a search then use the proper format struc */ X if (read_pat_mode) X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt; X X wind_on_dot (curwp); X curwp -> w_flag = WFHARD; X update (); X} X X/* X* Change the display mode to ASCII. X* The default binding is META C-A. X*/ Xbool asciimode () X{ X curwp -> w_fmt_ptr = &ascii_fmt; X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display mode to EBCDIC. X* The default binding is META C-E. X*/ Xbool ebcdicmode () X{ X curwp -> w_fmt_ptr = &ebcdic_fmt; X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display mode to DECIMAL. X* The default binding is META C-D. X*/ Xbool decimalmode () X{ X switch (curwp -> w_fmt_ptr -> r_size) X { X case BYTES: X curwp -> w_fmt_ptr = &decimal_8_fmt; X break; X case WORDS: X curwp -> w_fmt_ptr = &decimal_16_fmt; X break; X X case DWORDS: X curwp -> w_fmt_ptr = &decimal_32_fmt; X break; X#if RUNCHK X default: X writ_echo (ERR_rnd_4); X break; X#endif X } X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display mode to HEXADECIMAL. X* The default binding is META C-H. X*/ Xbool hexmode () X{ X switch (curwp -> w_fmt_ptr -> r_size) X { X case BYTES: X curwp -> w_fmt_ptr = &hex_8_fmt; X break; X case WORDS: X curwp -> w_fmt_ptr = &hex_16_fmt; X break; X case DWORDS: X curwp -> w_fmt_ptr = &hex_32_fmt; X break; X#if RUNCHK X default: X writ_echo (MSG_rnd_5); X break; X#endif X } X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display mode to OCTAL. X* The default binding is META C-O. X*/ Xbool octalmode () X{ X switch (curwp -> w_fmt_ptr -> r_size) X { X case BYTES: X curwp -> w_fmt_ptr = &octal_8_fmt; X break; X X case WORDS: X curwp -> w_fmt_ptr = &octal_16_fmt; X break; X X case DWORDS: X curwp -> w_fmt_ptr = &octal_32_fmt; X break; X#if RUNCHK X default: X writ_echo (ERR_rnd_6); X break; X#endif X } X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display mode to BINARY. X* The default binding is META C-B. X*/ Xbool binarymode () X{ X switch (curwp -> w_fmt_ptr -> r_size) X { X case BYTES: X curwp -> w_fmt_ptr = &binary_8_fmt; X break; X case WORDS: X curwp -> w_fmt_ptr = &binary_16_fmt; X break; X case DWORDS: X curwp -> w_fmt_ptr = &binary_32_fmt; X break; X#if RUNCHK X default: X writ_echo (ERR_rnd_7); X break; X#endif X } X set_mode_vars (); X return (TRUE); X} X X/* X* Change the display shift. X* Circularly rotate through display shift of 0 through 3. X* This value is used to shift the display by the designated number of bytes. X* This is used to cause WORD and DWORD values to be calculated X* from the correct offset. X*/ Xbool dispshift (f, n, k) X{ X char mode, X size; X X if (read_pat_mode) X return (TRUE); /* no shift is allowed in search mode */ X X mode = curwp -> w_fmt_ptr -> r_type; X size = curwp -> w_fmt_ptr -> r_size; X X if (((mode == HEX) || X (mode == DECIMAL) || X (mode == BINARY) || X (mode == OCTAL)) && X (size != BYTES)) X { X if ((size == WORDS) && X (curwp -> w_disp_shift >= 1)) X { /* roll over on words */ X curwp -> w_disp_shift = 0; X } X else X if ((size == DWORDS) && X (curwp -> w_disp_shift >= 3)) X { /* roll over on double words */ X curwp -> w_disp_shift = 0; X } X else X { X curwp -> w_disp_shift++;/* increment shift */ X } X } X else X { X curwp -> w_disp_shift = 0;/* set to no shift */ X } X move_ptr (curwp, 0L, TRUE, TRUE, TRUE); X wind_on_dot (curwp); X curwp -> w_flag = WFHARD; /* force full window refresh */ X return (TRUE); X} X X/* X* Delete forward. This is real X* easy, because the basic delete routine does X* all of the work. Watches for negative arguments, X* and does the right thing. If any argument is X* present, it kills rather than deletes, to prevent X* loss of text if typed with a big argument. X* Normally bound to "C-D". X*/ Xchar forwdel (f, n, k) X{ X char s; X X if (n < 0) X return (backdel (f, -n, KRANDOM)); X X s = FALSE; X if (R_SIZE(curwp) == BYTES) X { X if (f != FALSE) X { X /* Really a kill. */ X if ((lastflag & CFKILL) == 0) X kdelete (); X thisflag |= CFKILL; X } X s = ldelete (n, f); X curwp -> w_unit_offset = 0; X } X return (s); X} X X X/* X* Delete backwards. This is quite easy too, X* because it's all done with other functions. Just X* move the cursor back, and delete forwards. X* Like delete forward, this actually does a kill X* if presented with an argument. X*/ Xchar backdel (f, n, k) X{ X X int u_off; X char s; X X if (n < 0) X return (forwdel (f, -n, KRANDOM)); X X s = FALSE; X if (R_SIZE(curwp) == BYTES) X { X u_off = curwp -> w_unit_offset; X curwp -> w_unit_offset = 0; X if ((s = backchar (f, n * R_CHR_PER_U(curwp), KRANDOM)) == TRUE) X { X s = ldelete (n, f); X if (f != FALSE) X { X /* Really a kill. */ X if ((lastflag & CFKILL) == 0) X kdelete (); X thisflag |= CFKILL; X } X } X curwp -> w_unit_offset = u_off; X } X return (s); X} X X X/* X* Change the size of the display unit to BYTE. X* Adjust byte shift to the allowable range. X* Normally bound to "META-1". X*/ Xbool dispsize1 () X{ X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */ X curwp -> w_unit_offset = 0; /* go to end of unit */ X X switch (R_TYPE(curwp)) X { X case OCTAL: X curwp -> w_fmt_ptr = &octal_8_fmt; X break; X X case DECIMAL: X curwp -> w_fmt_ptr = &decimal_8_fmt; X break; X X case HEX: X curwp -> w_fmt_ptr = &hex_8_fmt; X break; X X case BINARY: X curwp -> w_fmt_ptr = &binary_8_fmt; X break; X X default: X return (TRUE); X break; X } X X /* if we are in the middle of a search then use the proper format struc */ X if (read_pat_mode) X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt; X X move_ptr (curwp, 0L, TRUE, TRUE, TRUE); X wind_on_dot (curwp); X curwp -> w_flag = WFHARD; X update (); X return (TRUE); X} X X/* X* Change the size of the display unit to WORD. X* Adjust byte shift to the allowable range. X* Normally bound to "META-2". X*/ Xbool dispsize2 () X{ X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */ X curwp -> w_unit_offset = 0; /* go to end of unit */ X X switch (R_TYPE(curwp)) X { X case OCTAL: X curwp -> w_fmt_ptr = &octal_16_fmt; X break; X X case DECIMAL: X curwp -> w_fmt_ptr = &decimal_16_fmt; X break; X X case HEX: X curwp -> w_fmt_ptr = &hex_16_fmt; X break; X X case BINARY: X curwp -> w_fmt_ptr = &binary_16_fmt; X break; X X default: X return (TRUE); X break; X } X X /* if we are in the middle of a search then use the proper format struc */ X if (read_pat_mode) X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt; X X move_ptr (curwp, 0L, TRUE, TRUE, TRUE); X wind_on_dot (curwp); X curwp -> w_flag = WFHARD; X update (); X return (TRUE); X} X X/* X* Change the size of the display unit to DOUBLE WORD. X* Adjust byte shift to the allowable range. X* Normally bound to "META-4". X*/ Xbool dispsize4 () X{ X curwp -> w_disp_shift = 0; /* shift to 0 when changing size */ X curwp -> w_unit_offset = 0; /* go to end of unit */ X X switch (R_TYPE(curwp)) X { X case OCTAL: X curwp -> w_fmt_ptr = &octal_32_fmt; X break; X X case DECIMAL: X curwp -> w_fmt_ptr = &decimal_32_fmt; X break; X X case HEX: X curwp -> w_fmt_ptr = &hex_32_fmt; X break; X X case BINARY: X curwp -> w_fmt_ptr = &binary_32_fmt; X break; X X default: X return (TRUE); X break; X } X X /* if we are in the middle of a search then use the proper format struc */ X if (read_pat_mode) X curwp -> w_fmt_ptr = curwp -> w_fmt_ptr -> r_srch_fmt; X X move_ptr (curwp, 0L, TRUE, TRUE, TRUE); X wind_on_dot (curwp); X curwp -> w_flag = WFHARD; X update (); X return (TRUE); X} X X/* X* Display byte swaped. This command causes the bytes X* that are displayed in WORD and DWORD mode to be swaped X* in the way that the INTEL microprocessors do it. X*/ Xbool dispswapbyte (f, n, k) X{ X if ((curwp -> w_fmt_ptr -> r_size) == BYTES) X return (TRUE); X X if (curwp -> w_intel_mode) X curwp -> w_intel_mode = FALSE; X else X curwp -> w_intel_mode = TRUE; X X curwp -> w_flag = WFHARD; X update (); X return (TRUE); X} X X/* X* Yank text back from the kill buffer. This X* is really easy. All of the work is done by the X* standard insert routines. All you do is run the loop, X* and check for errors. X* An attempt has been made to fix the cosmetic bug X* associated with a yank when dot is on the top line of X* the window (nothing moves, because all of the new X* text landed off screen). X*/ Xbool yank (f, n, k) X{ X register int c; X register int i; X register LINE * lp; X X if (n < 0) X return (FALSE); X while (n--) X { X i = 0; X while ((c = kremove (i)) >= 0) X { X if (linsert (1, c) == FALSE) X return (FALSE); X ++i; X } X } X curwp -> w_flag |= WFHARD; X return (TRUE); X} X X/* X* Link windows. pvr X* This function toggles the window linking function. X* When linking is enabled all windows that look at X* the same buffer will be forced to have the same X* dot position. Each window is then moved to be X* positioned on the dot. Thus when a user moves X* arround a buffer all other views into that buffer X* will follow. X*/ X Xbool linkwind () X X{ X char buf[80]; X X if (curwp -> w_bufp -> b_flag & BFLINK) X { X curwp -> w_bufp -> b_flag &= ~(BFLINK & 0xff); X sprintf (buf, MSG_lnk, curwp -> w_bufp -> b_bname, MSG_unlink); X } X else X { X curwp -> w_bufp -> b_flag |= BFLINK; X sprintf (buf, MSG_lnk, curwp -> w_bufp -> b_bname, MSG_link); X } X writ_echo (buf); X return (TRUE); X} X/* X* Print all bad keys to the screen and beep X*/ Xvoid bad_key (key) Xint key; X { X char buf[80], buf1[40]; X X ttbeep (); X sprintf (buf, MSG_bad_key); X if (key & KMETA) X sprintf (&buf[strlen (buf)], MSG_esc); X if (key & KCTLX) X sprintf (&buf[strlen (buf)], MSG_ctl_x); X if (key & KCTRL) X sprintf (&buf[strlen (buf)], MSG_ctl); X sprintf (buf1, MSG_key_code, char_str, R_BYTE_FMT(curwp)); X sprintf (&buf[strlen (buf)], buf1, (key & KCHAR), key); X writ_echo (buf); X } END_OF_FILE if test 30672 -ne `wc -c <'random.c'`; then echo shar: \"'random.c'\" unpacked with wrong size! fi chmod +x 'random.c' # end of 'random.c' fi echo shar: End of archive 9 \(of 11\). cp /dev/null ark9isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 11 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0