home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 436_01 / addattr.h < prev    next >
Encoding:
Text File  |  1994-10-07  |  2.9 KB  |  71 lines

  1. /*************************************************************************
  2.     ADDATTR.H
  3.  
  4.     C-callable routine that adds video attributes to a text buffer,
  5.     to prepare the buffer to be moved directly into video memory.
  6.     May be used with any memory model.
  7.  
  8.     AddAttr() works by transferring characters from SrcBuf to
  9.     DestBuf, along with an attribute byte from AttrList.  Each
  10.     time it encounters an embedded Flag character in SrcBuf,
  11.     AddAttr() gets the next attribute byte from AttrList.
  12.     For example:
  13.  
  14.     static char *NewMenu;
  15.     static char Menu[] =
  16.         {
  17.         "Menu of Choices"
  18.         "~F~irst Choice "                        Flag is '~' (ASCII 126)
  19.         "~S~econd Choice"
  20.         "~T~hird Choice "
  21.         };
  22.     static char MenuAttr[] = { 15, 7, 15, 7, 15, 7 };
  23.     NewMenu = (char *)malloc( sizeof(Menu) * 2 );
  24.     AddAttr( NewMenu, Menu, MenuAttr, sizeof(MenuAttr), 7, '~' );
  25.  
  26.     AddAttr() moves each character in the first line of Menu to
  27.     NewMenu, along with an attribute byte of 7, since that is the
  28.     default attribute passed to it in the call.  Next, AddAttr()
  29.     encounters a '~', so it picks up the first attribute byte (15)
  30.     from MenuAttr, and stores it in NewMenu along with 'F'.  When
  31.     AddAttr() encounters the second '~' character, it picks up the
  32.     second attribute byte (7) and stores it, along with each of the
  33.     remaining characters in the second line, in NewMenu.  AddAttr()
  34.     continues in this manner for the rest of Menu.  When it has
  35.     finished with Menu, NewMenu will be ready to move into video
  36.     memory with a routine such as Borland's puttext().
  37.  
  38.     If MenuAttr contains fewer attribute bytes than the number of
  39.     Flag characters in Menu, AddAttr() uses the last byte from
  40.     MenuAttr for the remainder of Menu.  If MenuAttr is null, or
  41.     if no flag characters occur in Menu, AddAttr() uses the
  42.     default attribute passed in Attr.
  43.  
  44.     Since AddAttr() requires three far pointers to char and
  45.     only two can be set up at any one time using DS and ES,
  46.     AttrList and SrcBuf MUST be in the same data segment.
  47.     That should not be a problem, since the string in SrcBuf
  48.     and the attribute list that applies to it will most likely
  49.     be defined in the same module.
  50.  
  51.     INCON source files and the object and library files created from
  52.     them are:
  53.         Copyright (c) 1993-94, Richard Zigler.
  54.     You may freely distribute unmodified source, object, and library
  55.     files, and incorporate them into your own non-commercial software,
  56.     provided that this paragraph and the program name and copyright
  57.     strings defined in INCON.C are included in all copies.
  58. *************************************************************************/
  59.  
  60. void pascal far AddAttr
  61.                     (
  62.                     char far    *    DestBuf,        /* receiving buffer                    */
  63.                     char far    *    SrcBuf,        /* text buffer                            */
  64.                     char far    *    AttrList,    /* list of attribute bytes            */
  65.                     int             ListSize,    /* length of AttrList                */
  66.                     int             Attr,            /* default attribute                    */
  67.                     int             Flag            /* mark attribute changes            */
  68.                     );
  69.  
  70. /**** EOF:  ADDATTR.H ****/
  71.