1 /********************************************************************
2  * $Author: jgoerzen $
3  * $Revision: 1.2 $
4  * $Date: 2000/12/20 01:19:20 $
5  * $Source: /home/jgoerzen/tmp/gopher-umn/gopher/head/object/BLblock.h,v $
6  * $State: Exp $
7  *
8  * Paul Lindner, University of Minnesota CIS.
9  *
10  * Copyright 1991, 1992,1993 by the Regents of the University of Minnesota
11  * see the file "Copyright" in the distribution for conditions of use.
12  *********************************************************************
13  * MODULE: BLblock.h
14  * Header file and abstraction of a gopher+ block
15  *********************************************************************
16  * Revision History:
17  * $Log: BLblock.h,v $
18  * Revision 1.2  2000/12/20 01:19:20  jgoerzen
19  * Added patches from David Allen <s2mdalle@titan.vcu.edu>
20  *
21  * Revision 1.1.1.1  2000/08/19 00:28:56  jgoerzen
22  * Import from UMN Gopher 2.3.1 after GPLization
23  *
24  * Revision 3.5  1995/09/26  05:16:30  lindner
25  * more fixes...
26  *
27  * Revision 3.4  1995/09/25  22:07:16  lindner
28  * Ansification
29  *
30  * Revision 3.3  1995/02/27  17:45:32  lindner
31  * Use enums for block structures
32  *
33  * Revision 3.2  1993/03/26  19:50:41  lindner
34  * Mitra fixes for better/clearer fromNet code
35  *
36  * Revision 3.1.1.1  1993/02/11  18:03:06  lindner
37  * Gopher+1.2beta release
38  *
39  * Revision 1.1  1993/01/31  00:31:12  lindner
40  * Initial revision
41  *
42  *
43  *********************************************************************/
44 
45 
46 #ifndef BLBLOCK_H
47 #define BLBLOCK_H
48 
49 #include "STRstring.h"
50 #include "STAarray.h"
51 #include "boolean.h"
52 #include "util.h"
53 
54 /** Return Values for *fromNet() functions **/
55 #define SOFTERROR -1
56 #define HARDERROR -2
57 #define MORECOMING 1
58 #define FOUNDEOF 0
59 
60 
61 typedef struct block_struct Blockobj;
62 typedef DynArray BlockArray;
63 
64 #include "GSgopherobj.h"
65 
66 
67 /** The different types of blocks **/
68 enum blocktype {
69 	 BLOCK_UNKNOWN  =0,
70 	 BLOCK_VIEW     =1,
71 	 BLOCK_ASK      =2,
72 	 BLOCK_ABSTRACT =3,
73 	 BLOCK_ADMIN    =4
74 };
75 typedef enum blocktype BlockType;
76 
77 
78 /** The block data is a union, it can either be a filename or the
79  ** actual data in a STRarray, or a gopher reference.
80  **/
81 
82 union BlockData_union {
83      String      *filename;
84      StrArray    *text;
85      GopherObj   *gs;
86 };
87 
88 typedef union BlockData_union BlockData;
89 
90 
91 enum blockdatatype {
92 	BDATA_NONE =0,
93 	BDATA_FILE =1,
94 	BDATA_TEXT =2,
95 	BDATA_GREF =3
96 };
97 typedef enum blockdatatype BlockDataType;
98 
99 
100 struct block_struct
101 {
102      BlockType     btype;
103      String        *Blockname;
104      BlockDataType datatype;
105      BlockData     data;
106 };
107 
108 
109 /****** Macros/data access ********/
110 #define BLgetName(a)        (STRget((a)->Blockname))
111 #define BLsetName(a,b)      (STRset((a)->Blockname,(b)))
112 
113 #define BLgetBlocktype(a)   (STRget((a)->btype))
114 #define BLsetBlocktype(a,b) (STRset((a)->btype,(b)))
115 
116 #define BLgetDatatype(a)    ((a)->datatype)
117 
118 /**** Prototype declarations. ****/
119 Blockobj *BLnew();
120 void      BLdestroy(Blockobj *bl);
121 void      BLinit(Blockobj *bl);
122 void      BLcpy(Blockobj *dest, Blockobj *orig);
123 int       BLgetNumLines(Blockobj *bl);
124 
125 void      BLsetFile(Blockobj *bl, char *filename);
126 void      BLsetGref(Blockobj *bl, GopherObj *);
127 void      BLsetText(Blockobj *bl, StrArray *sta);
128 char *    BLgetLine(Blockobj *bl, int lineno);
129 void      BLtoNet(Blockobj *bl, int fd, boolean showheader);
130 int       BLfromNet(Blockobj *bl, int fd, char *blockname);
131 int       BLAsearch(BlockArray *bla, char *bname);
132 void      BLaddText(Blockobj *bl, char *text);
133 
134 /*************************************************************
135  ** Define a dynamic block array
136  **/
137 
138 #include "DAarray.h"
139 
140 #define BLAnew(a)       (DAnew((a),BLnew,BLinit,BLdestroy,BLcpy))
141 #define BLAinit(a)       (DAinit((a)))
142 #define BLAgetTop(a)     (DAgetTop(a))
143 #define BLAgetEntry(a,b) (Blockobj*)(DAgetEntry(a,b))
144 #define BLApush(a,b)     (DApush((DynArray*)(a),(char*)(b)))
145 #define BLAdestroy(a)    (DAdestroy(a))
146 #define BLAcpy(a,b)      (DAcpy(a,b))
147 
148 #endif
149