MODULE essai6; (* test minimal de lecture de fichier char par char*) FROM IOResult IMPORT ReadResults, ReadResult; FROM TextIO IMPORT ReadRestLine, SkipLine, ReadToken, WriteLn, WriteString, ReadChar; FROM SeqFile IMPORT OpenRead, OpenWrite, OpenResults, Close, ChanId, read, write; IMPORT STextIO, SWholeIO; VAR leChanId : ChanId; leResultat : OpenResults; unChar : CHAR; numeroLigne : CARDINAL; BEGIN (* principe : on ouvre, on lit les chars les uns après les autres et on les affiche*) (* une fois arrivé au bout du fichier, on le ferme *) STextIO.WriteString("Hello you all ! ... be ready for the ISO libs tests !"); STextIO.WriteLn; STextIO.WriteString("trying to open a file and display the content,char by char"); STextIO.WriteLn; STextIO.WriteLn; (* initialisation des variables*) numeroLigne := 1; (* ouverture du fichier*) OpenRead(leChanId, "essai3.mod", read, leResultat); (* test du résultat*) IF leResultat=opened THEN (*le fichier est ouvert*) STextIO.WriteString("fichier ouvert!"); STextIO.WriteLn; STextIO.WriteLn; (* on lit un char*) ReadChar(leChanId, unChar); (* on teste le résulat de lecture du char*) (* si c'est bon, on continue *) WHILE ReadResult(leChanId) <> endOfInput DO (* on teste si on est en fin de ligne*) IF ReadResult(leChanId) = endOfLine THEN INC(numeroLigne); (* on est obligé d'utiliser cette fonction poue "passer" la fin de ligne*) (* sinon, boucle infinie .... car on n'arrive jamais à enOfInput*) SkipLine(leChanId); END; (* on affiche le char*) STextIO.WriteChar(unChar); (* on lit le char suivant*) ReadChar(leChanId, unChar); END; ELSE STextIO.WriteString("Error"); STextIO.WriteLn; END; Close(leChanId); STextIO.WriteLn; STextIO.WriteLn; STextIO.WriteString(" nombre de lignes : "); SWholeIO.WriteCard(numeroLigne, 6); STextIO.WriteLn; END essai6.