From:	AITGW::"FILESERV@WKUVX1.BITNET" 16-MAR-1992 10:29:49.67
To:	ARISIA::EVERHART
CC:	
Subj:	LOOK.02_OF_04

Received: by AITGW.DECnet (utk-mail11 v1.5) ; Mon, 16 Mar 92 10:29:02 EST
Received: from ukcc.uky.edu by aitgw.ge.com (5.65/GE Gateway 1.5)
	id AA02474; Mon, 16 Mar 92 10:28:53 -0500
Message-Id: <9203161528.AA02474@aitgw.ge.com>
Received: from ukcc.uky.edu by UKCC.uky.edu (IBM VM SMTP V2R2)
   with BSMTP id 6883; Mon, 16 Mar 92 10:25:27 EST
Received: from UKCC by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6663; Mon, 16
 Mar 92 10:25:26 EST
Received: from WKUVX1.BITNET by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6659;
 Mon, 16 Mar 92 10:25:24 EST
Received: by WKUVX1.BITNET (MX V3.0A) id 16029; Mon, 16 Mar 1992 08:32:36 CST
Date: Mon, 16 Mar 1992 08:32:36 CST
From: FILESERV-Mgr@WKUVX1.BITNET
Reply-To: FILESERV@WKUVX1.BITNET
Subject: LOOK.02_OF_04
To: ARISIA::EVERHART
 
-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
X`09if (vf_inf.bintxt == 0) vf_inf.bintxt = SS$_NORMAL;
X
X`09if (v_rec_len == 0)
X`09`7B
X`09    /* Retrieve record length */
X
X`09    if (sh_read(&ctrl_byte, 1) != 1) return -1;
X`09    v_rec_len = (int)((unsigned char)ctrl_byte);
X`09    if (sh_read(&ctrl_byte, 1) != 1)
X`09    `7B
X`09`09v_rec_len = 0;
X`09`09return -1;
X`09    `7D
X`09    v_rec_len += ((int)((unsigned char)ctrl_byte) << 8);
X`09    if (v_rec_len == 0)
X`09    `7B
X`09`09*str = '\0';
X`09`09return 0;
X`09    `7D
X`09    if (v_rec_len == 0xFFFF)
X`09    `7B
X`09`09v_rec_len = 0;
X`09`09return sh_fgets(str, maxchar, mode);
X`09    `7D
X
X`09/* Retrieve record */
X
X`09    align_byte = v_rec_len % 2;
X
X`09    switch(fab_of_file.fab$b_rat)
X`09    `7B
X`09    case FAB$M_PRN:`09    /* Printer file */
X`09`09if (sh_read(&ctrl_byte, 1) != 1)
X`09`09`7B
X`09`09    v_rec_len = 0;
X`09`09    return -1;
X`09`09`7D
X`09`09v_rec_len--;
X`09`09if (sh_read(&ctrl_byte, 1) != 1)
X`09`09`7B
X`09`09    v_rec_len = 0;
X`09`09    return -1;
X`09`09`7D
X`09`09v_rec_len--;
X`09    case FAB$M_FTN:`09    /* Fortran file */
X`09    case FAB$M_CR:`09    /* Text file */
X`09    default:`09`09    /* Abstract variable-length file */
X`09`09break;
X`09    `7D
X`09`7D
X`09
X`09if (maxchar >= v_rec_len)
X`09`7B
X`09    if (sh_read(str, v_rec_len) != v_rec_len)
X`09    `7B
X`09        v_rec_len = 0;
X`09        return -1;
X`09    `7D
X`09    if (align_byte == 1)
X`09    `7B
X`09        if (sh_read(&ctrl_byte, 1) != 1)
X`09`09`7B
X`09`09    v_rec_len = 0;
X`09`09    return -1;
X`09`09`7D
X`09    `7D
X`09    if (mode == SS$_NORMAL)
X`09    `7B
X`09        for (i = 0; i < v_rec_len; i++)
X`09`09    if ((isprint(str`5Bi`5D) == 0) && (str`5Bi`5D != '\t'))
X`09`09        str`5Bi`5D = UNPRINTABLE;
X`09`09str`5Bi`5D = '\0';
X`09    `7D
X`09    v_rec_len = 0;
X`09    return 0;
X`09`7D
X`09else
X`09`7B
X`09    if (sh_read(str, maxchar) != maxchar)
X`09    `7B
X`09`09v_rec_len = 0;
X`09`09return -1;
X`09    `7D
X`09    v_rec_len -= maxchar;
X`09    if (mode == SS$_NORMAL)
X`09    `7B
X`09        for (i = 0; i < maxchar; i++)
X`09`09    if ((isprint(str`5Bi`5D) == 0) && (str`5Bi`5D != '\t'))
X`09`09        str`5Bi`5D = UNPRINTABLE;
X`09`09str`5Bi`5D = '\0';
X`09    `7D
X`09    return 1;
X`09`7D
X    case FAB$C_STMLF:`09`09`09/* Files created by C language */
X        switch(fab_of_file.fab$b_rat)
X        `7B
X`09case FAB$M_PRN:
X`09    if (sh_read(&ctrl_byte, 1) != 1) return -1;
X`09    if (sh_read(&ctrl_byte, 1) != 1) return -1;
X`09case FAB$M_FTN:
X`09case FAB$M_CR:
X`09    if (vf_inf.bintxt == 0) vf_inf.bintxt = SS$_NORMAL;
X`09    for (v_rec_len = 0; v_rec_len < maxchar; v_rec_len++)
X`09    `7B
X`09`09if (sh_tell() >= sh_eof()) break;
X`09`09if (sh_read(&ctrl_byte, 1) != 1) return -1;
X`09`09if (ctrl_byte == '\n')
X`09`09`7B
X`09`09    if (mode == SS$_NORMAL) str`5Bv_rec_len`5D = '\0';
X`09`09    return 0;
X`09`09`7D
X`09`09if (mode == SS$_NORMAL)
X`09`09    str`5Bv_rec_len`5D = ((isprint(ctrl_byte) == 0) &&
X`09`09`09(ctrl_byte != '\t')) ? UNPRINTABLE : ctrl_byte;
X`09    `7D
X`09    if (mode == SS$_NORMAL) str`5Bv_rec_len`5D = '\0';
X`09    return 0;
X`09default:
X`09    if (vf_inf.bintxt == 0)
X`09    `7B
X`09`09vf_inf.bintxt = $_ABNORMAL;
X`09`09return bin_fgets(str, BINRECLEN, mode);
X`09    `7D
X`09    return txt_fgets(str, BINTXTLEN, mode);
X        `7D
X    default:`09`09`09    /* Any other files are binary */
X`09if (vf_inf.bintxt == 0)
X`09`7B
X`09    vf_inf.bintxt = $_ABNORMAL;
X`09    return bin_fgets(str, BINRECLEN, mode);
X`09`7D
X`09return txt_fgets(str, BINTXTLEN, mode);
X    `7D
X`7D
X
X`09/* Close a file */
X
Xint
Xsh_close(void)
X`7B
X    asy_stop = 0;
X    fab_of_file.fab$l_sts = 0;
X    sys$close(&fab_of_file, ast_stop, ast_stop);
X    while(asy_stop == 0);
X    return (fab_of_file.fab$l_sts == RMS$_NORMAL) ? 0 : -1;
X`7D
X
X
X    /* Looker routines */
X
X`09/* Fill in a line descriptor */
X
Xstruct dsc$descriptor_s *
Xoutline(char *str)
X`7B
X    outstr.dsc$w_length`09    = strlen(str);
X    outstr.dsc$a_pointer    = str;
X    return &outstr;
X`7D
X
X`09/* Initialize a screen */
X
Xint
Xinit_screen()
X`7B
X    int j = 0;
X
X    vdisp.vport.firstcol = vdisp.vport.firstrow = vdisp.vport.curcol =
X`09vdisp.cursor.row = vdisp.cursor.col = 1;
X
X    CHECKRESULT(smg$create_virtual_keyboard(&k_id));     `20
X
X    CHECKRESULT(smg$create_pasteboard(&p_id, outline(DEFAULT_OUTPUT),
X`09&k_bar.firstrow, &screensize));
X    if ((screensize < 10) `7C`7C (k_bar.firstrow < 5)) return $_ABNORMAL;
X    if (screensize > SCREENMAX) screensize = SCREENMAX;
X    vdisp.vport.len = screensize - BORDERFIELD;
X    vdisp.wid = k_bar.firstrow - 4;
X
X    CHECKRESULT(smg$create_virtual_display(&k_bar.wid,
X`09&k_bar.len, &k_bar.id));
X    CHECKRESULT(smg$put_line(&k_bar.id, outline(HELPLINE), &j, &k_bar.rend))
V;
X
X    CHECKRESULT(smg$create_virtual_display(&vdisp.wid,
X`09&vdisp.len, &vdisp.id));
X    CHECKRESULT(smg$create_viewport(&vdisp.id,
X`09&vdisp.vport.firstrow, &vdisp.vport.firstcol,
X`09&vdisp.wid, &vdisp.vport.len));
X    CHECKRESULT(smg$home_cursor(&vdisp.id));
X
X    return SS$_NORMAL;
X`7D
X
X`09/* Free a screen resources */
X
Xint
Xfree_screen()
X`7B
X    CHECKRESULT(smg$delete_virtual_keyboard(&k_id));
X    CHECKRESULT(smg$delete_viewport(&vdisp.id));
X    CHECKRESULT(smg$delete_virtual_display(&vdisp.id));
X    CHECKRESULT(smg$delete_virtual_display(&k_bar.id));
X    CHECKRESULT(smg$delete_pasteboard(&p_id));
X    free(vf_inf.home);
X    if (sh_close() == -1) return NO_CLOSE;
X    return SS$_NORMAL;
X`7D
X
X`09/* Fill in a screen page */
X
Xint
Xnew_page()
X`7B
X    int k = 0;
X
X    FBEG(vf_inf.current);
X    smg$begin_display_update(&vdisp.id);
X    CHECKRESULT(smg$erase_display(&vdisp.id));
X    CHECKRESULT(smg$home_cursor(&vdisp.id));
X    for (k = 0; (k < vdisp.wid) && (sh_fgets(line, MAXLINE, SS$_NORMAL) != -
V1);
X`09k++)
X        CHECKRESULT(smg$put_line(&vdisp.id, outline(line)));
X    smg$end_display_update(&vdisp.id);
X    return SS$_NORMAL;
X`7D
X
X`09/* Put a work indicator */
X
Xint
Xworking()
X`7B
X    unsigned short stop_key = 0;
X
X    if (wn == 0) CHECKRESULT(smg$set_cursor_mode(&p_id, &c_off));
X    if ((wn >= WORKING_STEP) `7C`7C (wn == 0))
X    `7B
X`09wn = 0;
X`09sprintf(vf_inf.inv.sline, WORKING_FORMAT,
X`09    (sh_eof() != 0) ? ((sh_tell() * 100)/sh_eof()) : 100);
X`09CHECKRESULT(smg$label_border(&vdisp.id, outline(vf_inf.inv.sline),
X`09    &vf_inf.inv.pos, &vf_inf.inv.beg, &vf_inf.inv.rend));
X    `7D
X    else if ((wn % READKEY_STEP == 0) &&
X`09(smg$read_keystroke(&k_id, &stop_key, NULL, &timeout) == SS$_NORMAL) &&
X`09((stop_key == EXIT) `7C`7C (stop_key == BREAK) `7C`7C
X`09    (stop_key == 'X') `7C`7C (stop_key == 'x')))
X    `7B
X`09rpt = 0;
X`09CHECKRESULT(smg$set_cursor_mode(&p_id, &c_on));
X`09return 0;
X    `7D
X    wn++;
X    return SS$_NORMAL;
X`7D
X
X
X`09/* Headline a screen page & set screen cursor */
X
Xint
Xheadline()
X`7B
X    int n = vf_inf.current + vdisp.cursor.row;
X
X    CHECKRESULT(smg$set_cursor_abs(&vdisp.id,
X`09&vdisp.cursor.row, &vdisp.cursor.col));
X    sprintf(vf_inf.head.sline, HEADLINE_FORMAT,
X`09sh_onlyname(), n, vdisp.cursor.col,
X`09(sh_eof() == 0) ? 100 :
X`09(n >= vf_inf.all-1) ? 100 : ((vf_inf.home`5Bn-1`5D * 100)/sh_eof()));
X    CHECKRESULT(smg$label_border(&vdisp.id, outline(vf_inf.head.sline),
X`09&vf_inf.head.pos, &vf_inf.head.beg, &vf_inf.head.rend));
X    return SS$_NORMAL;
X`7D
X
X`09/* Accept a line to buffer. Edition allowed */
X
Xint
Xget_line(int bufnum)
X`7B
X    char *invite`5B`5D =`20
X    `7B
X`09INVITE_FIND, INVITE_LINE
X    `7D;
X    unsigned short sch = 0;
X    int p = 0, q = 0, r = 0;
X    int p_rows = vdisp.wid + 2;
X    int p_cols = vf_inf.inv.pos + strlen(invite`5Bbufnum`5D);
X
X
X    if (linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen != 0)
X    `7B
X`09if (fbc`5Bbufnum`5D == BUFDEPTH)
X`09`7B
X`09    for (q = 1; q < BUFDEPTH; q++)
X`09    `7B
X`09`09strcpy(linebuf`5Bbufnum`5D`5Bq`5D.fline, linebuf`5Bbufnum`5D`5Bq + 1`5
VD.fline);
X`09`09linebuf`5Bbufnum`5D`5Bq`5D.flen = linebuf`5Bbufnum`5D`5Bq + 1`5D.flen;
X`09    `7D
X`09    memset(linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline, '\0', (size_t)
VSCREENMAX);
X`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen = 0;
X`09`7D
X`09else fbc`5Bbufnum`5D++;
X    `7D
X    r = fbc`5Bbufnum`5D;
X    CHECKRESULT(smg$label_border(&vdisp.id, outline(invite`5Bbufnum`5D),
X`09&vf_inf.inv.pos, &vf_inf.inv.beg, &vf_inf.inv.rend));
X    CHECKRESULT(smg$set_physical_cursor(&p_id, &p_rows, &p_cols));
X    while ((sch != ENTER) && (sch != eNTER) && (p_cols < vdisp.vport.len))
X    if (smg$read_keystroke(&k_id, &sch) == SS$_NORMAL)
X    `7B
X`09if ((sch < (unsigned short)256) && (isprint(sch) != 0))
X`09`7B
X`09    p_cols++;
X`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen++;
X`09    for (q = linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen; q > p; q--)
X`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq`5D =
X`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq-1`5D;
X`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bp`5D = (char)sch;
X`09    p++;
X`09`7D
X`09else
X`09`7B
X`09    switch(sch)
X`09    `7B
X`09    case RIGHT:
X`09`09if (p < linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen)
X`09`09`7B
X`09`09    p_cols++;
X`09`09    p++;
X`09`09`7D
X`09`09break;
X`09    case LEFT:
X`09`09if (p > 0)
X`09`09`7B
X`09`09    p_cols--;
X`09`09    p--;
X`09`09`7D
X`09`09break;
X`09    case SMG$K_TRM_CTRLH:
X`09`09p_cols = vf_inf.inv.pos + strlen(invite`5Bbufnum`5D);
X`09`09p = 0;
X`09`09break;
X`09    case SMG$K_TRM_CTRLE:
X`09`09p_cols = vf_inf.inv.pos + strlen(vf_inf.inv.sline);
X`09`09p = linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen;
X`09`09break;
X`09    case UP:
X`09`09if (r >= 0)
X`09`09`7B
X`09`09    if (r > 0) r--;
X`09`09    strcpy(linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline,
X`09`09`09linebuf`5Bbufnum`5D`5Br`5D.fline);
X`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen = linebuf`5Bbufnum`5
VD`5Br`5D.flen;
X`09`09    p_cols -= p;
X`09`09    p = 0;
X`09`09`7D
X`09`09break;
X`09    case DOWN:
X`09`09if (r < fbc`5Bbufnum`5D)
X`09`09`7B
X`09`09    r++;
X`09`09    if (r == fbc`5Bbufnum`5D) r = 0;
X`09`09    strcpy(linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline,
X`09`09`09linebuf`5Bbufnum`5D`5Br`5D.fline);
X`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen = linebuf`5Bbufnum`5
VD`5Br`5D.flen;
X`09`09    p_cols -= p;
X`09`09    p = 0;
X`09`09    if (r == 0) r = fbc`5Bbufnum`5D;
X`09`09`7D
X`09`09break;
X`09    case (unsigned short)DEL:
X`09`09if (p > 0)
X`09`09`7B
X`09`09    for (q = p; q < linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen; q++
V)
X`09`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq-1`5D =
X`09`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq`5D;
X`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline
X`09`09`09`5B--linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen`5D =`09'\0';
X`09`09    p_cols--;
X`09`09    p--;
X`09`09`7D
X`09`09break;
X`09    case SMG$K_TRM_F13:
X`09`09if (p == 0) break;
X`09`09sch = (unsigned short)linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5
VBp-1`5D;
X`09`09for (q = p; q < linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen; q++)
X`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq-1`5D =
X`09`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq`5D;
X`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline
X`09`09    `5B--linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen`5D = '\0';
X`09`09p_cols--;
X`09`09p--;
X`09`09if (isalpha((int)sch) != 0)
X`09`09    while((p > 0) &&
X`09`09`09(isalpha((int)linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bp-1`
V5D) != 0))
X`09`09    `7B
X`09`09`09for (q = p; q < linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen; q++)
X`09`09`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq-1`5D =
X`09`09`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline`5Bq`5D;
X`09`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline
X`09`09`09    `5B--linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen`5D = '\0';
X`09`09`09p_cols--;
X`09`09`09p--;
X`09`09    `7D
X`09`09break;
X`09    case EXIT:
X`09    case BREAK:
X`09`09memset(linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline, '\0',
X`09`09    (size_t)SCREENMAX);
X`09`09linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.flen = 0;
X`09`09return SS$_NORMAL;
X`09    `7D
X`09`7D   `20
X`09sprintf(vf_inf.inv.sline, "%s%s", invite`5Bbufnum`5D,
X`09    linebuf`5Bbufnum`5D`5Bfbc`5Bbufnum`5D`5D.fline);
X`09CHECKRESULT(smg$label_border(&vdisp.id, outline(vf_inf.inv.sline),`20
X`09    &vf_inf.inv.pos, &vf_inf.inv.beg, &vf_inf.inv.rend));
X`09CHECKRESULT(smg$set_physical_cursor(&p_id, &p_rows, &p_cols));
X    `7D
X    return SS$_NORMAL;
X`7D
X
X`09/* Find a template in line */
X
Xint
Xfind_in_line()
X`7B
X    int s = 0, k = 0, lnlin = 0;
X
X    no_line`5BMAXLINE`5D = '\0';
X    for (lnlin = strlen(no_line) - linebuf`5BTOFIND`5D`5Bfbc`5BTOFIND`5D`5D.
Vflen;
X`09s <= lnlin; s++)
X    `7B
X`09for (k = 0;
X`09    (tolower(no_line`5Bs + k`5D) ==
X`09`09tolower(linebuf`5BTOFIND`5D`5Bfbc`5BTOFIND`5D`5D.fline`5Bk`5D)) &&`20
X`09    (k < linebuf`5BTOFIND`5D`5Bfbc`5BTOFIND`5D`5D.flen); k++);
X`09if (k < linebuf`5BTOFIND`5D`5Bfbc`5BTOFIND`5D`5D.flen) s += k;
X`09else return s;
X    `7D
X    return $_ABNORMAL;
X`7D
X
X`09/* Find once again */
X
Xint
Xnextfind()
X`7B
X    int findbeg = 0, found = 0;
X    unsigned int cur_find = 0;
X    unsigned short any_key = 0;
X
X    if (rpt == 0)
X    `7B
X`09if ((vf_inf.end == 0) && (vdisp.cursor.row >= vf_inf.all))
X`09`7B
X`09    BEEP;
X`09    return SS$_NORMAL;
X`09`7D
X`09vdisp.cursor.col++;
X`09if (vdisp.cursor.col < MAXLINE)
X`09`7B
X`09    memset(no_line, 'A', (size_t)MAXLINE);
X`09    no_line`5BMAXLINE`5D = '\0';
X`09    CHECKRESULT(smg$set_cursor_abs(&vdisp.id,`20
X`09`09&vdisp.cursor.row, &vdisp.cursor.col));
X`09    CHECKRESULT(smg$read_from_display(&vdisp.id, outline(no_line)));
X`09    if ((found = find_in_line()) != $_ABNORMAL)
X`09    `7B
X`09`09CHECKRESULT(smg$begin_display_update(&vdisp.id));
X`09`09any_key = (unsigned short)no_line`5Bfound`5D;
X`09`09no_line`5Bfound`5D = '\0';
X`09`09CHECKRESULT(new_page());
X`09`09CHECKRESULT(smg$put_chars(&vdisp.id, outline(no_line),
X`09`09    &vdisp.cursor.row, &vdisp.cursor.col));
+-+-+-+-+-+-+-+-  END  OF PART 2 +-+-+-+-+-+-+-+-
