File: loadformats

package info (click to toggle)
epic5 2.0.1-1
  • links: PTS
  • area: main
  • in suites: buster, sid, stretch
  • size: 4,696 kB
  • ctags: 6,357
  • sloc: ansic: 69,814; makefile: 715; ruby: 227; sh: 178; perl: 13
file content (158 lines) | stat: -rw-r--r-- 3,674 bytes parent folder | download | duplicates (3)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# $EPIC: loadformats,v 1.3 2006/10/30 03:11:43 jnelson Exp $
# loadformats (format.irc) - Add customizeable formatting to EPIC5
# Copyright (c) 2005 Brian Weiss <brian@epicsol.org>
# See the 'COPYRIGHT' file for more information.
#
# This script provides support for easily adding customizeable
# formatting to EPIC5. Formats can either be added individually
# via /ADDFORMAT or they can be loaded from a "format file" with
# the /LOADFORMATS alias.
#
# The format of this file is as follows:
#
# <type> <str>
#
# where <type> is the name of the /ON hook that would normally be
# used to format output from the desired event and <str> is a text
# text string containing cparse(6) color codes and numeric expandos.
#
# e.g.
# PUBLIC %K<%n$0%K>%n $2-
# MSG %K[%C$0%K\(%c$userhost($0)%K\)] $1-
#
# Note: Due to the fact that this uses $cparse() to add colors, special
#       care may need to be taken when formats contain double quotes.
#
# Adding a format for an event with either of the above methods will
# create a /SET variable named "FORMAT_<type>" whose value will be
# used to determine the formatting of the event.
#
# This file will refuse to load if your client doesn't have implied on
# hooks (either cause it's too old, or you compiled it out)
#

# Make sure this file gets loaded with the PF loader.
if (word(2 $loadinfo()) != [pf])
{
	load -pf $word(1 $loadinfo());
	return;                       
};

if (index(h $info(O)) == -1) {
	xecho -b Your client doesn't have implied hooks, sorry.;
	return
};

#
# addformat <type> [value]
#
# Adds a new format into the system. This will create a /SET variable
# named "FORMAT_<type>" and will create an IMPLIED hook for the specified
# type via $hookctl().
#
alias addformat (type, value)
{
	if (!value)
		return;

	@ :type = toupper($type);
	@ :var = [FORMAT_] ## type;
	@ hookctl(set list $type implied \$$var);
	@ symbolctl(create $var);
	@ symbolctl(set $var 1 builtin_variable type str);
	^set $var $value;
	xecho -b -s Added format for the $type event;
};

#
# delformat <type>
#
# Removes a format from the system. This removes both the /SET variable
# and the implied hook.
#
alias delformat (type, void)
{
	if (!type) {
		xecho -b Usage: $(K)DELFORMAT <type>;
		return;
	};

	@ :type = toupper($type);
	@ hookctl(set list $type implied);
	@ symbolctl(delete FORMAT_$type builtin_variable);
	@ symbolctl(check FORMAT_$type);
	xecho -b -s Deleted format for the $type event;
};

#
# dumpformats
#
# Removes all formats from the system.
#
alias dumpformats (void)
{
	xecho -b -s Dumping all formats;
	for hook in ($hookctl(list lists))
	{
		if (hookctl(get list $hook implied))
			^delformat $hook;
	};
};

#
# loadformats <file>
#
# This loads all formats in the specified file.
#
alias loadformats (file, void)
{
	if (!file) {
		xecho -b Usage: $(K)LOADFORMATS <file>;
		return;
	};

	xecho -b -s Loading formats from $file;

	if ((:fd = open($file r)) != -1)
	{
		while (!eof($fd))
		{
			@ :line = read($fd);
			@ :type = word(0 $line);
			@ :value = restw(1 $line);
			^addformat $type $value;
		};
		@ close($fd);
	}{
		xecho -b ERROR: Unable to open file for reading: $file;
	};
};

#
# saveformats <file>
#
# Writes all existing formats to the specified file.
#
alias saveformats (file, void)
{
	if (!file) {
		xecho -b Usage: $(K)SAVEFORMATS <file>;
		return;
	};

	xecho -b -s Saving formats to $file;

	if ((:fd = open($file w)) != -1)
	{
		for hook in ($hookctl(list lists))
		{                                 
			if (hookctl(get list $hook implied)) {
				eval @ write\(\$fd \$hook \$FORMAT_$hook\);
			};
		};
		@ close($fd);
	}{
		xecho -b ERROR: Unable to open file for writing: $file;
	};
};