This commit was generated by cvs2svn to compensate for changes in r164,
[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.4  2002/04/03 01:44:15  short
18   Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
19
20   Revision 1.1.1.3  2002/04/03 00:08:17  short
21   Found in "gnokii-working" directory, some November-patches version
22
23   Revision 1.19  2001/06/28 00:28:45  pkot
24   Small docs updates (Pawel Kot)
25
26   Revision 1.18  2001/02/21 19:57:09  chris
27   More fiddling with the directory layout
28
29   Revision 1.17  2000/12/19 16:18:18  pkot
30   configure script updates and added shared function for configfile reading
31
32   
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <termios.h>
39 #include <fcntl.h>
40 #include <signal.h>
41 #include <sys/types.h>
42 #include <sys/time.h>
43 #include <string.h>
44
45 #include "misc.h"
46 #include "cfgreader.h"
47 #include "gsm-common.h"
48 #include "gsm-api.h"
49 #include "data/virtmodem.h"
50
51
52 /* Global variables */
53 bool     DebugMode;       /* When true, run in debug mode */
54 char     *Model;          /* Model from .gnokiirc file. */
55 char     *Port;           /* Serial port from .gnokiirc file */
56 char     *Initlength;     /* Init length from .gnokiirc file */
57 char     *Connection;     /* Connection type from .gnokiirc file */
58 char     *BinDir;         /* Directory of the mgnokiidev command */
59 bool     TerminateThread;
60
61 /* Local variables */
62 char     *DefaultConnection = "serial";
63 char     *DefaultBinDir = "/usr/local/sbin";
64
65 void version(void)
66 {
67
68         fprintf(stdout, _("gnokiid Version %s\n"
69 "Copyright (C) Hugh Blemings <hugh@blemings.org>, 1999\n"
70 "Copyright (C) Pavel Janík ml. <Pavel.Janik@suse.cz>, 1999\n"
71 "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, Model, Port);
72 }
73
74 /* The function usage is only informative - it prints this program's usage and
75    command-line options.*/
76
77 void usage(void)
78 {
79
80         fprintf(stdout, _("   usage: gnokiid {--help|--version}\n"
81 "          --help            display usage information."
82 "          --version         displays version and copyright information."
83 "          --debug           uses stdin/stdout for virtual modem comms.\n"));
84 }
85
86 /* Main function - handles command line arguments, passes them to separate
87    functions accordingly. */
88
89 int main(int argc, char *argv[])
90 {
91
92         GSM_ConnectionType connection = GCT_Serial;
93
94         /* For GNU gettext */
95
96 #ifdef USE_NLS
97         textdomain("gnokii");
98 #endif
99
100         if (readconfig(&Model, &Port, &Initlength, &Connection, &BinDir) < 0) {
101                 exit(-1);
102         }
103
104
105         /* Handle command line arguments. */
106
107         if (argc >= 2 && strcmp(argv[1], "--help") == 0) {
108                 usage();
109                 exit(0);
110         }
111
112         /* Display version, copyright and build information. */
113
114         if (argc >= 2 && strcmp(argv[1], "--version") == 0) {
115                 version();
116                 exit(0);
117         }
118
119         if (argc >= 2 && strcmp(argv[1], "--debug") == 0) {
120                 DebugMode = true;
121         } else {
122                 DebugMode = false;
123         }
124
125         if (!strcmp(Connection, "infrared")) {
126                 connection=GCT_Infrared;
127         }
128
129         if (!strcmp(Connection, "tcp")) {
130                 connection=GCT_TCP;
131         }
132
133         TerminateThread=false;
134
135         if (VM_Initialise(Model, Port, Initlength, connection, BinDir, DebugMode, true) == false) {
136                 exit (-1);
137         }
138
139         while (1) {
140                 if (TerminateThread==true) {
141                         VM_Terminate();
142                         exit(1);
143                 }
144                 sleep (1);
145         }
146         exit (0);
147 }