Tuesday, February 20, 2007

Mounting ISO images

http://www.linuxquestions.org/questions/showthread.php?t=277643

Do this:
Code:
md /mnt/iso

Code:
mount -o loop -t iso9660 .iso /mnt/iso
Try this...

mount -t iso9660 -o ro,loop=/dev/loop0 /home/ste/cd.iso /mnt/iso

Tuesday, February 13, 2007

Combining multiple PDF files in one

http://www.debianadmin.com/combine-multiple-pdfs-into-one-file-in-ubuntu-linux.html
http://www.newsforge.com/article.pl?sid=04/06/09/1844259

Preparing Your system
sudo apt-get install gs pdftk
(Merge, merging, cancatenate, concatenating pdf files)

Now we will see one example how to combine pdf files let us assume we have 1.pdf,2.pdf,3.pdf files and now we need to cobmine this files using the following command:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH 1.pdf 2.pdf 3.pdf
Another different approach:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
In the above command after “-sOUTPUTFILE=” type whatever name you want for the merged file (don’t forget to append .pdf to the end of the file name). Rename “1.pdf 2.pdf 3.pdf” to whatever your file names are (separate your file names with a space).
After you run the above command, a new PDF file called combinedpdf.pdf will be created with your individual files merged according to the order you list.
The same can be done with PS files:
gs -sDEVICE=pswrite -sOutputFile=output.ps -dNOPAUSE -dBATCH file1.ps file2.ps file3.ps
If you want to know more options available for gs command check man page

Tags: , , , , , , ,

Merge PDF files with pdftk
Having some of my manuals/documentations downloaded in several separated pdf files, I wanted to merge them into a single file.

First, I installed pdftk

# apt-get install pdftk

In Ubuntu 18.04 the previous command won't work. Instead:

sudo snap install pdftk

Then, I merged the files into a single file

$ pdftk   file1.pdf    file2.pdf    file3.pdf   cat  output   file123.pdf

When the files to be merged is a lot, I edited the file list in a text editor (or, when I am in a good mood, using ls & awk & sed) then combine it with the script found here

$ cat stdin_pdf.sh
#!/bin/sh
# combine PDFs; pass filenames in on stdin;
# pass output to stdout
read input_filenames
pdftk $input_filenames cat output -

$ cat filelist|./stdin_pdf.sh>mergedfile.pdf

So far, I am satisfied with the result. (link)

Saturday, February 10, 2007

Switching between different keyboard mappings

http://www2.blogger.com/post-create.g?blogID=4592078922113874023
setxkbmap us_intl # to write Spanish stuff
setxkbmap us # to write English stuff and code
setxkbmap es # to write Spanish stuff and code

Sunday, February 04, 2007

Saturday, February 03, 2007

Lenovo T60 with fedora core 6

http://www.thinkwiki.org/wiki/Installing_Fedora_Core_6_on_a_ThinkPad_T60

Lenovo Thinkpad T60

http://statgen.ncsu.edu/~jdstarme/fc5_on_t60.txt

I am much indebted to all of the great information there is already on the
internet about how to get Fedora Core 5 (FC5) working on a ThinkPad T60.
In this document I attempt to cite the sources where I got various bits
of information, however, I may have missed a few. To those authors I offer
an apology and ask that you send me an email! (jdstarme_at_ncsu.edu)

Special thanks to Tom Davidson for sending me feedback and good suggestions
for revisions to this document.


System:

Lenovo Thinkpad T60

Intel Core Duo T2500 2.00 GHz
1 GB RAM
100 GB Hard Drive (SATA150)
ATI Mobility Radeon X1400 M54
VGA video out


0) Boot into windows and make sure everything is working the way. Make
the rescue CDs (there are 7 total - oh, and it is not obvious how to make
the back up CDs. However, if you search around enough, you'll figure it out.)


1) Download the latest System Rescue CD from

www.sysrescd.org

I ended up with: SystemRescueCD-x86-0.2.19

(I tried using the version I made long ago when I installed FC2, but the
graphical partitioning program, qtparted, would not recognize the new
SATA type hard-drive)

In order to burn the ISO, I had to download something called "Nero 7". After
fiddling around for a bit, I figured out how to use it to burn the ISO to
a CD.

Reboot with the new CD in the drive

at the prompt, type: run_qtparted

Select the main partition and re-size it to about 20GB then commit your change.
I was unable to create all of the sub-partitions I usually make for linux.
However, I was able to do that when I installed FC5.


2) Boot up with FC5 disk1 and press return to begin installing. The old
problem (from FC2 days) of having to specify the hard-drive geometry in order
to get the system to dual boot no longer exists, so you
don't have to worry about specifying anything on the command line.

NOTE: this destroys part of the ThinkVantage buttons functionality. You can
still use the ThinkVantage button to get into the bios, but you can no
longer use it to restore and recover the system (good thing you made those
backup CDs?) This really doesn't bother me that much since I only
intend to use windows once in a blue moon and the only thing I'm really
concerned about being able to fix without reformatting the whole drive is
the linux stuff and the FC5 distribution comes with a rescue mode...


I did my own partitioning:

/dev/sda
/dev/sda1 ntfs 19807 1 2525
/dev/sda3 /boot ext3 102 2526 2538
/dev/sda4 extended70473 2539 11522
/dev/sda5 / ext3 10001 2539 3813
/dev/sda6 /usr/local ext3 4997 3814 4450
/dev/sda7 swap 2000 4451 4705
/dev/sda8 /home ext3 53474 4706 11522
Free FS 6 11523 11523
/dev/sda2 vfat 5006 11523 12161


3) Reboot (note, I did not have the problem with the system hanging on the
initial boot that was mentioned on the think-wiki site
http://www.thinkwiki.org/wiki/Installing_Fedora_Core_5_on_a_ThinkPad_T60),

The monitor was not detected
(it is a 14.1" TFT display with 1400x1050 resolution)

Set the monitor to LCD Panel 1400x1050 (generic).

THINGS THAT WORKED OUT OF THE BOX

- SMP (symmetrical multiprocessing support for the core duo)
- Sound (just remember to turn up the volume so you can hear the sound!)
- USB
- Suspend (after an update to (at least) kernel version 2.6.17-1.2139_FC5.
This means that suspend will not work immediately after a fresh
install. However, once you run "yum update", everything should
work fine.)

A NOTE ON SUSPEND: sometimes the wireless daemon or the
network-manager daemon is dead when you bring the computer back to
life. To remedy, just select System->Administration->Services
and then stop and start whichever daemon died.


After rebooting and verifying that I could boot into Windows XP,
I booted back into Fedora and updated the installed packages:

shell# yum update

This took forever and a day over my painfully slow DSL provided by BellSouth.

Getting the the thinkpad buttons to display information on the monitor only
required:

a)
shell# yum install tpb

b)
and then a restart.


To get X programs (like xterm and xfig) to have white backgrounds...

edit the file: /etc/X11/Xresources

and then add the lines:

xterm*background: white
xterm*scrollBar: true

xfig*background: white
xfig*foreground: black

(be sure to end the file with a new line)

The changes will take effect after you log out and then log back in, or you
can cause them to take effect now with the command:

shell> xrdb /etx/X11/Xresources


To make X programs have readable fonts, I set the font for the xterm and
emacs to 7x14 (you can do this per program with the -fn 7x14 option)


3) Wireless

0: Get NetworkManger working: all you have to do for this is to start
the NetworkManger services. System->Administration->Services


1: Add the "ATrpms" repository for yum by adding the file:

atrpms.repo

to the directory: /etc/yum.repos.d/

and in this file I put the lines:

[atrpms]
name=Fedora Core $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/fc$releasever-$basearch/atrpms/stable
enabled=0

and then ran the commands:

shell# rpm --import http://ATrpms.net/RPM-GPG-KEY.atrpms

shell# yum --enablerepo=atrpm\* install ipw3945 ipw3945d
ipw3945-ucode ipw3945-kmdl-CURRENT_KERNEL_VERSION_FC5smp

where CURRENT_KERNEL_VRESION is the version of the kernel that you are running.
You can figure out the version you are running with the command:

shell> uname -a

and this will print out all kinds of information about your kernel. Your
kernel version should be something like 2.6.17-1.2174_FC5smp.



2: Get the wireless kernel modules working...

shell# /sbin/depmod -a (you only have to do this once, right after installing
the rpms)

shell# /sbin/modprobe ipw3945 (load the kernel module)
shell# /sbin/ipw3945d (start the wireless daemon)

and then the wireless networks appear in the NetworkManager applet.

However, on restart, the module is not automatically loaded. However, to
fix this, I took the "wireless" script from Jim Hall's page:
http://us.fdos.org/linux/laptops/tp-t60/

and removed the case where it checks for eth0, since I'm going to let
NetworkManager deal with wired vs. wireless connections. So here's
my /etc/init.d/wireless file:

#! /bin/bash
#
# wireless Bring up/down integrated wireless networking (ipw3945)
#
# chkconfig: 2345 90 10
# description: Activates/Deactivates eth1 wireless interface (ipw3945)
#
### BEGIN INIT INFO

# # ipw3945d --help
# usage: ipw3945d [--OPTION]
# options:
# --quiet Load silently (unless errors occur)
# --version Display version information
# --debug=value Specify debug level to print
# --dvals View possible debug values
# --foreground Do not fork to background
# --kill Kill any running ipw3945d instance and exit
# --help View this help message
# --isrunning Check if already running. Returns 0 if yes.


# See how we were called.
case "$1" in
start)
/sbin/ipw3945d --isrunning
if [ $? -eq 0 ] ; then
echo "ipw3945d already running"
exit 1
fi

modprobe ipw3945
/sbin/ipw3945d
#ifup eth1

echo "ipw3945d started .."
;;

stop)
/sbin/ipw3945d --isrunning
if [ $? -ne 0 ] ; then
echo "ipw3945d not running"
exit 1
fi

ifdown eth1
/sbin/ipw3945d --kill
rmmod ipw3945

echo "ipw3945d stopped .."
;;

restart)
$0 stop ; $0 start
;;
esac

Once you create this file, make sure you set the permissions on this
file so that everyone can execute it (i.e. chmod a+x) and then run the
chkconfig program:

shell# /sbin/chkconfig --add wireless

Since nine-times out of ten I'm going to be using a wireless network,
I selected: System->Administration->Network and edited eth0 so that it would
not attempt to activate on startup. NetworkManager does a fine job activating
eth0 if you plug in an ethernet cable.

NOTES: One thing that can mess up wireless is if you have added an entry for
eth1 in System->Administration->Network. If you have done this, just delete
the entry and if you have followed the previous steps, things should work.


4) Touchpad...

turn off tapping, actually tapping is pretty good on this machine (better
than on my old T42), but still, I find it annoying overall.

Back up the file: /etc/X11/xorg.conf
Edit the file: /etc/X11/xorg.conf
Add the line:

Option "SHMConfig" "on"

to the section for the "Synaptics" mouse. It should then look like....

Section "InputDevice"
Identifier "Synaptics"
Driver "synaptics"
Option "Device" "/dev/input/mice"
Option "Protocol" "auto-dev"
Option "Emulate3Buttons" "yes"
Option "SHMConfig" "on"
EndSection

Now reboot the computer...

You can test that your editing of the xorg.conf file worked with the command:

shell# synclient -l

You should see a listing of all of the parameters settings.

you can experiment with various settings by using the synclient program
on the command line. For example, to turn off tapping:

shell# synclient MaxTapTime=0

To make these changes permanent, add the commands to the Synaptics section
of the xorg.conf file. For example:

Section "InputDevice"
Identifier "Synaptics"
Driver "synaptics"
Option "Device" "/dev/input/mice"
Option "Protocol" "auto-dev"
Option "Emulate3Buttons" "yes"
Option "SHMConfig" "on"
Option "MaxTapTime" "0"
EndSection


I also turned off the "forward and reverse" thing that affected web browsing
by adding the line:

Option "BottomEdge" "5500"

to the same section in my xorg.conf file... So the final version looked
like this:

Section "InputDevice"
Identifier "Synaptics"
Driver "synaptics"
Option "Device" "/dev/input/mice"
Option "Protocol" "auto-dev"
Option "Emulate3Buttons" "yes"
Option "SHMConfig" "on"
Option "MaxTapTime" "0"
Option "BottomEdge" "5500"
EndSection


5) .bashrc

# .bashrc


# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions

alias cleanup="rm -f *~; ls"

alias emacs="emacs -fn 7x14"

alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"

export EDITOR="emacs -nw"
export GRACE_EDITOR=emacs

export CVS_RSH=ssh


6) An mp3 player. I know they are not Free, as in speech, but I have to be
able to play them, otherwise I can't rehearse for gigs. Bands always send me
their stuff as mp3s...

add the "livna" repository for yum by adding the the file:

livna.repo

to the directory: /ety/yum.repos.d/

and in this file, put the lines:

[livna]
name=Livna for Fedora Core $releasever - $basearch - Base
baseurl=
http://rpm.livna.org/fedora/$releasever/$basearch/
http://livna.cat.pdx.edu/fedora/$releasever/$basearch/
http://wftp.tu-chemnitz.de/pub/linux/livna/fedora/$releasever/$basearch/
http://ftp-stud.fht-esslingen.de/pub/Mirrors/rpm.livna.org/fedora/$releasever/$basearch/
failovermethod=priority
#mirrorlist=http://rpm.livna.org/mirrorlist-5
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-livna


import the GPG key...

shell# rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY


and install xmms with mp3 support...

shell# yum --enablerepo=livna install xmms-mp3 xmms-faad2


7) A DVD player...

shell# yum --enablerepo=livna install xine libdvdcss

(However, until you can get hardware support for video, it's going to drop
a lot of frames - so see the tips below for "Graphics Card".)


8) Graphics Card (everything (video playback, OpenGL rendering, etc)
works as of kernel 2.6.17-1.2174 and the fglrx driver version 8.28.8)

shell# yum --enablerepo=livna install kmod-fglrx-smp

shell# /usr/sbin/ati-fglrx-config-display enable

restarted.

and then selected "display" form the administration menu, and then configured
the hardware graphics card to "fglrx". I then restarted X.
This seems to have done the trick!

You can double check that things are going well by looking at:
System->Administration->ATI-fglrx



9) Suspend (If you are running a kernel older than 2.6.17-1.2139_FC5)

First, make sure the kernel module for the wireless card exists (if a new
kernel just came out, you may have to wait a few days).

a: get a newer kernel (version 2.6.17-1.2139_FC5 or higher)

shell# yum update

b: plug the computer into a wired network and reboot into the new kernel.

c: remove the old wireless stuff...

shell# yum remove ipw3945 ipw3945d ipw3945-ucode ipw3945-kmdl-OLD_KERNEL_VERSION_FC5smp
Removing : ipw3945-kmdl-2.6.16-1.2133_F ######################### [1/5]
Removing : ipw3945-firmware ######################### [2/5]
Removing : ipw3945d ######################### [3/5]
Removing : ipw3945 ######################### [4/5]
Removing : ipw3945-ucode ######################### [5/5]


d: install the newer wireless stuff...

shell# yum --enablerepo=atrpm\* install ipw3945 ipw3945d ipw3945-ucode ipw3945-kmdl-CURRENT_KERNEL_VERSION_FC5smp
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
ipw3945 i386 1.0.10-10.rhfc5.at atrpms 35 k
ipw3945-kmdl-2.6.17-1.2139_FC5smp i686 1.0.10-10.rhfc5.at atrpms 89 k
ipw3945-ucode noarch 1.13-1.at atrpms 65 k
ipw3945d i386 1.7.19-2.at atrpms 35 k
Installing for dependencies:
ieee80211-kmdl-2.6.17-1.2139_FC5smp i686 1.1.14-11.rhfc5.at atrpms 34 k

Transaction Summary
=============================================================================

e: get the wireless daemon running again

shell# /sbin/depmod -a
shell# /sbin/modprobe ipw3945 (load the kernel module)
shell# /sbin/ipw3945d (start the wireless daemon)

And reboot. To suspend the computer, select suspend from the System
menu. Do not select "Shut Down" and then click on the "suspend" button. For
some reason, that doesn't work.

I then modified my Power Management Preferences so that the laptop would
suspend when the lid is closed. Also, when running on battery, I set it so
that it would suspend the computer if is inactive for 30 minutes.






##################################################################
#### ######
#### HOW TO UPDATE THE KERNEL ONCE YOU HAVE EVERYTHING SET ######
#### ######
##################################################################


a: First make sure everything is updated:

shell# yum update --exclude kernel-smp

b: Make sure there are wireless RPMs for new version of the kernel on the
ATRpms site:

http://atrpms.net/dist/fc5/ipw3945/

c: Install the new kernel:

shell# yum update

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
kernel-smp i686 2.6.17-1.2157_FC5 updates 15 M
Removing:
kernel-smp i686 2.6.16-1.2133_FC5 installed 39 M
Removing for dependencies:
ieee80211-kmdl-2.6.16-1.2133_FC5smp i686 1.1.13-10.rhfc5.at installed 84 k

Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 2 Package(s)
Total download size: 15 M
Is this ok [y/N]: y
Is this ok [y/N]: y
Downloading Packages:
(1/1): kernel-smp-2.6.17- 100% |=========================| 15 MB 04:32
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Removing : kernel-smp ######################### [1/3]
Installing: kernel-smp ######################### [2/3]
Removing : ieee80211-kmdl-2.6.16-1.2133 ######################### [3/3]


d: plug the computer into a wired network and reboot into the new kernel.

c: remove the old wireless stuff... (replace "OLD_KERNEL_VERSION" with the
actual version number.)

shell# yum remove ipw3945 ipw3945d ipw3945-ucode ipw3945-kmdl-OLD_KERNEL_VERSION_FC5smp
Removing : ipw3945-kmdl-2.6.16-1.2133_F ######################### [1/5]
Removing : ipw3945-firmware ######################### [2/5]
Removing : ipw3945d ######################### [3/5]
Removing : ipw3945 ######################### [4/5]
Removing : ipw3945-ucode ######################### [5/5]


d: install the newer wireless stuff...

shell# yum --enablerepo=atrpm\* install ipw3945 ipw3945d ipw3945-ucode ipw3945-kmdl-CURRENT_KERNEL_VERSION_FC5smp


e: Get the wireless daemon running again

shell# /sbin/depmod -a
shell# /sbin/modprobe ipw3945 (load the kernel module)
shell# /sbin/ipw3945d (start the wireless daemon)

(at this point you should be able to disconnect the ethernet cable from the
computer and the wireless should kick in automatically)

g: update the ati driver (if you can)

shell# yum --enablerepo=livna update kmod-fglrx-smp

shell# /usr/sbin/ati-fglrx-config-display enable

g: reboot!

Everything should be working....

Friday, February 02, 2007

C Tutorial: Strings

(link to tutorial)

Defining Strings:
C has a character type, but no string type as such. Text is defined as a character array, that is as a table of single characters. The lack of a string type in C is quite a severe deficit for application programming, and was one of the main reasons for developing C++, which does have a string type.

There are no C instructions that will handle a string as a single variable in the way MVC or MOVE do. Instead, string functions like strcpy() or memcpy() implement loops that address each character one by one.

To declare a text string, specify a type of char and place the number of characters in the array in square brackets after the string name.

char volume[6];

This generates a table of six contiguous characters and an implied pointer to the first character. A detailed description of this pointer is given in Addressing a String.

Addressing Each Character in a String:

The string declared above is an array with six members, volume[0] through volume[5]. Each member is of type character. A character literal is enclosed in single apostrophes. Double quotes identify a string literal (character array), not a character. So 'x' is a one-byte character and "x" is a two-byte character array consisting of an 'x' followed by a null-byte.

You can also assign characters hex values. In particular, note that a null-byte (a byte with all bits set to zero) can be written either using an escape character (backslash) or as a hex value:

char zerobyte = '\0'; /*use escape character*/
char zerobyte = 0x00; /*use hex value*/

Both of the following lines assign the letter S to the first character in volume[], first using a character literal and then using the EBCDIC hex value.

volume[0] = 'S';
volume[0] = 0xe2;

Since C handles characters internally as short integers, you can do arithmetic with them. This is more than a party trick: the routines to convert between uppercase and lowercase letters simply add or subtract 'A' - 'a' to the character. The following line sets the second character in volume[] to T.

volume[1] = volume[0] + 1;

Addressing a String:

The implied pointer that C generates when you declare a character array has some special properties:

  • It has the string name (no subscripts);
  • It is a constant (you can't alter its value);
  • The sizeof() function returns the size of the array, not that of a pointer.
The memcpy() function copies the string at the second address to the string at the first address for a length specified by the third parameter. Memcpy() will accept volume as its first parameter, because volume is a pointer.

Memcpy() also will allow a string literal as its second parameter. String literals are enclosed in double apostrophes and always have a null byte of binary zeros appended to the end in memory.

memcpy(volume, "STRG01", sizeof(volume));

The memset() function sets all characters in a string to a padding byte. The following line sets all six characters of volume[] to S.

memset(volume, 'S', sizeof(volume));

Memcmp() compares two strings for the length specified in the third parameter. It returns zero if a match is found.

if (memcmp(volume, "STRG", 4) == 0)
{
ProcessStorageVolume(volume);
}
else;

Looping through a String using a Subscript:
The usual way to loop through an array is to use a variable as the subscript in a for or while loop. More details about loops are given in the Loop Tutorial.

int i;
char volume[6];

for (i = 0; i LT sizeof(volume); i++)
{
volume[i] = '0';
}

This code will load volume[] with '000000'. The loop is set to terminate when i is less than 6 because the subscripts go from 0 through 5.

Looping through a String using a Pointer:
Since you can't change value of the pointer generated automatically by C when you declare an array, you must declare your own pointer to loop through a string. Initialize it by copying the implied pointer.

char volume[6];
char *cptr;

for (i = 0, cptr = volume; i LT sizeof(volume); cptr++, i++)
{
*cptr = i;
}

Initializing a String:
You can set the initial value of a character array when you declare it by specifying a string literal. If the array is too small for the literal, the literal will be truncated. If the literal (including its null terminator) is smaller than the array, then the final characters in the array will be undefined. If you don't specify the size of the array, but do specify a literal, then C will set the array to the size of the literal, including the null terminator.

char volume[6] = "STRG01"; /* contains 'S', 'T', 'R', 'G', '0', '1' */
char volume[] = "STRG01": /* contains 'S', 'T', 'R', 'G', '0', '1', '\0' */

Null-terminated Strings:
C was developed for Unix and still assumes that text strings will be delimited by a null terminator, a byte containing binary zeros. That means that string functions like strcpy() and strcmp(), as well as those that use strings like sprintf(), will identify the length of the operation to be not the length of the array declared, but the length between the first character and the first null byte, wherever it is.

S0C4 abends on a mainframe are often caused by a string not being delimited by a null terminator. The following lines will format a message containing the value in volume[], by copying volume[] into a temporary field initialized with nulls, and using that as the string.

char volume[6], temp[7], buffer[20];
memset(temp, '\0', sizeof(temp));
memcpy(temp, volume, sizeof(volume));
sprintf(buffer, "Volume is %s", temp);

If you know the exact size of a text string, you can print it out safely by setting the minimum and maximum size to print.

printf(buffer, "Volume is %6.6s", volume);