LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-22-2004, 11:51 PM   #1
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Rep: Reputation: 45
C File I/O. Need asistance.


Hi all, again me... Although I have knowledge of the C language, I think my I/O on files is way basic for what I need/want to do. My problem is that I have made a BASH script to do a series of tasks, with a nice user interface (Ok, just messages going by asking for user interaction). Anyway, this program depended on file interaction, because after its execution it would generate a specially formatted text file with various information:

Linux version (uname -smrp)
Memory
Graphics
etc.

In a C program, how would I get all this information?

I'd like now to make the same but with a nice Graphical User Interface, where the user may enter all the neede data (the questions of before) and then just let the program execute and verify see the output from that file... I just don't know where to start...

My biggest problem is that I would not know how to edit a text file in a specific location (for example similar to a find/replace function in a text editor.

I want to use GTK, by the way. Thanks for any info.
 
Old 02-23-2004, 12:19 AM   #2
Darktyco
Member
 
Registered: Aug 2003
Location: michigan
Distribution: slackware
Posts: 59

Rep: Reputation: 15
If I were you I'd get all that information out of /proc. Specifically memory out of /proc/meminfo and linux version from /proc/sys/kernel/osrelease. I'm not sure about the graphics information, are you looking for info on the device or info on the drivers?
 
Old 02-23-2004, 12:24 AM   #3
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Original Poster
Rep: Reputation: 45
Quote:
Originally posted by Darktyco
I'm not sure about the graphics information, are you looking for info on the device or info on the drivers?
If it's possible about both. I'm particularly interested on the Renderer string (as reported by glxinfo under OpenGL renderer) and the OpenGL version (since there is posted the driver version). In my BASH script I used the commands with the aid of grep and gawk, but in C how would I accomplish that... I'm trying to as much as I can... But still I have no clue.
 
Old 02-23-2004, 07:26 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The uname stuff is best taken from the uname function in sys/utsname.h. It would be faster to get it that way then to read/parse the proc files. Read the man page (man 2 uname) to figure out how to use it.

As far as that grapics information, I am guessing that the OpenGL libraries would have functions to get that information.
 
Old 02-23-2004, 02:19 PM   #5
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Original Poster
Rep: Reputation: 45
Thanks for the reply, I'll keep looking.
 
Old 02-23-2004, 02:49 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Check out the Xfree Library Functions. I saw a few that might be helpful at a quick glance like "ScreenOfDisplay", "ServerVendor", and 'VendorRelease".
 
Old 02-23-2004, 04:43 PM   #7
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Call
const GLubyte *glGetString (GLenum name)

and link to libGL.

The manpage will give you the name arguments you require.
 
Old 02-23-2004, 04:44 PM   #8
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Original Poster
Rep: Reputation: 45
Thanks!
 
Old 02-23-2004, 08:16 PM   #9
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Original Poster
Rep: Reputation: 45
Yes, this glGetString () function is what I need... I just don't seem to find where is it defined... I guess I should include gl.h or something?
 
Old 02-24-2004, 05:42 AM   #10
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Yes, but it is a bit more complicated than that, I am afraid.

gl.h is probably in /usr/include/GL/ ... make sure you have the opengl-dev package or whatever RedHat call it nowadays.

However, to make the call, OpenGL must first be initialised and that is performed by the windowing system not OpenGL :-(

You are already using GTK and there are OpenGL widgets for that (gtkglext and gtkglarea, I believe) and there is GLX which is the OpenGL interface to XWindows, which would cover this.

I think the easiest thing for you to do is to use glut, which is a platform independent OpenGl rendering toolkit and extremely easy to use - at least just to get started. The same underlying calls can be made by GTK, raw XWindows or whatever. This is quickest and easiest to give you an example and I am lazy.

Example using glut

You will need to #include <GL/glut.h> which also brings in gl.h and you will need to link to libglut.so.

Write a function that calls glutInit() and glutCreateWindow() - this will perform the necessary initialisation and then call glGetString() to get the information you want. The window will not be displayed and you can then use the information as you desire. Then glutDestroyWindow() the window and return the string.
A c++ example:
Code:
#include <iostream>
#include <GL/glut.h>

int main( int argc, char *argv[] )
{
  glutInit( &argc, argv );                  
  int win=glutCreateWindow( "Invisible" );
  std::cout << glGetString( GL_VENDOR ) << '\n';
  glutDestroyWindow( win );
}
Built with: g++ info.cpp -o oglinfo -lglut

Disclaimer: I don't know all the internals of glut, it's just useful sometimes, but you should get the result you want - it runs without the glutInit() call but the manual says this is needed - go figure!

reference: http://www.opengl.org/resources/libr...ec3/spec3.html
 
Old 02-24-2004, 05:53 AM   #11
Thetargos
Senior Member
 
Registered: Mar 2003
Location: Mexico City
Distribution: Fedora, Ubuntu & Mint
Posts: 1,679

Original Poster
Rep: Reputation: 45
Thanks a lot! I'll use your example as a guidelines for calling it from within a GTK2 window. I hope it works...
 
  


Reply



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
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 10:22 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
libawt.so: libXp.so.6: cannot open shared object file: No such file or directory man26 *BSD 0 09-10-2004 08:34 AM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 09:11 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM

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

All times are GMT -5. The time now is 01:28 PM.

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