Beispiel #1
0
static void
andline(struct node *lnode, unsigned char *lp)
{
  char *tok;
  unsigned char *end = lp+xxstrlen(lp);
  unsigned char *s = lp+1;
  char *idbase = NULL;
  int equals_flag = 0;

  next_trans_id = 0;

  if (!lnode)
    return;

  curr_lang = global_lang;

  while (*s && isspace(*s))
    ++s;
  if (isupper(*s))
    {
      tok = (char*)s++;
      while (isdigit(*s))
	++s;
#if 0
      /* this is not presently permitted in IDs, but we have talked
	 about enabling it from time to time */
      while (islower(*s))
	++s;
#endif
      if (!*s)
	idbase = tok;
      else if (isspace(*s))
	{
	  *s++ = '\0';
	  idbase = tok;
	}
      else if ('=' == *s)
	{
	  *s++ = '\0';
	  equals_flag = 1;
	  idbase = tok;
	}
      else
	{
	  unsigned char save = *s;
	  *s = '\0';
	  vwarning("malformed &-ID beginning %s", tok);
	  *s = save;
	}
    }
  else
    {
      vwarning("malformed &-ID: %s", s);
    }

  if (!idbase)
    {
      static int id = 0;
      static char Xbuf[8];
      sprintf(Xbuf,"X%06d",++id);
      textid = idbase = Xbuf;
    }
  else
    xstrcpy(textid,idbase);

  if (!check_and_register(idbase, 1))
    {
      xstrcpy(line_id_buf,idbase);
      xstrcat(line_id_buf,".");
      line_id_insertp = line_id_buf + xxstrlen(line_id_buf);
      setAttr(lnode,a_xml_id,ucc(idbase));
      tok = NULL;
      if (s < end)
	{
	  if (!equals_flag)
	    while (*s && '=' != *s)
	      ++s;
	  if ('=' == *s)
	    {
	      *s++ = '=';
	      ++equals_flag;
	    }
	  if (!equals_flag)
	    warning("expected '=' in and-line");
	  else
	    {
	      while (*s && isspace(*s))
		++s;
	      if (*s)
		{
		  tok = (char*)s;
		  s = end;
		  while (isspace(s[-1]))
		    --s;
		  *s = '\0';
		}
	    }
	}
      else
	warning("no text name in and-line");
      /* if there was no '= NAME' in the andline we fix up by using the IDBASE
	 and process the text to find further errors; because the warnings set
	 status the text will not be output */
      if (!tok)
	tok = idbase;
      if (check_pnames && 'P' == *textid)
	(void)check_pname(textid,ucc(tok));
      if (xxstrlen(tok)+1 > text_n_alloced)
	{
	  text_n_alloced = text_n_alloced ? text_n_alloced * 2 : 128;
	  text_n = realloc(text_n,text_n_alloced);
	}
      xstrcpy(text_n,tok);
      setAttr(lnode,a_n,ucc(tok));
      if (verbose)
	fprintf(f_log, "%s = %s\n",textid,tok);
    }
  else
    {
      if (!idbase)
	idbase = "X123456";
      xstrcpy(line_id_buf,idbase);
      xstrcat(line_id_buf,".");
      line_id_insertp = line_id_buf + xxstrlen(line_id_buf);
      setAttr(lnode,a_xml_id,ucc(idbase));
      tok = NULL;
      if (!tok)
	tok = idbase;
      if (check_pnames && 'P' == *textid)
	(void)check_pname(textid,ucc(tok));
      if (xxstrlen(tok)+1 > text_n_alloced)
	{
	  text_n_alloced = text_n_alloced ? text_n_alloced * 2 : 128;
	  text_n = realloc(text_n,text_n_alloced);
	}
      xstrcpy(text_n,tok);
      setAttr(lnode,a_n,ucc(tok));
      if (verbose)
	fprintf(f_log, "%s = %s\n",textid,tok);
    }
}
Beispiel #2
0
static const char *
scan_pair(const char *line)
{
    const char *tokend = NULL, *colon = NULL;
    char *pqid = NULL, *idstart;

    tokend = line;
    while (*tokend && !isspace(*tokend) && '=' != *tokend)
    {
        if (':' == *tokend)
            colon = tokend;
        ++tokend;
    }

    pqid = malloc((tokend - line) + 1);
    strncpy(pqid, line, tokend - line);
    pqid[tokend-line] = '\0';

    if (colon)
        idstart = pqid + (colon - line) + 1;
    else
    {
        /*idstart = pqid;*/
        warning("malformed link: protocol: no PROJECT (format is now PROJECT:PQX-ID)");
        return NULL;
    }

    if (*idstart == 'P')
    {
        if (check_and_register(idstart,0))
        {
            free(pqid);
            return NULL;
        }
    }
    else
    {
        if (*idstart != 'Q' && *idstart != 'X')
        {
            warning("malformed link: protocol: expected PQX-ID");
            return NULL;
        }
    }

    line = tokend;
    while (isspace(*line))
        ++line;

    if ('=' != *line || !isspace(line[1]))
    {
        warning("malformed link: protocol: expected '= '");
        return NULL;
    }

    ++line;
    while (isspace(*line))
        ++line;

    if (*line)
    {
        if (pnames && 'P' == *idstart)
            (void)check_pname(idstart,(const unsigned char *)line);
        last_pname = line;
        return pqid;
    }
    else
    {
        warning("malformed link: protocol: expected text name");
        last_pname = NULL;
        return NULL;
    }
}