Ejemplo n.º 1
0
static void convert_font(const font_params &param, FILE *infp, FILE *outfp)
{
  string s;
  while (get_line(infp, &s)) {
    put_string(s, outfp);
    if (s.length() >= 8
	&& strncmp(&s[0], "charset", 7))
      break;
  }
  while (get_line(infp, &s)) {
    s += '\0';
    string name;
    const char *p = s.contents();
    while (csspace(*p))
      p++;
    while (*p != '\0' && !csspace(*p))
      name += *p++;
    while (csspace(*p))
      p++;
    for (const char *q = s.contents(); q < p; q++)
      putc(*q, outfp);
    char *next;
    char_metric metric;
    metric.width = (int)strtol(p, &next, 10);
    if (next != p) {
      printf("%d", metric.width);
      p = next;
      metric.type = (int)strtol(p, &next, 10);
      if (next != p) {
	name += '\0';
	guess(name.contents(), param, &metric);
	if (metric.sk == 0) {
	  if (metric.left_ic == 0) {
	    if (metric.ic == 0) {
	      if (metric.depth == 0) {
		if (metric.height != 0)
		  printf(",%d", metric.height);
	      }
	      else
		printf(",%d,%d", metric.height, metric.depth);
	    }
	    else
	      printf(",%d,%d,%d", metric.height, metric.depth, metric.ic);
	  }
	  else
	    printf(",%d,%d,%d,%d", metric.height, metric.depth, metric.ic,
		   metric.left_ic);
	}
	else
	  printf(",%d,%d,%d,%d,%d", metric.height, metric.depth, metric.ic,
		 metric.left_ic, metric.sk);
      }
    }
    fputs(p, outfp);
  }
}
Ejemplo n.º 2
0
static char *trim_arg(char *p)
{
  if (!p)
    return 0;
  while (csspace(*p))
    p++;
  char *q = strchr(p, '\0');
  while (q > p && csspace(q[-1]))
    q--;
  *q = '\0';
  return p;
}
Ejemplo n.º 3
0
void ps_printer::do_file(char *arg, const environment *env)
{
  while (csspace(*arg))
    arg++;
  if (*arg == '\0') {
    error("missing argument to X file command");
    return;
  }
  const char *filename = arg;
  do {
    ++arg;
  } while (*arg != '\0' && *arg != ' ' && *arg != '\n');
  out.put_fix_number(env->hpos)
     .put_fix_number(env->vpos)
     .put_symbol("EBEGIN");
  rm.import_file(filename, out);
  out.put_symbol("EEND");
  output_hpos = output_vpos = -1;
  output_style.f = 0;
  output_draw_point_size = -1;
  output_line_thickness = -1;
  ndefined_styles = 0;
  if (!ndefs)
    ndefs = 1;
}
Ejemplo n.º 4
0
void ps_printer::do_mdef(char *arg, const environment *)
{
  flush_sbuf();
  char *p;
  int n = (int)strtol(arg, &p, 10);
  if (n == 0 && p == arg) {
    error("first argument to X mdef must be an integer");
    return;
  }
  if (n < 0) {
    error("out of range argument `%1' to X mdef command", int(n));
    return;
  }
  arg = p;
  while (csspace(*arg))
    arg++;
  if (!check_line_lengths(arg)) {
    error("lines in X mdef command must not be more than 255 characters long");
    return;
  }
  defs += arg;
  if (*arg != '\0' && strchr(arg, '\0')[-1] != '\n')
    defs += '\n';
  ndefs += n;
}
Ejemplo n.º 5
0
void ps_printer::do_exec(char *arg, const environment *env)
{
  flush_sbuf();
  while (csspace(*arg))
    arg++;
  if (*arg == '\0') {
    error("missing argument to X exec command");
    return;
  }
  if (!check_line_lengths(arg)) {
    error("lines in X exec command must not be more than 255 characters long");
    return;
  }
  out.put_fix_number(env->hpos)
     .put_fix_number(env->vpos)
     .put_symbol("EBEGIN")
     .special(arg)
     .put_symbol("EEND");
  output_hpos = output_vpos = -1;
  output_style.f = 0;
  output_draw_point_size = -1;
  output_line_thickness = -1;
  ndefined_styles = 0;
  if (!ndefs)
    ndefs = 1;
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
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);
    }
  }
}
Ejemplo n.º 8
0
void ps_printer::do_def(char *arg, const environment *)
{
  while (csspace(*arg))
    arg++;
  if (!check_line_lengths(arg))
    warning("lines in X def command should"
	    " not be more than 255 characters long");
  defs += arg;
  if (*arg != '\0' && strchr(arg, '\0')[-1] != '\n')
    defs += '\n';
  ndefs++;
}
Ejemplo n.º 9
0
void ps_printer::do_def(char *arg, const environment *)
{
  flush_sbuf();
  while (csspace(*arg))
    arg++;
  if (!check_line_lengths(arg)) {
    error("lines in X def command must not be more than 255 characters long");
    return;
  }
  defs += arg;
  if (*arg != '\0' && strchr(arg, '\0')[-1] != '\n')
    defs += '\n';
  ndefs++;
}
Ejemplo n.º 10
0
int read_map(const char *file, char_list **table)
{
  errno = 0;
  FILE *fp = fopen(file, "r");
  if (!fp) {
    error("can't open `%1': %2", file, strerror(errno));
    return 0;
  }
  for (int i = 0; i < 256; i++)
    table[i] = 0;
  char buf[512];
  int lineno = 0;
  while (fgets(buf, int(sizeof(buf)), fp)) {
    lineno++;
    char *ptr = buf;
    while (csspace(*ptr))
      ptr++;
    if (*ptr == '\0' || *ptr == '#')
      continue;
    ptr = strtok(ptr, " \n\t");
    if (!ptr)
      continue;
    int n;
    if (sscanf(ptr, "%d", &n) != 1) {
      error("%1:%2: bad map file", file, lineno);
      fclose(fp);
      return 0;
    }
    if (n < 0 || n > 255) {
      error("%1:%2: code out of range", file, lineno);
      fclose(fp);
      return 0;
    }
    ptr = strtok(0, " \n\t");
    if (!ptr) {
      error("%1:%2: missing names", file, lineno);
      fclose(fp);
      return 0;
    }
    for (; ptr; ptr = strtok(0, " \n\t"))
      table[n] = new char_list(ptr, table[n]);
  }
  fclose(fp);
  return 1;
}
Ejemplo n.º 11
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);
}
Ejemplo n.º 12
0
int text_file::next()
{
  if (fp == 0)
    return 0;
  if (buf == 0) {
    buf = new char[128];
    size = 128;
  }
  for (;;) {
    int i = 0;
    for (;;) {
      int c = getc(fp);
      if (c == EOF)
	break;
      if (invalid_input_char(c))
	error("invalid input character code `%1'", int(c));
      else {
	if (i + 1 >= size) {
	  char *old_buf = buf;
	  buf = new char[size*2];
	  memcpy(buf, old_buf, size);
	  a_delete old_buf;
	  size *= 2;
	}
	buf[i++] = c;
	if (c == '\n')
	  break;
      }
    }
    if (i == 0)
      break;
    buf[i] = '\0';
    lineno++;
    char *ptr = buf;
    while (csspace(*ptr))
      ptr++;
    if (*ptr != 0 && (!skip_comments || *ptr != '#'))
      return 1;
  }
  return 0;
}
Ejemplo n.º 13
0
Archivo: main.cpp Proyecto: att/uwin
options *process_options(table_input &in)
{
  options *opt = new options;
  string line;
  int level = 0;
  for (;;) {
    int c = in.get();
    if (c == EOF) {
      int i = line.length();
      while (--i >= 0)
	in.unget(line[i]);
      return opt;
    }
    if (c == '\n') {
      in.unget(c);
      int i = line.length();
      while (--i >= 0)
	in.unget(line[i]);
      return opt;
    }
    else if (c == '(')
      level++;
    else if (c == ')')
      level--;
    else if (c == ';' && level == 0) {
      line += '\0';
      break;
    }
    line += c;
  }
  if (line.empty())
    return opt;
  char *p = &line[0];
  for (;;) {
    while (!csalpha(*p) && *p != '\0')
      p++;
    if (*p == '\0')
      break;
    char *q = p;
    while (csalpha(*q))
      q++;
    char *arg = 0;
    if (*q != '(' && *q != '\0')
      *q++ = '\0';
    while (csspace(*q))
      q++;
    if (*q == '(') {
      *q++ = '\0';
      arg = q;
      while (*q != ')' && *q != '\0')
	q++;
      if (*q == '\0')
	error("missing `)'");
      else
	*q++ = '\0';
    }
    if (*p == '\0') {
      if (arg)
	error("argument without option");
    }
    else if (strieq(p, "tab")) {
      if (!arg)
	error("`tab' option requires argument in parentheses");
      else {
	if (arg[0] == '\0' || arg[1] != '\0')
	  error("argument to `tab' option must be a single character");
	else
	  opt->tab_char = arg[0];
      }
    }
    else if (strieq(p, "linesize")) {
      if (!arg)
	error("`linesize' option requires argument in parentheses");
      else {
	if (sscanf(arg, "%d", &opt->linesize) != 1)
	  error("bad linesize `%s'", arg);
	else if (opt->linesize <= 0) {
	  error("linesize must be positive");
	  opt->linesize = 0;
	}
      }
    }
    else if (strieq(p, "delim")) {
      if (!arg)
	error("`delim' option requires argument in parentheses");
      else if (arg[0] == '\0' || arg[1] == '\0' || arg[2] != '\0')
	error("argument to `delim' option must be two characters");
      else {
	opt->delim[0] = arg[0];
	opt->delim[1] = arg[1];
      }
    }
    else if (strieq(p, "center") || strieq(p, "centre")) {
      if (arg)
	error("`center' option does not take an argument");
      opt->flags |= table::CENTER;
    }
    else if (strieq(p, "expand")) {
      if (arg)
	error("`expand' option does not take an argument");
      opt->flags |= table::EXPAND;
    }
    else if (strieq(p, "box") || strieq(p, "frame")) {
      if (arg)
	error("`box' option does not take an argument");
      opt->flags |= table::BOX;
    }
    else if (strieq(p, "doublebox") || strieq(p, "doubleframe")) {
      if (arg)
	error("`doublebox' option does not take an argument");
      opt->flags |= table::DOUBLEBOX;
    }
    else if (strieq(p, "allbox")) {
      if (arg)
	error("`allbox' option does not take an argument");
      opt->flags |= table::ALLBOX;
    }
    else if (strieq(p, "nokeep")) {
      if (arg)
	error("`nokeep' option does not take an argument");
      opt->flags |= table::NOKEEP;
    }
    else if (strieq(p, "nospaces")) {
      if (arg)
	error("`nospaces' option does not take an argument");
      opt->flags |= table::NOSPACES;
    }
    else if (strieq(p, "decimalpoint")) {
      if (!arg)
	error("`decimalpoint' option requires argument in parentheses");
      else {
	if (arg[0] == '\0' || arg[1] != '\0')
	  error("argument to `decimalpoint' option must be a single character");
	else
	  opt->decimal_point_char = arg[0];
      }
    }
    else if (strieq(p, "experimental")) {
      opt->flags |= table::EXPERIMENTAL;
    }
    else {
      error("unrecognised global option `%1'", p);
      // delete opt;
      // return 0;
    }
    p = q;
  }
  return opt;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
  program_name = argv[0];
  static char stderr_buf[BUFSIZ];
  setbuf(stderr, stderr_buf);
  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, "vVi:t:", long_options, NULL)) != EOF)
    switch (opt) {
    case 'V':
      verify_flag = 1;
      break;
    case 'i':
      linear_ignore_fields = optarg;
      break;
    case 't':
      {
	char *ptr;
	long n = strtol(optarg, &ptr, 10);
	if (n == 0 && ptr == optarg) {
	  error("bad integer `%1' in `t' option", optarg);
	  break;
	}
	if (n < 1)
	  n = 1;
	linear_truncate_len = int(n);
	break;
      }
    case 'v':
      {
	printf("GNU lookbib (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);
    }
  if (optind >= argc) {
    usage(stderr);
    exit(1);
  }
  search_list list;
  for (int i = optind; i < argc; i++)
    list.add_file(argv[i]);
  if (list.nfiles() == 0)
    fatal("no databases");
  char line[1024];
  int interactive = isatty(fileno(stdin));
  for (;;) {
    if (interactive) {
      fputs("> ", stderr);
      fflush(stderr);
    }
    if (!fgets(line, sizeof(line), stdin))
      break;
    char *ptr = line;
    while (csspace(*ptr))
      ptr++;
    if (*ptr == '\0')
      continue;
    search_list_iterator iter(&list, line);
    const char *start;
    int len;
    int count;
    for (count = 0; iter.next(&start, &len); count++) {
      if (fwrite(start, 1, len, stdout) != (size_t)len)
	fatal("write error on stdout: %1", strerror(errno));
      // Can happen for last reference in file.
      if (start[len - 1] != '\n')
	putchar('\n');
      putchar('\n');
    }
    fflush(stdout);
    if (interactive) {
      fprintf(stderr, "%d found\n", count);
      fflush(stderr);
    }
  }
  if (interactive)
    putc('\n', stderr);
  return 0;
}
Ejemplo n.º 15
0
Archivo: ref.cpp Proyecto: att/uwin
reference::reference(const char *start, int len, reference_id *ridp)
: h(0), merged(0), no(-1), field(0), nfields(0), label_ptr(0),
  computed_authors(0), last_needed_author(-1), nauthors(-1)
{
  int i;
  for (i = 0; i < 256; i++)
    field_index[i] = NULL_FIELD_INDEX;
  if (ridp)
    rid = *ridp;
  if (start == 0)
    return;
  if (len <= 0)
    return;
  const char *end = start + len;
  const char *ptr = start;
  assert(*ptr == '%');
  while (ptr < end) {
    if (ptr + 1 < end && ptr[1] != '\0'
	&& ((ptr[1] != '%' && ptr[1] == annotation_field)
	    || (ptr + 2 < end && ptr[1] == '%' && ptr[2] != '\0'
		&& discard_fields.search(ptr[2]) < 0))) {
      if (ptr[1] == '%')
	ptr++;
      string &f = temp_fields[(unsigned char)ptr[1]];
      ptr += 2;
      while (ptr < end && csspace(*ptr))
	ptr++;
      for (;;) {
	for (;;) {
	  if (ptr >= end) {
	    f += '\n';
	    break;
	  }
	  f += *ptr;
	  if (*ptr++ == '\n')
	    break;
	}
	if (ptr >= end || *ptr == '%')
	  break;
      }
    }
    else if (ptr + 1 < end && ptr[1] != '\0' && ptr[1] != '%'
	     && discard_fields.search(ptr[1]) < 0) {
      string &f = temp_fields[(unsigned char)ptr[1]];
      if (f.length() > 0) {
	if (strchr(MULTI_FIELD_NAMES, ptr[1]) != 0)
	  f += FIELD_SEPARATOR;
	else
	  f.clear();
      }
      ptr += 2;
      if (ptr < end) {
	if (*ptr == ' ')
	  ptr++;
	for (;;) {
	  const char *p = ptr;
	  while (ptr < end && *ptr != '\n')
	    ptr++;
	  // strip trailing white space
	  const char *q = ptr;
	  while (q > p && q[-1] != '\n' && csspace(q[-1]))
	    q--;
	  while (p < q)
	    f += *p++;
	  if (ptr >= end)
	    break;
	  ptr++;
	  if (ptr >= end)
	    break;
	  if (*ptr == '%')
	    break;
	  f += ' ';
	}
      }
    }
    else {
      // skip this field
      for (;;) {
	while (ptr < end && *ptr++ != '\n')
	  ;
	if (ptr >= end || *ptr == '%')
	  break;
      }
    }
  }
  for (i = 0; i < 256; i++)
    if (temp_fields[i].length() > 0)
      nfields++;
  field = new string[nfields];
  int j = 0;
  for (i = 0; i < 256; i++)
    if (temp_fields[i].length() > 0) {
      field[j].move(temp_fields[i]);
      if (abbreviate_fields.search(i) >= 0)
	abbreviate_names(field[j]);
      field_index[i] = j;
      j++;
    }
}