Beispiel #1
0
/***************************************************************************
 * Read and process output from the application
 ***************************************************************************/
void get_token()
{
   unsigned int c;	/* magic token GCC_NULL is 0x100 so need an int*/ 


   /* somewhat changed. Matthias */ 
   /* Wait for something to do! */
   c = get_com_char(0);
   do {
     /* Got a character. Figure out what to do with it. */
      if(c>=' ' || c == '\n' || c == '\r' || c == '\t') 
	read_string();
      else
	{
	  switch(c)
	    {
	    case 0:         /* NUL does nothing */
	      break;
	    case EOF:
	      clean_exit(0);
	      break;
	    case 5:
	      cprintf("\033[?1;2c");/* I'm a VT100 w/ advanced video options */
	      break;
	    case 0xb:
	      scr_index(1);
	      break;
	    case 0xc:
	      scr_index(1);
	      break;
	    case ESC:
	      process_escape_sequence();
	      break;
	    case '\b' :
	      scr_backspace();
	      break;
	    case '\007' :	/* bell */
#ifdef MAPALERT
	      if (map_alert) XMapWindow(display,main_win);
#endif
	      XBell(display,0);
	      break;
	    case '\016':
	      scr_choose_charset(1);
	      break;
	    case '\017':
	      scr_choose_charset(0);
	      break;
	    }
	}
      c = get_com_char(1);
   }while(c != (unsigned int) GCC_NULL);
}
Beispiel #2
0
void process_csi_sequence()
{
  int c,n,i,nargs,private=0;
  int arg[ARGS_MAX];
  extern char *display_name;

  arg[0]=0;
  arg[1]=0;

  c = get_com_char(0);
    if (c >= '<' && c <= '?') 
    {
      private = c;
      c = get_com_char(0);
    }
Beispiel #3
0
void process_escape_sequence()
{
  int c,a;

  c = get_com_char(0);
  switch(c)
    {
    case '[':
      process_csi_sequence();
      break;
    case ']':
      process_xterm_sequence();
      break;
    case '(':
      scr_set_charset(0,get_com_char(0));
      break;
    case ')':
      scr_set_charset(1,get_com_char(0));
      break;
    case '7':
      scr_save_cursor();
      break;
    case '8' :
      scr_restore_cursor();
      break;
    case '=' :
      app_kp_keys = 1;
      break;
    case '>' :
      app_kp_keys = 0;
      break;
    case 'D' :
      scr_index(1);
      break;
    case 'E':
      scr_add_lines("\n\r",1,2);
      break;
    case 'M' :
      scr_index(-1);
      break;
    case 'Z' :
      /* cprintf("\033[?6c"); */	/* I am a VT102 */
      cprintf("\033[?1;2c");	/* changed to vt100 (Matthias) */ 
      break;
    case 'c' :                  /* restore power-on values */
      scr_power_on();
      break;
    case '#':                /* set character size */
      a=get_com_char(0);
      if(a=='8')
	scr_E();
      break;
    case 'H' :               /* horizontal tab set */
      scr_set_tab(1);
      break;
    case 'G' :
      process_robs_sequence();
    default:
      return;
    }
} 
Beispiel #4
0
void process_print_pipe()
{
  extern char *print_pipe;
  int c = 0;
  int pid, roura[2];
  char escape_seq [4] = "\033[4i";
  char rev_escape_seq [4] = "i4[\033";
  int index = 0;
  FILE *pipe_file=NULL;

  /* ****************** new part **************************** */
  if(pipe(roura)==-1){
    perror("kvt:pipe");
    return;
    }
  pid=fork();
  if(pid<0){
    perror("kvt:fork");
    return;
    }
  if(pid==0){
    if(close(0)==-1 || dup(roura[0])==-1 || close(roura[0])==-1 || close(roura[1])==-1){
      perror("kvt:child:dup");
      exit(1);
      }
    if(execlp(print_pipe,print_pipe,0)==-1){
      perror("kvt:exec");
      exit(1);
      }
    }
  else{
    if(close(roura[0])==-1)
      perror("kvt:close");
    if((pipe_file=fdopen(roura[1],"w"))==NULL)
      perror("kvt:fdopen");
    }        
  /* ********************* end ************************** */

  if (pipe_file == NULL)
    {
    fprintf (stderr, "rxvt: can't open printer pipe!\n");
    return ;
    }
  while (1)
    {
    c = get_com_char(0);
    
    if (c == escape_seq [index])
      index++;
    else 
      if (index)
        for (/*no init'ln*/; index > 0; index--)
          fputc (rev_escape_seq [index-1], pipe_file);
    
    if (index == 4) 
      {
      /* *********** some changes ************ */

      /*fflush (pipe_file);   --fclose flushes too */
      fclose (pipe_file);
      /* waitpid(pid,&stat,WUNTRACED); */
      return ;
      }

    if (index == 0) fputc (c, pipe_file);
    }
}
Beispiel #5
0
/*  Return an input token
 */
void get_token(struct tokenst* tk)
{
    int c, i, n;
    struct xeventst *xe;
    static unsigned int time1 = 0, time2 = 0;

    tk->tk_private = 0;
    tk->tk_type = TK_NULL;

    if ((xe = pop_xevent()) != NULL)
    {
        if (xe->xe_window == vt_win)
            tk->tk_region = SCREEN;
        /*
        else if (xe->xe_window == sb_win)
            tk->tk_region = SCROLLBAR;
        */ 
        else if (xe->xe_window == main_win)
            tk->tk_region = MAINWIN;
        else
            tk->tk_region = -1;
        switch (xe->xe_type)
        {
        case EnterNotify :
            tk->tk_type = TK_ENTRY;
            tk->tk_arg[0] = 1;
            tk->tk_nargs = 1;
            break;
        case LeaveNotify :
            tk->tk_type = TK_ENTRY;
            tk->tk_arg[0] = 0;
            tk->tk_nargs = 1;
            break;
        case FocusIn :
            tk->tk_type = TK_FOCUS;
            tk->tk_arg[0] = 1;
            tk->tk_arg[1] = xe->xe_detail;
            tk->tk_nargs = 2;
            break;
        case FocusOut :
            tk->tk_type = TK_FOCUS;
            tk->tk_arg[0] = 0;
            tk->tk_arg[1] = xe->xe_detail;
            tk->tk_nargs = 2;
            break;
        case Expose :
            tk->tk_type = TK_EXPOSE;
            tk->tk_arg[0] = xe->xe_x;
            tk->tk_arg[1] = xe->xe_y;
            tk->tk_arg[2] = xe->xe_width;
            tk->tk_arg[3] = xe->xe_height;
            tk->tk_nargs = 4;
            break;
        case ConfigureNotify :
            tk->tk_type = TK_RESIZE;
            tk->tk_nargs = 0;
            break;
        case SelectionClear :
            tk->tk_type = TK_SELCLEAR;
            tk->tk_arg[0] = xe->xe_time;
            tk->tk_nargs = 1;
            break;
        case SelectionNotify :
            tk->tk_type = TK_SELNOTIFY;
            tk->tk_arg[0] = xe->xe_time;
            tk->tk_arg[1] = xe->xe_requestor;
            tk->tk_arg[2] = xe->xe_property;
            tk->tk_nargs = 3;
            break;
        case SelectionRequest :
            tk->tk_type = TK_SELREQUEST;
            tk->tk_arg[0] = xe->xe_time;
            tk->tk_arg[1] = xe->xe_requestor;
            tk->tk_arg[2] = xe->xe_target;
            tk->tk_arg[3] = xe->xe_property;
            tk->tk_nargs = 4;
            break;
        case ButtonPress :
            if (xe->xe_window == vt_win && xe->xe_state == ControlMask)
            {
                /*tk->tk_type = TK_SBSWITCH;*/
                tk->tk_nargs = 0;
                break;
            }
            if (xe->xe_window == vt_win && (xe->xe_state & ControlMask) == 0)
            {
                switch (xe->xe_button)
                {
                case Button1 :
                    if (xe->xe_time - time2 < MP_INTERVAL)
                    {
                        time1 = 0;
                        time2 = 0;
                        tk->tk_type = TK_SELLINE;
                    }
                    else if (xe->xe_time - time1 < MP_INTERVAL)
                    {
                        time2 = xe->xe_time;
                        tk->tk_type = TK_SELWORD;
                    }
                    else
                    {
                        time1 = xe->xe_time;
                        tk->tk_type = TK_SELSTART;
                    }
                    break;
                case Button2 :
                    tk->tk_type = TK_NULL;
                    break;
                case Button3 :
                    tk->tk_type = TK_SELEXTND;
                    break;
                }
                tk->tk_arg[0] = xe->xe_x;
                tk->tk_arg[1] = xe->xe_y;
                tk->tk_nargs = 2;
                break;
            }
            /*
            if (xe->xe_window == sb_win)
            {
                if (xe->xe_button == Button2)
                {
                    tk->tk_type = TK_SBGOTO;
                    tk->tk_arg[0] = xe->xe_y;
                    tk->tk_nargs = 1;
                }
            }
            */
            break;
        case ButtonRelease :
            /*
            if (xe->xe_window == sb_win)
            {
                switch (xe->xe_button)
                {
                case Button1 :
                    tk->tk_type = TK_SBUP;
                    tk->tk_arg[0] = xe->xe_y;
                    tk->tk_nargs = 1;
                    break;
                case Button3 :
                    tk->tk_type = TK_SBDOWN;
                    tk->tk_arg[0] = xe->xe_y;
                    tk->tk_nargs = 1;
                    break;
                }
            }
            */
            /*else*/ if (xe->xe_window == vt_win &&
                     (xe->xe_state & ControlMask) == 0)
            {
                switch (xe->xe_button)
                {
                case Button1 :
                case Button3 :
                    tk->tk_type = TK_SELECT;
                    tk->tk_arg[0] = xe->xe_time;
                    tk->tk_nargs = 1;
                    break;
                case Button2 :
                    tk->tk_type = TK_SELINSRT;
                    tk->tk_arg[0] = xe->xe_time;
                    tk->tk_arg[1] = xe->xe_x;
                    tk->tk_arg[2] = xe->xe_y;
                    tk->tk_nargs = 3;
                    break;
                }
            }
            break;
        case MotionNotify :
            /*
            if (xe->xe_window == sb_win && (xe->xe_state & Button2Mask))
            {
                Window root, child;
                int root_x, root_y, x, y;
                unsigned int mods;

                XQueryPointer(display,sb_win,&root,&child,
                              &root_x,&root_y,&x,&y,&mods);
                if (mods & Button2Mask)
                {
                    tk->tk_type = TK_SBGOTO;
                    tk->tk_arg[0] = y;
                    tk->tk_nargs = 1;
                }
                break;
            }
            */
            if (xe->xe_window == vt_win && (xe->xe_state & Button1Mask) &&
                    !(xe->xe_state & ControlMask))
            {
                tk->tk_type = TK_SELDRAG;
                tk->tk_arg[0] = xe->xe_x;
                tk->tk_arg[1] = xe->xe_y;
                tk->tk_nargs = 2;
                break;
            }
            break;

        }
        free((void *)xe);
        return;
    }
    if ((c = get_com_char(GET_XEVENTS)) == GCC_NULL)
    {
        tk->tk_type = TK_NULL;
        return;
    }

    if (c == EOF)
    {
        tk->tk_type = TK_EOF;
        return;
    }
    if (is_string_char(c))
    {
        i = 0;
        tk->tk_nlcount = 0;
        do
        {
            tk->tk_string[i++] = c;
            c = get_com_char(1);
            if (c == '\n' && ++tk->tk_nlcount >= NLMAX)
            {
                tk->tk_nlcount--;
                break;
            }
        }
        while (is_string_char(c) && i < TKS_MAX);
        tk->tk_length = i;
        tk->tk_string[i] = 0;
        tk->tk_type = TK_STRING;
        if (c != GCC_NULL)
            push_com_char(c);
    }
    else if (c == ESC)
    {
        c = get_com_char(0);
        if (c == '[')
        {
            c = get_com_char(0);
            if (c >= '<' && c <= '?')
            {
                tk->tk_private = c;
                c = get_com_char(0);
            }

            /*  read any numerical arguments
             */
            i = 0;
            do
            {
                n = 0;
                while (c >= '0' && c <= '9')
                {
                    n = n * 10 + c - '0';
                    c = get_com_char(0);
                }
                if (i < TK_MAX_ARGS)
                    tk->tk_arg[i++] = n;
                if (c == ESC)
                    push_com_char(c);
                if (c < ' ')
                    return;
                if (c < '@')
                    c = get_com_char(0);
            }
            while (c < '@' && c >= ' ');
            if (c == ESC)
                push_com_char(c);
            if (c < ' ')
                return;
            tk->tk_nargs = i;
            tk->tk_type = c;
        }
        else if (c == ']')
        {
            c = get_com_char(0);
            n = 0;
            while (c >= '0' && c <= '9')
            {
                n = n * 10 + c - '0';
                c = get_com_char(0);
            }
            tk->tk_arg[0] = n;
            tk->tk_nargs = 1;
            c = get_com_char(0);
            i = 0;
            while ((c & 0177) >= ' ' && i < TKS_MAX)
            {
                if (c >= ' ')
                    tk->tk_string[i++] = c;
                c = get_com_char(0);
            }
            tk->tk_length = i;
            tk->tk_string[i] = 0;
            tk->tk_type = TK_TXTPAR;
        }
        else if (c == '#' || c == '(' || c == ')')
        {
            tk->tk_type = c;
            c = get_com_char(0);
            tk->tk_arg[0] = c;
            tk->tk_nargs = 1;
        }
        else if (c == '7' || c == '8' || c == '=' || c == '>')
        {
            tk->tk_type = c;
            tk->tk_nargs = 0;
        }
        else
        {
            switch (c)
            {
            case 'D' :
                tk->tk_type = TK_IND;
                break;
            case 'E' :
                tk->tk_type = TK_NEL;
                break;
            case 'H' :
                tk->tk_type = TK_HTS;
                break;
            case 'M' :
                tk->tk_type = TK_RI;
                break;
            case 'N' :
                tk->tk_type = TK_SS2;
                break;
            case 'O' :
                tk->tk_type = TK_SS3;
                break;
            case 'Z' :
                tk->tk_type = TK_DECID;
                break;
            default :
                return;
            }
        }
    }
    else
    {
        tk->tk_type = TK_CHAR;
        tk->tk_char = c;
    }
}