Exemplo n.º 1
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;
    }
  }
}
Exemplo n.º 2
0
static char *
read_string (struct obstack *ob, FILE *infile, int star_if_braced)
{
  char *stringbuf;
  int saw_paren = 0;
  int c;

  c = read_skip_spaces (infile);
  if (c == '(')
    {
      saw_paren = 1;
      c = read_skip_spaces (infile);
    }

  if (c == '"')
    stringbuf = read_quoted_string (ob, infile);
  else if (c == '{')
    {
      if (star_if_braced)
	obstack_1grow (ob, '*');
      stringbuf = read_braced_string (ob, infile);
    }
  else
    fatal_with_file_and_line (infile, "expected `\"' or `{', found `%c'", c);

  if (saw_paren)
    {
      c = read_skip_spaces (infile);
      if (c != ')')
	fatal_expected_char (infile, ')', c);
    }

  return stringbuf;
}
Exemplo n.º 3
0
/* Read a braced string (a la Tcl) onto the obstack.  Caller has
   scanned the leading brace.  Note that unlike quoted strings,
   the outermost braces _are_ included in the string constant.  */
static char *
read_braced_string (struct obstack *ob, FILE *infile)
{
  int c;
  int brace_depth = 1;  /* caller-processed */
  unsigned long starting_read_rtx_lineno = read_rtx_lineno;

  obstack_1grow (ob, '{');
  while (brace_depth)
    {
      c = getc (infile); /* Read the string  */

      if (c == '\n')
	read_rtx_lineno++;
      else if (c == '{')
	brace_depth++;
      else if (c == '}')
	brace_depth--;
      else if (c == '\\')
	{
	  read_escape (ob, infile);
	  continue;
	}
      else if (c == EOF)
	fatal_with_file_and_line
	  (infile, "missing closing } for opening brace on line %lu",
	   starting_read_rtx_lineno);

      obstack_1grow (ob, c);
    }

  obstack_1grow (ob, 0);
  return obstack_finish (ob);
}
Exemplo n.º 4
0
static void
read_name (char *str, FILE *infile)
{
  char *p;
  int c;

  c = read_skip_spaces (infile);

  p = str;
  while (1)
    {
      if (c == ' ' || c == '\n' || c == '\t' || c == '\f' || c == '\r')
	break;
      if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
	  || c == '(' || c == '[')
	{
	  ungetc (c, infile);
	  break;
	}
      *p++ = c;
      c = getc (infile);
    }
  if (p == str)
    fatal_with_file_and_line (infile, "missing name or number");
  if (c == '\n')
    read_rtx_lineno++;

  *p = 0;

  if (md_constants)
    {
      /* Do constant expansion.  */
      struct md_constant *def;

      p = str;
      do
	{
	  struct md_constant tmp_def;

	  tmp_def.name = p;
	  def = htab_find (md_constants, &tmp_def);
	  if (def)
	    p = def->value;
	} while (def);
      if (p != str)
	strcpy (str, p);
    }
}
Exemplo n.º 5
0
void lbp_font::handle_unknown_font_command(const char *command,
					   const char *arg,
					   const char *filename, int lineno)
{
  if (strcmp(command, "lbpname") == 0) {
    if (arg == 0)
      fatal_with_file_and_line(filename, lineno,
			       "`%1' command requires an argument",
			       command);
    this->lbpname = new char[strlen(arg) + 1];
    strcpy(this->lbpname, arg);
    // we recognize bitmapped fonts by the first character of its name
    if (arg[0] == 'N')
      this->is_scalable = 0;
    // fprintf(stderr, "Loading font \"%s\" \n", arg);
  }
  // fprintf(stderr, "Loading font  %s \"%s\" in %s at %d\n",
  //         command, arg, filename, lineno);
}
Exemplo n.º 6
0
void ps_printer::define_encoding(const char *encoding, int encoding_index)
{
  char *vec[256];
  int i;
  for (i = 0; i < 256; i++)
    vec[i] = 0;
  char *path;
  FILE *fp = font::open_file(encoding, &path);
  if (fp == 0)
    fatal("can't open encoding file `%1'", encoding);
  int lineno = 1;
  const int BUFFER_SIZE = 512;
  char buf[BUFFER_SIZE];
  while (fgets(buf, BUFFER_SIZE, fp) != 0) {
    char *p = buf;
    while (csspace(*p))
      p++;
    if (*p != '#' && *p != '\0' && (p = strtok(buf, WS)) != 0) {
      char *q = strtok(0, WS);
      int n = 0;		// pacify compiler
      if (q == 0 || sscanf(q, "%d", &n) != 1 || n < 0 || n >= 256)
	fatal_with_file_and_line(path, lineno, "bad second field");
      vec[n] = new char[strlen(p) + 1];
      strcpy(vec[n], p);
    }
    lineno++;
  }
  a_delete path;
  out.put_literal_symbol(make_encoding_name(encoding_index))
     .put_delimiter('[');
  for (i = 0; i < 256; i++) {
    if (vec[i] == 0)
      out.put_literal_symbol(".notdef");
    else {
      out.put_literal_symbol(vec[i]);
      a_delete vec[i];
    }
  }
  out.put_delimiter(']')
     .put_symbol("def");
  fclose(fp);
}
Exemplo n.º 7
0
void resource_manager::read_download_file()
{
  char *path = 0;
  FILE *fp = font::open_file("download", &path);
  if (!fp)
    fatal("can't find `download'");
  char buf[512];
  int lineno = 0;
  while (fgets(buf, sizeof(buf), fp)) {
    lineno++;
    char *p = strtok(buf, " \t\r\n");
    if (p == 0 || *p == '#')
      continue;
    char *q = strtok(0, " \t\r\n");
    if (!q)
      fatal_with_file_and_line(path, lineno, "missing filename");
    lookup_font(p)->filename = strsave(q);
  }
  a_delete path;
  fclose(fp);
}
Exemplo n.º 8
0
static void
fatal_expected_char (FILE *infile, int expected_c, int actual_c)
{
  fatal_with_file_and_line (infile, "expected character `%c', found `%c'",
			    expected_c, actual_c);
}