Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 19 Apr 2014, 05:35
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How do I put in external script into main?SOLVED
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
oldyeller


Joined: 15 Nov 2011
Posts: 723
Location: Mishawaka IN

PostPosted: Thu 27 Jun 2013, 12:19    Post subject:  How do I put in external script into main?SOLVED  

Hello Everyone,

I would like to know how I can take an external script in my workdir and add it into the main script?

Here is the codes

sans.sh is what I want to put into the main script.

Any help would be great thanks

Code:
 
#!/bin/sh
#sans.sh

WORKDIR="/usr/local/mannaeditor"


#define special Sans-12 font for Manna
READER_FONTSIZE=`cat $WORKDIR/font_size`
[ "$READER_FONTSIZE" = "" ] && READER_FONTSIZE="12" && echo "12" > $WORKDIR/font_size

echo "style \"specialsize\"
{
  font_name=\"sans $READER_FONTSIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"

export GTK2_RC_FILES="$WORKDIR/gtkrc_size:${HOME}/.gtkrc-2.0"

#define icon for current fontsize
if [ "$READER_FONTSIZE" = "12" ]; then
 FONTSIZE12_ICON='stock-id="gtk-apply"'
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "14" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON='stock-id="gtk-apply"'
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "16" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON='stock-id="gtk-apply"'
 FONTSIZE18_ICON=''
elif [ "$READER_FONTSIZE" = "18" ]; then
 FONTSIZE12_ICON=''
 FONTSIZE14_ICON=''
 FONTSIZE16_ICON=''
 FONTSIZE18_ICON='stock-id="gtk-apply"'
fi





Code:

#!/bin/bash
#130617 i18n started


if [ "`which gtkdialog4`" ]; then
 GTKDIALOG=gtkdialog4
elif [ "`which gtkdialog3`" ]; then
 GTKDIALOG=gtkdialog3
else
 GTKDIALOG=gtkdialog
fi

WORKDIR="/usr/local/mannaeditor"
NOTES_DIR="/root/my-documents/Manna"

export TEXTDOMAIN=Editor
export OUTPUT_CHARSET=UTF-8




export TMPDIR=/tmp/notes
mkdir -p "$TMPDIR"

echo "$TMPDIR"/notes



export NOTES_DIR="/root/my-documents/Manna"

add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'`   # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}
export -f add_note

#About dlg...
echo '#!/bin/sh' > /tmp/Editor-help
echo 'export EDITORHELP_DIALOG="
<window title=\"About\" icon-name=\"Com\" resizable=\"false\">
 <vbox>
 <notebook labels=\"About|License|Translations\">
 <vbox>
  <text height-request=\"2\"><label>\" \"</label></text>
  <pixmap><input file>/usr/local/Manna/icons/Com.png</input></pixmap>
  <text height-request=\"2\"><label>\" \"</label></text>
  <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor 2.2</span></b>\"</label></text>
  <text><label>\"    This is a basic text Editor for making notes or Teachings
    and can be exported to Abiword. The user interface
    supports the display of text in multiple font sizes for
    general viewing comfort.
   \"</label></text>

  <text><label>\"Copyright © 2013 GPL
  \"</label></text>
</vbox>
 <vbox>
 <text height-request=\"8\"><label>\" \"</label></text>
 <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Manna Editor</span></b>\"</label></text>
  <text use-markup=\"true\"><label>\"Is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
   <text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b><span color='"'red'"'>WITHOUT ANY WARRANTY</span></b>. See the GNU General Public License homepage for more details.\"</label></text>
    <hbox>
     <button>
      <label>\"http://www.gnu.org/licenses/\"</label>
      <action>defaultbrowser http:\/\/www.gnu.org\/licenses\/</action>
     </button>
    </hbox>
    </vbox>
   <vbox>
   <text height-request=\"8\"><label>\" \"</label></text>
   <text><label>\" German \"</label></text>
   <text><label>\" Spanish \"</label></text>
   </vbox>
  </notebook>
   <hbox homogeneous=\"true\">
     <button height-request=\"35\" width-request=\"100\">
      <label>\"Close\"</label>
     <input file stock=\"gtk-close\"></input>
     <action type=\"exit\">quit_now</action>
     </button>
   </hbox>
 </vbox>
</window>"
gtkdialog --center --program=EDITORHELP_DIALOG' >> /tmp/Editor-help
chmod 777 /tmp/Editor-help

export ADD_FILE='
  <window title="'$( gettext "Add Note")'" modal="true" icon-name="gtk-add" resizable="false">
    <vbox>
      <frame "'$(gettext "Note name:")'">
        <entry>
          <variable>NOTENAME</variable>
        </entry>
        <hbox>
          <button ok>
            <action>add_note</action>
            <action>clear:ITEM</action>
            <action>refresh:ITEM</action>
            <action type="closewindow">NOTENAME</action>
          </button>
          <button cancel>
            <action type="closewindow">NOTENAME</action>
          </button>
        </hbox>
      </frame>
    </vbox>
  </window>
'

export DEL_FILE='
  <window title="'$(gettext "Del Note")'" modal="true" icon-name="gtk-remove" resizable="false">
    <vbox>
      <text><label>"'$(gettext "Are you sure you want to delete:")'"</label></text>
         <text><input>echo "$ITEM"</input></text>
      <hbox>
        <button ok>
          <variable>CONFIRM</variable>
          <action>rm "$NOTES_DIR"/"$ITEM"</action>
          <action>clear:ITEM</action>
          <action>refresh:ITEM</action>
          <action type="closewindow">CONFIRM</action>
        </button>
        <button cancel>
          <action type="closewindow">CONFIRM</action>
        </button>
      </hbox>
    </vbox>
  </window>
'



export MAIN_DIALOG='
<window title="'$(gettext "Manna Editor")'" icon-name="Com" resizable="false">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>launch:ADD_FILE</action>
</menuitem>
<menuitem stock-id="gtk-save">
<action>Save:EDITOR</action>
<action>Save:Saving</action>
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-refresh">
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-delete">
<action>launch:DEL_FILE</action>
</menuitem>
<menuitem stock-id="gtk-quit">
<action>exit:Quit</action>
</menuitem>
<label>"'$(gettext "_File")'"</label>
</menu>
<menu label="'$(gettext "_Edit")'" use-underline="true">
<menuitem stock-id="gtk-edit" label="'$(gettext "Send to Wordprocessor")'">
      <action>defaultwordprocessor '"$TMPDIR"'/notes &</action>
     </menuitem>
</menu>
<menu label="'$(gettext "_View")'" use-underline="true" tooltip-text="'$(gettext " Change font size ")'">
<menu label="'$(gettext "_Font")'" use-underline="true" tooltip-text="'$(gettext " Change font ")'">
<menuitem '$FONTSIZE12_ICON' label="12">
      <action>echo "12" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/sans.sh</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE14_ICON' label="14">
      <action>echo "14" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/sans.sh</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE16_ICON' label="16">
      <action>echo "16" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/sans.sh</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      <menuitem '$FONTSIZE18_ICON' label="18">
      <action>echo "18" > '$WORKDIR'/font_size</action>
      <action>'$WORKDIR'/sans.sh</action>
      <action>'$WORKDIR'/Editor &</action>
      <action type="exit">quit_now</action>
      </menuitem>
      </menu>
    </menu>
    <menu label="'$(gettext "_Help")'" use-underline="true">
     <menuitem stock-id="gtk-info" label="'$(gettext "Help")'">
      <action>defaultbrowser '$WORKDIR'/editor-docs/MannaEditorHelp.html &</action>
     </menuitem>
     <menuitem stock-id="gtk-info" label="'$(gettext "About")'">
      <action>/tmp/Editor-help &</action>
     </menuitem>
    </menu>
</menubar>
</vbox>


<hbox>
<vbox width="160">
<table>
<label>"'$(gettext "Notes")'"</label>
<variable>ITEM</variable>
<input>ls '"$NOTES_DIR"'</input>
<action>ln -sf "/root/my-documents/Manna/$ITEM" '"$TMPDIR"'/notes</action>
<action>refresh:EDITOR</action>
</table>
</vbox>


<edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="2">
<variable>EDITOR</variable>
<height>600</height>
<width>700</width>
<input file>'"$TMPDIR"'/notes</input>
<output file>'"$TMPDIR"'/notes</output>
</edit>

</hbox>
</frame>
<action signal="hide">exit:Exit</action>
</window>
'

MM1RET="`gtkdialog --program=MAIN_DIALOG`"

Last edited by oldyeller on Thu 27 Jun 2013, 14:56; edited 1 time in total
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2167

PostPosted: Thu 27 Jun 2013, 13:49    Post subject:  

Code:
. sans.sh

If using bash, then you can alternately use:
Code:
source sans.sh
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 723
Location: Mishawaka IN

PostPosted: Thu 27 Jun 2013, 14:01    Post subject:  

amigo wrote:
Code:
. sans.sh

If using bash, then you can alternately use:
Code:
source sans.sh


Hi amigo,

I am still learning so where do I put this- in the main script?


Thanks
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: Thu 27 Jun 2013, 14:31    Post subject:  

Hi oldyeller !

Your sans.sh seems to be a configuration file .

As amigo said, it can be source 'd .

If you look into various Puppy scripts you'll see , that source ( mostly . ) occurs at the beginning of the script .
(rc.shutdown, delayedrun, probedisk2 , probepart you could look into - use which <command> to get the path)

source has a major disadvantage against executed scripts : If the source d file contains errors, it crashes the parent .

But for your purpose it might be the the best way to pull the wanted variables into the parent script .

So keep sourced files simple as your sans.sh is quite simple ..
Back to top
View user's profile Send private message Visit poster's website 
oldyeller


Joined: 15 Nov 2011
Posts: 723
Location: Mishawaka IN

PostPosted: Thu 27 Jun 2013, 14:56    Post subject:  

Hi Karl Godt,

Thanks for the name of scripts that I could look at that helped a lot and it works Very Happy


Thanks to the both of you


Cheers
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0775s ][ Queries: 12 (0.0039s) ][ GZIP on ]