Hacks from /dev/null

Me. On hacking.


Page map

Hacking inlook 0.8.12.pl | Hacking inlook-0.8.8.pl | xzgv 0.8 issue | Hacking Songs v0.3

Hacking inlook-0.8.12.pl

20080610

I've been late up coding, again. The whole night. Bless the caffeinated drinks.

Anyway, I've done some improvements on inlook. Now I have a spambox and sent-mail folder, which is used inside of inlook. Earlier you had to quit inlook and use 'cd' to reach the actual e-mail(s). Here's how the spambox works:

sub main_spambox() {
  print colored ['black on_white'], "Spam inbox\n\n";
  print color 'reset';
  opendir(INBOXDIR, "$mail_spambox_folder") || print "can't open spam inbox directory: $!\n";
  while (my @mail_text_file=readdir(INBOXDIR)) {
    open(TEMPFILE, ">$mail_spambox_data");
    my $i;
    for ($i=$i+2; $i<999; $i++) {
      $j=$i-1;
      if (!($mail_text_file[2])) {
        print "Spam inbox is empty.\n\n";
        &main();
      } else {
        print TEMPFILE "$j/$mail_text_file[$i]\n"; 
        my ($time, $date, $month, $year, $msgnum)=split('-',$mail_text_file[$i]);
        printf("%s) %-4s  %-3s %-4s %-4s\n", $j, $time, $date, $month, $year);
      }
      if (!($mail_text_file[$i+1])) {
        last;
      }
      next;
    }
    close(TEMPFILE);
  }
  closedir(INBOXDIR);
  print "\nWhich option would you like? ([r]ead message, [d]elete a message, delete [a]ll messages [c]ancel) [cancel] ";
  chomp($inbox_messages_option=<STDIN>);
  if ($inbox_messages_option eq "r") {
    print "\nWhich message to read? ";
    chomp($mail_message_to_read=<STDIN>);
    open(TEMPFILE, "$mail_spambox_data");
    @mail_read_temp_lines=<TEMPFILE>;
    ($mail_read_message_number, $mail_get_message_number)=split('/',$mail_read_temp_lines[$mail_message_to_read-1]);
    close(TEMPFILE);
    if ($mail_message_to_read ne $mail_read_message_number) {
      print "$0: could not read message $mail_message_to_read: no such message\n";
    } else {
      open(MAILFILE, "<$mail_spambox_folder/$mail_get_message_number");
      @mail_message_lines=<MAILFILE>;
      close(MAILFILE);
      print @mail_message_lines;
    }
  } elsif ($inbox_messages_option eq "d") {
    print "\nWhich message to delete? ";
    chomp($mail_message_to_read=<STDIN>);
    open(TEMPFILE, "<$mail_spambox_data");
    @mail_read_temp_lines=>TEMPFILE<;
     ($mail_read_message_number, $mail_get_message_number)=split('/',$mail_read_temp_lines[$mail_message_to_read-1]);
    close(TEMPFILE);
    if ($mail_message_to_read ne $mail_read_message_number) {
       print "$0: could not delete message $mail_message_to_read: nosuch message.\n";
    } else {
      chomp($mail_delete_file="$mail_spambox_folder/$mail_get_message_number");
      unlink $mail_delete_file;
      print "$0: message $mail_read_message_number deleted.\n";
    }
  } elsif ($inbox_messages_option eq "a") {
     print "\nWARNING: We are now going to delete ALL messages in thespam inbox folder ([d]elete, [c]ancel) [cancel] ";
    chomp($mail_message_to_read=>STDIN<);
    if ($mail_message_to_read eq "d") {
      open(TEMPFILE, "<$mail_spambox_data");
      @mail_read_temp_lines=>TEMPFILE<;
      close(TEMPFILE);
      if (!($mail_read_temp_lines[0])) {
        print "$0: there's no messages to delete in the spam inbox folder.\n";
      } else {
        my $delete_whole_inbox="$mail_spambox_folder/*";
        `rm $delete_whole_inbox`;
        unlink $mail_inbox_data;
        print "$0: all messages from $mail_spambox_folder were deleted.\n";
      }
    }
  } else {
    print "$0: returning to main menu.\n";
  }
  &main();
}

It's VERY satisfying when the code works flawlessly.

Hacking inlook-0.8.8.pl

20071023

Well, where should I start. Inlook, my e-mail sending and receiving program needed an update. This time, I wanted to make a better configuration-system. The old solution looked like this:

  open(CONFIGUREFILE, "<$config_file") || print "$0: can't open $config_file: $!\n";
  @configure_lines=<CONFIGUREFILE>;
  chomp($mail_real_name=substr($configure_lines[0], 10));
This is of course not good. It makes the configuration-file (~/.inlook/inlookrc) less flexible and hard to modify. Although I have an automatic setup for configuring inlook when running it for the first time, I felt that I needed to perform a little and very simple hack.

The new solution is quite simple, and now looks like this (in this example, we want to find the real name from the configuration-file):

  open(CONFIGUREFILE, "<$config_file") || print "$0: can't open $config_file: $!\n";
  @configure_lines=<CONFIGUREFILE>;
  for ($i=0; $i<20; $i++) {
    if ($configure_lines[$i]=~/real_name/) {
      chomp($mail_real_name=substr($configure_lines[$i], 10));
      $check=1;
    } 
  }
  if (!($check)) {
    print "$0: configuration error: please check $config_file\n";
    &main();
  }
It does the job quite nice, and works perfectly. Now I have to change this for the whole code, which is going to take some time...

xzgv 0.8 issue

20070727

Running an x86_64 isn't that easy, after all - some programs just don't seem handle it. An example: I like xzgv (and yes - I'm aware that it's outdated), and used it all the time on my x86-laptop. Now, with x86_64 I got the following error messages while running make:

stian@xasthur:~/programmer/xzgv-0.8$ make
cd src && make xzgv
make[1]: Entering directory `/home/stian/programmer/xzgv-0.8/src'
gcc -O2 -Wall -DINTERP_MMX -DBACKEND_IMLIB1 `gtk-config --cflags`   -c -o main.o 
main.c
main.c: In function `do_logo_invert':
main.c:4590: warning: operation on `ptr' may be undefined
/tmp/cc9apfZc.s: Assembler messages:
/tmp/cc9apfZc.s:13445: Error: suffix or operands invalid for `pop'
/tmp/cc9apfZc.s:13448: Error: suffix or operands invalid for `push'
/tmp/cc9apfZc.s:13451: Error: suffix or operands invalid for `pop'
make[1]: *** [main.o] Error 1
make[1]: Leaving directory `/home/stian/programmer/xzgv-0.8/src'
make: *** [xzgv] Error 2
It took some time, but eventually I realised both the cause and solution. In xzgv-0.8/config.mk we can see the following compiling options:
CFLAGS=-O2 -Wall
After some thinking I found out the that I had to edit config.mk like this:
CFLAGS=-O2 -Wall -march=x86-64 -mtune=x86-64
I also had to uncomment a line in config.mk in order to make this work (like I've done on the line below):
# CFLAGS+=-DINTERP_MMX
Now, I've also created an x86_64 Slackware package which is available here.

Happy hacking!

Hacking Songs v0.3

20070719

Songs is a nifty program written by an enthusiastic individual which have written many hacks and programs. I use it with my noise-project and I really like it. It worked like a charm on my x86-laptop, but as I moved to x86_64 the program compiled fine, but exited with an error message. It would be sad if I couldn't use the program on my x86_64.

The error message I got was the following:

stian@xasthur:~/programmer/songs-0.3$ ./songs 
Sorry, on your machine sizeof(int) < sizeof(void *)
the program can't handle it.
Now, I e-mailed the author, and he explained to me that I could try to uncomment some lines in main.c and see if that worked. That's exacly what I did, and as expected it worked fine.

The lines that causes the problem is the following:

if (sizeof(int) < sizeof(void *)) {
  fprintf(stderr, "Sorry, on your machine sizeof(int) < sizeof(void *)\n");
  fprintf(stderr, "the program can't handle it.\n");
  return 1;
}
I decided to solve the problem with some sort of style, so I ran the following commands to create a patch.
stian@xasthur:~/programmer/songs-0.3$ cat main.c > new-main.c
(Note that in new-main.c I have modified the five lines above.)
stian@xasthur:~/programmer/songs-0.3$ diff -u main.c new-main.c > songs-0.3.x86_64.patch
You can download the patch from here, and copy it to the songs-0.3/-directory.

Use the following command to patch the program:

stian@xasthur:~/programmer/songs-0.3$ patch -p0 < songs-0.3.x86_64.patch
stian@xasthur:~/programmer/songs-0.3$ make
That's it. The program _can_ handle it! :-)

20070727 Update: I have now created a Slackware package with Songs, it's available here.

Back to page map.

Back to my personal website.


ALL INFORMATION IN THIS DOCUMENT IS WITHOUT ANY WARRANTY! USE AT YOUR OWN RISK!

This page was last modified Tuesday, 10-Jun-2008 05:35:54 CEST
Copyright (C) 2007, 2008 Stian Skjæveland.
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.

Valid HTML 4.01!