Esempio n. 1
0
static int playback_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
	int changed = ucontrol->value.integer.value[0] != get_onoff();

	set_onoff( ucontrol->value.integer.value[0] );

	return changed;
}
Esempio n. 2
0
int
main (int argc, char ** argv) {
  int c, fd, irq, status, show_irq, offset = 0, retval;
  char *filename, *p;
  struct stat statbuf;
  struct command *cmds, *cmdst;

  progname = argv[0];
  if ((p = strrchr(progname, '/')) != NULL)
	  progname = p+1;

  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);

  if (argc < 2) print_usage(progname);

  cmdst = cmds = xmalloc(sizeof(struct command));
  cmds->next = 0;

  show_irq = 1;
  while ((c = getopt(argc, argv, "t:c:w:a:i:ho:C:sq:rT:vV")) != -1) {
    switch (c) {
    case 'h':
      print_usage(progname);
      break;
    case 'i':
      cmds->op = LPSETIRQ;
      cmds->val = get_val(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 't':
      cmds->op = LPTIME;
      cmds->val = get_val(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 'c':
      cmds->op = LPCHAR;
      cmds->val = get_val(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 'w':
      cmds->op = LPWAIT;
      cmds->val = get_val(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 'a':
      cmds->op = LPABORT;
      cmds->val = get_onoff(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 'q':
      if (get_onoff(optarg)) {
        show_irq=1;
      } else {
        show_irq=0;
      }
#ifdef LPGETSTATUS
    case 'o':
      cmds->op = LPABORTOPEN;
      cmds->val = get_onoff(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 'C':
      cmds->op = LPCAREFUL;
      cmds->val = get_onoff(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
    case 's':
      show_irq = 0;
      cmds->op = LPGETSTATUS;
      cmds->val = 0;
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
#endif
#ifdef LPRESET
    case 'r':
      cmds->op = LPRESET;
      cmds->val = 0;
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
#endif
#ifdef LPTRUSTIRQ
    case 'T':
      /* Note: this will do the wrong thing on 2.0.36 when compiled under 2.2.x */
      cmds->op = LPTRUSTIRQ;
      cmds->val = get_onoff(optarg);
      cmds->next = xmalloc(sizeof(struct command));
      cmds = cmds->next; cmds->next = 0;
      break;
#endif
    case 'v':
    case 'V':
      print_version(progname);
      exit(0);
    default:
      print_usage(progname);
    }
  }

  if (optind != argc-1)
    print_usage(progname);

  filename = strdup(argv[optind]);
  fd = open(filename, O_WRONLY|O_NONBLOCK, 0);
  /* Need to open O_NONBLOCK in case ABORTOPEN is already set and
     printer is off or off-line or in an error condition.  Otherwise
     we would abort... */
  if (fd < 0) {
    perror(filename);
    return -1;
  }

  fstat(fd, &statbuf);

  if(!S_ISCHR(statbuf.st_mode)) {
    printf(_("%s: %s not an lp device.\n"), argv[0], filename);
    print_usage(progname);
  }

  /* Allow for binaries compiled under a new kernel to work on the old ones */
  /* The irq argument to ioctl isn't touched by the old kernels, but we don't */
  /*  want to cause the kernel to complain if we are using a new kernel */
  if (LPGETIRQ >= 0x0600 && ioctl(fd, LPGETIRQ, &irq) < 0 && errno == EINVAL)
    offset = 0x0600;	/* We don't understand the new ioctls */

  cmds = cmdst;
  while (cmds->next) {
#ifdef LPGETSTATUS
    if (cmds->op == LPGETSTATUS) {
      status = 0xdeadbeef;
      retval = ioctl(fd, LPGETSTATUS - offset, &status);
      if (retval < 0)
	perror(_("LPGETSTATUS error"));
      else {
        if (status == 0xdeadbeef)	/* a few 1.1.7x kernels will do this */
          status = retval;
	printf(_("%s status is %d"), filename, status);
	if (!(status & LP_PBUSY)) printf(_(", busy"));
	if (!(status & LP_PACK)) printf(_(", ready"));
	if ((status & LP_POUTPA)) printf(_(", out of paper"));
	if ((status & LP_PSELECD)) printf(_(", on-line"));
	if (!(status & LP_PERRORP)) printf(_(", error"));
	printf("\n");
      }
    } else
#endif /* LPGETSTATUS */
    if (ioctl(fd, cmds->op - offset, cmds->val) < 0) {
      perror(_("tunelp: ioctl failed"));
    }
    cmdst = cmds;
    cmds = cmds->next;
    free(cmdst);
  }

  if (show_irq) {
    irq = 0xdeadbeef;
    retval = ioctl(fd, LPGETIRQ - offset, &irq);
    if (retval == -1) {
      perror(_("LPGETIRQ error"));
      exit(4);
    }
    if (irq == 0xdeadbeef)		/* up to 1.1.77 will do this */
      irq = retval;
    if (irq)
      printf(_("%s using IRQ %d\n"), filename, irq);
    else
      printf(_("%s using polling\n"), filename);
  }

  close(fd);

  return 0;
}
Esempio n. 3
0
int exec_menu(MENU menu)
{
 int i=0, cidx=0, fine;
 int off, ecnt=1;
 char tmp[MAXLEN];
 char output[MAXLEN];
 MENU tmenu = menu;
 int ret;
 int cpid;

 fine=1;
 while(cidx < tmenu.ncmd && fine)
 {
  off=1;
  switch(tmenu.cmd[cidx][0])
  {
   case '-':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	cpid = fork();
	if(cpid)
	{
	 waitpid(cpid,&ret,0);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	}
	else
	{
	 close(comport);
	 ret=system(tmp);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	 exit(ret);
	}
	if(off==1) ret=1;
	break;
   case '+':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	ret=execute(tmp, output, MAXLEN);
	sprintf(tmp, "$%d", ecnt++);
	setvar(tmp, output);
	if(off==1) ret=1;
	break;
   case '<':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"YesNo")==0 && argcnt==2)
	{
	 ret=get_yesno(args[1]);
	 sprintf(output,"%d",ret-1);
	 setvar("$YesNo",output);
	}
	if(strcmp(args[0],"OnOff")==0 && argcnt==3)
	{
	 ret=get_onoff(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret-1);
	 setvar("$OnOff",output);
	}
	if(strcmp(args[0],"Percent")==0 && argcnt==4)
	{
	 ret=get_percent(args[1], atoi(args[2]), atoi(args[3]));
	 sprintf(output,"%d",ret-1);
	 setvar("$Percent",output);
	}
	if(strcmp(args[0],"Choice")==0 && argcnt>=4)
	{
	 init_choice();
	 for(i=3; i<argcnt; i++)
	  addchoice(args[i]);
	 ret=get_choice(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret);
	 setvar("$Choice",output);
	}
	if(strcmp(args[0],"Real")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_real(output, args[1], args[2], args[3], args[4]);
	 setvar("$Real",output);
	}
	if(strcmp(args[0],"Int")==0 && (argcnt==5 || argcnt==6))
	{
	 if(argcnt==5) strcpy(args[5],"0");
	 ret=get_integer(output, args[1], args[2], atoi(args[3]), atoi(args[4]), atoi(args[5]));
	 setvar("$Int",output);
	}
	if(strcmp(args[0],"Phone")==0 && (argcnt==3 || argcnt==4))
	{
	 if(argcnt==3) strcpy(args[3],"");
	 ret=get_phone(output, args[1], args[2], args[3]);
	 setvar("$Phone",output);
	}
	if(strcmp(args[0],"Date")==0 && argcnt==2)
	{
	 ret=get_date(output, args[1]);
	 setvar("$Date",output);
	}
	if(strcmp(args[0],"Text")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_text(output, args[1], args[2], atoi(args[3]), args[4]);
	 setvar("$Text",output);
	}
	if(strcmp(args[0],"Secret")==0 && argcnt==4)
	{
	 ret=get_secret(output, args[1], args[2], atoi(args[3]));
	 setvar("$Secret",output);
	}
	break;
   case '>':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"MsgBox")==0 && (argcnt==2 || argcnt==3))
	{
	 if(argcnt==2) strcpy(args[2],"");
	 ret=msgbox(args[1], atoi(args[2]));
	}
	if(strcmp(args[0],"Info")==0 && argcnt>=3)
	 ret=info(args[1], args[2]);
	if(strcmp(args[0],"Status")==0 && argcnt>=2)
	 ret=status(args[1]);
	break;
   case ':':
   	for(i=0; i<fncnt; i++)
	 if(strcmp(tmenu.cmd[cidx]+1,flist[i].name)==0)
	  ret = flist[i].fn();
	break;
  }
  if(ret<=0) fine=0;
  cidx++;
 }
 return 0;
}
Esempio n. 4
0
static int playback_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
	ucontrol->value.integer.value[0] = get_onoff();

	return 0;
}