rebellion
Utente Èlite
- Messaggi
- 1,596
- Reazioni
- 508
- Punteggio
- 117
@« MoMy » rivisto e corretto il database libreria, tipo se premevi il tasto elimina senza aver selezionato nessun record ti brasava l'intero database. adesso mi sembra definitivo:
alla fine ho capito tutto, mi rimane questo:
perchè esporta il contenuto del file nella variabile?
Codice:
#!/bin/bash
## controllo dipendenze
if [ ! -e "/usr/bin/zenity" ] || [ ! -e "/usr/bin/gtkdialog" ] ; then dip=""
if [ ! -e "/usr/bin/zenity" ] ; then dip=$dip" zenity" ; fi ; if [ ! -e "/usr/bin/gtkdialog" ] ; then dip=$dip" gtkdialog" ; fi
zenity --error --width=500 --height=100 --text="Errore: dipendenze non soddisfatte, installa $dip. Applicazione terminata." ; if [ $? -eq 1 ] ; then gnome-terminal --geometry=35x6 --hide-menubar --title="ERRORE dipndenze" -e 'bash -c "echo "" ; echo --------------------------;echo installa: '$dip'; echo --------------------------; echo app terminata, premi invio..; read"' ; fi
exit 0
fi
AGGIUNGI_LIBRO()
{
while [ "$sceltains" != "Cancel" ] && [ "$sceltains" != "abort" ]
do
I=$IFS ; IFS=""
for STATEMENTS in $(gtkdialog --program INSERIMENTO); do
eval $STATEMENTS
done
IFS=$I
if [ "$formato" = "" ]; then formato="brossura"; else formato=${formato##* }; fi
sceltains=$EXIT
if [ "$EXIT" = "OK" ] && ([ -n "$autore" ] && [ -n "$titolo" ])
then
if [ -z "$genere" ] ; then genere="-" ; fi ; if [ -z "$anno" ] ; then anno="-" ; fi ; if [ -z "$editore" ] ; then editore="-" ; fi ; if [ -z "$note" ] ; then note="-" ; fi
if [ -e "$dir" ] ; then
num=$(tail -1 "$dir" | awk -F "|" '{print$1}') ; lett=${num:0: -3} ; num=${num:1}
if [ "$num" -eq 999 ] ; then num=0 ; lett=$(printf "%d\n" \'$lett) ; lett=$((lett+1)); lett=$(printf "\x$(printf %x $lett)") ; else num=$((num+1)) ; fi
else
num="a000"
fi
if [ "${#num}" = 1 ] ; then num=$lett"00"$num ; elif [ "${#num}" = 2 ] ; then num=$lett"0"$num ; else num=$lett$num ; fi
titolo=$(echo $titolo) ; autore=$(echo $autore) ; genere=$(echo $genere) ; anno=$(echo $anno) ; editore=$(echo $editore) ; note=$(echo $note)
titolo=${titolo//|/¦} ; autore=${autore//|/¦} ; genere=${genere//|/¦} ; anno=${anno//|/¦} ; editore=${editore//|/¦} ; note=${note//|/¦}
echo $num"|"$titolo"|"$autore"|"$genere"|"$anno"|"$editore"|"$formato"|"$note >> "$dir"
fi
done
}
FIND_BOOK()
{
if [[ -n "$TARGET_ITEM" ]] && [ "${#TARGET_ITEM}" -ge 3 ]; then
if [ "$VAR_TITOLO" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $2}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
elif [ "$VAR_AUTORE" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $3}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
elif [ "$VAR_GENERE" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $4}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
elif [ "$VAR_ANNO" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $5}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
elif [ "$VAR_EDITORE" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $6}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
elif [ "$VAR_FORMATO" = true ] ; then
LINEA_FIND_=`eval cat "$_DATA_BASE_" | awk 'BEGIN { FS="|" } {print NR, $7}' | grep -i "$TARGET_ITEM" | sed "s/ .*$//g"`
_RESULT_PUBBL_=`for PRE_RESULT_ in $LINEA_FIND_; do sed -n ${PRE_RESULT_}p $_DATA_BASE_ ; done`
else
_RESULT_PUBBL_=`cat "$_DATA_BASE_" | grep -i "$TARGET_ITEM"`
fi
fi
echo "$_RESULT_PUBBL_"
}
CONFERMA_ELIMINA()
{
if [ -n "$CERCA" ] ; then var=$CERCA ; fi
if [ -n "$TABLE" ] ; then var=$TABLE ; fi
zenity --question --width=400 --height=100 --title="conferma eliminazione record $var"
if [ $? = 0 ] ; then
sed -i "/^$var/d" "$dir"
sed -i "/^$/d" "$dir"
fi
}
MODIFICA()
{
titolo=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$2}')
autore=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$3}')
genere=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$4}')
anno=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$5}')
editore=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$6}')
formato=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$7}')
note=$(cat "$dir" | grep "$CERCA" | awk -F "|" '{print$8}')
export MODIFICA='
<window title="Modifica record '"$CERCA"'">
<vbox>
<hbox>
<frame Titolo>
<entry max_length="25">
<default>'"$titolo"'</default>
<variable>tit</variable>
<width>300</width><height>30</height>
</entry>
</frame>
<frame Autore>
<entry max_length="25">
<default>'"$autore"'</default>
<variable>aut</variable>
<width>300</width><height>30</height>
</entry>
</frame>
</hbox>
<hbox>
<frame Genere>
<entry max_length="25">
<default>'"$genere"'</default>
<variable>gen</variable>
<width>300</width><height>30</height>
</entry>
</frame>
<frame Anno>
<entry max_length="4">
<default>'"$anno"'</default>
<variable>ann</variable>
<width>300</width><height>30</height>
</entry>
</frame>
</hbox>
<hbox>
<frame Editore>
<entry max_length="25">
<default>'"$editore"'</default>
<variable>edi</variable>
<width>300</width><height>30</height>
</entry>
</frame>
<frame Formato>
<entry max_length="25">
<default>'"$formato"'</default>
<variable>form</variable>
<width>300</width><height>30</height>
</entry>
</frame>
</hbox>
<hbox>
<frame Note>
<edit>
<default>'"$note"'</default>
<variable>not</variable>
<width>300</width><height>150</height>
</edit>
</frame>
</hbox>
<hbox>
<button cancel></button>
<button>
<label>Applica modifica</label>
</button>
</hbox>
</vbox>
</window>
'
I=$IFS ; IFS=""
for STATEMENTS in $(gtkdialog --program=MODIFICA); do
eval $STATEMENTS
done
if [ "$EXIT" = "Applica modifica" ] ; then
tit=$(echo $tit) ; aut=$(echo $aut) ; gen=$(echo $gen) ; ann=$(echo $ann) ; edi=$(echo $edi) ; form=$(echo $form) ; not=$(echo $not)
if [ -z "$gen" ] ; then gen="-" ; fi ; if [ -z "$ann" ] ; then ann="-" ; fi ; if [ -z "$edi" ] ; then edi="-" ; fi ; if [ -z "$not" ] ; then not="-" ; fi ; if [ -z "$tit" ] ; then tit="-" ; fi ; if [ -z "$aut" ] ; then aut="-" ; fi
tit=${tit//|/¦} ; aut=${aut//|/¦} ; gen=${gen//|/¦} ; ann=${ann//|/¦} ; edi=${edi//|/¦} ; not=${not//|/¦}
if [ "$form" != "brossura" ] && [ "$form" != "rilegato" ] && [ "$form" != "digitale" ] ; then form="brossura" ; fi
modif1=$CERCA"|"$titolo"|"$autore"|"$genere"|"$anno"|"$editore"|"$formato"|"$note
modif=$CERCA"|"$tit"|"$aut"|"$gen"|"$ann"|"$edi"|"$form"|"$not
sed -i "/$modif1/c $modif" "$dir"
fi
}
export dir=$(find /home/$USER -name 'database_libri')
if [ "$dir" = "" ] ; then
export dir="/home/$USER/database_libri"
fi
export _DATA_BASE_="$dir"
export -f FIND_BOOK
export -f AGGIUNGI_LIBRO
export -f CONFERMA_ELIMINA
export -f MODIFICA
export MAIN_DIALOG='
<window title="Libreria" window_position="1">
<vbox>
<frame Database>
<hbox>
<tree file-monitor="true" auto-refresh="true" selection-mode="1">
<width>750</width><height>350</height>
<variable>TABLE</variable>
<label>ID | Titolo | Autore | Genere | Anno | Editore | Formato | Note</label>
<input file>'$_DATA_BASE_'</input>
<action>refresh:TABLE</action>
</tree>
</hbox>
<hbox>
<button use-stock="true" label="gtk-add">
<action signal="clicked">AGGIUNGI_LIBRO</action>
<action>refresh:TABLE</action>
</button>
<button use-stock="true" label="gtk-remove">
<action>if [ "$TABLE" != "" ];then CONFERMA_ELIMINA;fi</action>
<action>refresh:TABLE</action>
</button>
</hbox>
</frame>
<frame Cerca Records per tipo>
<hbox>
<radiobutton>
<label>Generico</label>
<default>true</default>
<variable>VAR_GENERICO</variable>
</radiobutton>
<radiobutton>
<label>Titolo</label>
<variable>VAR_TITOLO</variable>
<action>refresh:TARGET_ITEM</action>
</radiobutton>
<radiobutton>
<label>Autore</label>
<variable>VAR_AUTORE</variable>
<action>refresh:TARGET_ITEM</action>
</radiobutton>
<radiobutton>
<label>Genere</label>
<variable>VAR_GENERE</variable>
</radiobutton>
<radiobutton>
<label>Anno</label>
<variable>VAR_ANNO</variable>
</radiobutton>
<radiobutton>
<label>Editore</label>
<variable>VAR_EDITORE</variable>
</radiobutton>
<radiobutton>
<label>Formato</label>
<variable>VAR_FORMATO</variable>
</radiobutton>
</hbox>
<hbox>
<tree rules-hint="true">
<width>750</width><height>150</height>
<variable>CERCA</variable>
<label>ID | Titolo | Autore | Genere | Anno | Editore | Formato | Note</label>
<input>"FIND_BOOK"</input>
</tree>
</hbox>
<hbox>
<text>
<label> Cerca Qui, Inserire pattern:</label>
</text>
<entry editable="true" space-expand="false">
<height>30</height> <width>400</width>
<variable>TARGET_ITEM</variable>
<action>"FIND_BOOK $TARGET_ITEM"</action>
<action>refresh:CERCA</action>
</entry>
</hbox>
<hbox>
<button>
<label>Modifica</label>
<action>if [ "$CERCA" != "" ];then MODIFICA;fi</action>
<action>refresh:TABLE</action>
<action>refresh:CERCA</action>
</button>
<button use-stock="true" label="gtk-remove">
<action>if [ "$CERCA" != "" ];then CONFERMA_ELIMINA;fi</action>
<action>refresh:TABLE</action>
<action>refresh:CERCA</action>
</button>
</hbox>
</frame>
<vbox>
<button>
<label> Esci </label>
<action type="exit">Exit</action>
</button>
</vbox>
</vbox>
</window>
'
export INSERIMENTO='
<window title="GESTIONE LIBRERIA">
<vbox>
<frame inserimento Titolo>
<entry max_length="25">
<variable>titolo</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame inserimento Autore>
<entry max_length="25">
<variable>autore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame inserimento Genere>
<entry max_length="25">
<variable>genere</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Inserimento Editore>
<entry max_length="25">
<variable>editore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Inserimento Anno 1a Pubblicazione>
<entry max_length="4">
<variable>anno</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Formato>
<table>
<width>450</width><height>110</height>
<variable>formato</variable>
<item>() brossura</item>
<item>() rilegato</item>
<item>() digitale</item>
</table>
</frame>
<frame inserimento Note>
<edit editable="true">
<variable>note</variable>
<width>450</width><height>150</height>
</edit>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
</window>
'
gtkdialog --program=MAIN_DIALOG
exit 0
Codice:
export _DATA_BASE_="$dir"