Missing includes for uClinux patches on i386
[gnokii.git] / gnokii / gnokii.c
index 9daceb9..fadf2b4 100644 (file)
@@ -11,6 +11,8 @@
 
 */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <ctype.h>
 #include <time.h>
 #include <sys/stat.h>
+#include <limits.h>
+#include <errno.h>
+
+#ifdef UCLINUX
+/* <getopt.h> or "getopt.h" would include insufficient getopt.h from uClinux */
+#include "../getopt/getopt.h"
+#endif /* UCLINUX */
 
 #ifndef VC6
   #if defined(__svr4__) || defined(__FreeBSD__)
 #include "gsm-common.h"
 #include "gsm-api.h"
 #include "gsm-networks.h"
+#ifndef UCLINUX
 #include "gsm-ringtones.h"
 #include "gsm-bitmaps.h"
 #include "gsm-wap.h"
 #include "gsm-sms.h"
 #include "gsm-datetime.h"
+#endif /* UCLINUX */
 #include "gsm-phonebook.h"
+#ifndef UCLINUX
 #include "gsm-calendar.h"
+#endif /* UCLINUX */
 #include "gsm-coding.h"
+#ifndef UCLINUX
 #include "newmodules/n6110.h"
+#endif
 #include "files/cfgreader.h"
+#ifndef UCLINUX
 #include "files/gsm-filetypes.h"
+#endif /* UCLINUX */
 #include "gnokii.h"
+#ifdef UCLINUX
+#include "data/virtmodem.h"
+#endif /* UCLINUX */
 
 #ifdef USE_NLS
   #include <locale.h>
 #endif
 
-char *model;           /* Model from .gnokiirc file. */
-char *Port;            /* Port from .gnokiirc file */
-char *Initlength;      /* Init length from .gnokiirc file */
-char *Connection;      /* Connection type from .gnokiirc file */
+static char *model;           /* Model from .gnokiirc file. */
+static char *Port;            /* Port from .gnokiirc file */
+static char *Initlength;      /* Init length from .gnokiirc file */
+static char *Connection;      /* Connection type from .gnokiirc file */
+#ifndef UCLINUX
 char *SynchronizeTime; /* If we set date and time from computer to phone (from .gnokiirc file) */
-char *BinDir;          /* Binaries directory from .gnokiirc file - not used here yet */
+#endif /* UCLINUX */
+static char *BinDir;          /* Binaries directory from .gnokiirc file - not used here yet */
 
-GSM_SMSMessage SMS[4];
+#ifndef UCLINUX
+static GSM_SMSMessage SMS[4];
+#endif /* UCLINUX */
   
+#ifndef UCLINUX
+
 char *GetProfileCallAlertString(int code) {
 
   switch (code) {
@@ -214,7 +240,7 @@ char *GetProfileCallerGroups(int code)
   return BufferProfileGroups;
 }
 
-char *print_error(GSM_Error e)
+static char *print_error(GSM_Error e)
 {
 
 //     case GE_DEVICEOPENFAILED:         return "Couldn't open specified serial device.";
@@ -264,7 +290,6 @@ char *print_error(GSM_Error e)
        }
 }
 
-
 GSM_Error GSM_ReadRingtoneFileOnConsole(char *FileName, GSM_Ringtone *ringtone)
 {
   GSM_Error error;
@@ -537,7 +562,7 @@ int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int
   return 0;
 }
 
-int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
+static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
                                   bool inter, bool unicode, bool profile, bool scale) {
 
   int w,i;
@@ -682,9 +707,11 @@ void GSM_PlayRingtoneOnConsole(GSM_Ringtone *ringtone)
   GSM->PlayTone(255*255,0);
 }
 
+#endif /* UCLINUX */
+
 /* This function shows the copyright and some informations usefull for
    debugging. */
-int version(void)
+static int version(void)
 {
 
   fprintf(stdout, _("GNOKII Version %s\n"
@@ -698,12 +725,32 @@ int version(void)
 /* The function usage is only informative - it prints this program's usage and
    command-line options. */
 
-int usage(void)
+static int usage(void)
 {
 
-  fprintf(stdout, _("   usage: gnokii [--help|--monitor [-noloop|-nl]|--version]\n"
+  fprintf(stdout, _("   usage: gnokii [--help] [--version]\n"
+  ));
+#ifndef UCLINUX
+"          gnokii --monitor [-noloop|-nl]\n"
+  ));
+#endif /* UCLINUX */
+
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --getmemory memory_type [start [end]] [-short|-v30|-v21|-v]\n"
+  ));
+#else /* UCLINUX */
+  fprintf(stdout, _(
+"          gnokii --getmemory memory_type [start [end]] [-short]\n"
+  ));
+#endif /* UCLINUX */
+
+  fprintf(stdout, _(
 "          gnokii --writephonebook [-i]\n"
+  ));
+
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --sendphonebookentry destination memory_type location\n"
 "                 [--smsc message_center_number] [--smscno message_center_index]\n"
 "                 [-s] [-v n] [-d]\n"
@@ -711,9 +758,16 @@ int usage(void)
 "                 [--smsc message_center_number] [--smscno message_center_index]\n"
 "                 [-r] [-i] [-s] [-a] [--name name]\n"
 "          gnokii --getvoicemailbox\n"
+  ));
+#endif /* UCLINUX */
+
+  fprintf(stdout, _(
 "          gnokii --getspeeddial number\n"
 "          gnokii --setspeeddial number memory_type location\n\n"
+  ));
 
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --getsms memory_type start [end] [-f file]\n"
 "          gnokii --getsmsstatus\n"
 "          gnokii --getsmsfolders\n"
@@ -814,10 +868,25 @@ int usage(void)
 "          gnokii --sendprofile destination profile_name ringtonefile\n"
 "                 picturefile [--smsc message_center_number]\n"
 "                 [--smscno message_center_index] [-s] [-v n] [-d] [--scale]\n\n"
+  ));
+#endif /* UCLINUX */
 
+  fprintf(stdout, _(
 "          gnokii --reset [soft|hard]\n"
+  ));
+
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --dialvoice number\n"
+  ));
+#endif /* UCLINUX */
+
+  fprintf(stdout, _(
 "          gnokii --cancelcall\n"
+  ));
+
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --displayoutput\n"
 "          gnokii --presskeysequence sequence\n"
 "          gnokii --backupsettings file\n"
@@ -834,8 +903,15 @@ int usage(void)
 "          gnokii --phonetests\n"
 "          gnokii --simlock\n"
 "          gnokii --getdisplaystatus\n"
+  ));
+#endif /* UCLINUX */
+
+  fprintf(stdout, _(
 "          gnokii --identify\n\n"
+  ));
 
+#ifndef UCLINUX
+  fprintf(stdout, _(
 "          gnokii --getwapbookmark location\n"
 "          gnokii --setwapbookmark title url [location]\n"
 "          gnokii --sendwapbookmark location destination\n"
@@ -870,13 +946,21 @@ int usage(void)
   ));
 #endif
 
+#endif /* UCLINUX */
+
+#ifdef UCLINUX
+  fprintf(stdout, _(
+"          gnokii --gnokiid [--debug] [<child to run> [<child args>...]]\n"
+  ));
+#endif
+
   return 0;
 }
 
 /* fbusinit is the generic function which waits for the FBUS link. The limit
    is 10 seconds. After 10 seconds we quit. */
 
-void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
+static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 {
 
   int count=0;
@@ -888,7 +972,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 #endif
 
   /* Initialise the code for the GSM interface. */     
-  error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, SynchronizeTime);
+  error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, ""/*SynchronizeTime*/);
 
   if (error != GE_NONE) {
     fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
@@ -909,7 +993,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 /* This function checks that the argument count for a given options is withing
    an allowed range. */
 
-int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
+static int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
 {
 
   int i;
@@ -943,6 +1027,8 @@ int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
           else return 1;
 }
 
+static int gnokiid(int argc, char *argv[]);
+
 /* Main function - handles command line arguments, passes them to separate
    functions accordingly. */
 
@@ -960,14 +1046,19 @@ int main(int argc, char *argv[])
 
     { "help",               no_argument,       NULL, OPT_HELP             },// Display usage.
     { "version",            no_argument,       NULL, OPT_VERSION          },// Display version and build information.
+#ifndef UCLINUX
     { "getsmsfolders",      no_argument,       NULL, OPT_GETSMSFOLDERS    },// Gets SMS folders
     { "getsmsstatus",       no_argument,       NULL, OPT_GETSMSSTATUS     },// Get SMS Folder Status
+#endif /* UCLINUX */
     { "identify",           no_argument,       NULL, OPT_IDENTIFY         },// Identify
+#ifndef UCLINUX
     { "pmon",               no_argument,       NULL, OPT_PMON             },// For development purposes: run in passive monitoring mode
     { "foogle",             no_argument,       NULL, OPT_FOOGLE           },// For development purposes: insert you function calls here
     { "getdatetime",        no_argument,       NULL, OPT_GETDATETIME      },// Get date and time mode    
     { "getalarm",           no_argument,       NULL, OPT_GETALARM         },// Get alarm    
+#endif /* UCLINUX */
     { "cancelcall",         no_argument,       NULL, OPT_CANCELCALL       },// Cancel Call    
+#ifndef UCLINUX
     { "getdisplaystatus",   no_argument,       NULL, OPT_GETDISPLAYSTATUS },// Get display status mode    
     { "allringtones",       no_argument,       NULL, OPT_ALLRINGTONES     },/* Displays names of available ringtones */    
     { "displayoutput",      no_argument,       NULL, OPT_DISPLAYOUTPUT    },/* Show texts from phone's display */
@@ -979,8 +1070,10 @@ int main(int argc, char *argv[])
     { "receivesms",         no_argument,       NULL, OPT_RECEIVESMS       },    
     { "setoperatorname",    optional_argument, NULL, OPT_SETOPERATORNAME  },/* Set downloaded operator name */    
     { "setdatetime",        optional_argument, NULL, OPT_SETDATETIME      },// Set date and time    
+#endif /* UCLINUX */
     { "writephonebook",     optional_argument, NULL, OPT_WRITEPHONEBOOK   },// Write phonebook (memory) mode
     { "reset",              optional_argument, NULL, OPT_RESET            },// Resets the phone
+#ifndef UCLINUX
     { "monitor",            optional_argument, NULL, OPT_MONITOR          },// Monitor mode
     { "setlogo",            optional_argument, NULL, OPT_SETLOGO          },// Set logo
     { "getprofile",         optional_argument, NULL, OPT_GETPROFILE       },// Show profile
@@ -993,9 +1086,11 @@ int main(int argc, char *argv[])
     { "sendphonebookentry", required_argument, NULL, OPT_SENDPHONEBOOKENTRY},
     { "savephonebookentry", required_argument, NULL, OPT_SAVEPHONEBOOKENTRY},
     { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE  },// Delete calendar note mode    
+#endif /* UCLINUX */
     { "getmemory",          required_argument, NULL, OPT_GETMEMORY        },// Get memory mode
     { "getspeeddial",       required_argument, NULL, OPT_GETSPEEDDIAL     },// Get speed dial mode
     { "setspeeddial",       required_argument, NULL, OPT_SETSPEEDDIAL     },// Set speed dial mode
+#ifndef UCLINUX
     { "getsms",             required_argument, NULL, OPT_GETSMS           },// Get SMS message mode
     { "deletesms",          required_argument, NULL, OPT_DELETESMS        },// Delete SMS message mode
     { "sendsms",            required_argument, NULL, OPT_SENDSMS          },// Send SMS message mode
@@ -1047,6 +1142,11 @@ int main(int argc, char *argv[])
     { "sniff",              optional_argument, NULL, OPT_SNIFFER    },// Will show datas from port
     { "decodefile",         required_argument, NULL, OPT_DECODEFILE },//decode input file
 #endif
+#endif /* UCLINUX */
+
+#ifdef UCLINUX
+    { "gnokiid",            optional_argument, NULL, OPT_GNOKIID          },// gnokiid mode
+#endif /* UCLINUX */
 
     { 0, 0, 0, 0},
   };
@@ -1057,6 +1157,7 @@ int main(int argc, char *argv[])
   struct gnokii_arg_len gals[] =
   {
 
+#ifndef UCLINUX
     { OPT_MONITOR,           0, 1, 0 },
 
 #ifdef SECURITY
@@ -1081,9 +1182,11 @@ int main(int argc, char *argv[])
     { OPT_SAVEPHONEBOOKENTRY,2, 9, 0 },
     { OPT_SENDPHONEBOOKENTRY,3, 9, 0 },
     { OPT_DELCALENDARNOTE,   1, 1, 0 },
+#endif /* UCLINUX */
     { OPT_GETMEMORY,         2, 4, 0 },
     { OPT_GETSPEEDDIAL,      1, 1, 0 },
     { OPT_SETSPEEDDIAL,      3, 3, 0 },
+#ifndef UCLINUX
     { OPT_GETSMS,            2, 5, 0 },
     { OPT_DELETESMS,         2, 3, 0 },
     { OPT_SENDSMS,           1,10, 0 },
@@ -1101,11 +1204,15 @@ int main(int argc, char *argv[])
     { OPT_SETRINGTONE,       1, 3, 0 },
     { OPT_GETRINGTONE,       1, 2, 0 },
     { OPT_PRESSKEYSEQUENCE,  1, 1, 0 },
+#endif /* UCLINUX */
     { OPT_RESET,             0, 1, 0 },
+#ifndef UCLINUX
     { OPT_GETPROFILE,        0, 1, 0 },
     { OPT_SETPROFILE,        3, 3, 0 },
     { OPT_SENDPROFILE,       4,10, 0 },
+#endif /* UCLINUX */
     { OPT_WRITEPHONEBOOK,    0, 1, 0 },
+#ifndef UCLINUX
     { OPT_PLAYRINGTONE,      1, 1, 0 },
     { OPT_COMPOSER,          1, 1, 0 },
     { OPT_RINGTONECONVERT,   2, 2, 0 },
@@ -1124,10 +1231,17 @@ int main(int argc, char *argv[])
     { OPT_SAVEWAPSETTINGS,   1, 9, 0 },
     { OPT_SENDWAPSETTINGS,   2, 9, 0 },
     { OPT_DIVERT,            3, 5, 0 },    
+#endif /* UCLINUX */
+
+#ifdef UCLINUX
+    { OPT_GNOKIID,           0, INT_MAX, 0 },
+#endif /* UCLINUX */
 
     { 0, 0, 0, 0 },
   };
 
+  LIVE;
+
   opterr = 0;
 
   /* For GNU gettext */
@@ -1143,7 +1257,7 @@ int main(int argc, char *argv[])
 #endif
 
     /* Read config file */
-    if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, &SynchronizeTime,false) < 0) {
+    if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, false) < 0) {
        exit(-1);
     }
 
@@ -1168,6 +1282,7 @@ int main(int argc, char *argv[])
 
     for(i = 2; i < argc; i++)
       nargv[i-2] = argv[i];
+               nargv[argc] = NULL;     /* required by gnokiid() for execv(3) */
        
     if(checkargs(c, gals, nargc)) {
 
@@ -1195,14 +1310,17 @@ int main(int argc, char *argv[])
     // Then, options with no arguments
     case OPT_HELP:                  rc = usage();                   break;
     case OPT_VERSION:               rc = version();                 break;
+#ifndef UCLINUX
     case OPT_MONITOR:               rc = monitormode(nargc, nargv); break;
     case OPT_GETSMSFOLDERS:         rc = getsmsfolders();           break;
     case OPT_GETDATETIME:           rc = getdatetime();             break;
     case OPT_GETALARM:              rc = getalarm();                break;
     case OPT_GETDISPLAYSTATUS:      rc = getdisplaystatus();        break;
     case OPT_PMON:                  rc = pmon();                    break;
+#endif /* UCLINUX */
     case OPT_WRITEPHONEBOOK:        rc = writephonebook(nargc, nargv);break;
 
+#ifndef UCLINUX
 #ifdef SECURITY
     case OPT_ENTERSECURITYCODE:     rc = entersecuritycode(optarg); break;
     case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus();   break;
@@ -1221,7 +1339,9 @@ int main(int argc, char *argv[])
     case OPT_SETDATETIME:           rc = setdatetime(nargc, nargv); break;
     case OPT_SETALARM:              rc = setalarm(nargv);           break;
     case OPT_DIALVOICE:             rc = dialvoice(optarg);         break;
+#endif /* UCLINUX */
     case OPT_CANCELCALL:            rc = cancelcall();              break;
+#ifndef UCLINUX
     case OPT_GETCALENDARNOTE:       rc = getcalendarnote(nargc, nargv);break;
     case OPT_DELCALENDARNOTE:       rc = deletecalendarnote(optarg);break;
     case OPT_SAVECALENDARNOTE:      rc = savecalendarnote(nargc, nargv);break;
@@ -1229,9 +1349,11 @@ int main(int argc, char *argv[])
     case OPT_SAVEPHONEBOOKENTRY:    rc = savephonebookentry(nargc, nargv);break;
     case OPT_SENDPHONEBOOKENTRY:    rc = sendphonebookentry(nargc, nargv);break;
     case OPT_WRITECALENDARNOTE:     rc = writecalendarnote(nargv);  break;
+#endif /* UCLINUX */
     case OPT_GETMEMORY:             rc = getmemory(nargc, nargv);   break;
     case OPT_GETSPEEDDIAL:          rc = getspeeddial(optarg);      break;
     case OPT_SETSPEEDDIAL:          rc = setspeeddial(nargv);       break;
+#ifndef UCLINUX
     case OPT_GETSMS:                rc = getsms(argc, argv);        break;
     case OPT_GETSMSSTATUS:          rc = getsmsstatus(argc, argv);  break;
     case OPT_DELETESMS:             rc = deletesms(nargc, nargv);   break;
@@ -1243,7 +1365,9 @@ int main(int argc, char *argv[])
     case OPT_GETSMSC:               rc = getsmsc(optarg);           break;
     case OPT_RENAMESMSC:            rc = renamesmsc(nargc,nargv);   break;
     case OPT_NETMONITOR:            rc = netmonitor(optarg);        break;
+#endif /* UCLINUX */
     case OPT_IDENTIFY:              rc = identify();                break;
+#ifndef UCLINUX
     case OPT_SETLOGO:               rc = setlogo(nargc, nargv);     break;
     case OPT_GETLOGO:               rc = getlogo(nargc, nargv);     break;
     case OPT_RECEIVESMS:            rc = receivesms(nargc, nargv);  break;
@@ -1268,7 +1392,9 @@ int main(int argc, char *argv[])
     case OPT_PHONETESTS:            rc = phonetests();              break;
     case OPT_SIMLOCKINFO:           rc = simlockinfo();             break;
     case OPT_SENDDTMF:              rc = senddtmf(optarg);          break;
+#endif /* UCLINUX */
     case OPT_RESET:                 rc = reset(nargc,nargv);        break;
+#ifndef UCLINUX
     case OPT_GETOPERATORNAME:       rc = getoperatorname();         break;
     case OPT_SETOPERATORNAME:       rc = setoperatorname(nargc,nargv);break;
     case OPT_GETWAPBOOKMARK:        rc = getwapbookmark(nargc,nargv);break;
@@ -1284,7 +1410,11 @@ int main(int argc, char *argv[])
     case OPT_GETVOICEMAILBOX:       rc = getvoicemailbox();         break;
     case OPT_NM_COLLECT:            rc = nm_collect(nargc, nargv);  break;
     case OPT_NETMONITORDATA:        rc = netmonitordata(nargc, nargv);break;
+#endif /* UCLINUX */
 
+#ifdef UCLINUX
+    case OPT_GNOKIID:               rc = gnokiid(nargc, nargv);     break;
+#endif /* UCLINUX */
     default:         fprintf(stderr, _("Unknown option: %d\n"), c); break;
 
     }
@@ -1299,6 +1429,8 @@ int main(int argc, char *argv[])
   exit(-1);
 }
 
+#ifndef UCLINUX
+
 /* Restores various phone settings from one file */
 int restoresettings(char *argv[])
 {
@@ -1651,7 +1783,7 @@ int sendsms(int argc, char *argv[])
     case GSM_DisableFax:
     case GSM_EnableEmail:
     case GSM_DisableEmail:
-      fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText));
+      fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
       msgnum=1;
       break;
     default:
@@ -1856,7 +1988,7 @@ int savesms(int argc, char *argv[])
     case GSM_DisableFax:
     case GSM_EnableEmail:
     case GSM_DisableEmail:
-      fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText));
+      fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
       msgnum=1;
       break;
     default:
@@ -2705,8 +2837,10 @@ int dialvoice(char *Number)
   return 0;
 }
 
+#endif /* UCLINUX */
+
 /* Cancel a call */
-int cancelcall(void)
+static int cancelcall(void)
 {
   fbusinit(NULL);
 
@@ -2717,6 +2851,8 @@ int cancelcall(void)
   return 0;
 }
 
+#ifndef UCLINUX
+
 int savelogo(int argc, char *argv[])
 {
   GSM_Bitmap bitmap;
@@ -3325,7 +3461,7 @@ int setlogo(int argc, char *argv[])
                        } else {
                          GSM->SetBitmap(&bitmap);
                          GSM->GetBitmap(&oldbit);
-                         fprintf(stderr, _("too long, truncated to \"%s\" (length %i)\n"),oldbit.text,strlen(oldbit.text));
+                         fprintf(stderr, _("too long, truncated to \"%s\" (length %ld)\n"),oldbit.text,(long)strlen(oldbit.text));
                        }
                         ok=false;
                      }
@@ -3977,6 +4113,79 @@ int monitormode(int argc, char *argv[])
   return 0;
 }
 
+#endif /* UCLINUX */
+
+/* Emulation of separate gnokiid binary for uClinux */
+
+#ifdef UCLINUX
+
+static int gnokiid(int argc, char *argv[])
+{
+       bool    DebugMode;  /* When true, run in debug mode */
+       char    *Model;   /* Model from .gnokiirc file. */
+       char    *Port;    /* Port from .gnokiirc file */
+       char    *Initlength;  /* Init length from .gnokiirc file */
+       char    *Connection;  /* Connection type from .gnokiirc file */
+       char    *BinDir;  /* Directory of the mgnokiidev command */
+
+       /* evaluate for presence of "--debug" argument in parameter */
+       DebugMode = false;
+       if(argc>0)
+       {
+               if( !strcmp(argv[0],"--debug" ))
+               {
+                       DebugMode = true;
+                       argv++;
+                       argc--;
+               }
+       }
+
+#ifdef DEBUG
+  fprintf (stderr, _("Initializing gnokiid mode...\n"));
+#endif
+
+       if (CFG_ReadConfig(&Model, &Port, &Initlength, &Connection, &BinDir, true) < 0)
+               return(-1);
+
+  if (VM_Initialise(Model, Port, Initlength, GCT_FBUS, BinDir, DebugMode, true, ""/*SynchronizeTime*/) == false)
+               return (-1);
+
+       if (argc>0) {
+#ifdef DEBUG
+               fprintf (stderr, _("Spawning gnokiid startup child process \"%s\"...\n"), *argv);
+#endif
+               /* default action for SIGCHLD is SIG_IGN, should be OK */
+               errno=0;
+               switch (vfork()) {
+                       case -1: /* vfork() failure */
+                               fprintf (stderr, _("vfork() failed! (%m)\n"));
+                               return -1;
+                       case 0: /* child */
+                               execv(*argv,argv);
+                               fprintf (stderr, _("Spawn of child process failed! (%m)\n"));
+                               _exit(9);
+                               break;
+                       default: /* parent */
+                               /* PASSTHRU */
+                               break;
+                       }
+               }
+
+#ifdef DEBUG
+  fprintf (stderr, _("Entering gnokiid virtual modem main loop...\n"));
+#endif
+
+       VM_ThreadLoop();
+
+       VM_Terminate();
+
+  return 0;
+}
+
+#endif /* UCLINUX */
+
+#ifndef UCLINUX
+
 /* Shows texts from phone's display */
 
 int displayoutput()
@@ -4461,10 +4670,12 @@ int setprofile(int argc, char *argv[])
 
 }
 
+#endif /* UCLINUX */
+
 /* Get requested range of memory storage entries and output to stdout in
    easy-to-parse format */
 
-int getmemory(int argc, char *argv[])
+static int getmemory(int argc, char *argv[])
 {
 
   GSM_PhonebookEntry entry;
@@ -4492,6 +4703,7 @@ int getmemory(int argc, char *argv[])
     fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]);
     return (-1);
   }
+
   GetMemoryTypeString(memory_type_string, &entry.MemoryType);
 
   if (argv[argc-1][0] == '-')
@@ -4539,6 +4751,7 @@ int getmemory(int argc, char *argv[])
        i_used++;
       else if (do_all)
        break;
+#ifndef UCLINUX
       if (output_opt && !strcmp( output_opt,"-v30")) {
        semicolon_pipe_substitution( &entry, 0 );
         fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,30));
@@ -4554,6 +4767,7 @@ int getmemory(int argc, char *argv[])
         fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,10));
        formatdone=true;
       } 
+#endif /* UCLINUX */
       if (output_opt && !strcmp(output_opt,"-short")) {
         semicolon_pipe_substitution( &entry, 0 );
         fprintf(stdout, "%s;%s;%s;%d;%d;", entry.Name, entry.Number, memory_type_string, entry.Location, entry.Group);
@@ -4696,7 +4910,7 @@ int getmemory(int argc, char *argv[])
 /* Read data from stdin, parse and write to phone.  The parsing is relatively
    crude and doesn't allow for much variation from the stipulated format. */
 
-int writephonebook(int argc, char *args[])
+static int writephonebook(int argc, char *args[])
 {
 
   GSM_PhonebookEntry entry;
@@ -4912,7 +5126,7 @@ int writephonebook(int argc, char *args[])
 
 /* Getting speed dials. */
 
-int getspeeddial(char *Number) {
+static int getspeeddial(char *Number) {
 
   GSM_SpeedDial entry;
   GSM_Error error;
@@ -4945,7 +5159,7 @@ int getspeeddial(char *Number) {
 
 /* Setting speed dials. */
 
-int setspeeddial(char *argv[]) {
+static int setspeeddial(char *argv[]) {
 
   GSM_SpeedDial entry;
 
@@ -4981,6 +5195,8 @@ int setspeeddial(char *argv[]) {
   return 0;
 }
 
+#ifndef UCLINUX
+
 /* Getting the status of the display. */
 
 int getdisplaystatus()
@@ -5040,29 +5256,42 @@ int netmonitor(char *Mode)
   return 0;
 }
 
-int identify( void )
+#endif /* UCLINUX */
+
+static int identify( void )
 {
   /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
   char imei[64], model[64], rev[64], manufacturer[64];
 
+  LIVE;
   fbusinit(NULL);
 
+  LIVE;
   while (GSM->GetIMEI(imei)    != GE_NONE) sleep(1);
+  LIVE;
   while (GSM->GetRevision(rev) != GE_NONE) sleep(1);
+  LIVE;
   while (GSM->GetModel(model)  != GE_NONE) sleep(1);
+  LIVE;
 
   strcpy(manufacturer, "(unknown)");
+  LIVE;
   GSM->GetManufacturer(manufacturer);
+  LIVE;
 
   fprintf(stdout, _("IMEI:     %s\n"), imei);
   fprintf(stdout, _("Model:    %s %s (%s)\n"), manufacturer, GetModelName (model), model);
   fprintf(stdout, _("Revision: %s\n"), rev);
 
+  LIVE;
   GSM->Terminate();
+  LIVE;
 
   return 0;
 }
 
+#ifndef UCLINUX
+
 int senddtmf(char *String)
 {
 
@@ -5075,8 +5304,10 @@ int senddtmf(char *String)
   return 0;
 }
 
+#endif /* UCLINUX */
+
 /* Resets the phone */
-int reset(int argc, char *argv[])
+static int reset(int argc, char *argv[])
 {
 
   unsigned char _type=0x03;
@@ -5104,6 +5335,8 @@ int reset(int argc, char *argv[])
   return 0;
 }
 
+#ifndef UCLINUX
+
 /* This is a "convenience" function to allow quick test of new API stuff which
    doesn't warrant a "proper" command line function. */
 
@@ -5147,7 +5380,7 @@ int pmon()
 
   /* Initialise the code for the GSM interface. */     
 
-  error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, SynchronizeTime);
+  error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, ""/*SynchronizeTime*/);
 
   if (error != GE_NONE) {
     fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
@@ -7558,32 +7791,32 @@ int binringtoneconvert(int argc, char *argv[])
            w=w*2;
            if (w>z && (w/2)<=z) {
              switch (m) {
-               case 1:fprintf(file,_("16"));break;\r
-               case 2:fprintf(file,_("8"));break;\r
-               case 3:fprintf(file,_("4"));break;\r
-               case 4:fprintf(file,_("2"));break;\r
-               case 5:fprintf(file,_("1"));break;\r
+               case 1:fprintf(file,_("16"));break;
+               case 2:fprintf(file,_("8"));break;
+               case 3:fprintf(file,_("4"));break;
+               case 4:fprintf(file,_("2"));break;
+               case 5:fprintf(file,_("1"));break;
              }
              break;
            }
          }
          if (z>w) fprintf(file,_("1"));
          pause=false;
-          switch (GSM_GetNote(j)) {\r
-            case Note_C  :fprintf(file,_("c"));break;\r
-            case Note_Cis:fprintf(file,_("c#"));break;\r
-            case Note_D  :fprintf(file,_("d"));break;\r
-            case Note_Dis:fprintf(file,_("d#"));break;\r
-            case Note_E  :fprintf(file,_("e"));break;\r
-            case Note_F  :fprintf(file,_("f"));break;\r
-            case Note_Fis:fprintf(file,_("f#"));break;\r
-            case Note_G  :fprintf(file,_("g"));break;\r
-            case Note_Gis:fprintf(file,_("g#"));break;\r
-            case Note_A  :fprintf(file,_("a"));break;\r
-            case Note_Ais:fprintf(file,_("a#"));break;\r
-            case Note_H  :fprintf(file,_("h"));break;\r
-            default      :pause=true;fprintf(file,_("p"));break; //Pause ?\r
-          }\r
+          switch (GSM_GetNote(j)) {
+            case Note_C  :fprintf(file,_("c"));break;
+            case Note_Cis:fprintf(file,_("c#"));break;
+            case Note_D  :fprintf(file,_("d"));break;
+            case Note_Dis:fprintf(file,_("d#"));break;
+            case Note_E  :fprintf(file,_("e"));break;
+            case Note_F  :fprintf(file,_("f"));break;
+            case Note_Fis:fprintf(file,_("f#"));break;
+            case Note_G  :fprintf(file,_("g"));break;
+            case Note_Gis:fprintf(file,_("g#"));break;
+            case Note_A  :fprintf(file,_("a"));break;
+            case Note_Ais:fprintf(file,_("a#"));break;
+            case Note_H  :fprintf(file,_("h"));break;
+            default      :pause=true;fprintf(file,_("p"));break; //Pause ?
+          }
          w=deflen*1.5;
          for (m=0;m<6;m++) {
            w=w*2;
@@ -7643,11 +7876,13 @@ int renamesmsc(int argc, char *argv[])
   return 0;
 }
 
+#endif /* UCLINUX */
+
 /*
  * Returns number of sostituited characters.
  * ... may be useful one day ??
  */
-int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction )
+static int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction )
        /* direction = 0 : after reading phone memory (
         *             1 : writing phone memory
         */
@@ -7683,6 +7918,10 @@ int str_substch( char *str, const char toric, const char sost )
        return( i_sost );
 }                                                                               
 
+#ifndef UCLINUX
+
+extern GSM_Error N6110_EnableExtendedCommands (unsigned char status);
+
 /* Allows to set simlock state.
    With older phone (older 51xx, 61xx) can open them, with older
    and newer should be able to close them */
@@ -7722,11 +7961,11 @@ int setsimlock()
     fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
   }
   /* Opening all locks (we must check, if we can open them) */
-  NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer0);
-  openbuffer[4]=1;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=2;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=4;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=8;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
+  openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
   if (GSM->SimlockInfo(&siml)!=GE_NONE) {
     fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
   }
@@ -7775,13 +8014,13 @@ int setsimlock()
   }  
   /* Closing simlock with given values */
   closebuffer[4]=1+2+4+8;
-  NULL_SendMessageSequence\r(50, &CurrentMagicError, 20, 0x40,closebuffer);  
+  NULL_SendMessageSequence(50, &CurrentMagicError, 20, 0x40,closebuffer);  
   /* Opening all locks */
-  NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer0);
-  openbuffer[4]=1;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=2;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=4;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=8;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
+  openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
   GSM->Reset(0x03);
   GSM->Terminate();
   return 0;
@@ -7881,7 +8120,7 @@ int geteeprom()
     
     if ((i/256)!=((i-1)/256)) fprintf(stderr,_("."));
     
-    if (NULL_SendMessageSequence(50, &CurrentMagicError, 9, 0x40,buffer)!=GE_NONE)\r      break;
+    if (NULL_SendMessageSequence(50, &CurrentMagicError, 9, 0x40,buffer)!=GE_NONE)       break;
 
     i=i+0x10;
   }
@@ -8682,9 +8921,12 @@ int savephonebookentry(int argc, char *argv[])
     case GE_NONE:
 
       /* Put entry into SMS structure */
+#ifndef UCLINUX
       if (GetModelFeature(FN_PHONEBOOK)==F_PBK71) {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21);
-      } else {
+      } else
+#endif /* UCLINUX */
+                               {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10);
       }
 
@@ -8746,3 +8988,5 @@ int sendphonebookentry(int argc, char *argv[])
 
   return 0;
 }
+
+#endif /* UCLINUX */