예제 #1
0
int main(int argc, char *argv[]) {
  GtkWidget *main_window;

  gtk_set_locale();
  gtk_init(&argc, &argv);

  main_window = create_main_window();

#ifdef USE_HILDON
  HildonProgram *app = HILDON_PROGRAM(hildon_program_get_instance());
  g_set_application_name("SmallBASIC");
  output.osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
  hildon_program_add_window(app, HILDON_WINDOW(main_window));
#endif

  drawing_area_init(main_window);
  gtk_widget_show_all(GTK_WIDGET(main_window));
  g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(destroy_event), NULL);

  // prepare runtime flags
  opt_graphics = 1;
  opt_quiet = 1;
  opt_interactive = 0;
  opt_nosave = 1;
  opt_ide = IDE_NONE;           // for sberr.c
  opt_command[0] = 0;
  opt_pref_width = 0;
  opt_pref_height = 0;
  opt_pref_bpp = 0;

  if (argc == 2 && access(argv[1], R_OK) == 0) {
    sbasic_main(argv[1]);
  }

  GtkWidget *dialog = create_opendialog();
  while (1) {
    gtk_widget_show(dialog);
    gtk_window_set_title(GTK_WINDOW(dialog), "Open BAS File");
    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
      char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      const char *p = strrchr(filename, '/');
      gtk_window_set_title(GTK_WINDOW(main_window), p ? p + 1 : filename);
      gtk_widget_hide(dialog);
      sbasic_main(filename);
      g_free(filename);
    } else {
      break;
    }
  }
  gtk_widget_destroy(dialog);
  om_cleanup();
  return 0;
}
예제 #2
0
/*
 * program entry point
 */
int main(int argc, char *argv[]) {
  char prev_cwd[OS_PATHNAME_SIZE + 1];

  opt_graphics = 0;
  opt_quiet = 1;
  opt_ide = 0;
  opt_nosave = 1;
  opt_pref_width = opt_pref_height = opt_pref_bpp = 0;
  opt_verbose = 0;
  opt_file_permitted = 1;

  // init strings
  opt_command[0] = 0;
  opt_modlist[0] = 0;
  prev_cwd[0] = 0;
  g_file[0] = 0;

  getcwd(prev_cwd, sizeof(prev_cwd) - 1);

  opt_retval = process_options(argc, argv);

  if (!opt_retval) {
    if (!opt_quiet) {
      printf("SmallBASIC version %s, use -h for help\n", SB_STR_VER);
    }
    // run it
    if (!opt_interactive) {
      sbasic_main(g_file);
    }

    chdir(prev_cwd);
  }

  return gsb_last_error ? gsb_last_error : opt_retval;
}
예제 #3
0
MHD_Response *execute(struct MHD_Connection *connection, const char *bas) {
  const char *width =
    MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "width");
  const char *height =
    MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "height");
  const char *command =
    MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "command");
  const char *graphicText =
    MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "graphic-text");
  const char *accept =
    MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT);

  if (width != NULL) {
    os_graf_mx = atoi(width);
  }
  if (height != NULL) {
    os_graf_my = atoi(height);
  }
  if (graphicText != NULL) {
    g_graphicText = atoi(graphicText) > 0;
  }
  if (command != NULL) {
    strcpy(opt_command, command);
  }

  log("%s dim:%dX%d", bas, os_graf_mx, os_graf_my);
  g_connection = connection;
  g_canvas.reset();
  g_start = dev_get_millisecond_count();
  g_canvas.setGraphicText(g_graphicText);
  g_canvas.setJSON((strncmp(accept, "application/json", 16) == 0));
  g_cookies.removeAll();
  sbasic_main(bas);
  g_connection = NULL;
  String page = g_canvas.getPage();
  MHD_Response *response =
    MHD_create_response_from_buffer(page.length(), (void *)page.c_str(),
                                    MHD_RESPMEM_MUST_COPY);
  List_each(String *, it, g_cookies) {
    String *next = (*it);
    MHD_add_response_header(response,
                            MHD_HTTP_HEADER_SET_COOKIE,
                            next->c_str());
  }