Forum > Other
[SOLVED] StringUtils in MSDOS
chobani:
Is there a way to include stringutils when targeting MSDOS? I get cannot find BASE64, but if I change compile target to Win32/64 it compiles fine. I'm hoping I'm just doing something wrong, or I need to compile an older version of stringutils or something. I did some searches and didn't find anything. Thank you!
KodeZwerg:
I do not have MS-DOS to test, please try:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; uses Base64; var s: string;begin s := 'Test if it works'; WriteLn(s); // original s := EncodeStringBase64(s); WriteLn(s); // encoded s := DecodeStringBase64(s); WriteLn(s); // decodedend.
chobani:
Fatal: Cannot find Base64 used by Project1 of the Project Inspector.
I'm not sure why it's saying cannot find, but thank you that's a step in the right direction. If I change the target to Win32 this sample program compiles fine. Any idea why just this wouldn't be found and only just for MSDOS target? I can include sysutils for instance and it will compile to MSDOS.
KodeZwerg:
--- Quote from: chobani on November 25, 2022, 03:17:48 pm ---Fatal: Cannot find Base64 used by Project1 of the Project Inspector.
--- End quote ---
I do not know whats wrong at your installation / usage, so here is a solution that need nothing.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program base64test; var EncodeTable: array[0..63] of Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789+/'; DecodeTable: array[#0..#127] of Integer = ( Byte('='), 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64); type PPacket = ^TPacket; TPacket = packed record case Integer of 0: (b0, b1, b2, b3: Byte); 1: (i: Integer); 2: (a: array[0..3] of Byte); 3: (c: array[0..3] of Char); end; procedure EncodePacket(const Packet: TPacket; NumChars: Integer; OutBuf: PChar);begin OutBuf[0] := EnCodeTable[Packet.a[0] shr 2]; OutBuf[1] := EnCodeTable[((Packet.a[0] shl 4) or (Packet.a[1] shr 4)) and $0000003f]; if NumChars < 2 then OutBuf[2] := '=' else OutBuf[2] := EnCodeTable[((Packet.a[1] shl 2) or (Packet.a[2] shr 6)) and $0000003f]; if NumChars < 3 then OutBuf[3] := '=' else OutBuf[3] := EnCodeTable[Packet.a[2] and $0000003f];end; function Base64Encode(const Input: string): string;var I, K, J: Integer; Packet: TPacket;begin Result := ''; I := (Length(Input) div 3) * 4; if Length(Input) mod 3 > 0 then Inc(I, 4); SetLength(Result, I); J := 1; for I := 1 to Length(Input) div 3 do begin Packet.i := 0; Packet.a[0] := Byte(Input[(I - 1) * 3 + 1]); Packet.a[1] := Byte(Input[(I - 1) * 3 + 2]); Packet.a[2] := Byte(Input[(I - 1) * 3 + 3]); EncodePacket(Packet, 3, PChar(@Result[J])); Inc(J, 4); end; K := 0; Packet.i := 0; for I := Length(Input) - (Length(Input) mod 3) + 1 to Length(Input) do begin Packet.a[K] := Byte(Input[I]); Inc(K); if I = Length(Input) then EncodePacket(Packet, Length(Input) mod 3, PChar(@Result[J])); end;end; function DecodePacket(InBuf: PChar; var nChars: Integer): TPacket;begin Result.a[0] := (DecodeTable[InBuf[0]] shl 2) or (DecodeTable[InBuf[1]] shr 4); NChars := 1; if InBuf[2] <> '=' then begin Inc(NChars); Result.a[1] := (DecodeTable[InBuf[1]] shl 4) or (DecodeTable[InBuf[2]] shr 2); end; if InBuf[3] <> '=' then begin Inc(NChars); Result.a[2] := (DecodeTable[InBuf[2]] shl 6) or DecodeTable[InBuf[3]]; end;end; function Base64Decode(const Input: string): string;var I, J, K: Integer; Packet: TPacket;begin Result := ''; for I := 1 to Length(Input) div 4 do begin Packet := DecodePacket(PChar(@Input[(I - 1) * 4 + 1]), J); K := 0; while J > 0 do begin Result := Result + Packet.c[K]; Inc(K); Dec(J); end; end;end; var s: string;begin s := 'Test if it works'; WriteLn(s); // original s := Base64Encode(s); WriteLn(s); // encoded s := Base64Decode(s); WriteLn(s); // decodedend.
MarkMLl:
OP hasn't told us what version of compiler he's running. There's a reasonable chance that for some reason that file hasn't been built as part of the RTL: I can see it mentioned in fpcsrc/packages/fcl-base/fpmake.pp for 3.2.2 but haven't checked other versions.
MarkMLl
Navigation
[0] Message Index
[#] Next page