TCL clipboards

Home > Software > Clipboards
  • C++ tools and libraries
  • - The G2 preprocessor
    - Compressed Bitvectors
  • TCL tools ans libraries
  • - TODL
    - Clipboards
    - BWidgets
  • Papers
  • - Objects in TCL
    - TCL data formats
  • Poetry
  • Short fiction
  • About this site
  • What's new?
  • Links
  • Contact
  • Introduction

    This is a library for TCL clipboards. Warning: The implementation is extremely simple, and not very robust.

    The idea is that you can store text in a buffer, manipulate it, and then send it to output. The buffer allows you to change, remove or insert text many times before producing the final output. This helps in situations where you want to write the text in a come-back-and-fix-it-later fashion. You do not need to know in advance exactly what you will want to output. With "puts" you do not have this flexibility, because when you "puts" something, it's gone.

    A text buffer in this library is called a clipboard. A clipboard is a tree of nodes. Each node can be one of the following:

    • A text node, containing plain freeform text.
    • A plug with a name. New nodes can be inserted into a plug (they become child nodes of the plug), and plugs can be emptied so you can alter their contents.
    • A reference to another clipboard. You can refer to the same clipboard multiple times. When generating code, this allows you to create a fragment of code once, and output it multiple times (sort of like a #define in C).

    You can insert new text into a plug, or remove the contents of a plug. Plugs are accessed by their name, which is assumed to be unique within a clipboard.

    When the clipboard is finally printed to output, the tree is traversed depth-first and all encountered text is printed. References to other clipboards are printed in the same way, recursively.

    Although conceptually a clipboard is a tree, it is implemented in TCL as an array. The names of plug points are the entries into the array. These names are mapped to a list of nodes, each of which is a tuple starting with a specific letter: 't' for text nodes, 'p' for plugs, 'r' for references.

    Refer to the examples to see how it all works:

    • example1.tcl: Using the basic clipboard procedures.
      The output of running this script is in out1.txt.
    • example2.tcl: Using a more intuitive interface, we build nested structures in which the clipboard text is stored.
      The output of running this script is in out2.txt.
    • example3.tcl: Gives a brief impression of how clipboards can be used in code generation (in this case, generating a C++ class).
      The output of running this script is in out3.txt.

    Download area

    You can browse the implementation on-line, or download the entire thing in one tarball:

    • lib_clip.tcl contains the implementation of the clipboard arrays. For its use, see example1 above.
    • syn_clip.tcl offers a more intuitive interface for working with clipboards. For its use, see example2 above.
    • clip-0.1.tgz is the tarball for linux.