Skip to content
Merged
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
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,32 @@ jobs:
- run: ./bootstrap
- run: scripts/install_cppcheck.sh $CPPCHECK_REPO $CPPCHECK_VER
- run: scripts/run_cppcheck.sh -v $CPPCHECK_VER

code_formatting_check:
name: code formatting check
runs-on: ubuntu-latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be unstable because the "latest" version will change as time flows but not a big problem.

env:
CC: gcc
# This is required to use a version of astyle other than that
# supplied with the operating system
ASTYLE_VER: 3.1
ASTYLE_REPO: https://svn.code.sf.net/p/astyle/code/tags
steps:
# This is currently the only way to get a version into
# the cache tag name - see https://github.com/actions/cache/issues/543
- run: |
echo "OS_VERSION=`lsb_release -sr`" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Cache astyle
uses: actions/cache@v2
env:
cache-name: cache-astyle
with:
path: ~/astyle.local
key: ${{ runner.os }}-${{ env.OS_VERSION }}-build-${{ env.cache-name }}-${{ env.ASTYLE_VER }}
- run: sudo scripts/install_astyle_dependencies_with_apt.sh
- run: scripts/install_astyle.sh $ASTYLE_REPO $ASTYLE_VER
- name: Format code with astyle
run: scripts/run_astyle.sh
- name: Check code formatting
run: git diff --exit-code
9 changes: 8 additions & 1 deletion astyle_config.as
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
# For each directory in the command line, process all subdirectories recursively.
--recursive

# Exclude git submodule directories and generated files.
--exclude=libpainter
--exclude=librfxcodec
--exclude=xrdp_configure_options.h

# ignore errors from generated files that do not exist
--ignore-exclude-errors

# Preserve the original file's date and time modified.
--preserve-date

Expand All @@ -53,4 +61,3 @@
--formatted

--lineend=linux

10 changes: 5 additions & 5 deletions common/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,9 @@ log_end(void)
/* log a hex dump */
enum logReturns
log_hexdump(const enum logLevels log_level,
const char *message,
const char *src,
int len)
const char *message,
const char *src,
int len)
{
return log_hexdump_with_location("", "", 0, log_level, message, src, len);
}
Expand Down Expand Up @@ -820,12 +820,12 @@ log_hexdump_with_location(const char *function_name,
if (g_strlen(file_name) > 0)
{
rv = log_message_with_location(function_name, file_name, line_number,
log_level, "%s %s%s",
log_level, "%s %s%s",
message, HEX_DUMP_HEADER, dump_buffer);
}
else
{
rv = log_message(log_level, "%s %s%s",
rv = log_message(log_level, "%s %s%s",
message, HEX_DUMP_HEADER, dump_buffer);
}
g_free(dump_buffer);
Expand Down
2 changes: 1 addition & 1 deletion common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct exit_status
{
/* set to -1 when the process exited via a signal */
uint8_t exit_code;

/* set to 0 when the process exited normally */
uint8_t signal_no;
};
Expand Down
4 changes: 2 additions & 2 deletions common/string_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ g_bytes_to_hexdump(const char *src, int len)
+ HEX_DUMP_NEWLINE_SIZE);

dump_number_lines = (len / HEX_DUMP_SOURCE_BYTES_PER_LINE) + 1; /* +1 to round up */
dump_length = (dump_number_lines *dump_line_length /* hex dump lines */
dump_length = (dump_number_lines * dump_line_length /* hex dump lines */
+ 1); /* terminating NULL */
dump_buffer = (char *)g_malloc(dump_length, 1);
if (dump_buffer == NULL)
Expand Down Expand Up @@ -818,7 +818,7 @@ g_strnjoin(char *dest, int dest_len, const char *joiner, const char *src[], int
int dest_remaining;
char *dest_pos = dest;
char *dest_end;

if (dest == NULL || dest_len < 1)
{
return dest;
Expand Down
3 changes: 2 additions & 1 deletion genkeymap/evdev-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* xfree86(base)->evdev keycode mapping
*/

int xfree86_to_evdev[137-8+1] = {
int xfree86_to_evdev[137 - 8 + 1] =
{
/* MDSW */ 203,
/* ESC */ 9,
/* AE01 */ 10,
Expand Down
11 changes: 8 additions & 3 deletions genkeymap/genkeymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
#include <X11/XKBlib.h>
#include <locale.h>

extern int xfree86_to_evdev[137-8+1];
extern int xfree86_to_evdev[137 - 8 + 1];

int main(int argc, char **argv)
{
const char *programname;
char text[256];
char *displayname = NULL;
char *outfname;
const char *sections[8] = {
const char *sections[8] =
{
"noshift", "shift", "altgr", "shiftaltgr",
"capslock", "capslockaltgr", "shiftcapslock", "shiftcapslockaltgr"
};
Expand Down Expand Up @@ -139,9 +140,13 @@ int main(int argc, char **argv)
for (i = 8; i < 137; i++) /* Keycodes */
{
if (is_evdev)
e.keycode = xfree86_to_evdev[i-8];
{
e.keycode = xfree86_to_evdev[i - 8];
}
else
{
e.keycode = i;
}
nbytes = XLookupString(&e, text, 255, &ks, NULL);
text[nbytes] = 0;
char_count = mbstowcs(wtext, text, 255);
Expand Down
4 changes: 2 additions & 2 deletions neutrinordp/xrdp-neutrinordp.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ struct mod
int (*mod_suppress_output)(struct mod *mod, int suppress,
int left, int top, int right, int bottom);
int (*mod_server_monitor_resize)(struct mod *mod,
int width, int height);
int width, int height);
int (*mod_server_monitor_full_invalidate)(struct mod *mod,
int width, int height);
int width, int height);
int (*mod_server_version_message)(struct mod *mod);
tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod
functions above */
Expand Down
108 changes: 108 additions & 0 deletions scripts/install_astyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/sh

# Script to install a version of astyle in ~/astyle.local/
#
# Used by CI builds
#
# Currently only supports git repos as sources
#
# Usage: /path/to/install_astyle.sh <astyle-git-repo> <version-tag>

INSTALL_ROOT=~/astyle.local

# ----------------------------------------------------------------------------
# U S A G E
# ----------------------------------------------------------------------------
usage()
{
echo "** Usage: $0 <svn-tags-url> <tag-name>"
echo " e.g. $0 https://svn.code.sf.net/p/astyle/code/tags 3.1"
} >&2

# ----------------------------------------------------------------------------
# C A L L _ M A K E
#
# Calls make with the specified parameters, but only displays the error
# log if it fails
# ----------------------------------------------------------------------------
call_make()
{
# Disable set -e, if active
set_entry_opts=`set +o`
set +e

status=1
log=`mktemp /tmp/astyle-log.XXXXXXXXXX`
if [ -n "$log" ]; then
make "$@" >$log 2>&1
status=$?
if [ $status -ne 0 ]; then
cat $log >&2
fi
rm $log
fi

# Re-enable `set -e` if active before
$set_entry_opts

return $status
}


# ----------------------------------------------------------------------------
# M A I N
# ----------------------------------------------------------------------------
if [ $# -ne 2 ]; then
usage
exit 1
fi

REPO_URL="$1"
ASTYLE_VER="$2"

# Already installed?
exe=$INSTALL_ROOT/$ASTYLE_VER/usr/bin/astyle
if [ -x "$exe" ]; then
echo "astyle version $ASTYLE_VER is already installed at $exe" >&2
exit 0
fi

workdir=`mktemp -d /tmp/astyle.XXXXXXXXXX`
if [ -z "$workdir" ]; then
echo "** Unable to create temporary working directory" 2>&1
exit 1
fi

# Use a sub-process for the next bit to restrict the scope of 'set -e'
(
set -e ; # Exit sub-process on first error

# Put everything in this directory
FILESDIR=$INSTALL_ROOT/$ASTYLE_VER

svn checkout ${REPO_URL}/${ASTYLE_VER}/AStyle $workdir

cd $workdir

make_args="DESTDIR=$FILESDIR"

echo "Creating Makefiles..."
cmake .

echo "Making astyle..."
call_make $make_args

echo "Installing astyle..."
mkdir -p $FILESDIR
call_make install $make_args
# make install DESTDIR=~/astyle.local/3.1
)
status=$?

if [ $status -eq 0 ]; then
rm -rf $workdir
else
"** Script failed. Work dir is $workdir" >&2
fi

exit $status
6 changes: 6 additions & 0 deletions scripts/install_astyle_dependencies_with_apt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -eufx

PACKAGES="subversion cmake"

apt-get -yq --no-install-suggests --no-install-recommends install $PACKAGES
74 changes: 74 additions & 0 deletions scripts/run_astyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh

# Script to run astyle on the code
#
# Usage: /path/to/run_astyle.sh
#
# Note: the script must be run from the root directory of the xrdp repository

INSTALL_ROOT=~/astyle.local
ASTYLE_FROM_XRDP=$INSTALL_ROOT/3.1/usr/bin/astyle
MIN_ASTYLE_VER="3.1"

# ----------------------------------------------------------------------------
# U S A G E
# ----------------------------------------------------------------------------
usage()
{
echo "** Usage: $0"
echo " e.g. $0"
} >&2

# ----------------------------------------------------------------------------
# M A I N
# ----------------------------------------------------------------------------
if [ $# -ne 0 ]; then
usage
exit 1
fi

# check if the built-in astyle meets the minimum requrements
ASTYLE_FROM_OS_VER_OUTPUT=`astyle --version | grep "Artistic Style Version" | cut -d' ' -f4`

ASTYLE=""
ERROR_MESSAGE=""
if [ ! -z "$ASTYLE_FROM_OS_VER_OUTPUT" ]; then
# astyle is installed, so check if it's version meets the minimum requirements
LOWEST_VERSION=`echo -e "$MIN_ASTYLE_VER\n$ASTYLE_FROM_OS_VER_OUTPUT" | sort -V | head -n1`
if [ "$MIN_ASTYLE_VER" = "$LOWEST_VERSION" ]; then
ASTYLE=astyle
else
ERROR_MESSAGE="The version of astyle installed does not meet the minimum version requirement: >= $MIN_ASTYLE_VER "
fi
else
ERROR_MESSAGE="astyle is not installed on the system path"
fi

if [ -z "$ASTYLE" ]; then
# astyle from the os is invlid, fallback to the xrdp version if it is installed
if [ -x "$ASTYLE_FROM_XRDP" ]; then
ASTYLE="$ASTYLE_FROM_XRDP"
ERROR_MESSAGE=""
else
ERROR_MESSAGE="${ERROR_MESSAGE}\nastyle $MIN_ASTYLE_VER is not installed at the expected path: $ASTYLE_FROM_XRDP"
fi
fi

if [ ! -z "$ERROR_MESSAGE" ]; then
echo "$ERROR_MESSAGE"
exit 1
fi

if [ ! -f "astyle_config.as" ]; then
echo "$0 must be run from the root xrdp repository directory which "
echo "contains the 'astyle_config.as' file."
exit 2
fi

ASTYLE_FLAGS="--options=astyle_config.as ./\*.c ./\*.h"

# Display the astyle version and command for debugging
"$ASTYLE" --version && {
echo Command: $ASTYLE $ASTYLE_FLAGS
"$ASTYLE" $ASTYLE_FLAGS
}
4 changes: 2 additions & 2 deletions sesman/chansrv/chansrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int
g_is_term(void);

int send_channel_data(int chan_id, const char *data, int size);
int send_rail_drawing_orders(char* data, int size);
int send_rail_drawing_orders(char *data, int size);
int main_cleanup(void);
int add_timeout(int msoffset, void (*callback)(void* data), void* data);
int add_timeout(int msoffset, void (*callback)(void *data), void *data);

#ifndef GSET_UINT8
#define GSET_UINT8(_ptr, _offset, _data) \
Expand Down
2 changes: 1 addition & 1 deletion sesman/chansrv/chansrv_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ xfuse_add_clip_dir_item(const char *filename, int flags, int size, int lindex)
(0666 | S_IFREG));
if (xinode == NULL)
{
LOG(LOG_LEVEL_INFO,
LOG(LOG_LEVEL_INFO,
"failed to create file %s in xrdp filesystem", filename);
}
else
Expand Down
Loading