home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xinfo / part01 / InfoP.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-28  |  8.8 KB  |  328 lines

  1. #ifndef _InfoP_h
  2. #define _InfoP_h
  3.  
  4. /* $Header: /usr1/ben/jkh/src/xinfo/RCS/InfoP.h,v 1.3 90/01/29 11:29:24 jkh Exp $ */
  5.  
  6. /*
  7.  *
  8.  *                   Copyright 1989, 1990
  9.  *                    Jordan K. Hubbard
  10.  *
  11.  *                PCS Computer Systeme, GmbH.
  12.  *                   Munich, West Germany
  13.  *
  14.  *
  15.  * This file is part of GNU Info widget.
  16.  *
  17.  * The GNU Info widget is free software; you can redistribute it and/or
  18.  * modify it under the terms of the GNU General Public License as published
  19.  * by the Free Software Foundation; either version 1, or (at your option)
  20.  * any later version.
  21.  *
  22.  * This software is distributed in the hope that it will be useful,
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.  * GNU General Public License for more details.
  26.  *
  27.  * You should have received a copy of the GNU General Public License
  28.  * along with this software; see the file COPYING.  If not, write to
  29.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  30.  *
  31.  *
  32.  */
  33.  
  34. /*
  35.  *
  36.  * $Log:    InfoP.h,v $
  37.  * Revision 1.3  90/01/29  11:29:24  jkh
  38.  * *** empty log message ***
  39.  * 
  40.  * Revision 1.2  90/01/28  11:18:05  jkh
  41.  * Fixed comment header.
  42.  * 
  43.  * Revision 1.1  90/01/27  22:43:36  jkh
  44.  * Initial revision
  45.  * 
  46.  *
  47.  */
  48.  
  49. /* max length of argument string */
  50. #define ARGLEN        128
  51.  
  52. /* max generic string size */
  53. #define MAXSTR        128
  54.  
  55. /* if no max pathlen, define arbitrarily */
  56. #ifndef MAXPATHLEN
  57. #define MAXPATHLEN    512
  58. #endif
  59.  
  60. /* More explanatory macro names */
  61. #define Export
  62. #define Import    extern
  63. #define Local    static
  64. #ifdef __GNUC__
  65. #define Inline inline
  66. #else
  67. #define Inline
  68. #endif
  69.  
  70. /* number of inits to bump tables up by during allocation */
  71. #define TABLE_INC    50
  72.  
  73. /* special INFO separator character */
  74. #define INFO_CHAR    '\037'
  75.  
  76. /* Delete char */
  77. #define DEL_CHAR    '\177'
  78.  
  79. /* Indirect start token */
  80. #define INDIRECT_TOKEN    "\037\nIndirect:\n"
  81.  
  82. /* Tag table start token */
  83. #define TAGTABLE_TOKEN    "\nTag Table:\n"
  84.  
  85. /* Indirect tag table token */
  86. #define ITAGTABLE_TOKEN    "(Indirect)\n"
  87.  
  88. /* Tag table end token */
  89. #define TAGEND_TOKEN    "\037\nEnd tag table\n"
  90.  
  91. /* Node header tokens */
  92. #define NODE_TOKEN    "Node: "
  93. #define PREV_TOKEN    "Previous: "
  94. #define NEXT_TOKEN    "Next: "
  95. #define UP_TOKEN    "Up: "
  96.  
  97. /* Menu start token */
  98. #define MENU_TOKEN    "\n* Menu:"
  99.  
  100. /* Menu seperator token */
  101. #define MENU_SEP_TOKEN    "\n* "
  102.  
  103. /* Footnote start token */
  104. #define NOTE_TOKEN    "*note"
  105.  
  106. /* End of a name */
  107. #define NAME_END_TOKEN    "\t\n,."
  108.  
  109. /* white space */
  110. #define WHITE        "\t\n\f "
  111.  
  112. /* delimiting characters that designate a node name */
  113. #define NAME        "\t\n,."
  114.  
  115. /* Table manipulation macros */
  116.  
  117. #define ZERO_TABLE(tab)        \
  118.      (tab).size = (tab).idx = 0;\
  119.      (tab).table = (ID_P)NULL
  120.  
  121. #define FREE_TABLE(tab)        \
  122.      if ((tab).table)        \
  123.           XtFree((tab).table);    \
  124.      (tab).table = NULL
  125.  
  126. #define ALLOC_TABLE(tab)    \
  127.      FREE_TABLE(tab);        \
  128.      (tab).size = TABLE_INC;    \
  129.      (tab).idx = 0;        \
  130.      (tab).table = (ID_P)XtMalloc(sizeof(ID) * TABLE_INC)
  131.  
  132. #define MAYBE_BUMP_TABLE(tab)    \
  133.      if ((tab).idx == (tab).size) {    \
  134.          (tab).size += TABLE_INC;    \
  135.      (tab).table = (ID_P)XtRealloc((tab).table, (tab).size * sizeof(ID)); \
  136.      }
  137.  
  138. #define ROUND_TABLE(tab)    \
  139.      if ((tab).idx + 1 != (tab).size) { \
  140.      (tab).size = (tab).idx + 1;\
  141.      (tab).table = (ID_P)XtRealloc((tab).table, (tab).size * sizeof(ID)); \
  142.      }                \
  143.      (tab).table[(tab).idx].tag.name = NULL; \
  144.      (tab).table[(tab).idx].offset.length = 0
  145.  
  146. #define ZERO_LIST(lst)        \
  147.      ZERO_TABLE((lst).t);    \
  148.      (lst).l = (Strings)NULL
  149.  
  150. #define ALLOC_LIST(lst)        \
  151.      ALLOC_TABLE((lst).t);    \
  152.      (lst).l = (Strings)XtMalloc(sizeof(String) * TABLE_INC)
  153.  
  154. #define FREE_TAG_TABLE(tab)    \
  155.      {                \
  156.      int i;            \
  157.      for (i = 0; i < IDX((tab)); i++) \
  158.           XtFree(I_NAME((tab).table[i])); \
  159.      XtFree((tab).table);    \
  160.      (tab).table = NULL;    \
  161.      }
  162.  
  163. #define MAYBE_BUMP_LIST(lst)    \
  164.      if ((lst).t.idx == (lst).t.size) {    \
  165.          (lst).t.size += TABLE_INC;    \
  166.      (lst).t.table = (ID_P)XtRealloc((lst).t.table, (lst).t.size * \
  167.                      sizeof(ID)); \
  168.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size * \
  169.                       sizeof(String)); \
  170.      }
  171.  
  172. #define ROUND_LIST(lst)        \
  173.      if ((lst).t.idx + 1 != (lst).t.size) {    \
  174.      (lst).t.size = (lst).t.idx + 1;\
  175.      (lst).t.table = (ID_P)XtRealloc((lst).t.table, (lst).t.size * \
  176.                      sizeof(ID)); \
  177.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size * \
  178.                       sizeof(String)); \
  179.      }                \
  180.      (lst).t.table[(lst).t.idx].tag.name = NULL; \
  181.      (lst).t.table[(lst).t.idx].offset.length = 0; \
  182.      (lst).l[(lst).t.idx] = NULL
  183.  
  184. #define IDX(tab)    ((tab).idx)
  185. #define TPOS(tab)    ((tab).table[IDX(tab)])
  186. #define LPOS(lst)    ((lst).l[IDX((lst).t)])
  187. #define INCP(tab)    (IDX(tab)++)
  188.  
  189. /* Turn address s into ptr relative index */
  190. #define INTOFF(ptr, s)        ((int)((s) - (ptr)))
  191.  
  192. /* Make sure widget is outermost widget */
  193. #define TOP_WIDGET(ww) ((InfoWidget)(XtIsSubclass((ww), panedWidgetClass) ? \
  194.                      (ww) : XtParent((ww))));
  195.  
  196. /* #include <X11/Xaw/Info.h> */     
  197. #include "Info.h"
  198. #include <X11/Xaw/PanedP.h>
  199.  
  200. typedef String *Strings;
  201.      
  202. typedef struct {
  203.      int nichts;
  204. } InfoClassPart;
  205.  
  206. typedef struct _InfoClassRec {
  207.      CoreClassPart        core_class;
  208.      CompositeClassPart        composite_class;
  209.      ConstraintClassPart    constraint_class;
  210.      PanedClassPart        paned_class;
  211.      InfoClassPart        info_class;
  212. } InfoClassRec;
  213.  
  214. extern InfoClassRec infoClassRec;
  215.  
  216. /* A generic ID (tag/offset). */
  217. typedef union _id {
  218.      struct {                /* if it's a tag */
  219.       String name;
  220.       int offset;
  221.      } tag;
  222.      struct {                /* if it's an offset */
  223.       int start;
  224.       int length;
  225.      } offset;
  226. } ID, *ID_P;
  227.  
  228. /* An array of ID's */
  229. typedef struct _table {
  230.      int idx;                /* where we are in the table */
  231.      int size;
  232.      ID_P table;
  233. } Table;
  234.  
  235. /* a special string/ID associative table */
  236. typedef struct _idlist {
  237.      Table t;                /* ID array representation */
  238.      Strings l;                /* string array representation */
  239. } IDList;
  240.  
  241. /* everything we'd like to know about a node */
  242. typedef struct _nodeinfo {
  243.      String file;            /* node's file name */
  244.      String node;            /* node's nodename */
  245.      int start;                /* starting position */
  246.      int length;            /* length of node */
  247.      ID name;                /* location of nodename */
  248.      ID prev, up, next;            /* locations of prev, up, next */
  249.      ID text;                /* location of text */
  250.      IDList menu;            /* menu information */
  251.      IDList xref;            /* cross references */
  252.      struct _nodeinfo *nextNode;    /* for history list */
  253. } NodeInfo;
  254.  
  255. typedef struct {
  256.      /* resources */
  257.      String path;            /* search path */
  258.      String file;            /* current info file */
  259.      String node;            /* current node name */
  260.      String helpFile;            /* help file */
  261.      String printCmd;            /* lpr command */
  262.      XtCallbackList callback;        /* quit callback */
  263.  
  264.      /* private state */
  265.      String tempfile;            /* for the node contents */
  266.      String subFile;            /* current split file (if any) */
  267.      NodeInfo *history;            /* the history list */
  268.      Table indirect;            /* indirect files */
  269.      Table tags;            /* indirect tags */
  270.      String data;            /* pointer to file contents */
  271.      int size;                /* size of file contents */
  272.      int hdrSize;            /* size of file header */
  273.      char arg[ARGLEN];            /* command argument string */
  274.      Widget fileLabel, nodeLabel;    /* file and node labels */
  275.      Widget prevCmd, upCmd, nextCmd;    /* prev, up and next commands */
  276.      Widget menuList;            /* menu list */
  277.      Widget xrefList;            /* xref list */
  278.      Widget nodeText;            /* node text */
  279.      Widget statusLabel;        /* status area */
  280.      Widget messageLabel;        /* message area */
  281.      Widget xrefCmd, gotoCmd, searchCmd;/* xref, goto and search commands */
  282.      Widget argText;            /* xref/goto/search arg text */
  283.      Widget helpPopup;            /* help popup */
  284. } InfoPart;
  285.  
  286. typedef struct _InfoRec {
  287.      CorePart        core;
  288.      CompositePart    composite;
  289.      ConstraintPart    constraint;
  290.      PanedPart        paned;
  291.      InfoPart        info;
  292. } InfoRec;
  293.  
  294. typedef struct {
  295.      int null;
  296. } InfoConstraintsPart;
  297.  
  298. typedef struct _InfoConstraintsRec {
  299.     PanedConstraintsPart paned ;
  300.     InfoConstraintsPart   info;
  301. } InfoConstraintsRec, *InfoConstraints;
  302.  
  303. /* special accessors for info widget */
  304. #define DATA(iw)        ((iw)->info.data)
  305. #define DATASIZE(iw)        ((iw)->info.size)
  306. #define HDRSIZE(iw)        ((iw)->info.hdrSize)
  307. #define INDIRECT(iw)        ((iw)->info.indirect)
  308. #define TAGTABLE(iw)        ((iw)->info.tags)
  309. #define HISTORY(iw)        ((iw)->info.history)
  310.  
  311. /* misc */
  312. #define CURNODE(iw)        HISTORY(iw)
  313.  
  314. /* for search */
  315. #define START(iw)        (DATA(iw))
  316. #define END(iw)            (START(iw) + DATASIZE(iw))
  317. #define NSTART(iw, n)        (START(iw) + (n)->start)
  318. #define NEND(iw, n)        (NSTART(iw, n) + (n)->length)
  319. #define NSEARCH(iw, n, str)    (search(iw,NSTART(iw,n),NEND(iw,n),str,False))
  320.  
  321. /* for id's */
  322. #define I_NAME(i)        ((i).tag.name)
  323. #define I_OFFSET(i)        ((i).tag.offset)
  324. #define I_START(i)        ((i).offset.start)
  325. #define I_LEN(i)        ((i).offset.length)
  326.  
  327. #endif /* _InfoP_h */
  328.