473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Migrating C Code to C++ Builder

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.sourceforge.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 3840
Banfa
9,065 Expert Mod 8TB
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(XmlGetUtf8InternalEncoding). 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_utf8_encoding).enc;

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_encoding.

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
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 Expert Mod 8TB
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
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 Expert Mod 8TB
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
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
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
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_DSP 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
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...
8
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...
1
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
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...
2
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...
2
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...
6
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.