#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <libps/pslib.h>

void * my_malloc(PSDoc *p, size_t size, const char *caller) {
	void *a;
	a = (void *) malloc(size);
	return(a);
}   

void * my_realloc(PSDoc *p, void *mem, size_t size, const char *caller) {
	return((void *) realloc(mem, size));
} 
  
void my_free(PSDoc *p, void *mem) {
	free(mem);
}


int main() {
	PSDoc *psdoc;
	int psfont, b1;
	float len;
	float fontsize = 20.0;

	PS_boot();
	psdoc = PS_new2(NULL, my_malloc, my_realloc, my_free, NULL);
	PS_open_file(psdoc, "hyperlinks.ps");
	PS_begin_page(psdoc, 596, 842);
	b1 = PS_add_bookmark(psdoc, "Content", 0, 0);
	PS_add_bookmark(psdoc, "First Page", b1, 0);
	psfont = PS_findfont(psdoc, "Helvetica", "", 0);
	PS_setfont(psdoc, psfont, fontsize);
	PS_set_value(psdoc, "leading", 14.0);

	PS_show_xy(psdoc, "This is a web link", 100, 100);
	len = PS_stringwidth(psdoc, "This is a web link", psfont, fontsize);
	PS_add_weblink(psdoc, 100, 100, 100+len, 130, "http://www.kitadb.de");

	PS_show_xy(psdoc, "This is a pdf link to an external document", 100, 150);
	len = PS_stringwidth(psdoc, "This is a pdf link to an external document", psfont, fontsize);
	PS_add_pdflink(psdoc, 100, 150, 100+len, 180, "test.pdf", 1, "fitpage");

	PS_show_xy(psdoc, "This is a launch link", 100, 200);
	len = PS_stringwidth(psdoc, "This is a launch link", psfont, fontsize);
	PS_add_launchlink(psdoc, 100, 200, 100+len, 230, "/usr/bin/gedit");

	PS_show_xy(psdoc, "This is a pdf link within the document", 100, 250);
	len = PS_stringwidth(psdoc, "This is a pdf link within the document", psfont, fontsize);
	PS_add_locallink(psdoc, 100, 250, 100+len, 280, 2, "fitpage");

	PS_end_page(psdoc);

	PS_begin_page(psdoc, 300, 300);
	PS_add_bookmark(psdoc, "Second Page", b1, 0);
	PS_add_note(psdoc, 100, 100, 200, 200, "This is the contents of the note", "Title of Note", "help", 1);
	PS_end_page(psdoc);

	PS_close(psdoc);
	PS_delete(psdoc);
	PS_shutdown();
	exit(0);
}
