Exemple #1
0
int
main( int argc, char **argv )
{
	int ret;
	
	if( getuid() ) {
		printf("You must be root to run the MOL debugger\n");
		return 1;
	}
	mregs = &sv.mregs;

        res_manager_init(0, argc, argv );
        atexit( res_manager_cleanup );

	/* Initialize socket and connect to MOL */
	sv.fd = -1;
	do_connect();
	
	symbols_init();
	monitor_init();
	cmdline_init();
	install_monitor_cmds();

	printm("Mac-on-Linux debugger %s, ", MOL_RELEASE);
	printm("(C) 2001 Samuel Rydh <*****@*****.**>\n");

	atexit(exit_hook);
	for( ;; ) {
		if( (ret = mon_debugger()) == kDbgExit )
			break;
		send_dgram1( sv.fd, kMDG_debug_action, ret );
	}
	send_dgram( sv.fd, kMDG_disconnect );
	return 0;
}
Exemple #2
0
int
main(int argc, char **argv)
{
   char *fnm1, *fnm2;
   const char *survey = NULL;

   msg_init(argv);

   cmdline_set_syntax_message(/*FILE1 FILE2 [THRESHOLD]*/218,
			      /*FILE1 and FILE2 can be .pos or .3d files\nTHRESHOLD is the max. ignorable change along any axis in metres (default %s)*/255,
			      STRING(DFLT_MAX_THRESHOLD));
   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 2, 3);
   while (1) {
      int opt = cmdline_getopt();
      if (opt == EOF) break;
      if (opt == 's') survey = optarg;
   }
   fnm1 = argv[optind++];
   fnm2 = argv[optind++];
   if (argv[optind]) {
      optarg = argv[optind];
      threshold = cmdline_double_arg();
   }

   tree_init();

   old_separator = parse_file(fnm1, survey, tree_insert);

   new_separator = parse_file(fnm2, survey, tree_remove);

   return tree_check() ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemple #3
0
int main(int argc, char *argv[])
{
	/* Initialize random seed */
	srand(time(NULL));

	/* Initialize command line and fill all parameters */
	cmdline_init(argc, argv);

	/* Check if user requires help */
	if (help) {
		cmdline_print_usage(false);
		return 0;
	}

	/* Validate that a path was given */
	if (!env_get_data_path()) {
		LOG_E("No path specified!\n");
		goto err;
	}

	/* Initialize, run, and deinitialize machine */
	if (!machine_init())
		goto err;
	machine_run();
	machine_deinit();

	return 0;
err:
	cmdline_print_usage(true);
	return 1;
}
Exemple #4
0
int
main(void)
{
  halInit();
  chSysInit();

  get_device_id();

  /* start stdout port */
  sdStart(SD_STDIO, NULL);

  xflash_init();
  cmdline_init();

  rngStart(&RNGD);

  app_cfg_init();

  check_for_faults();

  gfx_init();
  touch_init();

  sensor_init(SENSOR_1, SD_OW1);
  sensor_init(SENSOR_2, SD_OW2);

  temp_control_init(CONTROLLER_1);
  temp_control_init(CONTROLLER_2);

  ota_update_init();
  net_init();
  web_api_init();
  sntp_init();
  gui_init();
  thread_watchdog_init();

  create_home_screen();

  recovery_screen_create();

  screen_saver_create();

  if (palReadPad(PORT_SELF_TEST_EN, PAD_SELF_TEST_EN) == 0) {
    widget_t* self_test_screen = self_test_screen_create();
    gui_push_screen(self_test_screen);
  }

  recovery_img_init();

  while (TRUE) {
    cmdline_restart();

    toggle_LED1();
  }
}
Exemple #5
0
/**
 * Initialise command line and initrd
 *
 */
static void runtime_init ( void ) {
	int rc;

	/* Initialise command line */
	if ( ( rc = cmdline_init() ) != 0 ) {
		/* No way to report failure */
		return;
	}

	/* Initialise initrd */
	if ( ( rc = initrd_init() ) != 0 ) {
		/* No way to report failure */
		return;
	}
}
Exemple #6
0
void
modules_init( void )
{
#ifdef CONFIG_CMDLINE
	cmdline_init();
#endif
#ifdef CONFIG_DEBLOCKER
	deblocker_init();
#endif
#ifdef CONFIG_DISK_LABEL
	disklabel_init();
#endif
#ifdef CONFIG_HFSP
	hfsp_init();
#endif
#ifdef CONFIG_HFS
	hfs_init();
#endif
#ifdef CONFIG_EXT2
	ext2_init();
#endif
#ifdef CONFIG_ISO9660
	iso9660_init();
#endif
#ifdef CONFIG_GRUBFS
	grubfs_init();
#endif
#ifdef CONFIG_MAC_PARTS
	macparts_init();
#endif
#ifdef CONFIG_PC_PARTS
	pcparts_init();
#endif
#ifdef CONFIG_SUN_PARTS
	sunparts_init();
#endif
#ifdef CONFIG_LOADER_XCOFF
	xcoff_loader_init();
#endif
#ifdef CONFIG_LOADER_ELF
	elf_loader_init();
#endif
#ifdef CONFIG_LOADER_BOOTINFO
	bootinfo_loader_init();
#endif

}
Exemple #7
0
int main(void)
{
  lcd_init(LCD_DISP_ON);
  lcd_command(LCD_DISP_ON_CURSOR_BLINK);
  lcd_clrscr();
  lcd_puts_P("Beispiel 2 v0.1");

  DDRA = _BV(PA4);

  cmdline_init();

  sei();

  for (;;)    /* main event loop */
    {
      process_cmdline();
    }
  return 0;
}
Exemple #8
0
extern CDECL int
main(int argc, char **argv)
{
   int d;
   time_t tmUserStart = time(NULL);
   clock_t tmCPUStart = clock();
   {
       /* FIXME: localtime? */
       struct tm * t = localtime(&tmUserStart);
       int y = t->tm_year + 1900;
       current_days_since_1900 = days_since_1900(y, t->tm_mon + 1, t->tm_mday);
   }

   /* Always buffer by line for aven's benefit. */
   setvbuf(stdout, NULL, _IOLBF, 0);

   msg_init(argv);

#if OS_WIN32 || OS_UNIX_MACOSX
   pj_set_finder(msg_proj_finder);
#endif

   pcs = osnew(settings);
   pcs->next = NULL;
   pcs->Translate = ((short*) osmalloc(ossizeof(short) * 257)) + 1;
   pcs->meta = NULL;
   pcs->proj = NULL;
   pcs->declination = HUGE_REAL;
   pcs->convergence = 0.0;

   /* Set up root of prefix hierarchy */
   root = osnew(prefix);
   root->up = root->right = root->down = NULL;
   root->stn = NULL;
   root->pos = NULL;
   root->ident = NULL;
   root->min_export = root->max_export = 0;
   root->sflags = BIT(SFLAGS_SURVEY);
   root->filename = NULL;

   nosurveyhead = NULL;

   stnlist = NULL;
   cLegs = cStns = cComponents = 0;
   totadj = total = totplan = totvert = 0.0;

   for (d = 0; d <= 2; d++) {
      min[d] = HUGE_REAL;
      max[d] = -HUGE_REAL;
      pfxHi[d] = pfxLo[d] = NULL;
   }

   /* at least one argument must be given */
   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, -1);
   while (1) {
      int opt = cmdline_getopt();
      if (opt == EOF) break;
      switch (opt) {
       case 'p':
	 /* Ignore for compatibility with older versions. */
	 break;
       case 'o': {
	 osfree(fnm_output_base); /* in case of multiple -o options */
	 /* can be a directory (in which case use basename of leaf input)
	  * or a file (in which case just trim the extension off) */
	 if (fDirectory(optarg)) {
	    /* this is a little tricky - we need to note the path here,
	     * and then add the leaf later on (in datain.c) */
	    fnm_output_base = base_from_fnm(optarg);
	    fnm_output_base_is_dir = 1;
	 } else {
	    fnm_output_base = base_from_fnm(optarg);
	 }
	 break;
       }
       case 'q':
	 if (fQuiet) fMute = 1;
	 fQuiet = 1;
	 break;
       case 's':
	 fSuppress = 1;
	 break;
       case 'v': {
	 int v = atoi(optarg);
	 if (v < IMG_VERSION_MIN || v > IMG_VERSION_MAX)
	    fatalerror(/*3d file format versions %d to %d supported*/88,
		       IMG_VERSION_MIN, IMG_VERSION_MAX);
	 img_output_version = v;
	 break;
       }
       case 'w':
	 f_warnings_are_errors = 1;
	 break;
       case 'z': {
	 /* Control which network optimisations are used (development tool) */
	 static int first_opt_z = 1;
	 char c;
	 if (first_opt_z) {
	    optimize = 0;
	    first_opt_z = 0;
	 }
	 /* Lollipops, Parallel legs, Iterate mx, Delta* */
	 while ((c = *optarg++) != '\0')
	    if (islower((unsigned char)c)) optimize |= BITA(c);
	 break;
       case 1:
	 fLog = fTrue;
	 break;
#if OS_WIN32
       case 2:
	 atexit(pause_on_exit);
	 break;
#endif
       }
      }
   }

   if (fLog) {
      char *fnm;
      if (!fnm_output_base) {
	 char *p;
	 p = baseleaf_from_fnm(argv[optind]);
	 fnm = add_ext(p, EXT_LOG);
	 osfree(p);
      } else if (fnm_output_base_is_dir) {
	 char *p;
	 fnm = baseleaf_from_fnm(argv[optind]);
	 p = use_path(fnm_output_base, fnm);
	 osfree(fnm);
	 fnm = add_ext(p, EXT_LOG);
	 osfree(p);
      } else {
	 fnm = add_ext(fnm_output_base, EXT_LOG);
      }

      if (!freopen(fnm, "w", stdout))
	 fatalerror(/*Failed to open output file “%s”*/47, fnm);

      osfree(fnm);
   }

   if (!fMute) {
      const char *p = COPYRIGHT_MSG;
      puts(PRETTYPACKAGE" "VERSION);
      while (1) {
	  const char *q = p;
	  p = strstr(p, "(C)");
	  if (p == NULL) {
	      puts(q);
	      break;
	  }
	  fwrite(q, 1, p - q, stdout);
	  fputs(msg(/*©*/0), stdout);
	  p += 3;
      }
   }

   atexit(delete_output_on_error);

   /* end of options, now process data files */
   while (argv[optind]) {
      const char *fnm = argv[optind];

      if (!fExplicitTitle) {
	 char *lf;
	 lf = baseleaf_from_fnm(fnm);
	 if (survey_title) s_catchar(&survey_title, &survey_title_len, ' ');
	 s_cat(&survey_title, &survey_title_len, lf);
	 osfree(lf);
      }

      /* Select defaults settings */
      default_all(pcs);
      data_file(NULL, fnm); /* first argument is current path */

      optind++;
   }

   validate();

   solve_network(/*stnlist*/); /* Find coordinates of all points */
   validate();

   /* close .3d file */
   if (!img_close(pimg)) {
      char *fnm = add_ext(fnm_output_base, EXT_SVX_3D);
      fatalerror(img_error2msg(img_error()), fnm);
   }
   if (fhErrStat) safe_fclose(fhErrStat);

   out_current_action(msg(/*Calculating statistics*/120));
   if (!fMute) do_stats();
   if (!fQuiet) {
      /* clock() typically wraps after 72 minutes, but there doesn't seem
       * to be a better way.  Still 72 minutes means some cave!
       * We detect if clock() could have wrapped and suppress CPU time
       * printing in this case.
       */
      double tmUser = difftime(time(NULL), tmUserStart);
      double tmCPU;
      clock_t now = clock();
#define CLOCK_T_WRAP \
	(sizeof(clock_t)<sizeof(long)?(1ul << (CHAR_BIT * sizeof(clock_t))):0)
      tmCPU = (now - (unsigned long)tmCPUStart)
	 / (double)CLOCKS_PER_SEC;
      if (now < tmCPUStart)
	 tmCPU += CLOCK_T_WRAP / (double)CLOCKS_PER_SEC;
      if (tmUser >= tmCPU + CLOCK_T_WRAP / (double)CLOCKS_PER_SEC)
	 tmCPU = 0;

      /* tmUser is integer, tmCPU not - equivalent to (ceil(tmCPU) >= tmUser) */
      if (tmCPU + 1 > tmUser) {
	 printf(msg(/*CPU time used %5.2fs*/140), tmCPU);
      } else if (tmCPU == 0) {
	 if (tmUser != 0.0) {
	    printf(msg(/*Time used %5.2fs*/141), tmUser);
	 } else {
	    fputs(msg(/*Time used unavailable*/142), stdout);
	 }
      } else {
	 printf(msg(/*Time used %5.2fs (%5.2fs CPU time)*/143), tmUser, tmCPU);
      }
      putnl();
   }
   if (msg_warnings || msg_errors) {
      if (msg_errors || (f_warnings_are_errors && msg_warnings)) {
	 printf(msg(/*There were %d warning(s) and %d error(s) - no output files produced.*/113),
		msg_warnings, msg_errors);
	 putnl();
	 return EXIT_FAILURE;
      }
      printf(msg(/*There were %d warning(s).*/16), msg_warnings);
      putnl();
   }
   return EXIT_SUCCESS;
}
Exemple #9
0
int main(void)
{

    /* USER CODE BEGIN 1 */
    CMDLINE_CONTEXT cmd_context;
    const char *zhonx_info = (char *)CONFIG_ZHONX_INFO_ADDR;
    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC1_Init();
    MX_ADC2_Init();
    MX_ADC3_Init();
    MX_I2C1_Init();
    MX_RNG_Init();
    MX_TIM1_Init();
    MX_TIM2_Init();
    MX_TIM3_Init();
    MX_TIM4_Init();
    MX_TIM5_Init();
    MX_TIM6_Init();
    MX_TIM7_Init();
    MX_TIM8_Init();
    MX_TIM11_Init();
    MX_USART3_UART_Init();

    /* USER CODE BEGIN 2 */
    expanderInit();
    HAL_Delay(100);
    mainControlInit();
    ssd1306Init(0);
    timesBaseInit();
    ledPowerBlink(990, 10);
    settingsInit();
    mulimeterInit();
    bluetoothInit();
    toneInit();
    spyPostInit();

    positionControlSetPositionType(GYRO);
    mainControlSetFollowType(NO_FOLLOW);

    toneSetVolulme(100);
    tone(F4, 50);
    toneItMode(A4, 50);

    // Register Output callback
    cmd_context.out = blockingPrintf;
    // Initialize Command Line module
    cmdline_init(&cmd_context);

    // Check if robot name is populated in Flash
    memset(zhonxName, 0, sizeof(zhonxName));
    // Retrieve ZHONX information from flash if any
    if (zhonx_info[0] == 'Z')
    {
        strcpy(zhonxName, zhonx_info);
    }

    while (zhonxName[0] == 0)
    {
        menu(zhonxNameMenu);
    }

    while (1)
    {
        menu(mainMenu);
        powerOffConfirmation();
    }

    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
        ;
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

    /* USER CODE END 3 */

}
Exemple #10
0
int init_cmdline_options(void)
{
    if (cmdline_init()) {
        archdep_startup_log_error("Cannot initialize command-line handling.\n");
        return -1;
    }
    if (log_cmdline_options_init() < 0) {
        init_cmdline_options_fail("log");
        return -1;
    }
    if (initcmdline_init() < 0) {
        init_cmdline_options_fail("main");
        return -1;
    }
    if (sysfile_cmdline_options_init() < 0) {
        init_cmdline_options_fail("system file locator");
        return -1;
    }
    if (!video_disabled_mode && ui_cmdline_options_init() < 0) {
        init_cmdline_options_fail("UI");
        return -1;
    }
    if (machine_class != VICE_MACHINE_VSID) {
        if (autostart_cmdline_options_init() < 0) {
            init_resource_fail("autostart");
            return -1;
        }
        if (romset_cmdline_options_init() < 0) {
            init_cmdline_options_fail("romset");
            return -1;
        }
        if (fliplist_cmdline_options_init() < 0) {
            init_cmdline_options_fail("flip list");
            return -1;
        }
        if (file_system_cmdline_options_init() < 0) {
            init_cmdline_options_fail("attach");
            return -1;
        }
        if (disk_image_cmdline_options_init() < 0) {
            init_cmdline_options_fail("disk image");
            return -1;
        }
        if (event_cmdline_options_init() < 0) {
            init_cmdline_options_fail("event");
            return -1;
        }
    }
    if (monitor_cmdline_options_init() < 0) {
        init_cmdline_options_fail("monitor");
        return -1;
    }
#ifdef DEBUG
    if (debug_cmdline_options_init() < 0) {
        init_cmdline_options_fail("debug");
        return -1;
    }
#endif
    if (machine_common_cmdline_options_init() < 0) {
        init_cmdline_options_fail("machine common");
        return -1;
    }
    if (machine_cmdline_options_init() < 0) {
        init_cmdline_options_fail("machine");
        return -1;
    }

    if (machine_class != VICE_MACHINE_VSID) {
        if (fsdevice_cmdline_options_init() < 0) {
            init_cmdline_options_fail("file system");
            return -1;
        }
    }
    if (!video_disabled_mode && joystick_init_cmdline_options() < 0) {
        init_cmdline_options_fail("joystick");
        return -1;
    }
    if (machine_class != VICE_MACHINE_VSID) {
        if (kbdbuf_cmdline_options_init() < 0) {
            init_cmdline_options_fail("keyboard");
            return -1;
        }
        if (ram_cmdline_options_init() < 0) {
            init_cmdline_options_fail("RAM");
            return -1;
        }
        if (gfxoutput_cmdline_options_init() < 0) {
            init_cmdline_options_fail("GFXOUTPUT");
            return -1;
        }
    }
#ifdef HAVE_NETWORK
    if (monitor_network_cmdline_options_init() < 0) {
        init_cmdline_options_fail("MONITOR_NETWORK");
        return -1;
    }
#endif
    return 0;
}
Exemple #11
0
int main(int argc, char *argv[])
{
	transfer * st_sender =NULL;
	int chk_interval = 0, attach = 0, cap_num = 0;
	char *dst_ip = NULL;
	unsigned short dst_port = 0;
	int opt_idx = 0, opt_id = 0, arg_num = 0;
	void *arglist = NULL;
	pkt_cap_ctx_p p_cap_ctx = NULL;
	st_ctx_p p_st_ctx = NULL;
	cpu_set_t set;

	if (argc < 2) return 1;

	if (0 != cmdline_init()) {
		fprintf(stderr, "cmdline_init failed!\n");
		return 1;
	}

	if (0 != cmdline_parse(argc-1, &argv[1], opt_prof)) {
		fprintf(stderr, "cmdline_parse failed!\n");
		return 1;
	}

	while (-1 != cmdline_result_loop(&opt_idx, &opt_id, &arglist, &arg_num)) {
		switch (opt_id) {
			case OPT_HELP:
				return usage();

				break;
			case OPT_DEST:
				dst_ip = strdup(cmdline_get_arg(arglist, 0));
				dst_port = atoi(cmdline_get_arg(arglist, 1));

				break;
			case OPT_INTERVAL:
				chk_interval = atoi(cmdline_get_arg(arglist, 0));

				break;
			case OPT_CAP_NUM:
				cap_num = atoi(cmdline_get_arg(arglist, 0));

				break;
			case OPT_ATTACH:
				attach = atoi(cmdline_get_arg(arglist, 0));

				break;
			default:
				break;
		}
	}

	cmdline_show();
	cmdline_destroy();

	st_sender = new transfer(IS_CLIENT, SOCK_DGRAM, dst_ip, dst_port);
	if (!st_sender || true != st_sender->is_ok()) {
		return -1;
	}

	p_cap_ctx = pkt_cap_ctx_new(cap_num);
	MEM_ALLOC(p_st_ctx, st_ctx_p, sizeof(st_ctx_t), 1);

	int cpu_num = sysconf(_SC_NPROCESSORS_CONF);
	fprintf(stdout, "cpu num = %d\n", cpu_num);
	p_st_ctx->num = cap_num;
	p_st_ctx->chk_interval = chk_interval;
	p_st_ctx->p_cap_ctx = p_cap_ctx;
	p_st_ctx->sender = st_sender;
	if (attach) p_st_ctx->id = cap_num > cpu_num ? (cpu_num-1) : cap_num;
	else p_st_ctx->id = -1;

	pthread_t st_thd;
	if (0 != pthread_create(&st_thd, NULL, st_cb, (void*)p_st_ctx)) {
		fprintf(stderr, "create st_cb failed!\n");
		return 1;
	}

	pthread_t cap_thd;
	for (int i = 0; i < cap_num; i++) {
		if (attach) p_cap_ctx[i].id = cap_num > cpu_num ? (i%(cpu_num-1)) : i;
		else p_cap_ctx[i].id = -1;
		if (0 != pthread_create(&cap_thd, NULL, pkt_cap_cb, &p_cap_ctx[i])) {
			fprintf(stderr, "create pkt_cap_cb failed!\n");
			return 1;
		}
	}

	void *ret = NULL;
	pthread_join(st_thd, &ret);

	return 0;
}
Exemple #12
0
int init_cmdline_options(void)
{
    if (cmdline_init()) {
        archdep_startup_log_error("Cannot initialize command-line handling.\n");
        return -1;
    }
    if (log_cmdline_options_init() < 0) {
        init_cmdline_options_fail("log");
        return -1;
    }
    if (initcmdline_init() < 0) {
        init_cmdline_options_fail("main");
        return -1;
    }
    if (sysfile_cmdline_options_init() < 0) {
        init_cmdline_options_fail("system file locator");
        return -1;
    }
    if (!video_disabled_mode && ui_cmdline_options_init() < 0) {
        init_cmdline_options_fail("UI");
        return -1;
    }
    if (machine_class != VICE_MACHINE_VSID) {
        if (romset_cmdline_options_init() < 0) {
            init_cmdline_options_fail("romset");
            return -1;
        }
    }
    if (monitor_cmdline_options_init() < 0) {
        init_cmdline_options_fail("monitor");
        return -1;
    }
    if (machine_common_cmdline_options_init() < 0) {
        init_cmdline_options_fail("machine common");
        return -1;
    }
    if (vsync_cmdline_options_init() < 0) {
        init_cmdline_options_fail("vsync");
        return -1;
    }
    if (sound_cmdline_options_init() < 0) {
        init_cmdline_options_fail("sound");
        return -1;
    }
    if (keyboard_cmdline_options_init() < 0) {
        init_cmdline_options_fail("keyboard");
        return -1;
    }
    if (video_cmdline_options_init() < 0) {
        init_cmdline_options_fail("video");
        return -1;
    }
    if (machine_cmdline_options_init() < 0) {
        init_cmdline_options_fail("machine");
        return -1;
    }

    if (machine_class != VICE_MACHINE_VSID) {
        if (ram_cmdline_options_init() < 0) {
            init_cmdline_options_fail("RAM");
            return -1;
        }
    }
#ifdef HAVE_NETWORK
    if (monitor_network_cmdline_options_init() < 0) {
        init_cmdline_options_fail("MONITOR_NETWORK");
        return -1;
    }
#endif
    return 0;
}
Exemple #13
0
int
main(int argc, char **argv)
{
   const char *fnm_in, *fnm_out;
   char *desc;
   img_point pt;
   int result;
   point *fr = NULL, *to;
   double zMax = -DBL_MAX;
   point *p;
   const char *survey = NULL;
   const char *specfile = NULL;
   img *pimg;
   int have_xsect = 0;

   msg_init(argv);

   /* TRANSLATORS: Part of extend --help */
   cmdline_set_syntax_message(/*INPUT_3D_FILE [OUTPUT_3D_FILE]*/267, 0, NULL);
   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, 2);
   while (1) {
      int opt = cmdline_getopt();
      if (opt == EOF) break;
      if (opt == 's') survey = optarg;
      if (opt == 'p') specfile = optarg;
   }
   fnm_in = argv[optind++];
   if (argv[optind]) {
      fnm_out = argv[optind];
   } else {
      char * base_in = base_from_fnm(fnm_in);
      char * base_out = osmalloc(strlen(base_in) + 8);
      strcpy(base_out, base_in);
      strcat(base_out, "_extend");
      fnm_out = add_ext(base_out, EXT_SVX_3D);
      osfree(base_in);
      osfree(base_out);
   }

   /* try to open image file, and check it has correct header */
   pimg = img_open_survey(fnm_in, survey);
   if (pimg == NULL) fatalerror(img_error2msg(img_error()), fnm_in);

   putnl();
   puts(msg(/*Reading in data - please wait…*/105));

   htab = osmalloc(ossizeof(pfx*) * HTAB_SIZE);
   {
       int i;
       for (i = 0; i < HTAB_SIZE; ++i) htab[i] = NULL;
   }

   do {
      result = img_read_item(pimg, &pt);
      switch (result) {
      case img_MOVE:
	 fr = find_point(&pt);
	 break;
      case img_LINE:
	 if (!fr) {
	    result = img_BAD;
	    break;
	 }
	 to = find_point(&pt);
	 if (!(pimg->flags & (img_FLAG_SURFACE|img_FLAG_SPLAY)))
	    add_leg(fr, to, pimg->label, pimg->flags);
	 fr = to;
	 break;
      case img_LABEL:
	 to = find_point(&pt);
	 add_label(to, pimg->label, pimg->flags);
	 break;
      case img_BAD:
	 (void)img_close(pimg);
	 fatalerror(img_error2msg(img_error()), fnm_in);
	 break;
      case img_XSECT:
         have_xsect = 1;
         break;
      }
   } while (result != img_STOP);

   desc = osstrdup(pimg->title);

   if (specfile) {
      FILE *fs = NULL;
      char *fnm_used;
      /* TRANSLATORS: for extend: */
      printf(msg(/*Applying specfile: “%s”*/521), specfile);
      putnl();
      fs = fopenWithPthAndExt("", specfile, NULL, "r", &fnm_used);
      if (fs == NULL) fatalerror(/*Couldn’t open file “%s”*/93, specfile);
      while (!feof(fs)) {
	 char *lbuf = getline_alloc(fs, 32);
	 lineno++;
	 if (!lbuf)
	    fatalerror_in_file(fnm_used, lineno, /*Error reading file*/18);
	 parseconfigline(fnm_used, lbuf);
	 osfree(lbuf);
      }
      osfree(fnm_used);
   }

   if (start == NULL) { /* i.e. start wasn't specified in specfile */

      /* start at the highest entrance with some legs attached */
      for (p = headpoint.next; p != NULL; p = p->next) {
	 if (p->order > 0 && p->p.z > zMax) {
	    const stn *s;
	    for (s = p->stns; s; s = s->next) {
	       if (s->flags & img_SFLAG_ENTRANCE) {
		  start = p;
		  zMax = p->p.z;
		  break;
	       }
	    }
	 }
      }
      if (start == NULL) {
	 /* if no entrances with legs, start at the highest 1-node */
	 for (p = headpoint.next; p != NULL; p = p->next) {
	    if (p->order == 1 && p->p.z > zMax) {
	       start = p;
	       zMax = p->p.z;
	    }
	 }
	 /* of course we may have no 1-nodes... */
	 if (start == NULL) {
	    for (p = headpoint.next; p != NULL; p = p->next) {
	       if (p->order != 0 && p->p.z > zMax) {
		  start = p;
		  zMax = p->p.z;
	       }
	    }
	    if (start == NULL) {
	       /* There are no legs - just pick the highest station... */
	       for (p = headpoint.next; p != NULL; p = p->next) {
		  if (p->p.z > zMax) {
		     start = p;
		     zMax = p->p.z;
		  }
	       }
	       if (!start) fatalerror(/*No survey data*/43);
	    }
	 }
      }
   }

   /* TRANSLATORS: for extend:
    * Used to tell the user that a file is being written - %s is the filename
    */
   printf(msg(/*Writing %s…*/522), fnm_out);
   putnl();
   pimg_out = img_open_write(fnm_out, desc, img_FFLAG_EXTENDED);

   /* Only does single connected component currently. */
   do_stn(start, 0.0, NULL, ERIGHT, 0);

   if (have_xsect) {
      img_rewind(pimg);
      /* Read ahead on pimg before writing pimg_out so we find out if an
       * img_XSECT_END comes next. */
      char * label = NULL;
      int flags = 0;
      do {
	 result = img_read_item(pimg, &pt);
	 if (result == img_XSECT || result == img_XSECT_END) {
	    if (label) {
	       if (result == img_XSECT_END)
		  flags |= img_XFLAG_END;
	       img_write_item(pimg_out, img_XSECT, flags, label, 0, 0, 0);
	       osfree(label);
	       label = NULL;
	    }
	 }
	 if (result == img_XSECT) {
	    label = osstrdup(pimg->label);
	    flags = pimg->flags;
	    pimg_out->l = pimg->l;
	    pimg_out->r = pimg->r;
	    pimg_out->u = pimg->u;
	    pimg_out->d = pimg->d;
	 }
      } while (result != img_STOP);
   }

   (void)img_close(pimg);

   if (!img_close(pimg_out)) {
      (void)remove(fnm_out);
      fatalerror(img_error2msg(img_error()), fnm_out);
   }

   return EXIT_SUCCESS;
}
Exemple #14
0
int main(int argc, char *argv[])
{
	int ret = -1;

#if 1
#ifndef DEEBE_RELEASE
	FILE *try_log = fopen(LOG_FILENAME, "wt");
	if (NULL != try_log)
		fp_log = try_log;
	else
		fp_log = stdout;

	try_log = NULL;
#endif
#else
	fp_log = stdout;
#endif

	/* Signal handlers */
	signal_handle_sigio = main_sigio;
	signal_handle_sigrtmin = main_sigrtmin;
	signal_handle_sigchld = main_sigchld;

	if (0 != cmdline_init(argc, argv)) {
		/* start the watchdog timer */
		if (cmdline_watchdog_minutes > 0) {
			/* watchdog is in seconds, for *= 60 */
			long seconds = 60 * cmdline_watchdog_minutes;
			if (!watchdog_init(seconds)) {
				/*
				 * Only report this error if timer_create
				 * is supported.  If it isn't then the watchdog
				 * functionality is simulated in the network
				 * code where read or connect delays are
				 * expected.
				 */
#ifdef HAVE_TIMER_CREATE
				fprintf(stderr, "Problem initializing watchdog timer for %ld seconds\n",
					seconds);
				/*
				 * watchdog_init does not turn on the
				 * the signal unless it is successful
				 * so we do not have to disable it
				 */
#endif
			}
		}

		if (cmdline_port_fwd > 0)
			ret = main_forward();
		else
			ret = main_debug();
	}
	cmdline_cleanup();

	if (fp_log) {
		if (fp_log != stdout) {
			fflush(fp_log);
			fclose(fp_log);
			fp_log = stdout;
		}
	}
	return ret;
}
Exemple #15
0
/* The main function */
int main(int argc, char *argv[])
{
    struct utsname  system;
    FILE           *infile, *outfile;
    unsigned short int i, n, filesize;
    unsigned char   buffer, optiondefs = 0;
    unsigned char   programData[28000];
    unsigned short int checksum;

    /* --- Header File Values --- */
    /* The header will be modified if your destcalc_id is not 3... */
    unsigned char   header[11] = { '*', '*', 'T', 'I', '8', '3', '*', '*', 0x1A, 0x0A, 0x00 };
    unsigned char   comment[42] = "File created under ";
    unsigned char   fileLenLL = 0x00;
    unsigned char   fileLenHH = 0x00;
    unsigned char   varHeadLL = 0x00;
    unsigned char   varHeadHH = 0x00;
    unsigned char   dataLenLL = 0x00;
    unsigned char   dataLenHH = 0x00;
    unsigned char   programLenLL = 0x00;
    unsigned char   programLenHH = 0x00;
    if (uname(&system) == -1)
	strcat(comment, "unknown system");
    else
	strncat(comment, system.sysname, 20);
    /* --- Header File Values --- */


    /* Parse all arguments */
    struct CmdLineArgs *cmdline = (CmdLineArgs *) malloc(sizeof(CmdLineArgs));
    cmdline_init(cmdline);	/* set to null or default values all the fields of the struct */
    getargs(argc, argv, cmdline);	/* Get cmdline args */
    cmdline_finalize(cmdline);	/* Set to uppercase (or not). Add inverted a for crash (only 82p) */

    /* At this point, all cmdline args should be parsed correctly */ 

    	
    if(cmdline->verbose) { 
    	puts("Bin8x v1.3 Ti-82/83/83+ squisher");
    	puts("Copyright (C) 2001 Peter Martijn Kuipers <*****@*****.**>");
    	puts("Copyright (C) 2003 Tijl Coosemans <*****@*****.**>");
    	puts("Copyright (C) 2004 Guillaume Hoffman <*****@*****.**>");
    	puts("Copyright (C) 2011 Thibault Duponchelle <*****@*****.**>");
    }

    /* Concat extension */
   
    switch(cmdline->destcalc_id) {
	case EXT_82P:
		header[5] = '2';
		strcat(cmdline->output, ext82);
		break;
	case EXT_83P:
		strcat(cmdline->output, ext83);
		break;
	case EXT_8XP:
		header[6] = 'F';
		strcat(cmdline->output, ext8x);
		break;
	default:
		puts("\nError : not a valid extension!");
		exit(2);
		break;
	}
   
	/* At this point, all the informations are correct, we can do the real job */
	if(cmdline->verbose)
		print_cmdline(cmdline);

    /* Unsquish the code if user asked for it (option -q) */
    if(cmdline->unsquish) {
	if((strcmp(cmdline->input, "__temp__.bin") == 0) || strcmp(cmdline->output, "__temp__.bin") == 0) {
		printf("You must use another input/output filename...\n");
		exit(2);
	}
	int ret = unsquish(cmdline->input);
	if(ret == 1)
		return 1;
    } 
	 


	
    /* Unsquisher use a different file */	
    if (cmdline->input) {
	if(cmdline->unsquish){ 
		if(!(infile = fopen("__temp__.bin", "r"))) {
		    	puts("Error opening inputfile!");
		    	printf("File: __temp__.bin\n");
		    	return (2);
		}
	} else {
		if (!(infile = fopen(cmdline->input, "r"))) {
		    puts("Error opening inputfile!");
		    printf("File: %s\n", cmdline->input);
		    return (2);
		}
	}
	printf("Using inputfile        : %s\n", cmdline->input);
    }

    		
	if (!(outfile = fopen(cmdline->output, "w"))) {
	    puts("Error opening outputfile!");
	    return (3);
	}
	printf("Using outputfile       : %s\n", cmdline->output);

    printf("Filename on calculator : %s\n", cmdline->name);

    filesize = -1;

    if (cmdline->executable && cmdline->destcalc_id == EXT_8XP) {
	filesize++;
	programData[filesize] = 0xBB;
	filesize++;
	programData[filesize] = 0x6D;
    }
    // UNTESTED : (works only for CrASH(19006))
    if (cmdline->destcalc_id == EXT_82P) {
	filesize++;
	programData[filesize] = 0xD5;
	filesize++;
	programData[filesize] = 0x00;
	filesize++;
	programData[filesize] = 0x11;
    }


    while (!feof(infile)) {
	filesize++;
	buffer = fgetc(infile);
	programData[filesize] = buffer;	/* put this byte in the data
					 * array, and increase the count */
    }
	
    //printf("dcid : %c\n", cmdline->destcalc_id);
    switch(cmdline->destcalc_id) {
	case EXT_82P:
		// THAT IT WORKS
		printf("Size on calculator     : %u bytes\n", filesize + strlen(cmdline->name) + 6);
		fileLenHH = HH(filesize + 0x11);	/* the file length = the size of the data array + 17 (0x11) */
		fileLenLL = LL(filesize + 0x11);
		varHeadLL = 0x0B;
		break;

	case EXT_83P:
		printf("Size on calculator     : %u bytes\n", filesize + strlen(cmdline->name) + 6);
		fileLenHH = HH(filesize + 0x11);	/* the file length = the size of the data array + 17 (0x11) */
		fileLenLL = LL(filesize + 0x11);
		varHeadLL = 0x0B;
		break;

	default: 
		//EXT_8XP:
		printf("Size on calculator     : %u bytes\n", filesize + strlen(cmdline->name) + 8);
		fileLenHH = HH(filesize + 0x13);	/* the file length = the size of the data array + 19 (0x13) */
		fileLenLL = LL(filesize + 0x13);
		varHeadLL = 0x0D;
		break;

	    }

    dataLenHH = HH(filesize + 2);	/* the length of the data includes the 2 checksum bytes */
    dataLenLL = LL(filesize + 2);

    programLenHH = HH(filesize);
    programLenLL = LL(filesize);

    checksum = 0x00;		/* begin with the checksum set on zero */

    for (i = 0; i < 11; i++)	/* write the static header */
	fputc(header[i], outfile);

    for (i = 0; i < 42; i++)
	fputc(comment[i], outfile);

    fputc(fileLenLL, outfile);	/* file length */
    fputc(fileLenHH, outfile);

    fputc(varHeadLL, outfile);	/* length of variable header */
    checksum += varHeadLL;	/* checksum calculs start here */
    fputc(varHeadHH, outfile);
    checksum += varHeadHH;

    fputc(dataLenLL, outfile);	/* length of data */
    checksum += dataLenLL;
    fputc(dataLenHH, outfile);
    checksum += dataLenHH;

    fputc(cmdline->progtype, outfile);	/* protected program */
    checksum += cmdline->progtype;



    for (i = 0; i < 8; i++) {	/* write the name of the variable */
	fputc(cmdline->name[i], outfile);
	checksum += cmdline->name[i];
    }

	
    switch(cmdline->destcalc_id) {
	case EXT_8XP:
		puts("\nTI-83 Plus file made!!");
		fputc(0x01, outfile);
		checksum += 0x01;
		fputc(0x00, outfile);
		break; /* checksum += 0x00; */
	case EXT_83P:
		puts("\nPlain TI-83 file made!!");
		break;
	case EXT_82P:
		puts("\nTI-82 file made!!");
		break;
	default:
		puts("\nError : not a valid extension!");
		exit(2);
		break;
    }
    

    fputc(dataLenLL, outfile);
    checksum += dataLenLL;
    fputc(dataLenHH, outfile);
    checksum += dataLenHH;

    fputc(programLenLL, outfile);	/* length of program */
    checksum += programLenLL;
    fputc(programLenHH, outfile);
    checksum += programLenHH;


    for (i = 0; i < filesize; i++) {	/* now write the data array to the 
					 * file */
	fputc(programData[i], outfile);
	checksum += programData[i];	/* and add it to the checksum */
    }


    fputc(LL(checksum), outfile);	/* write the checksum to the file */
    fputc(HH(checksum), outfile);


    /*
     * Close all Handles 
     */
    fclose(infile);
    fclose(outfile);

    free(cmdline);

    return (0);
}