Friday, April 27, 2007

I knew it !!!

I was toying with a Distro chooser, after all I'm thinking of setting up a Linux Distro on one box.

I've been thinking about a Linux From Scratch actually, the perk of defining my own file system hier (mostly) is hard to drop. I ran through it, and oddly enough it recomended two distros. The Second was Slackware which does not like the machine very well and the First recomendation which I knew it had to be !! HAHAHAAHAHHA


ROFLMBO I knew it had to do that to me!

Link to the Chooser

Thursday, April 26, 2007



I don't have time for starting off learning Ada and not in the mood for reading. So I'm toying with Ruby. Its good really, and I should brush up with Perl too.

I dunno why but for some reason I seem fascinated by the Ada language 0.o

Tuesday, April 24, 2007

Photo Op

PC-BSD 1.3/FreeBSD 6.1-Release and KDE 3.5.5. The system monitor is Gkrellm2, the console saver is cmatrix and the menu bar has a shredder and network browser applet installed.

Monday, April 23, 2007

Linux or BSD?

Some how it figures, I always have more issues setting up a Linux system then a BSD one... Go figure

Linux supports newer hardware faster

but BSD tends to just detect it.

Heck, if the box in question had a Floppy disk I think I'd install OpenBSD on the thing and go /w the X11 option. But if it won't dual boot FreeBSD and PC-BSD without hicups I doubt OpenBSD and PC-BSD would be any better....

Bloody hardware !!!

And thinking about early Linux systems, the term 'Linux/GNU' probably is more accurate then Linux or GNU/Linux =/

Sunday, April 22, 2007

Link fest

Saturday, April 21, 2007

I'm going out of my fucking mind.

During the day its impossimble to do _any_ thing that requires concintration.

At night I can only work till my mind shuts down due to lack of sleep.



Ether I throw all of you the fuck out of the house for a few hours.

Or life stays as is and I live with torture.


Ready to burst here...
While I'm to tired to understand why this writes past the end of the array

#include <assert.h>
#define bounds(_i, _n)  (assert( (unsigned) (_i) < (_n) ), (_i) )

 * fout is what we are appending to and should be open rw as necessary.
 * farray is an array of file pointers, "farsize" is the size of the array.
concatenate( FILE *fout, FILE *farray[], const unsigned char *farsize) {

        int c;
        unsigned int fi = 1;
        FILE *fin;      /* current segment of farray[] to fout. */

        while ( (fi < farsize[0])) {
                fin = farray[bounds(fi, *farsize)];
                while ( (c = fgetc(fin )) != EOF ) {
                        fputc( c, fout );

I'm GOING TO BED. 0832 Zulu time on my clock.... must sleeep sleep....

what is that again?

Thursday, April 19, 2007

Jingle All the Way

Got to enjoy a few good movies tonight. The end of 'The Man', 'Jingle All the Way' - I love a few parts of that movie. Especially the one where he gets in a brawl with the Rain Deer & they go drinking lol.

Ep IV is on, the New Hope is one of my favorite Star Wars movies. And after that is Mr & Mrs Smith. Now thats a sweet flick. And the gun battle at the ends not half bad hehehe.

Tuesday, April 17, 2007

Well since Windows lacks fgetln() but as far as I can tell the BSD and GNU C Libraries have it.

/* The origenal, basically the same as one of the functions in FreeBSDs head(1) implementation.

static void
read_top( FILE *fp, int lncnt ) {

        char *cp;
        size_t error, rlen;
        while ( lncnt && (cp = fgetln( fp, &rlen )) != NULL ) {
                error = fwrite( cp, sizeof(char), rlen, stdout );
                if ( error != rlen )
                        err( 1, "stdout" );

/* A new version of read_top that *should* be a bit more standard compilent and simple to read */

static void
read_top( FILE *fp, int lncnt ) {

        int c = 0;
        int f = 0;

        while ( (c < lncnt) && (f != EOF ) ) {
                f = fgetc( fp );
                printf( "%c", f );
                if ( (f == '\n') ) {

The biggest problem with rf.c is the use of err()/errx(), a nice pair of Macros that expand to a fairly compatible meaning would be nice for portability. *cough* Windows *cough* and I don't even want to know how groff works on WIN32 if at all....

Monday, April 16, 2007

10 Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that ``All the world's a VAX'', and have no commerce with the benighted heathens who cling to this barbarous belief, that the days of thy program may be long even though the days of thy current machine be short.
This particular heresy bids fair to be replaced by ``All the world's a Sun'' or ``All the world's a 386'' (this latter being a particularly revolting invention of Satan), but the words apply to all such without limitation. Beware, in particular, of the subtle and terrible ``All the world's a 32-bit machine'', which is almost true today but shall cease to be so before thy resume grows too much longer.

Ten Commandments of C Programming

This some times reminds me of how I feel about assumtions. Uusally met with me thinking.

"I'm not running Windows, !@#$ you"

"I'm not running Linux, !@#$ you"

"I'm not using MS-DOS, !@#$ off!"

"I'm not working in Visual BASIC or Visual C++, really un-!@#$ you"

"What if I'm not on a 32-Bit system, oh go !@#$ your self"


Sunday, April 15, 2007


Some good links

Maybe I'm werid but it is interesting stuff ^_^
1 Thing I'd love to see. Is a simple yet powerful language like Perl/Python/Ruby thats got a C/C++ style compiler like GCC. Like being able to run the C pre-processor on the files before compilation and being able to link the object files together into an executable.

But also, a simple interpreter that implements the standard library and can run single file 'scripts' like a Bourne Shell. Yet with the options of being able to 'link' to pre-compiled libraries of code to extend itself in order to run the script. That way, people could use the interpreter for use interactive (like irb / python) yet run scripts and not have to have a development environment (compiler and friends) and any precompiled libraries could be distributed with the script.


import math_module
import sockets_module

Compile the app and link it to a math and socket library. Or i f we're using the interpreter.

foo -l lib1, lib2

or even in the script

#!/usr/bin/foo -L /usr/lib/foo/

Would be kinda cool.

The power, flexibility, and speed of a compiler yet the simplicity of an interpretor. But with keeping the ability to also use various libraries of code with the scripts. One could probably do some preprocessor work to include the library code in the script before using it too and save disk space.

Wouldn't it be awesome if one could work on a Project in Python instead of C++ and keep a compiled executable. Yet when ya need a little script for some 'loose ends' to just go ahead and write a script to do it in the same language as the project ? Hehehehe.

I think D has the ability of doing a script, like #!/path/compiler -run at the top of the file. No clue if its a dual-purpose compiler/interpretor or if it just compiles an executable in temp space and runs it or what.

Saturday, April 14, 2007

rf.c semi-final

Well to make a long story short. I found out that calling setlocale() made my program (rf) crash when ever I used to -b switch. But strangely on OpenBSD it ran perfectly fine.

Sure enough after 2 days of tracking I found a few bugs and the little blighter I've just squashed was just the one I expected to find. It was just a matter of how. Just a bad pointer, my guess is after the setlocale() call. It was pointing some where FreeBSD didn't like and without the call it wasn't enough to get ballocked at. Who cares how thats possible... as long as its fixed hehe. Well as best as _I_ can tell any way.

The projects grown and I've learned quite since the start. Both about working in C, using Makefiles, dealing with GCC, GDB in more depth, and groff e.t.c. For sear size we are at:

#wc [ lines | words | bytes | filename ] 
  16     121     778 COPYING
      25      68     735 Makefile.optimize
     255    1023    6517 rf.c
      11     114    3636 rf.o
      87     333    1819 rf.1
       9      68     404 tags
     403    1727   13889 total

I have 3 Makefiles, a generic makefile for building the application on i686. Makefile.debug that does likewise but includes debugging symbols. And Makefile.optimize that has a few extra flags with mostly optimization options in it (hence the name). Each also can do a 'make install' for me. All in all gcc gets called from Makefile.optimize with:

-Wall -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Winline -Wnested-externs -std=c99 -march=i686 -fforce-mem -fforce-addr -finline-functions -fstrength-reduce -floop-optimize

I made some other changes too. I rewrote parts of main, its still not pretty but a wrapper on fopen() I think makes it easier to dick with. I finally added a -v option to see the file name. I was trying to figure out how to make a variadic macro and stumbled onto the __FILE__ and __LINE__ additions to C hehehe. I also decided to have it clean up after its malloc'ing. AFAIK a programs memory is free()'d after it exits so I didn't bother. Now I did for completeness sake. clean_up() is called after handling the output done in read_bottom (which actually uses read_all() to printout the file). So that if for some odd reason theres really low memory or some thing and it takes *awhile* to handle malloc'ing and seeking semi-end-to-end through a linked-list. I figured it'd be a good 'just in case' even if its not likely.

I really would like to rewrite read_top() b/c I don't know of any comparable function to fgetln() on windows and a Macro that inlines a rough equivalent to my beloved err() function too. Which likewise is available from the BSD and GNU C Libraries and both are marked as 'first appeared in 4.4BSD' in the man pages. And AFAICT not available from Microsofts implementation.

One thing I need to do is learn more about groff and the man page macros and stuff. So far its mostly been a matter of reading my systems man pages and trial/error to get a fairly decent manpage.

I try to keep things small, my displays usually 80x25 or 80x35 if I'm working on Windows (GVIM) and 1 thing I really hate. Is a huge function thats so freaking big, you don't even remember the NAME of it by the time you hit the closing bra}e. So lol, I do my best not to write functions that long. At 60 some lines with comments I think read_bottom should be broken up into 2 smaller functions, the extra function call is negiable overhead I'm sure. I just think it would take longer to read. Really if you snip off the variable declarations and list startup (which could be function'ized) it almost fits on 1 screen. be_verbose man as well be a macro or inline function too. Although a compiler could take care of that choice it self I'm sure.

To be honest, I just like functions that are small, do whats asked, and avoid being swiss-army knifes.

 * Copyright (C) 2007
 *      Terry M. P*****. All rights reserved.
 * permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.

// vim: set noexpandtab ts=8 sw=4 ai :
// vi: set ai nu ts=8 sw=4 :

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <locale.h>
#include <unistd.h>

struct lnpos {
        long nl;
        struct lnpos *next;
} lnpos = { .next = 0, .nl = 0 };

static FILE *open_file( char * );
static void read_all( FILE *, int );
static void read_top( FILE *, int );
static void read_bottom( FILE *, int );
static void clean_up( struct lnpos *);
static void be_verbose( void );
static void usage( void );

static const char *this_progname;

 * rf - read file to standard out v1.27

main( int argc, char *argv[] ) {

        char *erptr;
        int t_flag = 0, b_flag = 0, v_flag = 0;
        int ch, lncnt;
        FILE *fp;

 (void)setlocale( LC_ALL, "" );

        this_progname = argv[0];

        while ( (ch = getopt(argc, argv, "b:t:v")) != -1 ) {
                switch (ch) {
                case 'b':
                        lncnt = strtol(optarg, &erptr, 10);
                        if ( *erptr || lncnt <= 0 )
                                errx( 1, "Improper line count -- %s", optarg );
                case 't':
                        lncnt = strtol(optarg, &erptr, 10);
                        if ( *erptr || lncnt <= 0 )
                                errx( 1, "Improper line count -- %s", optarg );
                case 'v':
                case '?':
                        /* NOTREACHED */

 /* This is ugly but cleaner then w/o open_file(). */
 if ( argv[1] == NULL ) {
 } else if ( (t_flag < 1) && (b_flag < 1) && (v_flag < 1) )  {
  fp = open_file( argv[1] );
  read_all( fp, lncnt );
 } else if ( (v_flag != 0) && (t_flag < 1) && (b_flag < 1) ) {
  fp = open_file( argv[2] );
  read_all( fp, lncnt );
 }  else if ( t_flag > 0 ) {
  fp = open_file( argv[3] );
  read_top( fp, lncnt );
 } else if ( b_flag > 0 ) {
  fp = open_file( argv[3] );
      read_bottom( fp, lncnt );
 } else {

 if ( v_flag != 0 )

 fclose( fp );
 return 0;


/* Simple fopen wrapper to keep the if...else if...else blockage from
 * getting even uglier. Since doing other wise would defeat the purpose of it.
 * open_file() halts the program if fopen failed.
static FILE
*open_file( char *arg ) {

 FILE *fto;

 fto = fopen( arg, "r" );
 if ( fto == NULL ) 
  errx( 1, "File can not be opened or"
        " does not exist -- %s\n", arg );
 return fto;

 * print out an open file to standard output

static void
read_all( FILE *fp, int lncnt ) {

        while ( (lncnt = fgetc( fp )) != EOF ) {
                printf( "%c", lncnt );

/* Read n lines from the top of the file.
 * note that it was very inspired by the head(1) implementation of BSD
static void
read_top( FILE *fp, int lncnt ) {

        char *cp;
        size_t error, rlen;
        while ( lncnt && (cp = fgetln( fp, &rlen )) != NULL ) {
                error = fwrite( cp, sizeof(char), rlen, stdout );
                if ( error != rlen )
                        err( 1, "stdout" );

/* Read n lines from the bottom of the file
static void
read_bottom( FILE *fp, int lncnt ) {

        int hmany = lncnt;
        long nlnum = 0;
        long where;

        struct lnpos *root = 0;
        struct lnpos *cur = 0;

        root = malloc( sizeof(struct lnpos) );
        if ( root == NULL )
                err( 1, "can't init the list" );
        root->next = 0;
        cur = root;

        cur->next = malloc( sizeof(struct lnpos) );
        if ( cur->next == NULL )
                err( 1, "can't add first node" );
        cur = cur->next;

        /* read the file, count every '\n' and store them in a new member of
         * our linked list.
        while ( (lncnt = fgetc( fp )) != EOF ) {
                if ( lncnt == '\n' ) {
                        cur->nl = ftell( fp );
   cur->next = malloc( sizeof(struct lnpos) );
   if ( cur->next == NULL )
    err( 1, "can't store line feeds" );
   cur = cur->next;


 /* Let's mark the end of the list and move to it */
 cur->next = malloc( sizeof(struct lnpos) );
 if ( cur->next == NULL )
  err( 1, "can't terminate the list" );
 cur = cur->next;
 cur->next = NULL;

        /* rewind our linked-list and seek to b_flag segments. So readall() starts from
         * the correct fseek offset to print till EOF. - This keeps down on
         * unnecessary code here !
        cur = root;
        while ( hmany < nlnum ) {
                cur = cur->next;


        where = fseek( fp, cur->nl, SEEK_SET );
        if ( where != 0 )
                err( 1, "could not seek through the file\n" );

        read_all( fp, lncnt );
 clean_up( root );

/* Simple destructor - walk the list and free() the memory before the
 * program exits.
static void
clean_up( struct lnpos *rp ) {

 struct lnpos *t = rp;
 struct lnpos *atpos = rp;

 while ( atpos != NULL ) {
  free( t );
  atpos = atpos->next;
  t = atpos;

static void
be_verbose( void ) {

        printf("==> %s <==\n", __FILE__);

static void
usage( void ) {

        (void)fprintf( stderr, "usage: %s [-t count | -b count] "
                       "[-v] [file ...]\n",
                       this_progname );

        exit( EXIT_FAILURE );

I've learned so much in the past 2 months, its awesome. Really this is the largest project I've ever worked on in my ~/Programming directory. 255 Lines isn't much but when your a bumbling baboon trying to learn in the wilderness. It kinda helps to learn by reading and writing code I guess.

I also want to start assembling a little personal library of functions and macros that I can draw on to do odds and ends without rewriting them. After all with my little 'toys' I might have use of other stuff from time to time hehe.


Thursday, April 12, 2007

You know... if I was a smarter man I might pursue learning more about Particle Physics.

Its fascinating...

TBH I don't hate mathematics per say. Its just the way school tends to put me to work on'em.

Monday, April 9, 2007


A table that gives A-Za-Z and 0-9 a nummerical value per char. So going to foo in table gives us bar.

Find our position in the table by looping through the table. But instead of A-9 or some thing. Do it sorted via commonality.

Increment our position in the table by an arbitrary rotation value. If we're at the end of the table, start from the beginning again.

Remember that !!!

also, gotta figure some thing out /w that PBI. Dunno a good way of doing it any better then now for the NIC list.

Sunday, April 8, 2007

Backup took about 2 hours to take, plus a lot of set up time because of networking issues... It was to much bugger working with the install disk as a subsitute R&RO disk.

So booted and dropped to single user, mounted stuff RO after having fsck'd it with the install disk. Dumped it 'cross the network after sorting out a minor issue with PF ! Alls good but next time I think I need more compression and less speed on the gzip.

Only problem is I need to get the archive to a partition I can trust, that would be a FAT32 one but the max file size is 4GB and the backups a bit fatter then that. Tried to copy it to an ext3fs so I could test doing a restore to a Linux partition. While ext3 I think can handle files 16GB++ to a few TB. I could only create a 2GB file on it so bonkers.

If I can bzip or 7z it down to the right size I might be able to burn it to DVD-R. I think my best bet would be to *try* and copy the the dump from the ufs2 slice to my ntfs one using an ifs driver for it on XP.


Ok so I'm a crazy stooge !

I spent the night trying to evade my allergies by implementing a simple rot13 program based on some super-short implemnetations of the algorithm from USENET.

Shes got interactive and file based rot13, a -r option set up to use a different rotation then 13... but I havn't implemented those yet hehehe.

Had a lot of fun working on it and learned a few things while working on the manual page that even let me clean up rf.1 !

Saturday, April 7, 2007

Gotta look at:

Taking a dump(8) to - (stdin) and piping it to gzip and using |ssh over the network to use dd to create a backup might not be a bad idea.

dump -0f - / | gzip -2 | ssh -c blowfish Terry@IP dd of=vectra_date.gz


Monday, April 2, 2007


Got to remember to back up my home directory.

Think it'd be some thing like

cd ~
mv Music /somewhere
pax -wf /Backups/_usr-home-Terry.pax ./*
cd /Backups
gzip -9 _user-home-Terry.pax

I'll worry about it later

Sunday, April 1, 2007


Finnally... some time to relax.

This weeks been heck between work, allergies, and business. Little time to even be on the laptop.

Been working my way slowly threw a few books Link1 Link2.

Been working on stuff /w the SNCO project most of the week... been digging into XHTML/CSS with it. I'm starting to write pages XHTML compilent and use the validator to catch typos. Usually missing '/' on end tags in lists.

Had the bosses dog for the weekend while they were out of town.... spent most of it walking 3 dogs and being sat on.

I feel like shaving, showering, and throwing a 'Spidey can go back to work' party and inviting both the RvS and S4 departments lol.. Sad when you need a vacation from your time off work ! Or feel happy to be getting back to work in a day or two.

R&R would be nice....