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 Tue 21 Oct 2014, 07:58
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 3 [39 Posts]   Goto page: 1, 2, 3 Next
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7831
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  136 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: 4254
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: 5037
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: 1686

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: 7831
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: 1686

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: 7831
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: 3972
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   808 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: 7831
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 
01micko


Joined: 11 Oct 2008
Posts: 7831
Location: qld

PostPosted: Sat 19 Jul 2014, 21:15    Post subject:  

I seem to make a habit of this:

In the middle of slacko development I usually get a bit bogged down, so I take a break for a few days.. well a change is as good as a holiday they say, so I got into some more fun with C!

I have developed a simple splash message program based on Xlib and Cairo (yay! no GTK!) called funnily enough "cairo-msg" .

I've been wanting to do this ever since yaf-splash's demise due to lack of UTF-8 support. (jamesbond has patched it though I believe, haven't tried). Anyway, this is simpler but just as powerful. Cairo is easy to learn and could be the basis for a lot more small but useful and pretty gui programs.

Rather than explaining here go and check it out on github:

https://github.com/01micko/cairo-msg
cairo-msg.jpg
 Description   
 Filesize   14.46 KB
 Viewed   500 Time(s)

cairo-msg.jpg


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

Joined: 16 Aug 2007
Posts: 2346
Location: New Zealand

PostPosted: Sun 20 Jul 2014, 03:09    Post subject:  

And here's me been pondering giving up programming in the not too distant future because it takes up so much time! Not that I probably will give up entirely though - every so often I can't help but experiment with some programming idea or other... and have a few current project addons/extension ideas I still want to try out and maybe 'complete' one day... Haven't done any C programming in a long time, though used to be my favourite at system level anyway. I think I'm becoming lazier as I get older, and C programming needs constant practice to remain fluent(ish) at it whereas shell scripting is always easy to pick up again after a long sleep.

William

_________________
Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


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

PostPosted: Sun 20 Jul 2014, 13:45    Post subject:  

Hi William and other folks; C is very gritty, but also the most capable.

Consider BaCon ( BAsic CONverter ).
Easy to remember Basic language ( It was easy to go from Visual Basic to it ).
And it produces C binary executable files.
Has GTK based HUG ( Highlevel Universal GUI ) for window apps.

Micko is looking to convert his popup notice to BaCon on it`s forum.

Web site: http://www.basic-converter.org/

Forum: http://basic-converter.proboards.com/
.
Back to top
View user's profile Send private message 
darkcity


Joined: 23 May 2010
Posts: 2462
Location: near here

PostPosted: Sun 20 Jul 2014, 15:11    Post subject:  

I've worked through a little bit of
learncodethehardway C

For anyone wanting to learn this language I'd recommend it.
http://c.learncodethehardway.org/book/

_________________
helping Wiki for help | IF SendSpace link = "dead" THEN PM me ("up file to http://meownplanet.net/")
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 21 Jul 2014, 04:16    Post subject:  

I was just about to start a thread on optimizing your C and best practices. The problem with C is most of the people who use it think they are smart so most of the tutorials are a couple levels past being understandable by commoners. When I've spent a lot of time figuring something out I have to write stuff down in the simplest way possible so _I_ can read it later and not have to re-read it and re-look stuff up.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Mon 21 Jul 2014, 04:20    Post subject:  

01micko wrote:
I have developed a simple splash message program based on Xlib and Cairo (yay! no GTK!) called funnily enough "cairo-msg"
https://github.com/01micko/cairo-msg

What, no xcb + cairo-xcb port?
j/k I know how difficult it is to find good xcb examples - though I did find enough to write a very basic xcbmessage program a while back (no fancy cairo based images though)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [39 Posts]   Goto page: 1, 2, 3 Next
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.1075s ][ Queries: 13 (0.0159s) ][ GZIP on ]