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-2010 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"
40 void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_crash)
42 struct combine_data *cd;
44 unsigned int indenting = 0; //vars can be used as args for other vars
47 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
49 for (i=0; arg[i] != 0 && j < 2; i++) {
50 if(startvar[j] == -1) {
54 }else if(endvar[j] == -1) {
57 }else if(arg[i] == '}') {
60 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
66 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
67 cd = malloc(sizeof(struct combine_data));
68 memset(cd, 0, sizeof(struct combine_data));
70 cd->left = malloc(endvar[0]-startvar[0] + 1);
71 cd->seperation = malloc(startvar[1] - endvar[0] + 1);
72 cd->right= malloc(endvar[1]-startvar[1] + 1);
74 strncpy(cd->left, arg + startvar[0], endvar[0] - startvar[0]);
75 cd->left[endvar[0] - startvar[0]] = 0;
77 strncpy(cd->seperation, arg + endvar[0], startvar[1] - endvar[0]);
78 cd->seperation[startvar[1] - endvar[0]] = 0;
80 strncpy(cd->right, arg + startvar[1], endvar[1] - startvar[1]);
81 cd->right[endvar[1] - startvar[1]] = 0;
83 obj->sub = malloc(sizeof(struct text_object));
84 extract_variable_text_internal(obj->sub, cd->left);
85 obj->sub->sub = malloc(sizeof(struct text_object));
86 extract_variable_text_internal(obj->sub->sub, cd->right);
87 obj->data.opaque = cd;
89 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
93 void print_combine(struct text_object *obj, char *p, struct information *cur)
95 struct combine_data *cd = obj->data.opaque;
96 char buf[2][max_user_text];
105 struct llrows *ll_rows[2], *current[2];
106 struct text_object * objsub = obj->sub;
115 ll_rows[i] = malloc(sizeof(struct llrows));
116 current[i] = ll_rows[i];
117 for(j=0; j<i; j++) objsub = objsub->sub;
118 generate_text_internal(buf[i], max_user_text, *objsub, cur);
119 for(j=0; buf[i][j] != 0; j++) {
120 if(buf[i][j] == '\t') buf[i][j] = ' ';
121 if(buf[i][j] == '\n') {
123 current[i]->row = strdup(buf[i]+nextstart);
124 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
125 current[i]->next = malloc(sizeof(struct llrows));
126 current[i] = current[i]->next;
131 current[i]->row = strdup(buf[i]+nextstart);
132 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
133 current[i]->next = NULL;
134 current[i] = ll_rows[i];
136 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
138 strcat(p, current[0]->row);
139 i=strlen(current[0]->row);
146 strcat(p, cd->seperation);
147 strcat(p, current[1]->row);
151 #pragma omp parallel for schedule(dynamic,10)
152 #endif /* HAVE_OPENMP */
153 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
156 #pragma omp parallel for schedule(dynamic,10)
157 #endif /* HAVE_OPENMP */
159 while(ll_rows[i] != NULL) {
160 current[i]=ll_rows[i];
161 free(current[i]->row);
162 ll_rows[i]=current[i]->next;
168 void free_combine(struct text_object *obj)
170 struct combine_data *cd = obj->data.opaque;
175 free(cd->seperation);
177 free_text_objects(obj->sub, 1);
179 free(obj->data.opaque);
180 obj->data.opaque = NULL;