home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / MISC / NAMEL.PRG < prev    next >
Text File  |  1993-02-23  |  2KB  |  78 lines

  1. /*
  2.  * File......: NAMEL.PRG
  3.  * Author....: Steven Tyrakowski
  4.  * CIS ID....: 
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  * 
  9.  * This is an original work by various Netware API group participants
  10.  * and is placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19.  
  20. #include "netto.ch"
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *     fn_NameL()
  25.  *  $CATEGORY$
  26.  *     Miscellaneous
  27.  *  $ONELINER$
  28.  *     General purpose string to length+string packet function
  29.  *  $SYNTAX$
  30.  *
  31.  *     fn_NameL( cName, nRequiredLength)  => cReturn
  32.  *
  33.  *  $ARGUMENTS$
  34.  *
  35.  *     <cName>     - the character string to be used (shouldn't be longer
  36.  *                  than 255 characters
  37.  *     <nLength> -  if specified, the String is padded with NULLs
  38.  *                    to this length
  39.  *
  40.  *  $RETURNS$
  41.  *
  42.  *     <cReturn> - a character string with a one byte word at the beginning
  43.  *      which indicates the string length, including a null terminator
  44.  *      which is added if it does not exist.
  45.  *
  46.  *  $DESCRIPTION$
  47.  *
  48.  *     There are numerous places where a character string that is sent
  49.  *     needs to be encoded with a leading BYTE specifying the length
  50.  *     and may also need to be padded with NULLs.
  51.  *
  52.  *     A terminating null is guaranteed.
  53.  *
  54.  *     If the Length of cName is greater than nRequiredLength -1,
  55.  *     it is truncated to leave room for the terminator.
  56.  *
  57.  *  $EXAMPLES$
  58.  *
  59.  *  $SEEALSO$
  60.  *
  61.  *  $END$
  62.  */
  63.  
  64. function fn_nameL( cName, nLen )
  65.  
  66.   /*
  67.    *  If no length was specified, check for a terminating null
  68.    *  and add room for one if not found
  69.    *
  70.    */
  71.  
  72.   if nLen == nil
  73.     nLen := len( cName ) + iif( right( cName, 1 ) == chr(0), 0, 1 )
  74.   endif
  75.  
  76.   return chr( nLen ) + padr( cName, nLen - 1, chr(0) ) + chr(0)
  77.  
  78.