adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * This file is part of the Contiki desktop environment |
| 31 | * |
adamdunkels | fd5d2e5 | 2004-09-14 07:35:23 +0000 | [diff] [blame] | 32 | * $Id: configedit.c,v 1.14 2004/09/14 07:35:23 adamdunkels Exp $ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 36 | #include "contiki.h" |
adamdunkels | c012c56 | 2004-09-12 07:27:33 +0000 | [diff] [blame] | 37 | |
| 38 | #include "ctk-draw-service.h" |
| 39 | #include "packet-service.h" |
| 40 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 41 | #include "uip.h" |
| 42 | #include "uip_arp.h" |
| 43 | #include "resolv.h" |
| 44 | #include "ctk.h" |
| 45 | #include "ctk-draw.h" |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 46 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 47 | #include "program-handler.h" |
| 48 | |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 49 | #include "cfs.h" |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 50 | |
| 51 | #include "loader.h" |
| 52 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 53 | #include <stdio.h> |
| 54 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 55 | #include <string.h> |
| 56 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 57 | /* TCP/IP configuration window. */ |
| 58 | static struct ctk_window window; |
| 59 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 60 | #define LABELMAXWIDTH 12 |
| 61 | |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 62 | static struct ctk_label cfslabel = |
| 63 | {CTK_LABEL(0, 1, LABELMAXWIDTH, 1, "Disk driver")}; |
| 64 | static char cfs[25]; |
| 65 | static struct ctk_textentry cfstextentry = |
| 66 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 1, 16, 1, cfs, 24)}; |
| 67 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 68 | static struct ctk_label themelabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 69 | {CTK_LABEL(0, 3, LABELMAXWIDTH, 1, "CTK theme")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 70 | static char theme[25]; |
| 71 | static struct ctk_textentry themetextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 72 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 3, 16, 1, theme, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 73 | |
| 74 | static struct ctk_label driverlabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 75 | {CTK_LABEL(0, 5, LABELMAXWIDTH, 1, "Net driver")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 76 | static char driver[25]; |
| 77 | static struct ctk_textentry drivertextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 78 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 5, 16, 1, driver, 24)}; |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 79 | |
| 80 | static struct ctk_label screensaverlabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 81 | {CTK_LABEL(0, 7, LABELMAXWIDTH, 1, "Screensaver")}; |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 82 | static char screensaver[25]; |
| 83 | static struct ctk_textentry screensavertextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 84 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 7, 16, 1, screensaver, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 85 | |
| 86 | |
| 87 | static struct ctk_label ipaddrlabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 88 | {CTK_LABEL(0, 9, LABELMAXWIDTH, 1, "IP address")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 89 | static char ipaddr[25]; |
| 90 | static struct ctk_textentry ipaddrtextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 91 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 9, 16, 1, ipaddr, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 92 | static struct ctk_label netmasklabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 93 | {CTK_LABEL(0, 11, LABELMAXWIDTH, 1, "Netmask")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 94 | static char netmask[25]; |
| 95 | static struct ctk_textentry netmasktextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 96 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 11, 16, 1, netmask, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 97 | static struct ctk_label gatewaylabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 98 | {CTK_LABEL(0, 13, LABELMAXWIDTH, 1, "Gateway")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 99 | static char gateway[25]; |
| 100 | static struct ctk_textentry gatewaytextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 101 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 13, 16, 1, gateway, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 102 | static struct ctk_label dnsserverlabel = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 103 | {CTK_LABEL(0, 15, LABELMAXWIDTH, 1, "DNS server")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 104 | static char dnsserver[25]; |
| 105 | static struct ctk_textentry dnsservertextentry = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 106 | {CTK_TEXTENTRY(LABELMAXWIDTH + 1, 15, 16, 1, dnsserver, 24)}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 107 | |
| 108 | static struct ctk_button savebutton = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 109 | {CTK_BUTTON(0, 17, 12, "Save & close")}; |
adamdunkels | f9c8624 | 2003-08-29 20:31:12 +0000 | [diff] [blame] | 110 | static struct ctk_button cancelbutton = |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 111 | {CTK_BUTTON(24, 17, 6, "Cancel")}; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 112 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 113 | /*static DISPATCHER_SIGHANDLER(configedit_sighandler, s, data); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 114 | static struct dispatcher_proc p = |
| 115 | {DISPATCHER_PROC("Config editor", NULL, configedit_sighandler, NULL)}; |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 116 | static ek_id_t id;*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 117 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 118 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 119 | EK_PROCESS(p, "Config editor", EK_PRIO_NORMAL, |
| 120 | eventhandler, NULL, NULL); |
| 121 | static ek_id_t id = EK_ID_NONE; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 122 | |
| 123 | |
| 124 | /*-----------------------------------------------------------------------------------*/ |
| 125 | struct ptentry { |
| 126 | char c; |
| 127 | char * (* pfunc)(char *str); |
| 128 | }; |
| 129 | |
| 130 | /*-----------------------------------------------------------------------------------*/ |
| 131 | static char * |
| 132 | parse(char *str, struct ptentry *t) |
| 133 | { |
| 134 | struct ptentry *p; |
| 135 | |
| 136 | /* Loop over the parse table entries in t in order to find one that |
| 137 | matches the first character in str. */ |
| 138 | for(p = t; p->c != 0; ++p) { |
| 139 | if(*str == p->c) { |
| 140 | /* Skip rest of the characters up to the first space. */ |
| 141 | while(*str != ' ') { |
| 142 | ++str; |
| 143 | } |
| 144 | |
| 145 | /* Skip all spaces.*/ |
| 146 | while(*str == ' ') { |
| 147 | ++str; |
| 148 | } |
| 149 | |
| 150 | /* Call parse table entry function and return. */ |
| 151 | return p->pfunc(str); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /* Did not find matching entry in parse table. We just call the |
| 156 | default handler supplied by the caller and return. */ |
| 157 | return p->pfunc(str); |
| 158 | } |
| 159 | /*-----------------------------------------------------------------------------------*/ |
| 160 | static char * |
| 161 | skipnewline(char *str) |
| 162 | { |
| 163 | /* Skip all characters until the newline. */ |
| 164 | while(*str != '\n') { |
| 165 | ++str; |
| 166 | } |
| 167 | |
| 168 | /* Return a pointer to the first character after the newline. */ |
| 169 | return str + 1; |
| 170 | } |
| 171 | /*-----------------------------------------------------------------------------------*/ |
| 172 | static char * |
| 173 | nullterminate(char *str) |
| 174 | { |
| 175 | char *nt; |
| 176 | |
| 177 | /* Nullterminate string. Start with finding newline character. */ |
| 178 | for(nt = str; *nt != '\r' && |
| 179 | *nt != '\n'; ++nt); |
| 180 | |
| 181 | /* Replace newline with a null char. */ |
| 182 | *nt = 0; |
| 183 | |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 184 | /* Remove trailing spaces. */ |
| 185 | while(nt > str && *(nt - 1) == ' ') { |
| 186 | *(nt - 1) = 0; |
| 187 | --nt; |
| 188 | } |
| 189 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 190 | /* Return pointer to null char. */ |
| 191 | return nt; |
| 192 | } |
| 193 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 194 | static char * __fastcall__ |
| 195 | copystr(char *dst, char *src, int len) |
| 196 | { |
| 197 | char *nt = nullterminate(src); |
| 198 | strncpy(dst, src, len); |
| 199 | return nt + 1; |
| 200 | } |
| 201 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 202 | static char * |
| 203 | loaddriver(char *str) |
| 204 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 205 | return copystr(driver, str, sizeof(driver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 206 | } |
| 207 | /*-----------------------------------------------------------------------------------*/ |
| 208 | static char * |
| 209 | loadtheme(char *str) |
| 210 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 211 | return copystr(theme, str, sizeof(theme)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 212 | } |
| 213 | /*-----------------------------------------------------------------------------------*/ |
| 214 | static char * |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 215 | loadcfs(char *str) |
| 216 | { |
| 217 | return copystr(cfs, str, sizeof(cfs)); |
| 218 | } |
| 219 | /*-----------------------------------------------------------------------------------*/ |
| 220 | static char * |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame] | 221 | loadscreensaver(char *str) |
| 222 | { |
| 223 | return copystr(screensaver, str, sizeof(screensaver)); |
| 224 | } |
| 225 | /*-----------------------------------------------------------------------------------*/ |
| 226 | static char * |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 227 | ipaddrconf(char *str) |
| 228 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 229 | return copystr(ipaddr, str, sizeof(ipaddr)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 230 | } |
| 231 | /*-----------------------------------------------------------------------------------*/ |
| 232 | static char * |
| 233 | netmaskconf(char *str) |
| 234 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 235 | return copystr(netmask, str, sizeof(netmask)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 236 | } |
| 237 | /*-----------------------------------------------------------------------------------*/ |
| 238 | static char * |
| 239 | drconf(char *str) |
| 240 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 241 | return copystr(gateway, str, sizeof(gateway)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 242 | } |
| 243 | /*-----------------------------------------------------------------------------------*/ |
| 244 | static char * |
| 245 | dnsconf(char *str) |
| 246 | { |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 247 | return copystr(dnsserver, str, sizeof(dnsserver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 248 | } |
| 249 | /*-----------------------------------------------------------------------------------*/ |
| 250 | static struct ptentry initparsetab[] = |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 251 | {{'n', loaddriver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 252 | {'t', loadtheme}, |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 253 | {'c', loadcfs}, |
adamdunkels | 1f98271 | 2003-08-09 23:40:17 +0000 | [diff] [blame] | 254 | {'s', loadscreensaver}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 255 | {'i', ipaddrconf}, |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 256 | {'m', netmaskconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 257 | {'r', drconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 258 | {'d', dnsconf}, |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 259 | {'#', skipnewline}, |
| 260 | |
| 261 | /* Default action */ |
| 262 | {0, skipnewline}}; |
| 263 | static void |
| 264 | initscript(void) |
| 265 | { |
| 266 | char line[40], *lineptr; |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 267 | /* struct c64_fs_file f;*/ |
| 268 | int f; |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 269 | |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 270 | if((f = cfs_open("config.cfg", 0)) == -1) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | line[0] = ' '; |
| 274 | while(line[0] != '.' && |
| 275 | line[0] != 0) { |
| 276 | lineptr = line; |
| 277 | do { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 278 | if(cfs_read(f, lineptr, 1) != 1) { |
| 279 | cfs_close(f); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 280 | return; |
| 281 | } |
| 282 | ++lineptr; |
| 283 | } while(*(lineptr - 1) != '\n' && |
| 284 | *(lineptr - 1) != '\r'); |
| 285 | |
| 286 | *lineptr = 0; |
| 287 | |
| 288 | if(line[0] != '.' && |
| 289 | line[0] != 0) { |
| 290 | parse(line, initparsetab); |
| 291 | } |
| 292 | |
| 293 | } |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 294 | cfs_close(f); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 295 | return; |
| 296 | } |
| 297 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 298 | static int |
| 299 | makeline(char *line, char c, char *str) |
| 300 | { |
| 301 | int len; |
| 302 | |
| 303 | len = strlen(str); |
| 304 | |
| 305 | line[0] = c; |
| 306 | line[1] = ' '; |
| 307 | strcpy(&line[2], str); |
| 308 | line[2 + len] = '\n'; |
| 309 | line[3 + len] = 0; |
| 310 | return len + 3; |
| 311 | } |
| 312 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 313 | static void |
| 314 | savescript(void) |
| 315 | { |
| 316 | char line[40]; |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 317 | /* struct c64_fs_file f;*/ |
| 318 | int f; |
adamdunkels | fd5d2e5 | 2004-09-14 07:35:23 +0000 | [diff] [blame] | 319 | |
| 320 | f = cfs_open("@:config.cfg", CFS_WRITE); |
| 321 | if(f == -1) { |
| 322 | log_message("Could not open config.cfg", ""); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 323 | return; |
| 324 | } |
adamdunkels | fd5d2e5 | 2004-09-14 07:35:23 +0000 | [diff] [blame] | 325 | if(cfs[0] != 0) { |
| 326 | cfs_write(f, line, makeline(line, 'c', cfs)); |
| 327 | } |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 328 | if(theme[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 329 | cfs_write(f, line, makeline(line, 't', theme)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 330 | } |
| 331 | if(driver[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 332 | cfs_write(f, line, makeline(line, 'n', driver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 333 | } |
| 334 | if(ipaddr[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 335 | cfs_write(f, line, makeline(line, 'i', ipaddr)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 336 | } |
| 337 | if(netmask[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 338 | cfs_write(f, line, makeline(line, 'm', netmask)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 339 | } |
| 340 | if(gateway[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 341 | cfs_write(f, line, makeline(line, 'r', gateway)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 342 | } |
| 343 | if(dnsserver[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 344 | cfs_write(f, line, makeline(line, 'd', dnsserver)); |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if(screensaver[0] != 0) { |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 348 | cfs_write(f, line, makeline(line, 's', screensaver)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 349 | } |
| 350 | |
adamdunkels | 8178013 | 2003-08-15 18:44:26 +0000 | [diff] [blame] | 351 | strcpy(line, ".\n\0\n\n\n"); |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 352 | cfs_write(f, line, strlen(line)); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 353 | |
adamdunkels | 5abe18e | 2004-08-09 21:00:28 +0000 | [diff] [blame] | 354 | cfs_close(f); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 355 | |
| 356 | } |
| 357 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame] | 358 | LOADER_INIT_FUNC(configedit_init, arg) |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 359 | { |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame] | 360 | arg_free(arg); |
| 361 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 362 | if(id == EK_ID_NONE) { |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 363 | id = ek_start(&p); |
| 364 | } |
| 365 | } |
| 366 | /*-----------------------------------------------------------------------------------*/ |
| 367 | |
| 368 | /*-----------------------------------------------------------------------------------*/ |
| 369 | static void |
| 370 | configedit_quit(void) |
| 371 | { |
| 372 | ek_exit(); |
| 373 | id = EK_ID_NONE; |
| 374 | LOADER_UNLOAD(); |
| 375 | } |
| 376 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c012c56 | 2004-09-12 07:27:33 +0000 | [diff] [blame] | 377 | static void |
| 378 | quit_services(void) |
| 379 | { |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 380 | cfs_init_init(NULL); |
adamdunkels | c012c56 | 2004-09-12 07:27:33 +0000 | [diff] [blame] | 381 | ctk_draw_quit(); |
| 382 | } |
| 383 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 384 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 385 | { |
| 386 | EK_EVENTHANDLER_ARGS(ev, data); |
| 387 | |
| 388 | if(ev == EK_EVENT_INIT) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 389 | /* Create window. */ |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 390 | ctk_window_new(&window, 32, 18, "Config editor"); |
| 391 | |
| 392 | CTK_WIDGET_ADD(&window, &cfslabel); |
| 393 | CTK_WIDGET_ADD(&window, &cfstextentry); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 394 | |
| 395 | CTK_WIDGET_ADD(&window, &themelabel); |
| 396 | CTK_WIDGET_ADD(&window, &themetextentry); |
adamdunkels | 0ec151b | 2004-09-12 13:36:02 +0000 | [diff] [blame] | 397 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 398 | CTK_WIDGET_ADD(&window, &driverlabel); |
| 399 | CTK_WIDGET_ADD(&window, &drivertextentry); |
| 400 | |
adamdunkels | 93d8ea7 | 2003-08-09 23:27:57 +0000 | [diff] [blame] | 401 | CTK_WIDGET_ADD(&window, &screensaverlabel); |
| 402 | CTK_WIDGET_ADD(&window, &screensavertextentry); |
| 403 | |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 404 | CTK_WIDGET_ADD(&window, &ipaddrlabel); |
| 405 | CTK_WIDGET_ADD(&window, &ipaddrtextentry); |
| 406 | CTK_WIDGET_ADD(&window, &netmasklabel); |
| 407 | CTK_WIDGET_ADD(&window, &netmasktextentry); |
| 408 | CTK_WIDGET_ADD(&window, &gatewaylabel); |
| 409 | CTK_WIDGET_ADD(&window, &gatewaytextentry); |
| 410 | CTK_WIDGET_ADD(&window, &dnsserverlabel); |
| 411 | CTK_WIDGET_ADD(&window, &dnsservertextentry); |
| 412 | |
| 413 | CTK_WIDGET_ADD(&window, &savebutton); |
adamdunkels | f9c8624 | 2003-08-29 20:31:12 +0000 | [diff] [blame] | 414 | CTK_WIDGET_ADD(&window, &cancelbutton); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 415 | |
adamdunkels | fd5d2e5 | 2004-09-14 07:35:23 +0000 | [diff] [blame] | 416 | CTK_WIDGET_FOCUS(&window, &cfstextentry); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 417 | |
| 418 | /* Fill the configuration strings with values from the current |
| 419 | configuration */ |
| 420 | initscript(); |
| 421 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 422 | ctk_window_open(&window); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 423 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 424 | } else if(ev == ctk_signal_button_activate) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 425 | if(data == (ek_data_t)&savebutton) { |
| 426 | savescript(); |
adamdunkels | fd5d2e5 | 2004-09-14 07:35:23 +0000 | [diff] [blame] | 427 | quit_services(); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 428 | ctk_window_close(&window); |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 429 | configedit_quit(); |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame] | 430 | program_handler_load("config.prg", NULL); |
adamdunkels | a8a50ab | 2003-08-20 19:51:47 +0000 | [diff] [blame] | 431 | } else if(data == (ek_data_t)&cancelbutton) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 432 | ctk_window_close(&window); |
| 433 | configedit_quit(); |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 434 | } |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 435 | } else if(ev == ctk_signal_window_close || |
| 436 | ev == EK_EVENT_REQUEST_EXIT) { |
adamdunkels | 5ca1327 | 2003-08-06 22:57:05 +0000 | [diff] [blame] | 437 | ctk_window_close(&window); |
| 438 | configedit_quit(); |
| 439 | } |
| 440 | } |
| 441 | /*-----------------------------------------------------------------------------------*/ |