Main Page | Data Structures | File List | Data Fields | Globals

others.c

Go to the documentation of this file.
00001 /*
00002 lkmonitor (Linux Kernel Monitor)
00003 
00004 Application for monitoring and tuning a Linux kernel.
00005 
00006 Copyright (C) 2005,2006  Fernando ApesteguĂ­a
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 
00023 #include <string.h>
00024 #include <stdio.h>
00025 #include "lininfo.h"
00026 #include <sys/types.h>
00027 #include <dirent.h>
00028 
00029 #include <glib.h>
00030 #include <pthread.h>
00031 #include <gtk/gtk.h>
00032 
00033 extern pthread_t thread_id;//Id of collector thread.
00034 
00035 
00036 void set_tooltiptext(GtkWidget *object,gchar *str)
00037 {
00038         g_assert(object!=NULL && str!=NULL);
00039         
00040         GtkTooltips *gtt;
00041         
00042         gtt=gtk_tooltips_new();
00043         gtk_tooltips_set_tip(gtt,object,str,NULL);
00044         
00045 }
00046 
00051 char *
00052 trim (char *str)
00053 {
00054   return (str + strspn (str, " "));
00055 }                               
00056 
00061 char *
00062 rtrim(char* str)
00063 {
00064         g_assert(str!=NULL);
00065         
00066         char* p;
00067         if((p=rindex(str,' '))==NULL)
00068                 return(str);
00069         while(p>str){
00070                 if(*p==' '){
00071                         *p='\0';
00072                         p--;
00073                 }
00074                 else return(str);
00075         }
00076         return(str);//For gcc warning   
00077 }
00078 
00079 
00085 int
00086 skip_lines (char* contents, int num_lines)
00087 {
00088   g_assert(contents!=NULL && num_lines>=0);
00089         
00090   int i, c;
00091 
00092   for (i = 0; i < num_lines; c++)
00093     if (*contents=='\n'){
00094       i++;
00095         }else{
00096        contents++;
00097         }
00098 
00099   return (0);
00100 }
00101 
00109 void
00110 find_data_for (char* pattern,char* member, const char* contents)
00111 {       
00112 
00113         g_assert(pattern!=NULL && member!=NULL && contents!=NULL);
00114         
00115         char p[25];
00116         char* line;
00117         
00118         sscanf(pattern,"%[^\t:]",p);
00119         //p has the name of the attribute (model, model name...)
00120         strcpy(p,rtrim(p));
00121         if((line=strstr(contents,p))==NULL){
00122                 strcpy(member,"Unknown");
00123                 return;
00124         }//Position in the correct line
00125         
00126         sscanf(line, pattern,member);
00127         
00128 }                               
00129 
00132 void lkmonitor_exit()
00133 {
00134         if(pthread_cancel(thread_id)!=0)
00135           g_warning("Can't cancel collector thread!");
00136         
00137         gtk_main_quit();
00138 }

Generated on Wed Feb 15 11:24:01 2006 for lkmonitor by  doxygen 1.3.9.1