Ejemplo n.º 1
0
bool BadLBNList::loadBadLBNs(std::string filename){
  filename=filename_expand(filename);
  int count = 0;
  ifstream badfilestream(filename.c_str());
  if(!badfilestream){
    cerr << "No bad lbns specified by " << filename << " , don't add any bad lbns to existing list" << endl;
    if(_somebad != 1) _somebad = 0;
    return 0;
  }
  int run;
  while(badfilestream >> run){
    badlbns.insert(run);
    count++;
  }
  badfilestream.close();
  _somebad=1;
  cout << count << " bad lbns loaded from " << filename << endl;
  return 1;
}    
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	int starting_line = 1;	/* line to start editing at */
	char command[MAXPATHLEN + 50];	/* emacs command buffer */
	char fullpath[MAXPATHLEN + 1];	/* full pathname to file */
	char *eval_form = NULL;	/* form to evaluate with `-eval' */
	char *eval_function = NULL;	/* function to evaluate with `-f' */
	char *load_library = NULL;	/* library to load */
	int quick = 0;		/* quick edit, don't wait for user to
				   finish */
	int batch = 0;		/* batch mode */
	int view = 0;		/* view only. */
	int nofiles = 0;
	int errflg = 0;		/* option error */
	int s;			/* socket / msqid to server */
	int connect_type;	/* CONN_UNIX, CONN_INTERNET, or
				 * CONN_IPC */
	int suppress_windows_system = 0;
	char *display = NULL;
#ifdef INTERNET_DOMAIN_SOCKETS
	char *hostarg = NULL;	/* remote hostname */
	char *remotearg;
	char thishost[HOSTNAMSZ];	/* this hostname */
	char remotepath[MAXPATHLEN + 1];	/* remote pathname */
	int rflg = 0;		/* pathname given on cmdline */
	char *portarg;
	unsigned short port = 0;	/* port to server */
#endif				/* INTERNET_DOMAIN_SOCKETS */
	char *path;		/* used indiscriminately */
#ifdef SYSV_IPC
	struct msgbuf *msgp;	/* message */
#endif				/* SYSV_IPC */
	char *tty = NULL;
	char buffer[GSERV_BUFSZ + 1];	/* buffer to read pid */
	char result[GSERV_BUFSZ + 1];
	int i;
	int sz;
	size_t msz;

#ifdef INTERNET_DOMAIN_SOCKETS
	memset(remotepath, 0, sizeof(remotepath));
#endif				/* INTERNET_DOMAIN_SOCKETS */

	progname = strrchr(argv[0], '/');
	if (progname)
		++progname;
	else
		progname = argv[0];

#ifdef USE_TMPDIR
	tmpdir = getenv("TMPDIR");
#endif
	if (!tmpdir)
		tmpdir = "/tmp";

	display = getenv("DISPLAY");
	if (display)
		display = my_strdup(display);
	else
		suppress_windows_system = 1;

	for (i = 1; argv[i] && !errflg; i++) {
		if (*argv[i] != '-')
			break;
		else if (*argv[i] == '-'
			 && (*(argv[i] + 1) == '\0'
			     || (*(argv[i] + 1) == '-'
				 && *(argv[i] + 2) == '\0'))) {
			/* `-' or `--' */
			++i;
			break;
		}

		if (!strcmp(argv[i], "-batch") || !strcmp(argv[i], "--batch"))
			batch = 1;
		else if (!strcmp(argv[i], "-eval")
			 || !strcmp(argv[i], "--eval")) {
			if (!argv[++i]) {
				fprintf(stderr,
					"%s: `-eval' must be followed by an argument\n",
					progname);
				exit(1);
			}
			eval_form = argv[i];
		} else if (!strcmp(argv[i], "-display")
			   || !strcmp(argv[i], "--display")) {
			suppress_windows_system = 0;
			if (!argv[++i]) {
				fprintf(stderr,
					"%s: `-display' must be followed by an argument\n",
					progname);
				exit(1);
			}
			if (display)
				free(display);
			/* no need to strdup. */
			display = argv[i];
		} else if (!strcmp(argv[i], "-nw"))
			suppress_windows_system = 1;
		else {
			/* Iterate over one-letter options. */
			char *p;
			int over = 0;
			for (p = argv[i] + 1; *p && !over; p++) {
				switch (*p) {
				case 'q':
					quick = 1;
					break;
				case 'v':
					view = 1;
					break;
				case 'f':
					GET_ARGUMENT(eval_function, "-f");
					break;
				case 'l':
					GET_ARGUMENT(load_library, "-l");
					break;
#ifdef INTERNET_DOMAIN_SOCKETS
				case 'h':
					GET_ARGUMENT(hostarg, "-h");
					break;
				case 'p':
					GET_ARGUMENT(portarg, "-p");
					port = atoi(portarg);
					break;
				case 'r':
					GET_ARGUMENT(remotearg, "-r");
					xstrncpy(remotepath, remotearg, sizeof(remotepath));
					remotepath[sizeof(remotepath)-1]='\0';
					rflg = 1;
					break;
#endif				/* INTERNET_DOMAIN_SOCKETS */
				default:
					errflg = 1;
				}
			}	/* for */
		}		/* else */
	}			/* for */

	if (errflg) {
		fprintf(stderr,
#ifdef INTERNET_DOMAIN_SOCKETS
			"Usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
			"       [-batch] [-f function] [-eval form]\n"
			"       [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
#else				/* !INTERNET_DOMAIN_SOCKETS */
			"Usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
			"[[+line] path] ...\n",
#endif				/* !INTERNET_DOMAIN_SOCKETS */
			progname);
		exit(1);
	}
	if (batch && argv[i]) {
		fprintf(stderr, "%s: Cannot specify `-batch' with file names\n",
			progname);
		exit(1);
	}
#if defined(INTERNET_DOMAIN_SOCKETS)
	if (suppress_windows_system && hostarg) {
		fprintf(stderr, "%s: Remote editing is available only on X\n",
			progname);
		exit(1);
	}
#endif
	*result = '\0';
	if (eval_function || eval_form || load_library) {
#if defined(INTERNET_DOMAIN_SOCKETS)
		connect_type = make_connection(hostarg, port, &s);
#else
		connect_type = make_connection(NULL, 0, &s);
#endif
		SNPRINTF(sz, command, sizeof(command),
			 "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
		send_string(s, command);
		if (load_library) {
			send_string(s, "(load-library ");
			send_string(s, clean_string(load_library));
			send_string(s, ") ");
		}
		if (eval_form) {
			send_string(s, eval_form);
		}
		if (eval_function) {
			send_string(s, "(");
			send_string(s, eval_function);
			send_string(s, ")");
		}
		send_string(s, "))");
		/* disconnect already sends EOT_STR */
#ifdef SYSV_IPC
		if (connect_type == (int)CONN_IPC)
			disconnect_from_ipc_server(s, msgp, batch && !quick);
#else				/* !SYSV_IPC */
		if (connect_type != (int)CONN_IPC)
			disconnect_from_server(s, batch && !quick);
#endif				/* !SYSV_IPC */
	} /* eval_function || eval_form || load_library */
	else if (batch) {
		/* no sexp on the command line, so read it from stdin */
		int nb;

#if defined(INTERNET_DOMAIN_SOCKETS)
		connect_type = make_connection(hostarg, port, &s);
#else
		connect_type = make_connection(NULL, 0, &s);
#endif
		SNPRINTF(sz, command, sizeof(command),
			 "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
		send_string(s, command);

		while ((nb = read(fileno(stdin), buffer, GSERV_BUFSZ - 1)) > 0) {
			buffer[nb] = '\0';
			send_string(s, buffer);
		}
		send_string(s, "))");
		/* disconnect already sends EOT_STR */
#ifdef SYSV_IPC
		if (connect_type == (int)CONN_IPC)
			disconnect_from_ipc_server(s, msgp, batch && !quick);
#else				/* !SYSV_IPC */
		if (connect_type != (int)CONN_IPC)
			disconnect_from_server(s, batch && !quick);
#endif				/* !SYSV_IPC */
	}

	if (!batch) {
		if (suppress_windows_system) {
			tty = ttyname(0);
			if (!tty) {
				fprintf(stderr, "%s: Not connected to a tty",
					progname);
				exit(1);
			}
#if defined(INTERNET_DOMAIN_SOCKETS)
			connect_type = make_connection(hostarg, port, &s);
#else
			connect_type = make_connection(NULL, 0, &s);
#endif
			send_string(s, "(gnuserv-eval '(emacs-pid))");
			send_string(s, EOT_STR);

			if (read_line(s, buffer) == 0) {
				fprintf(stderr,
					"%s: Could not establish Emacs process id\n",
					progname);
				exit(1);
			}
			/* Don't do disconnect_from_server because we have already read
			   data, and disconnect doesn't do anything else. */
#ifdef SYSV_IPC
			if (connect_type == (int)CONN_IPC)
				disconnect_from_ipc_server(s, msgp, FALSE);
#endif				/* !SYSV_IPC */

			emacs_pid = (pid_t) atol(buffer);
			initialize_signals();
		}
		/* suppress_windows_system */
#if defined(INTERNET_DOMAIN_SOCKETS)
		connect_type = make_connection(hostarg, port, &s);
#else
		connect_type = make_connection(NULL, 0, &s);
#endif

#ifdef INTERNET_DOMAIN_SOCKETS
		if (connect_type == (int)CONN_INTERNET) {
			char *ptr;
			gethostname(thishost, HOSTNAMSZ);
			if (!rflg) {	/* attempt to generate a path
					 * to this machine */
				if ((ptr = getenv("GNU_NODE")) != NULL) {
					/* user specified a path */
					xstrncpy(remotepath, ptr, sizeof(remotepath)-1);
					remotepath[sizeof(remotepath)-1]='\0';
				}
			}
#if 0				/* This is really bogus... re-enable it if you must have it! */
#if defined (hp9000s300) || defined (hp9000s800)
			else if (strcmp(thishost, hostarg)) {	/* try /net/thishost */
				strcpy(remotepath, "/net/");	/* (this fails using internet
								   addresses) */
				strcat(remotepath, thishost);
			}
#endif
#endif
		} else {	/* same machines, no need for path */
			remotepath[0] = '\0';	/* default is the empty path */
		}
#endif				/* INTERNET_DOMAIN_SOCKETS */

#ifdef SYSV_IPC
		if ((msgp = (struct msgbuf *)
		     malloc(sizeof *msgp + GSERV_BUFSZ)) == NULL) {
			fprintf(stderr,
				"%s: not enough memory for message buffer\n",
				progname);
			exit(1);
		}
		/* if */
		msgp->mtext[0] = '\0';	/* ready for later strcats */
#endif				/* SYSV_IPC */

		if (suppress_windows_system) {
			char *term = getenv("TERM");
			pid_t pid = getpid();

			if (!term) {
				fprintf(stderr, "%s: unknown terminal type\n",
					progname);
				exit(1);
			}
			SNPRINTF(sz, command, sizeof(command),
				 "(gnuserv-edit-files '(tty %s %s %d) '(",
				 clean_string(tty), clean_string(term),
				 (int)pid);
		} else {	/* !suppress_windows_system */

			if (0) ;
#ifdef HAVE_X_WINDOWS
			else if (display) {
				SNPRINTF(sz, command, sizeof(command),
					 "(gnuserv-edit-files '(x %s) '(",
					 clean_string(display));
			}
#endif
		}		/* !suppress_windows_system */
		send_string(s, command);

		if (!argv[i])
			nofiles = 1;

		for (; argv[i]; i++) {
			if (i < argc - 1 && *argv[i] == '+') {
				starting_line = atoi(argv[i++]);
			} else {
				starting_line = 1;
			}
			/* If the last argument is +something, treat it as a
			   file. */
			if (i == argc) {
				starting_line = 1;
				--i;
			}
			filename_expand(fullpath, argv[i], sizeof(fullpath));
#ifdef INTERNET_DOMAIN_SOCKETS
			msz = strlen(remotepath) + strlen(fullpath) + 1;
			path = (char*)malloc(msz);
			SNPRINTF(sz, path, msz, "%s%s", remotepath, fullpath);
#else  /* !INTERNET_DOMAIN_SOCKETS */
			path = my_strdup(fullpath);
#endif	/* INTERNET_DOMAIN_SOCKETS */
			SNPRINTF(sz, command, sizeof(command),
				"(%d . %s)", starting_line, clean_string(path));
			send_string(s, command);
			free(path);
		}

		SNPRINTF(sz, command, sizeof(command), ")%s%s",
			 (quick || (nofiles && !suppress_windows_system))
			 ? " 'quick"
			 : "",
			 view ? " 'view" : "");
		send_string(s, command);
		send_string(s, ")");

#ifdef SYSV_IPC
		if (connect_type == (int)CONN_IPC)
			disconnect_from_ipc_server(s, msgp, FALSE);
#else				/* !SYSV_IPC */
		if (connect_type != (int)CONN_IPC)
			disconnect_from_server(s, FALSE);
#endif				/* !SYSV_IPC */
	}

	/* not batch */
	return 0;

}
Ejemplo n.º 3
0
static void option_do_set(option_t *option, char *value)
{
    char        expand[FILENAME_MAX+1];
    int         val;
    double      val2;
    char        c;
    char       *ptr;
    char       *temp;

    /* Handle comments after the value */
    ptr = strchr(value,';');
    if ( ptr )
        *ptr = 0;

    if ( option->type & OPT_ARRAY ) {
        switch ( option->type & ~OPT_ARRAY ) {
        case OPT_INT:
            val = parse_int(value);
            *(int **)option->value = realloc(*(int **)option->value, (*option->count + 1) * sizeof(int));
            (*(int **)(option->value))[*option->count] = val;
            (*option->count)++;
            break;
        case OPT_STR:
        case OPT_FILENAME:
            strip_ws(value);
            if ( (option->type & ~OPT_ARRAY) == OPT_FILENAME ) {
                filename_expand(value,expand,sizeof(expand),NULL,NULL);
                temp = strdup(expand);
            } else {
                temp = strdup(value);
            }
            *(char **)option->value = realloc(*(char **)option->value, (*option->count + 1) * sizeof(char *));
            (*(char ***)(option->value))[*option->count] = temp;
            (*option->count)++;
            break;
        case OPT_FLOAT:
            val2 = parse_float(value);
            *(double **)option->value = realloc(*(double **)option->value, (*option->count + 1) * sizeof(double));
            (*(double **)(option->value))[*option->count] = val2;
            (*option->count)++;
            break;
        }
        return;

    }
    switch ( option->type ) {
    case OPT_INT:
        val = parse_int(value);
        *(int *)(option->value) = val;
        return;
    case OPT_STR:
    case OPT_FILENAME:
        strip_ws(value);
        if ( option->type == OPT_FILENAME ) {
            filename_expand(value,expand,sizeof(expand),NULL,NULL);
            temp = strdup(expand);
        } else {
            temp = strdup(value);
        }
        *(char **)(option->value) = temp;
        return;
    case OPT_BOOL:
        c = toupper(value[0]);
        val = 0;
        switch (c) {
        case 'Y':
        case 'T':
        case '1':
            val = 1;
        }
        *(char *)(option->value) = val;
        return;
    case OPT_FLOAT:
        val2 = parse_float(value);
        *(double *)(option->value) = val2;
        return;
    }
}