All pastes #10038 Raw Edit

Stuff

public c v1 · immutable
#10038 ·published 2005-04-21 20:49 UTC
rendered paste body
/* Standard headers */#define _GNU_SOURCE /* Allow GNU specific funtions, by now, getdelim. */#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <string.h>#include <fcntl.h>/* Library headers */#include <glib.h>GString *load_text(gchar delimiter); static FILE *fd = NULL; /* declared statically to don't open it every time it's called*/        GString*load_text(gchar delimiter){        gchar *text=NULL;      /* store the line */        size_t len;         /* store the line len */        GString *textfull; /* store the full text. Must be g_free'd */        ssize_t size;        if ( fd == NULL )                fd = (FILE *)fopen("/dev/vcs1", "r");        if ( fd == NULL )        {                g_print("%s\n", "Error while trying to open /dev/vcs1");                exit(EXIT_FAILURE);        }        len = 0;        textfull = g_string_new("");        while( (size = getdelim(&text, &len, (gint)delimiter, fd)) != -1 )                g_string_append_printf(textfull, "%s%c",                                text, delimiter);        /* append new-line (nul) at the end just in case */        g_string_append(textfull, "\n");        return textfull;}int main(){        GString *screen_text = NULL;	gchar   *screen_position,      /* Host the last position or NULL if isn't found */		*last_screen_position, /* Host the last real position */		*percent_symbol;        int i;       for(i = 0;;i++)	{                        /* Read the screen */		screen_text = load_text(']');                		last_screen_position = 0;		if((screen_position = strstr(screen_text->str, "Booting process at ")) != NULL)			last_screen_position = screen_position;		else			continue;                /* If not found, wait and try again. */		if ( last_screen_position == 0 ) {			usleep(10);			continue;		} else			i = 0;                g_print("string: %s\n",&last_screen_position[strlen(last_screen_position)-2]);		percent_symbol = strchr(last_screen_position, '%');        		g_print("percentage: %s\n",percent_symbol);		    	                	} /* for statement closed */        g_print("%s\n", "program finished");        return 0;}