예제 #1
0
void get_argv(char *line, char argv[10][80])
{
	int i = 0;
	char *p_start = NULL;
	char *p_end = NULL;
	char *line_end = NULL;

	line_end = line + strlen(line);
	*line_end = ' ';
	p_start = line;
	skip_blank(&p_start); 

	if (strcmp(p_start, "") == 0)
		return;

	p_end = strchr(p_start, ' ');

	while (p_start != line_end)
	{
		strncpy(argv[i++], p_start, p_end-p_start+1);
		p_start = p_end;
		
		if (p_start == line_end)
			break;
		
		skip_blank(&p_start); 
		p_end = strchr(p_start, ' ');
	}

	for (;i>=0; i--)
		puts(argv[i]);

	return;
}
예제 #2
0
파일: ctpl-environ.c 프로젝트: antono/ctpl
/*
 * tries to read an array.
 * 
 * Returns: %TRUE on full success, %FALSE otherwise.
 */
static gboolean
read_array (CtplInputStream *stream,
            CtplValue       *value,
            GError         **error)
{
  GError *err = NULL;
  gchar   c;
  
  c = ctpl_input_stream_get_c (stream, &err);
  if (err) {
    /* I/O error */
  } else if (c != ARRAY_START_CHAR) {
    ctpl_input_stream_set_error (stream, &err, CTPL_ENVIRON_ERROR,
                                 CTPL_ENVIRON_ERROR_LOADER_MISSING_VALUE,
                                 "Not an array");
  } else {
    ctpl_value_set_array (value, CTPL_VTYPE_INT, 0, NULL);
    /* don't try to extract any value from an empty array */
    if (skip_blank (stream, &err) >= 0 &&
        ctpl_input_stream_peek_c (stream, &err) == ARRAY_END_CHAR &&
        ! err) {
      ctpl_input_stream_get_c (stream, &err); /* eat character */
    } else {
      CtplValue item;
      gboolean  in_array = TRUE;
      
      ctpl_value_init (&item);
      while (! err && in_array) {
        if (skip_blank (stream, &err) >= 0 &&
            read_value (stream, &item, &err)) {
          ctpl_value_array_append (value, &item);
          if (skip_blank (stream, &err) >= 0) {
            c = ctpl_input_stream_get_c (stream, &err);
            if (err) {
              /* I/O error */
            } else if (c == ARRAY_END_CHAR) {
              in_array = FALSE;
            } else if (c == ARRAY_SEPARATOR_CHAR) {
              /* nothing to do, just continue reading */
            } else {
              ctpl_input_stream_set_error (stream, &err, CTPL_ENVIRON_ERROR,
                                           CTPL_ENVIRON_ERROR_LOADER_MISSING_SEPARATOR,
                                           "Missing `%c` separator between array "
                                           "values", ARRAY_SEPARATOR_CHAR);
            }
          }
        }
      }
      ctpl_value_free_value (&item);
    }
  }
  if (err) {
    g_propagate_error (error, err);
  }
  
  return ! err;
}
예제 #3
0
int
spc_color_setup_handler (struct spc_handler *sph,
			 struct spc_env *spe, struct spc_arg *ap)
{
  const char *p;
  char *q;

  ASSERT(sph && spe && ap);

  skip_blank(&ap->curptr, ap->endptr);
  q = parse_c_ident(&ap->curptr, ap->endptr);
  if (!q)
    return  -1;
  skip_blank(&ap->curptr, ap->endptr);

  if (!strcmp(q, "background")) {
    ap->command = "background";
    sph->exec   = &spc_handler_background;
    RELEASE(q);
  } else if (!strcmp(q, "color")) { /* color */
    RELEASE(q);
    p = ap->curptr;

    q = parse_c_ident(&p, ap->endptr);
    if (!q)
      return  -1;
    else if (!strcmp(q, "push")) {
      ap->command = "push";
      sph->exec   = &spc_handler_color_push;
      ap->curptr  = p;
    } else if (!strcmp(q, "pop")) {
      ap->command = "pop";
      sph->exec   = &spc_handler_color_pop;
      ap->curptr  = p;
    } else { /* cmyk, rgb, ... */
      ap->command = "";
      sph->exec   = &spc_handler_color_default;
    }
    RELEASE(q);
  } else {
    spc_warn(spe, "Not color/background special?");
    RELEASE(q);
    return  -1;
  }

  skip_blank(&ap->curptr, ap->endptr);
  return  0;
}
예제 #4
0
int get_cmd(char **line, char *cmd)
{
	char *p_start = NULL;
	char *p_end = NULL;
	char *line_end = NULL;

	line_end = (*line) + strlen(*line) -1;
	p_start = *line;
		
	if (strcmp(p_start, "") == 0)
		return -1;

	skip_blank(&p_start);

	p_end = strchr(p_start, ' ');

	if (p_end == NULL)
		p_end = line_end;
	
	strncpy(cmd, p_start, p_end-p_start+1);

	puts(cmd);
	
	*line = p_end + 1;
	return 0;
}
예제 #5
0
bool DataTypeClassNameParser::Parser::read_raw_arguments(std::string* args) {
  skip_blank();

  if (is_eos() || str_[index_] == ')' || str_[index_] == ',') {
    *args = "";
    return true;
  }

  if (str_[index_] != '(') {
    parse_error(str_, index_, "Expected '('");
    return false;
  }

  int i = index_;
  int open = 1;
  while (open > 0) {
    ++index_;

    if (is_eos()) {
      parse_error(str_, index_, "Expected ')'");
      return false;
    }

    if (str_[index_] == '(') {
      open++;
    } else if (str_[index_] == ')') {
      open--;
    }
  }

  ++index_; // Skip ')'
  *args = str_.substr(i, index_);
  return true;
}
예제 #6
0
static int is_comment_line(char *line)
{
	char *p	= (char *) skip_blank(line);

	if (p && (*p == '#' || *p == '\n'))
		return 1;
	return 0;
}
예제 #7
0
bool DataTypeClassNameParser::Parser::get_name_and_type_params(NameAndTypeParamsVec* params) {
  while (skip_blank_and_comma()) {
    if (str_[index_] == ')') {
      ++index_;
      return true;
    }

    std::string hex;
    read_next_identifier(&hex);

    std::string name;
    if (!from_hex(hex, &name)) {
      LOG_ERROR("Invalid hex string \"%s\" for parameter", hex.c_str());
      return DataType::ConstPtr();
    }

    skip_blank();

    if (str_[index_] != ':') {
      parse_error(str_, index_,  "Expected ':'");
      return false;
    }

    ++index_;
    skip_blank();

    std::string type;

    if (!read_one(&type)) {
      return false;
    }

    params->push_back(std::make_pair(name, type));
  }

  parse_error(str_, index_,  "Unexpected end of string");
  return false;
}
예제 #8
0
BOOL	CCmdLineParser::DoParser(LPCTSTR lpCmdLine, 
				  LPCTSTR lpCurDir, 
				  LPCTSTR lpEnvVars, 
				  LPCTSTR lpExtNames,
				  LPCTSTR lpParentPath
				  )
{
	BOOL bResult = FALSE;

	//  修正 空白文件名 解析
	LPCTSTR lpCmdLineBegin = skip_blank(lpCmdLine);
	if ( lpCurDir != NULL || lpParentPath != NULL )
	{
		if ( lpCmdLineBegin != lpCmdLine )
		{
			BOOL bVaild = TRUE;

			LPCTSTR lpCmdLineEnd = skip_no_blank(lpCmdLineBegin);
			if ( lpCmdLineEnd != lpCmdLineBegin )
			{
				LPCTSTR lpStr = lpCmdLineBegin;
				while ( lpStr < lpCmdLineEnd )
				{
					if ( !is_vaild_file_name_char(*lpStr) )
					{
						bVaild = FALSE;
						break;
					}

					lpStr++;
				}
			}

			if ( bVaild )
			{
				bResult = _DoParser(lpCmdLine, lpCurDir, lpEnvVars, lpExtNames, lpParentPath);
				if ( bResult )
				{
					return TRUE;
				}
			}
		}
	}

	return _DoParser(lpCmdLineBegin, lpCurDir, lpEnvVars, lpExtNames, lpParentPath);
}
예제 #9
0
void CCmdLineParser::ExpandParam(LPCTSTR lpCmdEnd)
{
	if ( m_dwFlag & NEED_PARAM )
	{
		LPCTSTR lpParamBegin;

		lpParamBegin = lpCmdEnd;
		lpParamBegin = skip_blank(lpParamBegin);

		if ( !is_empty_str(lpParamBegin) )
		{
			size_t nParamLen = _tcslen(lpParamBegin);

			m_lpParam = new TCHAR[nParamLen + 2];
			_tcscpy(m_lpParam, lpParamBegin);
		}
	}
}
예제 #10
0
bool DataTypeCqlNameParser::Parser::read_raw_type_parameters(std::string* params) {
  skip_blank();

  params->clear();

  if (is_eos() || str_[index_] == '>' || str_[index_] == ',') return true;

  if (str_[index_] != '<') {
    LOG_ERROR("Expecting char %u of %s to be '<' but '%c' found",
              (unsigned int)index_, str_.c_str(), str_[index_]);
    return false;
  }

  size_t start_index = index_;
  int open = 1;
  bool in_quotes = false;
  while (open > 0) {
    ++index_;

    if (is_eos()) {
      LOG_ERROR("Angle brackets not closed in type %s", str_.c_str());
      return false;
    }

    if (!in_quotes) {
      if (str_[index_] == '"') {
        in_quotes = true;
      } else if (str_[index_] == '<') {
        open++;
      } else if (str_[index_] == '>') {
        open--;
      }
    } else if (str_[index_] == '"') {
      in_quotes = false;
    }
  }

  ++index_; // Move past the  trailing '>'
  params->assign(str_.begin() + start_index, str_.begin() + index_);
  return true;
}
예제 #11
0
static int next_number(char **s, int *num)
{
	char *end = NULL;

	assert(num);
	assert(s);

	*s = (char *) skip_blank(*s);
	if (!**s)
		return -1;
	*num = strtol(*s, &end, 10);
	if (end == NULL || *s == end)
	       return -1;

	*s = end;

	/* valid end of number is a space or a terminator */
	if (*end == ' ' || *end == '\t' || *end == '\0')
		return 0;
	return -1;
}
예제 #12
0
int
spc_color_check_special (const char *buf, long len)
{
  int   r = 0;
  const char *p, *endptr;
  char *q;

  p      = buf;
  endptr = p + len;

  skip_blank(&p, endptr);
  q = parse_c_ident(&p, endptr);
  if (!q)
    return  0;
  else if (!strcmp(q, "color"))
    r = 1;
  else if (!strcmp(q, "background")) {
    r = 1;
  }
  RELEASE(q);

  return  r;
}
예제 #13
0
static gboolean
ct_text_set_tooltip (DonnaColumnType    *ct,
                     gpointer            _data,
                     guint               index,
                     DonnaNode          *node,
                     GtkTooltip         *tooltip)
{
    struct tv_col_data *data = _data;
    DonnaNodeHasValue has;
    GValue value = G_VALUE_INIT;
    const gchar *s;

    donna_node_get (node, FALSE,
            (data->property_tooltip) ? data->property_tooltip : data->property,
            &has, &value, NULL);
    if (has != DONNA_NODE_VALUE_SET)
        return FALSE;
    if (G_VALUE_TYPE (&value) != G_TYPE_STRING)
    {
        g_value_unset (&value);
        return FALSE;
    }

    /* don't show tooltip w/ an empty string */
    s = g_value_get_string (&value);
    if (s)
    {
        skip_blank (s);
        if (*s != '\0')
            gtk_tooltip_set_text (tooltip, g_value_get_string (&value));
        else
            s = NULL;
    }
    g_value_unset (&value);
    return !!s;
}
예제 #14
0
DWORD GetFileListFromCmd(LPCTSTR lpCmd, LPCTSTR lpParam, CAtlArray<CString>& fileArray, LPCTSTR lpCurDir)
{
	if ( lpCmd == NULL || lpParam == NULL )
	{
		return 0;
	}

	LPCTSTR lpFileName = _tcsrchr(lpCmd, _T('\\'));
	if ( lpFileName != NULL )
	{
		lpFileName++;

		CCmdLineParser cmdParser((DWORD)0);
		if ( _tcscmp(lpFileName, _T("mshta.exe")) == 0 )
		{
			if ( cmdParser.DoParser(lpParam, lpCurDir, NULL, _T("hta")) )
			{
				fileArray.Add(cmdParser.GetCmd());
			}
		}
		else if ( _tcsicmp(lpFileName, _T("msiexec.exe")) == 0 )
		{
			LPCTSTR lpNextParam = skip_no_blank(lpParam);

			if ( _tcsnicmp(lpParam, _T("/i"), lpNextParam - lpParam) == 0 )
			{
				lpParam = skip_blank(lpNextParam);
				if ( cmdParser.DoParser(lpParam, lpCurDir, NULL, _T("msi")) )
				{
					fileArray.Add(cmdParser.GetCmd());
				}
			}
		}
		else if ( _tcsicmp(lpFileName, _T("rundll32.exe")) == 0 )
		{
			LPCTSTR lpNextParam = skip_no_blank(lpParam);

			if ( _tcsnicmp(lpParam, _T("shell32.dll,ShellExec_RunDLL"), lpNextParam - lpParam) == 0 )
			{
				lpParam = skip_blank(lpNextParam);
			}

			LPCTSTR lpXX = _tcschr(lpParam, _T(','));
			if ( lpXX != NULL )
			{
				*(LPTSTR)lpXX = 0;
			}

			if ( cmdParser.DoParser(lpParam, lpCurDir, NULL, _T("dll")) )
			{
				fileArray.Add(cmdParser.GetCmd());
			}

			if ( lpXX != NULL )
			{
				*(LPTSTR)lpXX = 0;
			}
		}
		else if ( _tcsicmp(lpFileName, _T("wscript.exe")) == 0 ||
			_tcsicmp(lpFileName, _T("cscript.exe")) == 0
			)
		{
			LPCTSTR lpStr = lpParam;
			while ( *lpStr != 0 )
			{
				lpStr = skip_blank(lpStr);
				if ( *lpStr == _T('/') || *lpStr == _T('-') )
				{
					lpStr = skip_no_blank(lpStr);
				}
				else//
				{
					if ( cmdParser.DoParser(lpStr, lpCurDir, NULL, _T("wsh;vbs;vbe;")) )
					{
						fileArray.Add(cmdParser.GetCmd());
					}
					break;
				}//
			}
		}
		else if ( _tcsicmp(lpFileName, _T("cmd.exe")) == 0 )
		{
			LPCTSTR lpStr = lpParam;
			while ( *lpStr != 0 )
			{
				lpStr = skip_blank(lpStr);
				if ( *lpStr == _T('/') || *lpStr == _T('-') )
				{
					lpStr = skip_no_blank(lpStr);
				}
				else
				{
					if ( cmdParser.DoParser(lpStr, lpCurDir, NULL, _T("bat;cmd;exe;")) )
					{
						fileArray.Add(cmdParser.GetCmd());
						GetFileListFromCmd(cmdParser, fileArray, lpCurDir);
					}
					break;
				}
			}
		}
		else if ( _tcsicmp(lpFileName, _T("regsvr32.exe")) == 0 )
		{
			LPCTSTR lpStr = lpParam;
			while ( *lpStr != 0 )
			{
				lpStr = skip_blank(lpStr);
				if ( *lpStr == _T('/') || *lpStr == _T('-') )
				{
					lpStr = skip_no_blank(lpStr);
				}
				else
				{
					if ( cmdParser.DoParser(lpStr, lpCurDir) )
					{
						fileArray.Add(cmdParser.GetCmd());
					}
					break;
				}
			}
		}
	}

	return (DWORD)fileArray.GetCount();
}
예제 #15
0
파일: ctpl-environ.c 프로젝트: antono/ctpl
/* tries to load the next symbol from the environment description */
static gboolean
load_next (CtplEnviron     *env,
           CtplInputStream *stream,
           GError         **error)
{
  gboolean  rv = FALSE;
  
  if (skip_blank (stream, error) >= 0) {
    gchar *symbol;
    
    symbol = ctpl_input_stream_read_symbol (stream, error);
    if (! symbol) {
      /* I/O error */
    } else if (! *symbol) {
      ctpl_input_stream_set_error (stream, error, CTPL_ENVIRON_ERROR,
                                   CTPL_ENVIRON_ERROR_LOADER_MISSING_SYMBOL,
                                   "Missing symbol");
    } else {
      if (skip_blank (stream, error) >= 0) {
        GError *err = NULL;
        gchar   c;
        
        c = ctpl_input_stream_get_c (stream, &err);
        if (err) {
          /* I/O error */
          g_propagate_error (error, err);
        } else if (c != VALUE_SEPARATOR_CHAR) {
          ctpl_input_stream_set_error (stream, error, CTPL_ENVIRON_ERROR,
                                       CTPL_ENVIRON_ERROR_LOADER_MISSING_SEPARATOR,
                                       "Missing `%c` separator between symbol "
                                       "and value", VALUE_SEPARATOR_CHAR);
        } else {
          if (skip_blank (stream, error) >= 0) {
            CtplValue value;
            
            ctpl_value_init (&value);
            if (read_value (stream, &value, error) &&
                skip_blank (stream, error) >= 0) {
              c = ctpl_input_stream_get_c (stream, &err);
              if (err) {
                /* I/O error */
                g_propagate_error (error, err);
              } else if (c != VALUE_END_CHAR) {
                ctpl_input_stream_set_error (stream, error, CTPL_ENVIRON_ERROR,
                                             CTPL_ENVIRON_ERROR_LOADER_MISSING_SEPARATOR,
                                             "Missing `%c` separator after end "
                                             "of symbol's value",
                                             VALUE_END_CHAR);
              } else {
                /* skip blanks again to try to reach end before next call */
                if (skip_blank (stream, error) >= 0) {
                  ctpl_environ_push (env, symbol, &value);
                  rv = TRUE;
                }
              }
            }
            ctpl_value_free_value (&value);
          }
        }
      }
    }
    g_free (symbol);
  }
  
  return rv;
}
예제 #16
0
void DataTypeClassNameParser::Parser::get_next_name(std::string* name) {
  skip_blank();
  read_next_identifier(name);
}
예제 #17
0
void DataTypeCqlNameParser::Parser::parse_type_name(std::string* name) {
  skip_blank();
  read_next_identifier(name);
}
예제 #18
0
int script_parse_fex(FILE *in, const char *filename, struct script *script)
{
	char buffer[MAX_LINE+1];
	int ok = 1;
	struct script_section *last_section = NULL;

	/* TODO: deal with longer lines correctly (specially in comments) */
	for(size_t line = 1; ok && fgets(buffer, sizeof(buffer), in); line++) {
		char *s = skip_blank(buffer); /* beginning */
		char *pe = s; /* \0... to be found */

		if (*pe) while (*++pe)
			;

		if (pe>s && pe[-1] == '\n') {
			if (pe>s+1 && pe[-2] == '\r')
				pe -= 2;
			else
				pe -= 1;
			*pe = '\0';
		}

		pe = rtrim(s, pe);

		if (pe == s || *s == ';' || *s == '#')
			continue; /* empty */
		else if (*s == '[') {
			/* section */
			char *p = ++s;
			while (isalnum(*p) || *p == '_')
				p++;

			if (*p == ']' && *(p+1) == '\0') {
				*p = '\0';
				if ((last_section = script_section_new(script, s)))
					continue;

				perror("malloc");
			} else if (*p) {
				errf("E: %s:%zu: invalid character at %zu.\n",
				     filename, line, p-buffer+1);
			} else {
				errf("E: %s:%zu: incomplete section declaration.\n",
				     filename, line);
			}
			ok = 0;
		} else {
			/* key = value */
			const char *key = s;
			char *mark, *p = s;

			if (!last_section) {
				errf("E: %s:%zu: data must follow a section.\n",
				     filename, line);
				goto parse_error;
			};

			while (isalnum(*p) || *p == '_')
				p++;
			mark = p;
			p = skip_blank(p);
			if (*p != '=')
				goto invalid_char_at_p;
			*mark = '\0'; /* truncate key */
			p = skip_blank(p+1);

			if (*p == '\0') {
				/* NULL */
				if (script_null_entry_new(last_section, key))
					continue;
				perror("malloc");
			} else if (pe > p+1 && *p == '"' && pe[-1] == '"') {
				/* string */
				p++; *--pe = '\0';
				if (script_string_entry_new(last_section, key, pe-p, p)) {
					pr_debug("%s.%s = \"%.*s\"\n",
						 last_section->name, key,
						 (int)(pe-p), p);
					continue;
				}
				perror("malloc");
			} else if (memcmp("port:", p, 5) == 0) {
				/* GPIO */
				p += 5;
				if (p[0] == 'P' &&
				    (p[1] < 'A' || p[1] > 'I'))
					;
				else if (*p != 'P' &&
					 memcmp(p, "power", 5) != 0)
					;
				else {
					char *end;
					int port;
					long v;

					if (*p == 'P') {
						/* port:PXN */
						port = p[1] - 'A' + 1;
						p += 2;
					} else {
						/* port:powerN */
						port = 0xffff;
						p += 5;
					}

					v = strtol(p, &end, 10);
					if (end == p)
						goto invalid_char_at_p;
					else if (v<0 || v>255) {
						errf("E: %s:%zu: port out of range at %zu (%ld).\n",
						     filename, line, p-buffer+1, v);
					} else {
						int data[] = {-1,-1,-1,-1};
						int port_num = v;
						p = end;
						for (int i=0; *p && i<4; i++) {
							if (memcmp(p, "<default>", 9) == 0) {
								p += 9;
								continue;
							} else if (*p == '<') {
								v = strtol(++p, &end, 10);
								if (end == p) {
									;
								} else if (v<0 || v>INT32_MAX) {
									errf("E: %s:%zu: value out of range at %zu (%ld).\n",
									     filename, line, p-buffer+1, v);
									goto parse_error;
								} else if (*end != '>') {
									p = end;
								} else {
									p = end+1;
									data[i] = v;
									continue;
								}
							}
							break;
						}
						if (*p)
							goto invalid_char_at_p;
						if (script_gpio_entry_new(last_section, key,
									  port, port_num, data)) {
							pr_debug("%s.%s = GPIO %d.%d (%d,%d,%d,%d)\n",
								 last_section->name, key,
								 port, port_num,
								 data[0], data[1], data[2], data[3]);
							continue;
						}
						perror("malloc");
					}
				}
			} else if (isdigit(*p)) {
				long long v = 0;
				char *end;
				v = strtoll(p, &end, 0);
				p = end;
				if (p != pe) {
					goto invalid_char_at_p;
				} else if (v > UINT32_MAX) {
					errf("E: %s:%zu: value out of range %lld.\n",
					     filename, line, v);
				} else if (script_single_entry_new(last_section, key, v)) {
					pr_debug("%s.%s = %lld\n",
						 last_section->name, key, v);
					continue;
				}
			} else {
				goto invalid_char_at_p;
			}
			goto parse_error;
invalid_char_at_p:
			errf("E: %s:%zu: invalid character at %zu.\n",
			     filename, line, p-buffer+1);
parse_error:
			ok = 0;
		}
	};

	if (ferror(in))
		ok = 0;
	return ok;
}
예제 #19
0
파일: ed.c 프로젝트: Crobisaur/busybox
/*
 * Read commands until we are told to stop.
 */
static void doCommands(void)
{
	const char *cp;
	char *endbuf, buf[USERSIZE];
	int len, num1, num2;
	smallint have1, have2;

	while (TRUE) {
		/* Returns:
		 * -1 on read errors or EOF, or on bare Ctrl-D.
		 * 0  on ctrl-C,
		 * >0 length of input string, including terminating '\n'
		 */
		len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1);
		if (len <= 0)
			return;
		endbuf = &buf[len - 1];
		while ((endbuf > buf) && isblank(endbuf[-1]))
			endbuf--;
		*endbuf = '\0';

		cp = skip_blank(buf);
		have1 = FALSE;
		have2 = FALSE;

		if ((curNum == 0) && (lastNum > 0)) {
			curNum = 1;
			curLine = lines.next;
		}

		if (!getNum(&cp, &have1, &num1))
			continue;

		cp = skip_blank(cp);

		if (*cp == ',') {
			cp++;
			if (!getNum(&cp, &have2, &num2))
				continue;
			if (!have1)
				num1 = 1;
			if (!have2)
				num2 = lastNum;
			have1 = TRUE;
			have2 = TRUE;
		}
		if (!have1)
			num1 = curNum;
		if (!have2)
			num2 = num1;

		switch (*cp++) {
		case 'a':
			addLines(num1 + 1);
			break;

		case 'c':
			deleteLines(num1, num2);
			addLines(num1);
			break;

		case 'd':
			deleteLines(num1, num2);
			break;

		case 'f':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad file command");
				break;
			}
			cp = skip_blank(cp);
			if (*cp == '\0') {
				if (fileName)
					printf("\"%s\"\n", fileName);
				else
					puts("No file name");
				break;
			}
			free(fileName);
			fileName = xstrdup(cp);
			break;

		case 'i':
			addLines(num1);
			break;

		case 'k':
			cp = skip_blank(cp);
			if ((*cp < 'a') || (*cp > 'z') || cp[1]) {
				bb_error_msg("bad mark name");
				break;
			}
			marks[*cp - 'a'] = num2;
			break;

		case 'l':
			printLines(num1, num2, TRUE);
			break;

		case 'p':
			printLines(num1, num2, FALSE);
			break;

		case 'q':
			cp = skip_blank(cp);
			if (have1 || *cp) {
				bb_error_msg("bad quit command");
				break;
			}
			if (!dirty)
				return;
			len = read_line_input(NULL, "Really quit? ", buf, 16, /*timeout*/ -1);
			/* read error/EOF - no way to continue */
			if (len < 0)
				return;
			cp = skip_blank(buf);
			if ((*cp | 0x20) == 'y') /* Y or y */
				return;
			break;

		case 'r':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad read command");
				break;
			}
			cp = skip_blank(cp);
			if (*cp == '\0') {
				bb_error_msg("no file name");
				break;
			}
			if (!have1)
				num1 = lastNum;
			if (readLines(cp, num1 + 1))
				break;
			if (fileName == NULL)
				fileName = xstrdup(cp);
			break;

		case 's':
			subCommand(cp, num1, num2);
			break;

		case 'w':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad write command");
				break;
			}
			cp = skip_blank(cp);
			if (!have1) {
				num1 = 1;
				num2 = lastNum;
			}
			if (*cp == '\0')
				cp = fileName;
			if (cp == NULL) {
				bb_error_msg("no file name specified");
				break;
			}
			writeLines(cp, num1, num2);
			break;

		case 'z':
			switch (*cp) {
			case '-':
				printLines(curNum - 21, curNum, FALSE);
				break;
			case '.':
				printLines(curNum - 11, curNum + 10, FALSE);
				break;
			default:
				printLines(curNum, curNum + 21, FALSE);
				break;
			}
			break;

		case '.':
			if (have1) {
				bb_error_msg("no arguments allowed");
				break;
			}
			printLines(curNum, curNum, FALSE);
			break;

		case '-':
			if (setCurNum(curNum - 1))
				printLines(curNum, curNum, FALSE);
			break;

		case '=':
			printf("%d\n", num1);
			break;
		case '\0':
			if (have1) {
				printLines(num2, num2, FALSE);
				break;
			}
			if (setCurNum(curNum + 1))
				printLines(curNum, curNum, FALSE);
			break;

		default:
			bb_error_msg("unimplemented command");
			break;
		}
	}
}
예제 #20
0
/*
 * Parses one line from {fs,m}tab
 */
static int mnt_parse_table_line(struct libmnt_fs *fs, char *s)
{
	int rc, n = 0, xrc;
	char *src = NULL, *fstype = NULL, *optstr = NULL;

	rc = sscanf(s,	UL_SCNsA" "	/* (1) source */
			UL_SCNsA" "	/* (2) target */
			UL_SCNsA" "	/* (3) FS type */
			UL_SCNsA" "	/* (4) options */
			"%n",		/* byte count */

			&src,
			&fs->target,
			&fstype,
			&optstr,
			&n);
	xrc = rc;

	if (rc == 3 || rc == 4) {			/* options are optional */
		unmangle_string(src);
		unmangle_string(fs->target);
		unmangle_string(fstype);

		if (optstr && *optstr)
			unmangle_string(optstr);

		/* note that __foo functions do not reallocate the string
		 */
		rc = __mnt_fs_set_source_ptr(fs, src);
		if (!rc) {
			src = NULL;
			rc = __mnt_fs_set_fstype_ptr(fs, fstype);
			if (!rc)
				fstype = NULL;
		}
		if (!rc && optstr)
			rc = mnt_fs_set_options(fs, optstr);
		free(optstr);
		optstr = NULL;
	} else {
		DBG(TAB, mnt_debug("tab parse error: [sscanf rc=%d]: '%s'", rc, s));
		rc = -EINVAL;
	}

	if (rc) {
		free(src);
		free(fstype);
		free(optstr);
		DBG(TAB, mnt_debug("tab parse error: [set vars, rc=%d]\n", rc));
		return rc;	/* error */
	}

	fs->passno = fs->freq = 0;

	if (xrc == 4 && n)
		s = (char *) skip_blank(s + n);
	if (xrc == 4 && *s) {
		if (next_number(&s, &fs->freq) != 0) {
			if (*s) {
				DBG(TAB, mnt_debug("tab parse error: [freq]"));
				rc = -EINVAL;
			}
		} else if (next_number(&s, &fs->passno) != 0 && *s) {
			DBG(TAB, mnt_debug("tab parse error: [passno]"));
			rc = -EINVAL;
		}
	}

	return rc;
}
예제 #21
0
LPTSTR CCmdLineParser::ExpandRelative(LPCTSTR lpCmdBegin, LPCTSTR lpCurDir, BOOL bQuotation)
{
	LPTSTR	lpFileNameOffset, lpFileNameOffsetEnd;
	LPTSTR	lpDirOffset;
	BOOL	bJmpDir;
	TCHAR	szTempBuff[MAX_PATH + 10];
	LPCTSTR lpCmdEnd = NULL, lpCmdEnd_Last = NULL;
	LPTSTR	lpCmdBuff = NULL;

	if ( lpCurDir == NULL )
	{
		GetCurrentDirectory(MAX_PATH, m_szCmd);
	}
	else
	{
		fix_path_separator(m_szCmd, MAX_PATH, lpCurDir);
	}

	lpFileNameOffset = m_szCmd + _tcslen(m_szCmd);
	lpFileNameOffsetEnd = m_szCmd + MAX_PATH;
	if ( lpFileNameOffset[-1] == _T('\\') )
	{
		*--lpFileNameOffset = 0;
	}

	if ( bQuotation )
	{
		lpCmdEnd = _tcschr(lpCmdBegin, _T('\"'));
		if ( lpCmdEnd == NULL )
		{
			goto _Failed_Exit;
		}
	}
	else
	{
		lpCmdEnd = skip_no_blank(lpCmdBegin);
		if ( lpCmdEnd == lpCmdBegin )
		{
			lpCmdEnd = skip_blank(lpCmdBegin);
		}
	}

	if ( !fix_path_separator(szTempBuff, MAX_PATH, lpCmdBegin, lpCmdEnd - lpCmdBegin) )
	{
		goto _Failed_Exit;
	}

	// ../../a.exe
	// ./a.exe
	// ./../a.exe
	// a/../a.exe
	// ../a/2.exe
	bJmpDir = TRUE;
	lpDirOffset = szTempBuff;
	
	while ( *lpDirOffset != 0 )
	{
		if ( lpFileNameOffset >= lpFileNameOffsetEnd )
		{
			// 缓冲区不够
			goto _Failed_Exit;
		}

		if ( lpDirOffset[0] == _T('.') )
		{
			if ( lpDirOffset[1] == _T('.') && lpDirOffset[2] == _T('\\') )
			{
				lpFileNameOffset = (LPTSTR)re_strchr(m_szCmd, lpFileNameOffset, _T('\\'));
				if ( lpFileNameOffset == NULL )
				{
					// Bad Command Line
					goto _Failed_Exit;
				}

				*lpFileNameOffset = 0;
				lpDirOffset += 3;

				bJmpDir = TRUE;
				continue;
			}
			else if ( is_path_separator_char(lpDirOffset[1]) )
			{
				lpDirOffset += 2;

				bJmpDir = TRUE;
				continue;
			}
		}
		else if ( lpDirOffset[0] == _T('\\') )
		{
			lpDirOffset++;

			bJmpDir = TRUE;
			continue;
		}

		if ( bJmpDir )
		{
			bJmpDir = FALSE;
			*lpFileNameOffset++ = _T('\\');
		}

		*lpFileNameOffset++ = *lpDirOffset++;
		*lpFileNameOffset = 0;
	}

	if ( !bJmpDir )
	{
		size_t dwLen1 = _tcslen(m_szCmd);

		lpCmdBuff = new TCHAR[dwLen1 +  _tcslen(lpCmdEnd) + 2];
		if ( lpCmdBuff != NULL )
		{
			_tcscpy(lpCmdBuff, m_szCmd);
			if ( lpCmdBuff[dwLen1 - 1] == _T('\\') )
			{
				dwLen1--;
			}

			_tcscpy(lpCmdBuff + dwLen1, lpCmdEnd);
		}
	}

_Failed_Exit:
	return lpCmdBuff;
}
예제 #22
0
int ib_trans_line(
/*****************/

    section_def         *section,
    int                 alloc_size
) {
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[ 100 ];
    int                 indent = 0;
    int                 ctr;
    char                *file_name;

    // check for special pre-processing stuff first
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;

    // We start at a new line...
    Wrap_Safe = section->section_size;
    Cursor_X = 0;
    R_Chars = 0;

    if( Blank_line && ( ch != CH_LIST_ITEM ||
                        Curr_list->compact != LIST_SPACE_COMPACT ) ) {
        Blank_line = FALSE;
    }
    switch( ch ) {
    // Tabbed-example
    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
        } else {
            read_tabs( ptr + 1 );
            Tab_xmp = TRUE;
        }
        return( alloc_size );

    // Box-mode start
    case CH_BOX_ON:
        ctr = 0;
        // indent properly
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char( ' ', section, &alloc_size);
        }
        // draw the top line of the box
        trans_add_char( BOX_CORNER_TOP_LEFT, section, &alloc_size );
        for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) {
            trans_add_char( BOX_HBAR, section, &alloc_size );
        }
        trans_add_char( BOX_CORNER_TOP_RIGHT, section, &alloc_size );

        trans_add_char_wrap( '\n', section, &alloc_size);

        Box_Mode = TRUE;
        return( alloc_size );

    case CH_BOX_OFF:
        ctr = 0;
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char( ' ', section, &alloc_size);
        }

        trans_add_char( BOX_CORNER_BOTOM_LEFT, section, &alloc_size );
        for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) {
            trans_add_char( BOX_HBAR, section, &alloc_size );
        }
        trans_add_char( BOX_CORNER_BOTOM_RIGHT, section, &alloc_size );
        Box_Mode = FALSE;

        trans_add_char_wrap( '\n', section, &alloc_size );

        return( alloc_size );

    case CH_OLIST_START:
        new_list( LIST_TYPE_ORDERED );
        set_compact( ptr );
        Curr_indent += Text_Indent;
        return( alloc_size );

    case CH_LIST_START:
    case CH_DLIST_START:
        new_list( ( ch == CH_LIST_START ) ? LIST_TYPE_UNORDERED :
                                                        LIST_TYPE_DEFN );
        set_compact( ptr );
        Curr_indent += Text_Indent;

        if( ch == CH_DLIST_START ) {
            ptr = skip_blank( ptr + 1 );
            if( *ptr != '\0' ) {
                /* due to a weakness in GML, the definition term must be
                   allowed on the same line as the definition tag. So
                   if its there, continue */
                break;
            }
        }
        return( alloc_size );

    case CH_DLIST_TERM:
        Curr_indent -= Text_Indent;
        break;

    case CH_SLIST_START:
        indent = 0;
        if( Curr_list->type == LIST_TYPE_SIMPLE ) {
            /* nested simple lists, with no pre-indent. Force an
               indent */
            indent = Text_Indent;
        }

        new_list( LIST_TYPE_SIMPLE );
        set_compact( ptr );
        Curr_indent += indent;
        return( alloc_size );

    case CH_SLIST_END:
    case CH_OLIST_END:
    case CH_LIST_END:
    case CH_DLIST_END:
        pop_list();
        return( alloc_size );

    case CH_DLIST_DESC:
        Curr_indent += Text_Indent;
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            /* no description on this line. Ignore it so that no
               blank line gets generated */
            return( alloc_size );
        }
        break;

    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    // skip preceding blank lines
    if( *skip_blank( ptr ) == '\0' && Curr_ctx->empty ) {
        return( alloc_size );
    }

    // remove '\n' on the end
    if( Blank_line ) {
        --section->section_size;
    }

    // indent properly if the first char is not white-space
    if( ch != '\0' && ch != ' ' && ch != '\t') {
        ctr = ( ch == CH_LIST_ITEM && !Box_Mode &&
                        Curr_list->type != LIST_TYPE_SIMPLE )
                ? Text_Indent
                : 0;
        while( ctr < Curr_indent ) {
            ctr++;
            trans_add_char_wrap( ' ', section, &alloc_size);
        }

        if( Box_Mode ) {
            trans_add_char_wrap( BOX_VBAR, section, &alloc_size);
            trans_add_char_wrap( ' ', section, &alloc_size);
        }
    }

    Blank_line = TRUE;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch != '\0' && ( ch != ' ' || ch != '\t' ) ) {
            Blank_line = FALSE;
        }
        if( ch == '\0' ) {
            // this just shuts off bolding after a def. list term
            if( Line_postfix == LPOSTFIX_TERM ) {
                Line_postfix = LPOSTFIX_NONE;
                trans_add_str( STR_BOLD_OFF, section, &alloc_size );
            }
            trans_add_char_wrap( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN || ch == CH_FLINK ) {
            Curr_ctx->empty = FALSE;
            if( ch == CH_FLINK ) {
                file_name = strchr( ptr + 1, ch );
                if( file_name == NULL ) {
                    error( ERR_BAD_LINK_DFN, TRUE );
                }
                *file_name = '\0';
            } else {
                file_name = ptr;
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_name = '\0';

            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_text = '\0';

            ctx_text = ctx_name + 1;
            ctx_name = file_name + 1;
            file_name = ptr + 1;
            if( ch != CH_FLINK ) {
                add_link( ctx_name );
            }

            ptr = ctx_text + strlen( ctx_text ) + 1;

            // Definition pop-up's are converted to hyper-links in InfoBench
            trans_add_char( CHR_TEMP_HLINK , section, &alloc_size );

            // Add line number to hyperlink so we can give meaningful errors
            trans_add_str( itoa( Line_num, buf, 10 ), section, &alloc_size );
            trans_add_char( CHR_TEMP_HLINK, section, &alloc_size );

            // We don't want links to break as IB doesn't like this...
            to_nobreak( ctx_text );

            indent = Curr_indent;
            if( indent < 0 )
                indent = 0;
            // find out the maximum allowed length for hyper-link text:
            ctr = Right_Margin - indent - ( ( Hyper_Brace_L == '<' ) ? 2 : 0 );

            // if the link name is too long then we warn & truncate it
            if( strlen( ctx_text ) > ctr ) {
                warning( "Hyperlink name too long", Line_num );
                ctx_text[ ctr ] = '\0';
            }

            /* If hyper-link bracing is on we have to do a kludge to fix
             * the spacing. The "XX" will make the wrap routine happy.
             * They're stripped off when it comes time to write the file.
             */
            if( Hyper_Brace_L == '<' ) {
                trans_add_str_wrap( "XX", section, &alloc_size );
            }
            trans_add_str_wrap( ctx_text, section, &alloc_size );
            trans_add_char( CHR_HLINK_BREAK , section, &alloc_size );
            trans_add_str( ctx_name, section, &alloc_size );
            if( ch == CH_FLINK ) {
                trans_add_char( CHR_HLINK_BREAK, section, &alloc_size );
                trans_add_str( file_name, section, &alloc_size );
            }
            trans_add_char( CHR_TEMP_HLINK , section, &alloc_size );
        } else if( ch == CH_LIST_ITEM ) {
            if( Curr_list->type != LIST_TYPE_SIMPLE ) {
                if( Curr_list->type == LIST_TYPE_UNORDERED ) {
                    // generate a bullet, correctly spaced for tab size
                    buf[0] = '\0';
                    for( ctr = 1; ctr <= Text_Indent; ctr++)
                    {
                        strcat( buf, " " );
                    }
                    buf[ Text_Indent / 2 - 1 ] = CHR_BULLET;
                } else if( Curr_list->type == LIST_TYPE_ORDERED ) {
                    /* ordered list type */
                    sprintf( buf, "%*d. ", Text_Indent - 2,
                                                        Curr_list->number );
                    ++Curr_list->number;
                }
                trans_add_str_wrap( buf, section, &alloc_size );
            }
            Eat_blanks = TRUE;
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            trans_add_str( STR_BOLD_ON, section, &alloc_size );
            Line_postfix = LPOSTFIX_TERM;
            ptr = skip_blank( ptr + 1 );
            Eat_blanks = TRUE;
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[end - ptr - 1] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords are
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            // we ignore paragraph resets
            ++ptr;
        } else if( ch == CH_BMP ) {
            // we ignore bitmaps
            ptr = strchr( ptr + 3, CH_BMP ) + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {

                // bold and italic map to bold
                case 'b':
                case 'i':
                    trans_add_str( STR_BOLD_ON, section, &alloc_size );
                    break;

                // underline and underscore map to underline
                case 'u':
                case 's':
                    trans_add_str( STR_UNDERLINE_ON, section, &alloc_size );
                    break;
                }
            }
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            // reset style (bold off, underline off)
            trans_add_str( Reset_Style, section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            // we basically ignore font type changes
            ptr = strchr( strchr( ptr + 1 , CH_FONTTYPE ) + 1,
                            CH_FONTTYPE ) + 1;
        } else {
            ++ptr;
            if( !Eat_blanks || ch != ' ' ) {
                Curr_ctx->empty = FALSE;

                if( Tab_xmp && ch == Tab_xmp_char ) {
                    tab_align( section, &alloc_size );
                    ptr = skip_blank( ptr );
                } else {
                    trans_add_char_wrap( ch, section, &alloc_size );
                }

                Eat_blanks = FALSE;
            }
        }
    }

    return( alloc_size );
}
예제 #23
0
int ipf_trans_line(
/*****************/

    section_def         *section,
    int                 alloc_size
) {
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[500];
    int                 font_idx;
    int                 line_len;
    bool                term_fix;
    int                 ch_len;
    int                 len;
    char                *file_name;

    /* check for special column 0 stuff first */
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;
    ch_len = 0;
    line_len = 0;

    switch( ch ) {
    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
            trans_add_str( ":exmp.\n", section, &alloc_size );
            Blank_line_sfx = FALSE;     // remove following blanks
        } else {
            read_tabs( ptr + 1 );
            trans_add_str( ":xmp.\n", section, &alloc_size );
            Tab_xmp = TRUE;
            Blank_line_pfx = FALSE;     // remove preceding blanks
        }
        return( alloc_size );

    case CH_BOX_ON:
        /* Table support is the closest thing to boxing in IPF, but it
           doesn't work well with changing fonts on items in the tables
           (the edges don't line up). So we draw long lines at the
           top and bottom instead */
        draw_line( section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_BOX_OFF:
        draw_line( section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_START:
        trans_add_list( ":ol", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_LIST_START:
        trans_add_list( ":ul", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_DLIST_START:
        trans_add_str( ":dl break=all tsize=5.\n", section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_START:
        trans_add_list( ":sl", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_END:
        trans_add_str( ":esl.\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_END:
        trans_add_str( ":eol.\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_END:
        trans_add_str( ":eul.\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_DLIST_END:
        trans_add_str( ":edl.\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_ITEM:
    case CH_DLIST_TERM:
        /* eat blank lines before list items and terms */
        Blank_line_pfx = FALSE;
        break;

    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    if( *skip_blank( ptr ) == '\0' ) {
        /* ignore blanks lines before the topic starts */
        if( !Curr_ctx->empty ) {
            /* the line is completely blank. This tells us to output
               a blank line. BUT, all lists and things automatically
               generate blank lines before they display, so we
               must pend the line */
            Blank_line_pfx = TRUE;
        }
        return( alloc_size );
    }

    /* An explanation of 'Blank_line_pfx': when we hit a blank line,
       we set Blank_line_pfx to TRUE. On the non-tag next line, the
       blank line is generated.
       Some tags automatically generate a blank line, so they
       turn this flag off. This causes the next non-tag line to NOT
       put out the blank line */

    if( Blank_line_pfx ) {
        if( Blank_line_sfx ) {
            line_len += trans_add_str( ".br\n", section, &alloc_size );
        }
        Blank_line_pfx = FALSE;
    }

    /* An explanation of 'Blank_line_sfx': some ending tags automatically
       generate a blank line, so no blank line after them should get
       generated. Normally, this flag is set to TRUE, but ending
       tags and Defn list term tags set this FALSE, so no extra '.br'
       is generated.
       But, this rule only applies if a blank line immediately
       follows the tag, so its reset here regardless */

    Blank_line_sfx = TRUE;

    ch = *(unsigned char *)ptr;
    if( ch != CH_LIST_ITEM && ch != CH_DLIST_TERM && ch != CH_DLIST_DESC && !Tab_xmp ) {
        /* a .br in front of li and dt would generate extra spaces */
        line_len += trans_add_str( ".br\n", section, &alloc_size );
    }

    term_fix = FALSE;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch == '\0' ) {
            if( term_fix ) {
                trans_add_str( ":ehp2.", section, &alloc_size );
                term_fix = FALSE;
            }
            trans_add_char( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN ) {
            Curr_ctx->empty = FALSE;
            /* there are no popups in IPF, so treat them as links */
            ctx_name = ptr + 1;
            ptr = strchr( ptr + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            ctx_text = ptr + 1;
            ptr = strchr( ctx_text + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            add_link( ctx_name );
            sprintf( buf, ":link reftype=hd refid=%s.", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_ipf( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( ":elink.", section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FLINK ) {
            Curr_ctx->empty = FALSE;
            file_name = strchr( ptr + 1, ch );
            if( file_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_text = '\0';
            ctx_text = ctx_name + 1;
            *ctx_name = '\0';
            ctx_name = file_name + 1;
            *file_name = '\0';
            file_name = ptr + 1;
            sprintf( buf, ":link reftype=launch object='view.exe' "
                          "data='%s %s'.", file_name, ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_ipf( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( ":elink.", section, &alloc_size );
            ptr = ctx_text + strlen( ctx_text ) + 1;
        } else if( ch == CH_LIST_ITEM ) {
            /* list item */
            line_len += trans_add_str( ":li.", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            trans_add_str( ":dd.", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            ptr = skip_blank( ptr + 1 );
            if( *(unsigned char *)ptr == CH_FONTSTYLE_START ) {  /* avoid nesting */
                line_len += trans_add_str( ":dt.", section, &alloc_size );
                Blank_line_sfx = FALSE;
            } else {
                line_len += trans_add_str( ":dt.:hp2.", section, &alloc_size );
                term_fix = TRUE;
                Blank_line_sfx = FALSE;
            }
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[end - ptr - 1] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords are
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            /* this can be ignored for IPF */
            ++ptr;
        } else if( ch == CH_BMP ) {
            Curr_ctx->empty = FALSE;
            ++ptr;
            ch = *(unsigned char *)ptr;
            ptr += 2;
            end = strchr( ptr, CH_BMP );
            *end = '\0';
            switch( ch ) {
            case 'i':
                sprintf( buf, ":artwork runin name='%s'.", ptr );
                break;

            case 'l':
                sprintf( buf, ":artwork align=left name='%s'.", ptr );
                break;

            case 'r':
                sprintf( buf, ":artwork align=right name='%s'.", ptr );
                break;

            case 'c':
                sprintf( buf, ":artwork align=center name='%s'.", ptr );
                break;
            }
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            font_idx = 0;
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {

                case 'b':
                    font_idx |= FONT_STYLE_BOLD;
                    break;

                case 'i':
                    font_idx |= FONT_STYLE_ITALIC;
                    break;

                case 'u':
                case 's':
                    font_idx |= FONT_STYLE_UNDERLINE;
                    break;
                }
            }
            line_len += trans_add_str( Font_match[font_idx],
                                                section, &alloc_size );
            Font_list[Font_list_curr] = font_idx;
            ++Font_list_curr;
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            --Font_list_curr;
            line_len += trans_add_str( Font_end[Font_list[Font_list_curr]],
                                                section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            ++ptr;
            end = strchr( ptr, CH_FONTTYPE );
            *end = '\0';
            strcpy( buf, ":font facename=" );

            if( Real_ipf_font ) {
                /* This code supports fonts in the expected
                   manor, but not in the usual IPF way. In IPF, font switching
                   (including sizing) is NEVER done, except to Courier for
                   examples. So, this code is inappropriate */

                if( stricmp( ptr, Fonttype_roman ) == 0 ) {
                    strcat( buf, "'Tms Rmn'" );
                } else if( stricmp( ptr, Fonttype_helv ) == 0 ) {
                    strcat( buf, "Helv" );
                } else {
                    /* Symbol doesn't work,so use courier instead */
                    strcat( buf, "Courier" );
                }
                line_len += trans_add_str( buf, section, &alloc_size );
                ptr = end + 1;
                end = strchr( ptr, CH_FONTTYPE );
                *end = '\0';
                sprintf( buf, " size=%dx10.", atoi( ptr ) );
            } else {
                /* this code turns all font changes to the default system
                   font, except for Courier. This is the normal IPF way */

                strcat( buf, "Courier" );
                if( stricmp( ptr, Fonttype_courier ) == 0 ) {
                    strcat( buf, " size=12x10." );
                } else {
                    /* default system font */
                    strcat( buf, " size=0x0." );
                }
                ptr = end + 1;
                end = strchr( ptr, CH_FONTTYPE );
            }

            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else {
            ++ptr;
            Curr_ctx->empty = FALSE;
            if( Tab_xmp && ch == Tab_xmp_char ) {
                len = tab_align( ch_len, section, &alloc_size );
                ch_len += len;
                line_len += len;
                ptr = skip_blank( ptr );
            } else {
                line_len += trans_add_char_ipf( ch, section, &alloc_size );
                ++ch_len;
            }
            if( line_len > 120 && ch == ' ' && !Tab_xmp ) {
                /* break onto the next line */
                line_len = 0;
                trans_add_char( '\n', section, &alloc_size );
            }
        }
    }

    return( alloc_size );
}
예제 #24
0
파일: ed.c 프로젝트: Crobisaur/busybox
/*
 * Parse a line number argument if it is present.  This is a sum
 * or difference of numbers, '.', '$', 'x, or a search string.
 * Returns TRUE if successful (whether or not there was a number).
 * Returns FALSE if there was a parsing error, with a message output.
 * Whether there was a number is returned indirectly, as is the number.
 * The character pointer which stopped the scan is also returned.
 */
static int getNum(const char **retcp, smallint *retHaveNum, int *retNum)
{
	const char *cp;
	char *endStr, str[USERSIZE];
	int value, num;
	smallint haveNum, minus;

	cp = *retcp;
	value = 0;
	haveNum = FALSE;
	minus = 0;

	while (TRUE) {
		cp = skip_blank(cp);

		switch (*cp) {
			case '.':
				haveNum = TRUE;
				num = curNum;
				cp++;
				break;

			case '$':
				haveNum = TRUE;
				num = lastNum;
				cp++;
				break;

			case '\'':
				cp++;
				if ((*cp < 'a') || (*cp > 'z')) {
					bb_error_msg("bad mark name");
					return FALSE;
				}
				haveNum = TRUE;
				num = marks[*cp++ - 'a'];
				break;

			case '/':
				strcpy(str, ++cp);
				endStr = strchr(str, '/');
				if (endStr) {
					*endStr++ = '\0';
					cp += (endStr - str);
				} else
					cp = "";
				num = searchLines(str, curNum, lastNum);
				if (num == 0)
					return FALSE;
				haveNum = TRUE;
				break;

			default:
				if (!isdigit(*cp)) {
					*retcp = cp;
					*retHaveNum = haveNum;
					*retNum = value;
					return TRUE;
				}
				num = 0;
				while (isdigit(*cp))
					num = num * 10 + *cp++ - '0';
				haveNum = TRUE;
				break;
		}

		value += (minus ? -num : num);

		cp = skip_blank(cp);

		switch (*cp) {
			case '-':
				minus = 1;
				cp++;
				break;

			case '+':
				minus = 0;
				cp++;
				break;

			default:
				*retcp = cp;
				*retHaveNum = haveNum;
				*retNum = value;
				return TRUE;
		}
	}
}
예제 #25
0
BOOL CCmdLineParser::ExpandAbsolute(LPCTSTR lpCmdBegin, LPCTSTR lpExtNames, BOOL bQuotation)
{
	BOOL bResult = FALSE;

	if ( is_absolute_path(lpCmdBegin) )
	{
		//
		// 绝对路径
		// 支持不加引号的命令行如 C:\Program Files\ASUS\Power4 Gear\BatteryLife.exe 1
		//
		TCHAR szCmdBuff[MAX_PATH + 10];
		LPCTSTR lpCmdEnd = NULL, lpCmdEnd_Last = NULL;

		m_szCmd[0] = 0;

		if ( bQuotation )
		{
			lpCmdEnd = _tcschr(lpCmdBegin, _T('\"'));
			if ( fix_path_separator(szCmdBuff, MAX_PATH, lpCmdBegin, lpCmdEnd - lpCmdBegin) &&
				ExpandExtNames(szCmdBuff, lpExtNames)
				)
			{
				MyGetLongPathName(szCmdBuff, m_szCmd, MAX_PATH);

				lpCmdEnd = skip_quotation(lpCmdEnd);
				lpCmdEnd = skip_blank(lpCmdEnd);
			}
		}
		else
		{
			lpCmdEnd = skip_no_blank(lpCmdBegin);
			lpCmdEnd_Last = lpCmdEnd;

			while ( TRUE )
			{
				if ( !fix_path_separator(szCmdBuff, MAX_PATH, lpCmdBegin, lpCmdEnd - lpCmdBegin) )
				{
					break;
				}

				if ( ExpandExtNames(szCmdBuff, lpExtNames) )
				{
					lpCmdEnd_Last = lpCmdEnd;
					MyGetLongPathName(szCmdBuff, m_szCmd, MAX_PATH);
				}

				lpCmdEnd = skip_blank(lpCmdEnd);
				if ( *lpCmdEnd == 0 ) 
				{
					break;
				}

				lpCmdEnd = skip_no_blank(lpCmdEnd);
			}

			lpCmdEnd = lpCmdEnd_Last;
		}

		if ( m_szCmd[0] != 0 )
		{
			ExpandParam(lpCmdEnd);
			bResult = TRUE;
		}
	}

	return bResult;
}
예제 #26
0
int html_trans_line( section_def *section, int alloc_size )
/*********************************************************/
{
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[ 500 ];
    int                 font_idx;
    int                 line_len;
    bool                term_fix;
    int                 ch_len;
    int                 len;
    char                *file_name;

    /* check for special column 0 stuff first */
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;
    ch_len = 0;
    line_len = 0;

    switch( ch ) {
    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
            trans_add_str( "</xmp>\n", section, &alloc_size );
            Blank_line_sfx = FALSE;     // remove following blanks
        } else {
            read_tabs( ptr + 1 );
            trans_add_str( "<xmp>\n", section, &alloc_size );
            Tab_xmp = TRUE;
            Blank_line_pfx = FALSE;     // remove preceding blanks
        }
        return( alloc_size );

    case CH_BOX_ON:
        /* Table support is the closest thing to boxing in IPF, but it
           doesn't work well with changing fonts on items in the tables
           (the edges don't line up). So we draw long lines at the
           top and bottom instead */
        draw_line( section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_BOX_OFF:
        draw_line( section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_START:
        trans_add_list( "<OL>\n", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_LIST_START:
        trans_add_list( "<UL>\n", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_DLIST_START:
        trans_add_str( "<DL>\n", section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_START:
        trans_add_list( "<UL>\n", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_END:
        trans_add_str( "</UL>\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_END:
        trans_add_str( "</OL>\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_END:
        trans_add_str( "</UL>\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_DLIST_END:
        trans_add_str( "</DL>\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_ITEM:
    case CH_DLIST_TERM:
        /* eat blank lines before list items and terms */
        Blank_line_pfx = FALSE;
        break;

    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    if( *skip_blank( ptr ) == '\0' ) {
        /* ignore blanks lines before the topic starts */
        if( !Curr_ctx->empty ) {
            /* the line is completely blank. This tells us to output
               a blank line. BUT, all lists and things automatically
               generate blank lines before they display, so we
               must pend the line */
            Blank_line_pfx = TRUE;
        }
        return( alloc_size );
    }

    /* An explanation of 'Blank_line_pfx': when we hit a blank line,
       we set Blank_line_pfx to TRUE. On the non-tag next line, the
       blank line is generated.
       Some tags automatically generate a blank line, so they
       turn this flag off. This causes the next non-tag line to NOT
       put out the blank line */

    if( Blank_line_pfx ) {
        if( Blank_line_sfx ) {
            line_len += trans_add_str( "<BR>", section, &alloc_size );
        }
        Blank_line_pfx = FALSE;
    }

    /* An explanation of 'Blank_line_sfx': some ending tags automatically
       generate a blank line, so no blank line after them should get
       generated. Normally, this flag is set to TRUE, but ending
       tags and Defn list term tags set this FALSE, so no extra '<BR>'
       is generated.
       But, this rule only applies if a blank line immediately
       follows the tag, so its reset here regardless */

    Blank_line_sfx = TRUE;

    ch = *(unsigned char *)ptr;
    if( ch != CH_LIST_ITEM && ch != CH_DLIST_TERM && ch != CH_DLIST_DESC && !Tab_xmp ) {
        /* a .br in front of li and dt would generate extra spaces */
        line_len += trans_add_str( "<BR>", section, &alloc_size );
    }

    term_fix = FALSE;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch == '\0' ) {
            if( term_fix ) {
//              trans_add_str( "</hp2>", section, &alloc_size );
                term_fix = FALSE;
            }
            trans_add_char( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN ) {
            Curr_ctx->empty = FALSE;
            /* there are no popups in IPF, so treat them as links */
            ctx_name = ptr + 1;
            ptr = strchr( ptr + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            ctx_text = ptr + 1;
            ptr = strchr( ctx_text + 1, ch );
            if( ptr == NULL ) {
              error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            add_link( ctx_name );
            sprintf( buf, "<A HREF=\"#%s\">", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_html( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( "</A>", section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FLINK ) {
            Curr_ctx->empty = FALSE;
            file_name = strchr( ptr + 1, ch );
            if( file_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_text = '\0';
            ctx_text = ctx_name + 1;
            *ctx_name = '\0';
            ctx_name = file_name + 1;
            *file_name = '\0';
            file_name = ptr + 1;
            sprintf( buf, "<A HREF=\"#%s\">", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_html( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( "</A>", section, &alloc_size );
            ptr = ctx_text + strlen( ctx_text ) + 1;
        } else if( ch == CH_LIST_ITEM ) {
            /* list item */
            line_len += trans_add_str( "<LI>", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            trans_add_str( "<DD>", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            line_len += trans_add_str( "<DT>", section, &alloc_size );
            term_fix = TRUE;
            ptr = skip_blank( ptr + 1 );
            Blank_line_sfx = FALSE;
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[ end - ptr - 1 ] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords are
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            /* this can be ignored for IPF */
            ++ptr;
        } else if( ch == CH_BMP ) {
            Curr_ctx->empty = FALSE;
            ++ptr;
            ch = *(unsigned char *)ptr;
            ptr += 2;
            end = strchr( ptr, CH_BMP );
            *end = '\0';
           // convert filenames to lower case
           strlwr( ptr );
           switch( ch ) {
            case 'i':
                sprintf( buf, "<IMG SRC=\"%s\">", ptr );
                break;

            case 'l':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=TOP>", ptr );
                break;

            case 'r':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=BOTTOM>", ptr );
                break;

            case 'c':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=MIDDLE>", ptr );
                break;
            }
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            font_idx = 0;
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {
                case 'b':
                    font_idx |= FONT_STYLE_BOLD;
                    break;

                case 'i':
                    font_idx |= FONT_STYLE_ITALIC;
                    break;

                case 'u':
                case 's':
                    font_idx |= FONT_STYLE_UNDERLINE;
                    break;
                }
            }
            line_len += trans_add_str( Font_match[ font_idx ], section, &alloc_size );
            Font_list[ Font_list_curr ] = font_idx;
            ++Font_list_curr;
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            --Font_list_curr;
            line_len += trans_add_str( Font_end[ Font_list[ Font_list_curr ] ], section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            ++ptr;
            end = strchr( ptr, CH_FONTTYPE );
            *end = '\0';

            if( stricmp( ptr, Fonttype_courier ) == 0 ) {
               strcpy( buf, "<TT>" );
            } else {
               /* default system font */
               strcpy( buf, "</TT>" );
            }
            ptr = end + 1;
            end = strchr( ptr, CH_FONTTYPE );
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else {
            ++ptr;
            Curr_ctx->empty = FALSE;
            if( Tab_xmp && ch == Tab_xmp_char ) {
                len = tab_align( ch_len, section, &alloc_size );
                ch_len += len;
                line_len += len * sizeof( HTML_SPACE );
                ptr = skip_blank( ptr );
            }
            if( line_len > 120 && ch == ' ' && !Tab_xmp ) {
                /* break onto the next line */
                line_len = 0;
                trans_add_char( '\n', section, &alloc_size );
                if( *ptr == ' ' ) {
                    line_len += trans_add_str( HTML_SPACE, section, &alloc_size );
                    ++ch_len;
                    ptr++;
                }
            } else {
                line_len += trans_add_char_html( ch, *(unsigned char *)ptr, section, &alloc_size );
                ++ch_len;
            }
        }
    }

    return( alloc_size );
}
예제 #27
0
/*
 * Read and parse the next line from {fs,m}tab or mountinfo
 */
static int mnt_table_parse_next(struct libmnt_table *tb, FILE *f,
				struct libmnt_fs *fs,
				const char *filename, int *nlines)
{
	char buf[BUFSIZ];
	char *s;
	int rc;

	assert(tb);
	assert(f);
	assert(fs);

	/* read the next non-blank non-comment line */
next_line:
	do {
		if (fgets(buf, sizeof(buf), f) == NULL)
			return -EINVAL;
		++*nlines;
		s = strchr (buf, '\n');
		if (!s) {
			/* Missing final newline?  Otherwise an extremely */
			/* long line - assume file was corrupted */
			if (feof(f)) {
				DBG(TAB, mnt_debug_h(tb,
					"%s: no final newline",	filename));
				s = strchr (buf, '\0');
			} else {
				DBG(TAB, mnt_debug_h(tb,
					"%s:%d: missing newline at line",
					filename, *nlines));
				goto err;
			}
		}

		/* comments parser */
		if (tb->comms
		    && (tb->fmt == MNT_FMT_GUESS || tb->fmt == MNT_FMT_FSTAB)
		    && is_comment_line(buf)) {
			do {
				rc = append_comment(tb, fs, buf, feof(f));
				if (!rc)
					rc = next_comment_line(buf,
							sizeof(buf),
							f, &s, nlines);
			} while (rc == 0);

			if (rc == 1 && feof(f))
				rc = append_comment(tb, fs, NULL, 1);
			if (rc < 0)
				return rc;

		}

		*s = '\0';
		if (--s >= buf && *s == '\r')
			*s = '\0';
		s = (char *) skip_blank(buf);
	} while (*s == '\0' || *s == '#');

	if (tb->fmt == MNT_FMT_GUESS) {
		tb->fmt = guess_table_format(s);
		if (tb->fmt == MNT_FMT_SWAPS)
			goto next_line;			/* skip swap header */
	}

	switch (tb->fmt) {
	case MNT_FMT_FSTAB:
		rc = mnt_parse_table_line(fs, s);
		break;
	case MNT_FMT_MOUNTINFO:
		rc = mnt_parse_mountinfo_line(fs, s);
		break;
	case MNT_FMT_UTAB:
		rc = mnt_parse_utab_line(fs, s);
		break;
	case MNT_FMT_SWAPS:
		if (strncmp(s, "Filename\t", 9) == 0)
			goto next_line;			/* skip swap header */
		rc = mnt_parse_swaps_line(fs, s);
		break;
	default:
		rc = -1;	/* unknown format */
		break;
	}

	if (rc == 0)
		return 0;
err:
	DBG(TAB, mnt_debug_h(tb, "%s:%d: %s parse error", filename, *nlines,
				tb->fmt == MNT_FMT_MOUNTINFO ? "mountinfo" :
				tb->fmt == MNT_FMT_SWAPS ? "swaps" :
				tb->fmt == MNT_FMT_FSTAB ? "tab" : "utab"));

	/* by default all errors are recoverable, otherwise behavior depends on
	 * the errcb() function. See mnt_table_set_parser_errcb().
	 */
	return tb->errcb ? tb->errcb(tb, filename, *nlines) : 1;
}
예제 #28
0
static int parse_line( char * buf, int * from, int * to, char * op, int * val, int * mod )
{
    char *s;
    int ret = 0, ina = 0;

    s = buf;
    while( *s != '\0' )
    {
        switch( *s )
        {
        case '\t':
            *s = ' ';
            break;
        case '\'':
            ina ^= 1;
            if( ina )
                ++s;
            break;
        case '\n':
        case '\r':
        case '#':
            *s = '\0';
            break;
        }
        if( *s != '\0' )
            ++s;
    }

    s = buf;
    skip_blank( &s );

    if( *s == '@' )
    {
        char *s2;
        ++s;
        s2 = buf;
        while( *s != '\0' && *s != ' ' )
            *s2++ = *s++;
        *s2 = '\0';
        ret = strlen( buf ) > 0 ? 2 : -1;
    }
    else if( *s != '\0' )
    {
        ret = *from = *to = *val = *mod = -1;
        *op = '=';

        *from = get_val( &s );
        if( *from >= 0 )
        {
            if( *s == '-' )
            {
                ++s;
                *to = get_val( &s );
            }
            else
                *to = *from;
        }

        if( *to >= 0 && *s == ':' && s[ 1 ] == ' ' )
        {
            ++s;
            skip_blank( &s );
            if( *s == '*' && ( s[ 1 ] == '+' || s[ 1 ] == '-' || s[ 1 ] == '&' ||
                               s[ 1 ] == '|' || s[ 1 ] == '^' || s[ 1 ] == '=' ||
                               s[ 1 ] == ' ' ) )
            {
                *op = s[ 1 ];
                s += 2;
            }
            *val = *op == ' ' ? 0 : get_val( &s );
            if( *val >= 0 )
            {
                skip_blank( &s );
                *mod = get_val( &s );
                skip_blank( &s );
                if( *mod >= 0 && *mod <= 5 && *s == '\0' )
                    ret = 1;
            }
        }
    }
    return ret;
}