예제 #1
0
/* Use a visual editor ($EDITOR,$VISUAL, or vi) to edit a crontab,
 * then copy the new one into CRONDIR
 */
void
visual(struct passwd *pwd)
{
    char ans[20];
    char commandline[80];
    char *editor;
    char *yn;
    struct stat st;
    int save_euid = geteuid();

    xchdir(pwd->pw_dir ? pwd->pw_dir : "/tmp");
    strcpy(vitemp, "/tmp/.crontab.XXXXXX");
    seteuid(getuid());
    mktemp(vitemp);

    atexit(nomorevitemp);

    if ( ((editor = getenv("EDITOR")) == 0) && ((editor = getenv("VISUAL")) == 0) )
	editor="vi";

    if ( access(editor, X_OK) == 0 )
	fatal("%s: %s", editor, strerror(errno));

    sprintf(commandline, "crontab -l > %s", vitemp);
    system(commandline);

    if ( (stat(vitemp, &st) != -1) && (st.st_size == 0) )
	unlink(vitemp);

    sprintf(commandline, "%s %s", editor, vitemp);
    while (1) {
	if ( system(commandline) == -1 )
	    fatal("running %s: %s", editor, strerror(errno));
	seteuid(save_euid);
	if ( (stat(vitemp, &st) == -1) || (st.st_size == 0)
	                                 || newcrontab(vitemp, pwd->pw_name))
	    exit(0);
	seteuid(getuid());
	do {
	    fprintf(stderr, "Do you want to retry the same edit? ");
	    fgets(ans, sizeof ans, stdin);
	    yn = firstnonblank(ans);
	    *yn = toupper(*yn);
	    if (*yn == 'N')
		exit(1);
	    if (*yn != 'Y')
		fprintf(stderr, "(Y)es or (N)o; ");
	} while (*yn != 'Y');
    }
}
예제 #2
0
int main(int argc, char *argv[])
{
  int     iarg, ifld, idata, n;
  int     lcount;
  FILE    *fpin;
  char    *fnin, buf[256], xtrac;
  double  Scale;
  double  Ttheta, Intens;


  Scale = 1.;

  fnin = NULL;
  fpin = NULL;

  for (iarg = 1; iarg < argc; iarg++)
  {
    if (argv[iarg][0] == '-') {
      if (str_ibegin(argv[iarg], "-Scale=") == 0) {
            n = sscanf(argv[iarg] + 7, "%lf %c", &Scale, &xtrac);
        if (n != 1) usage();
      }
      else
        usage();
    }
    else {
      if (fnin) usage();
      fnin = argv[iarg];
    }
  }

  if (fnin == NULL)
    fpin = stdin;
  else
  {
        fpin = fopen(fnin, "r");
    if (fpin == NULL)
    {
      fprintf(stderr, "%s: Can't open %s\n", progn, fnin);
      exit(1);
    }
  }

  ifld   = 0;
  idata  = 0;
  lcount = 0;

  while (fgetline(fpin, buf, sizeof buf))
  {
    lcount++;

    if (firstnonblank(buf) != '#')
    {
          n = sscanf(buf, "%lf%lf", &Ttheta, &Intens);
      if (n != 2)
        IllegalLine(fnin, lcount);

      Intens *= Scale;

      if (Intens < 1.) Intens = 1.;

      if (ifld == 8)
      {
        putc('\n', stdout);
	ifld = 0;
      }

      if (ifld == 0)
        putc(' ', stdout);

      fprintf(stdout, "%8.0f", Intens);
      ifld++;

          idata++;
      if (idata == 4095) break;
    }
  }

  if (fpin != stdin)
    fclose(fpin);

  if (ifld)
    putc('\n', stdout);

  fprintf(stdout, " %8.0f\n", 0.);

  exit(0);
  return 0;
}