home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Demo / PCDUO / data1.cab / Script_Samples / GTGROUP.scp < prev    next >
Encoding:
Text File  |  2003-11-28  |  3.0 KB  |  96 lines

  1. // GTGROUP.SCP - Sample Script which reads from GROUP.NSM
  2. // Copyright (c) 2001-2002, Vector Networks Limited.
  3. // All Rights Reserved
  4. //
  5. // Revision History:
  6. // 7.0 20-Mar-02 DB  - Separated from GRPFLUPD.SCP.
  7.  
  8. // GetGroup is used to retrieve full details of all Clients in a named Group
  9. // from the Known Clients Group file, GROUP.NSM, returning the results
  10. // in a list. There are no built-in functions to do this directly apart from 
  11. // GetClientsInGroup, and that does not return full details (i.e. the network). 
  12. //
  13. // The GROUP.NSM file is in the following format:-
  14. // GroupName|Description|Members
  15. // Client1Name|Address|Transport|Location|LocationName
  16. //
  17. // Groups are separated by a blank line. We distinguish the various lines
  18. // using their length and number of tokens.
  19. // 
  20. // The Client details line matches the equivalent data in CLIENT.NSM, though
  21. // it is a subset of that information. 
  22.  
  23. Function GetGroup (Group as String, Profile as String) as List
  24.   Dim GroupName as String, GroupFile as String, Line as String
  25.   Dim Handle, Lines, Tokens, GroupList as List, SplitLine as List
  26.   Dim CurrentGroup as String, ClientCount
  27.  
  28.   //  Initialise counter variables
  29.  
  30.   ClientCount = 0
  31.  
  32.   If  Len (Group) > 0 Then
  33.     Print "Searching for Group : ", Group
  34.   
  35.     //  Now, we look it up in the GROUP.NSM file.
  36.  
  37.     GroupFile = GetControlFile ("GROUP.NSM", Profile)
  38.  
  39.     If (FileExists (GroupFile)) Then
  40.       Handle = Open (GroupFile, FILE_READ)
  41.  
  42.       If Handle !=0 Then
  43.         Print "Reading file " + GroupFile + "..."
  44.         Print "File handle: ", Handle
  45.  
  46.         Lines = 0
  47.  
  48.         Do Until EOF (Handle)
  49.           Line = ReadLine (Handle)
  50.           Lines = Lines + 1
  51.           Print "Line ", Lines, " <", Line, ">"
  52.  
  53.           If Trim (Line) != "" Then
  54.             SplitLine = TokenList (Line, "|")
  55.             If Items (SplitLine) = 3 Then
  56.               CurrentGroup = GetItem (SplitLine, 1)
  57.               If (ClientCount) > 0 Then
  58.                 Print "End of Group : ", Group
  59.                 Exit Do
  60.               Else
  61.                 Print "Reading Group : ", CurrentGroup
  62.               Endif
  63.             Endif
  64.             If Items (SplitLine) > 4 Then
  65.               If (CurrentGroup = Group) Then
  66.                 Print "Adding : ", Line
  67.                 AddItem (GroupList, Line)
  68.                 ClientCount = ClientCount + 1
  69.               Else
  70.                 Print "Skipping : ", Line
  71.               Endif
  72.             Endif
  73.           Else
  74.             Print "Skipping blank line"
  75.           Endif
  76.         Loop
  77.  
  78.         Print "Summary"
  79.         Print Lines, " lines processed"
  80.         If (ClientCount > 0) Then
  81.           Print "Group : ", Group, " contains ", Items (GroupList), " Clients."
  82.         Else
  83.           Print "Group : ", Group, " was not found or contains no Clients."
  84.         Endif
  85.         Close (Handle)
  86.       Endif
  87.     Else
  88.       Print "ERROR: Unable to open Group file : ", GroupFile
  89.     Endif
  90.   Else
  91.     //  No Group name provided
  92.   Endif
  93.  
  94.   GetGroup = GroupList
  95. End Function
  96.