Re: Graphics and C with linux

1998-09-22 Thread VAN SY

Try this http://www.gtk.org. Hope this is what you are looking for


Van Sy
[EMAIL PROTECTED]

On Mon, 21 Sep 1998, Richard Ivanowich wrote:

 Very simple question...
   I want to know how to draw lines, rectangles, circle, etc. in the console
 or in X windows.  Can anyone give me some example code or point me in the
 right direction.
 
 Richard Ivanowich
 



Re: Graphics and C with linux

1998-09-22 Thread ZioBudda

On Mon, 21 Sep 1998, Richard Ivanowich wrote:

 Very simple question...
   I want to know how to draw lines, rectangles, circle, etc. in the console
 or in X windows.  Can anyone give me some example code or point me in the
 right direction.

www.gtk.org

A SI BIRI
--
Italian Linux Meeting - http://www.pluto.linux.it/meeting/
--
Morelli 'ZioBudda' Davide Michel - Member of Pluto Linux User Group
[EMAIL PROTECTED] - http://ziobudda.enter.it/
Linux Problem? Ask to [EMAIL PROTECTED]
"/dev/ziobudda: access to /var/tmp/beer denied, use /var/adm/pineapple"



Re: FD_ISSET -- select -- bug?? need help.

1998-09-22 Thread doc

On Fri, 18 Sep 1998, Bug Hunter wrote:

 
 We are using a stock redhat 5.1 in an embedded system.
 It is not on the internet, and has _very_ few services. (for
 you hacker types).
 
 If this is on the wrong list, please point me to a
 better list.  thanks!
 
 we opened a pipe without error.  we then did this:
 FD_ZERO(InputFD);  // initialize read
 descriptors
 
 FD_SET(s,InputFD); // Add
 socket to descriptors to
 FD_SET(FromDH,InputFD);// wait on Modem
 data as well
 
 FD_ZERO(wErrorFD);
 FD_SET(s,wErrorFD);
 FD_SET(FromDH, wErrorFD);
 
 signal(SIGALRM,SignalHandler);
 
 while(1){
 wInputFD = InputFD;
 // don't wait more than 500msec before
 reporting
 timeout.tv_sec = 0;
 timeout.tv_usec = 50;
 short result =
 select(FD_SETSIZE,wInputFD,NULL,wErrorFD,timeout);
 ...
 
 
 We get a 2 from select, then the pipe (FromDH) indicates
 an error.  errno is zero.  There is no error that we can
 see.  any clues?


I am not sure, but I think the SIGALARM and select use the same timer.
If my suposition is true, should be normaly for select to have strange 
behavior when got a interrupt.

Any oppinion ?

--
Best wishes,
Marcel - Titus MARGINEAN
[EMAIL PROTECTED], [EMAIL PROTECTED]



Re: How to use getopt() ?

1998-09-22 Thread Marin D


On Tue, 22 Sep 1998, Antonis Kanavouras wrote:

-  my C books are too old- no reference to getopt(). 
-  till today I wrote loops from scratch to manipulate comnd line options
-  ~# man 3 getopt makes me more confused

Try the glibc info pages ( Ctrl -H, I from Emacs, then browse to glibc /
Process Startup / Program Arguments / Parsing Options / )

-  Any simple  source files for example ?
-

There is a nice example too. U may find useful some simple option parsing
program sources ( ping , traceroute).

BTW any security FAQ proposes avoiding getopt() but this is hard to
achieve...

Regards,

Marin



   "Knowledge is not a crime. Some of its applications are..."

 - Unknown hacker





Re: FD_ISSET -- select -- bug?? need help.

1998-09-22 Thread Glynn Clements


Henrik Nordstrom wrote:

 Glynn Clements wrote:
 
  I don't think that you should use select() on descriptors which are
  non-blocking. You would normally either use select() or non-blocking
  I/O, but not both.
 
 I have to disagree here. Using select is REQUIRED when doing
 non-blocking I/O. There is no other method for waiting until data is
 available (or check which filedescriptors that have data waiting if you
 are using a zero timeout).

Using select() is required if you only want to read from a descriptor
when there is data available (e.g. because the read() would otherwise
block).

If the descriptor is non-blocking (O_NONBLOCK), read() will return -1
and set errno to EAGAIN. You don't need to check whether data is
available in order to prevent blocking.

-- 
Glynn Clements [EMAIL PROTECTED]



Re: How to use getopt() ?

1998-09-22 Thread Glynn Clements


Antonis Kanavouras wrote:

   my C books are too old- no reference to getopt(). 
   till today I wrote loops from scratch to manipulate comnd line options
   ~# man 3 getopt makes me more confused
   Any simple  source files for example ?

Look at the source for any of the GNU utilities. They nearly all use
getopt() for parsing the command line.

Also, the libc Info file has a couple of examples of using getopt().

-- 
Glynn Clements [EMAIL PROTECTED]



Re: Graphics and C with linux

1998-09-22 Thread Glynn Clements


Richard Ivanowich wrote:

   I want to know how to draw lines, rectangles, circle, etc. in the console
 or in X windows.  Can anyone give me some example code or point me in the
 right direction.

For the console, see the SVGAlib documentation, specifically the stuff
about the VGAGL library.

For X, you need to create a shell containing a suitable canvas widget. 
If you're using Motif, use an XmDrawingArea widget. I can send you the
code for a non-Motif canvas widget.

Then, add a callback for Expose events, which redraws the window using
the appropriate Xlib calls.

If you are unfamiliar with X programming, get a decent book.

-- 
Glynn Clements [EMAIL PROTECTED]



Re: Need help writing a terminal emulator

1998-09-22 Thread Glynn Clements


Syslab Sales and Services Pvt Ltd. wrote:

  You just need to be able to receive and send data via a serial
 ..
  Whenever a key is pressed, you need to send the corresponding ASCII
  code via the serial connection.
  

   1. How do I describe this terminal in termcap/terminfo?

You only need a termcap/terminfo entry if you wish to use the terminal
for `full-screen' applications, e.g. vi, Emacs. With only 2 lines,
this isn't likely to be of much use.

  I have just read something about the curses library, however a
  book on the curses library is not available here in India.
  Where could I get more info/downloadable tutorial perhaps?
  I'm currently reading the man page.

The manual pages should provide adequate documentation. Try looking at
some existing entries (use `infocmp' to read terminfo files).

   2. How do I make sure that Linux initialises this terminal on
  startup?
   3. How do I make sure that the getty  login processes are carried
out on starting?

If the terminal will be permanently connected, add a getty process to
/etc/inittab, e.g.

s1:12345:respawn:/sbin/agetty 19200 ttyS0 dumb

`19200' is the line speed, `ttyS0' is the serial port, and `dumb' is
the terminal type (used to initialise $TERM).

-- 
Glynn Clements [EMAIL PROTECTED]



Re: daemons

1998-09-22 Thread Glynn Clements


James wrote:

 how do i write a daemon? I know what they are (little programs that do something
 useful in the background), but are they just normal programs that get pushed
 into the background?

Basically, yes.

 how do i make one (e.g foobar) and have it so that it runs in the background
 if you type 'foobar -D' (or something).
 I have a feeling it has something to do with fork() but how? For a fork() to
 work you need a parent process and a child don't you?

No. fork() creates the child process.

To create a daemon, you would basically:

1. Call fork(). The parent process then exits, leaving the child
running in the background.

2. Call setsid() to establish a new session and process group.

3. Call `chdir("/")'.

4. Call umask(0), so that file modes aren't affected by any inherited
umask setting.

5. Close all open file descriptors.

Also, you should specify O_NOCTTY when opening anything which might be
a terminal device, so that the process doesn't inadvertantly acquire a
controlling TTY.

 and how do i monitor a /dev/TTYS? device so that when my modem picks up
 the line and connects to a remote computer my daemon does something, then
 when the modem puts down the line the daemon does something else?

This is difficult to do in a portable manner. You could try using the
TIOCMGET ioctl() to monitor the status lines; that may be adequate. 
Alternatively, you could try polling for a lock file.

-- 
Glynn Clements [EMAIL PROTECTED]



Re: daemons

1998-09-22 Thread Marin D



On Tue, 22 Sep 1998, James wrote:

-how do i write a daemon? I know what they are (little programs that do something
-useful in the background), but are they just normal programs that get pushed
-into the background?
-

Take a look at the c-programming FAQ available under
ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/lang/c

-and how do i monitor a /dev/TTYS? device so that when my modem picks up
-the line and connects to a remote computer my daemon does something, then
-when the modem puts down the line the daemon does something else?
-

U need to watch for the DCD line. Glynn Clements proposed once using the
TIOCMGET ioctl call and I find this quite useful. Something like this:



#include unistd.h
#include stdio.h
#include fcntl.h
#include sys/types.h
#include sys/stat.h
#include sys/ioctl.h
#include syslog.h


#define SLEEP_INTERVAL  5
#define DCD_HIGH1
#define DCD_LOW 0

extern char* program_invocation_short_name;

int TestDCD(int nDevice)
{
  int nStatus;
  
  if (ioctl(nDevice,TIOCMGET,nStatus) == -1)
{
  // oops something went wrong...

  syslog(LOG_ERR,"ioctl error!\n");
  exit(1);
}
  else
return nStatus  TIOCM_CD;   
}


int main(int argc,char** argv)
{
  int fd;
  
  openlog(program_invocation_short_name,0,LOG_DAEMON);  
  
  if (-1 == (fd = open( /*PUT THE TTYS DEVICE HERE*/ ,O_RDWR)))
{
  syslog(LOG_ERR,"Canot open device\n");
  exit(1);
};

  while ( DCD_LOW == TestDCD(fd) )
sleep(SLEEP_INTERVAL);

  /* here u have the DCD high i.e. modem connected */
  /* do some stuff*/

  while ( DCD_HIGH == TestDCD(fd) )
sleep(SLEEP_INTERVAL);

  /* here the modems are already disconnected */
  /* do other  stuff */


  closelog();

  return 0;
}


U may consider installing SIGALARM handler.

Regards,

Marin




   "Knowledge is not a crime. Some of its applications are..."

 - Unknown hacker






Re: FD_ISSET -- select -- bug?? need help.

1998-09-22 Thread Bug Hunter

hmmm.  I'm not sure that is it.  We have abandoned looking at select for
errors for the pipe.

It could be a sigalarm, as the timeout may have tripped.  However we are also
using sigalarm, and that code was not executed.   And, select did not return a -1,
and there were no errors indicated on the non-pipe handles.

bug


[EMAIL PROTECTED] wrote:

 On Fri, 18 Sep 1998, Bug Hunter wrote:

 
  We are using a stock redhat 5.1 in an embedded system.
  It is not on the internet, and has _very_ few services. (for
  you hacker types).
 
  If this is on the wrong list, please point me to a
  better list.  thanks!
 
  we opened a pipe without error.  we then did this:
  FD_ZERO(InputFD);  // initialize read
  descriptors
 
  FD_SET(s,InputFD); // Add
  socket to descriptors to
  FD_SET(FromDH,InputFD);// wait on Modem
  data as well
 
  FD_ZERO(wErrorFD);
  FD_SET(s,wErrorFD);
  FD_SET(FromDH, wErrorFD);
 
  signal(SIGALRM,SignalHandler);
 
  while(1){
  wInputFD = InputFD;
  // don't wait more than 500msec before
  reporting
  timeout.tv_sec = 0;
  timeout.tv_usec = 50;
  short result =
  select(FD_SETSIZE,wInputFD,NULL,wErrorFD,timeout);
  ...
 
 
  We get a 2 from select, then the pipe (FromDH) indicates
  an error.  errno is zero.  There is no error that we can
  see.  any clues?

 I am not sure, but I think the SIGALARM and select use the same timer.
 If my suposition is true, should be normaly for select to have strange
 behavior when got a interrupt.

 Any oppinion ?

 --
 Best wishes,
 Marcel - Titus MARGINEAN
 [EMAIL PROTECTED], [EMAIL PROTECTED]