4838c4cd5bf38f3af1679dd23e7c7ebc1661fe0e
[monky] / src / text_object.h
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  *
3  * Conky, a system monitor, based on torsmo
4  *
5  * Any original torsmo code is licensed under the BSD license
6  *
7  * All code written since the fork of torsmo is licensed under the GPL
8  *
9  * Please see COPYING for details
10  *
11  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
13  *      (see AUTHORS)
14  * All rights reserved.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 #ifndef _TEXT_OBJECT_H
30 #define _TEXT_OBJECT_H
31
32 #include "config.h"             /* for the defines */
33 #include "timed_thread.h"       /* timed_thread */
34
35 #ifdef TCP_PORT_MONITOR
36 #include "tcp-portmon.h"        /* tcp_port_monitor_data */
37 #endif
38
39 #include "mail.h"               /* local_mail_s */
40 #include "fs.h"                 /* struct fs_stat */
41
42 #ifdef NVIDIA
43 #include "nvidia.h"             /* nvidia_s */
44 #endif
45
46 #define SPECIAL_CHAR '\x01'
47 #define SECRIT_MULTILINE_CHAR '\x02'
48
49 enum text_object_type {
50         OBJ_read_tcp,
51         OBJ_addr,
52 #if defined(__linux__)
53         OBJ_addrs,
54 #endif /* __linux__ */
55 #ifndef __OpenBSD__
56         OBJ_acpiacadapter,
57         OBJ_adt746xcpu,
58         OBJ_adt746xfan,
59         OBJ_acpifan,
60         OBJ_acpitemp,
61         OBJ_battery,
62         OBJ_battery_time,
63         OBJ_battery_percent,
64         OBJ_battery_bar,
65         OBJ_battery_short,
66 #endif /* !__OpenBSD__ */
67         OBJ_buffers,
68         OBJ_cached,
69         OBJ_color,
70         OBJ_color0,
71         OBJ_color1,
72         OBJ_color2,
73         OBJ_color3,
74         OBJ_color4,
75         OBJ_color5,
76         OBJ_color6,
77         OBJ_color7,
78         OBJ_color8,
79         OBJ_color9,
80         OBJ_conky_version,
81         OBJ_conky_build_date,
82         OBJ_conky_build_arch,
83         OBJ_font,
84         OBJ_cpu,
85         OBJ_cpubar,
86 #ifdef X11
87         OBJ_cpugauge,
88         OBJ_cpugraph,
89         OBJ_loadgraph,
90 #endif /* X11 */
91         OBJ_diskio,
92         OBJ_diskio_read,
93         OBJ_diskio_write,
94 #ifdef X11
95         OBJ_diskiograph,
96         OBJ_diskiograph_read,
97         OBJ_diskiograph_write,
98 #endif /* X11 */
99         OBJ_downspeed,
100         OBJ_downspeedf,
101 #ifdef X11
102         OBJ_downspeedgraph,
103 #endif /* X11 */
104         OBJ_else,
105         OBJ_endif,
106         OBJ_eval,
107         OBJ_image,
108         OBJ_exec,
109         OBJ_execi,
110         OBJ_texeci,
111         OBJ_execbar,
112         OBJ_execibar,
113 #ifdef X11
114         OBJ_execgauge,
115         OBJ_execgraph,
116         OBJ_execigraph,
117         OBJ_execigauge,
118 #endif /* X11 */
119         OBJ_execp,
120         OBJ_execpi,
121         OBJ_freq,
122         OBJ_freq_g,
123         OBJ_fs_bar,
124         OBJ_fs_bar_free,
125         OBJ_fs_free,
126         OBJ_fs_free_perc,
127         OBJ_fs_size,
128         OBJ_fs_type,
129         OBJ_fs_used,
130         OBJ_fs_used_perc,
131         OBJ_goto,
132         OBJ_tab,
133         OBJ_hr,
134         OBJ_offset,
135         OBJ_voffset,
136         OBJ_alignr,
137         OBJ_alignc,
138         OBJ_i2c,
139         OBJ_platform,
140         OBJ_hwmon,
141 #if defined(__linux__)
142         OBJ_disk_protect,
143         OBJ_i8k_version,
144         OBJ_i8k_bios,
145         OBJ_i8k_serial,
146         OBJ_i8k_cpu_temp,
147         OBJ_i8k_left_fan_status,
148         OBJ_i8k_right_fan_status,
149         OBJ_i8k_left_fan_rpm,
150         OBJ_i8k_right_fan_rpm,
151         OBJ_i8k_ac_status,
152         OBJ_i8k_buttons_status,
153 #if defined(IBM)
154         OBJ_ibm_fan,
155         OBJ_ibm_temps,
156         OBJ_ibm_volume,
157         OBJ_ibm_brightness,
158         OBJ_smapi,
159 #ifdef X11
160         OBJ_smapi_bat_bar,
161 #endif /* X11 */
162         OBJ_smapi_bat_perc,
163         OBJ_smapi_bat_temp,
164         OBJ_smapi_bat_power,
165         OBJ_if_smapi_bat_installed,
166 #endif /* IBM */
167         /* information from sony_laptop kernel module
168          * /sys/devices/platform/sony-laptop */
169         OBJ_sony_fanspeed,
170         OBJ_if_gw,
171         OBJ_ioscheduler,
172         OBJ_gw_iface,
173         OBJ_gw_ip,
174         OBJ_laptop_mode,
175         OBJ_pb_battery,
176         OBJ_voltage_mv,
177         OBJ_voltage_v,
178         OBJ_wireless_essid,
179         OBJ_wireless_mode,
180         OBJ_wireless_bitrate,
181         OBJ_wireless_ap,
182         OBJ_wireless_link_qual,
183         OBJ_wireless_link_qual_max,
184         OBJ_wireless_link_qual_perc,
185         OBJ_wireless_link_bar,
186 #endif /* __linux__ */
187 #if defined(__FreeBSD__) || defined(__linux__)
188         OBJ_if_up,
189 #endif
190         OBJ_if_empty,
191         OBJ_if_match,
192         OBJ_if_existing,
193         OBJ_if_mounted,
194         OBJ_if_running,
195         OBJ_if_updatenr,
196         OBJ_top,
197         OBJ_top_mem,
198         OBJ_top_time,
199 #ifdef IOSTATS
200         OBJ_top_io,
201 #endif
202         OBJ_tail,
203         OBJ_head,
204         OBJ_lines,
205         OBJ_words,
206         OBJ_kernel,
207         OBJ_loadavg,
208         OBJ_machine,
209         OBJ_mails,
210         OBJ_new_mails,
211         OBJ_seen_mails,
212         OBJ_unseen_mails,
213         OBJ_flagged_mails,
214         OBJ_unflagged_mails,
215         OBJ_forwarded_mails,
216         OBJ_unforwarded_mails,
217         OBJ_replied_mails,
218         OBJ_unreplied_mails,
219         OBJ_draft_mails,
220         OBJ_trashed_mails,
221         OBJ_mboxscan,
222         OBJ_mem,
223         OBJ_memeasyfree,
224         OBJ_memfree,
225 #ifdef X11
226         OBJ_memgauge,
227         OBJ_memgraph,
228 #endif /* X11 */
229         OBJ_membar,
230         OBJ_memmax,
231         OBJ_memperc,
232         OBJ_mixer,
233         OBJ_mixerl,
234         OBJ_mixerr,
235 #ifdef X11
236         OBJ_mixerbar,
237         OBJ_mixerlbar,
238         OBJ_mixerrbar,
239 #endif /* X11 */
240         OBJ_if_mixer_mute,
241 #ifdef X11
242         OBJ_monitor,
243         OBJ_monitor_number,
244         OBJ_desktop,
245         OBJ_desktop_number,
246         OBJ_desktop_name,
247 #endif /* X11 */
248         OBJ_nameserver,
249         OBJ_nodename,
250         OBJ_nvidia,
251         OBJ_pre_exec,
252         OBJ_processes,
253         OBJ_running_processes,
254         OBJ_shadecolor,
255         OBJ_outlinecolor,
256         OBJ_stippled_hr,
257         OBJ_swap,
258         OBJ_swapfree,
259         OBJ_swapbar,
260         OBJ_swapmax,
261         OBJ_swapperc,
262         OBJ_sysname,
263         OBJ_text,
264         OBJ_time,
265         OBJ_utime,
266         OBJ_tztime,
267         OBJ_totaldown,
268         OBJ_totalup,
269         OBJ_updates,
270         OBJ_upspeed,
271         OBJ_upspeedf,
272 #ifdef X11
273         OBJ_upspeedgraph,
274 #endif /* X11 */
275         OBJ_uptime,
276         OBJ_uptime_short,
277         OBJ_user_names,
278         OBJ_user_terms,
279         OBJ_user_times,
280         OBJ_user_number,
281         OBJ_imap_messages,
282         OBJ_imap_unseen,
283         OBJ_pop3_unseen,
284         OBJ_pop3_used,
285 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
286                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
287         OBJ_apm_adapter,
288         OBJ_apm_battery_time,
289         OBJ_apm_battery_life,
290 #endif /* __FreeBSD__ __OpenBSD__ */
291 #ifdef __OpenBSD__
292         OBJ_obsd_sensors_temp,
293         OBJ_obsd_sensors_fan,
294         OBJ_obsd_sensors_volt,
295         OBJ_obsd_vendor,
296         OBJ_obsd_product,
297 #endif /* __OpenBSD__ */
298 #ifdef MPD
299         OBJ_mpd_title,
300         OBJ_mpd_artist,
301         OBJ_mpd_album,
302         OBJ_mpd_random,
303         OBJ_mpd_repeat,
304         OBJ_mpd_vol,
305         OBJ_mpd_bitrate,
306         OBJ_mpd_status,
307         OBJ_mpd_bar,
308         OBJ_mpd_elapsed,
309         OBJ_mpd_length,
310         OBJ_mpd_track,
311         OBJ_mpd_name,
312         OBJ_mpd_file,
313         OBJ_mpd_percent,
314         OBJ_mpd_smart,
315         OBJ_if_mpd_playing,
316 #endif /* MPD */
317 #ifdef MOC
318         OBJ_moc_state,
319         OBJ_moc_file,
320         OBJ_moc_title,
321         OBJ_moc_artist,
322         OBJ_moc_song,
323         OBJ_moc_album,
324         OBJ_moc_totaltime,
325         OBJ_moc_timeleft,
326         OBJ_moc_curtime,
327         OBJ_moc_bitrate,
328         OBJ_moc_rate,
329 #endif /* MOC */
330 #ifdef XMMS2
331         OBJ_xmms2_artist,
332         OBJ_xmms2_album,
333         OBJ_xmms2_title,
334         OBJ_xmms2_genre,
335         OBJ_xmms2_comment,
336         OBJ_xmms2_url,
337         OBJ_xmms2_date,
338         OBJ_xmms2_tracknr,
339         OBJ_xmms2_bitrate,
340         OBJ_xmms2_id,
341         OBJ_xmms2_duration,
342         OBJ_xmms2_elapsed,
343         OBJ_xmms2_size,
344         OBJ_xmms2_percent,
345         OBJ_xmms2_status,
346 #ifdef X11
347         OBJ_xmms2_bar,
348 #endif /* X11 */
349         OBJ_xmms2_smart,
350         OBJ_xmms2_playlist,
351         OBJ_xmms2_timesplayed,
352         OBJ_if_xmms2_connected,
353 #endif /* XMMS2 */
354 #ifdef AUDACIOUS
355         OBJ_audacious_status,
356         OBJ_audacious_title,
357         OBJ_audacious_length,
358         OBJ_audacious_length_seconds,
359         OBJ_audacious_position,
360         OBJ_audacious_position_seconds,
361         OBJ_audacious_bitrate,
362         OBJ_audacious_frequency,
363         OBJ_audacious_channels,
364         OBJ_audacious_filename,
365         OBJ_audacious_playlist_length,
366         OBJ_audacious_playlist_position,
367         OBJ_audacious_main_volume,
368 #ifdef X11
369         OBJ_audacious_bar,
370 #endif /* X11 */
371 #endif /* AUDACIOUS */
372 #ifdef BMPX
373         OBJ_bmpx_title,
374         OBJ_bmpx_artist,
375         OBJ_bmpx_album,
376         OBJ_bmpx_track,
377         OBJ_bmpx_uri,
378         OBJ_bmpx_bitrate,
379 #endif /* BMPX */
380 #ifdef EVE
381         OBJ_eve,
382 #endif /* EVE */
383 #ifdef HAVE_CURL
384         OBJ_curl,
385 #endif /* HAVE_CURL */
386 #ifdef RSS
387         OBJ_rss,
388 #endif /* RSS */
389 #ifdef WEATHER
390         OBJ_weather,
391 #endif /* WEATHER */
392 #ifdef XOAP
393         OBJ_weather_forecast,
394 #endif /* XOAP */
395 #ifdef HAVE_LUA
396         OBJ_lua,
397         OBJ_lua_parse,
398         OBJ_lua_bar,
399 #ifdef X11
400         OBJ_lua_graph,
401         OBJ_lua_gauge,
402 #endif /* X11 */
403 #endif /* HAVE_LUA */
404 #ifdef TCP_PORT_MONITOR
405         OBJ_tcp_portmon,
406 #endif /* TCP_PORT_MONITOR */
407 #ifdef HAVE_ICONV
408         OBJ_iconv_start,
409         OBJ_iconv_stop,
410 #endif /* HAVE_ICONV */
411 #ifdef HDDTEMP
412         OBJ_hddtemp,
413 #endif /* HDDTEMP */
414         OBJ_include,
415         OBJ_blink,
416         OBJ_to_bytes,
417         OBJ_scroll,
418         OBJ_combine,
419         OBJ_entropy_avail,
420         OBJ_entropy_perc,
421         OBJ_entropy_poolsize,
422         OBJ_entropy_bar,
423 #ifdef APCUPSD
424         OBJ_apcupsd,
425         OBJ_apcupsd_name,
426         OBJ_apcupsd_model,
427         OBJ_apcupsd_upsmode,
428         OBJ_apcupsd_cable,
429         OBJ_apcupsd_status,
430         OBJ_apcupsd_linev,
431         OBJ_apcupsd_load,
432         OBJ_apcupsd_loadbar,
433 #ifdef X11
434         OBJ_apcupsd_loadgraph,
435         OBJ_apcupsd_loadgauge,
436 #endif /* X11 */
437         OBJ_apcupsd_charge,
438         OBJ_apcupsd_timeleft,
439         OBJ_apcupsd_temp,
440         OBJ_apcupsd_lastxfer,
441 #endif /* APCUPSD */
442 };
443
444 struct text_object {
445         struct text_object *next, *prev;        /* doubly linked list of text objects */
446         struct text_object *sub;                /* for objects parsing text into objects */
447         union {
448                 char *s;                /* some string */
449                 int i;                  /* some integer */
450                 long l;                 /* some other integer */
451                 unsigned int sensor;
452                 struct net_stat *net;
453                 struct fs_stat *fs;
454                 struct diskio_stat *diskio;
455                 unsigned char loadavg[3];
456                 unsigned int cpu_index;
457                 struct mail_s *mail;
458
459                 struct {
460                         char *args;
461                         char *output;
462                 } mboxscan;
463
464                 struct {
465                         char *tz;       /* timezone variable */
466                         char *fmt;      /* time display formatting */
467                 } tztime;
468
469                 struct {
470                         struct fs_stat *fs;
471                         int w, h;
472                 } fsbar;                /* 3 */
473
474 #ifdef X11
475                 struct {
476                         int l;
477                         int w, h;
478                 } mixerbar;             /* 3 */
479 #endif
480
481                 struct {
482                         int fd;
483                         int arg;
484                         char devtype[256];
485                         char type[64];
486                         float factor, offset;
487                 } sysfs;
488
489                 struct {
490                         struct text_object *next;
491                         char *s;
492                         int i;
493                         char *str;
494                 } ifblock;
495
496                 struct {
497                         int num;
498                         int type;
499                         int was_parsed;
500                         char *s;
501                 } top;
502
503                 struct {
504                         int wantedlines;
505                         char *logfile;
506                         char *buffer;
507                         int current_use;
508                         int max_uses;
509                 } headtail;
510
511                 struct {
512                         double last_update;
513                         float interval;
514                         char *cmd;
515                         char *buffer;
516                         double data;
517                 } execi;                /* 5 */
518
519                 struct {
520                         float interval;
521                         char *cmd;
522                         char *buffer;
523                         double data;
524                         timed_thread *p_timed_thread;
525                 } texeci;
526
527                 struct {
528                         int a, b;
529                 } pair;                 /* 2 */
530 #ifdef TCP_PORT_MONITOR
531                 struct tcp_port_monitor_data tcp_port_monitor;
532 #endif
533 #ifdef HDDTEMP
534                 struct {
535                         char *addr;
536                         int port;
537                         char *dev;
538                         double update_time;
539                         char *temp;
540                 } hddtemp;              /* 2 */
541 #endif
542 #ifdef EVE
543                 struct {
544                         char *apikey;
545                         char *charid;
546                         char *userid;
547                 } eve;
548 #endif
549 #ifdef HAVE_CURL
550                 struct {
551                         char *uri;
552                         float interval;
553                 } curl;
554 #endif
555 #ifdef RSS
556                 struct {
557                         char *uri;
558                         char *action;
559                         int act_par;
560                         float interval;
561                         unsigned int nrspaces;
562                 } rss;
563 #endif
564 #ifdef WEATHER
565                 struct {
566                         char *uri;
567                         char *data_type;
568                         int interval;
569                 } weather;
570 #endif
571 #ifdef XOAP
572                 struct {
573                         char *uri;
574                         unsigned int day;
575                         char *data_type;
576                         int interval;
577                 } weather_forecast;
578 #endif
579                 struct {
580                         char *text;
581                         unsigned int show;
582                         unsigned int step;
583                         unsigned int start;
584                         long resetcolor;
585                 } scroll;
586
587                 struct {
588                         char *left;
589                         char *seperation;
590                         char *right;
591                 } combine;
592
593                 struct {
594                         char *host;
595                         unsigned int port;
596                 } read_tcp;
597
598                 struct local_mail_s local_mail;
599 #ifdef NVIDIA
600                 struct nvidia_s nvidia;
601 #endif /* NVIDIA */
602
603         } data;
604         int type;
605         int a, b;
606         long line;
607         unsigned int c, d, e;
608         float f;
609         char char_a, char_b;
610 };
611
612 /* text object list helpers */
613 int append_object(struct text_object *root, struct text_object *obj);
614
615 /* ifblock helpers
616  *
617  * Opaque is a pointer to the address of the ifblock stack's top object.
618  * Calling clients should pass the address of a defined void pointer which
619  * was initialised to NULL (empty stack).
620  * */
621 int obj_be_ifblock_if(void **opaque, struct text_object *);
622 int obj_be_ifblock_else(void **opaque, struct text_object *);
623 int obj_be_ifblock_endif(void **opaque, struct text_object *);
624 int ifblock_stack_empty(void **opaque);
625
626 #endif /* _TEXT_OBJECT_H */