How to 'read' programs

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
reasonit
Posts: 55
Joined: Sat 25 Mar 2006, 21:39

How to 'read' programs

#1 Post by reasonit »

So I know a bit of C# , php and a bit of C.
what I really want to do is modify some linux programs to suit my needs.

basically how does one 'read' or understand a program ? Lets take jwm for example, lets say I want to add the ability to close applications by middle clicking on them in the taskbar: how do I go about understanding it ? Is there a method to it? I downloaded the source, opened a few C files . didn't understand I thing.

Should I first wet my feet with simpler C programs ? If so can someone suggest me some? I am interested in 'real' C linux programs.

Thanks

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#2 Post by Lobster »

Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: How to 'read' programs

#3 Post by L18L »

reasonit wrote:...
Should I first wet my feet with simpler C programs ? If so can someone suggest me some? I am interested in 'real' C linux programs.
...
hello :idea: 8) :)

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#4 Post by dejan555 »

You download program's source code obviously and modify what you want then compile it.
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#5 Post by muggins »

And of course backup, backup & backup. Definitely start with small, simpler programs.

Bruce B

Re: How to 'read' programs

#6 Post by Bruce B »

reasonit wrote:Should I first wet my feet with simpler C programs ?
If so can someone suggest me some? I am interested in 'real' C linux
programs.

Thanks
This is real C. It is as trivial as it comes for a do something utility. It is
used as a pipe. Takes character input and outputs in hex.

Take a bite on it. Then Muggins or I can explain.

Code: Select all

#include <stdio.h>

int main() {

register int ch;

    while((ch=getchar()) != EOF) {

        if ( ch == 10 ) {
            printf ("0a ");
            continue;
        }

        printf ("%0x ", ch);

    }

    return(0);

}
~
Last edited by Bruce B on Thu 26 May 2011, 04:36, edited 1 time in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: How to 'read' programs

#7 Post by L18L »

Bruce B wrote:Take a bite on it.
May I join the playground ?

half bit of C, some php, bash and BaCon....

I am coming here from testing wary51157 running as fido, devx installed.

Code: Select all

mkdir ~/programming/C
copied code into char2hex.c
compiled (fido can !)

Code: Select all

# gcc char2hex.c
and used it:

Code: Select all

# echo "123" |  ./a.out
31 32 33 0a 

Code: Select all

# pwd
/root/programming/C
# whoami
fido
# echo "Thank you" | ./a.out
54 68 61 6e 6b 20 79 6f 75 0a # :) :) :)

Bruce B

#8 Post by Bruce B »

L18L,

This is the bash script to reassemble the hex. You should be able to
take the output of char2hex, even on a complex file like a binary file
and reassemble with perfect md5sum match. Moreover, if not
perfect something is wrong.

The script doesn't work like it looks like it works. It is strictly a pipe.
Use it the same as the char2hex.

It only works on the hex input format like char2hex outputs.

Code: Select all

#!/bin/bash
for i in `cat $1` ; do
	printf "\x$i"
done

cat filename.txt | char2hex | hex2char

So, you know by the command that filename.txt was converted to
the hex output, piped to hex2char and prints the text again.

For a binary file

cat filename.bin | char2hex


But not this

cat filename.bin | char2hex | hex2char

The reason why is there are often characters in the .bin file which
shouldn't be printed to the screen and locks up your bash terminal

In simple words. Don't output things to screen which crash the
monitor.

Bruce

~

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

C language

#9 Post by L18L »

Bruce B wrote:...
This is the bash script to reassemble the hex. You should be able to
take the output of char2hex, even on a complex file like a binary file
and reassemble with perfect md5sum match. Moreover, if not
perfect something is wrong.
...
Thank you, Bruce
For me it was working.

But first let me point to the story that might give an explanation to OP and others.

And then admit: If had completely read this before my example would have been better.
Not:

Code: Select all

# gcc char2hex.c
But:

Code: Select all

gcc char2hex.c -o char2hex


Anyway I had to use it with a.out instead of char2hex
No: with .a.aut

OT ?
- the dots are important
- fido can

Thanks again

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#10 Post by abushcrafter »

Great idea! Close window on middle click. I love it :D. I hope it gets added to JWM.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#11 Post by jpeps »

abushcrafter wrote:Great idea! Close window on middle click. I love it :D. I hope it gets added to JWM.
Middle button typically pastes the clipboard, which might be a conflict.

Bruce B

#12 Post by Bruce B »

Keyboard shortcuts for closing most apps

Ctrl+q

Alt+F4

~

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#13 Post by abushcrafter »

jpeps wrote:
abushcrafter wrote:Great idea! Close window on middle click. I love it :D. I hope it gets added to JWM.
Middle button typically pastes the clipboard, which might be a conflict.
Sorry, I meant on the task bar buttons.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

Bruce B

#14 Post by Bruce B »

omernaeem wrote:nice share bruceb. Did know about the ctrl Q shortcut
Keyboard shortcuts are often listed on the drop down menus. See the picture for Firefox's 'File' menu below.

~
Attachments
menu.jpg
(40.27 KiB) Downloaded 715 times

Post Reply