summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt17
-rw-r--r--Makefile259
-rw-r--r--draw_outputdev.cpp100
-rw-r--r--help/simple-text.c173
-rw-r--r--include/ldmicro.h73
-rw-r--r--ldmicro.cpp86
-rw-r--r--miscutil.cpp42
7 files changed, 750 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..4997a4d
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required (VERSION 2.6)
+project (LDMicro)
+set (LDMicro_VERSION_MAJOR 1)
+set (LDMicro_VERSION_MINOR 0)
+
+MESSAGE ( STATUS "Searching for X11..." )
+FIND_PACKAGE ( X11 REQUIRED )
+IF ( X11_FOUND )
+ INCLUDE_DIRECTORIES ( ${X11_INCLUDE_DIR} )
+ LINK_LIBRARIES ( ${X11_LIBRARIES} )
+ MESSAGE ( STATUS " X11_INCLUDE_DIR: " ${X11_INCLUDE_DIR} )
+ MESSAGE ( STATUS " X11_LIBRARIES: " ${X11_LIBRARIES} )
+ENDIF ( X11_FOUND )
+
+add_executable (LDMicro ldmicro.cpp miscutil.cpp draw_outputdev.cpp)
+include_directories ("${PROJECT_SOURCE_DIR}/include")
+install (TARGETS LDMicro DESTINATION bin)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2e1b95e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,259 @@
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 2.8
+
+# Default target executed when no arguments are given to make.
+default_target: all
+.PHONY : default_target
+
+#=============================================================================
+# Special targets provided by cmake.
+
+# Disable implicit rules so canonical targets will work.
+.SUFFIXES:
+
+# Remove some rules from gmake that .SUFFIXES does not remove.
+SUFFIXES =
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+# Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/bin/cmake
+
+# The command to remove a file.
+RM = /usr/bin/cmake -E remove -f
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /home/fossee/testarea/gui/ldmicro
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /home/fossee/testarea/gui/ldmicro
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
+ /usr/bin/cmake -i .
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+.PHONY : edit_cache/fast
+
+# Special rule for the target install
+install: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
+ /usr/bin/cmake -P cmake_install.cmake
+.PHONY : install
+
+# Special rule for the target install
+install/fast: preinstall/fast
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
+ /usr/bin/cmake -P cmake_install.cmake
+.PHONY : install/fast
+
+# Special rule for the target install/local
+install/local: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
+ /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
+.PHONY : install/local
+
+# Special rule for the target install/local
+install/local/fast: install/local
+.PHONY : install/local/fast
+
+# Special rule for the target install/strip
+install/strip: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
+ /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
+.PHONY : install/strip
+
+# Special rule for the target install/strip
+install/strip/fast: install/strip
+.PHONY : install/strip/fast
+
+# Special rule for the target list_install_components
+list_install_components:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
+.PHONY : list_install_components
+
+# Special rule for the target list_install_components
+list_install_components/fast: list_install_components
+.PHONY : list_install_components/fast
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+.PHONY : rebuild_cache/fast
+
+# The main all target
+all: cmake_check_build_system
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/fossee/testarea/gui/ldmicro/CMakeFiles /home/fossee/testarea/gui/ldmicro/CMakeFiles/progress.marks
+ $(MAKE) -f CMakeFiles/Makefile2 all
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/fossee/testarea/gui/ldmicro/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ $(MAKE) -f CMakeFiles/Makefile2 clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+#=============================================================================
+# Target rules for targets named LDMicro
+
+# Build rule for target.
+LDMicro: cmake_check_build_system
+ $(MAKE) -f CMakeFiles/Makefile2 LDMicro
+.PHONY : LDMicro
+
+# fast build rule for target.
+LDMicro/fast:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/build
+.PHONY : LDMicro/fast
+
+draw_outputdev.o: draw_outputdev.cpp.o
+.PHONY : draw_outputdev.o
+
+# target to build an object file
+draw_outputdev.cpp.o:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/draw_outputdev.cpp.o
+.PHONY : draw_outputdev.cpp.o
+
+draw_outputdev.i: draw_outputdev.cpp.i
+.PHONY : draw_outputdev.i
+
+# target to preprocess a source file
+draw_outputdev.cpp.i:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/draw_outputdev.cpp.i
+.PHONY : draw_outputdev.cpp.i
+
+draw_outputdev.s: draw_outputdev.cpp.s
+.PHONY : draw_outputdev.s
+
+# target to generate assembly for a file
+draw_outputdev.cpp.s:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/draw_outputdev.cpp.s
+.PHONY : draw_outputdev.cpp.s
+
+ldmicro.o: ldmicro.cpp.o
+.PHONY : ldmicro.o
+
+# target to build an object file
+ldmicro.cpp.o:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/ldmicro.cpp.o
+.PHONY : ldmicro.cpp.o
+
+ldmicro.i: ldmicro.cpp.i
+.PHONY : ldmicro.i
+
+# target to preprocess a source file
+ldmicro.cpp.i:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/ldmicro.cpp.i
+.PHONY : ldmicro.cpp.i
+
+ldmicro.s: ldmicro.cpp.s
+.PHONY : ldmicro.s
+
+# target to generate assembly for a file
+ldmicro.cpp.s:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/ldmicro.cpp.s
+.PHONY : ldmicro.cpp.s
+
+miscutil.o: miscutil.cpp.o
+.PHONY : miscutil.o
+
+# target to build an object file
+miscutil.cpp.o:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/miscutil.cpp.o
+.PHONY : miscutil.cpp.o
+
+miscutil.i: miscutil.cpp.i
+.PHONY : miscutil.i
+
+# target to preprocess a source file
+miscutil.cpp.i:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/miscutil.cpp.i
+.PHONY : miscutil.cpp.i
+
+miscutil.s: miscutil.cpp.s
+.PHONY : miscutil.s
+
+# target to generate assembly for a file
+miscutil.cpp.s:
+ $(MAKE) -f CMakeFiles/LDMicro.dir/build.make CMakeFiles/LDMicro.dir/miscutil.cpp.s
+.PHONY : miscutil.cpp.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... LDMicro"
+ @echo "... edit_cache"
+ @echo "... install"
+ @echo "... install/local"
+ @echo "... install/strip"
+ @echo "... list_install_components"
+ @echo "... rebuild_cache"
+ @echo "... draw_outputdev.o"
+ @echo "... draw_outputdev.i"
+ @echo "... draw_outputdev.s"
+ @echo "... ldmicro.o"
+ @echo "... ldmicro.i"
+ @echo "... ldmicro.s"
+ @echo "... miscutil.o"
+ @echo "... miscutil.i"
+ @echo "... miscutil.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
+
diff --git a/draw_outputdev.cpp b/draw_outputdev.cpp
new file mode 100644
index 0000000..12320c2
--- /dev/null
+++ b/draw_outputdev.cpp
@@ -0,0 +1,100 @@
+#include <X11/Xlib.h>
+#include <string.h>
+#include "ldmicro.h"
+#include <iostream>
+
+//unsigned long ColorSize;
+SyntaxHighlightingColours HighlightColours;
+
+Font FixedWidthFont;
+Font FixedWidthFontBold;
+
+XColor toRGB(unsigned long red, unsigned long green, unsigned long blue)
+{
+ XColor temp;
+ temp.red=(short)(red*65535/255);
+ temp.green=(short)(green*65535/255);
+ temp.blue=(short)(blue*65535/255);
+ temp.pixel=((red * ColorSize * ColorSize) | (green * ColorSize)
+ | (blue));
+ return temp;
+}
+
+static void SetSyntaxHighlightingColours(void)
+{
+ static const SyntaxHighlightingColours Schemes[] = {
+ {
+ toRGB(0, 0, 0), // bg
+ toRGB(255, 255, 225), // def
+ toRGB(255, 110, 90), // selected
+ toRGB(255, 150, 90), // op
+ toRGB(255, 255, 100), // punct
+ toRGB(255, 160, 160), // lit
+ toRGB(120, 255, 130), // name
+ toRGB(130, 130, 130), // rungNum
+ toRGB(130, 130, 245), // comment
+
+ toRGB(255, 255, 255), // bus
+
+ toRGB(0, 0, 0), // simBg
+ toRGB(130, 130, 130), // simRungNum
+ toRGB(100, 130, 130), // simOff
+ toRGB(255, 150, 150), // simOn
+
+ toRGB(255, 150, 150), // simBusLeft
+ toRGB(150, 150, 255), // simBusRight
+ },
+ };
+
+ memcpy(&HighlightColours, &Schemes[0], sizeof(Schemes[0]));
+}
+
+void InitForDrawing(void)
+{
+ SetSyntaxHighlightingColours();
+/* FixedWidthFont.font =
+ FixedWidthFont = CreateFont(
+ FONT_HEIGHT, FONT_WIDTH,
+ 0, 0,
+ FW_REGULAR,
+ FALSE,
+ FALSE,
+ FALSE,
+ ANSI_CHARSET,
+ OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS,
+ DEFAULT_QUALITY,
+ FF_DONTCARE,
+ "Lucida Console");
+
+ FixedWidthFontBold = CreateFont(
+ FONT_HEIGHT, FONT_WIDTH,
+ 0, 0,
+ FW_REGULAR, // the bold text renders funny under Vista
+ FALSE,
+ FALSE,
+ FALSE,
+ ANSI_CHARSET,
+ OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS,
+ DEFAULT_QUALITY,
+ FF_DONTCARE,
+ "Lucida Console");
+
+ LOGBRUSH lb;
+ lb.lbStyle = BS_SOLID;
+ lb.lbColor = HighlightColours.simBusRight;
+ BusRightBus = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.simBusLeft;
+ BusLeftBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.bus;
+ BusBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.bg;
+ BgBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.simBg;
+ SimBgBrush = CreateBrushIndirect(&lb);*/
+}
diff --git a/help/simple-text.c b/help/simple-text.c
new file mode 100644
index 0000000..d4a986c
--- /dev/null
+++ b/help/simple-text.c
@@ -0,0 +1,173 @@
+/*
+ * simple-text.c - demonstrate drawing of text strings on a window. All
+ * drawings are done in black color over a white background.
+ */
+
+#include <X11/Xlib.h>
+
+#include <stdio.h>
+#include <stdlib.h> /* getenv(), etc. */
+#include <unistd.h> /* sleep(), etc. */
+
+/*
+ * function: create_simple_window. Creates a window with a white background
+ * in the given size.
+ * input: display, size of the window (in pixels), and location of the window
+ * (in pixels).
+ * output: the window's ID.
+ * notes: window is created with a black border, 2 pixels wide.
+ * the window is automatically mapped after its creation.
+ */
+Window
+create_simple_window(Display* display, int width, int height, int x, int y)
+{
+ int screen_num = DefaultScreen(display);
+ int win_border_width = 2;
+ Window win;
+
+ /* create a simple window, as a direct child of the screen's */
+ /* root window. Use the screen's black and white colors as */
+ /* the foreground and background colors of the window, */
+ /* respectively. Place the new window's top-left corner at */
+ /* the given 'x,y' coordinates. */
+ win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
+ x, y, width, height, win_border_width,
+ BlackPixel(display, screen_num),
+ WhitePixel(display, screen_num));
+
+ /* make the window actually appear on the screen. */
+ XMapWindow(display, win);
+
+ /* flush all pending requests to the X server. */
+ XFlush(display);
+
+ return win;
+}
+
+GC
+create_gc(Display* display, Window win, int reverse_video)
+{
+ GC gc; /* handle of newly created GC. */
+ unsigned long valuemask = 0; /* which values in 'values' to */
+ /* check when creating the GC. */
+ XGCValues values; /* initial values for the GC. */
+ unsigned int line_width = 2; /* line width for the GC. */
+ int line_style = LineSolid; /* style for lines drawing and */
+ int cap_style = CapButt; /* style of the line's edje and */
+ int join_style = JoinBevel; /* joined lines. */
+ int screen_num = DefaultScreen(display);
+
+ gc = XCreateGC(display, win, valuemask, &values);
+ if (gc < 0) {
+ fprintf(stderr, "XCreateGC: \n");
+ }
+
+ /* allocate foreground and background colors for this GC. */
+ if (reverse_video) {
+ XSetForeground(display, gc, WhitePixel(display, screen_num));
+ XSetBackground(display, gc, BlackPixel(display, screen_num));
+ }
+ else {
+ XSetForeground(display, gc, BlackPixel(display, screen_num));
+ XSetBackground(display, gc, WhitePixel(display, screen_num));
+ }
+
+ /* define the style of lines that will be drawn using this GC. */
+ XSetLineAttributes(display, gc,
+ line_width, line_style, cap_style, join_style);
+
+ /* define the fill style for the GC. to be 'solid filling'. */
+ XSetFillStyle(display, gc, FillSolid);
+
+ return gc;
+}
+
+void
+main(int argc, char* argv[])
+{
+ Display* display; /* pointer to X Display structure. */
+ int screen_num; /* number of screen to place the window on. */
+ Window win; /* pointer to the newly created window. */
+ unsigned int display_width,
+ display_height; /* height and width of the X display. */
+ unsigned int win_width,
+ win_height; /* height and width for the new window. */
+ char *display_name = getenv("DISPLAY"); /* address of the X display. */
+ GC gc; /* GC (graphics context) used for drawing */
+ /* in our window. */
+ XFontStruct* font_info; /* Font structure, used for drawing text. */
+ char* font_name = "*-helvetica-*-12-*"; /* font to use for drawing text. */
+
+ /* open connection with the X server. */
+ display = XOpenDisplay(display_name);
+ if (display == NULL) {
+ fprintf(stderr, "%s: cannot connect to X server '%s'\n",
+ argv[0], display_name);
+ exit(1);
+ }
+
+ /* get the geometry of the default screen for our display. */
+ screen_num = DefaultScreen(display);
+ display_width = DisplayWidth(display, screen_num);
+ display_height = DisplayHeight(display, screen_num);
+
+ /* make the new window occupy 1/9 of the screen's size. */
+ win_width = (display_width / 3);
+ win_height = (display_height / 3);
+ printf("window width - '%d'; height - '%d'\n", win_width, win_height);
+
+ /* create a simple window, as a direct child of the screen's */
+ /* root window. Use the screen's white color as the background */
+ /* color of the window. Place the new window's top-left corner */
+ /* at the given 'x,y' coordinates. */
+ win = create_simple_window(display, win_width, win_height, 0, 0);
+
+ /* allocate a new GC (graphics context) for drawing in the window. */
+ gc = create_gc(display, win, 0);
+ XSync(display, False);
+
+ /* try to load the given font. */
+ font_info = XLoadQueryFont(display, font_name);
+ if (!font_info) {
+ fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name);
+ exit(-1);
+ }
+
+ /* assign the given font to our GC. */
+ XSetFont(display, gc, font_info->fid);
+
+ {
+ /* variables used for drawing the text strings. */
+ int x, y;
+ char* text_string;
+ int string_width;
+ int font_height;
+
+ /* find the height of the characters drawn using this font. */
+ font_height = font_info->ascent + font_info->descent;
+
+ /* draw a "hello world" string on the top-left side of our window. */
+ text_string = "hello world";
+ x = 0;
+ y = font_height;
+ XDrawString(display, win, gc, x, y, text_string, strlen(text_string));
+
+ /* draw a "middle of the road" string in the middle of our window. */
+ text_string = "middle of the road";
+ /* find the width, in pixels, of the text that will be drawn using */
+ /* the given font. */
+ string_width = XTextWidth(font_info, text_string, strlen(text_string));
+ x = (win_width - string_width) / 2;
+ y = (win_height + font_height) / 2;
+ XDrawString(display, win, gc, x, y, text_string, strlen(text_string));
+ }
+
+ /* flush all pending requests to the X server. */
+ XFlush(display);
+
+ /* make a delay for a short period. */
+ sleep(4);
+
+ /* close the connection to the X server. */
+ XCloseDisplay(display);
+}
diff --git a/include/ldmicro.h b/include/ldmicro.h
new file mode 100644
index 0000000..2491d98
--- /dev/null
+++ b/include/ldmicro.h
@@ -0,0 +1,73 @@
+#ifndef __LDMICRO_H
+#define __LDMICRO_H
+
+// Size of the font that we will use to draw the ladder diagrams, in pixels
+#define FONT_WIDTH "7"
+#define FONT_HEIGHT "13"
+
+#include <linux/limits.h>
+
+extern Display *disp;
+extern Window MainWindow;
+extern XEvent EventHandle;
+extern bool RunningInBatchMode;
+extern bool life;
+
+
+extern char CurrentSaveFile[PATH_MAX];
+extern char CurrentCompileFile[PATH_MAX];
+
+extern unsigned long ColorSize;
+
+// draw_outputdev.cpp
+/*extern void (*DrawChars)(int, int, char *);
+void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
+void PaintWindow(void);
+void ExportDrawingAsText(char *file);*/
+void InitForDrawing(void);/*
+void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert);
+int ScreenRowsAvailable(void);
+int ScreenColsAvailable(void);
+extern HFONT FixedWidthFont;
+extern HFONT FixedWidthFontBold;
+extern int SelectedGxAfterNextPaint;
+extern int SelectedGyAfterNextPaint;
+extern BOOL ScrollSelectedIntoViewAfterNextPaint;
+extern int ScrollXOffset;
+extern int ScrollYOffset;
+extern int ScrollXOffsetMax;
+extern int ScrollYOffsetMax;*/
+
+//-----------------------------------------------
+// The syntax highlighting style colours; a structure for the palette.
+
+
+typedef struct SyntaxHighlightingColoursTag {
+ XColor bg; // background
+ XColor def; // default foreground
+ XColor selected; // selected element
+ XColor op; // `op code' (like OSR, OSF, ADD, ...)
+ XColor punct; // punctuation, like square or curly braces
+ XColor lit; // a literal number
+ XColor name; // the name of an item
+ XColor rungNum; // rung numbers
+ XColor comment; // user-written comment text
+
+ XColor bus; // the `bus' at the right and left of screen
+
+ XColor simBg; // background, simulation mode
+ XColor simRungNum; // rung number, simulation mode
+ XColor simOff; // de-energized element, simulation mode
+ XColor simOn; // energzied element, simulation mode
+ XColor simBusLeft; // the `bus,' can be different colours for
+ XColor simBusRight; // right and left of the screen
+} SyntaxHighlightingColours;
+
+extern SyntaxHighlightingColours HighlightColours;
+
+
+
+
+void Error(char *str, ...);
+
+#endif
diff --git a/ldmicro.cpp b/ldmicro.cpp
new file mode 100644
index 0000000..feb689e
--- /dev/null
+++ b/ldmicro.cpp
@@ -0,0 +1,86 @@
+#include<linux/limits.h>
+#include<X11/Xlib.h>
+#include<assert.h>
+#include<unistd.h>
+#include<iostream>
+#include<stdbool.h>
+#include<string.h>
+#include<stdio.h>
+#include "include/ldmicro.h"
+#include<cmath>
+#include<stdlib.h>
+
+bool life = true;
+unsigned long ColorSize;
+char CurrentSaveFile[PATH_MAX];
+char CurrentCompileFile[PATH_MAX];
+Display *disp;
+Window MainWindow;
+XEvent EventHandle;
+
+int main(int argc,char* argv[])
+{
+ disp = XOpenDisplay(NULL);
+ assert(disp);
+ unsigned long BlackColor = BlackPixel(disp,DefaultScreen(disp));
+ unsigned long WhiteColor = WhitePixel(disp, DefaultScreen(disp));
+ ColorSize = (cbrt(WhiteColor + 1));
+ MainWindow = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0,
+ 800, 600, 0, BlackColor, BlackColor); //Needs to be modified later(border,background,depth)
+ //IoListHeight = 100;
+ //InitCommonControls();
+ InitForDrawing();
+
+ //MakeMainWindowControls();
+ //MainWindowResized();
+
+ //NewProgram();
+ strcpy(CurrentSaveFile, "");
+ // Check if we're running in non-interactive mode; in that case we should
+ // load the file, compile, and exit.
+ if((argc>1)){
+ RunningInBatchMode = true;
+ char *err = (char*)"Bad command line arguments: run 'ldmicro /c src.ld dest.hex'";
+ if(argc!=4) { Error(err); exit(-1); }
+ if(memcmp(argv[1], "/c", 2) == 0) {
+ char *source = argv[2];
+ char *dest = source;
+
+ /*if(!LoadProjectFromFile(source)) {
+ //Error("Couldn't open '%s', running non-interactively.",
+ source);
+ exit(-1);
+ }*/
+ strcpy(CurrentCompileFile, dest);
+ //GenerateIoList(-1);
+ //CompileProgram(false);
+ exit(0);
+ }
+ else{ Error(err); exit(-1); }
+ }
+
+ // We are running interactively, or we would already have exited. We
+ // can therefore show the window now, and otherwise set up the GUI.
+ XSelectInput(disp, MainWindow, StructureNotifyMask);
+ XMapWindow(disp, MainWindow);
+ GC GraphicsContext = XCreateGC(disp, MainWindow, 0, NULL);
+ XSetForeground(disp,GraphicsContext,WhiteColor); //Change the drawing color later.
+ Atom wmDeleteMessage = XInternAtom(disp, "WM_DELETE_WINDOW", false);
+ XSetWMProtocols(disp, MainWindow, &wmDeleteMessage, 1);
+ for(;;)
+ {
+ XNextEvent(disp,&EventHandle);
+ if(EventHandle.type == MapNotify)
+ break;
+ }
+ XFlush(disp); //Show Display
+ while(life){
+ XNextEvent(disp,&EventHandle);
+ switch(EventHandle.type){
+ case ClientMessage:
+ if(EventHandle.xclient.data.l[0] = wmDeleteMessage)
+ life=false;
+ break;
+ }
+ }
+}
diff --git a/miscutil.cpp b/miscutil.cpp
new file mode 100644
index 0000000..0377654
--- /dev/null
+++ b/miscutil.cpp
@@ -0,0 +1,42 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <iostream>
+#include <linux/limits.h>
+#include<X11/Xlib.h>
+#include "ldmicro.h"
+
+// We should display messages to the user differently if we are running
+// interactively vs. in batch (command-line) mode.
+//char CurrentSaveFile[PATH_MAX];
+//char CurrentCompileFile[PATH_MAX];
+bool RunningInBatchMode;
+
+void Error(char *str, ...)
+{
+ va_list f;
+ char buf[1024];
+ va_start(f, str);
+ vsprintf(buf, str, f);
+ if(RunningInBatchMode) {
+ /*AttachConsoleDynamic(ATTACH_PARENT_PROCESS);
+ HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
+ DWORD written;*/
+
+ // Indicate that it's an error, plus the output filename
+ char str[PATH_MAX+100];
+ sprintf(str, "compile error ('%s'): ", CurrentCompileFile);
+ std::cout<<str<<std::endl;
+ //WriteFile(h, str, strlen(str), &written, NULL);
+ // The error message itself
+ std::cout<<buf<<std::endl;
+ //WriteFile(h, buf, strlen(buf), &written, NULL);
+ // And an extra newline to be safe.
+ std::cout<<str<<std::endl;
+ //strcpy(str, "\n");
+ //WriteFile(h, str, strlen(str), &written, NULL);
+ } else {
+ //HWND h = GetForegroundWindow();
+ //MessageBox(h, buf, _("LDmicro Error"), MB_OK | MB_ICONERROR);
+ }
+}