home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SCREEN / READSCRN.ZIP / READSCRN.C next >
Encoding:
C/C++ Source or Header  |  1990-09-11  |  4.1 KB  |  132 lines

  1. /* This program reads a string from the screen at a specified location
  2.    and compares it with the string entered at the command line.  If the
  3.    two strings are identical, the value 0 is returned to DOS; otherwise,
  4.    the value 1 is returned.  The value -1 is returned if the command line
  5.    arguements are not correct.
  6.  
  7.    This program is entended to be used in batch files.  The returned value
  8.    can be tested by putting an IF ERRORLEVEL statement after the command.
  9.  
  10.    Syntax:
  11.  
  12.    READSCRN column row string
  13.  
  14.    column     The column at which the string begins on the screen.  The value
  15.               should be between 0 and the number of columns minus one.
  16.  
  17.    row        The number of rows above the command line at which the string
  18.               is located on the screen.  The value should be between 0 and
  19.               the number of rows minus one.
  20.  
  21.    string     The string that is to be compared.  It must be enclosed in double
  22.               quotes if a space is part of the string.  The length of the
  23.               string is only limited by the length of the DOS command line.
  24.  
  25. Examples:
  26.  
  27.    If you want to read the READSCRN command line and assume the DOS prompt is
  28.    C:\>, type the following:
  29.  
  30.        READSCRN 0 0 "C:/>READSCRN"
  31.  
  32.    The command will return 0 to the command processor.
  33.  
  34.    If you want to check the string "This is a test." two rows above the current
  35.    command line and the string begins at the fifth column, type the following:
  36.  
  37.        READSCRN 4 2 "This is a test."
  38.  
  39.    The command will return 0 to the command processor.
  40.  
  41.  
  42.    Author:     Jimmy Ning
  43.    CompuServe: [76066,1467]
  44.  
  45.    This program was compiled in TC 2.01 using the tiny memory model and
  46.    converted to a COM file by using EXE2BIN.                                 */
  47.  
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <dos.h>
  51.  
  52. /* ROM BIOS video interrupt */
  53. #define VIDEO 0x10
  54.  
  55. /* This procedure gets the location of the cursor on the screen. */
  56. void get_cursor(int *row, int *col);
  57.  
  58. /* This procedure returns a character from the screen at location
  59.    (col, row). */
  60. char readxy(int col, int row);
  61.  
  62. /* This procedure moves the cursor to location (col, row). */
  63. /* Does anyone know why the gotoxy() procedure in conio.h does not work
  64.    properly? */
  65. void gotoxy(int col, int row);
  66.  
  67. void main(int argc, char *argv[])
  68. {
  69.  int curr_row, curr_col;         /* Current location of the cursor */
  70.  int i = 0;                      /* A counter */
  71.  int row, col;                   /* Location of the string */
  72.  int len;                        /* The length of the string */
  73.  
  74.  if (argc != 4){
  75.     puts("Three arguements are required!");
  76.     exit(-1);
  77.  }
  78.  
  79.  get_cursor(&curr_col, &curr_row); /* Save the location */
  80.  col = atoi(argv[1]);
  81.  row = atoi(argv[2]);
  82.  len = strlen(argv[3]);
  83.  
  84.  while ( (argv[3][i] == readxy(col+i, curr_row-row-1))
  85.           && (i < len) )
  86.      i++;
  87.  
  88.  gotoxy(curr_col, curr_row);            /* Restore the location of the cursor */
  89.  if (i == len)                          /* Are the two strings identical? */
  90.     exit(0);
  91.  else
  92.      exit(1);
  93. }
  94.  
  95. /* This procedure gets the location of the cursor on the screen. */
  96. void get_cursor(int *col, int *row)
  97. {
  98.  union REGS regs;
  99.  
  100.  regs.h.ah = 0x03;               /* Get cursor position */
  101.  regs.h.bh = 0;                  /* Display page 0 */
  102.  int86(VIDEO, ®s, ®s);     /* BIOS video call */
  103.  
  104.  *row = regs.h.dh;
  105.  *col = regs.h.dl;
  106. }
  107.  
  108. /* This procedure returns a character from the screen at location
  109.    (row, col). */
  110. char readxy(int col, int row)
  111. {
  112.  union REGS regs;
  113.  
  114.  gotoxy(col, row);               /* Goto location (col, row) */
  115.  regs.h.ah = 0x08;               /* Read character */
  116.  regs.h.bh = 0;                  /* Display page 0 */
  117.  int86(VIDEO, ®s, ®s);     /* BIOS video call */
  118.  
  119.  return(regs.h.al);
  120. }
  121.  
  122. /* This procedure moves the cursor to location (col, row). */
  123. void gotoxy(int col, int row)
  124. {
  125.  union REGS regs;
  126.  
  127.  regs.h.ah = 2;                  /* Set cursor position */
  128.  regs.h.bh = 0;                  /* Display page 0 */
  129.  regs.h.dh = row;
  130.  regs.h.dl = col;
  131.  int86(VIDEO, ®s, ®s);     /* BIOS video call */
  132. }