Во первых давайте решим неясности в теме. - С++ в Delphi => Наверное имеется в виду C++ в Object-Pascal
- Опубликованный код не является С++, но С => Неободим конвертор С в Pascal
Вот он: http://c2pas.sourceforge.net/Мне кажется эта тема стоит рассмотрения, поскольку такие конверторы часто необходимы. Возможен ли такой конвертор na 100%?. По пунктам: - То есть синтакс конвертировать пожалуйста, но что делать с вызовом функций?
Ведь функции надо различать как по названиям, так и по удобству применения. - Если заменяю функцию, я обязан так же инклудовать соответсвующий .h
- Именно в Pascal'e отсутствует return
- ...
Так что поправлять всегда ручками придётся.  Вот кстати конвертированный код: | Код | #include <stdio.h> (* Needs only really basic stuff;) *) #include <stdlib.h>
Integer main(Integer argc, char *argv[]) begin if (argc=2) then begin FILE * fp; char temp :=0; Integer pm := 0; Integer i := 0; Integer passsize := 0; Integer port := 0;
printf('\ '#10''); printf(''#10''); printf('----------------------------------------- '#10'');
fp := fopen(argv[1], 'r');
if (fp <> nil) then begin (* fseek(fp, 230, SEEK_SET); *) for(i := 0;i<250;i++) begin temp := fgetc(fp); if (temp = 'C') then begin (* This basically just skips *) temp := fgetc(fp); (* the header of the file. *) if (temp='S') then begin (* A little messy, but it works *) fseek(fp, 24, SEEK_CUR); break; end; end; end; while ( not feof(fp)) do begin temp := fgetc(fp); if (temp > 31 and temp <127) then begin printf(''#10'Site name: '); do begin printf('%c', temp);
end; while ((temp := fgetc(fp))>31 and temp < 127) do; printf(''#10'');
fseek(fp, 18, SEEK_CUR); temp := fgetc(fp); if (temp<31) then begin while (temp<31) do temp :=fgetc(fp); end; printf('Host: '); do begin printf('%c', temp); end; while((temp := fgetc(fp))>31) do; printf(''#10'');
temp := fgetc(fp); printf('Username: '); if (temp=0) then begin printf('anonymous'); end else begin do begin printf('%c', temp);
end; while ((temp := fgetc(fp))>31 and temp < 127) do; end; printf(''#10'');
passsize := temp; printf('Password: '); for(i := 0;i<passsize;i++) begin temp := fgetc(fp); (* This glob of nastiness simply *) if (temp < -88 and temp > -97) then (* breaks the ASCII table down *) printf('%c', temp+200); (* into groups of 8 characters. *) if (temp < -80 and temp > -89) then (* This could have been done much *) printf('%c', temp+184); (* neater, but I haven't had time *) if (temp > -73 and temp < -64) then (* to re-do it. For a description *) printf('%c', temp+184); (* of how this "decrypts" the *) if (temp > -81 and temp < -73) then (* file, see the README. *) printf('%c', temp+200); if (temp > -25 and temp < -16) then printf('%c', temp+56); if (temp > -19 and temp < -8) then printf('%c', temp+72); if (temp > -9 and temp < 0) then printf('%c', temp+56); if (temp > -121 and temp < -112) then printf('%c', temp+184); if (temp > -129 and temp < -120) then printf('%c', temp+200); if (temp > -103 and temp < -96) then printf('%c', temp+184); if (temp > -111 and temp < -104) then printf('%c', temp+200); end; printf(''#10''); temp :=fgetc(fp); while (temp=0) do temp := fgetc(fp); (* fseek(fp, 2, SEEK_CUR); *) pm := fgetc(fp);
if (temp > 0 and pm = 0) then printf('Port: %i'#10'', temp); if (temp < 0 and pm = 0) then printf('Port: %i'#10'', temp+256);
if (pm <> 0) then begin
if (temp < 0) then begin (* Fun "decrypting" the port. *) pm := (pm * 256) + 256; (* See the README for a technical *) port := pm + temp; (* discription of how this works. *) printf('Port: %i'#10'', port); end; if (temp > 0) then begin pm := pm * 256; port := pm + temp; printf('Port: %i'#10'', port); end;
end; fseek(fp, 150, SEEK_CUR); end; end; (* End while(!eof) *)
printf(''#10''); printf('Finished.'#10''); printf('==================================================='#10''); fclose(fp); end else begin printf('Error opening %s'#10'', argv[1]); (* C2PAS: Exit *) Result :=(-1); end; (* C2PAS: Exit *) Result :=(1); end else begin printf('Usage: filename'#10''); printf('Where filename or other file of the same'#10''); printf('format, 5.0'#10''); (* C2PAS: Exit *) Result :=(-1); end; end; |
|