function_mem include gtk gtk include stdio include stdlib include stri

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
/* function_mem.c */
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINE_APPEARANCE "../ramdisk/line_status/"
typedef struct
{
FILE * file_pointer;
gchar file_buffer[255];
gchar file_line_array[1000][256];
gshort file_line_counter;
}var_struct;
var_struct * func_var;
void thread_function();
void read_file_function();
int main()
{
GThread *Thread1;
GError *err1 = NULL ;
func_var = g_slice_new (var_struct);
if( !g_thread_supported() )
{
g_thread_init(NULL);
gdk_threads_init(); // Called to initialize internal mutex "gdk_threads_mutex".
printf("g_thread supported\n");
}
else
{
printf("g_thread NOT supported\n");
}
if( (Thread1 = g_thread_create((GThreadFunc)thread_function, NULL, FALSE, &err1)) == NULL)
{
printf("Thread create failed: %s!!\n", err1->message );
g_error_free ( err1 ) ;
}
gdk_threads_enter();
gtk_main ();
gdk_threads_leave();
g_slice_free (var_struct, func_var);
return 0;
}
void thread_function()
{
for(;;)
{
g_usleep(1000000);
gdk_threads_enter();
read_file_function();
gdk_threads_leave();
}
}
void read_file_function()
{
func_var->file_pointer=fopen("line_appearance.txt","r");
if(func_var->file_pointer==NULL)
{
g_print(" WARN:LNAPP: line_appearance.txt file not found \n"); // if could not be opened the the defuault result is NULL
}
else
{
func_var->file_line_counter = 0;
while(fgets(func_var->file_buffer, 255, func_var->file_pointer)!=NULL)
{
// array length exceeded, too many lines in line_appearance.txt file
if( func_var->file_line_counter > 1000)
{
break;
}
strcpy(func_var->file_line_array[func_var->file_line_counter],func_var->file_buffer);
func_var->file_line_counter++;
}
fclose(func_var->file_pointer);
}
gchar **CID=NULL;
for(func_var->file_line_counter = 0 ; func_var->file_line_counter < 1000 ; func_var->file_line_counter ++)
{
CID=g_strsplit_set(func_var->file_line_array[func_var->file_line_counter],"_", -1);
if(g_strv_length(CID)>3)
{
printf("<%s><%s>", CID[1] ,CID[2]);
}
}
printf("\n");
g_strfreev(CID);
}