Example #1
0
void get_delimited_text()
{
  char *filename;
  int lineno;
  int got_location = get_location(&filename, &lineno);
  int start = get_char();
  while (start == ' ' || start == '\t' || start == '\n')
    start = get_char();
  token_buffer.clear();
  if (start == EOF) {
    if (got_location)
      error_with_file_and_line(filename, lineno,
			       "end of input while defining macro");
    else
      error("end of input while defining macro");
    return;
  }
  for (;;) {
    int c = get_char();
    if (c == EOF) {
      if (got_location)
	error_with_file_and_line(filename, lineno,
				 "end of input while defining macro");
      else
	error("end of input while defining macro");
      add_context(start + token_buffer);
      return;
    }
    if (c == start)
      break;
    token_buffer += char(c);
  }
  add_context(start + token_buffer + start);
}
Example #2
0
void lj4_font::handle_unknown_font_command(const char *command,
					   const char *arg,
					   const char *filename, int lineno)
{
  for (unsigned int i = 0;
       i < sizeof(command_table)/sizeof(command_table[0]); i++) {
    if (strcmp(command, command_table[i].s) == 0) {
      if (arg == 0)
	fatal_with_file_and_line(filename, lineno,
				 "`%1' command requires an argument",
				 command);
      char *ptr;
      long n = strtol(arg, &ptr, 10);
      if (n == 0 && ptr == arg)
	fatal_with_file_and_line(filename, lineno,
				 "`%1' command requires numeric argument",
				 command);
      if (n < command_table[i].min) {
	error_with_file_and_line(filename, lineno,
				 "argument for `%1' command must not be less than %2",
				 command, command_table[i].min);
	n = command_table[i].min;
      }
      else if (n > command_table[i].max) {
	error_with_file_and_line(filename, lineno,
				 "argument for `%1' command must not be greater than %2",
				 command, command_table[i].max);
	n = command_table[i].max;
      }
      this->*command_table[i].ptr = int(n);
      break;
    }
  }
}
Example #3
0
void tpic_output::command(const char *s, const char *filename, int lineno)
{
  assert(s[0] == '.');
  if (s[1] == 'p' && s[2] == 's' && (s[3] == '\0' || !csalpha(s[3]))) {
    const char *p = s + 3;
    while (csspace(*p))
      p++;
    if (*p == '\0') {
      int temp = default_pen_size;
      default_pen_size = prev_default_pen_size;
      prev_default_pen_size = temp;
    }
    else {
      char *ptr;
      int temp = (int)strtol(p, &ptr, 10);
      if (temp == 0 && ptr == p)
	error_with_file_and_line(filename, lineno,
				 "argument to `.ps' not an integer");
      else if (temp < 0)
	error_with_file_and_line(filename, lineno,
				 "negative pen size");
      else {
	prev_default_pen_size = default_pen_size;
	default_pen_size = temp;
      }
    }
  }
  else
    printf("\\%s%%\n", s + 1);
}
Example #4
0
void text_file::error(const char *format, 
		      const errarg &arg1,
		      const errarg &arg2,
		      const errarg &arg3)
{
  if (!silent)
    error_with_file_and_line(path, lineno, format, arg1, arg2, arg3);
}
Example #5
0
void yyerror(const char *s)
{
  char *filename;
  int lineno;
  if (!get_location(&filename, &lineno))
    error(s);
  else
    error_with_file_and_line(filename, lineno, s);
  show_context();
}
Example #6
0
static void handle_unknown_desc_command(const char *command, const char *arg,
					const char *filename, int lineno)
{
  if (strcmp(command, "broken") == 0) {
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`broken' command requires an argument");
    else if (!bflag)
      broken_flags = atoi(arg);
  }
}
Example #7
0
void ps_font::handle_unknown_font_command(const char *command, const char *arg,
					  const char *filename, int lineno)
{
  if (strcmp(command, "encoding") == 0) {
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`encoding' command requires an argument");
    else
      encoding = strsave(arg);
  }
}
Example #8
0
void handle_unknown_desc_command(const char *command, const char *arg,
				 const char *filename, int lineno)
{
  if (strcmp(command, "print") == 0) {
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`print' command requires an argument");
    else
      spooler = strsave(arg);
  }
  if (strcmp(command, "prepro") == 0) {
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`prepro' command requires an argument");
    else {
      for (const char *p = arg; *p; p++)
	if (csspace(*p)) {
	  error_with_file_and_line(filename, lineno,
				   "invalid `prepro' argument `%1'"
				   ": program name required", arg);
	  return;
	}
      predriver = strsave(arg);
    }
  }
  if (strcmp(command, "postpro") == 0) {
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`postpro' command requires an argument");
    else {
      for (const char *p = arg; *p; p++)
	if (csspace(*p)) {
	  error_with_file_and_line(filename, lineno,
				   "invalid `postpro' argument `%1'"
				   ": program name required", arg);
	  return;
	}
      postdriver = strsave(arg);
    }
  }
}
Example #9
0
File: command.cpp Project: att/uwin
void input_stack::error(const char *format, const errarg &arg1,
			const errarg &arg2, const errarg &arg3)
{
  const char *filename;
  int lineno;
  for (input_item *it = top; it; it = it->next)
    if (it->get_location(&filename, &lineno)) {
      error_with_file_and_line(filename, lineno, format, arg1, arg2, arg3);
      return;
    }
  ::error(format, arg1, arg2, arg3);
}
Example #10
0
void lex_error(const char *message,
	       const errarg &arg1,
	       const errarg &arg2,
	       const errarg &arg3)
{
  char *filename;
  int lineno;
  if (!get_location(&filename, &lineno))
    error(message, arg1, arg2, arg3);
  else
    error_with_file_and_line(filename, lineno, message, arg1, arg2, arg3);
}
Example #11
0
void yyerror(const char *s)
{
  const char *filename;
  int lineno;
  const char *context = 0;
  if (lookahead_token == -1) {
    if (context_buffer.length() > 0) {
      context_buffer += '\0';
      context = context_buffer.contents();
    }
  }
  else {
    if (old_context_buffer.length() > 0) {
      old_context_buffer += '\0';
      context = old_context_buffer.contents();
    }
  }
  if (!input_stack::get_location(&filename, &lineno)) {
    if (context) {
      if (context[0] == '\n' && context[1] == '\0')
	error("%1 before newline", s);
      else
	error("%1 before `%2'", s, context);
    }
    else
      error("%1 at end of picture", s);
  }
  else {
    if (context) {
      if (context[0] == '\n' && context[1] == '\0')
	error_with_file_and_line(filename, lineno, "%1 before newline", s);
      else
	error_with_file_and_line(filename, lineno, "%1 before `%2'",
				 s, context);
    }
    else
      error_with_file_and_line(filename, lineno, "%1 at end of picture", s);
  }
}
Example #12
0
static void handle_unknown_desc_command(const char *command, const char *arg,
					const char *filename, int lineno)
{
  // orientation command
  if (strcasecmp(command, "orientation") == 0) {
    // We give priority to command line options
    if (orientation > 0)
      return;
    if (arg == 0)
      error_with_file_and_line(filename, lineno,
			       "`orientation' command requires an argument");
    else {
      if (strcasecmp(arg, "portrait") == 0)
	orientation = 0;
      else {
	if (strcasecmp(arg, "landscape") == 0)
	  orientation = 1;
	else
	  error_with_file_and_line(filename, lineno,
				   "invalid argument to `orientation' command");
      }
    }
  }
}
Example #13
0
int top_input::get()
{
  if (eof)
    return EOF;
  if (push_back[2] != EOF) {
    int c = push_back[2];
    push_back[2] = EOF;
    return c;
  }
  else if (push_back[1] != EOF) {
    int c = push_back[1];
    push_back[1] = EOF;
    return c;
  }
  else if (push_back[0] != EOF) {
    int c = push_back[0];
    push_back[0] = EOF;
    return c;
  }
  int c = getc(fp);
  while (invalid_input_char(c)) {
    error("invalid input character code %1", int(c));
    c = getc(fp);
    bol = 0;
  }
  if (bol && c == '.') {
    c = getc(fp);
    if (c == 'P') {
      c = getc(fp);
      if (c == 'F' || c == 'E') {
	int d = getc(fp);
	if (d != EOF)
	  ungetc(d, fp);
	if (d == EOF || d == ' ' || d == '\n' || compatible_flag) {
	  eof = 1;
	  flyback_flag = c == 'F';
	  return EOF;
	}
	push_back[0] = c;
	push_back[1] = 'P';
	return '.';
      }
      if (c == 'S') {
	c = getc(fp);
	if (c != EOF)
	  ungetc(c, fp);
	if (c == EOF || c == ' ' || c == '\n' || compatible_flag) {
	  error("nested .PS");
	  eof = 1;
	  return EOF;
	}
	push_back[0] = 'S';
	push_back[1] = 'P';
	return '.';
      }
      if (c != EOF)
	ungetc(c, fp);
      push_back[0] = 'P';
      return '.';
    }
    else {
      if (c != EOF)
	ungetc(c, fp);
      return '.';
    }
  }
  if (c == '\n') {
    bol = 1;
    current_lineno++;
    return '\n';
  }
  bol = 0;
  if (c == EOF) {
    eof = 1;
    error("end of file before .PE or .PF");
    error_with_file_and_line(current_filename, start_lineno - 1,
			     ".PS was here");
  }
  return c;
}
Example #14
0
int main(int argc, char **argv)
{
  program_name = argv[0];
  static char stderr_buf[BUFSIZ];
  setbuf(stderr, stderr_buf);
  
  const char *base_name = 0;
  typedef int (*parser_t)(const char *);
  parser_t parser = do_file;
  const char *directory = 0;
  const char *foption = 0;
  int opt;
  static const struct option long_options[] = {
    { "help", no_argument, 0, CHAR_MAX + 1 },
    { "version", no_argument, 0, 'v' },
    { NULL, 0, 0, 0 }
  };
  while ((opt = getopt_long(argc, argv, "c:o:h:i:k:l:t:n:c:d:f:vw",
			    long_options, NULL))
	 != EOF)
    switch (opt) {
    case 'c':
      common_words_file = optarg;
      break;
    case 'd':
      directory = optarg;
      break;
    case 'f':
      foption = optarg;
      break;
    case 'h':
      check_integer_arg('h', optarg, 1, &hash_table_size);
      if (!is_prime(hash_table_size)) {
	while (!is_prime(++hash_table_size))
	  ;
	warning("%1 not prime: using %2 instead", optarg, hash_table_size);
      }
      break;
    case 'i':
      ignore_fields = optarg;
      break;
    case 'k':
      check_integer_arg('k', optarg, 1, &max_keys_per_item);
      break;
    case 'l':
      check_integer_arg('l', optarg, 0, &shortest_len);
      break;
    case 'n':
      check_integer_arg('n', optarg, 0, &n_ignore_words);
      break;
    case 'o':
      base_name = optarg;
      break;
    case 't':
      check_integer_arg('t', optarg, 1, &truncate_len);
      break;
    case 'w':
      parser = do_whole_file;
      break;
    case 'v':
      printf("GNU indxbib (groff) version %s\n", Version_string);
      exit(0);
      break;
    case CHAR_MAX + 1: // --help
      usage(stdout);
      exit(0);
      break;
    case '?':
      usage(stderr);
      exit(1);
      break;
    default:
      assert(0);
      break;
    }
  if (optind >= argc && foption == 0)
    fatal("no files and no -f option");
  if (!directory) {
    char *path = get_cwd();
    store_filename(path);
    a_delete path;
  }
  else
    store_filename(directory);
  init_hash_table();
  store_filename(common_words_file);
  store_filename(ignore_fields);
  key_buffer = new char[truncate_len];
  read_common_words_file();
  if (!base_name)
    base_name = optind < argc ? argv[optind] : DEFAULT_INDEX_NAME;
  const char *p = strrchr(base_name, DIR_SEPS[0]), *p1;
  const char *sep = &DIR_SEPS[1];
  while (*sep) {
    p1 = strrchr(base_name, *sep);
    if (p1 && (!p || p1 > p))
      p = p1;
    sep++;
  }
  size_t name_max;
  if (p) {
    char *dir = strsave(base_name);
    dir[p - base_name] = '\0';
    name_max = file_name_max(dir);
    a_delete dir;
  }
  else
    name_max = file_name_max(".");
  const char *filename = p ? p + 1 : base_name;
  if (strlen(filename) + sizeof(INDEX_SUFFIX) - 1 > name_max)
    fatal("`%1.%2' is too long for a filename", filename, INDEX_SUFFIX);
  if (p) {
    p++;
    temp_index_file = new char[p - base_name + sizeof(TEMP_INDEX_TEMPLATE)];
    memcpy(temp_index_file, base_name, p - base_name);
    strcpy(temp_index_file + (p - base_name), TEMP_INDEX_TEMPLATE);
  }
  else {
    temp_index_file = strsave(TEMP_INDEX_TEMPLATE);
  }
  catch_fatal_signals();
  int fd = mkstemp(temp_index_file);
  if (fd < 0)
    fatal("can't create temporary index file: %1", strerror(errno));
  indxfp = fdopen(fd, FOPEN_WB);
  if (indxfp == 0)
    fatal("fdopen failed");
  if (fseek(indxfp, sizeof(index_header), 0) < 0)
    fatal("can't seek past index header: %1", strerror(errno));
  int failed = 0;
  if (foption) {
    FILE *fp = stdin;
    if (strcmp(foption, "-") != 0) {
      errno = 0;
      fp = fopen(foption, "r");
      if (!fp)
	fatal("can't open `%1': %2", foption, strerror(errno));
    }
    string path;
    int lineno = 1;
    for (;;) {
      int c;
      for (c = getc(fp); c != '\n' && c != EOF; c = getc(fp)) {
	if (c == '\0')
	  error_with_file_and_line(foption, lineno,
				   "nul character in pathname ignored");
	else
	  path += c;
      }
      if (path.length() > 0) {
	path += '\0';
	if (!(*parser)(path.contents()))
	  failed = 1;
	path.clear();
      }
      if (c == EOF)
	break;
      lineno++;
    }
    if (fp != stdin)
      fclose(fp);
  }
  for (int i = optind; i < argc; i++)
    if (!(*parser)(argv[i]))
      failed = 1;
  write_hash_table();
  if (fclose(indxfp) < 0)
    fatal("error closing temporary index file: %1", strerror(errno));
  char *index_file = new char[strlen(base_name) + sizeof(INDEX_SUFFIX)];    
  strcpy(index_file, base_name);
  strcat(index_file, INDEX_SUFFIX);
#ifdef HAVE_RENAME
#ifdef __EMX__
  if (access(index_file, R_OK) == 0)
    unlink(index_file);
#endif /* __EMX__ */
  if (rename(temp_index_file, index_file) < 0) {
#ifdef __MSDOS__
    // RENAME could fail on plain MSDOS filesystems because
    // INDEX_FILE is an invalid filename, e.g. it has multiple dots.
    char *fname = p ? index_file + (p - base_name) : 0;
    char *dot = 0;

    // Replace the dot with an underscore and try again.
    if (fname
        && (dot = strchr(fname, '.')) != 0
        && strcmp(dot, INDEX_SUFFIX) != 0)
      *dot = '_';
    if (rename(temp_index_file, index_file) < 0)
#endif
    fatal("can't rename temporary index file: %1", strerror(errno));
  }
#else /* not HAVE_RENAME */
  ignore_fatal_signals();
  if (unlink(index_file) < 0) {
    if (errno != ENOENT)
      fatal("can't unlink `%1': %2", index_file, strerror(errno));
  }
  if (link(temp_index_file, index_file) < 0)
    fatal("can't link temporary index file: %1", strerror(errno));
  if (unlink(temp_index_file) < 0)
    fatal("can't unlink temporary index file: %1", strerror(errno));
#endif /* not HAVE_RENAME */
  temp_index_file = 0;
  return failed;
}
Example #15
0
File: command.cpp Project: att/uwin
void input_stack::push_file(const char *fn)
{
  FILE *fp;
  if (strcmp(fn, "-") == 0) {
    fp = stdin;
    fn = "<standard input>";
  }
  else {
    errno = 0;
    fp = fopen(fn, "r");
    if (fp == 0) {
      error("can't open `%1': %2", fn, strerror(errno));
      return;
    }
  }
  string buf;
  int bol = 1;
  int lineno = 1;
  for (;;) {
    int c = getc(fp);
    if (bol && c == '.') {
      // replace lines beginning with .R1 or .R2 with a blank line
      c = getc(fp);
      if (c == 'R') {
	c = getc(fp);
	if (c == '1' || c == '2') {
	  int cc = c;
	  c = getc(fp);
	  if (compatible_flag || c == ' ' || c == '\n' || c == EOF) {
	    while (c != '\n' && c != EOF)
	      c = getc(fp);
	  }
	  else {
	    buf += '.';
	    buf += 'R';
	    buf += cc;
	  }
	}
	else {
	  buf += '.';
	  buf += 'R';
	}
      }
      else
	buf += '.';
    }
    if (c == EOF)
      break;
    if (invalid_input_char(c))
      error_with_file_and_line(fn, lineno,
			       "invalid input character code %1", int(c));
    else {
      buf += c;
      if (c == '\n') {
	bol = 1;
	lineno++;
      }
      else
	bol = 0;
    }
  }
  if (fp != stdin)
    fclose(fp);
  if (buf.length() > 0 && buf[buf.length() - 1] != '\n')
    buf += '\n';
  input_item *it = new input_item(buf, fn);
  it->next = top;
  top = it;
}