/[gxemul]/trunk/src/emul_parse.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/emul_parse.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by dpavlin, Mon Oct 8 16:17:48 2007 UTC revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul_parse.c,v 1.29 2005/03/14 19:14:04 debug Exp $   *  $Id: emul_parse.c,v 1.32 2005/06/24 09:33:34 debug Exp $
29   *   *
30   *  Set up an emulation by parsing a config file.   *  Set up an emulation by parsing a config file.
31   *   *
  *  
32   *  TODO: This could be extended to support XML config files as well, but   *  TODO: This could be extended to support XML config files as well, but
33   *        XML is ugly.   *        XML is ugly. It is ugly right now as well. The question is: which
34     *        solution is the least ugly?
35   */   */
36    
37  #include <stdio.h>  #include <stdio.h>
# Line 198  static void read_one_word(FILE *f, char Line 198  static void read_one_word(FILE *f, char
198    
199  static char cur_net_ipv4net[50];  static char cur_net_ipv4net[50];
200  static char cur_net_ipv4len[50];  static char cur_net_ipv4len[50];
201    static char cur_net_local_port[10];
202    #define MAX_N_REMOTE            20
203    #define MAX_REMOTE_LEN          100
204    static char *cur_net_remote[MAX_N_REMOTE];
205    static int cur_net_n_remote;
206    
207  static char cur_machine_name[50];  static char cur_machine_name[50];
208  static char cur_machine_cpu[50];  static char cur_machine_cpu[50];
# Line 339  static void parse__emul(struct emul *e, Line 344  static void parse__emul(struct emul *e,
344                      line, EXPECT_LEFT_PARENTHESIS);                      line, EXPECT_LEFT_PARENTHESIS);
345    
346                  /*  Default net:  */                  /*  Default net:  */
347                  strcpy(cur_net_ipv4net, "10.0.0.0");                  strlcpy(cur_net_ipv4net, "10.0.0.0", sizeof(cur_net_ipv4net));
348                  strcpy(cur_net_ipv4len, "8");                  strlcpy(cur_net_ipv4len, "8", sizeof(cur_net_ipv4len));
349                    strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port));
350                    cur_net_n_remote = 0;
351                  return;                  return;
352          }          }
353    
# Line 390  static void parse__emul(struct emul *e, Line 397  static void parse__emul(struct emul *e,
397  /*  /*
398   *  parse__net():   *  parse__net():
399   *   *
400   *  Simple words: ipv4net, ipv4len   *  Simple words: ipv4net, ipv4len, local_port
401     *
402     *  Complex: add_remote
403   *   *
404   *  TODO: more words? for example an option to disable the gateway? that would   *  TODO: more words? for example an option to disable the gateway? that would
405   *  have to be implemented correctly in src/net.c first.   *  have to be implemented correctly in src/net.c first.
# Line 398  static void parse__emul(struct emul *e, Line 407  static void parse__emul(struct emul *e,
407  static void parse__net(struct emul *e, FILE *f, int *in_emul, int *line,  static void parse__net(struct emul *e, FILE *f, int *in_emul, int *line,
408          int *parsestate, char *word, size_t maxbuflen)          int *parsestate, char *word, size_t maxbuflen)
409  {  {
410            int i;
411    
412          if (word[0] == ')') {          if (word[0] == ')') {
413                  /*  Finished with the 'net' section. Let's create the net:  */                  /*  Finished with the 'net' section. Let's create the net:  */
414                  if (e->net != NULL) {                  if (e->net != NULL) {
# Line 406  static void parse__net(struct emul *e, F Line 417  static void parse__net(struct emul *e, F
417                          exit(1);                          exit(1);
418                  }                  }
419    
420                    if (!cur_net_local_port[0])
421                            strlcpy(cur_net_local_port, "0",
422                                sizeof(cur_net_local_port));
423    
424                  e->net = net_init(e, NET_INIT_FLAG_GATEWAY,                  e->net = net_init(e, NET_INIT_FLAG_GATEWAY,
425                      cur_net_ipv4net, atoi(cur_net_ipv4len));                      cur_net_ipv4net, atoi(cur_net_ipv4len),
426                        cur_net_remote, cur_net_n_remote,
427                        atoi(cur_net_local_port));
428    
429                  if (e->net == NULL) {                  if (e->net == NULL) {
430                          fatal("line %i: fatal error: could not create"                          fatal("line %i: fatal error: could not create"
# Line 415  static void parse__net(struct emul *e, F Line 432  static void parse__net(struct emul *e, F
432                          exit(1);                          exit(1);
433                  }                  }
434    
435                    for (i=0; i<cur_net_n_remote; i++) {
436                            free(cur_net_remote[i]);
437                            cur_net_remote[i] = NULL;
438                    }
439    
440                  *parsestate = PARSESTATE_EMUL;                  *parsestate = PARSESTATE_EMUL;
441                  return;                  return;
442          }          }
443    
444          WORD("ipv4net", cur_net_ipv4net);          WORD("ipv4net", cur_net_ipv4net);
445          WORD("ipv4len", cur_net_ipv4len);          WORD("ipv4len", cur_net_ipv4len);
446            WORD("local_port", cur_net_local_port);
447    
448            if (strcmp(word, "add_remote") == 0) {
449                    read_one_word(f, word, maxbuflen,
450                        line, EXPECT_LEFT_PARENTHESIS);
451                    if (cur_net_n_remote >= MAX_N_REMOTE) {
452                            fprintf(stderr, "too many remote networks\n");
453                            exit(1);
454                    }
455                    cur_net_remote[cur_net_n_remote] = malloc(MAX_REMOTE_LEN);
456                    if (cur_net_remote[cur_net_n_remote] == NULL) {
457                            fprintf(stderr, "out of memory\n");
458                            exit(1);
459                    }
460                    read_one_word(f, cur_net_remote[cur_net_n_remote],
461                        MAX_REMOTE_LEN, line, EXPECT_WORD);
462                    cur_net_n_remote ++;
463                    read_one_word(f, word, maxbuflen, line,
464                        EXPECT_RIGHT_PARENTHESIS);
465                    return;
466            }
467    
468          fatal("line %i: not expecting '%s' in a 'net' section\n", *line, word);          fatal("line %i: not expecting '%s' in a 'net' section\n", *line, word);
469          exit(1);          exit(1);
# Line 440  static void parse__machine(struct emul * Line 483  static void parse__machine(struct emul *
483                  struct machine *m;                  struct machine *m;
484    
485                  if (!cur_machine_name[0])                  if (!cur_machine_name[0])
486                          strcpy(cur_machine_name, "no_name");                          strlcpy(cur_machine_name, "no_name",
487                                sizeof(cur_machine_name));
488    
489                  m = emul_add_machine(e, cur_machine_name);                  m = emul_add_machine(e, cur_machine_name);
490    
# Line 453  static void parse__machine(struct emul * Line 497  static void parse__machine(struct emul *
497                          m->cpu_name = strdup(cur_machine_cpu);                          m->cpu_name = strdup(cur_machine_cpu);
498    
499                  if (!cur_machine_use_x11[0])                  if (!cur_machine_use_x11[0])
500                          strcpy(cur_machine_use_x11, "no");                          strlcpy(cur_machine_use_x11, "no",
501                                sizeof(cur_machine_use_x11));
502                  m->use_x11 = parse_on_off(cur_machine_use_x11);                  m->use_x11 = parse_on_off(cur_machine_use_x11);
503    
504                  if (!cur_machine_slowsi[0])                  if (!cur_machine_slowsi[0])
505                          strcpy(cur_machine_slowsi, "no");                          strlcpy(cur_machine_slowsi, "no",
506                                sizeof(cur_machine_slowsi));
507                  m->slow_serial_interrupts_hack_for_linux =                  m->slow_serial_interrupts_hack_for_linux =
508                      parse_on_off(cur_machine_slowsi);                      parse_on_off(cur_machine_slowsi);
509    
510                  if (!cur_machine_debugger_on_badaddr[0])                  if (!cur_machine_debugger_on_badaddr[0])
511                          strcpy(cur_machine_debugger_on_badaddr, "no");                          strlcpy(cur_machine_debugger_on_badaddr, "no",
512                                sizeof(cur_machine_debugger_on_badaddr));
513                  m->single_step_on_bad_addr =                  m->single_step_on_bad_addr =
514                      parse_on_off(cur_machine_debugger_on_badaddr);                      parse_on_off(cur_machine_debugger_on_badaddr);
515    
516                  if (!cur_machine_prom_emulation[0])                  if (!cur_machine_prom_emulation[0])
517                          strcpy(cur_machine_prom_emulation, "yes");                          strlcpy(cur_machine_prom_emulation, "yes",
518                                sizeof(cur_machine_prom_emulation));
519                  m->prom_emulation = parse_on_off(cur_machine_prom_emulation);                  m->prom_emulation = parse_on_off(cur_machine_prom_emulation);
520    
521                  if (!cur_machine_random_mem[0])                  if (!cur_machine_random_mem[0])
522                          strcpy(cur_machine_random_mem, "no");                          strlcpy(cur_machine_random_mem, "no",
523                                sizeof(cur_machine_random_mem));
524                  m->random_mem_contents =                  m->random_mem_contents =
525                      parse_on_off(cur_machine_random_mem);                      parse_on_off(cur_machine_random_mem);
526    
527                  if (!cur_machine_random_cpu[0])                  if (!cur_machine_random_cpu[0])
528                          strcpy(cur_machine_random_cpu, "no");                          strlcpy(cur_machine_random_cpu, "no",
529                                sizeof(cur_machine_random_cpu));
530                  m->use_random_bootstrap_cpu =                  m->use_random_bootstrap_cpu =
531                      parse_on_off(cur_machine_random_cpu);                      parse_on_off(cur_machine_random_cpu);
532    
# Line 495  static void parse__machine(struct emul * Line 545  static void parse__machine(struct emul *
545                  }                  }
546    
547                  if (!cur_machine_bintrans[0])                  if (!cur_machine_bintrans[0])
548                          strcpy(cur_machine_bintrans, "yes");                          strlcpy(cur_machine_bintrans, "yes",
549                                sizeof(cur_machine_bintrans));
550                  m->bintrans_enable = m->bintrans_enabled_from_start =                  m->bintrans_enable = m->bintrans_enabled_from_start =
551                      parse_on_off(cur_machine_bintrans);                      parse_on_off(cur_machine_bintrans);
552    
553                  if (!cur_machine_old_bintrans[0])                  if (!cur_machine_old_bintrans[0])
554                          strcpy(cur_machine_old_bintrans, "no");                          strlcpy(cur_machine_old_bintrans, "yes",
555                                sizeof(cur_machine_old_bintrans));
556                  m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans);                  m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans);
557    
558                  if (!m->bintrans_enable && m->old_bintrans_enable) {                  if (!m->bintrans_enable && m->old_bintrans_enable) {
# Line 518  static void parse__machine(struct emul * Line 570  static void parse__machine(struct emul *
570                              atoi(cur_machine_bintrans_size);                              atoi(cur_machine_bintrans_size);
571    
572                  if (!cur_machine_force_netboot[0])                  if (!cur_machine_force_netboot[0])
573                          strcpy(cur_machine_force_netboot, "no");                          strlcpy(cur_machine_force_netboot, "no",
574                                sizeof(cur_machine_force_netboot));
575                  m->force_netboot = parse_on_off(cur_machine_force_netboot);                  m->force_netboot = parse_on_off(cur_machine_force_netboot);
576    
577                  if (!cur_machine_start_paused[0])                  if (!cur_machine_start_paused[0])
578                          strcpy(cur_machine_start_paused, "no");                          strlcpy(cur_machine_start_paused, "no",
579                                sizeof(cur_machine_start_paused));
580                  m->start_paused = parse_on_off(cur_machine_start_paused);                  m->start_paused = parse_on_off(cur_machine_start_paused);
581    
582                  /*  NOTE: Default nr of CPUs is 0:  */                  /*  NOTE: Default nr of CPUs is 0:  */
583                  if (!cur_machine_ncpus[0])                  if (!cur_machine_ncpus[0])
584                          strcpy(cur_machine_ncpus, "0");                          strlcpy(cur_machine_ncpus, "0",
585                                sizeof(cur_machine_ncpus));
586                  m->ncpus = atoi(cur_machine_ncpus);                  m->ncpus = atoi(cur_machine_ncpus);
587    
588                  if (cur_machine_n_gfx_cards[0])                  if (cur_machine_n_gfx_cards[0])
# Line 546  static void parse__machine(struct emul * Line 601  static void parse__machine(struct emul *
601    
602                  /*  NOTE: Default nr of CPUs is 0:  */                  /*  NOTE: Default nr of CPUs is 0:  */
603                  if (!cur_machine_memory[0])                  if (!cur_machine_memory[0])
604                          strcpy(cur_machine_memory, "0");                          strlcpy(cur_machine_memory, "0",
605                                sizeof(cur_machine_memory));
606                  m->physical_ram_in_mb = atoi(cur_machine_memory);                  m->physical_ram_in_mb = atoi(cur_machine_memory);
607    
608                  if (!cur_machine_x11_scaledown[0])                  if (!cur_machine_x11_scaledown[0])

Legend:
Removed from v.9  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26