LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2009, 08:26 AM   #1
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 245
Blog Entries: 2

Rep: Reputation: 41
What all is there for programming for X in C?


I came across the gtk tutorials and have been going through them and find it to be fairly simple. So I was just wondering what else is there for programming in C. Most of what I have found so far is c++ related.
(Note: I really don't care for learning how to write games/image manipulation programs. I am only wanting to learn how to write text based programs using unicode and ascii.)


Oh, and if someone might know the answer to this. What are the correct terms to search for tutorials on how to scroll the screen in the console? I had tried to learn this before using DOS many years ago, but I don't know if the interupt calls are still used the same way as they were back on an old 486.
 
Old 04-10-2009, 02:13 PM   #2
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
What do you mean by 'text based program'?

Can your program function (assuming it did not need unicode) in the normal console?

If that is the case, then simply using a unicode aware terminal emulater in X should be all thats needed (I believe most emulaters need a argument passed that says to use unicode).

If thats not the case, then you will need a GUI toolkit. Only GTK is written in C, others are in C++. I believe Tk has C bindings tho, but I'm not aware of anyother toolkit thats even remotely popular that has plain C support.

And if your using interupts, stop. Look at Ncurses, if there is nothing about screen scrolling in there, then it probably cant be done and youll just have to implement it yourself. (note, I'm assuming your refering to scrolling the text console, if not, then use a scrolled window widget).

edit: Ah, there is also Cairo (not exactly a toolkit, and it'll require some extra low-level work with X to make it work fully) with Pango for text rendering.

Last edited by SciYro; 04-10-2009 at 02:15 PM.
 
Old 04-10-2009, 03:20 PM   #3
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 245

Original Poster
Blog Entries: 2

Rep: Reputation: 41
Thanks. I downloaded the ncurses manual and will have a look at it when I can.

As for text based programming, no I don't have a program yet. I'd like to, I am getting rather bored with all the tutorials and command line programs. Heck, I'd at least like to know how to position the cursor on screen. I did find it once, but haven't found it again and have been searching for weeks.

Anyway, why I was looking into scrolling the screen. I haven't programmed using interrupts since about 99, and that was basically using the mouse via int86(&h33, AX, BX...) using ASIC or int86old(&h33, rect) using Qbasic, as well as the keyboard (which I think was at &h10 or &h11, too long ago to remember), and had only began learning how to scroll on an old 486 before switching to WinXP which Qbasic no longer worked on it.

I've only been using C and linux for a few months and don't quite know exactly how one accesses the screen, mouse, etc through the console using C and linux on a computer 1.2g to 2.0g, or if there is some other way that it is done. I've read that instead of accessing the devices by int86() one would rather use open("/dev/device", something). However, I'm beginning to think that Linux has other methods to access the devices...

Eh, my mind is still in 99, lol, and I really haven't a clue what I should read in order to access the devices. Anyway, I'll have a look at ncurses and see what it says...

Thanks again...
 
Old 04-10-2009, 03:32 PM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Linux won't let you use interrupts unless you write your own kernel driver. You can move the cursor around the console using the standard escape sequences.

Any of the toolsets that are written for C++ can be invoked from C. Heck, I have been writing C++ classes that call gtk+ (and cairo and pango). Going back and forth between the two languages is not hard. In the worst case, you need stub routines that are callable by one language but call using the syntax of the other language. This is a frequent situation when using C to call C++.

You need to study /dev, /proc, and /sys. A lot of the information you want is found in those (particularly /dev).

Last edited by jiml8; 04-10-2009 at 03:34 PM.
 
Old 04-10-2009, 10:14 PM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
A user interface in a text based console is not X. I think you are sufficiently aware of that if I look at your posts.

Ncurses is the way to go when programming a menu driven application, I can't really call it a GUI. I know exactly what you mean with the DOS applications using interrupts etc. I did it myself, you know what a mess it was, single user, single application, TSRs etc.

Funny because in that time Unix was already around with curses available, the predecessor of ncurses. You can do what you need, text based screen navigation, but in a really structured way without ever having to worry about hardware. Even if you SSH into another computer you still can use your ncurses based application. The most well-known curses applications might be the kernel config program (make menuconfig) and Midnight Commander (mc)

Anyhow, you might run into difficulties in this like catching keystrokes and testing the value, there is buffered and unbuffered input, you have to initialize the screen properly. But again, this all is highly structured, and once you master that, writing your application is pretty straightforward. You will find plenty examples on the internet. There is also a widget library avaible which greatly extends the ncurses toolkit. I forgot the name, but you google it easily. Use the keys 'ncurses widget toolkit'

jlinkels
 
Old 04-10-2009, 11:51 PM   #6
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 245

Original Poster
Blog Entries: 2

Rep: Reputation: 41
Thanks Jlinkels, that's exactly what I'm looking for......

And as for programming in X, well, I guess I'll stick with gtk since it's used in programs more often, at least from what I've seen so far...

Last edited by Mol_Bolom; 04-10-2009 at 11:53 PM.
 
Old 04-11-2009, 05:12 PM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
also, the VT100 escape codes are fun:
e.g.

Code:
 printf "\33[2J\33[12;20H"
should put the cursor in the middle of your xterm somewhere.

p.s. that's the shell printf not the C one
but you get the idea.


(\33 is the ascii ESCAPE character)

Last edited by bigearsbilly; 04-11-2009 at 05:13 PM.
 
Old 04-11-2009, 06:22 PM   #8
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 245

Original Poster
Blog Entries: 2

Rep: Reputation: 41
Quote:
Originally Posted by bigearsbilly View Post
also, the VT100 escape codes are fun:
e.g.
Yeah, I came across those yesterday, was quite interesting to learn that ^[ wasn't the same as ^[ .
 
Old 04-11-2009, 07:36 PM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
yes that's how it's usually rendered.
if you type
CTRL-V ESC
in a terminal it'll look like that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New MSN group: programming fans -- enjoy programming lswhbcb Programming 1 06-29-2007 07:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration