예제 #1
0
static t_unicode *type_one_key(t_unicode *in)
{
	int esc, keynum;
	t_unicode ch;
	t_unicode keysym;
	static char ctrl[]="JMGHLIK";

	stroke_pause = default_stroke_pause;
	if (!in || !in[0]) return 0;
	
	ch=*(in++);
	switch(ch) {
	case '\\': {
		ch=(*in++);
		if (!ch) return 0;
		esc = -1;
		switch(ch) {
		case 'v': esc++;
		case 't': esc++;
		case 'f': esc++;
		case 'b': esc++;
		case 'a': esc++;
		case 'r': esc++;
		case 'n': esc++;
		case '^': { /* example:  \a  == \^G  == <Ctrl>G
			       		 \r  == \^M  == <Ctrl>M == <ENTER> */
			if (esc >= 0) 
				ch = ctrl[esc];
			else
				ch = *(in++);
			keysym = ch;
			if (keysym != KEY_VOID) {
				if (keysym == KEY_M) {
					put_symbol(PRESS, KEY_RETURN);
					put_symbol(RELEASE, KEY_RETURN);
				} else {
					put_modified_symbol(PRESS, MODIFIER_CTRL, keysym);
					put_modified_symbol(RELEASE, MODIFIER_CTRL, keysym);
				}
			}
			return in;
		}
		case 'A': { /* example: \Az == <Alt>z */
			ch = *(in++);
			keysym = ch;
			if (keysym != KEY_VOID) {
				put_modified_symbol(PRESS, MODIFIER_ALT, keysym);
				put_modified_symbol(RELEASE, MODIFIER_ALT, keysym);
			}
			return in;
		}
        	case 'F': { /* example:  \F12;  == key F12
                	                 \F1;   == key F1 */
			keynum = GETNUMBER(in);
			if ((keynum > 0) && (keynum < 12)) {
				keysym = KEY_F1 + keynum -1;
				put_symbol(PRESS, keysym);	/* key pressed */
				put_symbol(RELEASE, keysym);	/* key released */
			}
			return in;
		}
		case 'p': { /* example:  \p100; == pause one second */
			keynum = GETNUMBER(in);
			if ((keynum > 0) && (keynum < 10000)) {
				stroke_pause = keynum;
			}
			return in;
		}
		case 'P': { /* example:  \P15; == set rate to 100/15 cps */
			keynum = GETNUMBER(in);
			if (keynum > 0) {
				keynum--;
				if (keynum > 100) keynum = 100;
				default_stroke_pause = keynum;
			}
			return in;
		}
		case 'M': { /* 'M' ==  as in Move, 
                       ('P' would be nicer (Pu for PageUp) but is already used...)
                       example: \Mh  == <HOME>   \Mu  == <PageUp>
                                \Me  == <END>    \Md  == <PageDown>
                                \M8  == <ArrowUp>
                                \M4  == <ArrowLeft>  \M6  == <ArrowRight>
                                \M2  == <ArrowDown>
                       */
			ch=*(in++);
			switch(ch) {
			case 'i': keynum = KEY_INS;  break;  /* KEY_INS */
			case 'h': keynum = KEY_HOME; break;  /* KEY_HOME */
			case 'u': keynum = KEY_PGUP; break;  /* KEY_PGUP */
			case 'c': keynum = KEY_DEL;  break;  /* KEY_DEL */
			case 'e': keynum = KEY_END;  break;  /* KEY_END */
			case 'd': keynum = KEY_PGDN; break;  /* KEY_PGDN */
			case '8': keynum = KEY_UP;   break;  /* KEY_UP */
			case '4': keynum = KEY_LEFT; break;  /* KEY_LEFT */
			case '6': keynum = KEY_RIGHT; break;  /* KEY_RIGHT */
			case '2':
			default:  keynum = KEY_DOWN; break;  /* KEY_DOWN */
			}
			move_key(PRESS, keynum);
			move_key(RELEASE, keynum);
			return in;
		}
		default:
                        ;
			/* fall through */
		}
	}
	default: {
		keysym = ch;
		if (keysym != KEY_VOID) {
			put_symbol(PRESS, keysym);	/* key pressed */
			put_symbol(RELEASE, keysym);	/* key release */
		}
		return in;
	}
	}
	return in;
}
예제 #2
0
파일: umain.c 프로젝트: jdigittl/crepes
int main (int argc, char *argv[])
{
  FILE *fopen(), *fpin;
  char *infile, *outbase, *outext, *filter;
  char *ppa, *ppb;
  char **pending_name;
  int *pending_number;
  int i, r;
  int verbose_flag;
  int begin_frame,max_frames;
  int pp_flag;
  int outtype;

  infile = NULL;
  outbase = NULL;
  outext = NULL;
  verbose_flag = 0;
  filter = NULL;
  begin_frame=1;
  max_frames=-1;
  outtype = PPM_RAW;

  /* scan arguments */

  pp_flag = 0;
  pending_number = NULL;
  pending_name = NULL;
  ppa = ppb = NULL;

  if (argc == 1)
    { print_usage(); exit(1); }

  for (i=1; i < argc; i++)
    {
      ppa=argv[i];
      if (pp_flag == 1)
        { SCANINT(ppa, pending_number); pp_flag = 0; }
      else if (pp_flag == 2)
        { *pending_name = ppa; pp_flag = 0; }
      else if (*ppa == '-')
	{
	  ppb = (ppa++);
	  switch (*ppa)
	    {
	    case 'b':   GETNUMBER(begin_frame); break;
	    case 'n':   GETNUMBER(max_frames); break;
	    case 'a':   outtype = PPM_ASCII; break;
	    case 'm':   outtype = FBM_MAPPED; break;
	    case 'f':   GETNAME(filter); break;
	    case 'v':   verbose_flag = 1; break;
	    case 'h':   print_usage(); print_help(); exit(1);
	    default:
	      fprintf(stderr,"Illegal option '%c' in argument %d\n",
		      *ppa,i);
	      print_hint();
	      exit(1);
	    }
	}
      else  if (infile == NULL)
	{
	  infile=argv[i];
	}
      else if (outbase == NULL)
	{
	  outbase=argv[i];
	}
      else if (outext == NULL)
	{
	  outext=argv[i];
	}
      else
	{
	  fprintf(stderr,"Too many parameters specified\n");
	  print_hint();
	  exit(1);
	}
    }

  if (pp_flag == 1)
    {
      fprintf(stderr,"Missing number behind option '%c'\n",*ppb);
      print_hint();
      exit(1);
    }

  if (outbase == NULL)
    {
      print_usage();
      exit(1);
    }

  /* fprintf(stderr,"Open Input File\n"); */
  if ((fpin = fopen(infile, "rb")) == NULL)
    {
      fprintf(stderr,"Error opening input file '%s'\n",infile);
      exit(1);
    }

  r = unfli(fpin,outbase,outext,outtype,
	    begin_frame,max_frames,verbose_flag,filter);

  if (r == 0)
    fprintf(stderr,"Stop\n");
  else if (r == 1)
    fprintf(stderr,"Ready\n");
  else if (r == -1)
    fprintf(stderr,"Read error\n");
  else if (r == -2)
    fprintf(stderr,"Error allocating memory\n");
  else
    fprintf(stderr,"Unknown error\n");

  fclose(fpin);

  return(0);
}