There is a code written in C, I will be grateful for the help in translating it into Delphi (Pascal).
void f_print(void *uctx, const char *data, size_t length) { static int state = 0; const char *s = data; const char *prefix = (const char *)uctx; while (length != 0) { switch (state) { case 0: { if (prefix != NULL) printf(prefix); state = 1; s = data; break; } case 1: { size_t l = 0; while (*data != '\r' && *data != '\n' && length != 0) data++, length--, l++; if (l != 0) { fwrite(s, 1, l, stdout); } if (*data == '\r' || *data == '\n') state = 2; break; } case 2: { if (*data == '\r' || *data == '\n') data++, length--; else { fwrite("\r\n", 1, 2, stdout); state = 0; } break; } } } } Began to do this function (method) on delphi:
procedure TfrmMain.Print(AUctx: Pointer; AData: PAnsiChar; ALength: SIZE_T); var S : PAnsiChar; prefix : PAnsiChar; state : Byte; L : Byte; begin state := 0; prefix := AUctx; S := AData; while (ALength <> 0) do begin case state of 0: begin if prefix <> nil then FrmMain.mmoOutput.Lines.Add(prefix); s := AData; state := 1; end; 1: begin l := 0; { КАК ТУТ РЕАЛИЗОВАТЬ КОД ? } end; 2: begin { КАК ТУТ РЕАЛИЗОВАТЬ КОД ? } end; end; end; end; I do not know how to properly implement the code on Delphi, for case (state) = 1 and 2. Can I still have problems in written code? Thanks in advance for your help!