Component index
Section index

Component loadfile


Search

	/*
	    loadfile is a simple component to handle text file.
	*/
	<mod>
	static void sample_loadfile()
	{
	    // This is a minimal case to print a file. THis is short and does
	    // all the error reporting and testing.
	    <call loadfile>("/proc/net/route",false);
	    <f oneline>
	        fputs (line,stdout);
	    </f>
	    </call>
	
	    // Here is an example with more control
	    <call loadfile>("/proc/net/route",true);
	    <f missing>
	        tlmp_error ("No file /proc/net/route\n");
	    </f>
	    <f empty>
	        printf ("The file is empty\n");
	    </f>
	    <f start>
	        // Ok, we know the file is not empty, we format a nice table
	        printf ("This is the routing table\n");
	    </f>
	    <f end>
	        printf ("-------------\n");
	    </f>
	    <f oneline>
	        // Often a component pass "commodity" information
	        // Here it passes the line number. We use this to skip the first line.
	        // and we return -1 to print only the first 3 lines
	        if (noline > 0) printf ("%s\n",line);
	        return noline > 3 ? -1 : 0;
	    </f>
	    </call>
	}
	</mod>