ð€"Syntax10.Scn.Fnt“ýÿÿÐûÐûInfoElemsAlloc®Syntax10.Scn.FntÛSyntax10i.Scn.Fnt+`õÿÿÿzÀÔStampElemsAlloc10 Dec 970¿"Title": Base64 "Author": Andreas Krumenacker "Abstract": Base64 is a part of the Oberon-Web-Browser. It enhances the module Web with base64-coding and can be accessed via the procedures: Web.EncodeFile ('base64'; src, dest : Files.File) Web.DecodeFile ('base64'; src, dest : Files.File; VAR res : INTEGER) "Keywords": coding, coders, base64 "Version": no version "From": 10 Dec 97 "Until":  "Changes": no changes so far "Hints": no hints ìýÿÿÐûÐûBalloonElemsAlloc{Syntax10.Scn.Fnt¦Syntax10i.Scn.Fnt*¡™"Base64" Base64 is a part of the Oberon-Web-Browser. It enhances the module Web with base64-coding and can be accessed via the procedures: Web.EncodeFile ('base64'; src, dest : Files.File) Web.DecodeFile ('base64'; src, dest : Files.File; VAR res : INTEGER) "Install" Base64.Install This command is used to force the loading of module Base64. When loaded, the base64-coding is installed in module Web. $þÿÿ€8ÀÔFoldElemsNewÝSyntax10.Scn.FntqSyntax10i.Scn.Fnt  id = "base64"; ext = "b64"; CharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; (* A - Z: 65 - 90 *) (* a - z: 97 - 122 *) (* 0 - 9: 48 - 57 *) (* +: 43 *) (* /: 47 *) Pad = 3DX; (* "=" *) (* =: 61 *) offs = 43; maxLine = 76; ÿÿÿÿ€8ÀÔýÿÿ€8ÀÔESyntax10.Scn.Fnt$¯ÿÿÿ€8ÀÔFoldElemsNew#Syntax10.Scn.Fnt// EncoderDesc = RECORD (Web.EncoderDesc) END;ÿÿÿÿ€8ÀÔ$°ÿÿÿ€8ÀÔ#Syntax10.Scn.Fnt.. DecoderDesc = RECORD (Web.DecoderDesc) END;ÿÿÿÿ€8ÀÔ%…ÿÿÿ€8ÀÔ#Syntax10.Scn.FntYY TaskDesc = RECORD (Web.DecoderTaskDesc) buf : ARRAY 4 OF CHAR; idx : INTEGER; END;ÿÿÿÿ€8ÀÔ,¨ÿÿÿ€8ÀÔ#Syntax10.Scn.Fnt66 PresentatorDesc = RECORD (Web.PresentatorDesc) END;ÿÿÿÿ€8ÀÔ£ Encoder = POINTER TO EncoderDesc;  Decoder = POINTER TO DecoderDesc;  DecoderTask = POINTER TO TaskDesc;  Presentator = POINTER TO PresentatorDesc;  ÿÿÿÿ€8ÀÔ ÿÿÿ€8ÀÔ#Syntax10.Scn.Fnt>> charSet : ARRAY 65 OF CHAR; ordSet : ARRAY 80 OF INTEGER; ÿÿÿÿ€8ÀÔSyntax10i.Scn.Fnt28–úÿÿ€8ÀÔQSyntax10.Scn.Fnt1Syntax10i.Scn.FntVu VAR len, i : LONGINT; sIdx, line : INTEGER; sNum : ARRAY 3 OF INTEGER; sR, dR : Files.Rider; ch, nextCh : CHAR; lineF : BOOLEAN; BEGIN len := Files.Length(src) - 1; i := 0; sIdx := 0; line := 0; lineF := FALSE; nextCh := 0X; Files.Set(sR, src, 0); Files.Set(dR, dest, 0); WHILE i <= len DO IF nextCh # 0X THEN ch := nextCh; nextCh := 0X ELSE Files.Read(sR, ch); INC(i) END; IF lineF & (ch # 0AX) THEN nextCh := ch; ch := 0AX END; lineF := ch = 0DX; sNum[sIdx] := ORD(ch); INC(sIdx); IF sIdx = 3 THEN sIdx := 0; Files.Write(dR, charSet[sNum[0] DIV 4]); Files.Write(dR, charSet[(sNum[0] MOD 4) * 16 + sNum[1] DIV 16]); Files.Write(dR, charSet[(sNum[1] MOD 16) * 4 + sNum[2] DIV 64]); Files.Write(dR, charSet[sNum[2] MOD 64]); INC(line, 4); IF line = maxLine THEN (* begin new line *) line := 0; Files.Write(dR, 0DX); Files.Write(dR, 0AX) END END; END; (* sIdx = 0 | 1 | 2 *) IF sIdx > 0 THEN Files.Write(dR, charSet[sNum[0] DIV 4]); IF sIdx > 1 THEN Files.Write(dR, charSet[(sNum[0] MOD 4) * 16 + sNum[1] DIV 16]); Files.Write(dR, charSet[(sNum[1] MOD 16) * 4]); ELSE Files.Write(dR, charSet[(sNum[0] MOD 4) * 16]); Files.Write(dR, Pad) END; Files.Write(dR, Pad); Files.Write(dR, 0DX); Files.Write(dR, 0AX) END END Do;ÿÿÿÿ€8ÀÔ<ûÿÿ€8ÀÔQSyntax10.Scn.FntoSyntax10i.Scn.FntV·š VAR len, i : LONGINT; sIdx, line : INTEGER; sNum : ARRAY 3 OF INTEGER; sR, dR : Files.Rider; ch : CHAR; BEGIN len := Files.Length(src) - 1; i := 0; sIdx := 0; line := 0; Files.Set(sR, src, 0); Files.Set(dR, dest, 0); WHILE i <= len DO Files.Read(sR, ch); INC(i); sNum[sIdx] := ORD(ch); INC(sIdx); IF sIdx = 3 THEN sIdx := 0; Files.Write(dR, charSet[sNum[0] DIV 4]); Files.Write(dR, charSet[(sNum[0] MOD 4) * 16 + sNum[1] DIV 16]); Files.Write(dR, charSet[(sNum[1] MOD 16) * 4 + sNum[2] DIV 64]); Files.Write(dR, charSet[sNum[2] MOD 64]); INC(line, 4); IF line = maxLine THEN (* begin new line *) line := 0; Files.Write(dR, 0DX); Files.Write(dR, 0AX) END END; END; (* sIdx = 0 | 1 | 2 *) IF sIdx > 0 THEN Files.Write(dR, charSet[sNum[0] DIV 4]); IF sIdx > 1 THEN Files.Write(dR, charSet[(sNum[0] MOD 4) * 16 + sNum[1] DIV 16]); Files.Write(dR, charSet[(sNum[1] MOD 16) * 4]); ELSE Files.Write(dR, charSet[(sNum[0] MOD 4) * 16]); Files.Write(dR, Pad) END; Files.Write(dR, Pad); Files.Write(dR, 0DX); Files.Write(dR, 0AX) ELSIF line > 0 THEN Files.Write(dR, 0DX); Files.Write(dR, 0AX) END END Do;ÿÿÿÿ€8ÀÔ`¼úÿÿ€8ÀÔ#Syntax10.Scn.Fnt"" VAR ch : CHAR; num : ARRAY 4 OF INTEGER; i : INTEGER; toDo, read : LONGINT; BEGIN toDo := Files.Length(Files.Base(sR)) - Files.Pos(sR); WHILE toDo > 0 DO read := 0; WHILE (idx < 4) & (read < toDo) DO Files.Read(sR, ch); INC(read); IF ((ch >= "A") & (ch <= "Z")) OR ((ch >= "a") & (ch <= "z")) OR ((ch >= "0") & (ch <= "9")) OR (ch = "+") OR (ch = "/") THEN IF (idx < 3) OR (buf[2] # Pad) THEN buf[idx] := ch; INC(idx) ELSE res := Web.error; toDo := 0 END ELSIF ch = Pad THEN IF idx > 1 THEN buf[idx] := ch; INC(idx) ELSE res := Web.error; toDo := 0 END END END; DEC(toDo, read); IF (idx = 4) & (res # Web.error) THEN DEC(idx); WHILE buf[idx] = Pad DO DEC(idx) END; IF idx = 3 THEN FOR i := 0 TO 3 DO num[i] := ordSet[ORD(buf[i]) - offs] END; Files.Write(dR, CHR(num[0] * 4 + num[1] DIV 16)); Files.Write(dR, CHR((num[1] MOD 16) * 16 + num[2] DIV 4)); Files.Write(dR, CHR((num[2] MOD 4) * 64 + num[3])); ELSE res := Web.done; toDo := 0; FOR i := 0 TO 2 DO num[i] := ordSet[ORD(buf[i]) - offs] END; Files.Write(dR, CHR(num[0] * 4 + num[1] DIV 16)); IF idx = 2 THEN Files.Write(dR, CHR((num[1] MOD 16) * 16 + num[2] DIV 4)) END END; idx := 0 END END END Decode;ÿÿÿÿ€8ÀÔLÛþÿÿ€8ÀÔ#Syntax10.Scn.Fnt VAR sR, dR : Files.Rider; buf : ARRAY 4 OF CHAR; idx : INTEGER; BEGIN Files.Set(sR, src, 0); Files.Set(dR, dest, 0); idx := 0; res := Web.needData; Decode(sR, dR, buf, idx, res); IF (res = Web.needData) & (idx = 0) THEN res := Web.done END END Do;ÿÿÿÿ€8ÀÔ<ûþÿÿ€8ÀÔ#Syntax10.Scn.Fntãã VAR task : DecoderTask; BEGIN IF t.res = Web.needData THEN task := t(DecoderTask); IF task.fi.len.act > 0 THEN task.res := Web.done END; Decode(task.fi.r, task.dest.r, task.buf, task.idx, task.res) END END DoTasked;ÿÿÿÿ€8ÀÔF„ÿÿÿ€8ÀÔ#Syntax10.Scn.FntZZ VAR task : DecoderTask; BEGIN NEW(task); task.idx := 0; t := task END NewDecoderTask;ÿÿÿÿ€8ÀÔu1ÿÿÿ€8ÀÔ#Syntax10.Scn.Fnt­­ BEGIN fi.cKey := fi.cKey.alt; IF fi.cKey = NIL THEN NEW(fi.cKey); fi.cKey.id := Web.wildCard END; fi.coding := id; Web.OpenPresentator(fi, act, txt, elem) END Open;ÿÿÿÿ€8ÀÔSyntax10b.Scn.Fnt€ÿÿÿ€8ÀÔCSyntax10.Scn.Fnt Syntax10i.Scn.Fnt$> BEGIN (* only used to force loading of module *) END Install;ÿÿÿÿ€8ÀÔ‘þÿÿ€8ÀÔ#Syntax10.Scn.FntMM VAR encode : Encoder; decode : Decoder; pres : Presentator; BEGIN NEW(encode); encode.id := id; Web.InstallEncoder(encode); NEW(decode); decode.id := id; Web.InstallDecoder(decode); (* NEW(pres); pres.content := ext; IF ~ Web.ContentAdded(cont) THEN Web.LogStr("Content installing failed$") END *) END InstallCoding;ÿÿÿÿ€8ÀÔRÿÿÿ€8ÀÔ#Syntax10.Scn.FntŒŒ VAR i : INTEGER; BEGIN charSet := CharSet; i := 0; WHILE charSet[i] # 0X DO ordSet[ORD(charSet[i]) - offs] := i; INC(i) END END Init;ÿÿÿÿ€8ÀÔÉÿÿÿ€8ÀÔ#Syntax10.Scn.Fnt Init; InstallCodingÿÿÿÿ€8ÀÔ MODULE Base64;   IMPORT Files, Texts, Web; CONST  TYPE  VAR  (* Version including linefeeds after carriage-returns PROCEDURE (cod : Encoder) Do (src, dest : Files.File);  *) PROCEDURE (cod : Encoder) Do (src, dest : Files.File);  PROCEDURE Decode (VAR sR, dR : Files.Rider; VAR buf : ARRAY OF CHAR; VAR idx, res : INTEGER);  PROCEDURE (cod : Decoder) Do (src, dest : Files.File; VAR res : INTEGER);  PROCEDURE (cod : Decoder) DoTasked (t : Web.DecoderTask);  PROCEDURE (cod : Decoder) NewDecoderTask (VAR t : Web.DecoderTask);  (* PROCEDURE (cont : Presentator) Open (act : Web.UrlStack; txt : Web.Text; fi : Web.FileInfo; elem : Texts.Elem);  *) PROCEDURE Install*;  PROCEDURE InstallCoding;  PROCEDURE Init;  BEGIN  END Base64.