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 Sat 19 Apr 2014, 15:42
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Fun with C
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Tue 10 Dec 2013, 01:57    Post subject:  Fun with C
Subject description: -post your programs here
 

Anyone post your C code and snippets here.

I haven't written much in any real programming language but since I studied java in my course it has given me a better understanding of objects, classes and methods, not that C uses all of those but the underlying concepts are similar, not to mention syntax, since C is mother of most modern languages.

Here is something I threw together just to get a better handle on things (I can hear them now.. should he be fixing woof? Laughing ).

This is about the first fully functional app I've written from the ground up. It is just a simple program to get kernel major, minor, sub, sub-sub versions and extra version info that some kernel builders tack onto the end. It supports 2 and 3 series kernels. There are probably bugs and bloat in it, though hopefully I've removed most of that. It can be compiled normally with gcc using shared libs or statically with musl (and probably uclibc, dietlibc etc).

Oh and before anyone says.. "oh but I can do that in one line of shell!".. er, so can I.. (yes it's over 200 lines Shocked )

Attached is the source with configure script too, no it doesn't use automake or anything! It's just easy to add options, (like --enable-static if you have musl. makes 26k bin, upx'd >> 17k bin).

Thanks to Karl Godt for testing and advice.

Tested on slacko, dpups wheezy and sqzd (2.6 kernel) and slackware 32 and 64.

###########################

v0.5 added sys/utsname.h dependency, surprisingly makes static musl build smaller! ..gcc build about the same. system() calls add bloat it seems.
v0.6 removed kernel_min function, kernel_sub fucntion along with dotnum handles it all. Changed dotnum from int to void, changed kernel_sub to accept param based on which option calls it. reworked algorithms to be more robust.
ksub-0.6.tar.gz
Description  source code
gz

 Download 
Filename  ksub-0.6.tar.gz 
Filesize  2.45 KB 
Downloaded  81 Time(s) 

_________________
Woof Mailing List | keep the faith Cool |

Last edited by 01micko on Thu 12 Dec 2013, 08:49; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website 
musher0


Joined: 04 Jan 2009
Posts: 3798
Location: Gatineau (Qc), Canada

PostPosted: Tue 10 Dec 2013, 02:26    Post subject:  

Fun... with C? Wow, man, you're weird! Laughing
_________________
"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 4982
Location: Arizona, U.S.A.

PostPosted: Tue 10 Dec 2013, 04:19    Post subject:  

I`ve been looking at bits of C code for creating an X window. Lots of code to do so little.
When I get more time I`ll see if I can make it work and then draw on it using the XCB library.
I`ve built a number of controls, most of them I built in Visual Basic a decade and a half ago.
Back to top
View user's profile Send private message 
mavrothal


Joined: 24 Aug 2009
Posts: 1385

PostPosted: Tue 10 Dec 2013, 06:01    Post subject: Re: Fun with C
Subject description: -post your programs here
 

01micko wrote:

I'll attach source with configure script too


Dropping the -march=$ARCH flag from configure allowed compilation in 64bit PPC Wink
Worked too.

_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Tue 10 Dec 2013, 07:02    Post subject:  

musher0 wrote:
Fun... with C? Wow, man, you're weird! Laughing


Thank you ! Very Happy


mavrothal wrote:
Dropping the -march=$ARCH flag from configure allowed compilation in 64bit PPC Wink
Worked too.


Amazing.. had no idea macs use uname.. and that the kernel is delimited by dots, first field has only 1 digit and there are a max of 4 fields (for the dots) and possibly a fifth if delimited by a hyphen.

Next version is more of a test as I am actually using utsname header now, not system call.

_________________
Woof Mailing List | keep the faith Cool |

Last edited by 01micko on Thu 12 Dec 2013, 08:50; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
mavrothal


Joined: 24 Aug 2009
Posts: 1385

PostPosted: Tue 10 Dec 2013, 07:11    Post subject:  

01micko wrote:

Amazing.. had no idea macs use uname.. and that the kernel is delimited by dots, first field has only 1 digit and there are a max of 4 fields (for the dots) and possibly a fifth if delimited by a hyphen.


OS X is FreeBSD in the core.

Now I want to see it geting the name of the XOpup/OLPC kernels (2.6.35.13_xo1-20110713.2128.olpc.da7074b_Puppy Shocked ) Laughing

_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Tue 10 Dec 2013, 07:52    Post subject:  

mavrothal wrote:
01micko wrote:

Amazing.. had no idea macs use uname.. and that the kernel is delimited by dots, first field has only 1 digit and there are a max of 4 fields (for the dots) and possibly a fifth if delimited by a hyphen.


OS X is FreeBSD in the core.
Yep, knew that.

mavrothal wrote:
Now I want to see it geting the name of the XOpup/OLPC kernels (2.6.35.13_xo1-20110713.2128.olpc.da7074b_Puppy Shocked ) Laughing

it's close but I removed support for "_" delimiter (Karl Godt on the nabble forum Razz ) plus there are extra dots and all sorts of crap. I just tried the musl static version actually.. http://01micko.com/packages/ksub-0.5-i686-musl_static.tar.gz .. confirmed runs (with bugs) on olpc.

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


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

PostPosted: Tue 10 Dec 2013, 09:46    Post subject:  

cat /proc/sys/kernel/osrelease
2.6.37.4-KRG-i586TSC-64GB-1

CONFIG_LOCALVERSION: │
│ │
│ Append an extra string to the end of your kernel version. │
│ This will show up when you type uname, for example. │
│ The string you set here will be appended after the contents of │
│ any files with a filename matching localversion* in your │
│ object and source tree, in that order. Your total string can │
│ be a maximum of 64 characters.

Difficult to say , I think I need to compile a -rcY kernel to see how that gets appended .
VERSION = 3
PATCHLEVEL = 8
SUBLEVEL = 0
EXTRAVERSION = -rc1
NAME = Terrified Chipmunk

3.8.0.-rc1 OR 3.8.0-rc1 ??

What will happen then : ?
Will it show 2 6 39 41 ??
Or 2 6 39 41stJanuary2014 ?
Or 2 6 39 412014 ?
local_version.gif
 Description   
 Filesize   16.47 KB
 Viewed   198 Time(s)

local_version.gif


_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message Visit poster's website 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Tue 10 Dec 2013, 20:02    Post subject:  

Code:
[root@xo-4a-b2-3b olpc]# ksub -h
ksub-0.6
Usage :
   -m - shows version level
   -p - shows patchlevel
   -s - shows sublevel
   -n - shows extra name
   -ss - shows sub-sublevel (2 series kernels)

   Only one argument is accepted
   If no argument the kernel version is printed
   If extra name or sub-sublevel are undefined program exits with 0 status
[root@xo-4a-b2-3b olpc]# ksub
2.6.31_xo1.5-20100823.1646.1.olpc.12d64069981699a
[root@xo-4a-b2-3b olpc]# ksub -n
xo1.5-20100823.1646.1.olpc.12d64069981699a
[root@xo-4a-b2-3b olpc]# ksub -m
2
[root@xo-4a-b2-3b olpc]# ksub -p
6
[root@xo-4a-b2-3b olpc]# ksub -s
31
[root@xo-4a-b2-3b olpc]# ksub -ss
[root@xo-4a-b2-3b olpc]#


binary package << http://01micko.com/packages/ksub-0.6-i686-musl_static.tar.gz 12k (upx'd)

Source in top post.

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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
[ Time: 0.0647s ][ Queries: 12 (0.0058s) ][ GZIP on ]