Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
Hi there
 
I want to write my own console window using c++ and make it cross-platform
 
But I don't know from where should I start and how to write it
 

Should I write it using C++ and OpenGL or what, and in the same time I want to make it a cross-platform project but I don't know can I do this or I should use every platform''s APIs to achieve that and write a project for every platform
 
Should I use win32 APIs to write it for windows and Linux APIs to write it for Linux
 
Note: I'm going to write it because I want to make a console window that supports Arabic, because the existing consoles just supports English, so I want to write my own console to draw Arabic characters to it and make it available for every platform so developers can write console applications that supports Arabic  
 

Thanks in advance
Posted 5-Nov-11 20:29pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

A console is a ... console (something that is used to give commands to a system). It should support the less languages required to sustain a dialog towards the system, otherwise is anymore a console, but right more a "graphical application to manage text".
 
And a "multi-platform console" risk to be an illusion, since it has to be used to send command to the underlying operating system (so you also need a multi-platform command interpreter, may be even multi-language - but this way there will be no more scripting portability...)
 
Anyway, a multi-platform application should be defined in term of a self-consistent interaction model,exposing the the user/other programs the functions required to interact with it, and them "map" that model onto the underlying interaction model of the system is implemented on.
The first part is essentially "platform independent", the second part is "platform dependent" and should exist in as many versions as the underlying platforms and variants are.
 
All this in theory. In practice this may result in tons of "passthrough" code, so -as the most of platform application are- that clear distinction is not always "well evident", and lot of
#ifdef PLATFORM_WINDOWS
... do the windows way
#endif
#ifdef PLATFORM_LINUX
... do the linux way
#endif
will exist, inlined with the code.
  Permalink  
Comments
Amir Mahfoozi at 6-Nov-11 7:02am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you use pure C and make sure all your library calls are POSIX compliant you should be able to make it cross-platform. The basic functionality of a console is :
Do Forever
{
    Read next string
    Split string into words
    Switch on first word
    {
        If internal command
            run subroutine 
        If external command
            execute command process
        If unknown
            display error message
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This can be acheived with POSIX compliant functions. This is supported by almost all platforms including Linux, OSX, BSD, and many others (Windows not included). The basic idea is in Richard's answer, but when you execute an external command you open up some pipes and then spawn a child process.
See Mapping UNIX pipe descriptors to stdin and stdout in C[^] for an example on how to do this in a UNIX based environment (including linux and OSX) or QuickWin[^] for Windows. Create a common function for doing things, and use Emilio's solution to select the correct code based on the platform.
 
As for the GUI side of things, I'd suggest something like QT[^] which is cross platform. Just saves you having to do that bit cross platform too.
 
Whatever you end up doing, make sure that you are using some form of extended character set, like Unicode. You will probably need to convert the output from many of the programs, as they typically only print or take input in ASCII.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 6 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100