tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Understanding a source code file



Thank you for all your useful advices.
As a real "technical" clarification, there are two versions of "banner" in the system, one in /usr/games and one in /usr/bin/banner.
The source code we used was that of /usr/games/banner. But this is not the program runned after typing "banner" in the system, which by default is located in /usr/bin/banner. It is different and it has a different output. Its source code is located instead in

http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/usr.bin/banner/banner.c?rev=1.15&content-type=text/plain&only_with_tag=MAIN

I will test them following your useful hints.
Regards,

Rocky

 
 
 

> Sent: Saturday, November 22, 2014 at 12:28 AM
> From: "Iain Hibbert" <plunky%ogmig.net@localhost>
> To: "Rocky Hotas" <rockyhotas%post.com@localhost>
> Cc: "tech-userlevel%netbsd.org@localhost" <tech-userlevel%netbsd.org@localhost>
> Subject: Re: Understanding a source code file
>
> On Fri, 21 Nov 2014, Rocky Hotas wrote:
> 
> > Hoping this is the right section for my question.
> 
> maybe, in that it is a technical question relating to a userland program..
> however, I think you are asking a basic programming question really
> 
> > I would like to correctly understand the contents of a simple source
> > file: it is banner.c (/src/games/banner), the version contained in
> 
> > It is the source code of a very simple program, as you know.
> 
> > In the first lines, there are two "static const int" arrays declared: it
> > seems to be a mapping. I can't also understand the format of the "Table
> > of stuff to print" between the two arrays.
> 
> > First of all, what does this part mean?
> 
> this is an encoded and compressed method for printing the letters. you
> first look up the letter you want to print in the asc_ptr table, using its
> ASCII code (which is 41) as an index (see ascii(7)). Supposing you want to
> print an "A" then, you find the value 3072. You use this as the index to
> the data_table. The first number is 30, which is n. Since it is not >128
> or >64 you look at the next number 4 which is m. You put 4 characters at
> position 30. The next number is 132 which is 128 + 4, making n=4 . >128
> means print the current line n times, so you do that. The next numbers are
> 30 and 5, meaning 5 chars at position 30, and 129 meaning print this line
> once (128+1). look at the output of /usr/games/banner A and compare it to
> what I wrote so far above..
> 
> <30 spaces>####
> <30 spaces>####
> <30 spaces>####
> <30 spaces>####
> <30 spaces>#####
> 
> You carry on until you reach a value >64 when you can stop for that
> character.
> 
> > I have never analyzed a NetBSD kernel or something similar. Supposing
> > that I know the basics of the C language, is there a standard way to
> > proceed in the analysis of such source files? (I didn't find useful
> > sites talking about this topic)
> 
> you run the program in your head. if it is too difficult, then you can add
> trace points (maybe edit the program to print something during the run,
> maybe use a debugger of some kind). This is one reason why it is good to
> split tasks up into smaller sections!
> 
> regards,
> iain
> 


Home | Main Index | Thread Index | Old Index