File: main.c

package info (click to toggle)
dnprogs 2.52
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,644 kB
  • ctags: 4,021
  • sloc: ansic: 26,737; cpp: 10,666; makefile: 832; sh: 537; awk: 13
file content (89 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (8)
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
/*
 * phone.c
 * This is the 'phone' client program run by users.
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "phone_ncurses.h"
#ifdef HAVE_GTK
extern int gtk_phone_init(int argc, char *argv[]);
extern int gtk_phone_run(char *);
#endif

// Print a usage message.
static void usage(char *name, FILE *f)
{
    fprintf(f, "\nusage: %s [OPTIONS] infile", name);

    fprintf(f, "\n\n");
    fprintf(f, " Options\n");
    fprintf(f, "  -? -h        display this help message\n");
    fprintf(f, "  -v           verbose operation.\n");
    fprintf(f, "  -V           show version number.\n");
    fprintf(f, "  -s <char>    set switch hook character.\n");
#ifdef HAVE_GTK
    fprintf(f, "  -n           disable X-windows interface.\n");
#endif
    fprintf(f, "\n");
}

//
// You are here...
//
//
int main(int argc, char *argv[])
{
    char hook_char = '%'; // Default switch hook character
    char opt;
    int  enable_x = 1; // Not written yet.
    
    opterr = 0;
    optind = 0;
    while ((opt=getopt(argc,argv,"?Vhns:")) != EOF)
    {
	switch(opt)
	{
	case 'h': 
	    usage(argv[0], stdout);
	    exit(0);

	case '?': // Called if getopt doesn't recognise the option
	    usage(argv[0], stderr);
	    exit(0);

	case 'V':
	    printf("\nphone from dnprogs version %s\n\n", VERSION);
	    exit(0);

	case 's':
	    hook_char = optarg[0];
	    break;
	    
	case 'n':
	    enable_x = 0;
	    break;
	}
    }

    // argv[optind] is an initial command to pass to the UI so commands
    // like "phone answer" and "phone marsha::system" will work.
    
    // Check if X-Windows UI is possible
    if (enable_x)
    {
#ifdef HAVE_GTK
	if (gtk_phone_init(argc, argv))
	{
	    gtk_phone_run(argv[optind]);
	    exit(0);
	}
#endif
    }

    // Otherwise use terminal UI
    ncurses_init(hook_char);
    ncurses_run(argv[optind]);
    return 1;
}