-
-
Notifications
You must be signed in to change notification settings - Fork 623
/
core.cc
2132 lines (2067 loc) · 83.8 KB
/
core.cc
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* local headers */
#include "algebra.h"
#include "bsdapm.h"
#include "build.h"
#include "colours.h"
#include "combine.h"
#include "core.h"
#include "diskio.h"
#include "entropy.h"
#include "exec.h"
#include "i8k.h"
#include "misc.h"
#include "text_object.h"
#ifdef BUILD_IMLIB2
#include "imlib2.h"
#endif
#include "proc.h"
#ifdef BUILD_MYSQL
#include "mysql.h"
#endif
#ifdef BUILD_ICAL
#include "ical.h"
#endif
#ifdef BUILD_IRC
#include "irc.h"
#endif
#ifdef BUILD_X11
#include "fonts.h"
#endif
#include "fs.h"
#ifdef BUILD_IBM
#include "ibm.h"
#include "smapi.h"
#endif
#ifdef BUILD_ICONV
#include "iconv_tools.h"
#endif
#include "llua.h"
#include "logging.h"
#include "mail.h"
#include "mboxscan.h"
#include "mixer.h"
#include "nc.h"
#include "net_stat.h"
#ifdef BUILD_NVIDIA
#include "nvidia.h"
#endif
#include <inttypes.h>
#include "cpu.h"
#include "read_tcpip.h"
#include "scroll.h"
#include "specials.h"
#include "tailhead.h"
#include "temphelper.h"
#include "template.h"
#include "timeinfo.h"
#include "top.h"
#include "user.h"
#include "users.h"
#ifdef BUILD_CURL
#include "ccurl_thread.h"
#endif /* BUILD_CURL */
#ifdef BUILD_WEATHER_METAR
#include "weather.h"
#endif /* BUILD_WEATHER_METAR */
#ifdef BUILD_RSS
#include "rss.h"
#endif /* BUILD_RSS */
#ifdef BUILD_AUDACIOUS
#include "audacious.h"
#endif
#ifdef BUILD_CMUS
#include "cmus.h"
#endif
#ifdef BUILD_JOURNAL
#include "journal.h"
#endif
#ifdef BUILD_PULSEAUDIO
#include "pulseaudio.h"
#endif
/* check for OS and include appropriate headers */
#if defined(__linux__)
#include "linux.h"
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include "freebsd.h"
#elif defined(__DragonFly__)
#include "dragonfly.h"
#elif defined(__OpenBSD__)
#include "openbsd.h"
#elif defined(__APPLE__) && defined(__MACH__)
#include "darwin.h"
#endif
#include <cctype>
#include <cstring>
/* strip a leading /dev/ if any, following symlinks first
*
* BEWARE: this function returns a pointer to static content
* which gets overwritten in consecutive calls. I.e.:
* this function is NOT reentrant.
*/
const char *dev_name(const char *path) {
static char buf[PATH_MAX];
if (path == nullptr) { return nullptr; }
#define DEV_NAME(x) \
((x) != nullptr && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? (x) + 5 \
: (x))
if (realpath(path, buf) == nullptr) { return DEV_NAME(path); }
return DEV_NAME(buf);
#undef DEV_NAME
}
static struct text_object *new_text_object_internal() {
auto *obj = static_cast<text_object *>(malloc(sizeof(struct text_object)));
memset(obj, 0, sizeof(struct text_object));
return obj;
}
static struct text_object *create_plain_text(const char *s) {
struct text_object *obj;
if (s == nullptr || *s == '\0') { return nullptr; }
obj = new_text_object_internal();
obj_be_plain_text(obj, s);
return obj;
}
#ifdef BUILD_CURL
void stock_parse_arg(struct text_object *obj, const char *arg) {
char stock[8];
char data[16];
obj->data.s = nullptr;
if (sscanf(arg, "%7s %15s", stock, data) != 2) {
NORM_ERR("wrong number of arguments for $stock");
return;
}
if (!strcasecmp("ask", data))
strncpy(data, "a", 3);
else if (!strcasecmp("adv", data))
strncpy(data, "a2", 3);
else if (!strcasecmp("asksize", data))
strncpy(data, "a5", 3);
else if (!strcasecmp("bid", data))
strncpy(data, "b", 3);
else if (!strcasecmp("askrt", data))
strncpy(data, "b2", 3);
else if (!strcasecmp("bidrt", data))
strncpy(data, "b3", 3);
else if (!strcasecmp("bookvalue", data))
strncpy(data, "b4", 3);
else if (!strcasecmp("bidsize", data))
strncpy(data, "b6", 3);
else if (!strcasecmp("change", data))
strncpy(data, "c1", 3);
else if (!strcasecmp("commission", data))
strncpy(data, "c3", 3);
else if (!strcasecmp("changert", data))
strncpy(data, "c6", 3);
else if (!strcasecmp("ahcrt", data))
strncpy(data, "c8", 3);
else if (!strcasecmp("ds", data))
strncpy(data, "d", 3);
else if (!strcasecmp("ltd", data))
strncpy(data, "d1", 3);
else if (!strcasecmp("tradedate", data))
strncpy(data, "d2", 3);
else if (!strcasecmp("es", data))
strncpy(data, "e", 3);
else if (!strcasecmp("ei", data))
strncpy(data, "e1", 3);
else if (!strcasecmp("epsecy", data))
strncpy(data, "e7", 3);
else if (!strcasecmp("epseny", data))
strncpy(data, "e8", 3);
else if (!strcasecmp("epsenq", data))
strncpy(data, "e9", 3);
else if (!strcasecmp("floatshares", data))
strncpy(data, "f6", 3);
else if (!strcasecmp("dayslow", data))
strncpy(data, "g", 3);
else if (!strcasecmp("dayshigh", data))
strncpy(data, "h", 3);
else if (!strcasecmp("52weeklow", data))
strncpy(data, "j", 3);
else if (!strcasecmp("52weekhigh", data))
strncpy(data, "k", 3);
else if (!strcasecmp("hgp", data))
strncpy(data, "g1", 3);
else if (!strcasecmp("ag", data))
strncpy(data, "g3", 3);
else if (!strcasecmp("hg", data))
strncpy(data, "g4", 3);
else if (!strcasecmp("hgprt", data))
strncpy(data, "g5", 3);
else if (!strcasecmp("hgrt", data))
strncpy(data, "g6", 3);
else if (!strcasecmp("moreinfo", data))
strncpy(data, "i", 3);
else if (!strcasecmp("obrt", data))
strncpy(data, "i5", 3);
else if (!strcasecmp("mc", data))
strncpy(data, "j1", 3);
else if (!strcasecmp("mcrt", data))
strncpy(data, "j3", 3);
else if (!strcasecmp("ebitda", data))
strncpy(data, "j4", 3);
else if (!strcasecmp("c52wlow", data))
strncpy(data, "j5", 3);
else if (!strcasecmp("pc52wlow", data))
strncpy(data, "j6", 3);
else if (!strcasecmp("cprt", data))
strncpy(data, "k2", 3);
else if (!strcasecmp("lts", data))
strncpy(data, "k3", 3);
else if (!strcasecmp("c52whigh", data))
strncpy(data, "k4", 3);
else if (!strcasecmp("pc52whigh", data))
strncpy(data, "k5", 3);
else if (!strcasecmp("ltp", data))
strncpy(data, "l1", 3);
else if (!strcasecmp("hl", data))
strncpy(data, "l2", 3);
else if (!strcasecmp("ll", data))
strncpy(data, "l3", 3);
else if (!strcasecmp("dr", data))
strncpy(data, "m", 3);
else if (!strcasecmp("drrt", data))
strncpy(data, "m2", 3);
else if (!strcasecmp("50ma", data))
strncpy(data, "m3", 3);
else if (!strcasecmp("200ma", data))
strncpy(data, "m4", 3);
else if (!strcasecmp("c200ma", data))
strncpy(data, "m5", 3);
else if (!strcasecmp("pc200ma", data))
strncpy(data, "m6", 3);
else if (!strcasecmp("c50ma", data))
strncpy(data, "m7", 3);
else if (!strcasecmp("pc50ma", data))
strncpy(data, "m8", 3);
else if (!strcasecmp("name", data))
strncpy(data, "n", 3);
else if (!strcasecmp("notes", data))
strncpy(data, "n4", 3);
else if (!strcasecmp("open", data))
strncpy(data, "o", 3);
else if (!strcasecmp("pc", data))
strncpy(data, "p", 3);
else if (!strcasecmp("pricepaid", data))
strncpy(data, "p1", 3);
else if (!strcasecmp("cip", data))
strncpy(data, "p2", 3);
else if (!strcasecmp("ps", data))
strncpy(data, "p5", 3);
else if (!strcasecmp("pb", data))
strncpy(data, "p6", 3);
else if (!strcasecmp("edv", data))
strncpy(data, "q", 3);
else if (!strcasecmp("per", data))
strncpy(data, "r", 3);
else if (!strcasecmp("dpd", data))
strncpy(data, "r1", 3);
else if (!strcasecmp("perrt", data))
strncpy(data, "r2", 3);
else if (!strcasecmp("pegr", data))
strncpy(data, "r5", 3);
else if (!strcasecmp("pepsecy", data))
strncpy(data, "r6", 3);
else if (!strcasecmp("pepseny", data))
strncpy(data, "r7", 3);
else if (!strcasecmp("symbol", data))
strncpy(data, "s", 3);
else if (!strcasecmp("sharesowned", data))
strncpy(data, "s1", 3);
else if (!strcasecmp("shortratio", data))
strncpy(data, "s7", 3);
else if (!strcasecmp("ltt", data))
strncpy(data, "t1", 3);
else if (!strcasecmp("tradelinks", data))
strncpy(data, "t6", 3);
else if (!strcasecmp("tt", data))
strncpy(data, "t7", 3);
else if (!strcasecmp("1ytp", data))
strncpy(data, "t8", 3);
else if (!strcasecmp("volume", data))
strncpy(data, "v", 3);
else if (!strcasecmp("hv", data))
strncpy(data, "v1", 3);
else if (!strcasecmp("hvrt", data))
strncpy(data, "v7", 3);
else if (!strcasecmp("52weekrange", data))
strncpy(data, "w", 3);
else if (!strcasecmp("dvc", data))
strncpy(data, "w1", 3);
else if (!strcasecmp("dvcrt", data))
strncpy(data, "w4", 3);
else if (!strcasecmp("se", data))
strncpy(data, "x", 3);
else if (!strcasecmp("dy", data))
strncpy(data, "y", 3);
else {
NORM_ERR(
"\"%s\" is not supported by $stock. Supported: 1ytp, 200ma, 50ma, "
"52weeklow, 52weekhigh, 52weekrange, adv, ag, ahcrt, ask, askrt, "
"asksize, bid, bidrt, bidsize, bookvalue, c200ma, c50ma, c52whigh, "
"c52wlow, change, changert, cip, commission, cprt, dayshigh, dayslow, "
"dpd, dr, drrt, ds, dvc, dvcrt, dy, ebitda, edv, ei, epsecy, epsenq, "
"epseny, es, floatshares, hg, hgp, hgprt, hl, hv, hvrt, ll, ltd, ltp, "
"lts, ltt, mc, mcrt, moreinfo, name, notes, obrt, open, pb, pc, "
"pc200ma, pc50ma, pc52whigh, pc52wlow, pegr, pepsecy, pepseny, per, "
"perrt, pricepaid, ps, se, sharesowned, shortratio, symbol, tradedate, "
"tradelinks, tt, volume",
data);
return;
}
#define MAX_FINYAH_URL_LENGTH 64
obj->data.s = (char *)malloc(MAX_FINYAH_URL_LENGTH);
snprintf(obj->data.s, MAX_FINYAH_URL_LENGTH,
"http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=%s", stock,
data);
}
#endif /* BUILD_CURL */
legacy_cb_handle *create_cb_handle(int (*fn)()) {
if (fn != nullptr) {
return new legacy_cb_handle(conky::register_cb<legacy_cb>(1, fn));
}
{ return nullptr; }
}
/* construct_text_object() creates a new text_object */
struct text_object *construct_text_object(char *s, const char *arg, long line,
void **ifblock_opaque,
void *free_at_crash) {
// struct text_object *obj = new_text_object();
struct text_object *obj = new_text_object_internal();
obj->line = line;
/* helper defines for internal use only */
#define __OBJ_HEAD(a, n) \
if (!strcmp(s, #a)) { \
obj->cb_handle = create_cb_handle(n);
#define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
#define __OBJ_ARG(...) \
if (!arg) { \
free(s); \
CRIT_ERR(obj, free_at_crash, __VA_ARGS__); \
}
/* defines to be used below */
#define OBJ(a, n) __OBJ_HEAD(a, n) {
#define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
#define OBJ_IF(a, n) \
__OBJ_HEAD(a, n) __OBJ_IF; \
{
#define OBJ_IF_ARG(a, n, ...) \
__OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; \
{
#define END \
} \
} \
else
#ifdef BUILD_X11
if (s[0] == '#') {
obj->data.l = get_x11_color(s);
obj->callbacks.print = &new_fg;
} else
#endif /* BUILD_X11 */
#ifndef __OpenBSD__
OBJ(acpitemp, nullptr)
obj->data.i = open_acpi_temperature(arg);
obj->callbacks.print = &print_acpitemp;
obj->callbacks.free = &free_acpitemp;
END OBJ(acpiacadapter, nullptr) if (arg != nullptr) {
#ifdef __linux__
if (strpbrk(arg, "/.") != nullptr) {
/*
* a bit of paranoia. screen out funky paths
* i hope no device will have a '.' in its name
*/
NORM_ERR("acpiacadapter: arg must not contain '/' or '.'");
} else
obj->data.opaque = strdup(arg);
#else
NORM_ERR("acpiacadapter: arg is only used on linux");
#endif
}
obj->callbacks.print = &print_acpiacadapter;
obj->callbacks.free = &gen_free_opaque;
#endif /* !__OpenBSD__ */
END OBJ(freq, nullptr) get_cpu_count();
if ((arg == nullptr) || (isdigit((unsigned char)arg[0]) == 0) ||
strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
"Displaying the clock for CPU 1."); */
} else {
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_freq;
END OBJ(freq_g, nullptr) get_cpu_count();
if ((arg == nullptr) || (isdigit((unsigned char)arg[0]) == 0) ||
strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
"CPUs! Displaying the clock for CPU 1."); */
} else {
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_freq_g;
END OBJ_ARG(read_tcp, nullptr,
"read_tcp: Needs \"(host) port\" as argument(s)")
parse_read_tcpip_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_read_tcp;
obj->callbacks.free = &free_read_tcpip;
END OBJ_ARG(read_udp, nullptr,
"read_udp: Needs \"(host) port\" as argument(s)")
parse_read_tcpip_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_read_udp;
obj->callbacks.free = &free_read_tcpip;
END OBJ_ARG(tcp_ping, nullptr,
"tcp_ping: Needs \"host (port)\" as argument(s)")
parse_tcp_ping_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_tcp_ping;
obj->callbacks.free = &free_tcp_ping;
#if defined(__linux__)
END OBJ(voltage_mv, 0) get_cpu_count();
if (!arg || !isdigit((unsigned char)arg[0]) || strlen(arg) >= 3 ||
atoi(&arg[0]) == 0 || atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */
} else {
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_voltage_mv;
END OBJ(voltage_v, 0) get_cpu_count();
if (!arg || !isdigit((unsigned char)arg[0]) || strlen(arg) >= 3 ||
atoi(&arg[0]) == 0 || atoi(&arg[0]) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */
} else {
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_voltage_v;
#ifdef BUILD_WLAN
END OBJ(wireless_essid, &update_net_stats) obj->data.opaque =
get_net_stat(arg, obj, free_at_crash);
obj->callbacks.print = &print_wireless_essid;
END OBJ(wireless_channel, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_channel;
END OBJ(wireless_freq, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_frequency;
END OBJ(wireless_mode, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_mode;
END OBJ(wireless_bitrate, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_bitrate;
END OBJ(wireless_ap, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_ap;
END OBJ(wireless_link_qual, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_link_qual;
END OBJ(wireless_link_qual_max, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_link_qual_max;
END OBJ(wireless_link_qual_perc, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_wireless_link_qual_perc;
END OBJ(wireless_link_bar, &update_net_stats)
parse_net_stat_bar_arg(obj, arg, free_at_crash);
obj->callbacks.barval = &wireless_link_barval;
#endif /* BUILD_WLAN */
#endif /* __linux__ */
#ifndef __OpenBSD__
END OBJ(acpifan, nullptr) obj->callbacks.print = &print_acpifan;
END OBJ(battery, nullptr) char bat[64];
if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strncpy(bat, "BAT0", 5);
}
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery;
obj->callbacks.free = &gen_free_opaque;
END OBJ(battery_short, nullptr) char bat[64];
if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strncpy(bat, "BAT0", 5);
}
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery_short;
obj->callbacks.free = &gen_free_opaque;
END OBJ(battery_time, nullptr) char bat[64];
if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strncpy(bat, "BAT0", 5);
}
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery_time;
obj->callbacks.free = &gen_free_opaque;
END OBJ(battery_percent, nullptr) char bat[64];
if (arg != nullptr) {
sscanf(arg, "%63s", bat);
} else {
strncpy(bat, "BAT0", 5);
}
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.percentage = &battery_percentage;
obj->callbacks.free = &gen_free_opaque;
END OBJ(battery_bar, nullptr) char bat[64];
arg = scan_bar(obj, arg, 100);
if ((arg != nullptr) && strlen(arg) > 0) {
sscanf(arg, "%63s", bat);
} else {
strncpy(bat, "BAT0", 5);
}
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.barval = &get_battery_perct_bar;
obj->callbacks.free = &gen_free_opaque;
#endif /* !__OpenBSD__ */
#if defined(__linux__)
END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument") obj->data.s =
strndup(dev_name(arg), text_buffer_size.get(*state));
obj->callbacks.print = &print_disk_protect_queue;
obj->callbacks.free = &gen_free_opaque;
END OBJ(i8k_version, &update_i8k) obj->callbacks.print = &print_i8k_version;
END OBJ(i8k_bios, &update_i8k) obj->callbacks.print = &print_i8k_bios;
END OBJ(i8k_serial, &update_i8k) obj->callbacks.print = &print_i8k_serial;
END OBJ(i8k_cpu_temp, &update_i8k) obj->callbacks.print = &print_i8k_cpu_temp;
END OBJ(i8k_left_fan_status, &update_i8k) obj->callbacks.print =
&print_i8k_left_fan_status;
END OBJ(i8k_right_fan_status, &update_i8k) obj->callbacks.print =
&print_i8k_right_fan_status;
END OBJ(i8k_left_fan_rpm, &update_i8k) obj->callbacks.print =
&print_i8k_left_fan_rpm;
END OBJ(i8k_right_fan_rpm, &update_i8k) obj->callbacks.print =
&print_i8k_right_fan_rpm;
END OBJ(i8k_ac_status, &update_i8k) obj->callbacks.print =
&print_i8k_ac_status;
END OBJ(i8k_buttons_status, &update_i8k) obj->callbacks.print =
&print_i8k_buttons_status;
#if defined(BUILD_IBM)
END OBJ(ibm_fan, 0) obj->callbacks.print = &get_ibm_acpi_fan;
END OBJ_ARG(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
parse_ibm_temps_arg(obj, arg);
obj->callbacks.print = &print_ibm_temps;
END OBJ(ibm_volume, 0) obj->callbacks.print = &get_ibm_acpi_volume;
END OBJ(ibm_brightness, 0) obj->callbacks.print = &get_ibm_acpi_brightness;
END OBJ(ibm_thinklight, 0) obj->callbacks.print = &get_ibm_acpi_thinklight;
#endif
/* information from sony_laptop kernel module
* /sys/devices/platform/sony-laptop */
END OBJ(sony_fanspeed, 0) obj->callbacks.print = &get_sony_fanspeed;
END OBJ_IF(if_gw, &update_gateway_info) obj->callbacks.iftest =
&gateway_exists;
obj->callbacks.free = &free_gateway_info;
END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
obj->data.s = strndup(dev_name(arg), text_buffer_size.get(*state));
obj->callbacks.print = &print_ioscheduler;
obj->callbacks.free = &gen_free_opaque;
END OBJ(laptop_mode, 0) obj->callbacks.print = &print_laptop_mode;
END OBJ_ARG(
pb_battery, 0,
"pb_battery: needs one argument: status, percent or time") if (strcmp(arg,
"st"
"at"
"u"
"s") ==
EQUAL) {
obj->data.i = PB_BATT_STATUS;
}
else if (strcmp(arg, "percent") == EQUAL) {
obj->data.i = PB_BATT_PERCENT;
}
else if (strcmp(arg, "time") == EQUAL) {
obj->data.i = PB_BATT_TIME;
}
else {
NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
obj->data.i = PB_BATT_STATUS;
}
obj->callbacks.print = get_powerbook_batt_info;
#endif /* __linux__ */
#if (defined(__FreeBSD__) || defined(__linux__) || defined(__DragonFly__) || \
(defined(__APPLE__) && defined(__MACH__)))
END OBJ_IF_ARG(if_up, nullptr, "if_up needs an argument")
parse_if_up_arg(obj, arg);
obj->callbacks.iftest = &interface_up;
obj->callbacks.free = &free_if_up;
#endif
#if defined(__OpenBSD__)
END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
parse_obsd_sensor(obj, arg);
obj->callbacks.print = &print_obsd_sensors_temp;
END OBJ_ARG(obsd_sensors_fan, 0,
"obsd_sensors_fan: needs 2 arguments (device and sensor number)")
parse_obsd_sensor(obj, arg);
obj->callbacks.print = &print_obsd_sensors_fan;
END OBJ_ARG(obsd_sensors_volt, 0,
"obsd_sensors_volt: needs 2 arguments (device and sensor number)")
parse_obsd_sensor(obj, arg);
obj->callbacks.print = &print_obsd_sensors_volt;
END OBJ(obsd_vendor, 0) obj->callbacks.print = &get_obsd_vendor;
END OBJ(obsd_product, 0) obj->callbacks.print = &get_obsd_product;
#endif /* __OpenBSD__ */
END OBJ(buffers, &update_meminfo) obj->callbacks.print = &print_buffers;
END OBJ(cached, &update_meminfo) obj->callbacks.print = &print_cached;
#define SCAN_CPU(__arg, __var) \
{ \
int __offset = 0; \
if ((__arg) && sscanf(__arg, " cpu%d %n", &(__var), &__offset) > 0) \
(__arg) += __offset; \
else \
(__var) = 0; \
}
END OBJ(cpu, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
obj->callbacks.percentage = &cpu_percentage;
DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugauge, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_gauge(obj, arg, 1);
obj->callbacks.gaugeval = &cpu_barval;
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif
END OBJ(cpubar, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_bar(obj, arg, 1);
obj->callbacks.barval = &cpu_barval;
DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
char *buf = nullptr;
SCAN_CPU(arg, obj->data.i);
buf = scan_graph(obj, arg, 1);
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
free_and_zero(buf);
obj->callbacks.graphval = &cpu_barval;
END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg);
obj->callbacks.graphval = &loadgraphval;
#endif /* BUILD_X11 */
END OBJ(diskio, &update_diskio) parse_diskio_arg(obj, arg);
obj->callbacks.print = &print_diskio;
END OBJ(diskio_read, &update_diskio) parse_diskio_arg(obj, arg);
obj->callbacks.print = &print_diskio_read;
END OBJ(diskio_write, &update_diskio) parse_diskio_arg(obj, arg);
obj->callbacks.print = &print_diskio_write;
#ifdef BUILD_X11
END OBJ(diskiograph, &update_diskio) parse_diskiograph_arg(obj, arg);
obj->callbacks.graphval = &diskiographval;
END OBJ(diskiograph_read, &update_diskio) parse_diskiograph_arg(obj, arg);
obj->callbacks.graphval = &diskiographval_read;
END OBJ(diskiograph_write, &update_diskio) parse_diskiograph_arg(obj, arg);
obj->callbacks.graphval = &diskiographval_write;
#endif /* BUILD_X11 */
END OBJ(color, nullptr)
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
obj->data.l =
arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
set_current_text_color(obj->data.l);
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state)) {
obj->data.l = COLOR_WHITE;
if (arg != nullptr) {
if (strcasecmp(arg, "red") == 0) {
obj->data.l = COLOR_RED;
} else if (strcasecmp(arg, "green") == 0) {
obj->data.l = COLOR_GREEN;
} else if (strcasecmp(arg, "yellow") == 0) {
obj->data.l = COLOR_YELLOW;
} else if (strcasecmp(arg, "blue") == 0) {
obj->data.l = COLOR_BLUE;
} else if (strcasecmp(arg, "magenta") == 0) {
obj->data.l = COLOR_MAGENTA;
} else if (strcasecmp(arg, "cyan") == 0) {
obj->data.l = COLOR_CYAN;
} else if (strcasecmp(arg, "black") == 0) {
obj->data.l = COLOR_BLACK;
}
}
set_current_text_color(obj->data.l);
init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
}
#endif /* BUILD_NCURSES */
obj->callbacks.print = &new_fg;
#ifdef BUILD_X11
END OBJ(color0, nullptr) obj->data.l = color[0].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color1, nullptr) obj->data.l = color[1].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color2, nullptr) obj->data.l = color[2].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color3, nullptr) obj->data.l = color[3].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color4, nullptr) obj->data.l = color[4].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color5, nullptr) obj->data.l = color[5].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color6, nullptr) obj->data.l = color[6].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color7, nullptr) obj->data.l = color[7].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color8, nullptr) obj->data.l = color[8].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(color9, nullptr) obj->data.l = color[9].get(*state);
set_current_text_color(obj->data.l);
obj->callbacks.print = &new_fg;
END OBJ(font, nullptr) scan_font(obj, arg);
obj->callbacks.print = &new_font;
obj->callbacks.free = &gen_free_opaque;
#endif /* BUILD_X11 */
END OBJ(conky_version, nullptr) obj_be_plain_text(obj, VERSION);
END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE);
END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH);
END OBJ(downspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_downspeed;
END OBJ(downspeedf, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_downspeedf;
#ifdef BUILD_X11
END OBJ(downspeedgraph, &update_net_stats)
parse_net_stat_graph_arg(obj, arg, free_at_crash);
obj->callbacks.graphval = &downspeedgraphval;
#endif /* BUILD_X11 */
END OBJ(else, nullptr) obj_be_ifblock_else(ifblock_opaque, obj);
obj->callbacks.iftest = &gen_false_iftest;
END OBJ(endif, nullptr) obj_be_ifblock_endif(ifblock_opaque, obj);
obj->callbacks.print = &gen_print_nothing;
END OBJ(eval, nullptr) obj->data.s =
strndup(arg != nullptr ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_evaluate;
obj->callbacks.free = &gen_free_opaque;
#if defined(BUILD_IMLIB2) && defined(BUILD_X11)
END OBJ(image, nullptr) obj->data.s =
strndup(arg != nullptr ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_image_callback;
obj->callbacks.free = &gen_free_opaque;
#endif /* BUILD_IMLIB2 */
#ifdef BUILD_MYSQL
END OBJ_ARG(mysql, 0, "mysql needs a query") obj->data.s = strdup(arg);
obj->callbacks.print = &print_mysql;
#endif /* BUILD_MYSQL */
END OBJ_ARG(no_update, nullptr, "no_update needs arguments")
scan_no_update(obj, arg);
obj->callbacks.print = &print_no_update;
obj->callbacks.free = &free_no_update;
END OBJ(cat, 0) obj->data.s =
strndup(arg ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_cat;
obj->callbacks.free = &gen_free_opaque;
#ifdef BUILD_X11
END OBJ(num_led, 0) obj->callbacks.print = &print_num_led;
END OBJ(caps_led, 0) obj->callbacks.print = &print_caps_led;
END OBJ(scroll_led, 0) obj->callbacks.print = &print_scroll_led;
END OBJ(kb_layout, 0) obj->callbacks.print = &print_kb_layout;
END OBJ(mouse_speed, 0) obj->callbacks.print = &print_mouse_speed;
#endif /* BUILD_X11 */
END OBJ(password, 0) obj->data.s =
strndup(arg ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_password;
obj->callbacks.free = &gen_free_opaque;
#ifdef __x86_64__
END OBJ(freq2, 0) obj->callbacks.print = &print_freq2;
#endif /* __x86_64__ */
END OBJ(cap, 0) obj->data.s =
strndup(arg ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_cap;
obj->callbacks.free = &gen_free_opaque;
END OBJ(catp, 0) obj->data.s =
strndup(arg ? arg : "", text_buffer_size.get(*state));
obj->callbacks.print = &print_catp;
obj->callbacks.free = &gen_free_opaque;
END OBJ_ARG(exec, nullptr, "exec needs arguments: <command>")
scan_exec_arg(obj, arg, EF_EXEC);
obj->parse = false;
obj->thread = false;
register_exec(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_exec;
END OBJ_ARG(execi, nullptr, "execi needs arguments: <interval> <command>")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = false;
obj->thread = false;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
END OBJ_ARG(execp, nullptr, "execp needs arguments: <command>")
scan_exec_arg(obj, arg, EF_EXEC);
obj->parse = true;
obj->thread = false;
register_exec(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_exec;
END OBJ_ARG(execpi, nullptr, "execpi needs arguments: <interval> <command>")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = true;
obj->thread = false;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
END OBJ_ARG(execbar, nullptr,
"execbar needs arguments: [height],[width] <command>")
scan_exec_arg(obj, arg, EF_EXEC | EF_BAR);
register_exec(obj);
obj->callbacks.barval = &execbarval;
obj->callbacks.free = &free_exec;
END OBJ_ARG(execibar, nullptr,
"execibar needs arguments: <interval> [height],[width] <command>")
scan_exec_arg(obj, arg, EF_EXECI | EF_BAR);
register_execi(obj);
obj->callbacks.barval = &execbarval;
obj->callbacks.free = &free_execi;
#ifdef BUILD_X11
END OBJ_ARG(execgauge, nullptr,
"execgauge needs arguments: [height],[width] <command>")
scan_exec_arg(obj, arg, EF_EXEC | EF_GAUGE);
register_exec(obj);
obj->callbacks.gaugeval = &execbarval;
obj->callbacks.free = &free_exec;
END OBJ_ARG(
execigauge, nullptr,
"execigauge needs arguments: <interval> [height],[width] <command>")
scan_exec_arg(obj, arg, EF_EXECI | EF_GAUGE);
register_execi(obj);
obj->callbacks.gaugeval = &execbarval;
obj->callbacks.free = &free_execi;
END OBJ_ARG(execgraph, nullptr,
"execgraph needs arguments: <command> [height],[width] [color1] "
"[color2] [scale] [-t|-l]")
scan_exec_arg(obj, arg, EF_EXEC | EF_GRAPH);
register_exec(obj);
obj->callbacks.graphval = &execbarval;
obj->callbacks.free = &free_exec;
END OBJ_ARG(execigraph, nullptr,
"execigraph needs arguments: <interval> <command> "
"[height],[width] [color1] [color2] [scale] [-t|-l]")
scan_exec_arg(obj, arg, EF_EXECI | EF_GRAPH);
register_execi(obj);
obj->callbacks.graphval = &execbarval;
obj->callbacks.free = &free_execi;
#endif /* BUILD_X11 */
END OBJ_ARG(texeci, nullptr, "texeci needs arguments: <interval> <command>")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = false;
obj->thread = true;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
END OBJ_ARG(texecpi, nullptr, "texecpi needs arguments: <interval> <command>")
scan_exec_arg(obj, arg, EF_EXECI);
obj->parse = true;
obj->thread = true;
register_execi(obj);
obj->callbacks.print = &print_exec;
obj->callbacks.free = &free_execi;
END OBJ(fs_bar, &update_fs_stats) init_fs_bar(obj, arg);
obj->callbacks.barval = &fs_barval;
END OBJ(fs_bar_free, &update_fs_stats) init_fs_bar(obj, arg);
obj->callbacks.barval = &fs_free_barval;
END OBJ(fs_free, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_free;
END OBJ(fs_used_perc, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.percentage = &fs_used_percentage;
END OBJ(fs_free_perc, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.percentage = &fs_free_percentage;
END OBJ(fs_size, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_size;
END OBJ(fs_type, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_type;
END OBJ(fs_used, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_used;
#ifdef BUILD_X11
END OBJ(hr, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_hr;
#endif /* BUILD_X11 */
END OBJ(nameserver, &update_dns_data) parse_nameserver_arg(obj, arg);
obj->callbacks.print = &print_nameserver;
obj->callbacks.free = &free_dns_data;
END OBJ(offset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_offset;
END OBJ(voffset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
obj->callbacks.print = &new_voffset;
END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l = atoi(arg);
obj->callbacks.print = &new_goto;
#ifdef BUILD_X11
END OBJ(tab, nullptr) scan_tab(obj, arg);
obj->callbacks.print = &new_tab;
#endif /* BUILD_X11 */
#ifdef __linux__
END OBJ_ARG(i2c, 0, "i2c needs arguments") parse_i2c_sensor(obj, arg);
obj->callbacks.print = &print_sysfs_sensor;
obj->callbacks.free = &free_sysfs_sensor;
END OBJ_ARG(platform, 0, "platform needs arguments")
parse_platform_sensor(obj, arg);
obj->callbacks.print = &print_sysfs_sensor;
obj->callbacks.free = &free_sysfs_sensor;
END OBJ_ARG(hwmon, 0, "hwmon needs argumanets") parse_hwmon_sensor(obj, arg);
obj->callbacks.print = &print_sysfs_sensor;
obj->callbacks.free = &free_sysfs_sensor;
#endif /* __linux__ */
END
/* we have four different types of top (top, top_mem, top_time and
* top_io). To avoid having almost-same code four times, we have this
* special handler. */
/* XXX: maybe fiddle them apart later, as print_top() does
* nothing else than just that, using an ugly switch(). */
if (strncmp(s, "top", 3) == EQUAL) {
if (parse_top_args(s, arg, obj) != 0) {
#ifdef __linux__
determine_longstat_file();
#endif
obj->cb_handle = create_cb_handle(update_top);
} else {
free(obj);
return nullptr;
}
}
else OBJ(addr, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_addr;
END
#ifdef __linux__
OBJ(addrs, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_addrs;
#ifdef BUILD_IPV6