2
* Copyright 2007, Intel Corporation
4
* This file is part of PowerTOP
6
* This program file is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License
16
* along with this program in a file named COPYING; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
22
* Arjan van de Ven <arjan@linux.intel.com>
30
#include <sys/types.h>
38
suggestion_func *suggestion_activate;
43
struct suggestion *next;
51
suggestion_func *func;
55
static struct suggestion *suggestions;
56
static int total_weight;
58
static char previous[1024];
61
void reset_suggestions(void)
63
struct suggestion *ptr;
66
struct suggestion *next;
74
strcpy(status_bar_slots[8],"");
78
void reset_suggestions2(void)
81
suggestion_activate = NULL;
84
void add_suggestion(char *text, int weight, char key, char *keystring, suggestion_func *func)
86
struct suggestion *new;
91
new = malloc(sizeof(struct suggestion));
94
memset(new, 0, sizeof(struct suggestion));
95
new->string = strdup(text);
99
new->keystring = strdup(keystring);
100
new->next = suggestions;
103
total_weight += weight;
106
void pick_suggestion(void)
108
int value, running = 0;
109
struct suggestion *ptr;
112
strcpy(status_bar_slots[8],"");
113
suggestion_key = 255;
114
suggestion_activate = NULL;
116
if (total_weight==0 || suggestions==NULL) {
117
/* zero suggestions */
122
weight = total_weight;
123
if (strlen(previous) && displaytime > 0.0)
125
value = rand() % weight;
128
running += ptr->weight;
129
if (strcmp(ptr->string, previous)==0 && displaytime > 0.0)
131
if (running > value) {
133
strncpy(status_bar_slots[8],ptr->keystring, 40);
134
suggestion_key = ptr->key;
135
suggestion_activate = ptr->func;
136
show_suggestion(ptr->string);
137
if (strcmp(ptr->string, previous)) {
139
strcpy(previous, ptr->string);
146
memset(previous, 0, sizeof(previous));
150
void print_all_suggestions(void)
152
struct suggestion *ptr;
154
for (ptr = suggestions; ptr; ptr = ptr->next)
155
printf("\n%s\n", ptr->string);