man(1) Manual page archive


     TBLKS(2)                                                 TBLKS(2)

     NAME
          tblks - text data blocks

     SYNOPSIS
          include "tblks.m";
          tblks := load Tblks Tblks->PATH;

          Str: adt {
               s: string;
               findr:    fn(s: self ref Str, pos: int, c: int, lim: int): int;
               find:     fn(s: self ref Str, pos: int, c: int, lim: int): int;
          };

          Tblk:     adt {
               b:   array of ref Str;
               new: fn(s: string): ref Tblk;
               pack:     fn(blks: self ref Tblk): ref Str;
               ins: fn(blks: self ref Tblk, s: string, pos: int);
               del: fn(blks: self ref Tblk, n: int, pos: int): string;
               seek:     fn(blks: self ref Tblk, pos: int): (int, int);    # (index in b, off in Str)
               blen:     fn(blks: self ref Tblk): int;
               getc:     fn(blks: self ref Tblk, pos: int): int;
               gets:     fn(blks: self ref Tblk, pos: int, nr: int): string;
               dump:     fn(blks: self ref Tblk);
          };

          init:          fn(sysm: Sys, strm: String, e: Error, dbg: int);
          fixpos:        fn(pos: int, n: int): int;
          fixposins:          fn(pos: int, inspos: int, n: int): int;
          fixposdel:          fn(pos: int, delpos: int, n: int): int;
          strstr:        fn(s1, s2: string): int;
          strchr:        fn(s : string, c : int) : int;
          dtxt:          fn(s: string): string;

     DESCRIPTION
          Tblks provides support for text handling. The Tblk data type
          represents text. It is organized as an array of strings,
          Tblk.b, making up the whole text. To avoid too much string
          copying, an auxiliary Str data type is used to keep refer-
          ences to strings.

          Init should be called before using the module. It receives
          pointers to auxiliary modules loaded by the client program
          including sys(2), string(2), and error(2).

          Tblk.new creates a new Tblk and returns a reference to it.
          The argument s represents initial contents for the text.

          Tblk.pack packs all the strings in a single Str.  After
          calling pack the single string (returned by the function)

     TBLKS(2)                                                 TBLKS(2)

          can be used to operate on the text using standard Limbo
          utilities. Various functions from the module may call pack
          when convenient.

          Tblk.ins inserts s at pos in the text; Tblk.del deletes n
          runes starting at pos in the text (it returns the deleted
          string).

          Tblk.seek translates a position pos into a couple of
          indexes: one locating the string in Tblk.b containing the
          position; another locating the rune within that string.

          Tblk.len returns the number of runes in the text.

          Tblk.getc returns a single rune at pos from the text and
          Tblk.gets returns a substring starting at pos and consisting
          of nr runes.

          The auxiliary Str.find and Str.findr may be used to locate a
          rune c in the string given, not passing lim runes.

          Other auxiliary functions like strchr and strstr are pro-
          vided by the module for compatibility.

          Fixpos ensures that n is in range (adjusting it if needed).
          Fixposins adjusts pos assuming that n runes have been
          inserted at inspos so that it refers to the same (relative)
          place in the text.  Fixposdel is similar but adjusts for
          deletions.

          Dtxt returns a short string useful to print any string for
          debugging.

     EXAMPLE
          See the source for olive(1) as an example of use.

     SOURCE
          /usr/octopus/port/lib/tblks.b