[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] Orientação a objetos em Shell
From: |
Ivan lopes |
Subject: |
Re: [shell-script] Orientação a objetos em Shell |
Date: |
Mon, 19 Jun 2006 09:41:07 -0200 |
Concluo esse topico com um programa em bash orientado
a objetos, ou melhor emulado a objeto. Para mais informacao
fala direto comigo.
$ cat ClassDialog.v1.1
#$Id: ClassDialog.v1.1,v 1.1 2006/06/18 06:23:39 ivanczar Exp root $
# Class: ClassDialog
# -------------------------------------------------------------------------- #
# ----------------------------- Class: String ------------------------------ #
# -------------------------------------------------------------------------- #
String(){ obj_id=$1
eval "$id.$obj_id.set(){
eval \"$id.$obj_id.get(){
echo \$*
}\"
eval \"$id.$obj_id.writeln(){
$id.$obj_id.get | tr ':' '\134'
}\"
}"
eval "$id.$obj_id.append(){
$id.$obj_id.set \$*:n\$($id.$obj_id.get)
}"
}
Integer(){ obj_id=$1
eval "$id.$obj_id.value(){
eval \"$id.$obj_id(){
echo \$*
}\"
}"
}
# -------------------------------------------------------------------------- #
# ----------------------------- Class: MsgBox ------------------------------ #
# -------------------------------------------------------------------------- #
InitBox(){
# -- Attribute -- #
String title
String text
Integer height
Integer width
}
MsgBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--msgbox '\$($id.text.get)' \
\$($id.height) \$($id.width)\
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ----------------------------- Class: InfoBox ----------------------------- #
# -------------------------------------------------------------------------- #
InfoBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--infobox '\$($id.text.writeln)'\
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ---------------------------- Class: InputBox ----------------------------- #
# -------------------------------------------------------------------------- #
InputBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--inputbox '\$($id.text.get)' \
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# --------------------------- Class: passwordbox --------------------------- #
# -------------------------------------------------------------------------- #
PasswordBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--passwordbox '\$($id.text.get)' \
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ----------------------------- Class: TextBox ----------------------------- #
# -------------------------------------------------------------------------- #
TextBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--textbox '\$($id.text.get)' \
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ----------------------------- Class: TailBox ----------------------------- #
# -------------------------------------------------------------------------- #
TailBox.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--tailbox '\$($id.text.get)' \
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ---------------------------- Class TailBoxbg ----------------------------- #
# -------------------------------------------------------------------------- #
TailBoxBg.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)'\
--tailboxbg '\$($id.text.get)' \
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ------------------------------ Class: YesNo ------------------------------ #
# -------------------------------------------------------------------------- #
YesNo.new() { id=$1;this=$1
InitBox # inicialize variables.
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--yesno '\$($id.text.writeln)'\
\$($id.height) \$($id.width) \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ------------------------------ Class: Menu ------------------------------- #
# -------------------------------------------------------------------------- #
Menu.new() { id=$1;this=$1
InitBox # inicialize variables.
Integer line
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--menu '\$($id.text.get)' \
\$($id.height) \$($id.width) \$($id.line)\
\${mLIST[*]} \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ------------------------------- RadioList -------------------------------- #
# -------------------------------------------------------------------------- #
RadioList.new() { id=$1;this=$1
InitBox # inicialize variables.
Integer line
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--radiolist '\$($id.text.get)' \
\$($id.height) \$($id.width) \$($id.line)\
\${rLIST[*]} \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ---------------------------- Class: CheckList ---------------------------- #
# -------------------------------------------------------------------------- #
CheckList.new() { id=$1;this=$1
InitBox # inicialize variables.
Integer line
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--checklist '\$($id.text.get)' \
\$($id.height) \$($id.width) \$($id.line)\
\${cLIST[*]} \
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
# -------------------------------------------------------------------------- #
# ----------------------------- Class: Gauge ----------------------------- #
# -------------------------------------------------------------------------- #
Gauge.new() { id=$1;this=$1
InitBox # inicialize variables.
Integer progressbar
LINE_CMD=" \
\$DIALOG \$OPT \
--title '\$($id.title.get)' \
--gauge '\$($id.text.get)' \
\$($id.height) \$($id.width) \$($id.progressbar)\
"
eval "$id.execute() {
echo \"$LINE_CMD\" | sed \"s;[ ]\+; ;g\"
}"
}
$ cat
#!/bin/bash project-install.sh
# Universidade Federal Do Rio de Jnaneiro
# file: project-install.sh
# author: Ivan carlso Da Silva Lopes
# $Id:$
# program a gerador de janelas `wedget'
DIALOG=dialog
# load oo shell functions
. ./ClassDialog.v1.1
TITLE="2 2.1.0-beta Install A.I - CZAR [ REDES NEURAIS ]"
OPT="--stdout --backtitle '$TITLE'"
# size screen
rows=$(tput lines)
cols=$(tput cols)
Menu.new menu
$this.title.set Instalador
$this.text.set Selecione a opcao desejada:
$this.height.value 0
$this.width.value 0
$this.line.value 0
mLIST=(1 Instalar
2 Compilar
3 Debugar
4 Configurar
5 sobre
)
D_OUT=$(menu.execute| sh)
menu.execute | sh
conclusao:
...
--
[ ]'s
Ivan Carlos Da Silva Lopes
Engenheiro Eletronico e Computacao
UFRJ