in the name of zero

March 16, 2006

academic sidetrack

hectic days till the semester ends for sure. one thing, i’m beginning to feel the pressure in my database class though not that much yet. our teacher started a forum in our eclass where my classmates could share new insights about foxpro and they’ve been very vocal about their achievements. lots of sharing, teaching and asking going on in there.

i went home yesterday rather tired because our group spent the later part of the afternoon till about 7:30 making things work in our foxpro project. i honestly didnt knew anything about foxpro except the obvious, which is to drag and drop widgets onto a form. felt rather pathetic. i usually crack under pressure but yesterday was ok. jokes always lighten the mood and i’m lucky that my group mates were boys and my friends. we could cuss and tell green jokes to our hearts delight.. because there where no girls around. (but then that was also a disadvantage). i managed somehow. (but the foxpro project was still the same. no improvements whatsoever) i hope my groupmates won’t get angry at me.


nothing much on the hobby side. but this was interesting and i really had fun trying to make it work. it’s a generic __printf() function that accepts variable arguments and constructs a string based on user format. sadly, the putch() and puts() functions i made didn’t scale very well in terms of printing variables with a specified format, hence this function. i’m really screwed on this one. count: 5 tabs max.

#include 
void  __printf(const char *format, …)
{
        int c;
        int d;
        char buf[50];
        char *sptr;
	
        va_list arglist;
        va_start(arglist,  format); 
	
        while((c = *format++) != 0) {
                if (c != ‘%’) {
                        putch(c);
                } else {
                        c = *format++;
                        switch (c) {
                                case ‘x’: /* base 16 */
                                case ‘d’: /* base 10 */
                                        d = va_arg(arglist, int);
                                        __itoa(buf, c, d);
                                        sptr = buf;
                                        goto stringy;
                                        break;
                                case ’s’: /* char* */
                                        sptr = va_arg(arglist, char *);
                                stringy:
                                        puts(sptr);
                                        break;
                                default:
                                        va_arg(arglist, void*);
                                        break;
                        }
                }
        }
        va_end(arglist);
}

as you noticed, it only has formatting for decimals (%d), hexadecimals (%x) and strings (%s). when it encounters formatting other than those three, it doesn’t do anything except move the current va_arg pointer to the next argument and continue parsing. __itoa() is also a defined function and it’s purpose is to convert a number into it’s character counterpart.

now i can do something like __printf(”%d %x %s\n”, 0x8f, 143, “stephanie”); in the kernel sources. convenient.

Comments »

The URI to TrackBack this entry is: http://gnurbs.blogsome.com/2006/03/16/academic-sidetrack/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here