Exemplo n.º 1
0
static string
merge_declarations (string olds, string news) {
  hashmap<string,path> oldd= latex_get_declarations (olds);
  hashmap<string,path> newd= latex_get_declarations (news);
  //cout << "oldd= " << oldd << "\n";
  //cout << "newd= " << newd << "\n";

  // Substitute redefinitions into old preamble
  hashmap<int,string> oldw, oldb;
  iterator<string> it= iterate (oldd);
  while (it->busy ()) {
    string cmd= it->next ();
    if (newd->contains (cmd)) {
      path oldp= oldd[cmd];
      path newp= newd[cmd];
      oldw (oldp[0])= olds (oldp[0], oldp[1]);
      oldb (oldp[0])= news (newp[0], newp[1]);
    }
  }
  olds= replace (olds, oldw, oldb);

  // Extract new definitions from new preamble
  hashmap<int,string> back;
  it= iterate (newd);
  while (it->busy ()) {
    string cmd= it->next ();
    if (!oldd->contains (cmd)) {
      path p= newd [cmd];
      back (p[0])= news (p[0], p[1]);
    }
  }
  string accum;
  for (int i=0; i<N(news); i++)
    if (test (news, i, "\\begin{document}")) break;
    else if (back->contains (i)) accum << back[i] << "\n";

  // Insert new definitions into old preamble
  int oldi= search_forwards ("\\begin{document}", olds);
  int newi= search_forwards ("\\begin{document}", news);
  if (oldi < 0) {
    if (ends (olds, "\n") || olds == "" || accum == "") return olds * accum;
    else return olds * "\n" * accum;
  }
  int i= oldi, cnt= 0;
  while (i>0 && (olds[i-1] == ' ' || olds[i-1] == '\t' || olds[i-1] == '\n')) {
    i--; if (olds[i] == '\n') cnt++; }
  if (cnt < 2 && N(accum) != 0) accum= "\n" * accum;
  if (N(accum) != 0) accum << "\n";
  return olds (0, oldi) * accum * news (newi, N(news));
}
Exemplo n.º 2
0
Arquivo: rcp.c Projeto: ksherlock/gno
int
main(int argc, char **argv)
{
struct servent *sp;
int ch, fflag, tflag;
char *targ, *shell;

	fflag = tflag = 0;
	while ((ch = getopt(argc, argv, OPTIONS)) != EOF)
		switch(ch) {			/* User-visible flags. */
		case 'K':
#ifdef KERBEROS
			use_kerberos = 0;
#endif
			break;
#ifdef	KERBEROS
		case 'k':
			dest_realm = dst_realm_buf;
			(void)strncpy(dst_realm_buf, optarg, REALM_SZ);
			break;
#ifdef CRYPT
		case 'x':
			doencrypt = 1;
			/* des_set_key(cred.session, schedule); */
			break;
#endif
#endif
		case 'p':
			pflag = 1;
			break;
		case 'r':
			iamrecursive = 1;
			break;
						/* Server options. */
		case 'd':
			targetshouldbedirectory = 1;
			break;
		case 'f':			/* "from" */
			iamremote = 1;
			fflag = 1;
			break;
		case 't':			/* "to" */
			iamremote = 1;
			tflag = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

#ifdef KERBEROS
	if (use_kerberos) {
#ifdef CRYPT
		shell = doencrypt ? "ekshell" : "kshell";
#else
		shell = "kshell";
#endif
		if ((sp = getservbyname(shell, "tcp")) == NULL) {
			use_kerberos = 0;
			oldw("can't get entry for %s/tcp service", shell);
			sp = getservbyname(shell = "shell", "tcp");
		}
	} else
		sp = getservbyname(shell = "shell", "tcp");
#else
	sp = getservbyname(shell = "shell", "tcp");
#endif
	if (sp == NULL)
		errx(1, "%s/tcp: unknown service", shell);
	port = sp->s_port;

	if ((pwd = getpwuid(userid = getuid())) == NULL)
		errx(1, "unknown user %d", (int)userid);

	rem = STDIN_FILENO;		/* XXX */

	if (fflag) {			/* Follow "protocol", send data. */
		(void)response();
		(void)setuid(userid);
		source(argc, argv);
		exit(errs);
	}

	if (tflag) {			/* Receive data. */
		(void)setuid(userid);
		sink(argc, argv);
		exit(errs);
	}

	if (argc < 2)
		usage();
	if (argc > 2)
		targetshouldbedirectory = 1;

	rem = -1;
	/* Command to be executed on remote system using "rsh". */
#ifdef	KERBEROS
	(void)snprintf(cmd, sizeof(cmd),
	    "rcp%s%s%s%s", iamrecursive ? " -r" : "",
#ifdef CRYPT
	    (doencrypt && use_kerberos ? " -x" : ""),
#else
	    "",
#endif
	    pflag ? " -p" : "", targetshouldbedirectory ? " -d" : "");
#else
	(void)snprintf(cmd, sizeof(cmd), "rcp%s%s%s",
	    iamrecursive ? " -r" : "", pflag ? " -p" : "",
	    targetshouldbedirectory ? " -d" : "");
#endif

	(void)signal(SIGPIPE, lostconn);

	if ((targ = colon(argv[argc - 1])))	/* Dest is remote host. */
		toremote(targ, argc, argv);
	else {
		tolocal(argc, argv);		/* Dest is local host. */
		if (targetshouldbedirectory)
			verifydir(argv[argc - 1]);
	}
	exit(errs);
}