#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <libps/pslib-mp.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);
}

void usage() {
	fprintf(stderr, "Usage: hyphenate <list of words>\n\n");
}


int main(int argc, char *argv[]) {
	PSDoc *psdoc;
	char *buffer, *word, *str;
	int i;

	if(argc < 2) {
		usage();
		exit(1);
	}

	PS_mp_init();
	PS_boot();
	psdoc = PS_new2(NULL, PS_mp_malloc, PS_mp_realloc, PS_mp_free, NULL);
	PS_set_parameter(psdoc, "hyphendict", "hyph_de.dic");
	buffer = malloc(100);
	for(i=1; i<argc; i++) {
		word = argv[i];
		PS_hyphenate(psdoc, word, &buffer);
		for(str = buffer; *str != '\0'; str++) {
			printf("%c", *word++);
			if(*str & 1) {
				printf("-");
			} 
		}
		printf("\n");
	}

	free(buffer);
	PS_delete(psdoc);
	PS_mp_list_unfreed();
	exit(0);
}
