Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clang format #473

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (C) 2016 Olivier Goffart <[email protected]>
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.

# This is the clang-format configuration style to be used by Qt,
# based on the rules from https://wiki.qt.io/Qt_Coding_Style and
# https://wiki.qt.io/Coding_Conventions

---
# Webkit style was loosely based on the Qt style
BasedOnStyle: WebKit

Standard: Cpp11

# Column width is limited to 100 in accordance with Qt Coding Style.
# https://wiki.qt.io/Qt_Coding_Style
# Note that this may be changed at some point in the future.
ColumnLimit: 100
# How much weight do extra characters after the line length limit have.
# PenaltyExcessCharacter: 4

# Disable reflow of qdoc comments: indentation rules are different.
# Translation comments are also excluded.
CommentPragmas: "^!|^:"

# We want a space between the type and the star for pointer types.
PointerBindsToType: false

# We use template< without space.
SpaceAfterTemplateKeyword: false

# We want to break before the operators, but not before a '='.
BreakBeforeBinaryOperators: NonAssignment

# Braces are usually attached, but not after functions or class declarations.
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: true
IndentBraces: false

# When constructor initializers do not fit on one line, put them each on a new line.
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# Indent initializers by 4 spaces
ConstructorInitializerIndentWidth: 4

# Indent width for line continuations.
ContinuationIndentWidth: 8

# No indentation for namespaces.
NamespaceIndentation: None

# Allow indentation for preprocessing directives (if/ifdef/endif). https://reviews.llvm.org/rL312125
IndentPPDirectives: AfterHash

# Horizontally align arguments after an open bracket.
# The coding style does not specify the following, but this is what gives
# results closest to the existing code.
AlignAfterOpenBracket: true
AlwaysBreakTemplateDeclarations: true

# Ideally we should also allow less short function in a single line, but
# clang-format does not handle that.
AllowShortFunctionsOnASingleLine: Inline

# The coding style specifies some include order categories, but also tells to
# separate categories with an empty line. It does not specify the order within
# the categories. Since the SortInclude feature of clang-format does not
# re-order includes separated by empty lines, the feature is not used.
SortIncludes: false

# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ]

# Break constructor initializers before the colon and after the commas.
BreakConstructorInitializers: BeforeColon

# Avoids the addition of a space between an identifier and the
# initializer list in list-initialization.
SpaceBeforeCpp11BracedList: false

84 changes: 42 additions & 42 deletions lib/BlockArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@
#include <unistd.h>
#include <cstdio>


using namespace Konsole;

static int blocksize = 0;

BlockArray::BlockArray()
: size(0),
current(size_t(-1)),
index(size_t(-1)),
lastmap(nullptr),
lastmap_index(size_t(-1)),
lastblock(nullptr), ion(-1),
length(0)
: size(0),
current(size_t(-1)),
index(size_t(-1)),
lastmap(nullptr),
lastmap_index(size_t(-1)),
lastblock(nullptr),
ion(-1),
length(0)
{
// lastmap_index = index = current = size_t(-1);
if (blocksize == 0) {
blocksize = ((sizeof(Block) / getpagesize()) + 1) * getpagesize();
}

}

BlockArray::~BlockArray()
Expand All @@ -59,7 +58,7 @@ BlockArray::~BlockArray()
Q_ASSERT(!lastblock);
}

size_t BlockArray::append(Block * block)
size_t BlockArray::append(Block *block)
{
if (!size) {
return size_t(-1);
Expand Down Expand Up @@ -106,7 +105,7 @@ size_t BlockArray::newBlock()
return index + 1;
}

Block * BlockArray::lastBlock() const
Block *BlockArray::lastBlock() const
{
return lastblock;
}
Expand All @@ -126,7 +125,7 @@ bool BlockArray::has(size_t i) const
return true;
}

const Block * BlockArray::at(size_t i)
const Block *BlockArray::at(size_t i)
{
if (i == index + 1) {
return lastblock;
Expand All @@ -141,17 +140,17 @@ const Block * BlockArray::at(size_t i)
return nullptr;
}

// if (index - i >= length) {
// kDebug(1211) << "BlockArray::at() index - i >= length\n";
// return 0;
// }
// if (index - i >= length) {
// kDebug(1211) << "BlockArray::at() index - i >= length\n";
// return 0;
// }

size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ;

Q_ASSERT(j < size);
unmap();

Block * block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
Block *block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);

if (block == (Block *)-1) {
perror("mmap");
Expand Down Expand Up @@ -183,7 +182,7 @@ bool BlockArray::setSize(size_t newsize)

bool BlockArray::setHistorySize(size_t newsize)
{
// kDebug(1211) << "setHistorySize " << size << " " << newsize;
// kDebug(1211) << "setHistorySize " << size << " " << newsize;

if (size == newsize) {
return false;
Expand All @@ -203,12 +202,13 @@ bool BlockArray::setHistorySize(size_t newsize)
}

if (!size) {
FILE * tmp = tmpfile();
FILE *tmp = tmpfile();
if (!tmp) {
perror("konsole: cannot open temp file.\n");
} else {
}
else {
ion = dup(fileno(tmp));
if (ion<0) {
if (ion < 0) {
perror("konsole: cannot dup temp file.\n");
fclose(tmp);
}
Expand All @@ -228,16 +228,17 @@ bool BlockArray::setHistorySize(size_t newsize)
increaseBuffer();
size = newsize;
return false;
} else {
}
else {
decreaseBuffer(newsize);
ftruncate(ion, length*blocksize);
ftruncate(ion, length * blocksize);
size = newsize;

return true;
}
}

void moveBlock(FILE * fion, int cursor, int newpos, char * buffer2)
void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2)
{
int res = fseek(fion, cursor * blocksize, SEEK_SET);
if (res) {
Expand Down Expand Up @@ -272,40 +273,41 @@ void BlockArray::decreaseBuffer(size_t newsize)
}

// The Block constructor could do somthing in future...
char * buffer1 = new char[blocksize];
char *buffer1 = new char[blocksize];

FILE * fion = fdopen(dup(ion), "w+b");
FILE *fion = fdopen(dup(ion), "w+b");
if (!fion) {
delete [] buffer1;
delete[] buffer1;
perror("fdopen/dup");
return;
}

int firstblock;
if (current <= newsize) {
firstblock = current + 1;
} else {
}
else {
firstblock = 0;
}

size_t oldpos;
for (size_t i = 0, cursor=firstblock; i < newsize; i++) {
for (size_t i = 0, cursor = firstblock; i < newsize; i++) {
oldpos = (size + cursor + offset) % size;
moveBlock(fion, oldpos, cursor, buffer1);
if (oldpos < newsize) {
cursor = oldpos;
} else {
}
else {
cursor++;
}
}

current = newsize - 1;
length = newsize;

delete [] buffer1;
delete[] buffer1;

fclose(fion);

}

void BlockArray::increaseBuffer()
Expand All @@ -320,8 +322,8 @@ void BlockArray::increaseBuffer()
}

// The Block constructor could do somthing in future...
char * buffer1 = new char[blocksize];
char * buffer2 = new char[blocksize];
char *buffer1 = new char[blocksize];
char *buffer2 = new char[blocksize];

int runs = 1;
int bpr = size; // blocks per run
Expand All @@ -331,11 +333,11 @@ void BlockArray::increaseBuffer()
runs = offset;
}

FILE * fion = fdopen(dup(ion), "w+b");
FILE *fion = fdopen(dup(ion), "w+b");
if (!fion) {
perror("fdopen/dup");
delete [] buffer1;
delete [] buffer2;
delete[] buffer1;
delete[] buffer2;
return;
}

Expand All @@ -352,7 +354,7 @@ void BlockArray::increaseBuffer()
perror("fread");
}
int newpos = 0;
for (int j = 1, cursor=firstblock; j < bpr; j++) {
for (int j = 1, cursor = firstblock; j < bpr; j++) {
cursor = (cursor + offset) % size;
newpos = (cursor - offset + size) % size;
moveBlock(fion, cursor, newpos, buffer2);
Expand All @@ -369,10 +371,8 @@ void BlockArray::increaseBuffer()
current = size - 1;
length = size;

delete [] buffer1;
delete [] buffer2;
delete[] buffer1;
delete[] buffer2;

fclose(fion);

}

Loading