home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / man / cat3 / unvis.0 < prev    next >
Text File  |  1993-12-07  |  4KB  |  133 lines

  1.  
  2. UNVIS(3)                   UNIX Programmer's Manual                   UNVIS(3)
  3.  
  4. NNAAMMEE
  5.      uunnvviiss, ssttrruunnvviiss - decode a visual representation of characters
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<vviiss..hh>>
  9.  
  10.      _i_n_t
  11.      uunnvviiss(_u___c_h_a_r _*_c_p, _u___c_h_a_r _c, _i_n_t _*_a_s_t_a_t_e, _i_n_t _f_l_a_g)
  12.  
  13.      _i_n_t
  14.      ssttrruunnvviiss(_c_h_a_r _*_d_s_t, _c_h_a_r _*_s_r_c)
  15.  
  16. DDEESSCCRRIIPPTTIIOONN
  17.      The uunnvviiss() and ssttrruunnvviiss() functions are used to decode a visual repre­
  18.      sentation of characters, as produced by the vis(3) function, back into
  19.      the original form.  Unvis is called with successive characters in _c until
  20.      a valid sequence is recognized, at which time the decoded character is
  21.      available at the character pointed to by _c_p. Strunvis decodes the charac­
  22.      ters pointed to by _s_r_c into the buffer pointed to by _d_s_t.
  23.  
  24.      The ssttrruunnvviiss() function simply copies _s_r_c to _d_s_t, decoding any escape se­
  25.      quences along the way, and returns the number of characters placed into
  26.      _d_s_t, or -1 if an invalid escape sequence was detected.  The size of _d_s_t
  27.      should be equal to the size of _s_r_c (that is, no expansion takes place
  28.      during decoding).
  29.  
  30.      The uunnvviiss() function implements a state machine that can be used to de­
  31.      code an arbitrary stream of bytes.  All state associated with the bytes
  32.      being decoded is stored outside the uunnvviiss() function (that is, a pointer
  33.      to the state is passed in), so calls decoding different streams can be
  34.      freely intermixed.  To start decoding a stream of bytes, first initialize
  35.      an integer to zero.  Call uunnvviiss() with each successive byte, along with a
  36.      pointer to this integer, and a pointer to an destination character.  The
  37.      unvis function has several return codes that must be handled properly.
  38.      They are:
  39.  
  40.      0 (zero)         Another character is necessary; nothing has been recog­
  41.                       nized yet.
  42.  
  43.      UNVIS_VALID      A valid character has been recognized and is available
  44.                       at the location pointed to by cp.
  45.  
  46.      UNVIS_VALIDPUSH  A valid character has been recognized and is available
  47.                       at the location pointed to by cp; however, the character
  48.                       currently passed in should be passed in again.
  49.  
  50.      UNVIS_NOCHAR     A valid sequence was detected, but no character was pro­
  51.                       duced.  This return code is necessary to indicate a log­
  52.                       ical break between characters.
  53.  
  54.      UNVIS_SYNBAD     An invalid esacpe sequence was detected, or the decoder
  55.                       is in an unknown state.  The decoder is placed into the
  56.                       starting state.
  57.  
  58.      When all bytes in the stream have been processed, call uunnvviiss() one more
  59.      time with flag set to UNVIS_END to extract any remaining character (the
  60.      character passed in is ignored).
  61.  
  62.      The following code fragment illustrates a proper use of uunnvviiss().
  63.  
  64.            int state = 0;
  65.            char out;
  66.  
  67.            while ((ch = getchar()) != EOF) {
  68.            again:
  69.                    switch(unvis(&out, ch, &state, 0)) {
  70.                    case 0:
  71.                    case UNVIS_NOCHAR:
  72.                            break;
  73.                    case UNVIS_VALID:
  74.                            (void) putchar(out);
  75.                            break;
  76.                    case UNVIS_VALIDPUSH:
  77.                            (void) putchar(out);
  78.                            goto again;
  79.                    case UNVIS_SYNBAD:
  80.                            (void)fprintf(stderr, "bad sequence!0);
  81.                    exit(1);
  82.                    }
  83.            }
  84.            if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
  85.                    (void) putchar(out);
  86.  
  87. SSEEEE AALLSSOO
  88.      vis(1)
  89.  
  90. HHIISSTTOORRYY
  91.      The uunnvviiss() function is currently under development.
  92.  
  93. BSD Experimental                April 19, 1991                               2
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.