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

others.c File Reference

#include <string.h>
#include <stdio.h>
#include "lininfo.h"
#include <sys/types.h>
#include <dirent.h>
#include <glib.h>
#include <pthread.h>
#include <gtk/gtk.h>

Go to the source code of this file.

Functions

void set_tooltiptext (GtkWidget *object, gchar *str)
char * trim (char *str)
char * rtrim (char *str)
int skip_lines (char *contents, int num_lines)
void find_data_for (char *pattern, char *member, const char *contents)
void lkmonitor_exit ()
 performs collector cancellation

Variables

pthread_t thread_id


Function Documentation

void find_data_for char *  pattern,
char *  member,
const char *  contents
 

Main parse function. This function actually parses the contents of procfs files and tokenize elements to offer clean data.

Parameters:
pattern sscanf pattern format to make parsing
member Field struct to fill with parsed data
contents Contents of the file to be analyzed

Definition at line 110 of file others.c.

References rtrim().

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 }                               

void lkmonitor_exit  ) 
 

performs collector cancellation

Stops collector thread and runs outside event loop

Definition at line 132 of file others.c.

References thread_id.

Referenced by on_fixed1_destroy(), on_quit1_activate(), and on_window1_destroy().

00133 {
00134         if(pthread_cancel(thread_id)!=0)
00135           g_warning("Can't cancel collector thread!");
00136         
00137         gtk_main_quit();
00138 }

char* rtrim char *  str  ) 
 

Deletes blanks from the end of string

Parameters:
str String to delete blanks from
Returns:
Trimed String

Definition at line 62 of file others.c.

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 }

void set_tooltiptext GtkWidget *  object,
gchar *  str
 

Definition at line 36 of file others.c.

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 }

int skip_lines char *  contents,
int  num_lines
 

Delete initial lines form string

Parameters:
contents String that contents text
num_lines Number of lines to leave out
Returns:
0 on success

Definition at line 86 of file others.c.

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 }

char* trim char *  str  ) 
 

Deletes blanks from the begining of string

Parameters:
str String to delete blanks from
Returns:
Trimed String

Definition at line 52 of file others.c.

00053 {
00054   return (str + strspn (str, " "));
00055 }                               


Variable Documentation

pthread_t thread_id
 

Definition at line 53 of file main.c.

Referenced by lkmonitor_exit(), and main().


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