You are here: PSPad forum > Bug report / Hlášení chyb > Code Explorer Bug - C++ (build 2272)
Posted by: FoGyuri | Date: 09/07/2007 08:46 | IP: IP Logged
The #ifdef #else #endif pat of the following code snippet seems to prevent successfully parsing the remaining code. (I tried to keep only the relevant parts of the code, therefore it is a nonsense in its current form obviousy)
-------
static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
{
struct stat st;
if (len <= tdb->map_size)
return 0;
return 0;
}
static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
{
if (tdb->map_ptr)
memcpy(off + (char *)tdb->map_ptr, buf, len);
#ifdef HAVE_PWRITE
else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| write(tdb->fd, buf, len) != (ssize_t)len) {
#endif
return TDB_ERRCODE(TDB_ERR_IO, -1);
}
return 0;
}
static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
{
if (tdb->map_ptr)
memcpy(buf, off + (char *)tdb->map_ptr, len);
#ifdef HAVE_PREAD
else if (pread(tdb->fd, buf, len, off) != (ssize_t)len) {
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| read(tdb->fd, buf, len) != (ssize_t)len) {
#endif
return TDB_ERRCODE(TDB_ERR_IO, -1);
}
return 0;
}
static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len)
{
char *buf;
return buf;
}
Posted by: wal | Date: 09/07/2007 12:05 | IP: IP Logged
This problem exists long time in PSPad. Seems that editor counts opening and closing brackets ignoring #ifdef, #else, #endif directives. So it founds two opening brackets "{" and only one closing bracket "}" and seems this confuses code explorer.
As workaround I am trying to move opening bracket after #endif. So modified your example is shown correctly in code explorer:
static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
{
struct stat st;
if (len <= tdb->map_size)
return 0;
return 0;
}
static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
{
if (tdb->map_ptr)
memcpy(off + (char *)tdb->map_ptr, buf, len);
#ifdef HAVE_PWRITE
else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len)
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| write(tdb->fd, buf, len) != (ssize_t)len)
#endif
{
return TDB_ERRCODE(TDB_ERR_IO, -1);
}
return 0;
}
static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
{
if (tdb->map_ptr)
memcpy(buf, off + (char *)tdb->map_ptr, len);
#ifdef HAVE_PREAD
else if (pread(tdb->fd, buf, len, off) != (ssize_t)len)
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| read(tdb->fd, buf, len) != (ssize_t)len)
#endif
{
return TDB_ERRCODE(TDB_ERR_IO, -1);
}
return 0;
}
static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len)
{
char *buf;
return buf;
}
Posted by: pspad | Date: 09/27/2007 22:19 | IP: IP Logged
PSPad isn't compiler. It can't evaluate compiler conditions - it doesn't know conditions values.
Posted by: MilanA | Date: 10/04/2007 15:44 | IP: IP Logged
Possible workaround:
Parser doesn't need to really evaluate the condition values. It could treat section between #else and #endif as commented-out.
(Considering condition after #if to be true. - or - This can even be configurable, so that the user can choose which branch of #if/#else/#endif to take into account.)
It will probably not work in every possible case, but it may improve the result in usual situations.
Posted by: pspad | Date: 10/06/2007 21:41 | IP: IP Logged
I modified Code parser. In the next build PSPad should handle conditions. It will skip content #else..#end.
It should correctly handle multilevel conditions too.
Please check next build and let me know.
If something will be worng, send me sample and info.
Editor PSPad - freeware editor, © 2001 - 2013 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák