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

  1. #ifndef _InfoP_h
  2. #define _InfoP_h
  3.  
  4. /* $Header: /usr3/xinfo/RCS/InfoP.h,v 1.3 90/11/12 18:07:21 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.  * $Log:    InfoP.h,v $
  36.  * Revision 1.3  90/11/12  18:07:21  jkh
  37.  * Added SET_BLOCK method for initializing text blocks.
  38.  * 
  39.  * Revision 1.2  90/11/11  22:24:27  jkh
  40.  * Added retain_arg
  41.  * 
  42.  * Revision 1.1  90/11/11  21:20:02  jkh
  43.  * Initial revision
  44.  * 
  45.  */
  46.  
  47. #include <X11/IntrinsicP.h>
  48. #include <X11/CoreP.h>
  49.  
  50. #include "Info.h"
  51.  
  52. /* max length of argument string */
  53. #define ARGLEN        128
  54.  
  55. /* max generic string size */
  56. #define MAXSTR        128
  57.  
  58. /* if no max pathlen, define arbitrarily */
  59. #ifndef MAXPATHLEN
  60. #define MAXPATHLEN    512
  61. #endif
  62.  
  63. /* More explanatory macro names */
  64. #define Export
  65. #define Import    extern
  66. #define Local    static
  67. #ifdef __GNUC__
  68. #define Inline inline
  69. #else
  70. #define Inline
  71. #endif
  72.  
  73. /* If we couldn't find it anywhere, make it up */
  74. #ifndef R_OK
  75. #define R_OK    04
  76. #endif
  77.  
  78. /* Convenience macro for setting text blocks */
  79. #define SET_BLOCK(blk, start, end, string) \
  80.     (blk).firstPos = (start), (blk).length = (end), \
  81.     (blk).ptr = (string), (blk).format = FMT8BIT
  82.  
  83. /* number of inits to bump tables up by during allocation */
  84. #define TABLE_INC    50
  85.  
  86. /* special INFO separator character */
  87. #define INFO_CHAR(ch)    ((ch) == '\000' || (ch) == '\037')
  88.  
  89. /* Delete char */
  90. #define DEL_CHAR    '\177'
  91.  
  92. /* Indirect start token */
  93. #define INDIRECT_TOKEN    "\037\nIndirect:\n"
  94.  
  95. /* Tag table start token */
  96. #define TAGTABLE_TOKEN    "\nTag Table:\n"
  97.  
  98. /* Indirect tag table token */
  99. #define ITAGTABLE_TOKEN    "(Indirect)\n"
  100.  
  101. /* Tag table end token */
  102. #define TAGEND_TOKEN    "\037\nEnd tag table\n"
  103.  
  104. /* Node header tokens */
  105. #define NODE_TOKEN    "Node: "
  106. #define PREV_TOKEN    "Prev: "
  107. #define NEXT_TOKEN    "Next: "
  108. #define UP_TOKEN    "Up: "
  109.  
  110. /* Menu start token */
  111. #define MENU_TOKEN    "\n* Menu:"
  112.  
  113. /* Menu seperator token */
  114. #define MENU_SEP_TOKEN    "\n* "
  115.  
  116. /* Footnote start token */
  117. #define NOTE_TOKEN    "*note"
  118.  
  119. /* End of a name */
  120. #define NAME_END_TOKEN    "\t\n,."
  121.  
  122. /* white space */
  123. #define WHITE        "\t\n\f "
  124.  
  125. /* delimiting characters that designate a node name */
  126. #define NAME        "\t\n,."
  127.  
  128. /* Table manipulation macros */
  129.  
  130. #define ZERO_TABLE(tab)        \
  131.      (tab).size = (tab).idx = 0;\
  132.      (tab).table = (ID_P)NULL
  133.  
  134. #define FREE_TABLE(tab)        \
  135.      XtFree((tab).table);    \
  136.      (tab).table = NULL
  137.  
  138. #define ALLOC_TABLE(tab)    \
  139.      FREE_TABLE(tab);        \
  140.      (tab).size = TABLE_INC;    \
  141.      (tab).idx = 0;        \
  142.      (tab).table = (ID_P)XtMalloc(sizeof(ID) * TABLE_INC)
  143.  
  144. #define MAYBE_BUMP_TABLE(tab)    \
  145.      if ((tab).idx == (tab).size) {    \
  146.          (tab).size += TABLE_INC;    \
  147.      (tab).table = (ID_P)XtRealloc((tab).table, (tab).size * sizeof(ID)); \
  148.      }
  149.  
  150. #define ROUND_TABLE(tab)    \
  151.      if ((tab).idx + 1 != (tab).size) { \
  152.      (tab).size = (tab).idx + 1;\
  153.      (tab).table = (ID_P)XtRealloc((tab).table, (tab).size * sizeof(ID)); \
  154.      }                \
  155.      (tab).table[(tab).idx].tag.name = NULL; \
  156.      (tab).table[(tab).idx].offset.length = 0
  157.  
  158. #define ZERO_LIST(lst)        \
  159.      ZERO_TABLE((lst).t);    \
  160.      XtFree((lst).l);        \
  161.      (lst).l = (Strings)NULL
  162.  
  163. #define FREE_LIST(lst)        \
  164.      FREE_TABLE((lst).t);    \
  165.      XtFree((lst).l);        \
  166.      (lst).l = (Strings)NULL
  167.  
  168. #define ALLOC_LIST(lst)        \
  169.      ALLOC_TABLE((lst).t);    \
  170.      (lst).l = (Strings)XtMalloc(sizeof(String) * TABLE_INC)
  171.  
  172. #define FREE_TAG_TABLE(tab)    \
  173.      {                \
  174.      int i;            \
  175.      for (i = 0; i < IDX((tab)); i++) \
  176.           XtFree(I_NAME((tab).table[i])); \
  177.      XtFree((tab).table);    \
  178.      (tab).table = NULL;    \
  179.      }
  180.  
  181. #define MAYBE_BUMP_LIST(lst)    \
  182.      if ((lst).t.idx == (lst).t.size) {    \
  183.          (lst).t.size += TABLE_INC;    \
  184.      (lst).t.table = (ID_P)XtRealloc((lst).t.table, (lst).t.size * \
  185.                      sizeof(ID)); \
  186.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size * \
  187.                       sizeof(String)); \
  188.      }
  189.  
  190. #define ROUND_LIST(lst)        \
  191.      if ((lst).t.idx + 1 != (lst).t.size) {    \
  192.      (lst).t.size = (lst).t.idx + 1;\
  193.      (lst).t.table = (ID_P)XtRealloc((lst).t.table, (lst).t.size * \
  194.                      sizeof(ID)); \
  195.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size * \
  196.                       sizeof(String)); \
  197.      }                \
  198.      (lst).t.table[(lst).t.idx].tag.name = NULL; \
  199.      (lst).t.table[(lst).t.idx].offset.length = 0; \
  200.      (lst).l[(lst).t.idx] = NULL
  201.  
  202. #define IDX(tab)    ((tab).idx)
  203. #define TPOS(tab)    ((tab).table[IDX(tab)])
  204. #define LPOS(lst)    ((lst).l[IDX((lst).t)])
  205. #define INCP(tab)    (IDX(tab)++)
  206.  
  207. /* Turn address s into ptr relative index */
  208. #define INTOFF(ptr, s)        ((int)((s) - (ptr)))
  209.  
  210. typedef String *Strings;
  211.      
  212. typedef struct {
  213.      int nichts;
  214. } InfoClassPart;
  215.  
  216. typedef struct _InfoClassRec {
  217.      CoreClassPart        core_class;
  218.      CompositeClassPart        composite_class;
  219.      InfoClassPart        info_class;
  220. } InfoClassRec;
  221.  
  222. extern InfoClassRec infoClassRec;
  223.  
  224. /* A generic ID (tag/offset). */
  225. typedef union _id {
  226.      struct {                /* if it's a tag        */
  227.       String name;
  228.       int offset;
  229.      } tag;
  230.      struct {                /* if it's an offset        */
  231.       int start;
  232.       int length;
  233.      } offset;
  234. } ID, *ID_P;
  235.  
  236. /* An array of ID's */
  237. typedef struct _table {
  238.      int idx;                /* where we are in the table    */
  239.      int size;
  240.      ID_P table;
  241. } Table;
  242.  
  243. /* a special string/ID associative table */
  244. typedef struct _idlist {
  245.      Table t;                /* ID array representation    */
  246.      Strings l;                /* string array representation    */
  247. } IDList;
  248.  
  249. /* everything we'd like to know about a node */
  250. typedef struct _nodeinfo {
  251.      String file;            /* node's file name        */
  252.      String node;            /* node's nodename        */
  253.      int start;                /* starting position        */
  254.      int length;            /* length of node        */
  255.      ID name;                /* location of nodename        */
  256.      ID prev, up, next;            /* locations of prev, up, next    */
  257.      ID text;                /* location of text        */
  258.      IDList menu;            /* menu information        */
  259.      IDList xref;            /* cross references        */
  260.      struct _nodeinfo *nextNode;    /* for history list        */
  261. } NodeInfo;
  262.  
  263. typedef struct {
  264.      /* resources */
  265.      String path;            /* search path            */
  266.      String file;            /* current info file        */
  267.      String node;            /* current node name        */
  268.      String printCmd;            /* lpr command            */
  269.      int bell_volume;            /* bell volume for error feeps    */
  270.      Boolean retain_arg;        /* whether or not to save arg    */
  271.      XtCallbackList callback;        /* quit callback        */
  272.  
  273.      /* private state */
  274.      String subFile;            /* current split file (if any)    */
  275.      NodeInfo *history;            /* the history list        */
  276.      Table indirect;            /* indirect files        */
  277.      Table tags;            /* indirect tags        */
  278.      String data;            /* pointer to file contents    */
  279.      int size;                /* size of file contents    */
  280.      int hdrSize;            /* size of file header        */
  281.      char arg[ARGLEN];            /* command argument string    */
  282.      Widget fileLabel, nodeLabel;    /* file and node labels        */
  283.      Widget prevCmd, upCmd, nextCmd;    /* prev, up and next commands    */
  284.      Widget menuList;            /* menu list            */
  285.      Widget xrefList;            /* xref list            */
  286.      Widget nodeText;            /* node text            */
  287.      Widget statusLabel;        /* status area            */
  288.      Widget messageLabel;        /* message area            */
  289.      Widget xrefCmd, gotoCmd, searchCmd;/* xref, goto and search cmds    */
  290.      Widget argText;            /* xref/goto/search arg text    */
  291.      Widget helpPopup;            /* help popup            */
  292.      Widget argPopup;            /* argument popup        */
  293.      void (*requester)();        /* routine asking for argument    */
  294. } InfoPart;
  295.  
  296. typedef struct _InfoRec {
  297.      CorePart        core;
  298.      CompositePart    composite;
  299.      InfoPart        info;
  300. } InfoRec;
  301.  
  302. /* special accessors for info widget */
  303. #define DATA(iw)        ((iw)->info.data)
  304. #define DATASIZE(iw)        ((iw)->info.size)
  305. #define HDRSIZE(iw)        ((iw)->info.hdrSize)
  306. #define INDIRECT(iw)        ((iw)->info.indirect)
  307. #define TAGTABLE(iw)        ((iw)->info.tags)
  308. #define HISTORY(iw)        ((iw)->info.history)
  309.  
  310. /* misc */
  311. #define CURNODE(iw)        HISTORY(iw)
  312.  
  313. /* for search */
  314. #define START(iw)        (DATA(iw))
  315. #define END(iw)            (START(iw) + DATASIZE(iw))
  316. #define NSTART(iw, n)        (START(iw) + (n)->start)
  317. #define NEND(iw, n)        (NSTART(iw, n) + (n)->length)
  318. #define NSEARCH(iw, n, str)    (search(iw,NSTART(iw,n),NEND(iw,n),str,False))
  319.  
  320. /* for id's */
  321. #define I_NAME(i)        ((i).tag.name)
  322. #define I_OFFSET(i)        ((i).tag.offset)
  323. #define I_START(i)        ((i).offset.start)
  324. #define I_LEN(i)        ((i).offset.length)
  325.  
  326. #endif /* _InfoP_h */
  327.