1
0

Format files with tab indents

This commit is contained in:
Timothy Warren 2021-09-30 14:35:36 -04:00
parent b5fdf9af30
commit c67eb64364
11 changed files with 156 additions and 138 deletions

18
.editorconfig Normal file
View File

@ -0,0 +1,18 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
# Indentation override for all JS under lib directory
[*.{pas, lpr}]
indent_style = tab
indent_size = 2

View File

@ -5,35 +5,35 @@ program countries;
uses strutils;
type
TCountry = record
Name: string;
Area: LongInt;
end;
TCountry = record
Name: string;
Area: LongInt;
end;
const
Belgium: TCountry = (Name: 'Belgium'; Area: 30513);
Austria: TCountry = (Name: 'Austria'; Area: 83851);
finland: TCountry = (Name: 'Finland'; Area: 337032);
Germany: TCountry = (Name: 'Germany'; Area: 356734);
Belgium: TCountry = (Name: 'Belgium'; Area: 30513);
Austria: TCountry = (Name: 'Austria'; Area: 83851);
finland: TCountry = (Name: 'Finland'; Area: 337032);
Germany: TCountry = (Name: 'Germany'; Area: 356734);
procedure DisplayInfo(aCountry: TCountry);
var barLength: integer;
begin
with aCountry do
begin
barLength := Area div 30000;
WriteLn(Name:8, Area:7, ' ', DupeString('*', barLength));
end;
with aCountry do
begin
barLength := Area div 30000;
WriteLn(Name:8, Area:7, ' ', DupeString('*', barLength));
end;
end;
begin
WriteLn(' Country Area Relative area');
WriteLn(' ------- ------ -------------');
DisplayInfo(Belgium);
DisplayInfo(Austria);
DisplayInfo(finland);
DisplayInfo(Germany);
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
WriteLn(' Country Area Relative area');
WriteLn(' ------- ------ -------------');
DisplayInfo(Belgium);
DisplayInfo(Austria);
DisplayInfo(finland);
DisplayInfo(Germany);
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.

View File

@ -3,9 +3,9 @@ program firstproject;
{$mode objfpc}{$H+}
begin
writeln('A Free Pascal progam');
{$IFDEF WINDOWS}
readln;
{$ENDIF}
writeln('A Free Pascal progam');
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.

View File

@ -4,21 +4,21 @@ program keypress;
procedure KeyPress(Key: Char);
begin
case upCase(Key) of
'0'..'9': WriteLn('Key ''', Key, ''' is numeric');
'A', 'E', 'I', 'O', 'U': WriteLn('Key ''', Key, ''' is a vowel');
'B'..'D', 'F'..'H', 'J'..'N', 'P'..'T', 'V'..'Z':
WriteLn('Key ''', Key, ''' is a consonant');
else WriteLn('Key ''', Key, ''' is not alphanumeric');
end;
case upCase(Key) of
'0'..'9': WriteLn('Key ''', Key, ''' is numeric');
'A', 'E', 'I', 'O', 'U': WriteLn('Key ''', Key, ''' is a vowel');
'B'..'D', 'F'..'H', 'J'..'N', 'P'..'T', 'V'..'Z':
WriteLn('Key ''', Key, ''' is a consonant');
else WriteLn('Key ''', Key, ''' is not alphanumeric');
end;
end;
var s: string;
begin
WriteLn('Press a key, then [Enter], (or [Enter] alone to finish)');
repeat
ReadLn(s);
if s <> '' then KeyPress(s[1]);
until s='';
WriteLn('Press a key, then [Enter], (or [Enter] alone to finish)');
repeat
ReadLn(s);
if s <> '' then KeyPress(s[1]);
until s='';
end.

View File

@ -5,16 +5,16 @@ program pointer_project;
type Plongint = ^longint;
var
anInt: longint = 243;
intPtr: Plongint;
anInt: longint = 243;
intPtr: Plongint;
begin
intPtr := @anInt;
WriteLn('The value of intPtr^ is ', intPtr^);
Inc(intPtr^, 4);
WriteLn('The value of anInt after Inc(intPtr^, 4) is: ',anInt);
{$IFDEF WINDOWS}
readln;
{$ENDIF}
intPtr := @anInt;
WriteLn('The value of intPtr^ is ', intPtr^);
Inc(intPtr^, 4);
WriteLn('The value of anInt after Inc(intPtr^, 4) is: ',anInt);
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.

View File

@ -3,21 +3,21 @@ program simple_expressions;
{$mode objfpc}{$H+}
var
b: Byte = 4;
c: Byte = 3;
b: Byte = 4;
c: Byte = 3;
begin
WriteLn('Initial value of b is ', b, '; initial value of c is ', c, sLineBreak);
b := b shr 1; // >> shift right
c := c shl 4; // << shift left
WriteLn('After b shr 1, b is ', b, '; after c shl 4, c is ', c, sLineBreak);
WriteLn('c xor b = ',c xor b, '; c and b = ', c and b, '; c or b = ', c or b);
WriteLn('not c is ', not c, '; not b is ', not b);
WriteLn;
WriteLn('c > b is ', c > b, '; c < b is ', c < b, '; c <> b is ', c <> b, '; c = b is ', c = b);
WriteLn;
WriteLn('c div b is ', c div b, '; c mod b is ', c mod b);
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
WriteLn('Initial value of b is ', b, '; initial value of c is ', c, sLineBreak);
b := b shr 1; // >> shift right
c := c shl 4; // << shift left
WriteLn('After b shr 1, b is ', b, '; after c shl 4, c is ', c, sLineBreak);
WriteLn('c xor b = ',c xor b, '; c and b = ', c and b, '; c or b = ', c or b);
WriteLn('not c is ', not c, '; not b is ', not b);
WriteLn;
WriteLn('c > b is ', c > b, '; c < b is ', c < b, '; c <> b is ', c <> b, '; c = b is ', c = b);
WriteLn;
WriteLn('c div b is ', c div b, '; c mod b is ', c mod b);
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.

View File

@ -3,30 +3,30 @@ program simple_types;
{$mode objfpc}{$H+}
const
pName='simple_types';
tab=#9;
pName='simple_types';
tab=#9;
var
smallInteger: SmallInt= -37;
started: boolean = false;
smallInteger: SmallInt= -37;
started: boolean = false;
begin
WriteLn('This program is called ', tab, tab, '"', pName, '"', sLineBreak);
WriteLn('This program is called ', tab, tab, '"', pName, '"', sLineBreak);
WriteLn('When initalised smallInteger has the value: ', smallInteger);
WriteLn('When initialized started has the value: ', started, sLineBreak);
WriteLn('When initalised smallInteger has the value: ', smallInteger);
WriteLn('When initialized started has the value: ', started, sLineBreak);
smallInteger += 100;
WriteLn('After adding 100 to smallInteger its value is: ', smallInteger);
started:= not started;
WriteLn('Negating started gives it the new value: ', started, sLineBreak);
smallInteger += 100;
WriteLn('After adding 100 to smallInteger its value is: ', smallInteger);
started:= not started;
WriteLn('Negating started gives it the new value: ', started, sLineBreak);
WriteLn('The highest value a SmallInt can store is: ', High(SmallInt));
WriteLn('The lowest value a SmallInt can store is: ', Low(SmallInt));
WriteLn('The highest value a SmallInt can store is: ', High(SmallInt));
WriteLn('The lowest value a SmallInt can store is: ', Low(SmallInt));
{$IFDEF WINDOWS}
readln;
{$ENDIF}
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.

View File

@ -4,10 +4,10 @@ program stortstrings;
var testStr: string[10] = 'Lazarus';
begin
WriteLn('This shows testStr enclosed by square brackets [', testStr, ']');
WriteLn('testStr''s length is ', Length(testStr), ' characters');
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
WriteLn('This shows testStr enclosed by square brackets [', testStr, ']');
WriteLn('testStr''s length is ', Length(testStr), ' characters');
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.

View File

@ -7,16 +7,16 @@ uses strutils, sysutils;
var st: string;
begin
WriteLn('Enter a word or pharase ([Enter] completes the entry)');
ReadLn(st);
WriteLn('You typed: ', st);
WriteLn('Your text converted to uppercase: ', UpperCase(st));
WriteLn('Your text converted to lowercase: ', LowerCase(st));
WriteLn('Your text converted to proper case: ',
AnsiProperCase(st, StdWordDelims));
WriteLn('Your text reversed: ', ReverseString(st));
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
WriteLn('Enter a word or pharase ([Enter] completes the entry)');
ReadLn(st);
WriteLn('You typed: ', st);
WriteLn('Your text converted to uppercase: ', UpperCase(st));
WriteLn('Your text converted to lowercase: ', LowerCase(st));
WriteLn('Your text converted to proper case: ',
AnsiProperCase(st, StdWordDelims));
WriteLn('Your text reversed: ', ReverseString(st));
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.

View File

@ -6,23 +6,23 @@ Function GetAName: string;
const lastName: string = '';
var constName: string = 'Lazarus';
begin
WriteLn('[Last name entered was "', lastName, '"]');
WriteLn('[Value of constName is "', constName, '"]');
Write('Enter a new name: ');
ReadLn(Result);
lastName := Result;
WriteLn('[Last name entered was "', lastName, '"]');
WriteLn('[Value of constName is "', constName, '"]');
Write('Enter a new name: ');
ReadLn(Result);
lastName := Result;
end;
begin
WriteLn('First invocation of GetAName');
WriteLn(GetAName);
WriteLn;
WriteLn('Second invocation of GetAName');
WriteLn(GetAName);
WriteLn;
WriteLn('[Finished]');
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
WriteLn('First invocation of GetAName');
WriteLn(GetAName);
WriteLn;
WriteLn('Second invocation of GetAName');
WriteLn(GetAName);
WriteLn;
WriteLn('[Finished]');
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.

View File

@ -5,43 +5,43 @@ program text_file;
uses sysutils;
var
txtF: TextFile;
s: String;
txtF: TextFile;
s: String;
procedure ReadTenLines;
const lineNo: integer = 0;
var linesRead: integer = 0;
begin
while not EOF(txtF) and (linesRead < 10) do
begin
ReadLn(txtF, s); // Read the current line in the file, and store in s
Inc(linesRead); // linesRead += 1
Inc(lineNo);
s := Format('Line %d: %s', [lineNo, s]);
WriteLn(s);
end;
while not EOF(txtF) and (linesRead < 10) do
begin
ReadLn(txtF, s); // Read the current line in the file, and store in s
Inc(linesRead); // linesRead += 1
Inc(lineNo);
s := Format('Line %d: %s', [lineNo, s]);
WriteLn(s);
end;
end;
begin
AssignFile(txtF, 'text_file.lpr'); // Open pointer to the file
Reset(txtF); // Open existing file
WriteLn('Lines from text_file.lpr will be displayed 10 at a time');
WriteLn;
AssignFile(txtF, 'text_file.lpr'); // Open pointer to the file
Reset(txtF); // Open existing file
WriteLn('Lines from text_file.lpr will be displayed 10 at a time');
WriteLn;
// Read and display the file
try
while not EOF(txtF) do
begin
ReadTenLines;
WriteLn;
WriteLn('Press [Enter] to continue');
ReadLn;
end;
finally
CloseFile(txtF);
end;
// Read and display the file
try
while not EOF(txtF) do
begin
ReadTenLines;
WriteLn;
WriteLn('Press [Enter] to continue');
ReadLn;
end;
finally
CloseFile(txtF);
end;
Write('End of file reached. Press [Enter] to finish');
ReadLn;
Write('End of file reached. Press [Enter] to finish');
ReadLn;
end.