Difference between revisions of "Manual:DIL Manual/unitdir()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfunitdir"></span>
+
= unitdir() =
 +
'''Function''' (stringlist). Lists the unit files that DIL has stored, by a pattern.
  
−
  '''Function:'''  <i><!--CODE-->stringlist unitdir( match : string ) ;</i><!--ENDCODE-->
+
  unitdir(pattern : string)
  
−
<!--TERM--> '''match'''
+
Returns the names of the files in the <code>units</code> directory that match <code>pattern</code>: the files <code>store()</code> writes and <code>restore()</code> and <code>delunit()</code> read. death.zon uses <code>unitdir(".*")</code> at boot to bring back the corpses that were stored before a crash or reboot.
−
<!--DEFINITION-->         The wild card file you want to match or '*' for all.
 
−
<!--TERM--> '''return'''
 
−
<!--DEFINITION-->         a Stringlist with all the filenames that match the 'match' argument.
 
  
−
The 'match' argument uses the same wild cards as the Linux 'ls' command
+
== Parameters ==
−
so the following will work.
+
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| pattern || string || A regular expression that must match the ''whole'' file name. "" means all files.
 +
|}
  
−
<!--TERM-->  '''&ast;'''
+
== Returns ==
−
<!--DEFINITION-->        Match any character or group of characters
+
Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if <code>pattern</code> fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was.
−
<!--TERM-->  '''&quest;'''
 
−
<!--DEFINITION-->         Match one of any character
 
−
<!--TERM--> '''[...]'''
 
−
<!--DEFINITION-->        Match one of a set of characters
 
  
−
'''Example:'''
+
== Notes ==
−
<i><!--CODE-->
+
* The pattern is a regular expression (Perl style), not a shell wildcard: <code>".*"</code> is everything, <code>"corpse[.].*"</code> is every name starting with "corpse.", and a plain <code>.</code> matches any character. A shell-style <code>"*"</code> is not a valid expression.
−
---~---~---~---~---~---~---~---~---
+
* The directory is <code>units/</code> under the zone's DIL file directory: the sixth column of the zone's line in <code>vme/etc/zonelist</code> (death has <code>../lib/death</code>), or else <code>dil_file_dir</code> in <code>server.cfg</code>. The zone is that of the program the unit runs; a function from another zone that it calls (<code>f@otherzone</code>) still looks in the calling program's directory.
 +
* Only file names are returned, without a path, ready for <code>restore()</code>.
  
−
"corpse*" matches:  corpse.10938 corpse.whistler corpseofwhistler ...
+
== Example ==
−
"corpse?" matches corpse1 corpses corpse5 ...
+
<pre>
−
"[abc]*" matches ability about cost back ...
+
dilbegin aware reload_units();
−
"[a-z]*" about zoo man father ...
+
var
−
"start[nm]end" matches startnend startmend
+
  files : stringlist;
−
 
+
  u : unitptr;
−
---~---~---~---~---~---~---~---~---
+
  i : integer;
−
 
+
  n : integer;
−
</i><!--ENDCODE-->
+
code
−
'''Example DIL:'''
+
{
−
<i><!--CODE-->
+
  files := unitdir("corpse[.].*");
−
---~---~---~---~---~---~---~---~---
+
  n := length(files);
−
 
+
  i := 0;
−
dilbegin aware reload_corpse();
+
  while (i < n)
−
var
+
  {
−
        corpselist:stringlist;
+
      u := restore(files.[i], null);
−
        u:unitptr;
+
      if (u == null)
−
        ln:integer;
+
         log("reload_units: could not restore " + files.[i]);
−
        i:integer;
+
      i := i + 1;
−
        x:extraptr;
+
  }
−
code
+
  quit;
−
dilend
+
}
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
The previous DIL example is the DIL used in restoring corpses to the game in
 
−
case of a crash.  For more information you can see how the death DIL'S work
 
−
by reading through the file death.zon in the vme2.0/zone.
 
−
directory.
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bfunitdir"></span>
 
−
 
 
−
'''Function:'''  <i><!--CODE-->stringlist unitdir( match : string ) ;</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''match'''
 
−
<!--DEFINITION-->        The wild card file you want to match or '*' for all.
 
−
<!--TERM-->  '''return'''
 
−
<!--DEFINITION-->        a Stringlist with all the filenames that match the 'match' argument.
 
−
 
 
−
The 'match' argument uses the same wild cards as the Linux 'ls' command
 
−
so the following will work.
 
−
 
 
−
<!--TERM-->  '''&ast;'''
 
−
<!--DEFINITION-->        Match any character or group of characters
 
−
<!--TERM-->  '''&quest;'''
 
−
<!--DEFINITION-->        Match one of any character
 
−
<!--TERM-->  '''[...]'''
 
−
<!--DEFINITION-->        Match one of a set of characters
 
−
 
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
"corpse*" matches:  corpse.10938 corpse.whistler corpseofwhistler ...
 
−
"corpse?" matches corpse1 corpses corpse5 ...
 
−
"[abc]*" matches ability about cost back ...
 
−
"[a-z]*" about zoo man father ...
 
−
"start[nm]end" matches startnend startmend
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
'''Example DIL:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilbegin aware reload_corpse();
 
−
var
 
−
        corpselist:stringlist;
 
−
        u:unitptr;
 
−
         ln:integer;
 
−
        i:integer;
 
−
        x:extraptr;
 
−
code
 
 
dilend
 
dilend
 +
</pre>
 +
Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (<code>restore()</code> with null puts it there); adapted from <code>reload_corpse</code> in death.zon.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/store()|store()]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/restore()|restore()]]
−
The previous DIL example is the DIL used in restoring corpses to the game in
+
* [[Manual:DIL Manual/delunit()|delunit()]]
−
case of a crash.  For more information you can see how the death DIL'S work
+
* [[Manual:DIL Manual/strdir()|strdir()]]
−
by reading through the file death.zon in the vme2.0/zone.
 
−
directory.
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:15, 14 November 2026

unitdir()

Function (stringlist). Lists the unit files that DIL has stored, by a pattern.

unitdir(pattern : string)

Returns the names of the files in the units directory that match pattern: the files store() writes and restore() and delunit() read. death.zon uses unitdir(".*") at boot to bring back the corpses that were stored before a crash or reboot.

Parameters

Name Type Meaning
pattern string A regular expression that must match the whole file name. "" means all files.

Returns

Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if pattern fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was.

Notes

  • The pattern is a regular expression (Perl style), not a shell wildcard: ".*" is everything, "corpse[.].*" is every name starting with "corpse.", and a plain . matches any character. A shell-style "*" is not a valid expression.
  • The directory is units/ under the zone's DIL file directory: the sixth column of the zone's line in vme/etc/zonelist (death has ../lib/death), or else dil_file_dir in server.cfg. The zone is that of the program the unit runs; a function from another zone that it calls (f@otherzone) still looks in the calling program's directory.
  • Only file names are returned, without a path, ready for restore().

Example

dilbegin aware reload_units();
var
   files : stringlist;
   u : unitptr;
   i : integer;
   n : integer;
code
{
   files := unitdir("corpse[.].*");
   n := length(files);
   i := 0;
   while (i < n)
   {
      u := restore(files.[i], null);
      if (u == null)
         log("reload_units: could not restore " + files.[i]);
      i := i + 1;
   }
   quit;
}
dilend

Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (restore() with null puts it there); adapted from reload_corpse in death.zon.

See also