From: Lars Gullik Bjønnes Date: Mon, 15 Nov 1999 10:54:16 +0000 (+0000) Subject: some white-space changes, enum changes because of ridance of definitions.h, block... X-Git-Tag: 1.6.10~22524 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=94a6d7ed67321eb95363230bed0fca990766123b;p=features.git some white-space changes, enum changes because of ridance of definitions.h, block.h added small change in lyxstring.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@311 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/FileInfo.h b/src/support/FileInfo.h index 9093601b1c..614a8b1596 100644 --- a/src/support/FileInfo.h +++ b/src/support/FileInfo.h @@ -7,7 +7,7 @@ * Copyright 1995 Matthias Ettrich * Copyright 1995-1999 The LyX Team. * - * ======================================================*/ + * ====================================================== */ #ifndef FILE_INFO_H #define FILE_INFO_H diff --git a/src/support/LIstream.h b/src/support/LIstream.h index 18be5e8883..0abcb7490d 100644 --- a/src/support/LIstream.h +++ b/src/support/LIstream.h @@ -7,7 +7,7 @@ * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1999 The LyX Team. * - *======================================================*/ + * ====================================================== */ #ifndef LISTREAM_H diff --git a/src/support/LOstream.h b/src/support/LOstream.h index 0dd31d3b1e..2db23aeeba 100644 --- a/src/support/LOstream.h +++ b/src/support/LOstream.h @@ -7,7 +7,7 @@ * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1999 The LyX Team. * - *======================================================*/ + * ====================================================== */ #ifndef LOSTREAM_H diff --git a/src/support/LSubstring.C b/src/support/LSubstring.C index bff2fe8c0c..b2c2ef05de 100644 --- a/src/support/LSubstring.C +++ b/src/support/LSubstring.C @@ -6,7 +6,7 @@ * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1998 The LyX Team. * - *======================================================*/ + * ====================================================== */ #ifdef HAVE_CONFIG_H #include diff --git a/src/support/LSubstring.h b/src/support/LSubstring.h index 44463d3226..96164f11b9 100644 --- a/src/support/LSubstring.h +++ b/src/support/LSubstring.h @@ -7,7 +7,7 @@ * 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 diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 3b13ab6e9a..8bf8629e43 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -20,6 +20,7 @@ libsupport_a_SOURCES = \ LRegex.h \ LSubstring.C \ LSubstring.h \ + block.h \ filetools.C \ filetools.h \ lstrings.C \ diff --git a/src/support/block.h b/src/support/block.h new file mode 100644 index 0000000000..49279b1879 --- /dev/null +++ b/src/support/block.h @@ -0,0 +1,43 @@ +// -*- C++ -*- + +#ifndef BLOCK_H +#define BLOCK_H + +#include "LAssert.h" + +template +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_ diff --git a/src/support/filetools.C b/src/support/filetools.C index c1e82424ab..0865d9dbbc 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -105,9 +105,9 @@ string TmpFileName(string const & dir, string const & mask) // 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); @@ -198,7 +198,7 @@ string FileOpenSearch (string const & path, string const & name, 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); @@ -255,7 +255,7 @@ string FileSearch(string const & path, string const & name, 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; @@ -266,7 +266,7 @@ string LibFileSearch(string const & dir, string const & name, if (!fullname.empty()) return fullname; - return FileSearch(AddPath(system_lyxdir,dir), name, ext); + return FileSearch(AddPath(system_lyxdir, dir), name, ext); } @@ -348,7 +348,7 @@ int DeleteAllFilesInDir (string const & path) } while ((de = readdir(dir))) { string temp = de->d_name; - if (temp=="." || temp=="..") + if (temp == "." || temp == "..") continue; string unlinkpath = AddName (path, temp); @@ -497,7 +497,7 @@ string MakeAbsPath(string const & RelPath, string const & BasePath) // checks for already absolute path if (AbsolutePath(RelPath)) #ifdef __EMX__ - if(RelPath[0]!='/' && RelPath[0]!='\\') + if(RelPath[0]!= '/' && RelPath[0]!= '\\') #endif return RelPath; @@ -534,8 +534,8 @@ string MakeAbsPath(string const & RelPath, string const & BasePath) // 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__ @@ -604,7 +604,7 @@ bool AbsolutePath(string const & path) #ifndef __EMX__ return (!path.empty() && path[0] == '/'); #else - return (!path.empty() && (path[0]=='/' || (isalpha(static_cast(path[0])) && path.length()>1 && path[1]==':'))); + return (!path.empty() && (path[0] == '/' || (isalpha(static_cast(path[0])) && path.length()>1 && path[1] == ':'))); #endif } @@ -623,13 +623,13 @@ string ExpandPath(string const & path) 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 @@ -656,14 +656,14 @@ string NormalizePath(string const & path) // 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 = "../"; @@ -706,14 +706,14 @@ string ReplaceEnvironmentPath(string const & path) // 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); @@ -741,7 +741,7 @@ string ReplaceEnvironmentPath(string const & 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; @@ -750,7 +750,7 @@ string ReplaceEnvironmentPath(string const & path) // 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) { @@ -804,8 +804,8 @@ string MakeRelPath(string const & abspath0, string const & basepath0) // Go back to last / if (i < abslen && i < baselen - || (i s1=="a"; s2 == "bc";# + #s1= ""; s2= "a;bc".split(s1, ';') -> s1 == "a"; s2 == "bc";# */ string split(string const & a, string & piece, char delim); diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index dc0a1cef3c..7fd7616275 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -1,13 +1,13 @@ // -*- 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 @@ -26,7 +26,7 @@ unsigned long lyxsum(char const * file); 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)); @@ -56,7 +56,7 @@ struct lyx { return ::_getcwd2(buffer, size); #endif }; - static int chdir(const char * name) { + static int chdir(char const * name) { #ifndef __EMX__ return ::chdir(name); #else diff --git a/src/support/lyxstring.C b/src/support/lyxstring.C index 21f77ae29d..129cd75746 100644 --- a/src/support/lyxstring.C +++ b/src/support/lyxstring.C @@ -1,12 +1,12 @@ /* 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 @@ -103,7 +103,7 @@ private: 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; @@ -137,7 +137,7 @@ lyxstring::Srep::Srep(lyxstring::size_type nsz, value_type ch) 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; @@ -256,7 +256,7 @@ void lyxstring::Srep::reserve(lyxstring::size_type res_arg) 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) { @@ -349,7 +349,7 @@ void lyxstringInvariant::helper() const 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(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?) } @@ -523,7 +523,7 @@ void lyxstring::reserve(size_type res_arg) // Assignment //////////////// -lyxstring & lyxstring::operator=(lyxstring const & x) +lyxstring & lyxstring::operator= (lyxstring const & x) { TestlyxstringInvariant(this); @@ -531,11 +531,11 @@ lyxstring & lyxstring::operator=(lyxstring const & x) } -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); } @@ -1424,7 +1424,7 @@ int lyxstring::internal_compare(size_type pos, size_type n, { 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 @@ -1432,7 +1432,7 @@ int lyxstring::internal_compare(size_type pos, size_type n, 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) diff --git a/src/support/lyxstring.h b/src/support/lyxstring.h index ec09b96a9f..22e0b88cc3 100644 --- a/src/support/lyxstring.h +++ b/src/support/lyxstring.h @@ -7,7 +7,7 @@ * 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 @@ -415,18 +415,18 @@ public: // 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, diff --git a/src/support/lyxsum.C b/src/support/lyxsum.C index 602da11bbe..3bd9262e98 100644 --- a/src/support/lyxsum.C +++ b/src/support/lyxsum.C @@ -9,7 +9,7 @@ * * Modified for use in LyX by Lars G. Bjønnes. * - *====================================================== + * ====================================================== */ diff --git a/src/support/syscall.C b/src/support/syscall.C index 77521afacd..295785f713 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -209,7 +209,7 @@ int main(int, char**) { 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); diff --git a/src/support/syscontr.C b/src/support/syscontr.C index 51c903a2e0..192ef9058b 100644 --- a/src/support/syscontr.C +++ b/src/support/syscontr.C @@ -66,9 +66,9 @@ void 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) { diff --git a/src/support/textutils.h b/src/support/textutils.h index 73d97cd598..89e1a5cf27 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -6,87 +6,113 @@ * * Copyright (C) 1995 Matthias Ettrich * - *======================================================*/ -#ifndef _TEXTUTILS_H -#define _TEXTUTILS_H + * ====================================================== */ -#include "definitions.h" +#ifndef TEXTUTILS_H +#define TEXTUTILS_H + +#include /// 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