The time now is Tue 21 May 2013, 21:44
All times are UTC - 4 |
| Author |
Message |
Karl Godt

Joined: 20 Jun 2010 Posts: 2675 Location: Kiel,Germany
|
Posted: Tue 12 Jun 2012, 11:05 Post subject:
Assigning variables in C programming Subject description: (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
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 .
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 12 Jun 2012, 12:15 Post subject:
|
|
snprintf example
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2675 Location: Kiel,Germany
|
Posted: 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
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: 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 *)
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2675 Location: Kiel,Germany
|
Posted: Tue 12 Jun 2012, 21:58 Post subject:
|
|
the 'fd' was a typo of mine, meant 'fp'
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
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|