skylib_fluffos_v3/
skylib_fluffos_v3/bin/
skylib_fluffos_v3/bin/db/
skylib_fluffos_v3/fluffos-2.9-ds2.04/
skylib_fluffos_v3/fluffos-2.9-ds2.04/ChangeLog.old/
skylib_fluffos_v3/fluffos-2.9-ds2.04/Win32/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/simuls/
skylib_fluffos_v3/fluffos-2.9-ds2.04/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/clone/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/command/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/data/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/etc/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/master/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/log/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/compiler/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/efuns/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/operators/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/u/
skylib_fluffos_v3/fluffos-2.9-ds2.04/tmp/
skylib_fluffos_v3/fluffos-2.9-ds2.04/windows/
skylib_fluffos_v3/mudlib/
skylib_fluffos_v3/mudlib/cmds/
skylib_fluffos_v3/mudlib/cmds/admin/
skylib_fluffos_v3/mudlib/cmds/guild-race/
skylib_fluffos_v3/mudlib/cmds/living/broken/
skylib_fluffos_v3/mudlib/cmds/player/group_cmds/
skylib_fluffos_v3/mudlib/cmds/playtester/
skylib_fluffos_v3/mudlib/d/admin/
skylib_fluffos_v3/mudlib/d/admin/room/
skylib_fluffos_v3/mudlib/d/admin/room/we_care/
skylib_fluffos_v3/mudlib/d/admin/save/
skylib_fluffos_v3/mudlib/d/admin/text/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/buildings/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/map/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/roads/
skylib_fluffos_v3/mudlib/d/learning/chars/
skylib_fluffos_v3/mudlib/d/learning/functions/
skylib_fluffos_v3/mudlib/d/learning/handlers/
skylib_fluffos_v3/mudlib/d/learning/help_topics/
skylib_fluffos_v3/mudlib/d/learning/help_topics/npcs/
skylib_fluffos_v3/mudlib/d/learning/help_topics/objects/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/RCS/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/crowd/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/situations/
skylib_fluffos_v3/mudlib/d/learning/save/
skylib_fluffos_v3/mudlib/d/learning/school/
skylib_fluffos_v3/mudlib/d/learning/school/add_sc/
skylib_fluffos_v3/mudlib/d/learning/school/characters/
skylib_fluffos_v3/mudlib/d/learning/school/general/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/basic_commands/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/edtutor/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/unix_tutor/
skylib_fluffos_v3/mudlib/d/learning/school/items/
skylib_fluffos_v3/mudlib/d/learning/school/npc_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/room_basic/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/situations/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/terrain_tutor/
skylib_fluffos_v3/mudlib/d/learning/text/
skylib_fluffos_v3/mudlib/d/liaison/
skylib_fluffos_v3/mudlib/d/mudlib/
skylib_fluffos_v3/mudlib/d/mudlib/changes/
skylib_fluffos_v3/mudlib/d/playtesters/
skylib_fluffos_v3/mudlib/d/playtesters/effects/
skylib_fluffos_v3/mudlib/d/playtesters/handlers/
skylib_fluffos_v3/mudlib/d/playtesters/items/
skylib_fluffos_v3/mudlib/d/sage/
skylib_fluffos_v3/mudlib/doc/
skylib_fluffos_v3/mudlib/doc/creator/
skylib_fluffos_v3/mudlib/doc/driver/
skylib_fluffos_v3/mudlib/doc/driver/efuns/arrays/
skylib_fluffos_v3/mudlib/doc/driver/efuns/buffers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/calls/
skylib_fluffos_v3/mudlib/doc/driver/efuns/compile/
skylib_fluffos_v3/mudlib/doc/driver/efuns/filesystem/
skylib_fluffos_v3/mudlib/doc/driver/efuns/floats/
skylib_fluffos_v3/mudlib/doc/driver/efuns/functions/
skylib_fluffos_v3/mudlib/doc/driver/efuns/general/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mappings/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mixed/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mudlib/
skylib_fluffos_v3/mudlib/doc/driver/efuns/numbers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/parsing/
skylib_fluffos_v3/mudlib/doc/login/
skylib_fluffos_v3/mudlib/doc/lpc/basic_manual/
skylib_fluffos_v3/mudlib/doc/lpc/intermediate/
skylib_fluffos_v3/mudlib/doc/new/add_command/
skylib_fluffos_v3/mudlib/doc/new/events/
skylib_fluffos_v3/mudlib/doc/new/handlers/
skylib_fluffos_v3/mudlib/doc/new/living/race/
skylib_fluffos_v3/mudlib/doc/new/living/spells/
skylib_fluffos_v3/mudlib/doc/new/object/
skylib_fluffos_v3/mudlib/doc/new/player/
skylib_fluffos_v3/mudlib/doc/new/room/guild/
skylib_fluffos_v3/mudlib/doc/new/room/outside/
skylib_fluffos_v3/mudlib/doc/new/room/storeroom/
skylib_fluffos_v3/mudlib/doc/object/
skylib_fluffos_v3/mudlib/doc/playtesters/
skylib_fluffos_v3/mudlib/doc/policy/
skylib_fluffos_v3/mudlib/doc/weapons/
skylib_fluffos_v3/mudlib/global/
skylib_fluffos_v3/mudlib/global/creator/
skylib_fluffos_v3/mudlib/handlers/
skylib_fluffos_v3/mudlib/include/casino/
skylib_fluffos_v3/mudlib/include/cmds/
skylib_fluffos_v3/mudlib/include/effects/
skylib_fluffos_v3/mudlib/include/npc/
skylib_fluffos_v3/mudlib/include/room/
skylib_fluffos_v3/mudlib/include/shops/
skylib_fluffos_v3/mudlib/net/daemon/
skylib_fluffos_v3/mudlib/net/daemon/chars/
skylib_fluffos_v3/mudlib/net/inherit/
skylib_fluffos_v3/mudlib/net/obj/
skylib_fluffos_v3/mudlib/net/obj/BACKUPS/
skylib_fluffos_v3/mudlib/obj/amulets/
skylib_fluffos_v3/mudlib/obj/armours/plate/
skylib_fluffos_v3/mudlib/obj/b_day/
skylib_fluffos_v3/mudlib/obj/clothes/transport/horse/
skylib_fluffos_v3/mudlib/obj/faith/symbols/
skylib_fluffos_v3/mudlib/obj/fungi/
skylib_fluffos_v3/mudlib/obj/gatherables/
skylib_fluffos_v3/mudlib/obj/instruments/
skylib_fluffos_v3/mudlib/obj/media/
skylib_fluffos_v3/mudlib/obj/misc/player_shop/
skylib_fluffos_v3/mudlib/obj/monster/godmother/
skylib_fluffos_v3/mudlib/obj/monster/transport/
skylib_fluffos_v3/mudlib/obj/rings/
skylib_fluffos_v3/mudlib/obj/scabbards/
skylib_fluffos_v3/mudlib/obj/spells/
skylib_fluffos_v3/mudlib/obj/stationery/
skylib_fluffos_v3/mudlib/obj/stationery/envelopes/
skylib_fluffos_v3/mudlib/obj/toys/
skylib_fluffos_v3/mudlib/obj/vessels/
skylib_fluffos_v3/mudlib/obj/weapons/axes/
skylib_fluffos_v3/mudlib/obj/weapons/chains/
skylib_fluffos_v3/mudlib/obj/weapons/maces/BACKUPS/
skylib_fluffos_v3/mudlib/save/autodoc/
skylib_fluffos_v3/mudlib/save/book_handler/
skylib_fluffos_v3/mudlib/save/books/history/calarien/
skylib_fluffos_v3/mudlib/save/mail/
skylib_fluffos_v3/mudlib/save/new_soul/data/
skylib_fluffos_v3/mudlib/save/parcels/
skylib_fluffos_v3/mudlib/save/playerinfo/
skylib_fluffos_v3/mudlib/save/players/d/
skylib_fluffos_v3/mudlib/save/players/s/
skylib_fluffos_v3/mudlib/save/random_names/
skylib_fluffos_v3/mudlib/save/random_names/data/
skylib_fluffos_v3/mudlib/save/terrains/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_desert/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_grassy_field/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_mountain/
skylib_fluffos_v3/mudlib/save/todo_lists/
skylib_fluffos_v3/mudlib/secure/
skylib_fluffos_v3/mudlib/secure/cmds/admin/
skylib_fluffos_v3/mudlib/secure/cmds/lord/
skylib_fluffos_v3/mudlib/secure/config/
skylib_fluffos_v3/mudlib/secure/handlers/autodoc/
skylib_fluffos_v3/mudlib/secure/handlers/intermud/
skylib_fluffos_v3/mudlib/secure/include/global/
skylib_fluffos_v3/mudlib/secure/save/
skylib_fluffos_v3/mudlib/secure/save/handlers/
skylib_fluffos_v3/mudlib/secure/std/
skylib_fluffos_v3/mudlib/secure/std/classes/
skylib_fluffos_v3/mudlib/secure/std/modules/
skylib_fluffos_v3/mudlib/std/creator/
skylib_fluffos_v3/mudlib/std/dom/
skylib_fluffos_v3/mudlib/std/effects/
skylib_fluffos_v3/mudlib/std/effects/external/
skylib_fluffos_v3/mudlib/std/effects/fighting/
skylib_fluffos_v3/mudlib/std/effects/magic/
skylib_fluffos_v3/mudlib/std/effects/magic/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/other/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/priest/
skylib_fluffos_v3/mudlib/std/effects/room/
skylib_fluffos_v3/mudlib/std/environ/
skylib_fluffos_v3/mudlib/std/guilds/
skylib_fluffos_v3/mudlib/std/guilds/old/
skylib_fluffos_v3/mudlib/std/languages/
skylib_fluffos_v3/mudlib/std/liquids/
skylib_fluffos_v3/mudlib/std/npc/
skylib_fluffos_v3/mudlib/std/npc/goals/
skylib_fluffos_v3/mudlib/std/npc/goals/basic/
skylib_fluffos_v3/mudlib/std/npc/goals/misc/
skylib_fluffos_v3/mudlib/std/npc/plans/
skylib_fluffos_v3/mudlib/std/npc/plans/basic/
skylib_fluffos_v3/mudlib/std/npc/types/
skylib_fluffos_v3/mudlib/std/npc/types/helper/
skylib_fluffos_v3/mudlib/std/npcs/
skylib_fluffos_v3/mudlib/std/outsides/
skylib_fluffos_v3/mudlib/std/races/shadows/
skylib_fluffos_v3/mudlib/std/room/basic/BACKUPS/
skylib_fluffos_v3/mudlib/std/room/basic/topography/
skylib_fluffos_v3/mudlib/std/room/controller/
skylib_fluffos_v3/mudlib/std/room/inherit/topography/
skylib_fluffos_v3/mudlib/std/room/topography/area/
skylib_fluffos_v3/mudlib/std/room/topography/iroom/
skylib_fluffos_v3/mudlib/std/room/topography/milestone/
skylib_fluffos_v3/mudlib/std/shadows/curses/
skylib_fluffos_v3/mudlib/std/shadows/disease/
skylib_fluffos_v3/mudlib/std/shadows/fighting/
skylib_fluffos_v3/mudlib/std/shadows/healing/
skylib_fluffos_v3/mudlib/std/shadows/magic/
skylib_fluffos_v3/mudlib/std/shadows/poison/
skylib_fluffos_v3/mudlib/std/shadows/room/
skylib_fluffos_v3/mudlib/std/shops/controllers/
skylib_fluffos_v3/mudlib/std/shops/objs/
skylib_fluffos_v3/mudlib/std/shops/player_shop/
skylib_fluffos_v3/mudlib/std/socket/
skylib_fluffos_v3/mudlib/std/soul/d/
skylib_fluffos_v3/mudlib/std/soul/e/
skylib_fluffos_v3/mudlib/std/soul/i/
skylib_fluffos_v3/mudlib/std/soul/j/
skylib_fluffos_v3/mudlib/std/soul/k/
skylib_fluffos_v3/mudlib/std/soul/l/
skylib_fluffos_v3/mudlib/std/soul/n/
skylib_fluffos_v3/mudlib/std/soul/o/
skylib_fluffos_v3/mudlib/std/soul/q/
skylib_fluffos_v3/mudlib/std/soul/r/
skylib_fluffos_v3/mudlib/std/soul/u/
skylib_fluffos_v3/mudlib/std/soul/v/
skylib_fluffos_v3/mudlib/std/soul/y/
skylib_fluffos_v3/mudlib/std/soul/z/
skylib_fluffos_v3/mudlib/std/stationery/
skylib_fluffos_v3/mudlib/w/
skylib_fluffos_v3/mudlib/w/default/
skylib_fluffos_v3/mudlib/w/default/armour/
skylib_fluffos_v3/mudlib/w/default/clothes/
skylib_fluffos_v3/mudlib/w/default/item/
skylib_fluffos_v3/mudlib/w/default/npc/
skylib_fluffos_v3/mudlib/w/default/room/
skylib_fluffos_v3/mudlib/w/default/weapon/
skylib_fluffos_v3/mudlib/www/
skylib_fluffos_v3/mudlib/www/java/
skylib_fluffos_v3/mudlib/www/secure/
skylib_fluffos_v3/mudlib/www/secure/lpc/advanced/
skylib_fluffos_v3/mudlib/www/secure/lpc/intermediate/
skylib_fluffos_v3/win32/
<h3>Chapter 5: Advanced String Handling</h3>
<p><strong>5.1 What a String Is</strong></p>
<p>
The LPC Basics textbook taught strings as simple data types.
LPC generally deals with strings in such a matter.
The underlying driver program, however, is written in C, which has no string
data type. The driver in fact sees strings as a complex data type made up
of an array of characters, a simple C data type. LPC, on the other hand
does not recognize a character data type (there may actually be a driver
or two out there which do recognize the character as a data type, but in
general not). The net effect is that there are some array-like things you
can do with strings that you cannot do with other LPC data types.
</p>
<p>
The first efun regarding strings you should learn is the strlen()
efun. This efun returns the length in characters of an LPC string, and is
thus the string equivalent to sizeof() for arrays. Just from the behaviour
of this efun, you can see that the driver treats a string as if it were
made up of smaller elements. In this chapter, you will learn how to deal
with strings on a more basic level, as characters and sub strings.
</p>
<p>
<hr size="1">
<p><strong>5.2 Strings as Character Arrays</strong></p>
<p>You can do nearly anything with strings that you can do with arrays,
except assign values on a character basis. At the most basic, you can actually
refer to character constants by enclosing them in '' (single quotes). 'a' and
"a" are therefore very different things in LPC. 'a' represents a character
which cannot be used in assignment statements or any other operations except
comparison evaluations. "a" on the other hand is a string made up of a single
character. You can add and subtract other strings to it and assign it as a
value to a variable.
</p>
<p>
With string variables, you can access the individual characters
to run comparisons against character constants using exactly the same syntax
that is used with arrays. In other words, the statement:
<blockquote>
if( str[2] == 'a')
</blockquote>
is a valid LPC statement comparing the second character in the str string
to the character 'a'. You have to be very careful that you are not comparing
elements of arrays to characters, nor are you comparing characters of
strings to strings.
</p>
<p>
LPC also allows you to access several characters together using
LPC's range operator .. :
<blockquote>
if( str[0..1] == "ab")
</blockquote>
</p>
<p>
In other words, you can look for the string which is formed
by the characters 0 through 1 in the string str. As with arrays, you must
be careful when using indexing or range operators so that you do not try
to reference an index number larger than the last index. Doing so will result
in an error.
</p>
<p>
Now you can see a couple of similarities between strings and arrays:
<blockquote>
1) You may index on both to access the values of individual elements.
<blockquote>
a) The individual elements of strings are characters<br>
b) The individual elements of arrays match the data type of the array.
</blockquote>
2) You may operate on a range of values
<blockquote>
a) Ex: "abcdef"[1..3] is the string "bcd"<br>
b) Ex: ({ 1, 2, 3, 4, 5 })[1..3] is the int array ({ 2, 3, 4 })
</blockquote>
</blockquote>
</p>
<p>
And of course, you should always keep in mind the fundamental
difference: a string is not made up of a more fundamental LPC data type.
In other words, you may not act on the individual characters by assigning
them values.
</p>
<hr size="1">
<p><strong>5.3 The Efun sscanf()</strong></p>
<p>
You cannot do any decent string handling in LPC without using sscanf().
Without it, you are left trying to play with the full strings passed by
command statements to the command functions. In other words, you could
not handle a command like: "give sword to leo", since you would have no
way of separating "sword to leo" into its constituent parts. Commands such
as these therefore use this efun in order to use commands with multiple
arguments or to make commands more "English-like".
</p>
<p>
Most people find the manual entries for sscanf() to be rather difficult
reading. The function does not lend itself well to the format used by
manual entries. As I said above, the function is used to take a string
and break it into usable parts. Technically it is supposed to take a string
and scan it into one or more variables of varying types. Take the example
above:
<pre>
int give( string str ) {
    string what, whom;

    if( !str )
        return notify_fail("Give what to whom?\n");

    if( sscanf( str, "%s to %s", what, whom ) != 2 )
        return notify_fail("Give what to whom?\n");

    ... rest of give code ...

}
</pre>
</p>
<p>
The efun sscanf() takes three or more arguments. The first
argument is the string you want scanned. The second argument is called a
control string. The control string is a model which demonstrates in what
form the original string is written, and how it should be divided up. The
rest of the arguments are variables to which you will assign values based
upon the control string.
</p>
<p>
The control string is made up of three different types of elements: 1)
constants, 2) variable arguments to be scanned, and 3) variable arguments
to be discarded. You must have as many of the variable arguments in sscanf()
as you have elements of type 2 in your control string. In the above example,
the control string was "%s to %s", which is a three element control string
made up of one constant part (" to "), and two variable arguments to be
scanned ("%s"). There were no variables to be discarded.
</p>
<p>
The control string basically indicates that the function should find
the string " to " in the string str. Whatever comes before that constant
will be placed into the first variable argument as a string. The same
thing will happen to whatever comes after the constant.
</p>
<p>
Variable elements are noted by a "%" sign followed by a code for decoding
them. If the variable element is to be discarded, the "%" sign is followed
by the "*" as well as the code for decoding the variable. Common codes
for variable element decoding are "s" for strings and "d" for integers.
In addition, your mudlib may support other conversion codes, such as "f"
for float. So in the two examples above, the "%s" in the control string
indicates that whatever lies in the original string in the corresponding
place will be scanned into a new variable as a string.
</p>
<p>
A simple exercise. How would you turn the string "145" into an integer?
</p>
<p>Answer:</p>
<blockquote>
int x;<br>
<br>
sscanf("145", "%d", x );
</blockquote>
<p>
After the sscanf() function, x will equal the integer 145.
</p>
<p>
Whenever you scan a string against a control string, the function
searches the original string for the first instance of the first constant
in the original string. For example, if your string is "magic attack 100"
and you have the following:
<pre>
int improve(string str) {
    string skill;
    int x;

    if( sscanf( str, "%s %d", skill, x ) != 2 )
        return 0;

    ...

}
</pre>
you would find that you have come up with the wrong return
value for sscanf() (more on the return values later). The control string,
"%s %d", is made up of to variables to be scanned and one constant. The
constant is " ". So the function searches the original string for the first
instance of " ", placing whatever comes before the " " into skill, and trying
to place whatever comes after the " " into x. This separates "magic attack
100" into the components "magic" and "attack 100". The function, however,
cannot make heads or tales of "attack 100" as an integer, so it returns
1, meaning that 1 variable value was successfully scanned ("magic" into
skill).
</p>
<p>
Perhaps you guessed from the above examples, but the efun sscanf()
returns an int, which is the number of variables into which values from
the original string were successfully scanned. Some examples with return
values for you to examine:
<blockquote>
sscanf("swo rd descartes", "%s to %s", str1, str2) return: 0<br>
sscanf("swo rd descartes", "%s %s", str1, str2) return: 2<br>
sscanf("200 gold to descartes", "%d %s to %s", x, str1, str2) return: 3<br>
sscanf("200 gold to descartes", "%d %*s to %s", x, str1) return: 2
</blockquote>
where x is an int and str1 and str2 are strings.
</p>
<hr size="1">
<p><strong>5.4 Summary</strong></p>
<p>
LPC strings can be thought of as arrays of characters, yet
always keeping in mind that LPC does not have the character data type
(with most, but not all drivers). Since the character is not a true LPC
data type, you cannot act upon individual characters in an LPC string
in the same manner you would act upon different data types. Noticing the
intimate relationship between strings and arrays nevertheless makes it
easier to understand such concepts as the range operator and indexing
on strings.
</p>
<p>
There are efuns other than sscanf() which involve advanced string handling,
however, they are not needed nearly as often. You should check on your
mud for man or help files on the efuns: explode(), implode(), replace_string(),
sprintf(). All of these are very valuable tools, especially if you intend
to do coding at the mudlib level.
</p>