Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 31 Oct 2014, 08:55
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Assigning variables in C programming
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Tue 12 Jun 2012, 11:05    Post_subject:  Assigning variables in C programming
Sub_title: (freememapplet)
 

There are some sources flying around here on the forum ,
one of them is freememapplet[_tray] source .

Today i discovered on a Puppy 5 installation a folder i had nearly forgotten about where i had several source tarballs of freememapplet .

The problem is that since Lupu 5.1.1
playdays somehow shifted the Puppy df wrapper,
that substitutes "/dev/root" with `rdev' output for full installs,

this source had been altered to
Code:
else if (pupmode==2) fp = (FILE *)popen("df -m |  grep '/dev/root' | tr -s ' '| cut -f 2,4 -d ' '","r");

which does not work on Puppy full installations that have the df script and the df-FULL binary .

It is easy to alter the code to
Code:
else if (pupmode==2) fp = (FILE *)popen("df -m |  grep -m1 -w '/' | tr -s ' '| cut -f 2,4 -d ' '","r");

To make it work .

But i wanted to create a fall back line if fp still stays NULL somehow .

I tried this
Code:
 if (!fp) fp=-1;

which gave Warning but compiles
Quote:
// freememapplet_tray.c: In function ‘Update’:
// freememapplet_tray.c:71: Warnung: assignment makes pointer from integer without a cast

and is incorrect, since fd should contain 2 values
and freememapplet still segfaults

and tried
Code:
if (!fp) (char *) fp = "0 0";

which gave error
Quote:
// freememapplet_tray.c: In function ‘Update’:
// freememapplet_tray.c:71: Fehler: lvalue required as left operand of assignment


I am guessing i need a C command to parse a string of two values to the fd variable .
Question
Back to top
View user's profile Send_private_message Visit_website 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Tue 12 Jun 2012, 12:15    Post_subject:  

snprintf example
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Tue 12 Jun 2012, 19:15    Post_subject:  

Thanks, technosaurus !

Googled a little for "snprintf example" and found this almost complete :

http://www.codecogs.com/reference/computing/c/stdio.h/printf.php?alias=snprintf

for all the other *printf 's .

will take me a while to figure things, cos

Code:
if (!fp) sprintf( (char *)fp, "%d %d\n", 0, 0) ;

or
Code:
if (fp == NULL) sprintf( (char *)fp, "%d %d", 100, 10) ;

seems not to work, it seems that fp is not empty , probably still as a linefeed \n or \0 char somewhere .

the source i am nagging on can be found here :
http://www.murga-linux.com/puppy/viewtopic.php?p=450192#450192
Back to top
View user's profile Send_private_message Visit_website 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Tue 12 Jun 2012, 20:10    Post_subject:  

crap I answered the question asked, not the real question
- fp is a pointer to an int (that is what FILE does - it is equivalent to int) so (FILE *) is a file descriptor pointer the equivalent of (int *) ... does not cast well to a char *
fyi: the standard file descriptors are 0 (stdin), 1 (stdout), 2 (stderr)

anyhow after that last one you can just try your alternate if !fp do:
Code:
else if (pupmode==2) {
    fp = (FILE *)popen("df -m |  grep '/dev/root' | tr -s ' '| cut -f 2,4 -d ' '","r");
    if (!fp) fp = (FILE *)popen("df -m |  grep -m1 -w '/' | tr -s ' '| cut -f 2,4 -d ' '","r");
}

later you may use that file descriptor to read() the output (which is when you will store it in a char *)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Tue 12 Jun 2012, 21:58    Post_subject:  

Embarassed the 'fd' was a typo of mine, meant 'fp' Embarassed

Thanks, techno, this way i altered xosview to look for different paths for the temperature line . Will post source if i find them. But in xosview it seems to be clumpsy, should look everywhere in /sys for temp_input[0-9] files .
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0590s ][ Queries: 11 (0.0076s) ][ GZIP on ]