:pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
[gnokii.git] / gnokiid / gnokiid.c
1 /*
2
3   $Id$
4   
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml.
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13   Mainline code for gnokiid daemon. Handles command line parsing and
14   various daemon functions.
15
16   $Log$
17   Revision 1.1.1.1  2001/11/25 21:59:18  short
18   :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
19
20   Revision 1.19  2001/06/28 00:28:45  pkot
21   Small docs updates (Pawel Kot)
22
23   Revision 1.18  2001/02/21 19:57:09  chris
24   More fiddling with the directory layout
25
26   Revision 1.17  2000/12/19 16:18:18  pkot
27   configure script updates and added shared function for configfile reading
28
29   
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <termios.h>
36 #include <fcntl.h>
37 #include <signal.h>
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <string.h>
41
42 #include "misc.h"
43 #include "cfgreader.h"
44 #include "gsm-common.h"
45 #include "gsm-api.h"
46 #include "data/virtmodem.h"
47
48
49 /* Global variables */
50 bool     DebugMode;       /* When true, run in debug mode */
51 char     *Model;          /* Model from .gnokiirc file. */
52 char     *Port;           /* Serial port from .gnokiirc file */
53 char     *Initlength;     /* Init length from .gnokiirc file */
54 char     *Connection;     /* Connection type from .gnokiirc file */
55 char     *BinDir;         /* Directory of the mgnokiidev command */
56 bool     TerminateThread;
57
58 /* Local variables */
59 char     *DefaultConnection = "serial";
60 char     *DefaultBinDir = "/usr/local/sbin";
61
62 void version(void)
63 {
64
65         fprintf(stdout, _("gnokiid Version %s\n"
66 "Copyright (C) Hugh Blemings <hugh@blemings.org>, 1999\n"
67 "Copyright (C) Pavel Janík ml. <Pavel.Janik@suse.cz>, 1999\n"
68 "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, Model, Port);
69 }
70
71 /* The function usage is only informative - it prints this program's usage and
72    command-line options.*/
73
74 void usage(void)
75 {
76
77         fprintf(stdout, _("   usage: gnokiid {--help|--version}\n"
78 "          --help            display usage information."
79 "          --version         displays version and copyright information."
80 "          --debug           uses stdin/stdout for virtual modem comms.\n"));
81 }
82
83 /* Main function - handles command line arguments, passes them to separate
84    functions accordingly. */
85
86 int main(int argc, char *argv[])
87 {
88
89         GSM_ConnectionType connection = GCT_Serial;
90
91         /* For GNU gettext */
92
93 #ifdef USE_NLS
94         textdomain("gnokii");
95 #endif
96
97         if (readconfig(&Model, &Port, &Initlength, &Connection, &BinDir) < 0) {
98                 exit(-1);
99         }
100
101
102         /* Handle command line arguments. */
103
104         if (argc >= 2 && strcmp(argv[1], "--help") == 0) {
105                 usage();
106                 exit(0);
107         }
108
109         /* Display version, copyright and build information. */
110
111         if (argc >= 2 && strcmp(argv[1], "--version") == 0) {
112                 version();
113                 exit(0);
114         }
115
116         if (argc >= 2 && strcmp(argv[1], "--debug") == 0) {
117                 DebugMode = true;
118         } else {
119                 DebugMode = false;
120         }
121
122         if (!strcmp(Connection, "infrared")) {
123                 connection=GCT_Infrared;
124         }
125
126         TerminateThread=false;
127
128         if (VM_Initialise(Model, Port, Initlength, connection, BinDir, DebugMode, true) == false) {
129                 exit (-1);
130         }
131
132         while (1) {
133                 if (TerminateThread==true) {
134                         VM_Terminate();
135                         exit(1);
136                 }
137                 sleep (1);
138         }
139         exit (0);
140 }