Index: src/lem_utf8/Makefile
===================================================================
--- src/lem_utf8/Makefile	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/Makefile	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,62 @@
+include ../../config.mak
+
+# because of OpenFST this application cannot be compiled statically, yet
+#ifeq ($(BUILD_STATIC), yes)
+#  LDFLAGS += -static
+#endif
+
+LDFLAGS += -ldl -lfst
+CXXFLAGS += -g  -fpermissive
+
+LIB_PATH=../lib
+COMMON_PATH=../common
+CMDLINE_FILE='"../lem_utf8/cmdline.h"'
+
+
+lem: main.cc lem.o lemfst.o $(LIB_PATH)/auttools.o $(LIB_PATH)/word.o \
+      cmdline.c common_lem.o common.o symtab.o
+	$(CXX) $(CXXFLAGS) -D _CMDLINE_FILE=$(CMDLINE_FILE) \
+	main.cc lem.o lemfst.o $(LIB_PATH)/auttools.o \
+	$(LIB_PATH)/word.o cmdline.c common.o common_lem.o \
+	symtab.o -o lem $(LDFLAGS)
+
+lem.o: lem.h lem.cc
+	$(CXX) $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) lem.cc
+
+common.o: $(COMMON_PATH)/cmdline_common.ggo $(COMMON_PATH)/common.cc \
+	 $(COMMON_PATH)/common.h
+	$(CXX) $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) $(COMMON_PATH)/common.cc
+
+common_lem.o: cmdline.h common_lem.h common_lem.cc
+	$(CXX) $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) common_lem.cc
+
+cmdline.c cmdline.h: cmdline.ggo
+	$(GENGETOPT) -i cmdline.ggo --conf-parser
+
+cmdline.ggo: cmdline_lem.ggo ../common/cmdline_common.ggo
+	cat cmdline_lem.ggo ../common/cmdline_common.ggo > cmdline.ggo
+
+symtab.o: $(LIB_PATH)/symtab.h $(LIB_PATH)/symtab.cc
+	$(CXX) $(CXXFLAGS) -c $(LIB_PATH)/symtab.cc
+
+clean: clean.cmdline
+	rm *.o || true
+	rm lem || true
+
+clean.cmdline:
+	rm cmdline.* || true
+
+lemfst.o: 
+	$(CXX) -c lemfst.cpp $(CXXFLAGS) -o lemfst.o
+
+.PHONY: install
+install:
+ifdef BIN_DIR
+	install -m 0755 lem $(BIN_DIR)
+endif
+
+.PHONY: uninstall
+uninstall:
+ifdef BIN_DIR
+	rm $(BIN_DIR)/lem
+endif
Index: src/lem_utf8/cmdline_lem.ggo
===================================================================
--- src/lem_utf8/cmdline_lem.ggo	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/cmdline_lem.ggo	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,5 @@
+package "lem"
+version "0.1"
+
+option "dictionary-home"	-	"D.h." string typestr="FILENAME" hidden no
+option "dictionary"		d	"Dictionary" string typestr="FILENAME" default="lem.bin" no
Index: src/lem_utf8/common_lem.cc
===================================================================
--- src/lem_utf8/common_lem.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/common_lem.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,51 @@
+#include <stdlib.h>
+#include <string.h>
+#include "common_lem.h"
+
+char dictionary[255];
+
+void process_lem_options(gengetopt_args_info* args)
+{
+
+  if(args->dictionary_given)
+    {
+      expand_path(args->dictionary_arg,dictionary);
+      if(file_accessible(dictionary)!=0)
+	{
+	  fprintf(stderr,"Cannot open the dictionary file: %s\nAborting.\n",dictionary);
+	  exit(1);
+	}
+    }
+  else if (args->dictionary_home_given && args->language_given)
+    {
+      char buf[255];
+      expand_path(args->dictionary_home_arg, buf);
+      sprintf(dictionary,"%s/%s/lem.bin",buf,args->language_arg);
+      if(file_accessible(dictionary)!=0)
+	{
+	  fprintf(stderr,"Cannot open the dictionary file: %s\nAborting.\n",dictionary);
+	  exit(1);
+	}
+    }
+}
+
+
+// STARE
+//  if(args.dictionary_given)
+//    strcpy(dictionary, args.dictionary_arg);
+//  else {
+//     char path[256];
+//     //sprintf(path, "/etc/utt/data/%s/%s", args.locale_arg, DICT_FILE);
+//     //if (file_accessible(path) == 0)
+//     //  strcpy(dictionary, path);
+//     //else {
+//       sprintf(path, "%s/%s", utt_dir, DICT_FILE);
+//       if (file_accessible(path) == 0)
+// 	strcpy(dictionary, path);
+//       else {
+// 	fprintf(stderr, "Cannot find dictionary!\n");
+// 	exit(1);
+//       }
+//       //}
+//   }
+
Index: src/lem_utf8/common_lem.h
===================================================================
--- src/lem_utf8/common_lem.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/common_lem.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,15 @@
+#ifndef __COMMON_LEM__H
+#define __COMMON_LEM__H
+
+#include <stdio.h>
+#include "../common/common.h"
+
+#include "cmdline.h"
+
+#define DICT_FILE "lem.bin"
+
+extern char dictionary[];
+
+extern void process_lem_options(gengetopt_args_info* args);
+
+#endif
Index: src/lem_utf8/lem.cc
===================================================================
--- src/lem_utf8/lem.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/lem.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,133 @@
+#include "lem.h"
+#include <cstdlib>
+#include <cassert>
+
+/* Znajduje opisy slownikowe dla wyrazu.
+ * Parametry:
+ * form - wyraz,
+ * tab - referencja do tablicy Words (miejsce na wyniki)
+ * Wartosc:
+ * liczba dodanych opisow
+ */
+int Lem::ana(const wchar_t* form, Words& tab) {
+  assert(form && &tab);
+  int count0 = tab.count();
+  LemFST::State l,d;
+  int i = 0;
+  LemFST::Word w = *LemFST::charToWord(form);
+  d = _dict.next(_dict.start(), w);
+  d = _dict.next(d, ';');
+
+  if (d>=0)
+    add_to_table(tab, form, d);
+  return tab.count()-count0;
+}
+
+
+
+/* Dodaje kolejne opisy do tablicy wynikow.
+ * Parametry:
+ * tab - tablica wynikow,
+ * f - wyraz,
+ * s - stan, na ktorym zaczyna sie pierwszy opis
+ */
+void Lem::add_to_table(Words& tab, const wchar_t* f, LemFST::State s) {
+  assert(&tab);
+  assert(f);
+  
+  LemFST::Word *w = new LemFST::Word();
+  int r;
+  while (r = _dict.cont(s, w, 200)) {
+	char fchar[200]; //Bufor do przetrzymywania f w postaci zwyklych char 
+	wcstombs(fchar, f, 200); // Zamien f w zwykle chary i umiesc w fchar
+	const char* wChar = LemFST::wordToChar(w); // Aktualne slowo zamien w chary
+	w->clear(); // czyscimy bufor ze slowem.
+	tab.add(fchar, wChar);
+   }
+   _dict.cont(LemFST::noStateId, w, 200); // ubijamy generator
+   delete w;
+}
+
+void Lem::prn_dict()
+{
+  LemFST::Word des;
+  LemFST::State s=_dict.start();
+
+  while (_dict.cont(s, &des, 200))
+    {
+      wprintf(L"%ls\n",des.size()); // Ladne drukowanie!
+      s=-1;
+	// TODO: Ladne wyswiatlanie slownika; 
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+//======================================================================
+// AUX LEM
+//======================================================================
+AuxLem::AuxLem(const char* filename)
+        : Lem(filename), _dict(SIZE)
+{
+  FILE* f;
+  char buf[MAX_LINE+2];
+  f=fopen(filename,"r");
+  for(long i=0; i<SIZE; ++i) info[i]=(char*)NULL;
+  while(fgets(buf,MAX_LINE,f))
+  {
+    int l=strlen(buf);
+    if(l>=MAX_LINE-1) continue; // BEZ isalpha!
+    buf[l-1]='\0';
+    char* sep=strchr(buf,';');
+    if(sep==NULL) continue;
+    *sep='\0';
+    long formind=_dict.add(buf);
+    if(formind>=0)
+    {
+      char* desc=strdup(sep+1);
+      info[formind]=desc;
+    }
+    else
+      fprintf(stderr,"AuxLem: Form not added: %s;%s.\n", buf,sep+1);
+  }
+  fclose(f);
+};
+
+
+AuxLem::~AuxLem()
+{
+  for(long i=0; i<SIZE; ++i)
+    if(info[i]) free(info[i]);
+}
+
+
+int AuxLem::ana(const char* form, Words& tab)
+{
+  if(!form) return 0;
+  int count0=tab.count();
+  char des[MAX_LINE];
+  long ind=_dict[form];
+  if(ind>=0)
+  {
+    strcpy(des,info[ind]);
+    char* des1;
+    if((des1=strtok(des,";"))!=NULL)
+      do
+      {
+        if(tab.cnt>=MAXALT) break;
+        tab.add(form,des1);
+        des1=strtok(NULL,";");
+      } while(des1!=NULL);
+  }
+  return tab.count()-count0;
+}
+
+
Index: src/lem_utf8/lem.h
===================================================================
--- src/lem_utf8/lem.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/lem.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,50 @@
+// Do wyrzucenia. Korzystamy z LemFST.h teraz#include "../lib/tfti.h"
+#include "lemfst.h"
+#include "../lib/word.h"
+#include "../lib/symtab.h"
+#include "../lib/const.h"
+
+class Lem {
+
+ protected:
+  //  Alphabet& _alpha;
+
+  // slownik
+  //TFTiv<char,char> _dict;
+  LemFST _dict;
+  void add_to_table(Words& tab, const wchar_t* f, LemFST::State s);
+
+ public:
+
+  //Lem(// {}
+  Lem(const char* d) : _dict(d) {} // TODO: Dodaj konstruktor z sciezka do FST.bin
+  virtual int ana(const wchar_t* form, Words& tab);
+  //int pref(char* form, Words& tab);
+  void prn_dict();
+
+};
+
+
+class AuxLem : public Lem {
+public:
+
+  static const int SIZE=1500000;
+  //  static const int MAXLINE=1000;
+  static const int MAXALT=256;
+
+  AuxLem(const char* filename);
+  ~AuxLem();
+
+//  int ana(const char* form, Grams& tab);
+  int ana(const char* form, Words& tab);
+
+//  operator bool() { return _dict && info; }
+
+private:
+  UTT::SymbolTable _dict;
+  char* info[SIZE];
+
+};
+
+
+
Index: src/lem_utf8/lemfst.cpp
===================================================================
--- src/lem_utf8/lemfst.cpp	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/lemfst.cpp	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,147 @@
+#include "lemfst.h"
+
+LemFST::LemFST(const char* plik_fst)
+{
+    fst = StdFst::Read(plik_fst);
+}
+
+
+LemFST::~LemFST(void)
+{
+	delete fst;
+	path.clear();
+}
+
+/** Zwraca true jezeli s jest koncowym */
+bool LemFST::accept(State s) {
+	if (s == fst::kNoStateId) return false;
+	return fst->Final(s)!=StdFst::Weight::Zero();
+}
+
+
+LemFST::State LemFST::start() { 
+	return fst->Start();
+}
+
+
+/** Przechodzi do nastepnego stanu po jednym znaku */
+LemFST::State LemFST::next(State s, Char c) {
+	if (s==fst::kNoStateId) return fst::kNoStateId;
+	ArcsIt aiter(*fst, s);
+	for (; !aiter.Done(); aiter.Next()) {
+		StdArc arc = aiter.Value();	
+		if (arc.ilabel==c) return arc.nextstate;
+		
+	}
+	return fst::kNoStateId;
+}
+
+/** Konsumuje slowo W zaczynajac w stanie s.
+  * Zwraca:
+  * State (int64) -  w jakim sie znajdzie
+  * kNoStateId (-1) - gdy nie moze dokonac takiego przejscia.
+  */
+LemFST::State LemFST::next(State s, Word w) {
+	if (s==fst::kNoStateId) return fst::kNoStateId;
+	LemFST::WordIt it;
+	State ns = s;
+	for(it=w.begin(); it!=w.end(); ++it) {
+		ns = next(ns, *it);
+		if (ns==fst::kNoStateId) {
+			return fst::kNoStateId;
+		}
+	}
+	return ns;
+
+}
+
+/** Funkcja zwraca kolejne sciezki z automatu w formie generatora.
+  * Ustawienie s na kNoStateId (lub -1) restartuje generator.
+  * Dopoki s!=-1 metoda zwraca przy kolejnych wywolaniach kolejne sciezki od stanu s 
+  * do stanow konczacych.
+  * Sciezke mozna odzyskac poprzez metode getPath();
+  */
+long LemFST::cont(State s, Word *result, int maxPath) {
+	// Restart generatora po podaniu -1
+	// Lub przekroczeniu dlugosci sciezki
+	if (s==fst::kNoStateId || path.size() > maxPath) {
+		path.clear();
+		return 0;
+	}
+
+
+	// Stos jest pusty. Mozemy dodac do niego wierzcholek poczatkowy.
+	if (path.empty()) {
+		path.push_back(getStateInfo(s, fst::kNoStateId, 0));
+	}
+	while(!path.empty()) {
+
+		// Zdejmujemy ze stosu stan i jego iterator:
+		StateInfo *state = &path.back();
+		ArcsIt *ait = state->it;
+
+		// Jezeli stan jest koncowy to zwracamy sciezke do stanu "s"
+		// Dodatkowo sprawdzamy czy juz nie startowalismy z tego stanu, aby nie wyswietlac wielokrotnie tego samego
+		if (!state->checked && accept(state->id)) {
+			state->checked = true;
+			StateInfo tState;
+			PathRevIt pit=path.rbegin();
+			State prevId = pit->id;
+            		result->clear();
+			for(; pit!=path.rend(); ++pit) {
+				tState = (*pit);
+				if (tState.id == prevId && tState.prev!=fst::kNoStateId && tState.id !=s) {
+					ArcsIt *tArcIt = tState.it;
+					result->push_front(tState.symbol);
+				}
+				if (tState.prev==fst::kNoStateId) break;
+				prevId = tState.prev;		
+			}
+			ait->Next();
+			return path.size();
+		}
+
+
+		// Skonczylismy sprawdzac dany iterator (stan).
+		// Dlatego mozemy go usunac ze stosu.
+		if (ait->Done()) {
+			path.pop_back();
+			// Jezeli jakies wierzcholki sa jeszcze na stosie to kontynuuj:
+			if (path.size() > 0) continue;
+			// w.p.p zakoncz.
+			else return 0;
+		}
+
+
+		// Odwiedzamy stan.
+		// Dodajemy jego nastepnikow:
+		for(; !ait->Done(); ait->Next()) {
+			State next = ait->Value().nextstate;
+			Char isymbol = ait->Value().ilabel;
+			path.push_back(getStateInfo(next, state->id, isymbol));
+		}
+	} // Koniec (while(!path.empty())
+
+
+
+	return 0;
+}
+
+
+/** Zwraca strukture StateInfo uzupelniajac ja o dane
+  * Parametry:
+  * s - ktory stan opisujemy
+  * prev - poprzednik stanu w automacie
+  * isymbol - symbol po jakim dostalismy sie z 'prev' do 's'
+  */
+inline const LemFST::StateInfo LemFST::getStateInfo(State s, State prev, Char isymbol) {
+	StateInfo sInfo;
+	sInfo.id = s; 
+	sInfo.it = new ArcsIt(*fst, s); //Wyciagamy iterator z automatu
+	sInfo.symbol = isymbol; 
+	sInfo.prev = prev;
+	sInfo.checked = false; // Czy stan byl juz sprawdzany jako koncowy
+	return sInfo;
+}
+
+
Index: src/lem_utf8/lemfst.h
===================================================================
--- src/lem_utf8/lemfst.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/lemfst.h	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,112 @@
+#ifndef __LemFST
+#define __LemFST
+
+#include <fst/fst.h>
+#include <list>
+#include <wchar.h>
+
+#define fstMAXPATH 100
+using namespace fst;
+class LemFST
+{
+public:
+	LemFST(const char*);
+	~LemFST(void);
+
+
+//////////////////////////////////////////////////////////////////////////////
+	typedef StdFst::Arc::Label Char; // Pojedynczy znak
+	typedef StdFst::StateId State; // Stan
+	
+	typedef std::list<Char> Word; // Lista znakow. 
+	typedef std::list<Char>::iterator WordIt; // Iterator po lisice znakow
+
+
+	typedef ArcIterator<StdFst> ArcsIt; // Iterator po krawedziach
+	typedef struct {
+		ArcsIt* it;		// Krawedzie wychodzace (Iterator)
+		State id;		// Numer stanu
+		State prev;		// Poprzednik stanu
+		Char symbol;	// Symbol po jakim przeszlismy z prev do id
+		bool checked;	// Czy stan byl juz brany pod uwage jako koncowy
+	} StateInfo;
+
+	typedef std::list<StateInfo> Path;	// Sciezka stanow (wlasc. stos)
+	typedef Path::iterator PathIt;		// Iterator po Sciezce
+	typedef Path::reverse_iterator PathRevIt; // Odwrotny iterator po Scieze
+	
+	
+	// Operacje na automacie:
+	StdFst *fst; // Automat LEMa
+	State start();
+	bool accept(State);
+	State next(State, Char); // Go to next state by Char
+	State next(State, Word); // Go to end of the Word
+
+
+
+
+
+	// Przeszukiwanie automatu:
+	Path path;
+    long cont(State, Word*, int); // Return a path from state to finish state;
+
+
+
+	// Pomocnicze:
+	inline const StateInfo getStateInfo(State, State, Char);
+
+
+	static const State noStateId = fst::kNoStateId;
+
+	/** Zwraca ciag wchar_t zbudowany ze slowa w */
+	inline static char* wordToChar(Word* w) {
+		int len = w->size();
+		WordIt it;
+		char* ret = new char[len+1];
+		int i=0;
+		for(it=w->begin(); it!=w->end(); it++) {
+			ret[i++] = static_cast<char>(*it);
+		}
+		ret[i]='\0';
+		return ret;
+	}
+
+    /** Zwraca ciag wchar_t zbudowany ze slowa w */
+	inline static wchar_t* wordToWChar(Word* w) {
+		int len = w->size();
+		WordIt it;
+		wchar_t* ret = new wchar_t[len+1];
+		int i=0;
+		for(it=w->begin(); it!=w->end(); it++) {
+			ret[i++] = static_cast<wchar_t>(*it);
+		}
+		ret[i]=L'\0';
+		return ret;
+	}
+
+
+
+	/** Zwraca slowo Word* na podstawie ciagu wchar_t */
+	inline static Word* charToWord(const wchar_t* ch) {
+		int i =0;
+		Word *w = new Word();
+		for(; ch[i]!=L'\0'; i++)  {
+			w->push_back((int)ch[i]);
+		}
+		return w;
+	}
+    
+    /** Zwraca slowo Word* na podstawie ciagu wchar_t */
+	inline static Word* charToWord(const char* ch) {
+		int i =0;
+		Word *w = new Word();
+		for(; ch[i]!='\0'; i++)  {
+			w->push_back((int)ch[i]);
+		}
+		return w;
+	}
+
+};
+
+#endif
Index: src/lem_utf8/main.cc
===================================================================
--- src/lem_utf8/main.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
+++ src/lem_utf8/main.cc	(revision 5f4d9c3b32eea7b6643a751aa75bdb05b7d41576)
@@ -0,0 +1,140 @@
+#include "../lib/iotools.h"
+//do wyrzucenia - definicja w Makefile! #define _CMDLINE_FILE "../lem/cmdline.h"
+#include "../common/common.h"
+#include "common_lem.h"
+#include "lem.h"
+#include "cmdline.h"
+#include <cwchar>
+#include <clocale>
+#include <wctype.h>
+
+int main(int argc, char** argv) {
+
+   setlocale(LC_CTYPE,"");
+
+  gengetopt_args_info args;
+
+  if(cmdline_parser(argc, argv, &args) != 0)
+    exit(1);
+
+  process_config_files(&args,argv[0]);
+  process_common_options(&args,argv[0]);
+  process_lem_options(&args);
+  
+  wchar_t line[MAX_LINE+1];
+  wchar_t outline[MAX_LINE+1];
+  wchar_t parms[MAX_LINE+1], desc[MAX_LINE+1], lemma[MAX_LINE+1];
+  long line_count = 0;
+
+  Lem* lem;
+  
+  if(strcmp(dictionary+strlen(dictionary)-4,".bin")==0)
+    lem = new Lem(dictionary);
+  else if(strcmp(dictionary+strlen(dictionary)-4,".dic")==0)
+    lem = new AuxLem(dictionary);
+  else
+    fprintf(stderr,"lem: Invalid dictionary file extension.\n");
+  
+  Words tab;
+//   Segment seg;
+
+  while (fgetws(line, MAX_LINE, inputf))
+  {
+      ++line_count;
+      int start, len;
+     
+      char linechar[MAX_LINE+1];
+      wcstombs(linechar, line, MAX_LINE+1);
+      if (!process_seg(linechar, args)) // TO POWINNO BYC WCZESNIEJ ZABEZPIECZONE
+	      fputws(line, outputf);
+      else
+	    {
+	      wchar_t form[MAX_FORM+1];
+
+	      tab.clear();
+        	wchar_t winput_field_prefix[MAX_LINE+1];
+        	mbstowcs(winput_field_prefix, input_field_prefix, MAX_LINE+1);
+	     	getfield(line,winput_field_prefix,form); /// SEGMENTATION FAULT!!!
+		/* W trakcie uzupelniania pola "4" nastepuje cos dziwnego... */
+	      if (form==NULL) continue;//BZDURA
+	      lem->ana(form, tab);
+	      if(tab.count()==0)
+	      {
+		          
+	        wchar_t form1[MAX_FORM]; // tymczasowo tak, trzeba zmienic ana
+	        wchar_t* p;
+	        wcscpy(form1,form);
+	        for(p=form1;*p;++p) *p=towlower(*p);
+	        p=form1;
+	        lem->ana(p,tab);
+	      }
+	      if (tab.count() == 0) {
+	        fputws(line, failedf);
+       		 }
+      
+	      else 
+	      { // mamy jakies opisy w slowniku
+	        if(one_line)
+		      {
+		        wchar_t* descp=desc;
+            //wchar_t woutput_field_prefix[MAX_LINE+1];
+            //mbstowcs(woutput_field_prefix, output_field_prefix, MAX_LINE+1);
+		        wprintf(L"tab.count() in one-line: %d prefix: %s", tab.count(), output_field_prefix);
+            for (int i=0; i< tab.count(); ++i)
+		        {
+		          descp += swprintf(descp,MAX_LINE, L" %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr());
+              wprintf(L"for %d lemma '%s' descr '%s'", i, tab[i].lemma(), tab[i].descr());
+		        }
+            wprintf(L"descp: %ls", descp);
+		        wcscpy(outline,line);
+		        outline[wcslen(outline)-1]='\0';
+	      		wcscat(outline,descp);
+		        wcscat(outline,L"\n");
+      			fputws(outline, outputf);
+		        if (copy_processed)
+      			    fputws(line,outputf);
+		      }
+	        else if(one_field)
+		      {
+      		  wchar_t* descp=desc;
+      		  for (int i=0; i< tab.count(); ++i)
+		          if(i==0)
+      		      descp += swprintf(descp,MAX_LINE,L" %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr());
+		          else
+		          {
+        	  		if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0)
+          			  descp += swprintf(descp,MAX_LINE,L",%s",tab[i].descr());
+          			else
+          			  descp += swprintf(descp,MAX_LINE,L";%s,%s",tab[i].lemma(),tab[i].descr());
+    		      }
+		 	 
+		          wcscpy(outline,line);
+			wprintf(L"%ls \n", line);
+          	  outline[wcslen(outline)-1]=L'\0';
+        		  wcscat(outline,desc);
+        		  wcscat(outline,L"\n");
+        		  fputws(outline, outputf);
+        		  
+              if (copy_processed)  fputws(line,outputf);
+		      }
+          else
+		      {
+			  for (int i=0; i< tab.count(); ++i)
+				{
+				      swprintf(desc,MAX_LINE,L" %s%s,%s \n", output_field_prefix, tab[i].lemma(), tab[i].descr());
+				      wcscpy(outline,line);
+				      outline[wcslen(outline)-1]='\0';
+				      wcscat(outline,desc);
+				      fputws(outline, outputf);
+				}
+			  if (copy_processed) fputws(line,outputf);
+		      }
+	      } 
+	    }
+      
+      if (args.interactive_flag) 
+    	  fflush(outputf), fflush(failedf);
+      
+    }
+    cmdline_parser_free(&args);
+}
