* Copyright 1995 Matthias Ettrich
* Copyright 1995-1999 The LyX Team.
*
- * ======================================================*/
+ * ====================================================== */
#ifndef FILE_INFO_H
#define FILE_INFO_H
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
#ifndef LISTREAM_H
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
#ifndef LOSTREAM_H
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1998 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
#ifdef HAVE_CONFIG_H
#include <config.h>
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1998 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
// This one is heavily based on the substring class in The C++
// Programming Language by Bjarne Stroustrup
LRegex.h \
LSubstring.C \
LSubstring.h \
+ block.h \
filetools.C \
filetools.h \
lstrings.C \
--- /dev/null
+// -*- C++ -*-
+
+#ifndef BLOCK_H
+#define BLOCK_H
+
+#include "LAssert.h"
+
+template <class T, size_t s>
+class block {
+public:
+ typedef T value_type;
+ typedef size_t size_type;
+ typedef value_type * pointer;
+ typedef value_type const * const_pointer;
+ typedef value_type & reference;
+ typedef value_type const & const_reference;
+ typedef value_type * iterator;
+ typedef value_type const * const_iterator;
+ size_type size() const { return s; }
+ reference operator[](int i) { return arr[i]; }
+ const_reference operator[](int i) const { return arr[i]; }
+ void operator=(block const & b) {
+ Assert(b.size() == size());
+ for (size_t i = 0; i < size(); ++i) {
+ arr[i] == b[i];
+ }
+ }
+ bool operator==(block const & b) const {
+ Assert(b.size() == size());
+ for (size_t i = 0; i < size(); ++i) {
+ if (arr[i] != b[i]) return false;
+ }
+ return true;
+ }
+ iterator begin() { return arr[0]; }
+ iterator end() { return arr[s]; }
+ const_iterator begin() const { return arr[0]; }
+ const_iterator end() const { return arr[s]; }
+private:
+ value_type arr[s + 1];
+};
+
+#endif // BLOCK_H_
// a short string...
string ret;
FileInfo fnfo;
- for (int a='a'; a<= 'z'; ++a)
- for (int b='a'; b<= 'z'; ++b)
- for (int c='a'; c<= 'z'; ++c) {
+ for (int a= 'a'; a<= 'z'; ++a)
+ for (int b= 'a'; b<= 'z'; ++b)
+ for (int c= 'a'; c<= 'z'; ++c) {
// if this is not enough I have no idea what
// to do.
ret = tmpfl + char(a) + char(b) + char(c);
while (notfound && !path_element.empty()) {
path_element = CleanupPath(path_element);
if (!suffixIs(path_element, '/'))
- path_element+='/';
+ path_element+= '/';
path_element = subst(path_element, "$$LyX", system_lyxdir);
path_element = subst(path_element, "$$User", user_lyxdir);
string LibFileSearch(string const & dir, string const & name,
string const & ext)
{
- string fullname = FileSearch(AddPath(user_lyxdir,dir), name,
+ string fullname = FileSearch(AddPath(user_lyxdir, dir), name,
ext);
if (!fullname.empty())
return fullname;
if (!fullname.empty())
return fullname;
- return FileSearch(AddPath(system_lyxdir,dir), name, ext);
+ return FileSearch(AddPath(system_lyxdir, dir), name, ext);
}
}
while ((de = readdir(dir))) {
string temp = de->d_name;
- if (temp=="." || temp=="..")
+ if (temp == "." || temp == "..")
continue;
string unlinkpath = AddName (path, temp);
// checks for already absolute path
if (AbsolutePath(RelPath))
#ifdef __EMX__
- if(RelPath[0]!='/' && RelPath[0]!='\\')
+ if(RelPath[0]!= '/' && RelPath[0]!= '\\')
#endif
return RelPath;
// Split by next /
RTemp = split(RTemp, Temp, '/');
- if (Temp==".") continue;
- if (Temp=="..") {
+ if (Temp == ".") continue;
+ if (Temp == "..") {
// Remove one level of TempBase
int i = TempBase.length()-2;
#ifndef __EMX__
#ifndef __EMX__
return (!path.empty() && path[0] == '/');
#else
- return (!path.empty() && (path[0]=='/' || (isalpha(static_cast<unsigned char>(path[0])) && path.length()>1 && path[1]==':')));
+ return (!path.empty() && (path[0] == '/' || (isalpha(static_cast<unsigned char>(path[0])) && path.length()>1 && path[1] == ':')));
#endif
}
string copy(RTemp);
// Split by next /
- RTemp=split(RTemp, Temp, '/');
+ RTemp= split(RTemp, Temp, '/');
- if (Temp==".") {
+ if (Temp == ".") {
return GetCWD() + '/' + RTemp;
- } else if (Temp=="~") {
+ } else if (Temp == "~") {
return GetEnvPath("HOME") + '/' + RTemp;
- } else if (Temp=="..") {
+ } else if (Temp == "..") {
return MakeAbsPath(copy);
} else
// Don't know how to handle this
// Split by next /
RTemp = split(RTemp, Temp, '/');
- if (Temp==".") {
+ if (Temp == ".") {
TempBase = "./";
- } else if (Temp=="..") {
+ } else if (Temp == "..") {
// Remove one level of TempBase
int i = TempBase.length()-2;
while (i>0 && TempBase[i] != '/')
--i;
- if (i>=0 && TempBase[i] == '/')
+ if (i>= 0 && TempBase[i] == '/')
TempBase.erase(i+1, string::npos);
else
TempBase = "../";
// Search Environmentvariable
// if found: Replace Strings
//
- const char CompareChar = '$';
- const char FirstChar = '{';
- const char EndChar = '}';
- const char UnderscoreChar = '_';
+ char const CompareChar = '$';
+ char const FirstChar = '{';
+ char const EndChar = '}';
+ char const UnderscoreChar = '_';
string EndString; EndString += EndChar;
string FirstString; FirstString += FirstChar;
string CompareString; CompareString += CompareChar;
- const string RegExp("*}*"); // Exist EndChar inside a String?
+ string const RegExp("*}*"); // Exist EndChar inside a String?
// first: Search for a '$' - Sign.
//string copy(path);
continue;
}
// check contents of res1
- const char * res1_contents = res1.c_str();
+ char const * res1_contents = res1.c_str();
if (*res1_contents != FirstChar) {
// Again No Environmentvariable
result1 += CompareString;
// Check for variable names
// Situation ${} is detected as "No Environmentvariable"
- const char * cp1 = res1_contents+1;
+ char const * cp1 = res1_contents+1;
bool result = isalpha(*cp1) || (*cp1 == UnderscoreChar);
++cp1;
while (*cp1 && result) {
// Go back to last /
if (i < abslen && i < baselen
- || (i<abslen && abspath[i] != '/' && i==baselen)
- || (i<baselen && basepath[i] != '/' && i==abslen))
+ || (i<abslen && abspath[i] != '/' && i == baselen)
+ || (i<baselen && basepath[i] != '/' && i == abslen))
{
if (i) --i; // here was the last match
while (i && abspath[i] != '/') --i;
string ext;
// Make sure the extension starts with a dot
if (!extension.empty() && extension[0] != '.')
- ext='.' + extension;
+ ext= '.' + extension;
else
ext = extension;
string ret_str;
char LinkBuffer[512];
// Should be PATH_MAX but that needs autconf support
int nRead;
- nRead = readlink(File.c_str(), LinkBuffer,sizeof(LinkBuffer)-1);
+ nRead = readlink(File.c_str(), LinkBuffer, sizeof(LinkBuffer)-1);
if (nRead <= 0)
return false;
LinkBuffer[nRead] = 0;
/// automatic converson to FILE* if that is needed.
operator FILE*() { return p; }
///
- FilePtr & operator=(FILE * f) { p=f; return *this;}
+ FilePtr & operator=(FILE * f) { p= f; return *this;}
///
FILE * operator()() { return p; }
private:
// Should probably be rewritten to use open(2)
if((p = fopen(name.c_str(), modestr.c_str()))) {
// file succesfully opened.
- if (fcntl(fileno(p),F_SETFD,FD_CLOEXEC) == -1) {
+ if (fcntl(fileno(p), F_SETFD, FD_CLOEXEC) == -1) {
p = 0;
}
} else {
/** Creates a nice compact path for displaying. The parameter
threshold, if given, specifies the maximal length of the path.
*/
-string MakeDisplayPath(string const & path, unsigned int threshold=1000);
+string MakeDisplayPath(string const & path, unsigned int threshold= 1000);
/** Makes relative path out of absolute path.
If it is deeper than basepath,
while (!str.empty()) {
str = split(str, tmptok, delim);
- if (tok==tmptok)
+ if (tok == tmptok)
return i;
++i;
}
if (a.empty())
return false;
- string::size_type si=0, pi=0;
+ string::size_type si= 0, pi= 0;
string::size_type const sl = a.length();
string::size_type const pl = pattern.length();
while (si < sl && pi < pl) {
- if (pattern[pi]=='*') {
+ if (pattern[pi] == '*') {
// Skip all consequtive *s
while (pattern[pi] == '*') {
++pi;
return false;
si += chunk.length()-1;
pi += chunk.length();
- if (si==sl && pi==pl-1)
+ if (si == sl && pi == pl-1)
return true;
}
} else if (a[si++] != pattern[pi++]) {
The leading string up to delim is returned in piece (not including
delim), while the original string is cut from after the delimiter.
Example:
- #s1=""; s2="a;bc".split(s1, ';') -> s1=="a"; s2 == "bc";#
+ #s1= ""; s2= "a;bc".split(s1, ';') -> s1 == "a"; s2 == "bc";#
*/
string split(string const & a, string & piece, char delim);
// -*- C++ -*-
/* This file is part of
- * ======================================================
+ * ======================================================
*
* LyX, The Document Processor
*
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
- * ======================================================*/
+ * ====================================================== */
#ifndef LYX_LIB_H
#define LYX_LIB_H
inline char * date()
{
time_t tid;
- if ((tid=time(0)) == (time_t)-1)
+ if ((tid= time(0)) == (time_t)-1)
return (char*)0;
else
return (ctime(&tid));
return ::_getcwd2(buffer, size);
#endif
};
- static int chdir(const char * name) {
+ static int chdir(char const * name) {
#ifndef __EMX__
return ::chdir(name);
#else
/* This file is part of
- * ======================================================
+ * ======================================================
*
* LyX, The Document Processor
*
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
- * ======================================================*/
+ * ====================================================== */
#ifdef HAVE_CONFIG_H
#include <config.h>
lyxstring::Srep::Srep(lyxstring::size_type nsz, const value_type * p)
{
-// can be called with p==0 by lyxstring::assign(const value_type *, size_type)
+// can be called with p == 0 by lyxstring::assign(const value_type *, size_type)
sz = nsz;
ref = 1;
void lyxstring::Srep::assign(lyxstring::size_type nsz, const value_type * p)
{
-// can be called with p==0 by lyxstring::assign(const value_type *, size_type)
+// can be called with p == 0 by lyxstring::assign(const value_type *, size_type)
if (res < nsz) {
delete[] s;
void lyxstring::Srep::replace(lyxstring::size_type i, lyxstring::size_type n,
value_type const * p, size_type n2)
{
-// can be called with p=0 and n2=0
+// can be called with p= 0 and n2= 0
n = min(sz - i, n);
sz -= n;
if (res >= n2 + sz) {
Assert(object->rep->res); // always some space allocated
Assert(object->rep->sz <= object->rep->res);
Assert(object->rep->ref >= 1); // its in use so it must be referenced
- Assert(object->rep->ref < static_cast<size_t>(1) << (8 * sizeof(object->rep->ref) - 1));
+ Assert(object->rep->ref < 1UL << (8UL * sizeof(object->rep->ref) - 1));
// if it does ever == then we should be generating a new copy
// and starting again. (Is char always 8-bits?)
}
// Assignment
////////////////
-lyxstring & lyxstring::operator=(lyxstring const & x)
+lyxstring & lyxstring::operator= (lyxstring const & x)
{
TestlyxstringInvariant(this);
}
-lyxstring & lyxstring::operator=(value_type const * s)
+lyxstring & lyxstring::operator= (value_type const * s)
{
Assert(s); // OURS!
TestlyxstringInvariant(this);
-// printf("lyxstring::operator=(value_type const *)\n");
+// printf("lyxstring::operator= (value_type const *)\n");
return assign(s);
}
{
if ((rep->sz == 0 || n == 0) && (!*s || n2 == 0)) return 0;
if (!*s) return 1;
- // since n > n2, min(n,n2) == 0, c == 0 (stops segfault also)
+ // since n > n2, min(n, n2) == 0, c == 0 (stops segfault also)
// remember that n can very well be a lot larger than rep->sz
// so we have to ensure that n is no larger than rep->sz
n2 = min(n2, slen);
if (n == n2)
return memcmp(&(rep->s[pos]), s, n);
- int c = memcmp(&(rep->s[pos]), s, min(n,n2));
+ int c = memcmp(&(rep->s[pos]), s, min(n, n2));
if (c)
return c;
if (n < n2)
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
// This one is heavily based on the string class in The C++
// Programming Language by Bjarne Stroustrup
// replace [(*this)[i], (*this)[i+n]] with other characters:
///
- lyxstring & replace(size_type i,size_type n, lyxstring const & str);
+ lyxstring & replace(size_type i, size_type n, lyxstring const & str);
///
- lyxstring & replace(size_type i,size_type n, lyxstring const & s,
+ lyxstring & replace(size_type i, size_type n, lyxstring const & s,
size_type i2, size_type n2);
///
- lyxstring & replace(size_type i,size_type n, value_type const * p,
+ lyxstring & replace(size_type i, size_type n, value_type const * p,
size_type n2);
///
- lyxstring & replace(size_type i,size_type n, value_type const * p);
+ lyxstring & replace(size_type i, size_type n, value_type const * p);
///
lyxstring & replace(size_type i, size_type n,
*
* Modified for use in LyX by Lars G. Bjønnes.
*
- *======================================================
+ * ======================================================
*/
{
SystemcallsSingletoncontroller::Startcontroller starter;
- SystemcallsSingletoncontroller *contr=starter.GetController();
+ SystemcallsSingletoncontroller *contr= starter.GetController();
Systemcalls one(Systemcalls::System, "ls -ltag", back);
Systemcalls two(Systemcalls::Wait, "ls -ltag", back);
SystemcallsSingletoncontroller::timer() {
// check each entry of our list, if it's finished
ControlledCalls *prev = 0;
- for (ControlledCalls *actCall=sysCalls; actCall; actCall=actCall->next)
+ for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next)
{
- pid_t pid=actCall->call->getpid();
+ pid_t pid= actCall->call->getpid();
int stat_loc;
int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
if (waitrpid == -1) {
*
* Copyright (C) 1995 Matthias Ettrich
*
- *======================================================*/
-#ifndef _TEXTUTILS_H
-#define _TEXTUTILS_H
+ * ====================================================== */
-#include "definitions.h"
+#ifndef TEXTUTILS_H
+#define TEXTUTILS_H
+
+#include <cctype>
///
inline bool IsNewlineChar(char c) {
- return (c == LYX_META_NEWLINE);
+ return (c == LyXParagraph::META_NEWLINE);
}
+
+
///
inline bool IsSeparatorChar(char c) {
- return (c == ' ' || c == LYX_META_PROTECTED_SEPARATOR);
+ return (c == ' ' || c == LyXParagraph::META_PROTECTED_SEPARATOR);
}
+
+
///
inline bool IsHfillChar(char c) {
- return (c == LYX_META_HFILL);
+ return (c == LyXParagraph::META_HFILL);
}
+
+
///
inline bool IsInsetChar(char c) {
- return (c == LYX_META_INSET);
+ return (c == LyXParagraph::META_INSET);
}
+
+
///
inline bool IsFloatChar(char c) {
- return (c == LYX_META_FOOTNOTE
- || c == LYX_META_MARGIN
- || c == LYX_META_FIG
- || c == LYX_META_TAB
- || c == LYX_META_ALGORITHM
- || c == LYX_META_WIDE_FIG
- || c == LYX_META_WIDE_TAB);
+ return (c == LyXParagraph::META_FOOTNOTE
+ || c == LyXParagraph::META_MARGIN
+ || c == LyXParagraph::META_FIG
+ || c == LyXParagraph::META_TAB
+ || c == LyXParagraph::META_ALGORITHM
+ || c == LyXParagraph::META_WIDE_FIG
+ || c == LyXParagraph::META_WIDE_TAB);
}
+
+
///
inline bool IsLineSeparatorChar(char c) {
return (c == ' ');
}
+
+
///
inline bool IsKommaChar(char c) {
return (c == ','
- || c=='('
- || c==')'
- || c=='['
- || c==']'
- || c=='{'
- || c=='}'
- || c==';'
- || c=='.'
- || c==':'
- || c=='-'
- || c=='?'
- || c=='!'
- || c=='&'
- || c=='@'
- || c=='+'
- || c=='-'
- || c=='~'
- || c=='#'
- || c=='%'
- || c=='^'
- || c=='/'
- || c=='\\'
- || c==LYX_META_NEWLINE
- || c==LYX_META_PROTECTED_SEPARATOR
+ || c == '('
+ || c == ')'
+ || c == '['
+ || c == ']'
+ || c == '{'
+ || c == '}'
+ || c == ';'
+ || c == '.'
+ || c == ':'
+ || c == '-'
+ || c == '?'
+ || c == '!'
+ || c == '&'
+ || c == '@'
+ || c == '+'
+ || c == '-'
+ || c == '~'
+ || c == '#'
+ || c == '%'
+ || c == '^'
+ || c == '/'
+ || c == '\\'
+ || c == LyXParagraph::META_NEWLINE
+ || c == LyXParagraph::META_PROTECTED_SEPARATOR
);
}
+
+
///
inline bool IsLetterChar(unsigned char c) {
- return ((c>='A' && c<='Z')
- || (c>='a' && c<='z')
- || (c>=192)); // in iso-8859-x these are accented chars
+ return ((c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z')
+ || (c >= 192)); // in iso-8859-x these are accented chars
}
+
+
///
inline bool IsPrintable(unsigned char c) {
- return (c>=' ');
+ return (c >= ' ');
}
+
+
/// Word is not IsSeparator or IsKomma or IsHfill or IsFloat or IsInset.
inline bool IsWordChar(unsigned char c) {
return !( IsSeparatorChar( c )
- || IsKommaChar( c )
- || IsHfillChar( c )
- || IsFloatChar( c )
- || IsInsetChar( c ) ) ;
+ || IsKommaChar( c )
+ || IsHfillChar( c )
+ || IsFloatChar( c )
+ || IsInsetChar( c ) ) ;
+}
+
+
+///
+inline bool IsLetterCharOrDigit(char ch)
+{
+ return IsLetterChar(ch) || isdigit(ch);
}
#endif