473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Migrating C Code to C++ Builder

8 New Member
Hello C/C++ Gurus,

Could someone give me a quick hint, how to make this piece of C code Borland Builder-worthy? Or just explain the meaning of this piece of code. I try to compile a cross-plattform application named JSBSim (jsbsim.sourcef orge.net) with Borland Builder 6 and the compiler came up with following syntax intepretation problem:

Expand|Select|Wrap|Line Numbers
  1. const ENCODING *
  2. NS(XmlGetUtf8InternalEncoding)(void)
  3. {
  4.   return &ns(internal_utf8_encoding).enc;
  5. }
  6.  
I coded with delphi untill now and don't understand this syntactic construct.


Many thanks in advance
Mar 14 '06 #1
8 3860
Banfa
9,065 Recognized Expert Moderator Expert
You haven't provide enough context to make an answer possible.

This code is declaring a function returning const ENCODING * and taking no parameters. The function name is NS(XmlGetUtf8In ternalEncoding) . However ( and ) are not valid identifiers in a function name so something sneaky must be going on, I would assume that NS is a macro, you will need to find it to work out what it is doing, some possibilities are (but not limited to)

#define NS(x) x
#define NS(x) NS_##x

The function returns &ns(internal_ut f8_encoding).en c;

In English this would be a pointer (&) to the enc member (.enc) of a structure, union or class returned from the function ns (ns(...)) when it is passed the value internal_utf8_e ncoding.

Unless, of course, ns is also a macro (although normally by convention most people use upper case for macros) in which case it could be something else.
Mar 14 '06 #2
BugHunter
8 New Member
Thanks for the quick responce, Banfa.

The code i reference here is expat XML parser integrated per include into JSBSim cross-plattform FDM application. here is the entire code of the "xmltok_ns. c":

Expand|Select|Wrap|Line Numbers
  1. const ENCODING *
  2. NS(XmlGetUtf8InternalEncoding)(void)
  3. {
  4.   return &ns(internal_utf8_encoding).enc;
  5. }
  6.  
  7. const ENCODING *
  8. NS(XmlGetUtf16InternalEncoding)(void)
  9. {
  10. #if BYTEORDER == 1234
  11.   return &ns(internal_little2_encoding).enc;
  12. #elif BYTEORDER == 4321
  13.   return &ns(internal_big2_encoding).enc;
  14. #else
  15.   const short n = 1;
  16.   return (*(const char *)&n
  17.           ? &ns(internal_little2_encoding).enc
  18.           : &ns(internal_big2_encoding).enc);
  19. #endif
  20. }
  21.  
  22. static const ENCODING *NS(encodings)[] = {
  23.   &ns(latin1_encoding).enc,
  24.   &ns(ascii_encoding).enc,
  25.   &ns(utf8_encoding).enc,
  26.   &ns(big2_encoding).enc,
  27.   &ns(big2_encoding).enc,
  28.   &ns(little2_encoding).enc,
  29.   &ns(utf8_encoding).enc /* NO_ENC */
  30. };
  31.  
  32. static int PTRCALL
  33. NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
  34.                    const char **nextTokPtr)
  35. {
  36.   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
  37.                   XML_PROLOG_STATE, ptr, end, nextTokPtr);
  38. }
  39.  
  40. static int PTRCALL
  41. NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
  42.                     const char **nextTokPtr)
  43. {
  44.   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
  45.                   XML_CONTENT_STATE, ptr, end, nextTokPtr);
  46. }
  47.  
  48. int
  49. NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
  50.                     const char *name)
  51. {
  52.   int i = getEncodingIndex(name);
  53.   if (i == UNKNOWN_ENC)
  54.     return 0;
  55.   SET_INIT_ENC_INDEX(p, i);
  56.   p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
  57.   p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
  58.   p->initEnc.updatePosition = initUpdatePosition;
  59.   p->encPtr = encPtr;
  60.   *encPtr = &(p->initEnc);
  61.   return 1;
  62. }
  63.  
  64. static const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end){
  65. #define ENCODING_MAX 128
  66.   char buf[ENCODING_MAX];
  67.   char *p = buf;
  68.   int i;
  69.   XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
  70.   if (ptr != end)
  71.     return 0;
  72.   *p = 0;
  73.   if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
  74.     return enc;
  75.   i = getEncodingIndex(buf);
  76.   if (i == UNKNOWN_ENC)
  77.     return 0;
  78.   return NS(encodings)[i];
  79. }
  80.  
  81. int NS(XmlParseXmlDecl)(int isGeneralTextEntity,
  82.                     const ENCODING *enc,
  83.                     const char *ptr,
  84.                     const char *end,
  85.                     const char **badPtr,
  86.                     const char **versionPtr,
  87.                     const char **versionEndPtr,
  88.                     const char **encodingName,
  89.                     const ENCODING **encoding,
  90.                     int *standalone){
  91.   return doParseXmlDecl(NS(findEncoding),
  92.                         isGeneralTextEntity,
  93.                         enc,
  94.                         ptr,
  95.                         end,
  96.                         badPtr,
  97.                         versionPtr,
  98.                         versionEndPtr,
  99.                         encodingName,
  100.                         encoding,
  101.                         standalone);
  102. }
  103.  
  104.  
Mar 14 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
here is the entire code of the "xmltok_ns. c":
I find this statement hard to believe, I would have expected to see some

#include

statements at the top of the file.

You need to find the definition of NS which is clearly not in this file so must be in another file.
Mar 14 '06 #4
BugHunter
8 New Member
Hello Banfa,

This will hopefully solve the problem. The most helpfull hint is your explanation about the syntax meaning here. Many thanks!

I find this statement hard to believe, I would have expected to see some
BTW, try following: copy/paste the first line of the code and "google" for it. One of the first pages is the expat XML cvs web view and the source file looks exactly the same way as my copy. Should i fail in assembling broken pieces together, i just throw away entire XML parser thingy and'll try it my way.

Thanks again!
Mar 14 '06 #5
Banfa
9,065 Recognized Expert Moderator Expert
Right that makes things clearer, this file is not meant to be compiled stand alone, you have chosen to ask about 1 file out of context.

The context of this file is that it is included into xmltok.c and it is included like this

Expand|Select|Wrap|Line Numbers
  1. #define NS(x) x
  2. #define ns(x) x
  3. #include "xmltok_ns.c"
  4. #undef NS
  5. #undef ns
  6.  
The definitions result in the code in xmltok_ns.c taking a compilable form.

Are you familar with #define and what it does?

Anyway the code for the expat module compiles for me straight out of the box, so I guess that it's worth using.

You should not try to be compiling

xmltok_ns.c
xmltok_impl.c

they are not meant for direct compilation but for inclusion into xmltok.c
Mar 14 '06 #6
BugHunter
8 New Member
Wow Banfa,

I really didn't hope to solve my problem that easy :D. The project i try to compile is JSBSim, which uses expat to read in flight dynamics (XML tables).

I attempt to compile it with Borland Builder and have no project file for this compiler, in other words i set the inclusion paths and include sources into the project file one by one referencing the compiler error messages. So far, i was lucky to recreate entire JSBSim project, but as soon as it got to expat inclusion i stuck :D. No it won't be a problem at all i guess.

This is what i call the perfect refernce and helper board! Thank you very much!

P.S. I will get on configured PC tonight and give a try. Most probably it will work, i'll let you know tomorrow :).

P.P.S. I should learn C++. It's one of the languages looking elegant and powerfull for coding more complex stuff. Sofar i have been involved in some Delphi projects and the class architecture in Object Pascal appeared to be not that way flexible as it is in C++ (templating'n stuff).
Mar 14 '06 #7
BugHunter
8 New Member
Hello Banfa,
I changed the inclusion strategy in the project file and digged for DEFINES in the Visual Studio project file used to compile FlightGear (JSBSim is used here as a subset). As expected, after inserting the defines the compilation went totally diferent way but stuck again at the xmltok_ns.c. This time compiler was unable to handle constant symbol findEncoding: this string (my most basic description for this code-beeing) doesn't exist in any other source file. I also tried to grep for it in original expat 1.9... and 2.0.0: without any luck. This textual element appears to exist only in this source file and should probably belong to external source like compiler header library... will see... exploration goes on.
Mar 15 '06 #8
SimBuilder
1 New Member
BugHunter (and Banfa),

Thanks for pursuing this problem. I just happened to Google the web with the same problem that BugHunter is having. However, I'm building JSBSim in a Microsoft Visual C++ (v7.1) environment.

Here's what's going on:
The file that you are having the problem building is xmltok_ns.c . This is not a "complete" C file, rather it is only part of a file that is included by xmltok.c, as showin the in following section of xmltok.c
#define NS(x) x
#define ns(x) x
#include "xmltok_ns. c"
#undef NS
#undef ns

#ifdef XML_NS

#define NS(x) x ## NS
#define ns(x) x ## _ns

#include "xmltok_ns. c"

#undef NS
#undef ns
Solution: Remove xmltok_ns.c from your build list and just build xmltok.c . Also, make sure you have the correct includes at the top of xmltok.c (i.e., COMPILED_FROM_D SP for Win32 platforms).
FYI: It took two people to track down this little "trick" by the author...
Mar 30 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1324
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I click on the respective buttons absolutely nothing happens! I was wondering if anyone could help? The code I have is below... ADDING A RECORD Private Sub cmdaddstudent_Click() On Error GoTo Err_cmdaddstudent_Click
8
1442
by: gnu | last post by:
I'd my Windows free day! I don't have any more Windows machines within 10 yards of my house: Linux replaced everything: home theater box, servers, laptops, and desktops. My IPAQ runs familiar linux 0.7.1, OPIE windows environment. Most of my machines use Debian based distributions: Knoppix, Morphix, etc. I had a little app developed with Compact .NET Framework. Perhaps Java is more suitable for that (with excellent GPL Exclipse IDE), but I...
1
2505
by: new to access | last post by:
Im very new to access, how do I copy paste only a specific field and not any entire record? Specific fiel to specific field in another form.
1
2185
by: infp76 | last post by:
I'm creating a simple form in Access, and I've added a couple of drop-down calendars, but I don't know how to have the user-selected date append to the table with the rest of the form data. I'm guessing I need to select "Code Builder" after selecting Event Procedure (On Exit) on the Event tab. Does anyone know the VB code necessary to append the date to the table?? Or is there a different way to get this done? Any help is GREATLY...
2
2600
by: rafnavsun | last post by:
Hello Access experts, I am just new in this field and struggling with my code. I have a nested IF and it works in query but not sure how to apply it in form. I am thinking of making an event expression under "After Update". The idea is to populate the Description field by concatenating other fields. Below is the code I did in query, all help is appreciated. Description: IIf( Is Not Null And Is Not Null,(Trim( & " " & & " with " & & ",...
2
7185
by: diane | last post by:
I'm hurrying to error-check a bunch of in-house applications in Access 2007 before we roll it out to the whole firm in less than a month. One of the time-wasters I'm encountering is having to select "Code Builder" (as opposed to "Expression Builder" or "Macro Builder") every time I try to add an event to an object. Long, long ago I found out how to default this right to Code Builder in Access 2003, but it's been so long I don't remember...
6
4823
by: jambonjamasb | last post by:
Hi All, I am now on the next part of my quest. I have built my Form, which has used subforms to show my records and what I need to complete as the POL authority. I am now trying to jazz the form up so I thought of adding a next record and previous record button. I added two combo boxes called Next_Record and Previous_Button.
4
6024
by: VikrantS | last post by:
Hi, I am migrating code from VS 6.0 to VS2008. The Code compiles in VS 6.0 but gives the following errors when compiled in VS 2008, --- \Program Files\VC\atlmfc\include\afxcmn.inl(376) : error C2065: 'TVM_GETLINECOLOR' : undeclared identifier E:\Program Files\VC\atlmfc\include\afxcmn.inl(378) : error C2065: 'TVM_SETLINECOLOR' : undeclared identifier E:\Program Files\VC\atlmfc\include\afxcmn.inl(394) : error C2065: 'TVIF_STATEEX' :...
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.