Astyle.
This commit is contained in:
parent
6eafb157de
commit
ed8c0031f4
0
includes/font.h
Executable file → Normal file
0
includes/font.h
Executable file → Normal file
46
src/air.c
46
src/air.c
@ -18,15 +18,15 @@ void make_kernel(void)
|
||||
{
|
||||
int i, j;
|
||||
float s = 0.0f;
|
||||
for(j=-1; j<2; j++)
|
||||
for(i=-1; i<2; i++)
|
||||
for (j=-1; j<2; j++)
|
||||
for (i=-1; i<2; i++)
|
||||
{
|
||||
kernel[(i+1)+3*(j+1)] = expf(-2.0f*(i*i+j*j));
|
||||
s += kernel[(i+1)+3*(j+1)];
|
||||
}
|
||||
s = 1.0f / s;
|
||||
for(j=-1; j<2; j++)
|
||||
for(i=-1; i<2; i++)
|
||||
for (j=-1; j<2; j++)
|
||||
for (i=-1; i<2; i++)
|
||||
kernel[(i+1)+3*(j+1)] *= s;
|
||||
}
|
||||
void update_air(void)
|
||||
@ -34,8 +34,8 @@ void update_air(void)
|
||||
int x, y, i, j;
|
||||
float dp, dx, dy, f, tx, ty;
|
||||
|
||||
for(y=1; y<YRES/CELL; y++)
|
||||
for(x=1; x<XRES/CELL; x++)
|
||||
for (y=1; y<YRES/CELL; y++)
|
||||
for (x=1; x<XRES/CELL; x++)
|
||||
{
|
||||
dp = 0.0f;
|
||||
dp += vx[y][x-1] - vx[y][x];
|
||||
@ -44,8 +44,8 @@ void update_air(void)
|
||||
pv[y][x] += dp*TSTEPP;
|
||||
}
|
||||
|
||||
for(y=0; y<YRES/CELL-1; y++)
|
||||
for(x=0; x<XRES/CELL-1; x++)
|
||||
for (y=0; y<YRES/CELL-1; y++)
|
||||
for (x=0; x<XRES/CELL-1; x++)
|
||||
{
|
||||
dx = dy = 0.0f;
|
||||
dx += pv[y][x] - pv[y][x+1];
|
||||
@ -54,27 +54,27 @@ void update_air(void)
|
||||
vy[y][x] *= VLOSS;
|
||||
vx[y][x] += dx*TSTEPV;
|
||||
vy[y][x] += dy*TSTEPV;
|
||||
if(bmap[y][x]==WL_WALL || bmap[y][x+1]==WL_WALL ||
|
||||
if (bmap[y][x]==WL_WALL || bmap[y][x+1]==WL_WALL ||
|
||||
bmap[y][x]==WL_WALLELEC || bmap[y][x+1]==WL_WALLELEC ||
|
||||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
|
||||
(bmap[y][x+1]==WL_EWALL && !emap[y][x+1]))
|
||||
vx[y][x] = 0;
|
||||
if(bmap[y][x]==WL_WALL || bmap[y+1][x]==WL_WALL ||
|
||||
if (bmap[y][x]==WL_WALL || bmap[y+1][x]==WL_WALL ||
|
||||
bmap[y][x]==WL_WALLELEC || bmap[y+1][x]==WL_WALLELEC ||
|
||||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
|
||||
(bmap[y+1][x]==WL_EWALL && !emap[y+1][x]))
|
||||
vy[y][x] = 0;
|
||||
}
|
||||
|
||||
for(y=0; y<YRES/CELL; y++)
|
||||
for(x=0; x<XRES/CELL; x++)
|
||||
for (y=0; y<YRES/CELL; y++)
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
{
|
||||
dx = 0.0f;
|
||||
dy = 0.0f;
|
||||
dp = 0.0f;
|
||||
for(j=-1; j<2; j++)
|
||||
for(i=-1; i<2; i++)
|
||||
if(y+j>0 && y+j<YRES/CELL-1 &&
|
||||
for (j=-1; j<2; j++)
|
||||
for (i=-1; i<2; i++)
|
||||
if (y+j>0 && y+j<YRES/CELL-1 &&
|
||||
x+i>0 && x+i<XRES/CELL-1 &&
|
||||
bmap[y+j][x+i]!=WL_WALL &&
|
||||
bmap[y+j][x+i]!=WL_WALLELEC &&
|
||||
@ -99,7 +99,7 @@ void update_air(void)
|
||||
j = (int)ty;
|
||||
tx -= i;
|
||||
ty -= j;
|
||||
if(i>=2 && i<XRES/CELL-3 &&
|
||||
if (i>=2 && i<XRES/CELL-3 &&
|
||||
j>=2 && j<YRES/CELL-3)
|
||||
{
|
||||
dx *= 1.0f - VADV;
|
||||
@ -118,18 +118,18 @@ void update_air(void)
|
||||
dy += VADV*tx*ty*vy[j+1][i+1];
|
||||
}
|
||||
|
||||
if(bmap[y][x] == WL_FAN)
|
||||
if (bmap[y][x] == WL_FAN)
|
||||
{
|
||||
dx += fvx[y][x];
|
||||
dy += fvy[y][x];
|
||||
}
|
||||
|
||||
if(dp > 256.0f) dp = 256.0f;
|
||||
if(dp < -256.0f) dp = -256.0f;
|
||||
if(dx > 256.0f) dx = 256.0f;
|
||||
if(dx < -256.0f) dx = -256.0f;
|
||||
if(dy > 256.0f) dy = 256.0f;
|
||||
if(dy < -256.0f) dy = -256.0f;
|
||||
if (dp > 256.0f) dp = 256.0f;
|
||||
if (dp < -256.0f) dp = -256.0f;
|
||||
if (dx > 256.0f) dx = 256.0f;
|
||||
if (dx < -256.0f) dx = -256.0f;
|
||||
if (dy > 256.0f) dy = 256.0f;
|
||||
if (dy < -256.0f) dy = -256.0f;
|
||||
|
||||
ovx[y][x] = dx;
|
||||
ovy[y][x] = dy;
|
||||
|
1212
src/graphics.c
1212
src/graphics.c
File diff suppressed because it is too large
Load Diff
266
src/http.c
266
src/http.c
@ -72,7 +72,7 @@ static struct sockaddr_in http_proxy;
|
||||
static char *mystrdup(char *s)
|
||||
{
|
||||
char *x;
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
x = malloc(strlen(s)+1);
|
||||
strcpy(x, s);
|
||||
@ -84,19 +84,19 @@ static char *mystrdup(char *s)
|
||||
static int splituri(char *uri, char **host, char **path)
|
||||
{
|
||||
char *p=uri,*q,*x,*y;
|
||||
if(!strncmp(p, "http://", 7))
|
||||
if (!strncmp(p, "http://", 7))
|
||||
p += 7;
|
||||
q = strchr(p, '/');
|
||||
if(!q)
|
||||
if (!q)
|
||||
q = p + strlen(p);
|
||||
x = malloc(q-p+1);
|
||||
if(*q)
|
||||
if (*q)
|
||||
y = mystrdup(q);
|
||||
else
|
||||
y = mystrdup("/");
|
||||
strncpy(x, p, q-p);
|
||||
x[q-p] = 0;
|
||||
if(q==p || x[q-p-1]==':')
|
||||
if (q==p || x[q-p-1]==':')
|
||||
{
|
||||
free(x);
|
||||
free(y);
|
||||
@ -111,7 +111,7 @@ static char *getserv(char *host)
|
||||
{
|
||||
char *q, *x = mystrdup(host);
|
||||
q = strchr(x, ':');
|
||||
if(q)
|
||||
if (q)
|
||||
*q = 0;
|
||||
return x;
|
||||
}
|
||||
@ -120,7 +120,7 @@ static char *getport(char *host)
|
||||
{
|
||||
char *p, *q;
|
||||
q = strchr(host, ':');
|
||||
if(q)
|
||||
if (q)
|
||||
p = mystrdup(q+1);
|
||||
else
|
||||
p = mystrdup("80");
|
||||
@ -130,7 +130,7 @@ static char *getport(char *host)
|
||||
static int resolve(char *dns, char *srv, struct sockaddr_in *addr)
|
||||
{
|
||||
struct addrinfo hnt, *res = 0;
|
||||
if(http_use_proxy)
|
||||
if (http_use_proxy)
|
||||
{
|
||||
memcpy(addr, &http_proxy, sizeof(struct sockaddr_in));
|
||||
return 0;
|
||||
@ -138,11 +138,11 @@ static int resolve(char *dns, char *srv, struct sockaddr_in *addr)
|
||||
memset(&hnt, 0, sizeof(hnt));
|
||||
hnt.ai_family = AF_INET;
|
||||
hnt.ai_socktype = SOCK_STREAM;
|
||||
if(getaddrinfo(dns, srv, &hnt, &res))
|
||||
if (getaddrinfo(dns, srv, &hnt, &res))
|
||||
return 1;
|
||||
if(res)
|
||||
if (res)
|
||||
{
|
||||
if(res->ai_family != AF_INET)
|
||||
if (res->ai_family != AF_INET)
|
||||
{
|
||||
freeaddrinfo(res);
|
||||
return 1;
|
||||
@ -159,17 +159,17 @@ void http_init(char *proxy)
|
||||
char *host, *port;
|
||||
#ifdef WIN32
|
||||
WSADATA wsadata;
|
||||
if(!WSAStartup(MAKEWORD(2,2), &wsadata))
|
||||
if (!WSAStartup(MAKEWORD(2,2), &wsadata))
|
||||
http_up = 1;
|
||||
#else
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
http_up = 1;
|
||||
#endif
|
||||
if(proxy)
|
||||
if (proxy)
|
||||
{
|
||||
host = getserv(proxy);
|
||||
port = getport(proxy);
|
||||
if(resolve(host, port, &http_proxy))
|
||||
if (resolve(host, port, &http_proxy))
|
||||
http_up = 0;
|
||||
else
|
||||
http_use_proxy = 1;
|
||||
@ -220,27 +220,27 @@ struct http_ctx
|
||||
void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
|
||||
{
|
||||
struct http_ctx *cx = ctx;
|
||||
if(!ctx)
|
||||
if (!ctx)
|
||||
{
|
||||
ctx = calloc(1, sizeof(struct http_ctx));
|
||||
cx = ctx;
|
||||
cx->fd = PERROR;
|
||||
}
|
||||
|
||||
if(!cx->hbuf)
|
||||
if (!cx->hbuf)
|
||||
{
|
||||
cx->hbuf = malloc(256);
|
||||
cx->hlen = 256;
|
||||
}
|
||||
|
||||
if(!http_up)
|
||||
if (!http_up)
|
||||
{
|
||||
cx->ret = 604;
|
||||
cx->state = HTS_DONE;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
if(cx->state!=HTS_STRT && cx->state!=HTS_IDLE)
|
||||
if (cx->state!=HTS_STRT && cx->state!=HTS_IDLE)
|
||||
{
|
||||
fprintf(stderr, "HTTP: unclean request restart state.\n");
|
||||
exit(1);
|
||||
@ -248,18 +248,18 @@ void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
|
||||
|
||||
cx->keep = keep;
|
||||
cx->ret = 600;
|
||||
if(splituri(uri, &cx->host, &cx->path))
|
||||
if (splituri(uri, &cx->host, &cx->path))
|
||||
{
|
||||
cx->ret = 601;
|
||||
cx->state = HTS_DONE;
|
||||
return ctx;
|
||||
}
|
||||
if(http_use_proxy)
|
||||
if (http_use_proxy)
|
||||
{
|
||||
free(cx->path);
|
||||
cx->path = mystrdup(uri);
|
||||
}
|
||||
if(cx->fdhost && strcmp(cx->host, cx->fdhost))
|
||||
if (cx->fdhost && strcmp(cx->host, cx->fdhost))
|
||||
{
|
||||
free(cx->fdhost);
|
||||
cx->fdhost = NULL;
|
||||
@ -267,9 +267,9 @@ void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
|
||||
cx->fd = PERROR;
|
||||
cx->state = HTS_STRT;
|
||||
}
|
||||
if(data)
|
||||
if (data)
|
||||
{
|
||||
if(!dlen)
|
||||
if (!dlen)
|
||||
dlen = strlen(data);
|
||||
cx->txd = malloc(dlen);
|
||||
memcpy(cx->txd, data, dlen);
|
||||
@ -302,28 +302,28 @@ void http_async_add_header(void *ctx, char *name, char *data)
|
||||
static void process_header(struct http_ctx *cx, char *str)
|
||||
{
|
||||
char *p;
|
||||
if(cx->chunkhdr)
|
||||
if (cx->chunkhdr)
|
||||
{
|
||||
p = strchr(str, ';');
|
||||
if(p)
|
||||
if (p)
|
||||
*p = 0;
|
||||
cx->rxtogo = strtoul(str, NULL, 16);
|
||||
cx->chunkhdr = 0;
|
||||
if(!cx->rxtogo)
|
||||
if (!cx->rxtogo)
|
||||
cx->chunked = 0;
|
||||
}
|
||||
if(!str[0])
|
||||
if (!str[0])
|
||||
{
|
||||
cx->rxtogo = cx->contlen;
|
||||
cx->chunkhdr = cx->chunked;
|
||||
if(!cx->contlen && !cx->chunked && cx->ret!=100)
|
||||
if (!cx->contlen && !cx->chunked && cx->ret!=100)
|
||||
cx->state = HTS_DONE;
|
||||
return;
|
||||
}
|
||||
if(!strncmp(str, "HTTP/", 5))
|
||||
if (!strncmp(str, "HTTP/", 5))
|
||||
{
|
||||
p = strchr(str, ' ');
|
||||
if(!p)
|
||||
if (!p)
|
||||
{
|
||||
cx->ret = 603;
|
||||
cx->state = HTS_DONE;
|
||||
@ -333,17 +333,17 @@ static void process_header(struct http_ctx *cx, char *str)
|
||||
cx->ret = atoi(p);
|
||||
return;
|
||||
}
|
||||
if(!strncmp(str, "Content-Length: ", 16))
|
||||
if (!strncmp(str, "Content-Length: ", 16))
|
||||
{
|
||||
cx->contlen = atoi(str+16);
|
||||
return;
|
||||
}
|
||||
if(!strcmp(str, "Transfer-Encoding: chunked"))
|
||||
if (!strcmp(str, "Transfer-Encoding: chunked"))
|
||||
{
|
||||
cx->chunked = 1;
|
||||
return;
|
||||
}
|
||||
if(!strcmp(str, "Connection: close"))
|
||||
if (!strcmp(str, "Connection: close"))
|
||||
{
|
||||
cx->cclose = 1;
|
||||
return;
|
||||
@ -352,36 +352,36 @@ static void process_header(struct http_ctx *cx, char *str)
|
||||
|
||||
static void process_byte(struct http_ctx *cx, char ch)
|
||||
{
|
||||
if(cx->rxtogo)
|
||||
if (cx->rxtogo)
|
||||
{
|
||||
cx->rxtogo--;
|
||||
|
||||
if(!cx->rbuf)
|
||||
if (!cx->rbuf)
|
||||
{
|
||||
cx->rbuf = malloc(256);
|
||||
cx->rlen = 256;
|
||||
}
|
||||
if(cx->rptr >= cx->rlen-1)
|
||||
if (cx->rptr >= cx->rlen-1)
|
||||
{
|
||||
cx->rlen *= 2;
|
||||
cx->rbuf = realloc(cx->rbuf, cx->rlen);
|
||||
}
|
||||
cx->rbuf[cx->rptr++] = ch;
|
||||
|
||||
if(!cx->rxtogo && !cx->chunked)
|
||||
if (!cx->rxtogo && !cx->chunked)
|
||||
cx->state = HTS_DONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ch == '\n')
|
||||
if (ch == '\n')
|
||||
{
|
||||
cx->hbuf[cx->hptr] = 0;
|
||||
process_header(cx, cx->hbuf);
|
||||
cx->hptr = 0;
|
||||
}
|
||||
else if(ch != '\r')
|
||||
else if (ch != '\r')
|
||||
{
|
||||
if(cx->hptr >= cx->hlen-1)
|
||||
if (cx->hptr >= cx->hlen-1)
|
||||
{
|
||||
cx->hlen *= 2;
|
||||
cx->hbuf = realloc(cx->hbuf, cx->hlen);
|
||||
@ -401,12 +401,12 @@ int http_async_req_status(void *ctx)
|
||||
unsigned long tmp2;
|
||||
#endif
|
||||
|
||||
switch(cx->state)
|
||||
switch (cx->state)
|
||||
{
|
||||
case HTS_STRT:
|
||||
dns = getserv(cx->host);
|
||||
srv = getport(cx->host);
|
||||
if(resolve(dns, srv, &cx->addr))
|
||||
if (resolve(dns, srv, &cx->addr))
|
||||
{
|
||||
free(dns);
|
||||
free(srv);
|
||||
@ -423,45 +423,45 @@ int http_async_req_status(void *ctx)
|
||||
cx->last = now;
|
||||
return 0;
|
||||
case HTS_CONN:
|
||||
if(cx->fd == PERROR)
|
||||
if (cx->fd == PERROR)
|
||||
{
|
||||
cx->fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(cx->fd == PERROR)
|
||||
if (cx->fd == PERROR)
|
||||
goto fail;
|
||||
cx->fdhost = mystrdup(cx->host);
|
||||
#ifdef WIN32
|
||||
tmp2 = 1;
|
||||
if(ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
|
||||
if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
|
||||
goto fail;
|
||||
#else
|
||||
tmp = fcntl(cx->fd, F_GETFL);
|
||||
if(tmp < 0)
|
||||
if (tmp < 0)
|
||||
goto fail;
|
||||
if(fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
|
||||
if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
|
||||
goto fail;
|
||||
#endif
|
||||
}
|
||||
if(!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
|
||||
if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
|
||||
cx->state = HTS_IDLE;
|
||||
#ifdef WIN32
|
||||
else if(PERRNO==WSAEISCONN)
|
||||
else if (PERRNO==WSAEISCONN)
|
||||
cx->state = HTS_IDLE;
|
||||
#endif
|
||||
#ifdef MACOSX
|
||||
else if(PERRNO==EISCONN)
|
||||
else if (PERRNO==EISCONN)
|
||||
cx->state = HTS_IDLE;
|
||||
#endif
|
||||
else if(PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
|
||||
else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
|
||||
#ifdef WIN32
|
||||
&& PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
|
||||
#endif
|
||||
)
|
||||
goto fail;
|
||||
if(now-cx->last>http_timeout)
|
||||
if (now-cx->last>http_timeout)
|
||||
goto timeout;
|
||||
return 0;
|
||||
case HTS_IDLE:
|
||||
if(cx->txdl)
|
||||
if (cx->txdl)
|
||||
{
|
||||
// generate POST
|
||||
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 121 + cx->txdl + cx->thlen);
|
||||
@ -469,9 +469,9 @@ int http_async_req_status(void *ctx)
|
||||
cx->tlen = 0;
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path);
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host);
|
||||
if(!cx->keep)
|
||||
if (!cx->keep)
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
|
||||
if(cx->thdr)
|
||||
if (cx->thdr)
|
||||
{
|
||||
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
|
||||
cx->tlen += cx->thlen;
|
||||
@ -500,7 +500,7 @@ int http_async_req_status(void *ctx)
|
||||
cx->tlen = 0;
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path);
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host);
|
||||
if(cx->thdr)
|
||||
if (cx->thdr)
|
||||
{
|
||||
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
|
||||
cx->tlen += cx->thlen;
|
||||
@ -508,7 +508,7 @@ int http_async_req_status(void *ctx)
|
||||
cx->thdr = NULL;
|
||||
cx->thlen = 0;
|
||||
}
|
||||
if(!cx->keep)
|
||||
if (!cx->keep)
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
|
||||
#ifdef BETA
|
||||
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
|
||||
@ -522,39 +522,39 @@ int http_async_req_status(void *ctx)
|
||||
return 0;
|
||||
case HTS_XMIT:
|
||||
tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
|
||||
if(tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
|
||||
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
|
||||
goto fail;
|
||||
if(tmp!=PERROR)
|
||||
if (tmp!=PERROR)
|
||||
{
|
||||
cx->tptr += tmp;
|
||||
if(cx->tptr == cx->tlen)
|
||||
if (cx->tptr == cx->tlen)
|
||||
{
|
||||
cx->tptr = 0;
|
||||
cx->tlen = 0;
|
||||
if(cx->tbuf)
|
||||
if (cx->tbuf)
|
||||
free(cx->tbuf);
|
||||
cx->state = HTS_RECV;
|
||||
}
|
||||
cx->last = now;
|
||||
}
|
||||
if(now-cx->last>http_timeout)
|
||||
if (now-cx->last>http_timeout)
|
||||
goto timeout;
|
||||
return 0;
|
||||
case HTS_RECV:
|
||||
tmp = recv(cx->fd, buf, CHUNK, 0);
|
||||
if(tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
|
||||
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
|
||||
goto fail;
|
||||
if(tmp!=PERROR)
|
||||
if (tmp!=PERROR)
|
||||
{
|
||||
for(i=0; i<tmp; i++)
|
||||
for (i=0; i<tmp; i++)
|
||||
{
|
||||
process_byte(cx, buf[i]);
|
||||
if(cx->state == HTS_DONE)
|
||||
if (cx->state == HTS_DONE)
|
||||
return 1;
|
||||
}
|
||||
cx->last = now;
|
||||
}
|
||||
if(now-cx->last>http_timeout)
|
||||
if (now-cx->last>http_timeout)
|
||||
goto timeout;
|
||||
return 0;
|
||||
case HTS_DONE:
|
||||
@ -578,42 +578,42 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
|
||||
struct http_ctx *cx = ctx;
|
||||
char *rxd;
|
||||
|
||||
if(cx->state != HTS_DONE)
|
||||
while(!http_async_req_status(ctx)) ;
|
||||
if (cx->state != HTS_DONE)
|
||||
while (!http_async_req_status(ctx)) ;
|
||||
|
||||
if(cx->host)
|
||||
if (cx->host)
|
||||
{
|
||||
free(cx->host);
|
||||
cx->host = NULL;
|
||||
}
|
||||
if(cx->path)
|
||||
if (cx->path)
|
||||
{
|
||||
free(cx->path);
|
||||
cx->path = NULL;
|
||||
}
|
||||
if(cx->txd)
|
||||
if (cx->txd)
|
||||
{
|
||||
free(cx->txd);
|
||||
cx->txd = NULL;
|
||||
cx->txdl = 0;
|
||||
}
|
||||
if(cx->hbuf)
|
||||
if (cx->hbuf)
|
||||
{
|
||||
free(cx->hbuf);
|
||||
cx->hbuf = NULL;
|
||||
}
|
||||
if(cx->thdr)
|
||||
if (cx->thdr)
|
||||
{
|
||||
free(cx->thdr);
|
||||
cx->thdr = NULL;
|
||||
cx->thlen = 0;
|
||||
}
|
||||
|
||||
if(ret)
|
||||
if (ret)
|
||||
*ret = cx->ret;
|
||||
if(len)
|
||||
if (len)
|
||||
*len = cx->rptr;
|
||||
if(cx->rbuf)
|
||||
if (cx->rbuf)
|
||||
cx->rbuf[cx->rptr] = 0;
|
||||
rxd = cx->rbuf;
|
||||
cx->rbuf = NULL;
|
||||
@ -621,13 +621,13 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
|
||||
cx->rptr = 0;
|
||||
cx->contlen = 0;
|
||||
|
||||
if(!cx->keep)
|
||||
if (!cx->keep)
|
||||
http_async_req_close(ctx);
|
||||
else if(cx->cclose)
|
||||
else if (cx->cclose)
|
||||
{
|
||||
PCLOSE(cx->fd);
|
||||
cx->fd = PERROR;
|
||||
if(cx->fdhost)
|
||||
if (cx->fdhost)
|
||||
{
|
||||
free(cx->fdhost);
|
||||
cx->fdhost = NULL;
|
||||
@ -643,9 +643,9 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
|
||||
void http_async_get_length(void *ctx, int *total, int *done)
|
||||
{
|
||||
struct http_ctx *cx = ctx;
|
||||
if(done)
|
||||
if (done)
|
||||
*done = cx->rptr;
|
||||
if(total)
|
||||
if (total)
|
||||
*total = cx->contlen;
|
||||
}
|
||||
|
||||
@ -653,14 +653,14 @@ void http_async_req_close(void *ctx)
|
||||
{
|
||||
struct http_ctx *cx = ctx;
|
||||
void *tmp;
|
||||
if(cx->host)
|
||||
if (cx->host)
|
||||
{
|
||||
cx->keep = 1;
|
||||
tmp = http_async_req_stop(ctx, NULL, NULL);
|
||||
if(tmp)
|
||||
if (tmp)
|
||||
free(tmp);
|
||||
}
|
||||
if(cx->fdhost)
|
||||
if (cx->fdhost)
|
||||
free(cx->fdhost);
|
||||
PCLOSE(cx->fd);
|
||||
free(ctx);
|
||||
@ -669,11 +669,11 @@ void http_async_req_close(void *ctx)
|
||||
char *http_simple_get(char *uri, int *ret, int *len)
|
||||
{
|
||||
void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
|
||||
if(!ctx)
|
||||
if (!ctx)
|
||||
{
|
||||
if(ret)
|
||||
if (ret)
|
||||
*ret = 600;
|
||||
if(len)
|
||||
if (len)
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
@ -688,10 +688,10 @@ void http_auth_headers(void *ctx, char *user, char *pass)
|
||||
unsigned int m;
|
||||
struct md5_context md5;
|
||||
|
||||
if(user)
|
||||
if (user)
|
||||
{
|
||||
http_async_add_header(ctx, "X-Auth-User", user);
|
||||
if(pass)
|
||||
if (pass)
|
||||
{
|
||||
md5_init(&md5);
|
||||
md5_update(&md5, (unsigned char *)user, strlen(user));
|
||||
@ -701,7 +701,7 @@ void http_auth_headers(void *ctx, char *user, char *pass)
|
||||
md5_update(&md5, (unsigned char *)pass, strlen(pass));
|
||||
md5_final(hash, &md5);
|
||||
tmp = malloc(33);
|
||||
for(i=0; i<16; i++)
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
tmp[i*2] = hex[hash[i]>>4];
|
||||
tmp[i*2+1] = hex[hash[i]&15];
|
||||
@ -716,11 +716,11 @@ char *http_auth_get(char *uri, char *user, char *pass, int *ret, int *len)
|
||||
{
|
||||
void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
|
||||
|
||||
if(!ctx)
|
||||
if (!ctx)
|
||||
{
|
||||
if(ret)
|
||||
if (ret)
|
||||
*ret = 600;
|
||||
if(len)
|
||||
if (len)
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
@ -730,11 +730,11 @@ char *http_auth_get(char *uri, char *user, char *pass, int *ret, int *len)
|
||||
char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len)
|
||||
{
|
||||
void *ctx = http_async_req_start(NULL, uri, data, dlen, 0);
|
||||
if(!ctx)
|
||||
if (!ctx)
|
||||
{
|
||||
if(ret)
|
||||
if (ret)
|
||||
*ret = 600;
|
||||
if(len)
|
||||
if (len)
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
@ -743,7 +743,7 @@ char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len)
|
||||
|
||||
char *http_ret_text(int ret)
|
||||
{
|
||||
switch(ret)
|
||||
switch (ret)
|
||||
{
|
||||
case 100:
|
||||
return "Continue";
|
||||
@ -883,64 +883,64 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
|
||||
//struct md5_context md52;
|
||||
int own_plen = 0;
|
||||
|
||||
if(names)
|
||||
if (names)
|
||||
{
|
||||
if(!plens)
|
||||
if (!plens)
|
||||
{
|
||||
own_plen = 1;
|
||||
for(i=0; names[i]; i++) ;
|
||||
for (i=0; names[i]; i++) ;
|
||||
plens = calloc(i, sizeof(int));
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
plens[i] = strlen(parts[i]);
|
||||
}
|
||||
|
||||
retry:
|
||||
if(blen >= 31)
|
||||
if (blen >= 31)
|
||||
goto fail;
|
||||
memset(map, 0, 62*sizeof(int));
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
{
|
||||
for(j=0; j<plens[i]-blen; j++)
|
||||
if(!blen || !memcmp(parts[i]+j, boundary, blen))
|
||||
for (j=0; j<plens[i]-blen; j++)
|
||||
if (!blen || !memcmp(parts[i]+j, boundary, blen))
|
||||
{
|
||||
ch = parts[i][j+blen];
|
||||
if(ch>='0' && ch<='9')
|
||||
if (ch>='0' && ch<='9')
|
||||
map[ch-'0']++;
|
||||
else if(ch>='A' && ch<='Z')
|
||||
else if (ch>='A' && ch<='Z')
|
||||
map[ch-'A'+10]++;
|
||||
else if(ch>='a' && ch<='z')
|
||||
else if (ch>='a' && ch<='z')
|
||||
map[ch-'a'+36]++;
|
||||
}
|
||||
}
|
||||
m = ~0;
|
||||
j = 61;
|
||||
for(i=0; i<62; i++)
|
||||
if(map[i]<m)
|
||||
for (i=0; i<62; i++)
|
||||
if (map[i]<m)
|
||||
{
|
||||
m = map[i];
|
||||
j = i;
|
||||
}
|
||||
if(j<10)
|
||||
if (j<10)
|
||||
boundary[blen] = '0'+j;
|
||||
else if(j<36)
|
||||
else if (j<36)
|
||||
boundary[blen] = 'A'+(j-10);
|
||||
else
|
||||
boundary[blen] = 'a'+(j-36);
|
||||
blen++;
|
||||
if(map[j])
|
||||
if (map[j])
|
||||
goto retry;
|
||||
boundary[blen] = 0;
|
||||
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
dlen += blen+strlen(names[i])+plens[i]+128;
|
||||
dlen += blen+8;
|
||||
data = malloc(dlen);
|
||||
dlen = 0;
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
{
|
||||
dlen += sprintf(data+dlen, "--%s\r\n", boundary);
|
||||
dlen += sprintf(data+dlen, "Content-transfer-encoding: binary\r\n");
|
||||
if(strchr(names[i], ':'))
|
||||
if (strchr(names[i], ':'))
|
||||
{
|
||||
tmp = mystrdup(names[i]);
|
||||
p = strchr(tmp, ':');
|
||||
@ -960,26 +960,26 @@ retry:
|
||||
}
|
||||
|
||||
ctx = http_async_req_start(NULL, uri, data, dlen, 0);
|
||||
if(!ctx)
|
||||
if (!ctx)
|
||||
goto fail;
|
||||
|
||||
if(user)
|
||||
if (user)
|
||||
{
|
||||
http_async_add_header(ctx, "X-Auth-User", user);
|
||||
if(pass)
|
||||
if (pass)
|
||||
{
|
||||
md5_init(&md5);
|
||||
md5_update(&md5, (unsigned char *)user, strlen(user));
|
||||
md5_update(&md5, (unsigned char *)"-", 1);
|
||||
m = 0;
|
||||
if(names)
|
||||
if (names)
|
||||
{
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
{
|
||||
//md5_update(&md5, (unsigned char *)parts[i], plens[i]); //WHY?
|
||||
//md5_update(&md5, (unsigned char *)"-", 1);
|
||||
p = strchr(names[i], ':');
|
||||
if(p)
|
||||
if (p)
|
||||
m += (p - names[i]) + 1;
|
||||
else
|
||||
m += strlen(names[i])+1;
|
||||
@ -987,15 +987,15 @@ retry:
|
||||
|
||||
tmp = malloc(m);
|
||||
m = 0;
|
||||
for(i=0; names[i]; i++)
|
||||
for (i=0; names[i]; i++)
|
||||
{
|
||||
p = strchr(names[i], ':');
|
||||
if(m)
|
||||
if (m)
|
||||
{
|
||||
tmp[m] = ' ';
|
||||
m ++;
|
||||
}
|
||||
if(p)
|
||||
if (p)
|
||||
{
|
||||
memcpy(tmp+m, names[i], p-names[i]);
|
||||
m += p - names[i];
|
||||
@ -1014,7 +1014,7 @@ retry:
|
||||
md5_update(&md5, (unsigned char *)pass, strlen(pass));
|
||||
md5_final(hash, &md5);
|
||||
tmp = malloc(33);
|
||||
for(i=0; i<16; i++)
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
tmp[i*2] = hex[hash[i]>>4];
|
||||
tmp[i*2+1] = hex[hash[i]&15];
|
||||
@ -1025,7 +1025,7 @@ retry:
|
||||
}
|
||||
}
|
||||
|
||||
if(data)
|
||||
if (data)
|
||||
{
|
||||
tmp = malloc(32+strlen((char *)boundary));
|
||||
sprintf(tmp, "multipart/form-data, boundary=%s", boundary);
|
||||
@ -1034,18 +1034,18 @@ retry:
|
||||
free(data);
|
||||
}
|
||||
|
||||
if(own_plen)
|
||||
if (own_plen)
|
||||
free(plens);
|
||||
return http_async_req_stop(ctx, ret, len);
|
||||
|
||||
fail:
|
||||
if(data)
|
||||
if (data)
|
||||
free(data);
|
||||
if(own_plen)
|
||||
if (own_plen)
|
||||
free(plens);
|
||||
if(ret)
|
||||
if (ret)
|
||||
*ret = 600;
|
||||
if(len)
|
||||
if (len)
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
1170
src/interface.c
1170
src/interface.c
File diff suppressed because it is too large
Load Diff
926
src/main.c
926
src/main.c
File diff suppressed because it is too large
Load Diff
12
src/md5.c
12
src/md5.c
@ -32,7 +32,7 @@ void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
|
||||
|
||||
// update bit count
|
||||
t = ctx->bits[0];
|
||||
if((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t)
|
||||
if ((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t)
|
||||
ctx->bits[1]++; // carry
|
||||
ctx->bits[1] += len >> 29;
|
||||
|
||||
@ -40,7 +40,7 @@ void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
|
||||
|
||||
// use leading data to top up the buffer
|
||||
|
||||
if(t)
|
||||
if (t)
|
||||
{
|
||||
unsigned char *p = ctx->in + t;
|
||||
|
||||
@ -58,7 +58,7 @@ void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
|
||||
|
||||
// following 64-byte chunks
|
||||
|
||||
while(len >= 64)
|
||||
while (len >= 64)
|
||||
{
|
||||
memcpy(ctx->in, buf, 64);
|
||||
md5_transform(ctx->buf, ctx->in);
|
||||
@ -87,7 +87,7 @@ void md5_final(unsigned char digest[16], struct md5_context *ctx)
|
||||
count = 64 - 1 - count;
|
||||
|
||||
// Pad out to 56 mod 64
|
||||
if(count < 8)
|
||||
if (count < 8)
|
||||
{
|
||||
// we need to finish a whole block before padding
|
||||
memset(p, 0, count);
|
||||
@ -215,14 +215,14 @@ void md5_ascii(char *result, unsigned char const *buf, unsigned len)
|
||||
unsigned char hash[16];
|
||||
int i;
|
||||
|
||||
if(len==0)
|
||||
if (len==0)
|
||||
len = strlen((char *)buf);
|
||||
|
||||
md5_init(&md5);
|
||||
md5_update(&md5, buf, len);
|
||||
md5_final(hash, &md5);
|
||||
|
||||
for(i=0; i<16; i++)
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
result[i*2] = hex[(hash[i]>>4)&0xF];
|
||||
result[i*2+1] = hex[hash[i]&0x0F];
|
||||
|
68
src/misc.c
68
src/misc.c
@ -26,9 +26,9 @@ _inline unsigned clamp_flt(float f, float min, float max)
|
||||
inline unsigned clamp_flt(float f, float min, float max)
|
||||
#endif
|
||||
{
|
||||
if(f<min)
|
||||
if (f<min)
|
||||
return 0;
|
||||
if(f>max)
|
||||
if (f>max)
|
||||
return 255;
|
||||
return (int)(255.0f*(f-min)/(max-min));
|
||||
}
|
||||
@ -39,9 +39,9 @@ _inline float restrict_flt(float f, float min, float max)
|
||||
inline float restrict_flt(float f, float min, float max)
|
||||
#endif
|
||||
{
|
||||
if(f<min)
|
||||
if (f<min)
|
||||
return min;
|
||||
if(f>max)
|
||||
if (f>max)
|
||||
return max;
|
||||
return f;
|
||||
}
|
||||
@ -49,7 +49,7 @@ inline float restrict_flt(float f, float min, float max)
|
||||
char *mystrdup(char *s)
|
||||
{
|
||||
char *x;
|
||||
if(s)
|
||||
if (s)
|
||||
{
|
||||
x = (char*)malloc(strlen(s)+1);
|
||||
strcpy(x, s);
|
||||
@ -69,8 +69,8 @@ void strlist_add(struct strlist **list, char *str)
|
||||
int strlist_find(struct strlist **list, char *str)
|
||||
{
|
||||
struct strlist *item;
|
||||
for(item=*list; item; item=item->next)
|
||||
if(!strcmp(item->str, str))
|
||||
for (item=*list; item; item=item->next)
|
||||
if (!strcmp(item->str, str))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@ -78,7 +78,7 @@ int strlist_find(struct strlist **list, char *str)
|
||||
void strlist_free(struct strlist **list)
|
||||
{
|
||||
struct strlist *item;
|
||||
while(*list)
|
||||
while (*list)
|
||||
{
|
||||
item = *list;
|
||||
*list = (*list)->next;
|
||||
@ -91,7 +91,7 @@ void save_presets(int do_update)
|
||||
FILE *f=fopen("powder.def", "wb");
|
||||
unsigned char sig[4] = {0x50, 0x44, 0x65, 0x66};
|
||||
unsigned char tmp = sdl_scale;
|
||||
if(!f)
|
||||
if (!f)
|
||||
return;
|
||||
fwrite(sig, 1, 4, f);
|
||||
save_string(f, svf_user);
|
||||
@ -117,19 +117,19 @@ void load_presets(void)
|
||||
{
|
||||
FILE *f=fopen("powder.def", "rb");
|
||||
unsigned char sig[4], tmp;
|
||||
if(!f)
|
||||
if (!f)
|
||||
return;
|
||||
fread(sig, 1, 4, f);
|
||||
if(sig[0]!=0x50 || sig[1]!=0x44 || sig[2]!=0x65 || sig[3]!=0x66)
|
||||
if (sig[0]!=0x50 || sig[1]!=0x44 || sig[2]!=0x65 || sig[3]!=0x66)
|
||||
{
|
||||
if(sig[0]==0x4D && sig[1]==0x6F && sig[2]==0x46 && sig[3]==0x6F)
|
||||
if (sig[0]==0x4D && sig[1]==0x6F && sig[2]==0x46 && sig[3]==0x6F)
|
||||
{
|
||||
if(fseek(f, -3, SEEK_END))
|
||||
if (fseek(f, -3, SEEK_END))
|
||||
{
|
||||
remove("powder.def");
|
||||
return;
|
||||
}
|
||||
if(fread(sig, 1, 3, f) != 3)
|
||||
if (fread(sig, 1, 3, f) != 3)
|
||||
{
|
||||
remove("powder.def");
|
||||
goto fail;
|
||||
@ -142,26 +142,26 @@ void load_presets(void)
|
||||
remove("powder.def");
|
||||
return;
|
||||
}
|
||||
if(load_string(f, svf_user, 63))
|
||||
if (load_string(f, svf_user, 63))
|
||||
goto fail;
|
||||
if(load_string(f, svf_pass, 63))
|
||||
if (load_string(f, svf_pass, 63))
|
||||
goto fail;
|
||||
svf_login = !!svf_user[0];
|
||||
if(fread(&tmp, 1, 1, f) != 1)
|
||||
if (fread(&tmp, 1, 1, f) != 1)
|
||||
goto fail;
|
||||
sdl_scale = (tmp == 2) ? 2 : 1;
|
||||
if(fread(&tmp, 1, 1, f) != 1)
|
||||
if (fread(&tmp, 1, 1, f) != 1)
|
||||
goto fail;
|
||||
cmode = tmp%7;
|
||||
if(fread(&tmp, 1, 1, f) != 1)
|
||||
if (fread(&tmp, 1, 1, f) != 1)
|
||||
goto fail;
|
||||
svf_admin = tmp;
|
||||
if(fread(&tmp, 1, 1, f) != 1)
|
||||
if (fread(&tmp, 1, 1, f) != 1)
|
||||
goto fail;
|
||||
svf_mod = tmp;
|
||||
if(load_string(f, http_proxy_string, 255))
|
||||
if (load_string(f, http_proxy_string, 255))
|
||||
goto fail;
|
||||
if(fread(sig, 1, 3, f) != 3)
|
||||
if (fread(sig, 1, 3, f) != 3)
|
||||
goto fail;
|
||||
last_major = sig[0];
|
||||
last_minor = sig[1];
|
||||
@ -186,7 +186,7 @@ int load_string(FILE *f, char *str, int max)
|
||||
unsigned char lb[2];
|
||||
fread(lb, 2, 1, f);
|
||||
li = lb[0] | (lb[1] << 8);
|
||||
if(li > max)
|
||||
if (li > max)
|
||||
{
|
||||
str[0] = 0;
|
||||
return 1;
|
||||
@ -201,11 +201,11 @@ void strcaturl(char *dst, char *src)
|
||||
char *d;
|
||||
unsigned char *s;
|
||||
|
||||
for(d=dst; *d; d++) ;
|
||||
for (d=dst; *d; d++) ;
|
||||
|
||||
for(s=(unsigned char *)src; *s; s++)
|
||||
for (s=(unsigned char *)src; *s; s++)
|
||||
{
|
||||
if((*s>='0' && *s<='9') ||
|
||||
if ((*s>='0' && *s<='9') ||
|
||||
(*s>='a' && *s<='z') ||
|
||||
(*s>='A' && *s<='Z'))
|
||||
*(d++) = *s;
|
||||
@ -224,9 +224,9 @@ void strappend(char *dst, char *src)
|
||||
char *d;
|
||||
unsigned char *s;
|
||||
|
||||
for(d=dst; *d; d++) ;
|
||||
for (d=dst; *d; d++) ;
|
||||
|
||||
for(s=(unsigned char *)src; *s; s++)
|
||||
for (s=(unsigned char *)src; *s; s++)
|
||||
{
|
||||
*(d++) = *s;
|
||||
}
|
||||
@ -238,13 +238,13 @@ void *file_load(char *fn, int *size)
|
||||
FILE *f = fopen(fn, "rb");
|
||||
void *s;
|
||||
|
||||
if(!f)
|
||||
if (!f)
|
||||
return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
*size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
s = malloc(*size);
|
||||
if(!s)
|
||||
if (!s)
|
||||
{
|
||||
fclose(f);
|
||||
return NULL;
|
||||
@ -262,19 +262,19 @@ int cpu_check(void)
|
||||
#ifdef X86
|
||||
unsigned af,bf,cf,df;
|
||||
x86_cpuid(0, af, bf, cf, df);
|
||||
if(bf==0x68747541 && cf==0x444D4163 && df==0x69746E65)
|
||||
if (bf==0x68747541 && cf==0x444D4163 && df==0x69746E65)
|
||||
amd = 1;
|
||||
x86_cpuid(1, af, bf, cf, df);
|
||||
#ifdef X86_SSE
|
||||
if(!(df&(1<<25)))
|
||||
if (!(df&(1<<25)))
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef X86_SSE2
|
||||
if(!(df&(1<<26)))
|
||||
if (!(df&(1<<26)))
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef X86_SSE3
|
||||
if(!(cf&1))
|
||||
if (!(cf&1))
|
||||
return 1;
|
||||
#endif
|
||||
#endif
|
||||
|
2950
src/powder.c
2950
src/powder.c
File diff suppressed because it is too large
Load Diff
38
src/update.c
38
src/update.c
@ -43,16 +43,16 @@ static char *exe_name(void)
|
||||
{
|
||||
#if defined WIN32
|
||||
char *name= (char *)malloc(64), max=64, res;
|
||||
while((res = (char)GetModuleFileName(NULL, name, max)) >= max)
|
||||
while ((res = (char)GetModuleFileName(NULL, name, max)) >= max)
|
||||
{
|
||||
#elif defined MACOSX
|
||||
char *fn=malloc(64),*name=malloc(PATH_MAX), max=64, res;
|
||||
if(_NSGetExecutablePath(fn, &max) != 0)
|
||||
if (_NSGetExecutablePath(fn, &max) != 0)
|
||||
{
|
||||
fn = realloc(fn, max);
|
||||
_NSGetExecutablePath(fn, &max);
|
||||
}
|
||||
if(realpath(fn, name) == NULL)
|
||||
if (realpath(fn, name) == NULL)
|
||||
{
|
||||
free(fn);
|
||||
free(name);
|
||||
@ -63,7 +63,7 @@ static char *exe_name(void)
|
||||
char fn[64], *name=malloc(64), max=64, res;
|
||||
sprintf(fn, "/proc/self/exe");
|
||||
memset(name, 0, max);
|
||||
while((res = readlink(fn, name, max)) >= max-1)
|
||||
while ((res = readlink(fn, name, max)) >= max-1)
|
||||
{
|
||||
#endif
|
||||
#ifndef MACOSX
|
||||
@ -72,7 +72,7 @@ static char *exe_name(void)
|
||||
memset(name, 0, max);
|
||||
}
|
||||
#endif
|
||||
if(res <= 0)
|
||||
if (res <= 0)
|
||||
{
|
||||
free(name);
|
||||
return NULL;
|
||||
@ -89,24 +89,24 @@ int update_start(char *data, int len)
|
||||
FILE *f;
|
||||
int res = 1;
|
||||
|
||||
if(!self)
|
||||
if (!self)
|
||||
return 1;
|
||||
|
||||
#ifdef WIN32
|
||||
temp = malloc(strlen(self)+12);
|
||||
strcpy(temp, self);
|
||||
p = temp + strlen(temp) - 4;
|
||||
if(_stricmp(p, ".exe"))
|
||||
if (_stricmp(p, ".exe"))
|
||||
p += 4;
|
||||
strcpy(p, "_update.exe");
|
||||
|
||||
if(!MoveFile(self, temp))
|
||||
if (!MoveFile(self, temp))
|
||||
goto fail;
|
||||
|
||||
f = fopen(self, "wb");
|
||||
if(!f)
|
||||
if (!f)
|
||||
goto fail;
|
||||
if(fwrite(data, 1, len, f) != len)
|
||||
if (fwrite(data, 1, len, f) != len)
|
||||
{
|
||||
fclose(f);
|
||||
DeleteFile(self);
|
||||
@ -114,7 +114,7 @@ int update_start(char *data, int len)
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32)
|
||||
if ((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32)
|
||||
{
|
||||
DeleteFile(self);
|
||||
goto fail;
|
||||
@ -127,9 +127,9 @@ int update_start(char *data, int len)
|
||||
strcat(temp, "-update");
|
||||
|
||||
f = fopen(temp, "w");
|
||||
if(!f)
|
||||
if (!f)
|
||||
goto fail;
|
||||
if(fwrite(data, 1, len, f) != len)
|
||||
if (fwrite(data, 1, len, f) != len)
|
||||
{
|
||||
fclose(f);
|
||||
unlink(temp);
|
||||
@ -137,13 +137,13 @@ int update_start(char *data, int len)
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if(chmod(temp, 0755))
|
||||
if (chmod(temp, 0755))
|
||||
{
|
||||
unlink(temp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(rename(temp, self))
|
||||
if (rename(temp, self))
|
||||
{
|
||||
unlink(temp);
|
||||
goto fail;
|
||||
@ -167,14 +167,14 @@ int update_finish(void)
|
||||
temp = malloc(strlen(self)+12);
|
||||
strcpy(temp, self);
|
||||
p = temp + strlen(temp) - 4;
|
||||
if(_stricmp(p, ".exe"))
|
||||
if (_stricmp(p, ".exe"))
|
||||
p += 4;
|
||||
strcpy(p, "_update.exe");
|
||||
|
||||
while(!DeleteFile(temp))
|
||||
while (!DeleteFile(temp))
|
||||
{
|
||||
err = GetLastError();
|
||||
if(err == ERROR_FILE_NOT_FOUND)
|
||||
if (err == ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
// just as well, then
|
||||
free(temp);
|
||||
@ -182,7 +182,7 @@ int update_finish(void)
|
||||
}
|
||||
Sleep(500);
|
||||
timeout--;
|
||||
if(timeout <= 0)
|
||||
if (timeout <= 0)
|
||||
{
|
||||
free(temp);
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user