Changeset 524
- Timestamp:
- 09/23/08 00:24:37 (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
core/gui.c (modified) (2 diffs)
-
core/script.c (modified) (12 diffs)
-
doc/version.txt (modified) (1 diff)
-
include/stdlib.h (modified) (1 diff)
-
lib/ubasic/ubasic.c (modified) (2 diffs)
-
version.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/gui.c
r522 r524 835 835 static const char* modes[]={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 836 836 837 if (change != 0) 838 { 839 if (conf.script_param_save) 840 { 841 save_params_values(0); 842 } 843 conf.script_param_set += change; 844 if (conf.script_param_set < 0) conf.script_param_set = (sizeof(modes)/sizeof(modes[0]))-1; else 845 if (conf.script_param_set >= (sizeof(modes)/sizeof(modes[0]))) conf.script_param_set=0; 846 847 if (!load_params_values(conf.script_file, 1, 0)) script_load(conf.script_file, 0); 848 gui_update_script_submenu(); 849 } 837 if (change != 0) { 838 if (conf.script_param_save) { 839 save_params_values(0); 840 } 841 conf.script_param_set += change; 842 if (conf.script_param_set < 0) 843 conf.script_param_set = (sizeof(modes)/sizeof(modes[0]))-1; 844 else if (conf.script_param_set >= (sizeof(modes)/sizeof(modes[0]))) 845 conf.script_param_set=0; 846 847 if (!load_params_values(conf.script_file, 1, 0)) 848 script_load(conf.script_file, 0); 849 gui_update_script_submenu(); 850 } 850 851 851 852 return modes[conf.script_param_set]; … … 2668 2669 2669 2670 void gui_load_script_default(int arg) { 2670 script_load(conf.script_file, 0); 2671 if (conf.script_param_save) 2672 { 2671 script_load(conf.script_file, 0); 2672 if (conf.script_param_save) { 2673 2673 save_params_values(1); 2674 }} 2674 } 2675 } 2675 2676 2676 2677 -
trunk/core/script.c
r515 r524 10 10 //------------------------------------------------------------------- 11 11 12 #define SCRIPT_BUF_SIZE 819213 #define SCRIPT_PARAM_BUF_SIZE 204814 12 #define SCRIPT_CONSOLE_NUM_LINES 5 15 13 #define SCRIPT_CONSOLE_LINE_LENGTH 25 … … 22 20 char cfg_set_name[100] = "\0"; 23 21 24 static char ubasic_script_buf[SCRIPT_BUF_SIZE];25 static char ubasic_scriptparam_buf[SCRIPT_PARAM_BUF_SIZE];26 22 static const char *ubasic_script_default = 27 23 #if 0 … … 207 203 int i, fd=-1, rcnt; 208 204 register const char *ptr; 205 struct stat st; 206 char *buf; 209 207 210 208 if (fn == NULL || fn[0] == 0) return 0; … … 216 214 if (fd >= 0) 217 215 { 218 rcnt = read(fd, ubasic_scriptparam_buf, SCRIPT_PARAM_BUF_SIZE); 219 ubasic_scriptparam_buf[rcnt] = 0; 216 char s[16]; // plenty for one number 217 rcnt = read(fd, s, sizeof(s)-1); 218 s[rcnt] = 0; 220 219 close(fd); 221 conf.script_param_set = strtol( ubasic_scriptparam_buf, NULL, 0);220 conf.script_param_set = strtol(s, NULL, 0); 222 221 } else conf.script_param_set = 0; 223 222 } … … 226 225 227 226 // open and read file 227 if (stat(cfg_set_name,&st) != 0) 228 return 0; 229 buf=malloc(st.st_size+1); 230 if(!buf) 231 return 0; 228 232 fd = open(cfg_set_name, O_RDONLY, 0777); 229 if (fd < 0) return 0; 230 rcnt = read(fd, ubasic_scriptparam_buf, SCRIPT_PARAM_BUF_SIZE); 231 ubasic_scriptparam_buf[rcnt] = 0; 233 if (fd < 0) { 234 free(buf); 235 return 0; 236 } 237 rcnt = read(fd, buf, st.st_size); 238 buf[rcnt] = 0; 232 239 close(fd); 233 240 234 241 for(i = 0; i < SCRIPT_NUM_PARAMS; ++i) script_params_update[i]=0; 235 ptr = ubasic_scriptparam_buf;242 ptr = buf; 236 243 237 244 while (ptr[0]) … … 252 259 if (ptr[0]) ++ptr; 253 260 } 261 free(buf); 254 262 return 1; 255 263 } … … 259 267 { 260 268 int i, n, fd, changed=0; 261 269 char *buf,*p; 262 270 for(i = 0; i < SCRIPT_NUM_PARAMS; i++) 263 271 { … … 271 279 if (fd >= 0) 272 280 { 273 sprintf(ubasic_scriptparam_buf, " %d\n\0", conf.script_param_set); 274 write(fd, ubasic_scriptparam_buf, strlen(ubasic_scriptparam_buf)); 281 char s[20]; 282 sprintf(s, " %d\n", conf.script_param_set); 283 write(fd, s, strlen(s)); 275 284 close(fd); 276 285 } … … 278 287 // open and read file 279 288 set_params_values_name(conf.script_file, conf.script_param_set); 289 290 buf=malloc(SCRIPT_NUM_PARAMS*(28 + 20)); // max possible params * (param description + some extra for @default etc) 291 if(!buf) 292 return; 293 280 294 fd = open(cfg_set_name, O_WRONLY|O_CREAT, 0777); 281 if (fd < 0) return; 282 ubasic_scriptparam_buf[0] = 0; 295 if (fd < 0) { 296 free(buf); 297 return; 298 } 299 buf[0] = 0; 300 p=buf; 283 301 for(n = 0; n < SCRIPT_NUM_PARAMS; ++n) 284 302 { 285 303 if (script_params[n][0] != 0) 286 304 { 287 strcat(ubasic_scriptparam_buf, "@param "); 288 i = strlen(ubasic_scriptparam_buf); 289 ubasic_scriptparam_buf[i] = 'a'+n; 290 strcpy(ubasic_scriptparam_buf+i+1, " \0"); 291 strcat(ubasic_scriptparam_buf, script_params[n]); 292 strcat(ubasic_scriptparam_buf, "\n@default "); 293 i = strlen(ubasic_scriptparam_buf); 294 ubasic_scriptparam_buf[i] = 'a'+n; 295 sprintf(ubasic_scriptparam_buf+i+1, " %d\n\0", conf.ubasic_vars[n]); 305 p+=sprintf(p,"@param %c %s\n@default %c %d\n",'a'+n,script_params[n],'a'+n,conf.ubasic_vars[n]); 296 306 } 297 307 } 298 write(fd, ubasic_scriptparam_buf, strlen(ubasic_scriptparam_buf));308 write(fd, buf, strlen(buf)); 299 309 close(fd); 310 free(buf); 300 311 } 301 312 … … 305 316 void script_load(const char *fn, int saved_params) { 306 317 int fd=-1, i, update_vars; 318 struct stat st; 307 319 308 320 // save_params_values(0); 321 322 if(state_ubasic_script && state_ubasic_script != ubasic_script_default) 323 free((void *)state_ubasic_script); 309 324 310 325 state_ubasic_script = ubasic_script_default; … … 326 341 } 327 342 } 328 343 // zero size = default script 344 if(stat(fn,&st) != 0 || st.st_size == 0) { 345 conf.script_file[0]=0; 346 update_vars = 1; 347 if(fd > 0) { 348 close(fd); 349 fd=-1; 350 } 351 } 329 352 if (fd>=0){ 330 int rcnt = read(fd, ubasic_script_buf, SCRIPT_BUF_SIZE); 331 if (rcnt > 0){ 332 if (rcnt == SCRIPT_BUF_SIZE) { /* FIXME TODO script is too big? */ 333 ubasic_script_buf[SCRIPT_BUF_SIZE-1] = 0; 334 } else 335 ubasic_script_buf[rcnt] = 0; 336 state_ubasic_script = ubasic_script_buf; 337 } 338 close(fd); 339 strcpy(conf.script_file, fn); 353 int rcnt; 354 char *buf; 355 356 buf = malloc(st.st_size+1); 357 if(!buf) { 358 close(fd); 359 return; 360 } 361 362 // TODO we could process the script here to reduce size 363 // or compile for lua 364 rcnt = read(fd, buf, st.st_size); 365 if (rcnt > 0){ 366 buf[rcnt] = 0; 367 state_ubasic_script = buf; 368 strcpy(conf.script_file, fn); 369 } 370 else { 371 free(buf); 372 } 373 close(fd); 340 374 } 341 375 … … 346 380 } 347 381 } 348 script_scan(fn, update_vars); 349 if (saved_params) load_params_values(fn, update_vars, (saved_params!=2)); 382 script_scan(conf.script_file, update_vars); 383 if (saved_params) 384 load_params_values(conf.script_file, update_vars, (saved_params!=2)); 350 385 gui_update_script_submenu(); 351 386 } -
trunk/doc/version.txt
r523 r524 5 5 6 6 log 7 0.5.5 / reyalp 8 * made ubasic eat up to 100 labels or REMs in one call to ubasic_run, rather than taking 10ms each 9 * made script buffer dynamic, allocated when script is loaded 10 * made some other script related memory dynamic 11 see http://chdk.setepontos.com/index.php/topic,688.msg21646.html#msg21646 for details 12 7 13 0.5.4 / reyalp 8 14 * Made games compile time optional. Set or unset OPT_GAME_* in root makefile.inc -
trunk/include/stdlib.h
r517 r524 240 240 extern int closedir (DIR*); 241 241 extern void rewinddir (DIR*); 242 extern int stat (c har *name, struct stat *pStat);242 extern int stat (const char *name, struct stat *pStat); 243 243 244 244 -
trunk/lib/ubasic/ubasic.c
r515 r524 2387 2387 DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_line_number()); 2388 2388 /* current_linenum = tokenizer_num();*/ 2389 #if 0 2389 2390 if (tokenizer_token() == TOKENIZER_LABEL) { 2390 2391 #ifdef DEBUG … … 2396 2397 return; 2397 2398 } 2399 #endif 2400 /* reyalp - eat up to 100 labels or rems at a time so they don't cost 10ms each */ 2401 int count = 100; 2402 do { 2403 int r=tokenizer_token(); 2404 if ( r == TOKENIZER_LABEL ) { 2405 /* hit limit and we are on a label, return */ 2406 if( count == 1 ) 2407 return; 2408 #ifdef DEBUG 2409 tokenizer_label(string, sizeof(string)); 2410 DEBUG_PRINTF("line_statement: label: %s\n", string ); 2411 #endif 2412 accept(TOKENIZER_LABEL); 2413 accept(TOKENIZER_CR); 2414 } 2415 else if ( r == TOKENIZER_REM ) { 2416 rem_statement(); 2417 } 2418 } while(--count); 2398 2419 statement(); 2399 2420 return; -
trunk/version.inc
r523 r524 1 BUILD_NUMBER := 0.5. 41 BUILD_NUMBER := 0.5.5
Note: See TracChangeset
for help on using the changeset viewer.