summaryrefslogtreecommitdiffstats
path: root/WWW/Library/Implementation/HTStyle.c
blob: 53b38642cf5a9c953e007529dbd865dc14006d7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * $LynxId: HTStyle.c,v 1.17 2023/10/24 08:14:31 tom Exp $
 *
 *	Style Implementation for Hypertext			HTStyle.c
 *	==================================
 *
 *	Styles allow the translation between a logical property
 *	of a piece of text and its physical representation.
 *
 *	A StyleSheet is a collection of styles, defining the
 *	translation necessary to
 *	represent a document.  It is a linked list of styles.
 */

#include <HTUtils.h>
#include <HTStyle.h>

#include <LYLeaks.h>

/*	Create a new style
*/
HTStyle *HTStyleNew(void)
{
    HTStyle *self = typecalloc(HTStyle);

    if (self == NULL)
	outofmem(__FILE__, "HTStyleNew");
    return self;
}

/*	Create a new style with a name
*/
HTStyle *HTStyleNewNamed(const char *name)
{
    HTStyle *self = HTStyleNew();

    StrAllocCopy(self->w_name, name);
    self->id = -1;		/* <0 */
    return self;
}

/*	Free a style
*/
HTStyle *HTStyleFree(HTStyle *self)
{
    FREE(self->w_name);
    FREE(self->w_SGMLTag);
    FREE(self);
    return NULL;
}

/*			StyleSheet Functions
 *			====================
 */

/*	Searching for styles:
*/
HTStyle *HTStyleNamed(HTStyleSheet *self, const char *name)
{
    HTStyle *scan;

    for (scan = self->styles; scan; scan = scan->next)
	if (0 == strcmp(GetHTStyleName(scan), name))
	    return scan;
    CTRACE((tfp, "StyleSheet: No style named `%s'\n", name));
    return NULL;
}

/*	Add a style to a sheet
 *	----------------------
 */
HTStyleSheet *HTStyleSheetAddStyle(HTStyleSheet *self, HTStyle *style)
{
    style->next = 0;		/* The style will go on the end */
    if (!self->styles) {
	self->styles = style;
    } else {
	HTStyle *scan;

	for (scan = self->styles; scan->next; scan = scan->next) ;	/* Find end */
	scan->next = style;
    }
    return self;
}

/*	Remove the given object from a style sheet if it exists
*/
HTStyleSheet *HTStyleSheetRemoveStyle(HTStyleSheet *self, HTStyle *style)
{
    if (self->styles == style) {
	self->styles = style->next;
	return self;
    } else {
	HTStyle *scan;

	for (scan = self->styles; scan; scan = scan->next) {
	    if (scan->next == style) {
		scan->next = style->next;
		return self;
	    }
	}
    }
    return NULL;
}

/*	Create new style sheet
*/

HTStyleSheet *HTStyleSheetNew(void)
{
    HTStyleSheet *self = typecalloc(HTStyleSheet);

    if (self == NULL)
	outofmem(__FILE__, "HTStyleSheetNew");
    return self;
}

/*	Free off a style sheet pointer
*/
HTStyleSheet *HTStyleSheetFree(HTStyleSheet *self)
{
    HTStyle *style;

    while ((style = self->styles) != 0) {
	self->styles = style->next;
	HTStyleFree(style);
    }
    FREE(self);
    return NULL;
}