quinta-feira, 16 de setembro de 2010

Selection Sort in PASCAL

PROGRAM Selection_Sort;

CONST len = 12;

TYPE intarray = ARRAY[1..len] OF INTEGER;
 
FUNCTION ssort (A: intarray): intarray;
VAR
 at, i, j, smaller, tmp: integer;
 newarray: intarray;
BEGIN
  { copy array }
  FOR i:=1 TO len DO
   newarray[i] := A[i];

  { sort }
  FOR i:=1 TO len-1 DO
  BEGIN
   smaller := newarray[i];
   at   := i;
   FOR j:=i+1 TO len DO
   BEGIN
    IF newarray[j] < smaller THEN
    BEGIN
     smaller := newarray[j];
     at  := j;
    END
   END; { FOR j:=i+1 }

   IF newarray[i] > smaller THEN
   BEGIN { swap } 
    tmp := newarray[i];
    newarray[i] := smaller;
    newarray[at] := tmp;
   END
  END; { FOR i:= 0 }
  ssort := newarray;
END;

{ MAIN }
VAR
 a1, a2: intarray;
 buf, i: integer;

BEGIN
 { read array }
 FOR i:=1 TO len DO
 BEGIN
  writeln ('Enter a number');
  readln (buf);
  a1[i] := buf; 
 END;

 { print a1 }
 FOR i:=1 TO len DO
 BEGIN
  write(a1[i], ' ');
 END;
 writeln;

 { sort }
 a2 := ssort (a1);

 { print sorted a2}
 FOR i:=1 TO len DO
 BEGIN
  write(a2[i], ' ');
 END;
 writeln;
END.

segunda-feira, 30 de agosto de 2010

compiling the kernel

#!/bin/bash

# This script will download, check, compile and install modules of a chosen kernel
# at a setted directory. You must suply your password for root needed
# actions
 
# set variables
VERSION='2.6.35.4' # what is the kernel version
UNPACKDIR=/usr/src/ # where to unpack
EXTENSION=tar.bz2 # the kernel extension
RC=1 # this will be incremented at every compile
TARGET=/home/geckos/projects/goot # where to copy kernel
T_ROOT=${TARGET}/root # where to install modules
# stop here

SRC=linux-${VERSION}
SRCDIR=${UNPACKDIR}${SRC}
SRCFILE="${SRC}.${EXTENSION}"
CHECKSUM="${SRCFILE}.sign"
LINUX_URL="ftp://ftp.kernel.org/pub/linux/kernel/v2.6"
MAKEOPTION="menuconfig"

for ARG in $@; do
 case $ARG in
 makeopt=*) 
  MAKEOPTION=`echo $ARG | cut -f2 -d=`
 ;;
 unpack)
  sudo rm ${SRCDIR} -r
 ;;
 download)
  rm ${SRCFILE} ${CHECKSUM}
 ;;
 esac
done
  
# check source
chk_src () {
 echo "Checking source ..."
 if [ ! -d "${SRCDIR}" ]; then
  if [ ! -r "${SRCFILE}" ]; then
   wget -c "${LINUX_URL}/${SRCFILE}" || return 1
  fi
  if [ ! -r "${CHECKSUM}" ]; then
   wget -c "${LINUX_URL}/${CHECKSUM}" || return 1

  fi
  gpg2 --keyserver wwwkeys.pgp.net --recv-keys 0x517D0F0E 
  gpg2 --verify ${CHECKSUM} ${SRCFILE} || return 1 
  sudo tar vxf ${SRCFILE} -C ${UNPACKDIR} && return 0 || return 1
 fi
 echo "DONE"
 return 0
}

# build kernel
build () {
 echo "Starting build ..."
 # to install modules at target
 export INSTALL_MOD_PATH=${T_ROOT}
 { sudo make -C ${SRCDIR} mrproper ; } &&
 { sudo make -C ${SRCDIR} ${MAKEOPTION}; } &&
 { sudo make -C ${SRCDIR}; } &&
 { sudo make -C ${SRCDIR} modules_install; } || return 1;
 echo "DONE"
}

# copy files
cpy_files () {
 echo "Copying files..."
 cp ${SRCDIR}/arch/x86/boot/bzImage ${TARGET}vmlinuz-${VERSION} -v;
 cp ${SRCDIR}/.config ${TARGET}config-${VERSION} -v;
 echo "DONE"
}

# increment the RC of this file at every execution 
inc_rc () {
 N=`sed -n 's|^RC=\([0-9]\{1,2\}\)$|\1|p' $0`
 let N++
 sed -e "s|^RC=.*$|RC=$N|" -i $0
}

# main
echo "Start.."
{
 chk_src &&
 build &&
 cpy_files &&
 inc_rc
} &&
echo "Finish" || echo "Fails"

quinta-feira, 26 de agosto de 2010

I like pencil

I bought a new pencil today. Lost the last one so
I have no choise. Also I install slackware 13
(long time ago) at a flash drive and yesterday I
build a boot cd for it based on slackware 13 disk 1
cd. I mix the initrd of flash drive installation
with the slack cd, keeping only the kernels and
isolinux directories on new cd. The final iso gets
only 16mb and with root=/dev/disk parameters can boot a
lot stuff. :-)

terça-feira, 17 de agosto de 2010

I want the POSIX guide book :-P

I want this

Linked list API

Well, working on a general linked list API.
... note: I guess this will be never released, because I'm so lazzyyy! :-(

sexta-feira, 13 de agosto de 2010

segunda-feira, 19 de julho de 2010

The university is pissing me off!

I need a job.. All I can find is web developer.. PHP, SQL, Oracle etc..
I want a cool job...
I want to understand firmware, assembly, kernel, microcontrolers...
I don't want to create a new facebook/twitter/orkut... (angry)