Skip to Content.
Sympa Menu

sm-sorcery - [SM-Sorcery]Re: CVS: sourcemage/sorcery/usr/sbin scribe,1.12,1.13

sm-sorcery AT lists.ibiblio.org

Subject: Discussion of Sorcery related topics

List archive

Chronological Thread  
  • From: Ryan Abrams <rabrams AT sourcemage.org>
  • To: Sergey A Lipnevich <sergeyli AT pisem.net>
  • Cc: rabrams AT cvs.sourcemage.org, sm-sorcery AT lists.ibiblio.org
  • Subject: [SM-Sorcery]Re: CVS: sourcemage/sorcery/usr/sbin scribe,1.12,1.13
  • Date: Thu, 24 Oct 2002 17:55:57 -0500

Sergey,

In all honesty, I didn't follow the $IFS discussion much, if at all. That said, I understand the concept and concede the point. In my defense, scribe is completely separate from the things that seem to cause the issues... scribe is rarely called from anywhere else in sorcery (except system-update). This doesn't excuse the coding style (which I was unaware of), but it does mean it is less likely a problem. Still, feel free to correct the work. I just wanted to get it in there asap. Heck, the three new functions are all pretty much standalone except for calling codex_add_grimoire.

On a related note, if the whole $IFS thing is what i think it is, it means we cannot even rely on basic programming constructs in bash. Instead we have to generate a list, then do crazy pipes to get things filtered through read to separate them. Thats insanity, and if that is the case then bash has got to go.

-Ryan

On Thursday, October 24, 2002, at 03:58 PM, Sergey A Lipnevich wrote:

Ryan,

May I ask you to refrain from using "for i in <list>" construct when <list> is a multi-line entity, for example the output of `codex_get_all_grimoires`? You can use "echo <list> | while read i; do ...; done" or "while read i; do ...; done < echo <list>" instead, whichever you prefer, but please don't count on $IFS implicitly, or on the fact that lines in the <list> don't have whitespace. I daresay current "libcodex" may be a good example now that I cut out all $IFS-dependent stuff. Since you seem to be passing return values using "echo" instead of assigning global env variables, this must be a really easy change.
Thanks!

Sergey.

rabrams AT cvs.sourcemage.org wrote:

Update of /cvsroot/sourcemage/sourcemage/sorcery/usr/sbin
In directory claire:/tmp/cvs-serv17955/usr/sbin

Modified Files:
scribe Log Message:
Added swap, set, and index commands to scribe.


Index: scribe
===================================================================
RCS file: /cvsroot/sourcemage/sourcemage/sorcery/usr/sbin/scribe,v
retrieving revision 1.12
retrieving revision 1.13
diff -U2 -r1.12 -r1.13
--- scribe 2002/09/30 20:54:06 1.12
+++ scribe 2002/10/24 20:49:01 1.13
@@ -37,4 +37,112 @@
}
+##########################
+# Function: Index
+# Display installed grimoires
+#########################
+
+index() {
+
+echo "Codex Listing"
+echo "-------------"
+echo ""
+
+#get installed grimoires
+grimoires=`codex_get_all_grimoires`
+ +#for each grimoire
+let c=0
+for j in $grimoires; do
+ i=`basename "$j"`
+echo " [$c] : $i : $j"
+ c=$((c+1))
+done
+
+#echo ""
+#echo "The number in [] is the ID of the grimoire."
+#echo "Grimoires are searched in ascending order when looking for spells."
+#echo ""
+#echo "The second item is the \"basename\" of the grimoire,"
+#echo "or what it is referred to as."
+#echo ""
+#echo "The final item is the full path location of the grimoire."
+#echo "This will usually be in /var/lib/sorcery/codex"
+
+}
+
+#######################################
+#swap()
+#######################################
+swap(){
+
+#get installed grimoires
+grimoires=`codex_get_all_grimoires`
+ +#for each grimoire
+let c=0
+for j in $grimoires; do
+ i=`basename "$j"`
+if [ "$i" = "${ITEMS[0]}" ]; then
+ let p1=$c
+ i1=$j
+elif [ "$i" = "${ITEMS[1]}" ]; then
+ let p2=$c
+ i2=$j
+fi
+ c=$((c+1))
+done
+
+if [ -z "$p1" ]; then
+ echo "Error: ${ITEMS[0]} not found in codex"
+elif [ -z "$p2" ]; then
+ echo "Error: ${ITEMS[1]} not found in codex"
+else
+echo -n "swapping "
+ echo "${ITEMS[0]} with ${ITEMS[1]}"
+codex_add_grimoire $i1 $p2
+codex_add_grimoire $i2 $p1
+fi
+
+
+}
+
+
+######################################
+#set()
+######################################
+set(){
+
+#get installed grimoires
+grimoires=`codex_get_all_grimoires`
+ +#for each grimoire
+let c=0
+movemode="n"
+for j in $grimoires; do
+ i=`basename "$j"`
+#echo "testing $i"
+ if [ "$i" = "${ITEMS[0]}" ]; then
+ movemode="t"
+ tmove=$j
+# echo "movemode = $movemode"
+ fi
+# if [ ! "${ITEMS[0]}" -ne "$c" ]; then
+# nmove="$i"
+# fi
+ c=$((c+1))
+done
+
+echo -n "moving "
+#if [ $movemode == "n" ]; then
+# echo "id ${ITEMS[0]} ($nmove) to position ${ITEMS[1]}"
+#else
+ echo "${ITEMS[0]} to position ${ITEMS[1]}"
+codex_add_grimoire $tmove ${ITEMS[1]}
+
+#fi
+
+}
+
+
######################################
#add()
@@ -83,5 +191,5 @@
#switch to and work in the codex
- pushd $CODEX_ROOT
+ pushd $CODEX_ROOT > /dev/null
#download the grimoire using subroutines
@@ -488,4 +596,7 @@
r|re|rem|remo|remov|remove) FUNCTION="r" ;;
u|up|upd|upda|updat|update) FUNCTION="u" ;;
+ sw|swa|swap)
FUNCTION="swap";;
+ se|set) FUNCTION="set";;
+ i|in|ind|inde|index)
FUNCTION="index";;
*) #unrecognized function. give help
help ;;
@@ -566,4 +677,7 @@
r) remove ;;
u) update ;;
+ set) set ;;
+ swap) swap ;;
+ index) index ;;
*) help ;;
esac




------------------
Get free mailbox 20 Mb at http://www.hotbox.ru





Archive powered by MHonArc 2.6.24.

Top of Page