home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / turbopas / turbogen.arc / CROSSREF.MAN < prev    next >
Encoding:
Text File  |  1988-01-28  |  17.6 KB  |  462 lines

  1.                                   CROSSREFERENCE UTILITY
  2.           
  3.                   STARTUP:
  4.                           simply call crossref.com by entering CROSSREF<cr>.
  5.           
  6.                   The application will comeup to a signon/data entry screen.
  7.                   This screen expects a valid complete filename (with
  8.                   extension).
  9.           
  10.                   Most of the standard crossref/listing utilities ask for a
  11.                   filename and take off;
  12.                                   Printing in 80 column format,
  13.                                   Printing a variable crossref list,
  14.                                   And perform no type of logical indenting.
  15.           
  16.                   Well I tired of waiting for the listing of variables when all
  17.                   I had changed was syntax or some other such non variable bug.
  18.                   
  19.           
  20.           Printer Wide - default Y - (wide being 132 col.)
  21.           
  22.                   I like to write lines as a single line of code.  Must be a
  23.                   throwback to my damm basic days.  But reading up to the semi-
  24.                   colon just helps me.  Now there are those times when that is
  25.                   not possible but I hate to break a line just because we are
  26.                   nearing the 80 col. mark.  Example:
  27.           
  28.                   Has to be shorten to fit on this 80 col manual
  29.           
  30.                           
  31.                   Write(lst,name:20,address:20,city:20,state:2,zip:5);
  32.           
  33.                   The above is easier to see that all the data items are printed
  34.                   on the same line.  However this does the same job and is a bit
  35.                   more involved paper wise and speed reading wise.
  36.           
  37.                   Write(lst,name:20);
  38.                   Write(lst,Address:20);
  39.                   ETc.
  40.           
  41.                   And of course the the problem with this is that most almost
  42.                   all Pascal code I have seen is written to fit on 80 col stock.
  43.                   But Turbo's own editor lets you create lines out to 128????
  44.                   Suffice it to say the crossref here is designed to be usable
  45.                   in either mode and you can toggle back to the 80 col standard
  46.                   is you so desire.
  47.           
  48.           Print CrossReference - Default N
  49.           
  50.                   Another thing that frustrates me is all crossref/listing
  51.                   utilities I have come across always give you that cross
  52.                   reference.  Well many times I have not changed variable usage
  53.                   and do not wish to wait for another copy of what I already
  54.                   have.  I have made the printing of the crossreference
  55.                   selectable by you.
  56.           
  57.           
  58.           Doing Include Files - Default N
  59.           
  60.                   If you are not changing your include files why reprint them
  61.                   during development.  You can turn this on when doing a final
  62.                   listing of a system.  If you are working on an include then
  63.                   name that file for Crossref to list.
  64.           
  65.           Create New Formated File - Default N;
  66.           
  67.                   I may be the only guy who thinks this is necessary but I am
  68.                   sure from looking at other programers code I am not the only
  69.                   one who suffers from source-format-lazies.  This reoccuring
  70.                   affliction causes programers to become so engrossed in the
  71.                   task at hand they forget about (or think they will come back
  72.                   to) the job of proper indentation and line structure.  Well
  73.                   when I suffer from this condition I never get back to it, or
  74.                   think "This little diddy is only for me so who cares.". Six
  75.                   months later while I am trying to figure out my own
  76.                   code...yeah you know.  So this formater is designed to rewrite
  77.                   your source and indent it according to the rules laid down in
  78.                   the section of Printed Listing/Format File Appearance.
  79.           
  80.                   This is probably where the world will find the most use or
  81.                   most fault with this application.  I am still wondering why I
  82.                   have never found a public domain utility to do this work I
  83.                   can't have overlooked them.  I am sure there are some but most
  84.                   programers have been told about the official indenting rules
  85.                   and how you should follow the rules.  Well I have looked at
  86.                   lots and lots of other peoples code..(Good programers are
  87.                   included here) and no two listing have been alike...many times
  88.                   even from the same programer.  So the reason a indenting
  89.                   formater has not been listed is because they are so hard to
  90.                   write.... Bunk.  what's hard to do is please everybody.
  91.           
  92.                   If you reply with Y for yes you will open another field on the
  93.                   same line expecting the filename to write to.  You do not have
  94.                   to give an extension for the system forces one of .FMT.
  95.           
  96.           THE PRINTED LISTING/FORMAT FILE APPEARANCE
  97.           
  98.           
  99.                   So this indenting code is not designed to please everybody...
  100.                   as a matter of fact it does not please me all
  101.           the time.  But it does provide me with a FIXED FORMAT that handles
  102.           about 95% of the indenting required to quickly examine IF,WHILES,FOR
  103.           and other constructs that get tricky when nested.  Yes I know there
  104.           are rules to follow....even the experts say follow the rules and every
  105.           one of them has different rules.... so here are my rules.
  106.           
  107.                           1.  Ignore anything inside text strings or comments.
  108.                                   Many of the crossref systems don't to that.
  109.           
  110.                           1a. Forget about trying to check semi-colon usage. If
  111.                           the indenting is correct then the compiler or you will
  112.                           easily spot all missing semi-colons.
  113.           
  114.                           2.  A procedure or function rewinds indenting back to
  115.                           the left margin.  Which means if we haven't backed up
  116.                           to the left margin before hitting the next procedure
  117.                           or function then we have a mismatch or un-ended
  118.                           something.
  119.           
  120.                           3.  Record, Begin, Repeat, Case increment the indent
  121.                           tab.  These are the only words that trigger increases,
  122.                           and the indent increase will occur on the next line
  123.                           NOT THE LINE CONTAINING THE KEYWORD.  This is
  124.                           important as you can see from the samples at the end.
  125.           
  126.                           4. END and UNTIL are the only backup or decrease
  127.                           indent tab keywords.  Since most everything in Pascal
  128.                           is ended this should work.
  129.           
  130.                           5.  Begin should be on a line all to its' self.
  131.           
  132.                           6.  End/Until should not appear on the same line as
  133.                           it's mate.  See the formated code line 105 for example
  134.                           of what happens if you care to write short statements
  135.                           on a single line.
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.           EXAMPLE:
  164.           
  165.           
  166.           Lets get real sloppy with the indenting for a short piece of Turbo code then run
  167.           it through the indenter code to see what we get.
  168.           
  169.           
  170.           SOURCE AS WRITTEN
  171.           
  172.           Program Weight_Distribution;
  173.           
  174.           
  175.                FOR ILLUSTRATION OF INDENTING BY CROSSREF ONLY!!!
  176.           
  177.           
  178.           
  179.           Const                   (* pulling vehicle *)
  180.                       Veh_wgt        = 5860;
  181.                       Veh_front_axle = 32;
  182.                       Veh_rear_Axle  = 119;
  183.                       veh_5th        = 105;
  184.           
  185.               Trailer = 5420;         (* hauling trailer *)
  186.               T_hitch = 224;
  187.               t_front_axle = 63;
  188.               t_rear_axle  = 1;
  189.           
  190.           Var
  191.           
  192.           i,j               : integer;              (* loop controls *)
  193.           Total_lbs,
  194.           Total_moments,
  195.           bag_count,bags_row: real;                 (* misc globals  *)
  196.           t_front, t_rear   : real;                 (* wgt at hitch,axle*)
  197.           Front_Empty       : boolean;              (* loading front *)
  198.           rows              : array[0..16] of real; (* bags in each row *)
  199.           
  200.           procedure keyarr;
  201.           
  202.           const
  203.           endflag  = 'END';
  204.           
  205.           var
  206.           Entry  : string[20];
  207.           code   : integer;
  208.           
  209.           begin
  210.           j:= 0;
  211.           Entry := '';
  212.           clrscr;
  213.           writeln('*** Enter bag count per row counting from back of trailer **');
  214.           writeln('*** Enter ',Endflag,' to end data entry.  **');
  215.           while (entry <> endflag) and (j <= 16) do
  216.           begin
  217.           if j = 11 then writeln('*** Front Section ***');
  218.           write('Enter bag count for row ',j+1,': ');
  219.           readln(Entry);
  220.           if length(entry) = 0 then entry := 'bad';
  221.           if (entry <> endflag) and (j <= 16) then
  222.           begin
  223.           val(entry,rows[j],code);
  224.           if code <> 0 then
  225.           begin
  226.           writeln('** Illegal.  Please reenter.  **');
  227.           j := j-1;
  228.           end;
  229.           j := j+1;
  230.           end;
  231.           end;
  232.           (* array is full now scan for total bag_count *)
  233.           clrscr;
  234.           bag_count := 0;
  235.           for j := 0 to 16 do
  236.           begin
  237.           bag_count := bag_count + rows[j];
  238.           (* if first 6 rows empty then front_empty is set true *)
  239.           if (j=5) and (bag_count=0.0) then front_empty := true
  240.           else front_empty := false;
  241.           end;
  242.           end;
  243.           
  244.            there are several procs and functions missing that go here 
  245.           
  246.           
  247.           begin  (* main loop repeat forever. The -1 is caught in get_bag_count *)
  248.           repeat
  249.           i := 0;
  250.           j := 0;
  251.              bags_row := 0;
  252.              bag_count := 0;
  253.              Total_lbs := 0.0;
  254.              Total_moments := 100 * trailer; empty trailer wgt applied at cg.
  255.              get_bag_count;
  256.           
  257.               The real work starts here we have bags per row in rows[x].
  258.                There are four rows to the rear of fulcrum point hence the
  259.                strange looking FOR loop indexes, need moments behind
  260.                fulcrum negated.
  261.           
  262.                For i := -3 to 7 do
  263.                        begin
  264.                           Total_lbs := Total_lbs+(rows[i+3]*45);
  265.                Total_moments := Total_Moments+((rows[i+3]*45)*(16 * i));
  266.               end;
  267.           
  268.              If Not Front_Empty then
  269.                                 For i := 11 to 16 do
  270.                               begin
  271.                 Total_lbs :=
  272.           Total_lbs+(rows[i]*40);
  273.                 Total_moments := Total_moments+((rows[i]*40 )*(16*i));
  274.               end;
  275.           
  276.                     report;
  277.           writeln('Press any key');  repeat until keypressed;
  278.           
  279.           until bag_count = -1;
  280.           
  281.           end.
  282.  
  283.  
  284.  
  285.  
  286. Now this is the indented version of the same file....
  287.  
  288. Program weight_distribution;
  289.  
  290.  
  291. FOR ILLUSTRATION OF INDENTING BY CROSSREF ONLY!!!
  292.  
  293.  
  294.  
  295. Const                   (* pulling vehicle *)
  296. veh_wgt        = 5860;
  297. veh_front_axle = 32;
  298. veh_rear_axle  = 119;
  299. veh_5th        = 105;
  300.  
  301. trailer = 5420;         (* hauling trailer *)
  302. t_hitch = 224;
  303. t_front_axle = 63;
  304. t_rear_axle  = 1;
  305.  
  306. Var
  307.  
  308. i,j               : Integer;              (* loop controls *)
  309. total_lbs,
  310. total_moments,
  311. bag_count,bags_row: Real;                 (* misc globals  *)
  312. t_front, t_rear   : Real;                 (* wgt at hitch,axle*)
  313. front_empty       : Boolean;              (* loading front *)
  314. rows              : Array[0..16] Of Real; (* bags in each row *)
  315.  
  316. Procedure keyarr;
  317.  
  318. Const
  319. endflag  = 'END';
  320.  
  321. Var
  322. entry  : String[20];
  323. code   : Integer;
  324.  
  325. Begin
  326.  | j:= 0;
  327.  | entry := '';
  328.  | Clrscr;
  329.  | Writeln('*** Enter bag count per row counting from back of trailer **');
  330.  | Writeln('*** Enter ',endflag,' to end data entry.  **');
  331.  | While (entry <> endflag) And (j <= 16) Do
  332.  | Begin
  333.  |  | If j = 11 Then Writeln('*** Front Section ***');
  334.  |  | Write('Enter bag count for row ',j+1,': ');
  335.  |  | Readln(entry);
  336.  |  | If Length(entry) = 0 Then entry := 'bad';
  337.  |  | If (entry <> endflag) And (j <= 16) Then
  338.  |  | Begin
  339.  |  |  | Val(entry,rows[j],code);
  340.  |  |  | If code <> 0 Then
  341.  |  |  | Begin
  342.  |  |  |  | Writeln('** Illegal.  Please reenter.  **');
  343.  |  |  |  | j := j-1;
  344.  |  |  | End;
  345.  |  |  | j := j+1;
  346.  |  | End;
  347.  | End;
  348.  | (* array is full now scan for total bag_count *)
  349.  | Clrscr;
  350.  | bag_count := 0;
  351.  | For j := 0 To 16 Do
  352.  | Begin
  353.  |  | bag_count := bag_count + rows[j];
  354.  |  | (* if first 6 rows empty then front_empty is set true *)
  355.  |  | If (j=5) And (bag_count=0.0) Then front_empty := True
  356.  |  | Else front_empty := False;
  357.  | End;
  358. End;
  359.  
  360. {there are several procs and functions missing that go here}
  361.  
  362.  
  363. Begin  (* main loop repeat forever. The -1 is caught in get_bag_count *)
  364.  | Repeat
  365.  |  | i := 0;
  366.  |  | j := 0;
  367.  |  | bags_row := 0;
  368.  |  | bag_count := 0;
  369.  |  | total_lbs := 0.0;
  370.  |  | total_moments := 100 * trailer; empty trailer wgt applied at cg.
  371.  |  | get_bag_count;
  372.  |  |
  373.  |  | {The real work starts here we have bags per row in rows[x].
  374.  |  |  There are four rows to the rear of fulcrum point hence the
  375.  |  |  strange looking FOR loop indexes, need moments behind
  376.  |  |  fulcrum negated.}
  377.  |  |
  378.  |  |  For i := -3 To 7 Do
  379.  |  |  Begin
  380.  |  |   | total_lbs := total_lbs+(rows[i+3]*45);
  381.  |  |   | total_moments := total_moments+((rows[i+3]*45)*(16 * i));
  382.  |  |  End;
  383.  |  |
  384.  |  |  If Not front_empty Then
  385.  |  |  For i := 11 To 16 Do
  386.  |  |  Begin
  387.  |  |   | total_lbs := total_lbs+(rows[i]*40);
  388.  |  |   | total_moments := total_moments+((rows[i]*40 )*(16*i));
  389.  |  |  End;
  390.  |  |
  391.  |  |  report;
  392.  |  Writeln('Press any key');  Repeat Until Keypressed;
  393.  |  |
  394.  |  Until bag_count = -1;
  395.  |
  396. End.
  397.  
  398.  
  399. First notice how the header including the const, type, vars are pulled to the
  400. left margin.....
  401.  
  402.           Next in the procedure this same left margin is adopted, plus within the
  403.           begin:end you see indenting which allows drawing vertical lines which properly
  404.           nest logical blocks for quick visual inspection.  This indentation is also don
  405.           to a format file but without the verticle lines which of course would not
  406.           compile..
  407.           
  408.           Now on the printed copy only you may see the message;
  409.           
  410.             ( Record, Case, Begin/End ) or ( Repeat/Until ) pairing mismatch )
  411.           
  412.           Which means that within the Function/Procedure directly above the message you
  413.           have not ended a Record, Case, Begin  or You didn't use Repeat or Until as a
  414.           pair....
  415.  
  416.           
  417.           
  418.           The Corssref list for the above code is pretty standard...expect we do not list
  419.           reserved words nor do we list any words within
  420.           literal strings or comments...
  421.           
  422.           
  423.           bag_count       24      63      66      68      81      107
  424.           bags_row        24      80
  425.           code            36      52      53
  426.           endflag         32      43      44      50
  427.           entry           35      40      44      48      49      50      52
  428.           front_empty     26      68      69      97
  429.           get_bag_count   84
  430.           i               21      78      91      93      94      94      98      100
  431.                          101     101
  432.           j               21      39      44      46      47      50      52      56
  433.                           56      58      58      64      66      68      79
  434.           keyarr          29
  435.           report         104
  436.           rows            27      52      66      93      94     100     101
  437.           t_front         25
  438.           t_from_axle     16
  439.           t_hitch         15
  440.           t_rear          25
  441.           t_rear_axle     17
  442.           total_lbs       22      82      93     100     100
  443.           total_moments   23      83      94      94     101     101
  444.           trailer         14      83
  445.           veh_5th         12
  446.           veh_front_axle  10
  447.           veh_rear_axle   11
  448.           veh_wgt          9
  449.           weight_distribu  1
  450.           
  451.           
  452.           Notice that you can use this list to locate any unused functions or procedures.
  453.           You see when using libraries there are many times when the entire library is
  454.           included but only access one or two items within that library.   By using this
  455.           crossreference list you can find any varables/Functions/Procedures which are
  456.           used on only one line.  This is either the line the procedure/function is
  457.           declared on or the line where you will get the complier error message
  458.           **Undefined label** or equivlant.  So use this list when you are ready to
  459.           compile your final 'tightest' version of the code....
  460.           
  461.  
  462.