home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / BROWSR.ZIP / BROWSR.PAS
Encoding:
Pascal/Delphi Source File  |  1990-09-27  |  10.4 KB  |  855 lines

  1. program clbrowse;                { contains specific browser }
  2.  
  3. uses  CRT, DOS, Objects{, nodes2, cellist};
  4.  
  5.  
  6.  
  7. {The following classes have been reconstructed from LISTINGS 3 thru 6}
  8.  
  9.  
  10.  
  11. type
  12.  
  13.   AnyTypePtr = ^AnyType;
  14.  
  15.   AnyType = object(Node)
  16.  
  17.   {  constructor init;
  18.  
  19.     destructor  done;   virtual;
  20.  
  21.   }
  22.  
  23.     procedure   DSAction; virtual;
  24.  
  25.     procedure   BTAction; virtual;
  26.  
  27.     procedure   EditAction; virtual;
  28.  
  29.     end;
  30.  
  31.  
  32.  
  33.   procedure AnyType.DSAction;
  34.  
  35.     begin end; {Abstract}
  36.  
  37.  
  38.  
  39.   procedure AnyType.BTAction;
  40.  
  41.     begin end; {Abstract}
  42.  
  43.  
  44.  
  45.   procedure AnyType.EditAction;
  46.  
  47.     begin end; {Abstract}
  48.  
  49.  
  50.  
  51. type
  52.  
  53.  
  54.  
  55.   AnyTypeListPtr = ^AnyTypeList;
  56.  
  57.   AnyTypeList = Object(List)
  58.  
  59.     constructor init;
  60.  
  61.     destructor  done;   virtual;
  62.  
  63.     procedure   GetNodes; virtual;
  64.  
  65.     end;
  66.  
  67.  
  68.  
  69.   constructor AnyTypeList.Init;
  70.  
  71.     begin
  72.  
  73.       Self.Clear;
  74.  
  75.     end;
  76.  
  77.  
  78.  
  79.   destructor AnyTypeList.Done;
  80.  
  81.     begin
  82.  
  83.       while not Empty do
  84.  
  85.         Delete;
  86.  
  87.     end;
  88.  
  89.  
  90.  
  91. procedure AnyTypeList.GetNodes;  { process the browser list }
  92.  
  93. begin
  94.  
  95. (*
  96.  
  97.   P  := AnyTypePtr(First);      { set pointer to first node }
  98.  
  99.   while P <> nil do
  100.  
  101.   begin
  102.  
  103.     P^.BTAction;
  104.  
  105.     P := AnyTypePtr(Next(P));
  106.  
  107. *)
  108.  
  109.   end;
  110.  
  111.  
  112.  
  113. {END RECONSTRUCTION}
  114.  
  115.  
  116.  
  117. type
  118.  
  119.  
  120.  
  121. StringPtr = ^String;
  122.  
  123. BrowserListPtr = ^BrowserList;
  124.  
  125. BrowserList = object(AnyTypeList)
  126.  
  127.   constructor init;
  128.  
  129.   destructor done; virtual;
  130.  
  131.   procedure GetNodes; virtual;
  132.  
  133. end;
  134.  
  135.  
  136.  
  137. DisplayStrPtr = ^DisplayStr;
  138.  
  139. DisplayStr = object(AnyType)
  140.  
  141.   Value: StringPtr;
  142.  
  143.   constructor Init(V: String);
  144.  
  145.   destructor Done; virtual;
  146.  
  147.   procedure DSAction; virtual;    { Process a StrCell }
  148.  
  149. end;
  150.  
  151.  
  152.  
  153. BackTrackPtr = ^BackTrack;
  154.  
  155. BackTrack = object(AnyType)
  156.  
  157.   Value: StringPtr;
  158.  
  159.   constructor Init(V: String);
  160.  
  161.   destructor Done; virtual;
  162.  
  163.   procedure BTAction; virtual;    { Process a BTCell }
  164.  
  165. end;
  166.  
  167.  
  168.  
  169. EditPtr = ^Editor;
  170.  
  171. Editor = object(AnyType)
  172.  
  173.   FileName : String;
  174.  
  175.   Line     : String;
  176.  
  177.   LineNo   : word;
  178.  
  179.   Position : word;
  180.  
  181.   constructor Init(F: string; L: string; Ln: word; P: word);
  182.  
  183.   destructor Done; virtual;
  184.  
  185.   procedure EditAction; virtual;    { Edit }
  186.  
  187. end;
  188.  
  189.  
  190.  
  191. TextFile = object(base)
  192.  
  193.   F         : Text;
  194.  
  195.   FileName  : String;
  196.  
  197.   Line      : String;
  198.  
  199.   Buf       : array[0..8191] of char; { buffer for faster I/O }
  200.  
  201.   LineNo    : word;
  202.  
  203.   Position  : word;
  204.  
  205.   function open_file: boolean;
  206.  
  207. end;
  208.  
  209.  
  210.  
  211. HierarchyPtr = ^hierarchy;
  212.  
  213. Hierarchy = object(TextFile)
  214.  
  215.   Recurse : boolean;
  216.  
  217.   Method : String;
  218.  
  219.   Language_type : char;
  220.  
  221.   End_type, Base_type, Derived_type       : string[30];
  222.  
  223.   Object_type, Search_type, Ancestor_type : String[30];
  224.  
  225.   function base       : boolean;    { looks for base types }
  226.  
  227.   function derived    : boolean;    { looks for derived types }
  228.  
  229.   function ancestor   : boolean;    { looks for ancestors }
  230.  
  231.   constructor     init;
  232.  
  233.   destructor      done; virtual;
  234.  
  235.   procedure init_types;       { sets up types for C++ or Pascal }
  236.  
  237.   procedure init_files;       { sets up files for C++ or Pascal }
  238.  
  239.   procedure construct;              { flow controller }
  240.  
  241.   procedure Reconstruct; {calls construct & simplifies recursion}
  242.  
  243.   procedure update_backtrack_list;  { keeps track of types }
  244.  
  245.   procedure find_methods;           { finds methods }
  246.  
  247. end;
  248.  
  249.  
  250.  
  251. var                           { globals }
  252.  
  253.   Display, Edit : boolean;
  254.  
  255.   H      : HierarchyPtr;
  256.  
  257.   L      : BrowserListPtr;
  258.  
  259.   P      : AnyTypePtr;
  260.  
  261.  
  262.  
  263. { constructors }
  264.  
  265.  
  266.  
  267. constructor DisplayStr.Init(V: String);
  268.  
  269. begin
  270.  
  271.   GetMem(Value, Length(V) + 1);
  272.  
  273.   Value^ := V;
  274.  
  275. end;
  276.  
  277.  
  278.  
  279. constructor BackTrack.Init(V: String);
  280.  
  281. begin
  282.  
  283.   GetMem(Value, Length(V) + 1);
  284.  
  285.   Value^ := V;
  286.  
  287. end;
  288.  
  289.  
  290.  
  291. constructor Editor.Init(F: string; L: string; Ln: word; P: word);
  292.  
  293. begin
  294.  
  295.   FileName := F;
  296.  
  297.   Line     := L;
  298.  
  299.   LineNo   := Ln;
  300.  
  301.   Position := P;
  302.  
  303. end;
  304.  
  305.  
  306.  
  307. constructor Hierarchy.init;   begin end;
  308.  
  309. constructor BrowserList.init; begin end;
  310.  
  311.  
  312.  
  313. {destructors }
  314.  
  315.  
  316.  
  317. destructor Editor.Done; begin end;
  318.  
  319.  
  320.  
  321. destructor DisplayStr.Done;
  322.  
  323. begin  FreeMem(Value, Length(Value^) + 1); end;
  324.  
  325.  
  326.  
  327. destructor BackTrack.Done;
  328.  
  329. begin  FreeMem(Value, Length(Value^) + 1); end;
  330.  
  331.  
  332.  
  333. destructor  Hierarchy.done;   begin end;
  334.  
  335. destructor  BrowserList.done; begin end;
  336.  
  337.  
  338.  
  339. { methods }
  340.  
  341.  
  342.  
  343. procedure DisplayStr.DSAction;
  344.  
  345. var
  346.  
  347.   Ch : char;
  348.  
  349. begin
  350.  
  351.   writeln(Value^);
  352.  
  353.   Ch := readkey;
  354.  
  355. end;
  356.  
  357.  
  358.  
  359. procedure BackTrack.BTAction;  { show the object hierarchy }
  360.  
  361. begin  writeln(Value^); end;
  362.  
  363.  
  364.  
  365. procedure Editor.EditAction;
  366.  
  367. var Ch : char;
  368.  
  369. begin
  370.  
  371.   writeln(#13, #10,'File      = ',FileName);
  372.  
  373.   writeln('Line      = ',Line);
  374.  
  375.   writeln('LineNumber= ',LineNo);
  376.  
  377.   writeln('Position  = ',Position);
  378.  
  379.   { Call editor here & pass it appropriate information. }
  380.  
  381. end;
  382.  
  383.  
  384.  
  385. procedure hierarchy.init_types;
  386.  
  387. begin
  388.  
  389.   case Language_type of
  390.  
  391.   'p': begin                        { Pascal }
  392.  
  393.          Base_type := ' = object';
  394.  
  395.          Derived_type := ' = object(';
  396.  
  397.          End_type := 'end';
  398.  
  399.        end;
  400.  
  401.   'c': begin                        { C++ }
  402.  
  403.          Base_type := 'class ';
  404.  
  405.          Derived_type := ' :';
  406.  
  407.          End_type := '}';
  408.  
  409.        end;
  410.  
  411.   end; { case }
  412.  
  413. end;
  414.  
  415.  
  416.  
  417. procedure hierarchy.init_files;
  418.  
  419. begin
  420.  
  421.   case Language_type of
  422.  
  423.   'p': FileName := 'cltest.pas';   { Pascal }
  424.  
  425.   'c': FileName := 'cltest.cpp';   { C++ }
  426.  
  427.   end;  { case }
  428.  
  429.   write('Enter File Name : ');Readln(FileName);
  430.  
  431. { add functions here to read a project's files }
  432.  
  433. end;
  434.  
  435.  
  436.  
  437. procedure hierarchy.find_methods;
  438.  
  439. var
  440.  
  441.   NextLine     : string;
  442.  
  443.   TempPosition : word;
  444.  
  445. begin
  446.  
  447.   Method := '';
  448.  
  449.   NextLine := Line;
  450.  
  451.   TempPosition := 0;
  452.  
  453.   While (TempPosition = 0) do
  454.  
  455.   begin
  456.  
  457.     TempPosition := Pos(End_type,NextLine);
  458.  
  459.     Method := Method + NextLine + #13 + #10;
  460.  
  461.     readln(F,NextLine);
  462.  
  463.   end;
  464.  
  465.   L^.Append(New(DisplayStrPtr,Init(Method)));
  466.  
  467.   L^.Append(New(EditPtr,Init(FileName,Line,LineNo,Position)));
  468.  
  469. end;
  470.  
  471.  
  472.  
  473. function hierarchy.base: boolean;
  474.  
  475. begin
  476.  
  477.   LineNo := 1;
  478.  
  479.   case Language_type of
  480.  
  481.   'p': Search_type := Object_type + Base_type;
  482.  
  483.   'c': Search_type := Base_type + Object_type;
  484.  
  485.   end; { case }
  486.  
  487.   while not eof(F) do
  488.  
  489.   begin
  490.  
  491.     readln(F,Line);
  492.  
  493.     Position := Pos(Search_type,Line);
  494.  
  495.     If (Position > 0) then
  496.  
  497.     begin
  498.  
  499.       Position := Pos(Derived_type,Line);
  500.  
  501.       If (Position = 0) then
  502.  
  503.         begin
  504.  
  505.           find_methods;
  506.  
  507.           base := true;
  508.  
  509.           exit;
  510.  
  511.         end;
  512.  
  513.     end;
  514.  
  515.     inc(LineNo);
  516.  
  517.   end;
  518.  
  519.   base := false;
  520.  
  521. end;
  522.  
  523.  
  524.  
  525. function hierarchy.derived: boolean;
  526.  
  527. begin
  528.  
  529.   case Language_type of
  530.  
  531.   'p': Search_type := Object_type + Derived_type;
  532.  
  533.   'c': Search_type := Base_type + Object_type + Derived_type;
  534.  
  535.   end; { case }
  536.  
  537.   LineNo := 1;
  538.  
  539.   while not eof(F) do
  540.  
  541.   begin
  542.  
  543.     readln(F,Line);
  544.  
  545.     Position := Pos(Search_type,Line);
  546.  
  547.     If (Position > 0) then
  548.  
  549.     begin
  550.  
  551.       If ancestor then
  552.  
  553.       begin
  554.  
  555.         find_methods;
  556.  
  557.         derived := true;
  558.  
  559.         exit;
  560.  
  561.       end;
  562.  
  563.     end;
  564.  
  565.     inc(LineNo);
  566.  
  567.   end;
  568.  
  569.   derived := false;
  570.  
  571. end;
  572.  
  573.  
  574.  
  575. function hierarchy.ancestor: boolean;
  576.  
  577. var
  578.  
  579.   T_Ancestor_type : string[30];
  580.  
  581.   I,J,L : integer;
  582.  
  583. begin
  584.  
  585.     Ancestor_type := '';
  586.  
  587.     T_Ancestor_type := '';
  588.  
  589.     I := Length(Line);        { start at the end of the Line }
  590.  
  591.     while (Line[I] = #32) do  { space }
  592.  
  593.     dec(I);
  594.  
  595.     while (Line[I] = ')') do  { empty in C++ }
  596.  
  597.     dec(I);
  598.  
  599.     case Language_type of
  600.  
  601.     'c':
  602.  
  603.       while (Line[I] <> #32) do  { space }
  604.  
  605.       begin
  606.  
  607.         T_Ancestor_type := T_Ancestor_type + Line[I];
  608.  
  609.         dec(I);
  610.  
  611.       end;
  612.  
  613.     'p':
  614.  
  615.       while (Line[I] <> '(') do
  616.  
  617.       begin
  618.  
  619.         T_Ancestor_type := T_Ancestor_type + Line[I];
  620.  
  621.         dec(I);
  622.  
  623.       end;
  624.  
  625.     end; { case }
  626.  
  627.  
  628.  
  629.     L := Length(T_Ancestor_type);
  630.  
  631.     for I := L downto 1 do       { reverse the list }
  632.  
  633.       Ancestor_type := Ancestor_type + T_Ancestor_type[I];
  634.  
  635. end;
  636.  
  637.  
  638.  
  639. procedure hierarchy.update_backtrack_list;
  640.  
  641. begin
  642.  
  643.   L^.Append(New(BackTrackPtr, Init(Object_type)));
  644.  
  645. end;
  646.  
  647.  
  648.  
  649. function TextFile.open_file: boolean;
  650.  
  651. begin
  652.  
  653.   {$I-}                     { test for I/O error }
  654.  
  655.   assign(F,FileName);
  656.  
  657.   Reset(f);
  658.  
  659.   {$I+}
  660.  
  661.   Open_file := (IOResult = 0);
  662.  
  663. end;
  664.  
  665.  
  666.  
  667. procedure hierarchy.Reconstruct;
  668.  
  669. begin
  670.  
  671.   Recurse := true;  { still more ancestors }
  672.  
  673.   While Recurse do  { recursively backtrack for ancestors }
  674.  
  675.     construct;
  676.  
  677. end;
  678.  
  679.  
  680.  
  681. procedure hierarchy.construct;
  682.  
  683. begin
  684.  
  685.   Recurse := FALSE;
  686.  
  687.   If Open_file then      { if open successful }
  688.  
  689.   begin
  690.  
  691.     SetTextBuf(F,buf);
  692.  
  693.     update_backtrack_list;
  694.  
  695.     Close(F);
  696.  
  697.     If Open_file then
  698.  
  699.       If Derived then { If derived class, find its ancestor. }
  700.  
  701.       begin
  702.  
  703.           Object_type := ancestor_type; { set up for backtrack }
  704.  
  705.           Close(F);
  706.  
  707.           Recurse := true; { still more ancestors }
  708.  
  709.       end
  710.  
  711.     ELSE
  712.  
  713.       Close(F);
  714.  
  715.     IF Open_file then
  716.  
  717.       If Base then     { if base type, we're done. }
  718.  
  719.       begin
  720.  
  721.         Close(F);
  722.  
  723.         Recurse := false;  { no more ancestors }
  724.  
  725.       end;
  726.  
  727.   end;
  728.  
  729. end;
  730.  
  731.  
  732.  
  733. procedure display_mode;
  734.  
  735. var Ch : char;
  736.  
  737. begin
  738.  
  739.   write('e-Edit or d-display '); { display/edit option }
  740.  
  741.   Ch := Readkey;
  742.  
  743.   writeln;
  744.  
  745.   If Ch = 'e' then Edit := true
  746.  
  747.   Else Display := true;
  748.  
  749. end;
  750.  
  751.  
  752.  
  753. procedure BrowserList.GetNodes;  { process the browser list }
  754.  
  755. begin
  756.  
  757.   P  := AnyTypePtr(First);      { set pointer to first node }
  758.  
  759.   while P <> nil do
  760.  
  761.   begin
  762.  
  763.     P^.BTAction;
  764.  
  765.     P := AnyTypePtr(Next(P));
  766.  
  767.   end;
  768.  
  769.  
  770.  
  771.   If Display = true then        { are we displaying ? }
  772.  
  773.   begin
  774.  
  775.     P  := AnyTypePtr(First);
  776.  
  777.     while P <> nil do
  778.  
  779.     begin
  780.  
  781.       P^.DSAction;
  782.  
  783.       P := AnyTypePtr(Next(P));
  784.  
  785.     end;
  786.  
  787.   end;
  788.  
  789.  
  790.  
  791.   If Edit = true then           { editing ? }
  792.  
  793.   begin
  794.  
  795.     P  := AnyTypePtr(First);
  796.  
  797.     while P <> nil do
  798.  
  799.     begin
  800.  
  801.       P^.EditAction;
  802.  
  803.       P := AnyTypePtr(Next(P));
  804.  
  805.     end;
  806.  
  807.   end;
  808.  
  809. end;
  810.  
  811.  
  812.  
  813. { main }
  814.  
  815.  
  816.  
  817. begin
  818.  
  819.   Clrscr;
  820.  
  821.   Edit := false;                 { initializations }
  822.  
  823.   Display := false;
  824.  
  825.   New(L,init);               { initialize a new browser list }
  826.  
  827.   L^.clear;
  828.  
  829.   New(H,init);             { initialize a new hierarchy list }
  830.  
  831.   write('Enter Language -- p or c : ');
  832.  
  833.   readln(H^.Language_type);
  834.  
  835.   write('Enter Object: ');
  836.  
  837.   readln(H^.Object_type);
  838.  
  839.   writeln;
  840.  
  841.   H^.Init_files;
  842.  
  843.   H^.Init_types;
  844.  
  845.   H^.ReConstruct;
  846.  
  847.   display_mode;            { set display or edit }
  848.  
  849.   L^.GetNodes;             { process the browser list }
  850.  
  851.   Dispose(L,Done);         { cleanup }
  852.  
  853.   Dispose(H,Done);
  854.  
  855. end. { main