~ubuntu-branches/ubuntu/quantal/cobalt-panel-utils/quantal

« back to all changes in this revision

Viewing changes to lcd-getip.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2006-09-23 17:58:08 UTC
  • Revision ID: james.westby@ubuntu.com-20060923175808-1y364v1jk38av0yp
Tags: upstream-1.0.2
Import upstream version 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
 
3
 *
 
4
 * Use is subject to the GNU General Public License, Version 2,
 
5
 * June 1991, which is contained in the read-me file named
 
6
 * "README_GNU_GPL." This program is free software; you can
 
7
 * redistribute it and/or modify it under the terms of the GNU
 
8
 * General Public License as published by the Free Software
 
9
 * Foundation; either version 2 of the License, or (at your
 
10
 * option) any later version. This library is distributed in the
 
11
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without
 
12
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
13
 * PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
 * more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public
 
17
 * License along with this library; if not, write to the Free
 
18
 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
19
 * MA  02111-1307  USA.
 
20
 */
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <string.h>
 
24
#include <sys/stat.h>
 
25
#include <unistd.h>
 
26
#include <getopt.h>
 
27
#include "lcd.h"
 
28
#include "lcdutils.h"
 
29
 
 
30
/* FIXME - timeout needed */
 
31
#define OPTIONS "sh1:i:"
 
32
 
 
33
int main(int argc, char **argv) {
 
34
        void *lcd;
 
35
        int one, two, three, four, c, silent = 0;
 
36
        char *line, ipstr[17], ipaddr[17];
 
37
        
 
38
        extern char *optarg;
 
39
        extern int opterr;
 
40
        
 
41
        opterr = 0; /* make getopt quiet */ 
 
42
        
 
43
        lcd_setlocale();
 
44
        
 
45
        strcpy(ipaddr, "000.000.000.000");
 
46
        strcpy(ipstr, _("PRIMARY IP ADDR:"));
 
47
        
 
48
        /* we silently ignore bad options. so, only -h returns usage. */
 
49
        while ((c = getopt(argc, argv, OPTIONS)) != EOF) {
 
50
                switch (c) {
 
51
                        case 's':
 
52
                                silent++;
 
53
                                break;
 
54
                        
 
55
                        case '1':
 
56
                                strncpy(ipstr, optarg, sizeof(ipstr) - 1);
 
57
                                break;
 
58
                        
 
59
                        case 'i':
 
60
                                strncpy(ipaddr, optarg, sizeof(ipaddr) - 1);
 
61
                                lcd_rev_format(ipaddr);
 
62
                                break;
 
63
                        
 
64
                        case 'h':
 
65
                                printf(_("Usage: %s [-1 <line text>] [-i <ip addr>]\n"),argv[0]);
 
66
                                exit(0);
 
67
                                break;
 
68
                        
 
69
                        default:
 
70
                                break;
 
71
                }
 
72
        }
 
73
        
 
74
        if (!silent && (lcd_lock() < 0)) {
 
75
                printf(_("LCD in use... try again later\n"));
 
76
                exit(0);
 
77
        }
 
78
        
 
79
        if ((lcd = lcd_open(O_RDWR)) == NULL) {
 
80
                printf(_("LCD is not present\n"));
 
81
                exit(0);
 
82
        }
 
83
        
 
84
        lcd_reset(lcd);
 
85
        lcd_set(lcd, LCD_Blink_Off);
 
86
        lcd_wait_no_button(lcd);
 
87
        lcd_write(lcd, ipstr, ipaddr);
 
88
        lcd_setcursorpos(lcd, 0x40);
 
89
        lcd_wait_no_button(lcd);
 
90
        lcd_netbutton(lcd);
 
91
        
 
92
        lcd_getdisplay(lcd, NULL, &line, NULL);
 
93
        strncpy( ipaddr, line, 15 );
 
94
        lcd_close(lcd);
 
95
        if (!silent)
 
96
                lcd_unlock();
 
97
        
 
98
        sscanf(ipaddr,"%d.%d.%d.%d", &one, &two, &three, &four);
 
99
        if (one > 255) one = 0;
 
100
        if (two > 255) two = 0;
 
101
        if (three > 255) three = 0;
 
102
        if (four > 255) four = 0;
 
103
        printf("%d.%d.%d.%d",one,two,three,four);
 
104
        exit(0);
 
105
}
 
106
 
 
107