1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
15 * All rights reserved.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #include "text_object.h"
34 void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_crash)
37 unsigned int indenting = 0; //vars can be used as args for other vars
40 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
42 for (i=0; arg[i] != 0 && j < 2; i++) {
43 if(startvar[j] == -1) {
47 }else if(endvar[j] == -1) {
50 }else if(arg[i] == '}') {
53 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
59 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
60 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
61 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
62 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
64 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
65 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
67 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
68 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
70 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
71 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
73 obj->sub = malloc(sizeof(struct text_object));
74 extract_variable_text_internal(obj->sub, obj->data.combine.left);
75 obj->sub->sub = malloc(sizeof(struct text_object));
76 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
78 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
82 void print_combine(struct text_object *obj, char *p, struct information *cur)
84 char buf[2][max_user_text];
93 struct llrows *ll_rows[2], *current[2];
94 struct text_object * objsub = obj->sub;
103 ll_rows[i] = malloc(sizeof(struct llrows));
104 current[i] = ll_rows[i];
105 for(j=0; j<i; j++) objsub = objsub->sub;
106 generate_text_internal(buf[i], max_user_text, *objsub, cur);
107 for(j=0; buf[i][j] != 0; j++) {
108 if(buf[i][j] == '\t') buf[i][j] = ' ';
109 if(buf[i][j] == '\n') {
111 current[i]->row = strdup(buf[i]+nextstart);
112 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
113 current[i]->next = malloc(sizeof(struct llrows));
114 current[i] = current[i]->next;
119 current[i]->row = strdup(buf[i]+nextstart);
120 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
121 current[i]->next = NULL;
122 current[i] = ll_rows[i];
124 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
126 strcat(p, current[0]->row);
127 i=strlen(current[0]->row);
134 strcat(p, obj->data.combine.seperation);
135 strcat(p, current[1]->row);
139 #pragma omp parallel for schedule(dynamic,10)
140 #endif /* HAVE_OPENMP */
141 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
144 #pragma omp parallel for schedule(dynamic,10)
145 #endif /* HAVE_OPENMP */
147 while(ll_rows[i] != NULL) {
148 current[i]=ll_rows[i];
149 free(current[i]->row);
150 ll_rows[i]=current[i]->next;
156 void free_combine(struct text_object *obj)
158 free(obj->data.combine.left);
159 free(obj->data.combine.seperation);
160 free(obj->data.combine.right);
161 free_text_objects(obj->sub, 1);