#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <libps/pslib-mp.h>

void errorhandler(PSDoc *p, int error, const char *str, void *data) {
	fprintf(stderr, "PSLib: %s\n", str);
}

void frame(PSDoc *psdoc, float width) {
	PS_rect(psdoc, 0, 0, width, 1000);
	PS_stroke(psdoc);
}

int main() {
	PSDoc *psdoc;
	int myfont;
	float boxwidth, boxheight, baseline, colsep, leftmargin;
	float fontsize;
	int boxed;

	boxwidth = 100;
	boxheight = 630;
	baseline = 100;
	colsep = 20;
	leftmargin = 100;
	boxed = 0;
	fontsize = 10.0;

	PS_boot();
#ifdef MEMORY_DEBUGGING
	PS_mp_init();
#endif

#ifdef MEMORY_DEBUGGING
	psdoc = PS_new2(errorhandler, PS_mp_malloc, PS_mp_realloc, PS_mp_free, NULL);
#else
	psdoc = PS_new();
#endif
	PS_open_file(psdoc, "schematic.ps");
	PS_set_info(psdoc, "Creator", __FILE__);
	PS_set_info(psdoc, "Author", "Uwe Steinmann");
	PS_set_info(psdoc, "Title", "Schematic");
	PS_set_info(psdoc, "Keywords", "Schematic");
	PS_set_info(psdoc, "BoundingBox", "0 0 596 842");

	myfont = PS_begin_font(psdoc, "test", 0, 0.001, 0.0, 0.0, 0.001, 0.0, 0.0, NULL);
	PS_begin_glyph(psdoc, "plus", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "period", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_circle(psdoc, 500, 500, 20);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "x", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_circle(psdoc, 500, 500, 50);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "t", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_moveto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_circle(psdoc, 500, 500, 50);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "T", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_moveto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 0);
	PS_stroke(psdoc);
	PS_circle(psdoc, 500, 500, 50);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "i", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 500, 1000);
	PS_lineto(psdoc, 500, 0);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "minus", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 0, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "a", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 0);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "s", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "d", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 1000, 500);
	PS_lineto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "f", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 1000, 500);
	PS_lineto(psdoc, 500, 500);
	PS_lineto(psdoc, 500, 0);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "r", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 200, 500);
	PS_rect(psdoc, 200, 400, 600, 200);
	PS_moveto(psdoc, 800, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "R", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 200);
	PS_rect(psdoc, 400, 200, 200, 600);
	PS_moveto(psdoc, 500, 800);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "l", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 200, 500);
	PS_rect(psdoc, 200, 400, 600, 200);
	PS_moveto(psdoc, 800, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "L", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 200);
	PS_rect(psdoc, 400, 200, 200, 600);
	PS_moveto(psdoc, 500, 800);
	PS_lineto(psdoc, 500, 1000);
	PS_fill_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "c", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 400, 500);
	PS_moveto(psdoc, 400, 800);
	PS_lineto(psdoc, 400, 200);
	PS_moveto(psdoc, 600, 800);
	PS_lineto(psdoc, 600, 200);
	PS_moveto(psdoc, 600, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "C", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 400);
	PS_moveto(psdoc, 800, 400);
	PS_lineto(psdoc, 200, 400);
	PS_moveto(psdoc, 800, 600);
	PS_lineto(psdoc, 200, 600);
	PS_moveto(psdoc, 500, 600);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "y", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 0, 500);
	PS_lineto(psdoc, 350, 500);
	PS_moveto(psdoc, 350, 700);
	PS_lineto(psdoc, 350, 300);
	PS_stroke(psdoc);
	PS_moveto(psdoc, 350, 500);
	PS_lineto(psdoc, 650, 700);
	PS_lineto(psdoc, 650, 300);
	PS_closepath(psdoc);
	PS_fill(psdoc);
	PS_moveto(psdoc, 650, 500);
	PS_lineto(psdoc, 1000, 500);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "Y", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 500, 0);
	PS_lineto(psdoc, 500, 350);
	PS_moveto(psdoc, 700, 350);
	PS_lineto(psdoc, 300, 350);
	PS_stroke(psdoc);
	PS_moveto(psdoc, 500, 350);
	PS_lineto(psdoc, 700, 650);
	PS_lineto(psdoc, 300, 650);
	PS_closepath(psdoc);
	PS_fill(psdoc);
	PS_moveto(psdoc, 500, 650);
	PS_lineto(psdoc, 500, 1000);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_begin_glyph(psdoc, "g", 1000.0, 0.0, 0.0, 1000.0, 1000.0);
	PS_setlinewidth(psdoc, 40);
	PS_moveto(psdoc, 400, 100);
	PS_lineto(psdoc, 600, 100);
	PS_moveto(psdoc, 300, 300);
	PS_lineto(psdoc, 700, 300);
	PS_moveto(psdoc, 200, 400);
	PS_lineto(psdoc, 800, 400);
	PS_moveto(psdoc, 500, 400);
	PS_lineto(psdoc, 1000, 500);
	PS_stroke(psdoc);
	PS_end_glyph(psdoc);

	PS_add_ligature(psdoc, 0, "plus", "period", "x");
	PS_end_font(psdoc);

	PS_begin_page(psdoc, 596, 842);

	PS_setfont(psdoc, myfont, 50.0);
	PS_show_xy(psdoc, "rclRCLyY", 80, 700);
	PS_show_xy(psdoc, "asdfg", 80, 600);
	PS_show_xy(psdoc, "++.tTi-", 80, 500);

	PS_end_page(psdoc);

	PS_close(psdoc);
	PS_delete(psdoc);

#ifdef MEMORY_DEBUGGING 
	PS_mp_list_unfreed();
#endif  

	PS_shutdown();
	exit(0);
}


