/[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 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul_parse.c,v 1.42 2006/06/22 13:22:41 debug Exp $   *  $Id: emul_parse.c,v 1.46 2007/06/15 17:02:38 debug Exp $
29   *   *
30   *  Set up an emulation by parsing a config file.   *  Set up an emulation by parsing a config file.
31   *   *
# Line 306  static void parse__emul(struct emul *e, Line 306  static void parse__emul(struct emul *e,
306                          free(e->name);                          free(e->name);
307                          e->name = NULL;                          e->name = NULL;
308                  }                  }
309                  e->name = strdup(tmp);                  CHECK_ALLOCATION(e->name = strdup(tmp));
                 if (e->name == NULL) {  
                         fprintf(stderr, "out of memory in parse__emul()\n");  
                         exit(1);  
                 }  
310                  debug("name: \"%s\"\n", e->name);                  debug("name: \"%s\"\n", e->name);
311                  return;                  return;
312          }          }
# Line 321  static void parse__emul(struct emul *e, Line 317  static void parse__emul(struct emul *e,
317                      line, EXPECT_LEFT_PARENTHESIS);                      line, EXPECT_LEFT_PARENTHESIS);
318    
319                  /*  Default net:  */                  /*  Default net:  */
320                  strlcpy(cur_net_ipv4net, "10.0.0.0", sizeof(cur_net_ipv4net));                  strlcpy(cur_net_ipv4net, NET_DEFAULT_IPV4_MASK,
321                  strlcpy(cur_net_ipv4len, "8", sizeof(cur_net_ipv4len));                      sizeof(cur_net_ipv4net));
322                    snprintf(cur_net_ipv4len, sizeof(cur_net_ipv4len), "%i",
323                        NET_DEFAULT_IPV4_LEN);
324                  strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port));                  strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port));
325                  cur_net_n_remote = 0;                  cur_net_n_remote = 0;
326                  return;                  return;
# Line 397  static void parse__net(struct emul *e, F Line 395  static void parse__net(struct emul *e, F
395                  e->net = net_init(e, NET_INIT_FLAG_GATEWAY,                  e->net = net_init(e, NET_INIT_FLAG_GATEWAY,
396                      cur_net_ipv4net, atoi(cur_net_ipv4len),                      cur_net_ipv4net, atoi(cur_net_ipv4len),
397                      cur_net_remote, cur_net_n_remote,                      cur_net_remote, cur_net_n_remote,
398                      atoi(cur_net_local_port));                      atoi(cur_net_local_port), NULL);
399    
400                  if (e->net == NULL) {                  if (e->net == NULL) {
401                          fatal("line %i: fatal error: could not create"                          fatal("line %i: fatal error: could not create"
# Line 425  static void parse__net(struct emul *e, F Line 423  static void parse__net(struct emul *e, F
423                          fprintf(stderr, "too many remote networks\n");                          fprintf(stderr, "too many remote networks\n");
424                          exit(1);                          exit(1);
425                  }                  }
426                  cur_net_remote[cur_net_n_remote] = malloc(MAX_REMOTE_LEN);  
427                  if (cur_net_remote[cur_net_n_remote] == NULL) {                  CHECK_ALLOCATION(cur_net_remote[cur_net_n_remote] =
428                          fprintf(stderr, "out of memory\n");                      malloc(MAX_REMOTE_LEN));
                         exit(1);  
                 }  
429                  read_one_word(f, cur_net_remote[cur_net_n_remote],                  read_one_word(f, cur_net_remote[cur_net_n_remote],
430                      MAX_REMOTE_LEN, line, EXPECT_WORD);                      MAX_REMOTE_LEN, line, EXPECT_WORD);
431                  cur_net_n_remote ++;                  cur_net_n_remote ++;
# Line 467  static void parse__machine(struct emul * Line 463  static void parse__machine(struct emul *
463                          exit(1);                          exit(1);
464    
465                  if (cur_machine_cpu[0])                  if (cur_machine_cpu[0])
466                          m->cpu_name = strdup(cur_machine_cpu);                          CHECK_ALLOCATION(m->cpu_name = strdup(cur_machine_cpu));
467    
468                  if (!cur_machine_use_x11[0])                  if (!cur_machine_use_x11[0])
469                          strlcpy(cur_machine_use_x11, "no",                          strlcpy(cur_machine_use_x11, "no",
470                              sizeof(cur_machine_use_x11));                              sizeof(cur_machine_use_x11));
471                  m->use_x11 = parse_on_off(cur_machine_use_x11);                  m->x11_md.in_use = parse_on_off(cur_machine_use_x11);
472    
473                  if (!cur_machine_slowsi[0])                  if (!cur_machine_slowsi[0])
474                          strlcpy(cur_machine_slowsi, "no",                          strlcpy(cur_machine_slowsi, "no",
# Line 538  static void parse__machine(struct emul * Line 534  static void parse__machine(struct emul *
534                  if (cur_machine_emulated_hz[0]) {                  if (cur_machine_emulated_hz[0]) {
535                          m->emulated_hz = mystrtoull(cur_machine_emulated_hz,                          m->emulated_hz = mystrtoull(cur_machine_emulated_hz,
536                              NULL, 0);                              NULL, 0);
                         m->automatic_clock_adjustment = 0;  
537                  }                  }
538    
539                  /*  NOTE: Default nr of CPUs is 0:  */                  /*  NOTE: Default nr of CPUs is 0:  */
# Line 548  static void parse__machine(struct emul * Line 543  static void parse__machine(struct emul *
543                  m->physical_ram_in_mb = atoi(cur_machine_memory);                  m->physical_ram_in_mb = atoi(cur_machine_memory);
544    
545                  if (!cur_machine_x11_scaledown[0])                  if (!cur_machine_x11_scaledown[0])
546                          m->x11_scaledown = 1;                          m->x11_md.scaledown = 1;
547                  else {                  else {
548                          m->x11_scaledown = atoi(cur_machine_x11_scaledown);                          m->x11_md.scaledown = atoi(cur_machine_x11_scaledown);
549                          if (m->x11_scaledown < 0) {                          if (m->x11_md.scaledown < 0) {
550                                  m->x11_scaleup = 0 - m->x11_scaledown;                                  m->x11_md.scaleup = 0 - m->x11_md.scaledown;
551                                  m->x11_scaledown = 1;                                  m->x11_md.scaledown = 1;
552                          }                          }
553                          if (m->x11_scaledown < 1) {                          if (m->x11_md.scaledown < 1) {
554                                  fprintf(stderr, "Invalid scaledown value"                                  fprintf(stderr, "Invalid scaledown value"
555                                      " (%i)\n", m->x11_scaledown);                                      " (%i)\n", m->x11_md.scaledown);
556                                  exit(1);                                  exit(1);
557                          }                          }
558                  }                  }
# Line 574  static void parse__machine(struct emul * Line 569  static void parse__machine(struct emul *
569                          m->boot_string_argument = strdup(cur_machine_bootarg);                          m->boot_string_argument = strdup(cur_machine_bootarg);
570    
571                  for (i=0; i<cur_machine_n_x11_disp; i++) {                  for (i=0; i<cur_machine_n_x11_disp; i++) {
572                          m->x11_n_display_names ++;                          m->x11_md.n_display_names ++;
573                          m->x11_display_names = realloc(                          CHECK_ALLOCATION(m->x11_md.display_names = realloc(
574                              m->x11_display_names, m->x11_n_display_names                              m->x11_md.display_names, m->x11_md.n_display_names
575                              * sizeof(char *));                              * sizeof(char *)));
576                          if (m->x11_display_names == NULL) {                          CHECK_ALLOCATION(m->x11_md.display_names[
577                                  printf("out of memory\n");                              m->x11_md.n_display_names-1] =
578                                  exit(1);                              strdup(cur_machine_x11_disp[i]));
                         }  
                         m->x11_display_names[m->x11_n_display_names-1] =  
                             strdup(cur_machine_x11_disp[i]);  
                         if (m->x11_display_names  
                            [m->x11_n_display_names-1] == NULL) {  
                                 printf("out of memory\n");  
                                 exit(1);  
                         }  
579                          free(cur_machine_x11_disp[i]);                          free(cur_machine_x11_disp[i]);
580                          cur_machine_x11_disp[i] = NULL;                          cur_machine_x11_disp[i] = NULL;
581                  }                  }
# Line 639  static void parse__machine(struct emul * Line 626  static void parse__machine(struct emul *
626                          fprintf(stderr, "too many loads\n");                          fprintf(stderr, "too many loads\n");
627                          exit(1);                          exit(1);
628                  }                  }
629                  cur_machine_load[cur_machine_n_load] = malloc(MAX_LOAD_LEN);                  CHECK_ALLOCATION(cur_machine_load[cur_machine_n_load] =
630                  if (cur_machine_load[cur_machine_n_load] == NULL) {                      malloc(MAX_LOAD_LEN));
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
631                  read_one_word(f, cur_machine_load[cur_machine_n_load],                  read_one_word(f, cur_machine_load[cur_machine_n_load],
632                      MAX_LOAD_LEN, line, EXPECT_WORD);                      MAX_LOAD_LEN, line, EXPECT_WORD);
633                  cur_machine_n_load ++;                  cur_machine_n_load ++;
# Line 659  static void parse__machine(struct emul * Line 643  static void parse__machine(struct emul *
643                          fprintf(stderr, "too many disks\n");                          fprintf(stderr, "too many disks\n");
644                          exit(1);                          exit(1);
645                  }                  }
646                  cur_machine_disk[cur_machine_n_disk] = malloc(MAX_DISK_LEN);                  CHECK_ALLOCATION(cur_machine_disk[cur_machine_n_disk] =
647                  if (cur_machine_disk[cur_machine_n_disk] == NULL) {                      malloc(MAX_DISK_LEN));
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
648                  read_one_word(f, cur_machine_disk[cur_machine_n_disk],                  read_one_word(f, cur_machine_disk[cur_machine_n_disk],
649                      MAX_DISK_LEN, line, EXPECT_WORD);                      MAX_DISK_LEN, line, EXPECT_WORD);
650                  cur_machine_n_disk ++;                  cur_machine_n_disk ++;
# Line 679  static void parse__machine(struct emul * Line 660  static void parse__machine(struct emul *
660                          fprintf(stderr, "too many devices\n");                          fprintf(stderr, "too many devices\n");
661                          exit(1);                          exit(1);
662                  }                  }
663                  cur_machine_device[cur_machine_n_device] =                  CHECK_ALLOCATION(cur_machine_device[cur_machine_n_device] =
664                      malloc(MAX_DEVICE_LEN);                      malloc(MAX_DEVICE_LEN));
                 if (cur_machine_device[cur_machine_n_device] == NULL) {  
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
665                  read_one_word(f, cur_machine_device[cur_machine_n_device],                  read_one_word(f, cur_machine_device[cur_machine_n_device],
666                      MAX_DEVICE_LEN, line, EXPECT_WORD);                      MAX_DEVICE_LEN, line, EXPECT_WORD);
667                  cur_machine_n_device ++;                  cur_machine_n_device ++;
# Line 700  static void parse__machine(struct emul * Line 677  static void parse__machine(struct emul *
677                          fprintf(stderr, "too many x11 displays\n");                          fprintf(stderr, "too many x11 displays\n");
678                          exit(1);                          exit(1);
679                  }                  }
680                  cur_machine_x11_disp[cur_machine_n_x11_disp] =                  CHECK_ALLOCATION(cur_machine_x11_disp[cur_machine_n_x11_disp] =
681                      malloc(MAX_X11_DISP_LEN);                      malloc(MAX_X11_DISP_LEN));
                 if (cur_machine_x11_disp[cur_machine_n_x11_disp] == NULL) {  
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
682                  read_one_word(f, cur_machine_x11_disp[cur_machine_n_x11_disp],                  read_one_word(f, cur_machine_x11_disp[cur_machine_n_x11_disp],
683                      MAX_X11_DISP_LEN, line, EXPECT_WORD);                      MAX_X11_DISP_LEN, line, EXPECT_WORD);
684                  cur_machine_n_x11_disp ++;                  cur_machine_n_x11_disp ++;

Legend:
Removed from v.24  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26