i21sys/Mod/Listings.odc

(* примеры создания списков подсистем, модулей и проч. *)

MODULE  i21sysListings; (* F.V.Tkachov 2004; edited 2008-2-18 *)
	IMPORT  Log := StdLog,  F := Files,  TextModels,  TextMappers,  TextViews,  StdLinks,  
		Ports,  Views,  Strings;
	
	PROCEDURE Subsystems*;
		VAR  loc: F.Locator;  li: F.LocInfo;
	BEGIN
		loc := F.dir.This('');
		li := F.dir.LocList( loc );
		Log.Ln;
		(* Log.String('subsystems:');  Log.Ln; *)
		WHILE  li # NIL  DO
			Log.String( li.name );  Log.Ln;
			li := li.next
		END
	END Subsystems;
	
	PROCEDURE Modules* ( IN subsystem: ARRAY OF CHAR );
		VAR  loc: F.Locator;  fi: F.FileInfo;  li: F.LocInfo;  name: ARRAY 100 OF CHAR;
			pos: INTEGER;
	BEGIN
		ASSERT( subsystem # '', 20 );
		loc := F.dir.This( '' );
		li := F.dir.LocList( loc );
		WHILE  ( li # NIL ) & ( li.name$ = subsystem$ )  DO
			li := li.next
		END;
		IF  li = NIL  THEN
			Log.String( 'subsystem ' + subsystem + ' not found.' );  Log.Ln;  RETURN
		END;

		loc := loc.This( subsystem );
		li := F.dir.LocList( loc );
		WHILE  ( li # NIL ) & ( li.name$ = 'Mod' )  DO
			li := li.next
		END;
		IF  li = NIL  THEN
			Log.String( 'folder Mod not found in subsystem ' + subsystem );  Log.Ln;  RETURN
		END;
		
		loc := loc.This( 'Mod' );
		
		fi := F.dir.FileList( loc );
		IF  fi # NIL  THEN
			Log.Ln
		END;
		WHILE  fi # NIL  DO
			name := subsystem + fi.name;
			Strings.Find( name, '.odc', 0, pos );
			IF  pos >= 0  THEN
			   Strings.Replace( name, pos, 4, '' );
				Log.String( name );
				Log.Ln
			END;
			fi := fi.next
		END;
	END Modules;
	
	PROCEDURE ModulesAsLinks* ( IN subsystem: ARRAY OF CHAR );
		VAR  loc: F.Locator;  fi: F.FileInfo;  li: F.LocInfo;   name: ARRAY 100 OF CHAR;
			t: TextModels.Model;  fm: TextMappers.Formatter;  pos, pos0, pos1: INTEGER;
			link: StdLinks.Link;
			blue, default: TextModels.Attributes;
			v: TextViews.View;
	BEGIN
		ASSERT( subsystem # '', 20 );
		loc := F.dir.This( '' );
		li := F.dir.LocList( loc );
		WHILE  ( li # NIL ) & ( li.name$ = subsystem$ )  DO
			li := li.next
		END;
		IF  li = NIL  THEN
			Log.String( 'subsystem ' + subsystem + ' not found.' );  Log.Ln;  RETURN
		END;

		loc := loc.This( subsystem );
		li := F.dir.LocList( loc );
		WHILE  ( li # NIL ) & ( li.name$ = 'Mod' )  DO
			li := li.next
		END;
		IF  li = NIL  THEN
			Log.String( 'folder Mod not found in subsystem ' + subsystem );  Log.Ln;  RETURN
		END;
		
		loc := loc.This( 'Mod' );
		
		default := TextModels.dir.attr;
		blue := TextModels.NewColor( default, Ports.blue );
		
		fi := F.dir.FileList( loc );
		t := Log.text;
		fm.ConnectTo( t );
		IF  fi # NIL  THEN
			fm.WriteString("A mouse click on a name opens the document:");
			fm.WriteLn
		END;
		WHILE  fi # NIL  DO
			name := fi.name$;
			Strings.Find( name, '.odc', 0, pos );
			IF  pos >= 0  THEN
				Strings.Replace( name, pos, 4, '' );
				name := subsystem + name;
				
				link := StdLinks.dir.NewLink('StdCmds.OpenDoc(' + "'" + subsystem + '/Mod/' + fi.name + "'" + ')');
				fm.WriteView( link );
					pos0 := fm.Pos();
					fm.WriteString( name );
					pos1 := fm.Pos();
				link := StdLinks.dir.NewLink('');
				fm.WriteView( link );

				t.SetAttr( pos0, pos1, blue );
				fm.WriteLn;
			END;
			fi := fi.next
		END;
	END ModulesAsLinks;
	
	PROCEDURE Files* ( IN folder: ARRAY OF CHAR );
		VAR  loc: F.Locator;  fi: F.FileInfo;  li: F.LocInfo;
	BEGIN
		ASSERT( folder # '', 20 );
		loc := F.dir.This( folder );  ASSERT( loc.res = 0, 21 );

		fi := F.dir.FileList( loc );
		IF  fi # NIL  THEN
			Log.Ln
		END;
		WHILE  fi # NIL  DO
			Log.String( folder + '/' + fi.name );  Log.Ln;
			fi := fi.next
		END;
	END Files;
	
END i21sysListings.