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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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