woutervannifterick / c-to-delphi Goto Github PK
View Code? Open in Web Editor NEWC To Delphi converter
License: MIT License
C To Delphi converter
License: MIT License
Hello!
I have install SynEdit (download from https://github.com/SynEdit/SynEdit) to use TSynEdit for this project but it has a lot error in SynEdit. Please let me know what source SynEdit no error? I use Delphi 10.2,
Thank a lot!
Class TSynEdit not found when opening project in Delpho 10.3.3
In Delphi an enum is by default 2 bytes in size whereas in C the default is 4 bytes. This could lead to errors when passing an enum to a function or an alignment error when using an enum in a record/struct.
I would suggest to add {$MINENUMSIZE 4}
See also http://docwiki.embarcadero.com/RADStudio/Rio/en/Minimum_enumeration_size_(Delphi)
Can i send the developer a bunch of old c
simple c most do not translate.
limelect at gmail dot com
Can the converter handle pointers?
/Per
Just took a c file i found on my computer and ... a mess
/*
/*#include <sys/types.h>
#include <sys/select.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/ftp.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
*/
#define BUF_SIZE 4096
char client_hostname[64];
void
cleanup(int sig)
{
// syslog(LOG_NOTICE, "Cleaning up...");
exit(0);
}
void
sigreap(int sig)
{
int status;
pid_t p;
signal(SIGCHLD, sigreap);
while ((p = waitpid(-1, &status, WNOHANG)) > 0);
/* no debugging in signal handler! */
}
void
set_nonblock(int fd)
{
int fl;
int x;
fl = fcntl(fd, F_GETFL, 0);
if (fl < 0) {
syslog(LOG_ERR, "fcntl F_GETFL: FD %d: %s", fd, strerror(errno));
exit(1);
}
x = fcntl(fd, F_SETFL, fl | O_NONBLOCK);
if (x < 0) {
syslog(LOG_ERR, "fcntl F_SETFL: FD %d: %s", fd, strerror(errno));
exit(1);
}
}
int
create_server_sock(char *addr, int port)
{
int addrlen, s, on = 1, x;
static struct sockaddr_in client_addr;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
err(1, "socket");
addrlen = sizeof(client_addr);
memset(&client_addr, '\0', addrlen);
client_addr.sin_family = AF_INET;
client_addr.sin_addr.s_addr = inet_addr(addr);
client_addr.sin_port = htons(port);
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, 4);
x = bind(s, (struct sockaddr *) &client_addr, addrlen);
if (x < 0)
err(1, "bind %s:%d", addr, port);
x = listen(s, 5);
if (x < 0)
err(1, "listen %s:%d", addr, port);
// syslog(LOG_NOTICE, "listening on %s port %d", addr, port);
return s;
}
int
open_remote_host(char *host, int port)
{
struct sockaddr_in rem_addr;
int len, s, x;
struct hostent *H;
int on = 1;
H = gethostbyname(host);
if (!H)
return (-2);
len = sizeof(rem_addr);
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return s;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, 4);
len = sizeof(rem_addr);
memset(&rem_addr, '\0', len);
rem_addr.sin_family = AF_INET;
memcpy(&rem_addr.sin_addr, H->h_addr, H->h_length);
rem_addr.sin_port = htons(port);
x = connect(s, (struct sockaddr *) &rem_addr, len);
if (x < 0) {
close(s);
return x;
}
set_nonblock(s);
return s;
}
int
get_hinfo_from_sockaddr(struct sockaddr_in addr, int len, char *fqdn)
{
struct hostent *hostinfo;
hostinfo = gethostbyaddr((char *) &addr.sin_addr.s_addr, len, AF_INET);
if (!hostinfo) {
sprintf(fqdn, "%s", inet_ntoa(addr.sin_addr));
return 0;
}
if (hostinfo && fqdn)
sprintf(fqdn, "%s [%s]", hostinfo->h_name, inet_ntoa(addr.sin_addr));
return 0;
}
int
wait_for_connection(int s)
{
static int newsock, len;
static struct sockaddr_in peer;
len = sizeof(struct sockaddr);
syslog(LOG_INFO, "calling accept FD %d", s);
newsock = accept(s, (struct sockaddr *) &peer, &len);
/* dump_sockaddr (peer, len); */
if (newsock < 0) {
if (errno != EINTR) {
// syslog(LOG_NOTICE, "accept FD %d: %s", s, strerror(errno));
return -1;
}
}
get_hinfo_from_sockaddr(peer, len, client_hostname);
set_nonblock(newsock);
return (newsock);
}
int
mywrite(int fd, char *buf, int *len)
{
int x = write(fd, buf, *len);
if (x < 0)
return x;
if (x == 0)
return x;
if (x != *len)
memmove(buf, buf+x, (*len)-x);
*len -= x;
return x;
}
void
service_client(int cfd, int sfd)
{
int maxfd;
char *sbuf;
char *cbuf;
int x, n;
int cbo = 0;
int sbo = 0;
fd_set R;
sbuf = malloc(BUF_SIZE);
cbuf = malloc(BUF_SIZE);
maxfd = cfd > sfd ? cfd : sfd;
maxfd++;
while (1) {
struct timeval to;
if (cbo) {
if (mywrite(sfd, cbuf, &cbo) < 0 && errno != EWOULDBLOCK) {
// syslog(LOG_ERR, "write %d: %s", sfd, strerror(errno));
exit(1);
}
}
if (sbo) {
if (mywrite(cfd, sbuf, &sbo) < 0 && errno != EWOULDBLOCK) {
// syslog(LOG_ERR, "write %d: %s", cfd, strerror(errno));
exit(1);
}
}
FD_ZERO(&R);
if (cbo < BUF_SIZE)
FD_SET(cfd, &R);
if (sbo < BUF_SIZE)
FD_SET(sfd, &R);
to.tv_sec = 0;
to.tv_usec = 1000;
x = select(maxfd+1, &R, 0, 0, &to);
if (x > 0) {
if (FD_ISSET(cfd, &R)) {
n = read(cfd, cbuf+cbo, BUF_SIZE-cbo);
syslog(LOG_INFO, "read %d bytes from CLIENT (%d)", n, cfd);
if (n > 0) {
cbo += n;
} else {
close(cfd);
close(sfd);
// syslog(LOG_INFO, "exiting");
_exit(0);
}
}
if (FD_ISSET(sfd, &R)) {
n = read(sfd, sbuf+sbo, BUF_SIZE-sbo);
syslog(LOG_INFO, "read %d bytes from SERVER (%d)", n, sfd);
if (n > 0) {
sbo += n;
} else {
close(sfd);
close(cfd);
syslog(LOG_INFO, "exiting");
_exit(0);
}
}
} else if (x < 0 && errno != EINTR) {
syslog(LOG_NOTICE, "select: %s", strerror(errno));
close(sfd);
close(cfd);
syslog(LOG_NOTICE, "exiting");
_exit(0);
}
}
}
int
main(int argc, char *argv[])
{
char *localaddr = NULL;
int localport = -1;
char *remoteaddr = NULL;
int remoteport = -1;
int client = -1;
int server = -1;
int master_sock = -1;
if (5 != argc) {
fprintf(stderr, "usage: %s laddr lport rhost rport\n", argv[0]);
exit(1);
}
localaddr = strdup(argv[1]);
localport = atoi(argv[2]);
remoteaddr = strdup(argv[3]);
remoteport = atoi(argv[4]);
assert(localaddr);
assert(localport > 0);
assert(remoteaddr);
assert(remoteport > 0);
openlog(argv[0], LOG_PID, LOG_LOCAL4);
signal(SIGINT, cleanup);
signal(SIGCHLD, sigreap);
master_sock = create_server_sock(localaddr, localport);
for (;;) {
if ((client = wait_for_connection(master_sock)) < 0)
continue;
if ((server = open_remote_host(remoteaddr, remoteport)) < 0) {
close(client);
client = -1;
continue;
}
if (0 == fork()) {
/* child */
syslog(LOG_NOTICE, "connection from %s fd=%d", client_hostname, client);
syslog(LOG_INFO, "connected to %s:%d fd=%d", remoteaddr, remoteport, server);
close(master_sock);
service_client(client, server);
abort();
}
close(client);
client = -1;
close(server);
server = -1;
}
}
Hi,
Your code translator is awesome! You are doing a very good JOB.
Normally i'm involved on C to Pascal library Wrappers. C headers using export are not compatible with your code converter, so would be great to implement this feature :)
when evere i resize the window the loading mouse pointer icon flickers and i am unable to use the program
Can it keep comments after convertion?
Great tool. I see it is able to convert a lot of C++ code. The best one I've seen in a long time.
One type of function I see that the converter is not able to parse. It is just completely blank instead of any mis-conversion.
int __stdcall ListC_Resize(ILanguageObject* pEL, COLLECTION_ID nID, int nNewCount)
{
BEGIN_METHOD(ListC, pList)
int nOldCount = pList->container.size();
if (nNewCount > nOldCount)
pList->container.insert(pList->container.end(), nNewCount - nOldCount, 0);
else if (nNewCount < nOldCount) {
pList->FreeChildren(pEL, nNewCount);
pList->container.erase(pList->container.begin() + nNewCount, pList->container.end());
}
END_METHOD()
}
I changed on Delphi hello(i) to hello(i+.. errors
and to i+1 errors
Hello,
I tried to use your application to convert the dhnetsdk.h file
but the application freezed
i am having odd issues and as it doesnt specify which C i thought i'd ask.
Cheers
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.