File: epgsearchsvdrp.c

package info (click to toggle)
vdr-plugin-epgsearch 1.0.1~beta6+git20150211-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,780 kB
  • ctags: 2,325
  • sloc: ansic: 23,325; perl: 1,330; sh: 609; makefile: 197
file content (1328 lines) | stat: -rw-r--r-- 44,259 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
/*                                                                  -*- c++ -*-
Copyright (C) 2004-2013 Christian Wieninger

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

The author can be reached at cwieninger@gmx.de

The project's page is at http://winni.vdr-developer.org/epgsearch
*/

#include <string>
#include <set>
#include <iomanip>
#include <sstream>
#include <vdr/plugin.h>
#include <vdr/epg.h>
#include "epgsearchtools.h"
#include "recdone.h"
#include "epgsearch.h"
#include "changrp.h"
#include "epgsearchcfg.h"
#include "searchtimer_thread.h"
#include "blacklist.h"
#include "epgsearchcats.h"
#include "menu_dirselect.h"
#include "menu_deftimercheckmethod.h"
#include "conflictcheck.h"
#include "menu_main.h"

using std::string;
using std::set;

template< class Iter > Iter advance_copy( Iter it, std::size_t count = 1) { using std::advance; advance( it, count ); return it; }

extern int updateForced;
extern int exitToMainMenu;

const char **cPluginEpgsearch::SVDRPHelpPages(void)
{
   static const char *HelpPages[] = {
      "LSTS [ ID ]\n"
      "    List searches.\n"
      "    If the optional numeric argument ID is passed,\n"
      "    only the search with the according ID is listed",
      "NEWS <settings>\n"
      "    Add a new search\n",
      "DELS <ID>\n"
      "    Delete search with passed ID\n",
      "EDIS <settings>\n"
      "    Edit an existing search\n",
      "MODS ID ON|OFF\n"
      "    Turn on/off 'Use as search timer'\n",
      "UPDS [ OSD ] [ SCAN ]\n"
      "    Update search timers.\n"
      "    If the optional keyword 'OSD' is passed, an OSD message\n"
      "    will inform about update completion. With 'SCAN' you can\n"
      "    trigger an EPG scan before the searchtimer udpate.",
      "UPDD\n"
      "    Reload epgsearchdone.data",
      "SETS <ON|OFF>\n"
      "    Temporarily activate or cancel the search timer background\n"
      "    thread.",
      "FIND <settings>\n"
      "    Search the EPG for events and receive a result list.",
      "QRYS < ID[|ID] >|<settings> \n"
      "    Search the EPG for events and receive a result list\n"
      "    for the given ID or any search settings. Separate multiple\n"
      "    searches with '|'",
      "QRYF [hours]\n"
      "    Search the EPG for favorite events with the next 24h or\n"
      "    the given number of hours",
      "LSRD\n"
      "    List of all recording directories used in recordings, timers,\n"
      "    search timers or in epgsearchdirs.conf",
      "LSTC [ channel group name ]\n"
      "    List all channel groups or if given the one with name\n"
      "    group name.",
      "NEWC <channel group settings>\n"
      "    Create a new channel group, format as in\n"
      "    epgsearchchangrps.conf.",
      "EDIC <channel group settings>\n"
      "    Modify an existing channel group, format as in\n"
      "    epgsearchchangrps.conf.",
      "DELC <channel group name>\n"
      "    Delete an existing channel group.",
      "RENC <old channelgroup name|new channel group name>\n"
      "    Rename an existing channel group.",
      "LSTB [ ID ]\n"
      "    List blacklists.\n"
      "    If the optional numeric argument ID is passed,\n"
      "    only the blacklist with the according ID is listed",
      "NEWB <settings>\n"
      "    Add a new blacklist",
      "DELB <ID>\n"
      "    Delete blacklist with passed ID",
      "EDIB <settings>\n"
      "    Edit an existing blacklist",
      "LSTE [ ID ]\n"
      "    List the extended EPG categories defined in\n"
      "    epgsearchcats.conf or only the one with the given ID",
      "SETP [ option ]\n"
      "    Get the current setup option value",
      "LSTT [ ID ]\n"
      "    List search templates.\n"
      "    If the optional numeric argument ID is passed,\n"
      "    only the search template with the according ID\n"
      "    is listed",
      "NEWT <settings>\n"
      "    Add a new search template\n",
      "DELT <ID>\n"
      "    Delete search template with passed ID\n",
      "EDIT <settings>\n"
      "    Edit an existing search template\n",
      "DEFT [ ID ]\n"
      "    Returns the ID of the default search template\n"
      "    or activates a search template with ID as default",
      "LSCC [ REL ]\n"
      "    Returns the current timer conflicts. With the option\n"
      "    'REL' only relevant conflicts are listed",
      "MENU [ NOW|PRG|SUM ]\n"
      "    Calls one of the main menus of epgsearch or the summary\n"
      "    of the current event\n",
      "UPDT\n"
      "    Reload search timers from epgsearch.conf",
      NULL
   };
   return HelpPages;
}

cString cPluginEpgsearch::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
   if (strcasecmp(Command, "UPDS") == 0)
   {
     if (!EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
       cSearchTimerThread::Init((cPluginEpgsearch*) cPluginManager::GetPlugin("epgsearch"), true);
     updateForced = 1;
     if (Option)
       {
	 char *pstrOptionToken, *pptr;
	 char *pstrOptions=strdup(Option);
	 pstrOptionToken=strtok_r(pstrOptions, " ", &pptr);
	 while(pstrOptionToken)
	   {
	     if (strcasecmp(Option, "OSD")==0)
	       updateForced |= UPDS_WITH_OSD;
	     if (strcasecmp(Option, "SCAN")==0)
	       updateForced |= UPDS_WITH_EPGSCAN;
	     pstrOptionToken=strtok_r(NULL, "|", &pptr);
	   }
	 free(pstrOptions);
       }
     return cString("update triggered");
   }
   else if (strcasecmp(Command, "UPDD") == 0)
   {
      if (RecsDone.Load(AddDirectory(CONFIGDIR, "epgsearchdone.data")))
         return cString("reload successful");
      else
         return cString("reload failed");
   }
   // -----------------------
   // search timer management
   else if (strcasecmp(Command, "LSTS") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cSearchExt *search = SearchExts.GetSearchFromID(atol(Option));
            if (search)
               return cString(search->ToText());
            else
            {
               ReplyCode = 901;
               return cString::sprintf("search id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in search ID \"%s\"", Option);
         }
      }
      else if (SearchExts.Count()>0)
      {
         string sBuffer;
         cMutexLock SearchExtsLock(&SearchExts);
         for (int i = 0; i < SearchExts.Count(); i++)
         {
            cSearchExt* search = SearchExts.Get(i);
            if (search)
               sBuffer += string(search->ToText()) + string((i<SearchExts.Count()-1)?"\n":"");
         }
         return sBuffer.c_str();
      }
      else
      {
         ReplyCode = 901;
         return cString("no searches defined");
      }
   }
   else if (strcasecmp(Command, "DELS") == 0)
   {
      if (*Option)
      {
         string sOption = Option;
         bool delTimers = false;
         if (strcasestr(Option, "DELT"))
         {
            delTimers = true;
            sOption = ReplaceAll(sOption, "DELT", "");
            sOption = Strip(sOption);
         }
         if (isnumber(sOption.c_str()))
         {
            long SID = atol(sOption.c_str());
            cSearchExt *search = SearchExts.GetSearchFromID(SID);
            if (search)
            {
               LogFile.Log(1,"search '%s' deleted via SVDRP", search->search);
               cMutexLock SearchExtsLock(&SearchExts);
               if (delTimers && !Timers.BeingEdited())
                  search->DeleteAllTimers();
               SearchExts.Del(search);
               SearchExts.Save();
               RecsDone.RemoveSearchID(SID);
               return cString::sprintf("search id %s deleted%s", sOption.c_str(), delTimers?" with timers":"");
            }
            else
            {
               ReplyCode = 901;
               return cString::sprintf("search id %s not defined", sOption.c_str());
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in search ID \"%s\"", Option);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search ID");
      }
   }
   else if (strcasecmp(Command, "NEWS") == 0)
   {
      if (*Option)
      {
         cSearchExt* search = new cSearchExt;
         if (search->Parse(Option))
         {
            search->ID = SearchExts.GetNewID();
            LogFile.Log(1,"added search '%s' (%d) via SVDRP", search->search, search->ID);
            cMutexLock SearchExtsLock(&SearchExts);
            SearchExts.Add(search);
            SearchExts.Save();
            if (search->useAsSearchTimer && !EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
               cSearchTimerThread::Init(this, true);
            return cString::sprintf("search '%s' (with new ID %d) added", search->search, search->ID);
         }
         else
         {
            ReplyCode = 901;
            delete search;
            return cString("Error in search settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search settings");
      }
   }
   else if (strcasecmp(Command, "EDIS") == 0)
   {
      if (*Option)
      {
         cSearchExt* search = new cSearchExt;
         if (search->Parse(Option))
         {
            cSearchExt *searchTemp = SearchExts.GetSearchFromID(search->ID);
            if (searchTemp)
            {
               searchTemp->Parse(Option);
               LogFile.Log(1,"modified search '%s' (%d) via SVDRP", searchTemp->search, searchTemp->ID);
               SearchExts.Save();
               if (searchTemp->useAsSearchTimer && !EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
                  cSearchTimerThread::Init((cPluginEpgsearch*) cPluginManager::GetPlugin("epgsearch"), true);

               return cString::sprintf("search '%s' with %d modified", searchTemp->search, searchTemp->ID);
            }
            else
            {
               ReplyCode = 901;
               int ID = search->ID;
               delete search;
               return cString::sprintf("search id %d does not exists", ID);
            }
         }
         else
         {
            ReplyCode = 901;
            delete search;
            return cString("Error in search settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search settings");
      }
   }
   else if (strcasecmp(Command, "MODS") == 0)
   {
      if (*Option)
      {
         char *tail;
         int ID = strtol(Option, &tail, 10);
         tail = skipspace(tail);
         if (!*tail)
         {
            ReplyCode = 901;
            return cString::sprintf("missing parameter ON|OFF");
         }
         cSearchExt *searchTemp = SearchExts.GetSearchFromID(ID);
         if (searchTemp)
         {
            searchTemp->useAsSearchTimer = (strcasecmp(tail, "ON") == 0)?1:0;
            LogFile.Log(1,"modified search '%s' (%d) via SVDRP", searchTemp->search, searchTemp->ID);
            SearchExts.Save();

            if (searchTemp->useAsSearchTimer && !EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
               cSearchTimerThread::Init((cPluginEpgsearch*) cPluginManager::GetPlugin("epgsearch"), true);

            return cString::sprintf("search '%s' with ID %d modified", searchTemp->search, searchTemp->ID);
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("search id %d does not exists", ID);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search ID");
      }
   }
   else if (strcasecmp(Command, "SETS") == 0)
   {
      if (*Option)
      {
         if (strcasecmp(Option, "ON") == 0)
         {
            if (cSearchTimerThread::m_Instance)
            {
               ReplyCode = 901;
               return cString("search timer thread already active!");
            }
            else
            {
               LogFile.Log(1,"search timer thread started via SVDRP");
               cSearchTimerThread::Init(this);
               return cString("search timer activated.");
            }
         }
         else if (strcasecmp(Option, "OFF") == 0)
         {
            if (!cSearchTimerThread::m_Instance)
            {
               ReplyCode = 901;
               return cString("search timer thread already inactive!");
            }
            else
            {
               LogFile.Log(1,"search timer thread canceled via SVDRP");
               cSearchTimerThread::Exit();
               return cString("search timer thread canceled.");
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("unknown option '%s'", Option);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing option <on|off>");
      }
   }
   else if (strcasecmp(Command, "FIND") == 0)
   {
      if (*Option)
      {
         cSearchExt* search = new cSearchExt;
         if (search->Parse(Option))
         {
            cSearchResults* results = search->Run();
            // transfer to result list
            string sBuffer;
            if (results)
            {
               results->SortBy(CompareEventTime);
               cSearchResult *result = results->First();
               while (result)
               {
                  const cEvent* pEvent = result->event;
                  cTimer* Timer = new cTimer(pEvent);

                  static char bufStart[25];
                  static char bufEnd[25];

                  struct tm tm_r;    time_t eStart = pEvent->StartTime();
                  time_t eStop = pEvent->EndTime();
                  time_t start = eStart - (search->MarginStart * 60);
                  time_t stop  = eStop + (search->MarginStop * 60);
                  int Flags = Timer->Flags();
                  if (search->useVPS && pEvent->Vps() && Setup.UseVps)
                  {
                     start = pEvent->Vps();
                     stop = start + pEvent->Duration();
                  }
                  else
                     Flags = 1; // don't use VPS, if not set in this search

                  strftime(bufStart, sizeof(bufStart), "%H%M", localtime_r(&start, &tm_r));
                  strftime(bufEnd, sizeof(bufEnd), "%H%M", localtime_r(&stop, &tm_r));

		  cString cmdbuf = cString::sprintf("NEWT %d:%d:%s:%s:%s:%d:%d:%s:%s",
                           Flags,
                           Timer->Channel()->Number(),
                           *Timer->PrintDay(start, Timer->WeekDays(), true),
                           bufStart,
                           bufEnd,
                           search->Priority,
                           search->Lifetime,
                           Timer->File(),
                           "");


                  sBuffer += string(cmdbuf) + string(results->Next(result)?"\n":"");
                  delete(Timer);
                  result = results->Next(result);
               }
               return sBuffer.c_str();
            }
            else
            {
               ReplyCode = 901;
               delete search;
               return cString("no results");
            }
         }
         else
         {
            ReplyCode = 901;
            delete search;
            return cString("Error in search settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search settings");
      }
   }
   else if (strcasecmp(Command, "QRYS") == 0 || strcasecmp(Command, "QRYF") == 0)
   {
      cSearchExt *temp_SearchExt = NULL;
      cSearchResults* pCompleteSearchResults = NULL;
      if (strcasecmp(Command, "QRYS") == 0) // query one or more searches
      {
         if (*Option)
         {
            if (strchr(Option, ':'))
            {
               cSearchExt* temp_SearchExt = new cSearchExt;
               if (temp_SearchExt->Parse(Option))
                  pCompleteSearchResults = temp_SearchExt->Run();
            }
            else
            {
               char *pstrSearchToken, *pptr;
               char *pstrSearch=strdup(Option);
               pstrSearchToken=strtok_r(pstrSearch, "|", &pptr);

               while(pstrSearchToken)
               {
                  cSearchExt* search = SearchExts.GetSearchFromID(atoi(pstrSearchToken));
                  if (search)
                     pCompleteSearchResults = search->Run(-1, false, 0, pCompleteSearchResults);
                  pstrSearchToken=strtok_r(NULL, "|", &pptr);
               }
               free(pstrSearch);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString("missing search IDs");
         }
      }
      else // query the favorites
      {
         int hours = EPGSearchConfig.FavoritesMenuTimespan;
         if (*Option)
            hours = atoi(Option);

         cMutexLock SearchExtsLock(&SearchExts);
         cSearchExt *SearchExt = SearchExts.First();
         while (SearchExt)
         {
            if (SearchExt->useInFavorites)
               pCompleteSearchResults = SearchExt->Run(-1, false, 60*hours, pCompleteSearchResults);
            SearchExt = SearchExts.Next(SearchExt);
         }
      }

      if (pCompleteSearchResults)
      {
         // transfer to result list
         string sBuffer;
         pCompleteSearchResults->SortBy(CompareEventTime);
         cSearchResult *result = pCompleteSearchResults->First();
         while (result && result->search)
         {
            const cEvent* pEvent = result->event;
            cTimer* Timer = new cTimer(pEvent);

            static char bufStart[25];
            static char bufEnd[25];

            struct tm tm_r;    time_t eStart = pEvent->StartTime();
            time_t eStop = pEvent->EndTime();
            time_t start = eStart - (result->search->MarginStart * 60);
            time_t stop  = eStop + (result->search->MarginStop * 60);
            if (result->search->useVPS && pEvent->Vps() && Setup.UseVps)
            {
               start = pEvent->Vps();
               stop = start + pEvent->Duration();
            }

            strftime(bufStart, sizeof(bufStart), "%H%M", localtime_r(&start, &tm_r));
            strftime(bufEnd, sizeof(bufEnd), "%H%M", localtime_r(&stop, &tm_r));

            eTimerMatch timerMatch;
            bool hasTimer = false;
            if (Timers.GetMatch(pEvent, &timerMatch))
               hasTimer = (timerMatch == tmFull);

            if (!result->search->useAsSearchTimer)
               result->needsTimer = false;

            cChannel *channel = Channels.GetByChannelID(pEvent->ChannelID(), true,true);
            int timerMode = hasTimer?1:(result->needsTimer?2:0);

            string title = pEvent->Title()?ReplaceAll(pEvent->Title(), "|", "!^pipe!^"):"";
            title = ReplaceAll(title, ":", "|");
            string shorttext = pEvent->ShortText()?ReplaceAll(pEvent->ShortText(), "|", "!^pipe!^"):"";
            shorttext = ReplaceAll(shorttext, ":", "|");

            cString cmdbuf = cString::sprintf("%d:%u:%s:%s:%ld:%ld:%s:%ld:%ld:%s:%d",
                     result->search->ID,
                     pEvent->EventID(),
                     title.c_str(),
                     shorttext.c_str(),
                     pEvent->StartTime(),
                     pEvent->EndTime(),
                     CHANNELSTRING(channel),
                     timerMode>0?start:-1,
                     timerMode>0?stop:-1,
                     timerMode>0?result->search->BuildFile(pEvent):"",
                     timerMode);

            sBuffer += string(cmdbuf) + string(pCompleteSearchResults->Next(result)?"\n":"");
            delete(Timer);
            result = pCompleteSearchResults->Next(result);
         }
         if (temp_SearchExt) delete temp_SearchExt;
         if (pCompleteSearchResults) delete pCompleteSearchResults;
         return sBuffer.c_str();
      }
      else
      {
         ReplyCode = 901;
         if (temp_SearchExt) delete temp_SearchExt;
         return cString("no results");
      }
   }
   else if (strcasecmp(Command, "UPDT") == 0)
   {
     if (SearchExts.Load(AddDirectory(CONFIGDIR, "epgsearch.conf")))
       return cString("reload epgsearch.conf successful");
     else
       return cString("reload epgsearch.conf failed");
   }
   // ---------------------
   // recording directories
   else if (strcasecmp(Command, "LSRD") == 0)
   {
      cMenuDirSelect::CreateDirSet();

      if (cMenuDirSelect::directorySet.size() > 0)
      {
         cString sBuffer("");
         std::set<string>::iterator it;
         for (it = cMenuDirSelect::directorySet.begin(); it != cMenuDirSelect::directorySet.end(); ++it)
         {
            cString sOldBuffer = sBuffer;
            sBuffer = cString::sprintf("%s%s\n", *sOldBuffer, (*it).c_str());
         }
         char* buffer = strdup(*sBuffer);
         cString sResBuffer = cString(buffer);
         free(buffer);
         return sResBuffer;
      }
      else
      {
         ReplyCode = 901;
         return cString("no recording directories found");
      }
   }
   // -------------------------
   // channel groups management
   else if (strcasecmp(Command, "LSTC") == 0)
   {
      if (*Option)
      {
         cChannelGroup *changrp = ChannelGroups.GetGroupByName(Option);
         if (changrp)
            return cString(changrp->ToText());
         else
         {
            ReplyCode = 901;
            return cString::sprintf("channel group '%s' not defined", Option);
         }
      }
      else if (ChannelGroups.Count()>0)
      {
         cString sBuffer("");
         for (int i = 0; i < ChannelGroups.Count(); i++)
         {
            cChannelGroup *changrp = ChannelGroups.Get(i);
            if (changrp)
            {
               cString sOldBuffer = sBuffer;
               sBuffer = cString::sprintf("%s%s\n", *sOldBuffer, changrp->ToText());
            }
         }
         char* buffer = strdup(*sBuffer);
         cString sResBuffer = cString(buffer);
         free(buffer);
         return sResBuffer;
      }
      else
      {
         ReplyCode = 901;
         return cString("no channel groups defined");
      }
   }
   else if (strcasecmp(Command, "EDIC") == 0)
   {
      if (*Option)
      {
         cChannelGroup *changrp = new cChannelGroup;
         if (changrp->Parse(Option))
         {
            cChannelGroup *changrpTemp = ChannelGroups.GetGroupByName(changrp->name);
            if (changrpTemp)
            {
               changrpTemp->channels.Clear();
               changrpTemp->Parse(Option);
               LogFile.Log(1,"modified channel group '%s' via SVDRP", changrpTemp->name);
               ChannelGroups.Save();
               return cString::sprintf("channel group '%s' modified", changrpTemp->name);
            }
            else
            {
               ReplyCode = 901;
               delete changrp;
               return cString::sprintf("channel group '%s' does not exists", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            delete changrp;
            return cString("Error in channel group settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing channel group settings");
      }
   }
   else if (strcasecmp(Command, "DELC") == 0)
   {
      if (*Option)
      {
         cChannelGroup *changrp = ChannelGroups.GetGroupByName(Option);
         if (changrp)
         {
            cSearchExt* search = ChannelGroups.Used(changrp);
            if (search)
            {
               ReplyCode = 901;
               return cString::sprintf("channel group '%s' used by: %s", changrp->name, search->search);
            }
            LogFile.Log(1,"channel group '%s' deleted via SVDRP", changrp->name);
            ChannelGroups.Del(changrp);
            ChannelGroups.Save();
            return cString::sprintf("channel group '%s' deleted", Option);
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("channel group '%s' not defined", Option);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing channel group");
      }
   }
   else if (strcasecmp(Command, "NEWC") == 0)
   {
      if (*Option)
      {
         cChannelGroup *changrp = new cChannelGroup;
         if (changrp->Parse(Option))
         {
            LogFile.Log(1,"added channel group '%s' via SVDRP", changrp->name);
            ChannelGroups.Add(changrp);
            ChannelGroups.Save();
            return cString::sprintf("channel group '%s' added", changrp->name);
         }
         else
         {
            ReplyCode = 901;
            delete changrp;
            return cString("Error in channel group settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing channel group settings");
      }
   }
   else if (strcasecmp(Command, "RENC") == 0)
   {
     if (*Option)
       {
         const char* pipePos = strchr(Option, '|');
         if (pipePos)
	   {
	     int index = pipePos - Option;
	     char* oldName = strdup(Option);
	     *(oldName + index) = 0;
	     const char* newName = oldName + index + 1;
	     if (strlen(oldName) > 0 && strlen(newName) > 0)
	       {
		 cChannelGroup *changrp = ChannelGroups.GetGroupByName(oldName);
		 if (changrp)
		   {
		     strcpy(changrp->name, newName);
		     cMutexLock SearchExtsLock(&SearchExts);
		     cSearchExt *SearchExt = SearchExts.First();
		     while (SearchExt)
		       {
			 if (SearchExt->useChannel == 2 &&
			     SearchExt->channelGroup &&
			     strcmp(SearchExt->channelGroup, oldName) == 0)
			   {
			     free(SearchExt->channelGroup);
			     SearchExt->channelGroup = strdup(newName);
			   }
			 SearchExt = SearchExts.Next(SearchExt);
		       }
		     ChannelGroups.Save();
		     SearchExts.Save();
		     cString strReturn = cString::sprintf("renamed channel group '%s' to '%s'", oldName, newName);
		     free(oldName);
		     return strReturn;

		   }
		 else
		   {
		     free(oldName);
		     ReplyCode = 901;
		     return cString::sprintf("channel group '%s' not defined", Option);
		   }
	       }
	     free(oldName);
	   }
         ReplyCode = 901;
         return cString("Error in channel group parameters");
      }
      else
      {
         ReplyCode = 901;
         return cString("missing channel group parameters");
      }
   }
   // --------------------
   // blacklist management
   else if (strcasecmp(Command, "LSTB") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cBlacklist *blacklist = Blacklists.GetBlacklistFromID(atol(Option));
            if (blacklist)
               return cString(blacklist->ToText());
            else
            {
               ReplyCode = 901;
               return cString::sprintf("blacklist id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in blacklist ID \"%s\"", Option);
         }
      }
      else if (Blacklists.Count()>0)
      {
         cMutexLock BlacklistLock(&Blacklists);
         string sBuffer;
         for (int i = 0; i < Blacklists.Count(); i++)
         {
            cBlacklist *blacklist = Blacklists.Get(i);
            if (blacklist)
               sBuffer += string(blacklist->ToText()) + string((i<Blacklists.Count()-1)?"\n":"");
         }
         return sBuffer.c_str();
      }
      else
      {
         ReplyCode = 901;
         return cString("no blacklists defined");
      }
   }
   else if (strcasecmp(Command, "DELB") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cBlacklist *blacklist = Blacklists.GetBlacklistFromID(atol(Option));
            if (blacklist)
            {
               LogFile.Log(1,"blacklist '%s' deleted via SVDRP", blacklist->search);
               SearchExts.RemoveBlacklistID( blacklist->ID);
               cMutexLock BlacklistLock(&Blacklists);
               Blacklists.Del(blacklist);
               Blacklists.Save();
               RecsDone.RemoveSearchID(atol(Option));
               return cString::sprintf("blacklist id %s deleted", Option);
            }
            else
            {
               ReplyCode = 901;
               return cString::sprintf("blacklist id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in blacklist ID \"%s\"", Option);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing blacklist ID");
      }
   }
   else if (strcasecmp(Command, "NEWB") == 0)
   {
      if (*Option)
      {
         cBlacklist *blacklist = new cBlacklist;
         if (blacklist->Parse(Option))
         {
            blacklist->ID = Blacklists.GetNewID();
            LogFile.Log(1,"added blacklist '%s' (%d) via SVDRP", blacklist->search, blacklist->ID);
            cMutexLock BlacklistLock(&Blacklists);
            Blacklists.Add(blacklist);
            Blacklists.Save();
            return cString::sprintf("blacklist '%s' (with new ID %d) added", blacklist->search, blacklist->ID);
         }
         else
         {
            ReplyCode = 901;
            delete blacklist;
            return cString("Error in blacklist settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing blacklist settings");
      }
   }
   else if (strcasecmp(Command, "EDIB") == 0)
   {
      if (*Option)
      {
         cBlacklist *blacklist = new cBlacklist;
         if (blacklist->Parse(Option))
         {
            cBlacklist *blacklistTemp = Blacklists.GetBlacklistFromID(blacklist->ID);
            if (blacklistTemp)
            {
               blacklistTemp->Parse(Option);
               LogFile.Log(1,"modified blacklist '%s' (%d) via SVDRP", blacklistTemp->search, blacklistTemp->ID);
               Blacklists.Save();
               return cString::sprintf("blacklist '%s' with ID %d modified", blacklistTemp->search, blacklistTemp->ID);
            }
            else
            {
               ReplyCode = 901;
               int ID = blacklist->ID;
               delete blacklist;
               return cString::sprintf("blacklist id %d does not exists", ID);
            }
         }
         else
         {
            ReplyCode = 901;
            delete blacklist;
            return cString("Error in blacklist settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing blacklist settings");
      }
   }
   // ----------------------------------
   // extended EPG categories management
   else if (strcasecmp(Command, "LSTE") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cSearchExtCat *SearchExtCat = NULL;
            int index = SearchExtCats.GetIndexFromID(atoi(Option));
            if (index >= 0) SearchExtCat = SearchExtCats.Get(index);
            if (SearchExtCat)
               return cString(SearchExtCat->ToText());
            else
            {
               ReplyCode = 901;
               return cString::sprintf("category id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in category ID \"%s\"", Option);
         }
      }
      else if (SearchExtCats.Count()>0)
      {
         string sBuffer;
         for (int i = 0; i < SearchExtCats.Count(); i++)
         {
            cSearchExtCat *SearchExtCat = SearchExtCats.Get(i);
            if (SearchExtCat)
               sBuffer += string(SearchExtCat->ToText()) + string((i<SearchExtCats.Count()-1)?"\n":"");
         }
         return sBuffer.c_str();
      }
      else
      {
         ReplyCode = 901;
         return cString("no EPG categories defined");
      }
   }
   // ------------
   // setup values
   else if (strcasecmp(Command, "SETP") == 0)
   {
      if (*Option)
      {
         if (strcasecmp(Option, "ShowFavoritesMenu") == 0)
            return cString::sprintf("%d", EPGSearchConfig.showFavoritesMenu);
         else if (strcasecmp(Option, "UseSearchTimers") == 0)
            return cString::sprintf("%d", EPGSearchConfig.useSearchTimers);
         else if (strcasecmp(Option, "DefRecordingDir") == 0)
         {
            if (strlen(EPGSearchConfig.defrecdir)>0)
               return cString::sprintf("%s", EPGSearchConfig.defrecdir);
            else
            {
               ReplyCode = 901;
               return cString::sprintf("empty");
            }
         }
         else if (strcasecmp(Option, "AddSubtitleToTimerMode") == 0)
            return cString::sprintf("%d", EPGSearchConfig.addSubtitleToTimer);
         else if (strcasecmp(Option, "DefPriority") == 0)
            return cString::sprintf("%d", EPGSearchConfig.DefPriority);
         else if (strcasecmp(Option, "DefLifetime") == 0)
            return cString::sprintf("%d", EPGSearchConfig.DefLifetime);
         else if (strcasecmp(Option, "DefMarginStart") == 0)
            return cString::sprintf("%d", EPGSearchConfig.DefMarginStart);
         else if (strcasecmp(Option, "DefMarginStop") == 0)
            return cString::sprintf("%d", EPGSearchConfig.DefMarginStop);
         else if (strcasestr(Option, "DefTimerCheckMethod") == Option)
         {
            tChannelID chID;
            if (strlen(Option) > strlen("DefTimerCheckMethod")+1)
            {
               chID = tChannelID::FromString(Option + strlen("DefTimerCheckMethod")+1);
               if (!chID.Valid())
               {
                  ReplyCode = 901;
                  return cString::sprintf("invalid channel id");
               }
               cChannel *ch = Channels.GetByChannelID(chID,true,true);
               if (!ch)
               {
                  ReplyCode = 901;
                  return cString::sprintf("unknown channel");
               }
               return cString::sprintf("%s: %d", *ch->GetChannelID().ToString(), DefTimerCheckModes.GetMode(ch));
            }
            else
            {
               string sBuffer;
               for (int i = 0; i < Channels.Count(); i++)
               {
                  cChannel* ch = Channels.Get(i);
                  if (ch && !ch->GroupSep())
                     sBuffer += string(*ch->GetChannelID().ToString()) + string(": ") + NumToString(DefTimerCheckModes.GetMode(ch)) + string((i<Channels.Count()-1)?"\n":"");
               }
               return sBuffer.c_str();
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("setup option not supported");
         }
      }
      else
      {
         string sBuffer;
         sBuffer += "ShowFavoritesMenu: " + NumToString(EPGSearchConfig.showFavoritesMenu) + "\n";
         sBuffer += "UseSearchTimers: " + NumToString(EPGSearchConfig.useSearchTimers) + "\n";
         sBuffer += "DefRecordingDir: " + string(EPGSearchConfig.defrecdir) + "\n";
         sBuffer += "AddSubtitleToTimerMode: " + NumToString(EPGSearchConfig.addSubtitleToTimer) + "\n";
         sBuffer += "DefPriority: " + NumToString(EPGSearchConfig.DefPriority) + "\n";
         sBuffer += "DefLifetime: " + NumToString(EPGSearchConfig.DefLifetime) + "\n";
         sBuffer += "DefMarginStart: " + NumToString(EPGSearchConfig.DefMarginStart) + "\n";
         sBuffer += "DefMarginStop: " + NumToString(EPGSearchConfig.DefMarginStop);

         return sBuffer.c_str();
      }
   }
   // ---------------------------------
   // search timer templates management
   else if (strcasecmp(Command, "LSTT") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cSearchExt *search = SearchTemplates.GetSearchFromID(atol(Option));
            if (search)
               return cString(search->ToText());
            else
            {
               ReplyCode = 901;
               return cString::sprintf("search template id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in search template ID \"%s\"", Option);
         }
      }
      else if (SearchTemplates.Count()>0)
      {
         string sBuffer;
         cMutexLock SearchExtsLock(&SearchTemplates);
         for (int i = 0; i < SearchTemplates.Count(); i++)
         {
            cSearchExt* search = SearchTemplates.Get(i);
            if (search)
               sBuffer += string(search->ToText()) + string((i<SearchTemplates.Count()-1)?"\n":"");
         }
         return sBuffer.c_str();
      }
      else
      {
         ReplyCode = 901;
         return cString("no search templates defined");
      }
   }
   else if (strcasecmp(Command, "DELT") == 0)
   {
      if (*Option)
      {
         if (isnumber(Option))
         {
            cSearchExt *search = SearchTemplates.GetSearchFromID(atoi(Option));
            if (search)
            {
               LogFile.Log(1,"search template '%s' deleted via SVDRP", search->search);
               cMutexLock SearchExtsLock(&SearchTemplates);
               SearchTemplates.Del(search);
               SearchTemplates.Save();
               return cString::sprintf("search template id %s deleted", Option);
            }
            else
            {
               ReplyCode = 901;
               return cString::sprintf("search template id %s not defined", Option);
            }
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("Error in search template ID \"%s\"", Option);
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search template ID");
      }
   }
   else if (strcasecmp(Command, "NEWT") == 0)
   {
      if (*Option)
      {
         cSearchExt* search = new cSearchExt;
         if (search->Parse(Option))
         {
            search->ID = SearchTemplates.GetNewID();
            LogFile.Log(1,"added search template '%s' (%d) via SVDRP", search->search, search->ID);
            cMutexLock SearchExtsLock(&SearchTemplates);
            SearchTemplates.Add(search);
            SearchTemplates.Save();
            return cString::sprintf("search template '%s' (with new ID %d) added", search->search, search->ID);
         }
         else
         {
            ReplyCode = 901;
            delete search;
            return cString("Error in search template settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search template settings");
      }
   }
   else if (strcasecmp(Command, "EDIT") == 0)
   {
      if (*Option)
      {
         cSearchExt* search = new cSearchExt;
         if (search->Parse(Option))
         {
            cSearchExt *searchTemp = SearchTemplates.GetSearchFromID(search->ID);
            if (searchTemp)
            {
               searchTemp->Parse(Option);
               LogFile.Log(1,"modified search template '%s' (%d) via SVDRP", searchTemp->search, searchTemp->ID);
               SearchTemplates.Save();
               return cString::sprintf("search template '%s' with ID %d modified", searchTemp->search, searchTemp->ID);
            }
            else
            {
               ReplyCode = 901;
               int ID = search->ID;
               delete search;
               return cString::sprintf("search template id %d does not exists", ID);
            }
         }
         else
         {
            ReplyCode = 901;
            delete search;
            return cString("Error in search template settings");
         }
      }
      else
      {
         ReplyCode = 901;
         return cString("missing search template settings");
      }
   }
   else if (strcasecmp(Command, "DEFT") == 0)
   {
      if (*Option)
      {
         cSearchExt *searchTemp = SearchTemplates.GetSearchFromID(atoi(Option));
         if (searchTemp)
         {
            LogFile.Log(1,"set search template '%s' (%d) as default via SVDRP", searchTemp->search, searchTemp->ID);
            EPGSearchConfig.DefSearchTemplateID = searchTemp->ID;
            cPluginManager::GetPlugin("epgsearch")->SetupStore("DefSearchTemplateID",  EPGSearchConfig.DefSearchTemplateID);
            return cString::sprintf("search template '%s' with ID %d set as default", searchTemp->search, searchTemp->ID);
         }
         else
         {
            ReplyCode = 901;
            return cString::sprintf("search template id %s does not exists", Option);
         }
      }
      else
         return cString::sprintf("%d", EPGSearchConfig.DefSearchTemplateID);
   }

   // ---------------------------------
   // timer conflicts
   else if (strcasecmp(Command, "LSCC") == 0)
   {
     bool relOnly = false;
     if (*Option && strcasecmp(Option, "REL") == 0)
       relOnly = true;

     cConflictCheck conflictCheck;
     conflictCheck.Check();

     if ((relOnly && conflictCheck.numConflicts > 0) ||
	 conflictCheck.relevantConflicts > 0)
       {
         string sBuffer;
	 cList<cConflictCheckTime>* failedList = conflictCheck.GetFailed();
	 for(cConflictCheckTime* ct = failedList->First(); ct; ct = failedList->Next(ct))
	   {
	     if (relOnly && ct->ignore) continue;

	     std::ostringstream conflline;
	     conflline << ct->evaltime << ":";
	     std::set<cConflictCheckTimerObj*,TimerObjSort>::iterator it;

	     std::ostringstream timerparts;
	     for (it = ct->failedTimers.begin(); it != ct->failedTimers.end(); ++it)
	       {
		 if (relOnly && (*it)->ignore) continue;
		 std::ostringstream timerpart;
		 int recPart = (*it)->recDuration * 100 / ((*it)->stop - (*it)->start);
		 timerpart << (*it)->origIndex+1 << "|" << recPart << "|";
		 std::set<cConflictCheckTimerObj*,TimerObjSort>::iterator itcc;
		 if ((*it)->concurrentTimers)
		   {
		   std::ostringstream cctimers;
		   for (itcc = (*it)->concurrentTimers->begin(); itcc != (*it)->concurrentTimers->end(); ++itcc)
		     cctimers << (cctimers.str().empty()?"":"#") << (*itcc)->origIndex+1;
		   timerpart << cctimers.str();
		   }
		 timerparts << (timerparts.str().empty()?"":":") << timerpart.str();
	       }
	     conflline << timerparts.str();
	     sBuffer += conflline.str() + "\n";
	   }
	 return sBuffer.c_str();
       }
     else
       {
         ReplyCode = 901;
         return cString("no conflicts found");
       }
   }
   else if (strcasecmp(Command, "MENU") == 0)
     {
       if (*Option)
	 {
	   if (cMenuSearchMain::forceMenu == 0)
	     {
	       if (strcasecmp(Option, "PRG") == 0)
		 cMenuSearchMain::forceMenu = 2;
	       else if (strcasecmp(Option, "NOW") == 0)
		 cMenuSearchMain::forceMenu = 1;
	       else if (strcasecmp(Option, "SUM") == 0)
		 cMenuSearchMain::forceMenu = 3;
	       else
		 {
		   ReplyCode = 901;
		   return cString::sprintf("unknown option '%s'", Option);
		 }
	       cRemote::CallPlugin("epgsearch");
	       return "menu called";
	     }
	   else
	     {
	       cRemote::Put(kBack);
	       exitToMainMenu = 1;
	       return "menu closed";
	     }
	 }
     }

   return NULL;
}