Fun with C
Fun with C
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? ).
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 )
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.
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? ).
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 )
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.
- Attachments
-
- ksub-0.6.tar.gz
- source code
- (2.45 KiB) Downloaded 349 times
Last edited by 01micko on Thu 12 Dec 2013, 12:49, edited 4 times in total.
Puppy Linux Blog - contact me for access
Re: Fun with C
Dropping the -march=$ARCH flag from configure allowed compilation in 64bit PPC01micko wrote: I'll attach source with configure script too
Worked too.
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==
Thank you !musher0 wrote:Fun... with C? Wow, man, you're weird!
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.mavrothal wrote:Dropping the -march=$ARCH flag from configure allowed compilation in 64bit PPC
Worked too.
Next version is more of a test as I am actually using utsname header now, not system call.
Last edited by 01micko on Thu 12 Dec 2013, 12:50, edited 1 time in total.
Puppy Linux Blog - contact me for access
OS X is FreeBSD in the core.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.
Now I want to see it geting the name of the XOpup/OLPC kernels (2.6.35.13_xo1-20110713.2128.olpc.da7074b_Puppy )
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==
Yep, knew that.mavrothal wrote:OS X is FreeBSD in the core.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.
it's close but I removed support for "_" delimiter (Karl Godt on the nabble forum ) 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-i6 ... tic.tar.gz .. confirmed runs (with bugs) on olpc.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 )
Puppy Linux Blog - contact me for access
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 ?
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 ?
- Attachments
-
- local_version.gif
- (16.47 KiB) Downloaded 2169 times
«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 :P
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P
Code: Select all
[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]#
Source in top post.
Puppy Linux Blog - contact me for access
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
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
- Attachments
-
- cairo-msg.jpg
- (14.46 KiB) Downloaded 1133 times
Puppy Linux Blog - contact me for access
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
William
github mcewanw
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/
.
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/
.
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/
learncodethehardway C
For anyone wanting to learn this language I'd recommend it.
http://c.learncodethehardway.org/book/
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
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.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
What, no xcb + cairo-xcb port?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
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)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Rome wasn't built in a daytechnosaurus wrote:What, no xcb + cairo-xcb port?
This one looks useful as a start.technosaurus wrote:j/k I know how difficult it is to find good xcb examples
I remember that! I had a bit of a look at xcb but went xlib because it fell into place ( = more docs and examples, which I referenced in the github readme). The program does what I want and looks ok, contrary to vovchik's "so goddamn ugly" comment. Of course the glam is all cairo.technosaurus wrote:- though I did find enough to write a very basic xcbmessage program a while back (no fancy cairo based images though)
Q> in your opinion, briefly, what are the advantages of xcb over xlib?
Puppy Linux Blog - contact me for access
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
xlib is ... xlib. xcb is smaller, faster and asynchronous You could have one thread sending requests, one handling responses, another handling errors and another (or a few) handling their callbacks while other threads handle program stuff. With xlib you send a request, wait for a response, handle, repeat. With glibc threads are actually pretty heavy (8MB+ or so each), but musl-libc has really lightweight threads (in the 10s of kb range). Now that quad-core processors with multiple execution units are a virtual standard even in mobile space, xcb _could_ really make a difference especially with openMP and other technologies that make it easier for us to take advantage. A few of us have been using musl pretty extensively and the rough edges are getting much smoother but we haven't really tested the threads much.01micko wrote:Q> in your opinion, briefly, what are the advantages of xcb over xlib?
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Interesting.
For my little venture, a very simple splash, xlib seems to suffice.
But..
For my little venture, a very simple splash, xlib seems to suffice.
But..
Remember when you had ideas to make icons for a JWM only desktop? What about xcb and cairo for that? Sure, a bit of a project. I don't think musl would support the cairo part though, not without extensive (probably way too much work) patching.technosaurus wrote:xcb is smaller, faster and asynchronous You could have one thread sending requests, one handling responses, another handling errors and another (or a few) handling their callbacks while other threads handle program stuff.
Puppy Linux Blog - contact me for access
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
see goingnuts' patches to idesk, they turned out pretty well.
It would be a shame to use an external program though, jwm already has everything in place to create them... I have even simulated icons using a solid color background and matching no-border trays for each icon (vertically oriented, fixed position with a icon+tooltip on top and optionally text on bottom) We only need a way to set individual tray background colors (probably as a property) and have the color be none (copy from parent)...not opacity as it is, that affects everything on the tray as well. If that happens I'll update my jwm tools to a 1.0 version.
It would be a shame to use an external program though, jwm already has everything in place to create them... I have even simulated icons using a solid color background and matching no-border trays for each icon (vertically oriented, fixed position with a icon+tooltip on top and optionally text on bottom) We only need a way to set individual tray background colors (probably as a property) and have the color be none (copy from parent)...not opacity as it is, that affects everything on the tray as well. If that happens I'll update my jwm tools to a 1.0 version.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- matiasbatero
- Posts: 60
- Joined: Fri 12 Oct 2012, 01:27
- Location: Mar del Plata, Argentina
I'm new in programming. I'm started with C a week ago.
The code, compiles and runs OK.
But it is only a functional structure.
structs, pointers, unions etc.. in order to provide a:
"Readable post-code".
The code, compiles and runs OK.
But it is only a functional structure.
structs, pointers, unions etc.. in order to provide a:
"Readable post-code".
- Attachments
-
- str.c.tar
- (5 KiB) Downloaded 243 times