NTS

Have a T-Shirt made that shouts:

I don’t care about spelling unless it involves Vi !

Days progress

Null (0)
Eines (1)
Zwei (2)
Drei (3)
Vier (4) – tis one hard to remember lol
Fuenf (5) – properly fünf
Sechs (6)
Sieben (7)
Acht (8)
Neun (9)
Zehn (10)
Elf (11)
Zwoelf (12) – properly zwölf
Dreizehn (13)
Vierzehn (14)
Fuenfzehn (15) – properly fünfzehn
Sechszehn (16)
Siebzehn (17)
Achtzehn (18)
Neunzehn (19)
Zwozig (20) – I wonder if Zweizig would be interrupted as 20. Seems that ‘zwo’ seems to be used in place of Zwei at times to avoid confusing people.. Probably foreigners lol.
einetausend (1000)

For the most part German numbers seem pretty logical and seem to follow the same convention style as English numbers. I.e. 15 in English is Fift-Teen, rymes with 5th (fifth, Viertel) a fraction and teen being a fairly standard suffix for any thing between ( > 10 && < 20 ). So Siebzehn makes sense for Seventeen. Its more or less 'Seven Ten' which is basically what a 17 is. Or maybe it could just be my backwards mind that finds this all so logical ! hehe I dunno. Larger numbers seen to follow a similar style but with a und (and) in the middle and changing suffixes as you got, teens, twenties, thirties and so on. But each comparable German suffix seems to end in ‘zig’ except for Dreissig (dreißig, thirty). Much like how in English many of then have a ‘ty’ suffix often preceded by an r or ir. Fourty “four’ity” (Vierundvierzig), Seventy (Siebundsiebzig), or Fifty (Fuenfundfuenfzig). Quiet logical imho. Sechhundertzweiundzwanzig (626) looks about right to me aside from being a mouth full but who says I know any thing. Six hundred Two and Twenty – logical. It seems while we use a decimal point . In German a comma , seems to be used and pronouced. I wonder how 600,400.01 would be spoken if 3.04 would be like ‘Drei Komma null vier’. I think thats some what grammatically correct. ‘Komma’ always seems to be capitalized, the first word being capitalized the way I wrote it is probably an English’ism. I’ve yet to learn much for German grammar and punctuation. Instead concentrating on basic spoken communication and reading. I’ll worry more about it when I have a rough understanding of how words work out, then I’ll worry more about sentences and phases. So far though the only languages I know my way around well is C and English +S lol sorry to say but I think its in that order 😛

read file

This is a little thing I’ve been working on this month. Its made to simulate the behavior of ‘cat file’ and ‘head -n’ / ‘tail -n’ more or less scratch a little itch. It works very simple as its supposed to be simple. It parses arguments taking a count to its -t and -b switches. It looks through argv till it finds a file to open. It’ll read the entire file out, if it’s given the -t switch it will read out up to the count its given. If its given the -b switch, it will read the entire file. Store the location of every newline in a linked-list. Then rewind the list, seek to the specified location (plus padding) and print out the end of the remainder of the file.

Heres a straight copy & paste of it. Portability wise it assumes that the file is in the correct format and requires a number of functions that first appeared in BSD 4.x, namely getopts, fgetln, and err/errx. It also presumes that their should be enough room to store the location of every newline in the file within memory. So if one only has 64K of RAM, it might be a problem to read a few files xD.

I can’t say if its well written or not… I don’t know of any program with my system that does exactly this other then what this simulates. Rather then wrap around cat/head/tail using system() or including the sources I worked through this as a learning experience. Its more or less written in the style I prefer, the type on a line of its own bit in function declarations is the only ‘real’ part of it stemming from my occasional reads of stuff in /usr/src alone.

/*
* rf read file to standard out
*/

// 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 <unistd.h>


static void readall( FILE *, int );
static void readtop( FILE *, int );
static int readbottom( FILE *, int );
static void usage( void );

struct lnpos {
long nl;
struct lnpos *next;
};

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

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

extern char *optarg;
extern int optind;
extern int optopt;
extern int opterr;
extern int optreset;

while ( (ch = getopt(argc, argv, "b:t:")) != -1 ) {
switch (ch) {
case 'b':
b_flag++;
lncnt = strtol(optarg, &erptr, 10);
if ( *erptr || lncnt <= 0 )
errx( 1, "Improper line count -- %s", optarg );
break;
case 't':
t_flag++;
lncnt = strtol(optarg, &erptr, 10);
if ( *erptr || lncnt <= 0 )
errx( 1, "Improper line count -- %s", optarg );
break;
case '?':
default:
usage();
return 1;
}
argc -= optind;
argv += optind;
}


/* loop through cli args and find a file to open */
for ( int i = 0; i <= argc; i++ ) {
fp = fopen( argv[i], "r" );
if ( fp == NULL )
err( 1, "File does not exist or could not be opened "
"for reading -- %s", optarg );
}

if ( (t_flag < 1) && (b_flag < 1) ) {
readall( fp, lncnt );
} else if ( t_flag > 0 ) {
readtop( fp, lncnt );
} else if ( b_flag > 0 ) {
readbottom( fp, lncnt );
} else {
errx( 1, "flag processing failed" );
}

fclose( fp );
return 0;
}

/*
* print out an open file to standard output
*/

static void
readall( 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
readtop( 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" );
lncnt--;
}
}


/* Read n lines from the bottom of the file
* This function really should be broken up - but I have not learned how yet.
*/
static int
readbottom( FILE *fp, int lncnt ) {

char *cp;
int hmany = lncnt;
long nlnum = 0;
long where;
size_t error, rlen;

struct lnpos *root;
struct lnpos *cur;

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 nodes" );
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' ) {
nlnum++;
cur->nl = ftell( fp );
if ( cur->next != NULL )
cur = cur->next;
cur->next = malloc( sizeof(struct lnpos) );
if ( cur->next == NULL )
err( 1, "can't add nodes" );
cur = cur->next;
}
}

/* rewind our linked-list and seek b_flag + 1 segments short of the
* end of the list.
*/
cur = root->next;
hmany++;
while ( hmany < nlnum ) {
cur = cur->next;
nlnum--;

}

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

while ( lncnt && (cp = fgetln( fp, &rlen )) != NULL ) {
error = fwrite( cp, sizeof(char), rlen, stdout );
if ( error != rlen )
err( 1, "stdout" );
lncnt--;
cur = cur->next;
if ( cur->next == 0 )
return 0;
}
return 0;
}


static void
usage( void ) {
fprintf( stderr, "usage:n rf filen "
"rf [-t number lines from the top] filen "
"rf [ -b number of lines from the bottom ] [ file ]n" );
}


Any comments about the file it self or its design is much welcome by this moron who tries to teach him self.

Nice pair

Pioneer HDJ-1000 headphones /w ear-cup http://www.amazon.com/Pioneer-HDJ-1000-Headphones-ear-cup/dp/B0002DV7Z2

Temptational joke

Three Distros for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Steve Ballmer on his dark throne
In the Land of Redmond where the $hadow$ lie.
One distro to rule them all, One Ring to find them,
One distro to bring them all and in the darkness bind them
In the Land of Redmond where the $hadow$ lie.

There can only be one distro and its MicrosoftSUSE !

Sorrry, I couldn’t resist doing that just for the laughs !!!