home *** CD-ROM | disk | FTP | other *** search
- /*
- testtty.c
-
- Fun with tty cmap windows
-
- jmd 8/06/89
-
- This program demonstrates the use of a character map (cmap) window.
- The function cmap_PlotTTY is called to output text to the window in
- TTY fashion. See cmap_PlotTTY in the OWL file CMWINTTY.C for details.
-
- Also demostrated here is attaching a border to the window; setting the
- border title and prompt; enabling mouse features in the border; and
- positioning the window.
-
- You may call this program with an ASCII file as an argument and see
- the text roll thru the window:
-
- testtty mytext.txt
-
- Or, you may invoke it with no argument and enter text from the
- keyboard. Note that there is no cursor.
-
- */
-
- /*
- if you had included cscape.h you wouldn't have to include oak.h,
- odisp.h or bordobj.h.
- */
-
- #include <stdio.h>
- #include <ctype.h> /* for isprint() */
-
- #include <oak.h>
- #include <odisp.h>
-
- #include <cmwinobj.h> /* for cmwin stuff */
- #include <bordobj.h> /* for border stuff */
-
- #include <scancode.h> /* for referring to keyboard */
-
- #define FEATURE (BD_MOVE | BD_RESIZE | BD_OUTLINE)
- #define BORDER bd_prompt
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- win_type win;
- ocbox cbox;
- FILE *fp = NULL;
- char buffer[501];
- SIZE_T len;
-
- boolean done;
- int scancode;
-
- /* open file specified on command line for reading */
-
- if (argc > 1) {
- fp = fopen(argv[1], "r");
- }
-
- /* use the current video mode */
- disp_Init(def_ModeCurrent, NULL);
-
- /* initialize the mouse */
- hard_InitMouse();
- cmwin_MouseInit();
-
- /* set up for a window with half as many row & cols as display */
- cbox.toprow = 1;
- cbox.leftcol = 1;
- cbox.botrow = (int) (disp_GetHeight() / 2);
- cbox.rightcol = (int) (disp_GetWidth() / 2);
-
- /* create the window and attach the border */
-
- /* Create a cmap window */
- win = win_Open(cmwin_Class, &cbox);
- win_SetPosition(win, (int)(disp_GetHeight() / 4), (int)(disp_GetWidth() / 4));
-
- /* attach a border to the window */
- win_SetBorder(win, BORDER);
- bord_SetFeature(win, FEATURE);
- bord_SendMsg(win, BDM_SETTITLE, "Character map (cmap) TTY window", NULL);
-
- /* employ the window and paint it to the display */
- win_Employ(win);
-
- if (fp == NULL) {
- done = FALSE; /* read keys if no input file given */
- bord_SendMsg(win, BDM_PROMPT, "Ready for keybd input! ESC=quit", NULL);
- while(!done) {
- switch (scancode = kb_Read()) {
- case ESC:
- done = TRUE; /* ESC to quit */
- buffer[0] = '\0';
- break;
-
- case ENTER: /* CR and LF */
- buffer[0] = '\n';
- buffer[1] = '\0';
- break;
-
- case BACKSPACE: /* back up one col in row */
- buffer[0] = '\b';
- buffer[1] = '\0';
- break;
-
- case UP: /* reverse linefeed */
- buffer[0] = '\v';
- buffer[1] = '\0';
- break;
-
- case RIGHT: /* move left one col in row */
- buffer[0] = ' ';
- buffer[1] = '\0';
- break;
-
- case TAB: /* tab */
- buffer[0] = '\t';
- buffer[1] = '\0';
- break;
-
- case PGDN: /* form feed (the height of win) */
- buffer[0] = '\f';
- buffer[1] = '\0';
- break;
- /* print whats printable */
- default:
- buffer[0] = (char) (isprint(ascii(scancode))) ? ascii(scancode) : '\0';
- buffer[1] = '\0';
- break;
- }
- cmwin_PlotTTY(win, buffer);
- }
- }
-
- else { /* if we have an input file */
-
- bord_SendMsg(win, BDM_PROMPT, "Press a key to begin!", NULL);
- kb_Read(); /* wait for a starting keypress */
- bord_SendMsg(win, BDM_PROMPT, "ESC=quit", NULL);
-
- do { /* then read file 500 at a shot */
- len = fread(buffer, 1, 500, fp);
- buffer[len] = '\0';
- cmwin_PlotTTY(win, buffer); /* and show */
-
- } while (len == 500); /* till done */
-
- kb_Read();
- }
-
- /* close the OWL and the input file, if present */
-
- disp_Close();
-
- if (fp != NULL) {
- fclose(fp);
- }
- }
-
-
-