ICOMMENT.PAS 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. (* programme comment‚ et expliqu‚ dans le livre *)
  2. (* LE DESASSEMBLEUR 8086 COLIBRI, publi‚ par *)
  3. (* L'INSTITUT PASCAL: *)
  4. (* 26 Rue Lamartine, 75009 PARIS *)
  5. (* Tel: (1) 42.85.10.82 *)
  6. procedure ouvre_fichier_commentaires;
  7. begin
  8. b_fichier_commentaires_ouvert:= true;
  9. (*$i-*)
  10. assign(fichier_commentaires, nom_fichier_commentaires);
  11. reset(fichier_commentaires);
  12. (*$i+*)
  13. if ioresult<> 0
  14. then begin
  15. write('pas de fichier ', nom_fichier_commentaires, ' Cr‚er, Quitter ? ');
  16. choix1:= f_lis_commande(['C', 'Q']);
  17. if choix1= 'C'
  18. then begin
  19. assign(fichier_commentaires, nom_fichier_commentaires);
  20. rewrite(fichier_commentaires);
  21. end
  22. else b_fichier_commentaires_ouvert:= false;
  23. end
  24. else writeln('a ouvert le fichier ', nom_fichier_commentaires);
  25. end;
  26. procedure charge_fichier_commentaires;
  27. var l_adresse_debut, l_adresse_fin: integer;
  28. procedure charge_les_commentaires;
  29. var l_numero_fiche: integer;
  30. procedure ajoute(var p: t_pt_commentaire);
  31. begin
  32. if p= nil
  33. then begin
  34. new(p);
  35. p^.adresse:= fiche_commentaire.adresse;
  36. p^.position_commentaire:= fiche_commentaire.position_commentaire;
  37. p^.numero_fiche:= l_numero_fiche;
  38. p^.pt_inferieurs:= nil; p^.pt_superieurs:= nil;
  39. end
  40. else
  41. if fiche_commentaire.adresse- $8000< p^.adresse- $8000
  42. then ajoute(p^.pt_inferieurs)
  43. else ajoute(p^.pt_superieurs);
  44. end;
  45. begin
  46. racine_commentaire:= nil;
  47. reset(fichier_commentaires);
  48. l_numero_fiche:= 0;
  49. while not eof(fichier_commentaires) do
  50. begin
  51. read(fichier_commentaires, fiche_commentaire);
  52. with fiche_commentaire do
  53. if (adresse- $8000>= l_adresse_debut- $8000)
  54. and (adresse- $8000<= l_adresse_fin- $8000)
  55. then ajoute(racine_commentaire);
  56. l_numero_fiche:= l_numero_fiche+ 1;
  57. end;
  58. end;
  59. begin
  60. if not b_fichier_commentaires_ouvert
  61. then exit;
  62. l_adresse_debut:= $0; l_adresse_fin:= $FFFF;
  63. repeat
  64. writeln;
  65. write('de $', f_entier_hexadecimal(l_adresse_debut));
  66. writeln(' … $', f_entier_hexadecimal(l_adresse_fin));
  67. write('Minimum, mAximum, charge commenTaires, Quitte ? ');
  68. choix1:= f_lis_commande(['T', 'M', 'A', 'Q', ' ', k_return]);
  69. case choix1 of
  70. 'A' : begin
  71. writeln; write('adresse maximum: <$1234> ? $');
  72. lis_entier_hexadecimal(29, wherey, l_adresse_fin);
  73. end;
  74. 'T' : charge_les_commentaires;
  75. 'M' : begin
  76. writeln; write('adresse minimum: <$5678> ? $');
  77. lis_entier_hexadecimal(29, wherey, l_adresse_debut);
  78. end;
  79. end;
  80. until choix1 in ['Q', 'T'];
  81. writeln;
  82. end;
  83. procedure cherche_commentaire(p_adresse: integer;
  84. p_position_commentaire: char;
  85. var pv_pt_commentaire: t_pt_commentaire;
  86. var pv_commentaire: string127);
  87. var l_trouve: boolean;
  88. begin
  89. pv_commentaire:= '';
  90. l_trouve:= false;
  91. while not l_trouve and (pv_pt_commentaire<> nil) do
  92. if p_adresse< pv_pt_commentaire^.adresse
  93. then pv_pt_commentaire:= pv_pt_commentaire^.pt_inferieurs
  94. else
  95. if p_adresse> pv_pt_commentaire^.adresse
  96. then pv_pt_commentaire:= pv_pt_commentaire^.pt_superieurs
  97. else
  98. if p_position_commentaire<> pv_pt_commentaire^.position_commentaire
  99. then pv_pt_commentaire:= pv_pt_commentaire^.pt_superieurs
  100. else begin
  101. seek(fichier_commentaires, pv_pt_commentaire^.numero_fiche);
  102. read(fichier_commentaires, fiche_commentaire);
  103. pv_commentaire:= fiche_commentaire.commentaire;
  104. l_trouve:= true;
  105. pv_pt_commentaire:= pv_pt_commentaire^.pt_superieurs;
  106. end;
  107. end;
  108. procedure liste_arbre_commentaires(p_pointeur: t_pt_commentaire);
  109. begin
  110. if p_pointeur<> nil
  111. then begin
  112. liste_arbre_commentaires(p_pointeur^.pt_inferieurs);
  113. with p_pointeur^ do
  114. begin
  115. write(sortie, numero_fiche: 4, ' $', f_entier_hexadecimal(adresse),
  116. position_commentaire:2, ' ');
  117. seek(fichier_commentaires, numero_fiche);
  118. read(fichier_commentaires, fiche_commentaire);
  119. writeln(sortie, fiche_commentaire.commentaire);
  120. end;
  121. liste_arbre_commentaires(p_pointeur^.pt_superieurs);
  122. end
  123. end;