NO

Author Topic: PreProc  (Read 15054 times)

CommonTater

  • Guest
Re: PreProc
« Reply #15 on: January 07, 2012, 01:50:38 PM »
I have two questions to AddIn_EnumProjectFiles:

When is this function returning TRUE or FALSE resp.?
I haven't done a lot with this macro, but it would make sense for it to return true when it is returning a file and false when it's not... probably you'll get false at the end of the enum as a loop control, but the easy way is to try it and find out.

Quote
What about the return value of the callback function? It seems to me, that a return FALSE stopps enumeration. Is this right? Is this value returned by AddIn_EnumProjectFiles?

The callback is provided by you... and, again you need to test it to be sure, but I would think a return of false would stop the enum.

The AddIn SDK help file isn't terribly clear on this...

Quote
A  third point:
If  I enum project files, the file tst.c (which is excluded) is also listed.
How can I check, if a file is excluded?

While the AddIn mechanism is pretty flexible it's not perfect... take a look at the uFlags item in the struct, about your best bet if you're only wanting to run the preprocessor is to use the enum dependent files feature... not the enum all files.

Just a thought... but you might want to set it up to only run the preprocessor on the currently active file in the IDE...
 

czerny

  • Guest
Re: PreProc
« Reply #16 on: January 07, 2012, 02:46:09 PM »
Quote
I haven't done a lot with this macro, but it would make sense for it to return true when it is returning a file and false when it's not... probably you'll get false at the end of the enum as a loop control, but the easy way is to try it and find out.

What I get is always TRUE. I have hopped that it forwards the callback return. So I have to signal my search result over a global variable.

Quote
While the AddIn mechanism is pretty flexible it's not perfect... take a look at the uFlags item in the struct

If it is fuFlags, what you mean, this is of no help. I use
Code: [Select]
aepf.fuFlags = EPFF_DEPENDENT_FILES;and I think that tst.c should not in this file set because  it is excluded. But it is!


Quote
use the enum dependent files feature... not the enum all files

I have done this! See above.

czerny
« Last Edit: January 07, 2012, 02:52:48 PM by czerny »

czerny

  • Guest
Re: PreProc
« Reply #17 on: January 07, 2012, 02:58:05 PM »
I want to show my enum code. My be this is from help:

Code: [Select]
ADDIN_ENUM_PROJECT_FILES aepf = { 0 };

aepf.cbSize = sizeof(aepf);
aepf.fuFlags = EPFF_DEPENDENT_FILES;
aepf.pfnCallback= pfn;
aepf.pvData = szTmp; // actual files name
if (hwndProj && AddIn_EnumProjectFiles(hwndProj, &aepf))
AddIn_WriteOutput(hwndMain, _T("True"));
else
AddIn_WriteOutput(hwndMain, _T("False"));

and

Code: [Select]
BOOL pfn(LPCTSTR pszFilename, LPVOID pvData)
{
return !(_tcscmp(pszFilename, (TCHAR *)pvData)==0);
}


czerny

czerny

  • Guest
Re: PreProc
« Reply #18 on: January 08, 2012, 02:20:07 PM »
ok, I do not find a way to distinguish between ex- and included project files, I will go back to invoke pocc per CreateProcess.
If somebody finds something to the rename problem (s.a.) or the ex-, include difference I would be glad to hear from.

czerny

CommonTater

  • Guest
Re: PreProc
« Reply #19 on: January 08, 2012, 03:12:56 PM »
I'm sorry... I don't catch the relationship here... if you can't enumerate included files you have to use create process...  Why? 

Just start a build operation using the current file AddIn_GetActiveDocument and the preprocessor flags, as I explained earlier... It's pretty simple, click on the file you want to pre-process then click your button.  I sincerely don't see why you need to enumerate files and/or worry about anything except the active document...



czerny

  • Guest
Re: PreProc
« Reply #20 on: January 09, 2012, 12:44:51 AM »
1. If I try to compile a file which is part of the project but excluded the compilation is not executed and the flags are therefor not restored.
2. if I have an regular (included) file, loaded in a edit window, than rename this file in project window and then invoke preproc I get the same error.

czerny

CommonTater

  • Guest
Re: PreProc
« Reply #21 on: January 09, 2012, 01:19:33 AM »
Post your code... lets see what you're doing...

czerny

  • Guest
Re: PreProc
« Reply #22 on: January 09, 2012, 01:23:20 AM »
replace preproc-cp.c with preproc-pr.c.

czerny

CommonTater

  • Guest
Re: PreProc
« Reply #23 on: January 09, 2012, 03:57:45 AM »
Ok... what you want is probably something very close to this...

Note, this has been tested only very cursorily, no promises it will work exactly as you want, but it should give you the general idea... (i.e. there's bound to be a bug in there someplace.)
 
« Last Edit: January 09, 2012, 04:05:37 AM by CommonTater »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: PreProc
« Reply #24 on: January 09, 2012, 02:15:43 PM »
With this code you can borrow more options from current project for external file:
Code: [Select]
TCHAR *GetIFile(TCHAR *szFileName)
{
TCHAR *szTmp;

if (*szFileName)
{
szTmp = _tcsrchr(szFileName, '.');
*(++szTmp) = 'i';
*(++szTmp) = '\0';
}
return szFileName;
}

void ExecutePOCC(void)
{
HWND hwnd;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
ADDIN_DOCUMENT_INFO adi = { .cbSize = sizeof(adi) };
TCHAR szTmp[MAX_PATH*3];
TCHAR szTmp2[1024];

hwnd = AddIn_GetActiveDocument(hwndMain);
if (!hwnd) return;
if (!AddIn_GetDocumentInfo(hwnd, &adi)) return;
if ((adi.fDirty) || (!adi.szFilename[0]))
AddIn_SendIDECommand(hwndMain, AIC_FILE_SAVE);
if (!AddIn_GetDocumentInfo(hwnd, &adi)) return;
int nLen = AddIn_GetIDEFolder(hwndMain, ADDIN_FOLDER_BIN, szTmp, sizeof(szTmp)/sizeof(TCHAR));
_tcscat(szTmp, _T("\\pocc.exe -P "));
nLen += 13;
if (hwndProj && AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), &szTmp[nLen], sizeof(szTmp)/sizeof(TCHAR)-nLen)) {
_tcscat(szTmp, _T(" "));
AddIn_GetProjectSymbol(hwndProj, _T("INCLUDE"), szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
SetEnvironmentVariable(_T("INCLUDE"), szTmp2);
AddIn_GetProjectSymbol(hwndProj, _T("LIB"), szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
SetEnvironmentVariable(_T("LIB"), szTmp2);
}
_tcscat(szTmp, adi.szFilename);

//AddIn_WriteOutput(hwndMain, NULL);
AddIn_ClearOutput(hwndMain);
AddIn_WriteOutput(hwndMain, szTmp);

si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if (CreateProcess(NULL,szTmp,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
_tcscpy(szTmp,adi.szFilename);
AddIn_OpenDocument(hwndMain, AID_SOURCE, GetIFile(szTmp));
} else AddIn_WriteOutput(hwndMain, _T("error"));
}
« Last Edit: January 09, 2012, 02:18:08 PM by timovjl »
May the source be with you

czerny

  • Guest
Re: PreProc
« Reply #25 on: January 09, 2012, 05:56:35 PM »
hi timovjl,

if I understand your snippet right, this is just a info what else I can get from the project options.

It is NOT a solution to one of my problems, right?

czerny

czerny

  • Guest
Re: PreProc
« Reply #26 on: January 09, 2012, 06:14:57 PM »
Tater,

have you installed and checked your version?
I have not much time now. Will have a closer lock to night.

But as a quick view

1. There is no button
2. There is a /P option with every compile

czerny

czerny

  • Guest
Re: PreProc
« Reply #27 on: January 09, 2012, 10:51:38 PM »
Hallo CommonTater,

your snippet shows the same behaviour.

1. A just renamed file (in the project panel) doesn't compile.
2. A excluded file doesn't compile too.

czerny

CommonTater

  • Guest
Re: PreProc
« Reply #28 on: January 09, 2012, 11:41:59 PM »
Tater,

have you installed and checked your version?
I have not much time now. Will have a closer lock to night.

But as a quick view

1. There is no button
2. There is a /P option with every compile

czerny

I did check it here... but only so far as to make sure it compiled and did something resembling the desired function... I was not trying to provide you a working solution, just a direction to take in your project.  It is YOUR project, I'm not going to "steal your thunder".

My thought was for you to study the code and see the process, not to copy and paste it into your own project.
 
Excluded projects won't compile because they have no project "shells" for the compiler to use... Look at a project file in notepad, you will find that extra files and excluded files are listed in a special section at the bottom, apart from the active sections at the top.  (FWIW... the project file is also a sort of makefile)
 
« Last Edit: January 09, 2012, 11:44:51 PM by CommonTater »

czerny

  • Guest
Re: PreProc
« Reply #29 on: January 10, 2012, 12:23:14 AM »
Hi CommonTater,

it is clear to me, that an excluded file shouldn't be compiled by design. But this is not what I want.
I would like to write a test file with a macro to test and see, if it works. Such a test file should NOT be part of the project I am working on. So an excluded file needs to be compiled via CreateProcess.

On the other side it could be of use, to see the preprocessors result of a regular project. Than the AIC_PROJ_COMPILE way would be better.

But to differentiate between this two situations I have to parse the project file.

It remains the renaming problem. I consider this as a bug.

Can you verify this behaviour?

czerny