home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_08 / v6n8071a.txt < prev    next >
Text File  |  1989-09-28  |  5KB  |  132 lines

  1.     1: /*
  2.     2:  * Listing 4:
  3.     3:  * 
  4.     4:  * sc_admin.c - a server task to run resident on a PC,
  5.     5:  * reading  the console and returning the data to a client
  6.     6:  * task such as  the CVIEW program in listing 3.
  7.     7:  */
  8.     8: 
  9.     9: #include <stdio.h>
  10.    10: #include <dev.h>
  11.    11: #include <task_msgs.h>
  12.    12: #include "sc_admin.h"  /* #defines for this application. */
  13.    13: 
  14.    14: extern char Cmd_flags;  /* Defined in <magic.h> */
  15.    15: 
  16.    16: my_seg()
  17.    17: {
  18.    18:   asm("  mov ax,ds");
  19.    19: }
  20.    20: 
  21.    21: main(argc,argv)
  22.    22: int argc;
  23.    23: char *argv[];
  24.    24: {
  25.    25:   register DISP_MSG *sbuffer;
  26.    26:   register unsigned msg_size;
  27.    27:   register int i;
  28.    28:   int bytes, j;
  29.    29:   unsigned rows, cols;
  30.    30:   unsigned row_size;
  31.    31:   unsigned max_size;
  32.    32:   int tid;
  33.    33: 
  34.    34:   /* Check for concurrent invocation. */
  35.    35:   if (!(Cmd_flags & RUN_CONCURRENT))
  36.    36:     error("This program cannot run by itself.\n");
  37.    37: 
  38.    38:   /* Get size of current display window */
  39.    39:   bytes = video_save_image(-1, 0, 0, 0, 0, 0);
  40.    40:   i = video_get_size(-1);
  41.    41:   rows = (i >> 8) & 0xff;
  42.    42:   cols = i & 0xff;
  43.    43:   row_size = cols * bytes;
  44.    44: 
  45.    45:   /* Allocate enough space for message plus screen buffer */
  46.    46:   max_size = sizeof(DISP_MSG) + ((rows + 1)* row_size);
  47.    47:   sbuffer = (DISP_MSG *)calloc(1, max_size);
  48.    48: 
  49.    49:   if (sbuffer == (DISP_MSG *)NULL)
  50.    50:     error("Not enough memory to run.\n");
  51.    51: 
  52.    52:   /* Loop forever */
  53.    53:   while (TRUE) {
  54.    54: 
  55.    55:     /*
  56.    56:      * Receive messages from any client task.
  57.    57:      * This task will block, consuming no CPU time
  58.    58:      * if no client task is requesting data.
  59.    59:      */
  60.    60:     tid = receive(0, sbuffer, max_size);
  61.    61: 
  62.    62:     /* Check for exception condition or failed receive */
  63.    63:     /* If OK, process and reply to tid */
  64.    64:     if (tid != -1 && tid != 0) {
  65.    65: 
  66.    66:       switch (sbuffer->dtype) {
  67.    67: 
  68.    68:         case GET_DSP_INFO :
  69.    69:           sbuffer->dtype = OK;
  70.    70:           sbuffer->drow = rows;
  71.    71:           sbuffer->dcol = cols;
  72.    72:           sbuffer->dbytes = bytes;
  73.    73:           msg_size = sizeof(DISP_MSG);
  74.    74:           break;
  75.    75: 
  76.    76:         case GET_NXT_CHGS :
  77.    77:           msg_size = sizeof(DISP_MSG) + row_size;
  78.    78:           sbuffer->dbytes = bytes;
  79.    79:           sbuffer->dtype = OK;
  80.    80:           i = sbuffer->drow;
  81.    81:           for (sbuffer->drow = -1; i < rows; i++) {
  82.    82:             video_save_image( -1, i, 0,
  83.    83:                               sbuffer->dbuffer, cols,
  84.    84:                               my_seg());
  85.    85:             if (memcmp( sbuffer->dbuffer,
  86.    86:                         sbuffer->dbuffer +
  87.    87:                         ((i + 1) * row_size),
  88.    88:                         row_size))
  89.    89:             {
  90.    90:               for (j = sbuffer->dcol; j < cols; j++) {
  91.    91:                 if (memcmp( sbuffer->dbuffer + (j * bytes),
  92.    92:                             sbuffer->dbuffer +
  93.    93:                             ((i + 1) * row_size)
  94.    94:                             + (j * bytes), bytes))
  95.    95:                   break;
  96.    96:               }
  97.    97:               memcpy( sbuffer->dbuffer +
  98.    98:                       ((i + 1) * row_size),
  99.    99:                       sbuffer->dbuffer, row_size);
  100.   100:               sbuffer->drow = i;
  101.   101:               sbuffer->dcol = j;
  102.   102:               break;
  103.   103:             }
  104.   104:           }
  105.   105:           break;
  106.   106: 
  107.   107:         case GET_ALL_DATA :
  108.   108:           for (i = 0; i < rows; i++)
  109.   109:             video_save_image( -1, i, 0,
  110.   110:                               sbuffer->dbuffer +
  111.   111:                               ((i + 1) * row_size),
  112.   112:                               cols, my_seg());
  113.   113:           sbuffer->drow = rows;
  114.   114:           sbuffer->dcol = cols;
  115.   115:           sbuffer->dbytes = bytes;
  116.   116:           sbuffer->dtype = OK;
  117.   117:           msg_size = max_size;
  118.   118:           break;
  119.   119: 
  120.   120:         default :
  121.   121:           sbuffer->dtype = NOT_OK;
  122.   122:           msg_size = sizeof(DISP_MSG);
  123.   123:           break;
  124.   124:       }
  125.   125: 
  126.   126:       /* Get video state (cursor position) of console */
  127.   127:       video_get_state(-1, &sbuffer->dstate);
  128.   128:       reply(tid, sbuffer, msg_size);
  129.   129:     }
  130.   130:   }
  131.   131: }
  132.