示例#1
0
文件: diagram.c 项目: brunetton/dia
Diagram *
diagram_load(const char *filename, DiaImportFilter *ifilter)
{
  Diagram *diagram = NULL;
  GList *diagrams;
  gboolean was_default = FALSE;

  for (diagrams = open_diagrams; diagrams != NULL; diagrams = g_list_next(diagrams)) {
    Diagram *old_diagram = (Diagram*)diagrams->data;
    if (old_diagram->is_default) {
      diagram = old_diagram;
      was_default = TRUE;
      break;
    }	
  }

  /* TODO: Make diagram not be initialized twice */
  if (diagram == NULL) {
    diagram = new_diagram(filename);
  }
  if (diagram == NULL) return NULL;

  if (   !diagram_init(diagram, filename)
      || !diagram_load_into (diagram, filename, ifilter)) {
    if (!was_default) /* don't kill the default diagram on import failure */
      diagram_destroy(diagram);
    diagram = NULL;
  } else {
    /* not modifying 'diagram->unsaved' the state depends on the import filter used */
    diagram_set_modified(diagram, FALSE);
    if (app_is_interactive()) {
      recent_file_history_add(filename);
      if (was_default) /* replacing it is like first remove than add */
        dia_diagram_remove(diagram);
      dia_diagram_add(diagram);
    }
  }
  
  if (diagram != NULL && was_default && app_is_interactive()) {
    diagram_update_for_filename(diagram);
    diagram->is_default = FALSE;
    if ( g_slist_length(diagram->displays) == 1 )
      display_set_active (diagram->displays->data);
  }
  
  return diagram;
}
示例#2
0
文件: app_procs.c 项目: UIKit0/dia
void
app_init (int argc, char **argv)
{
  static gboolean nosplash = FALSE;
  static gboolean nonew = FALSE;
  static gboolean use_integrated_ui = TRUE;
  static gboolean credits = FALSE;
  static gboolean version = FALSE;
  static gboolean verbose = FALSE;
  static gboolean log_to_stderr = FALSE;
#ifdef HAVE_GNOME
  GnomeClient *client;
#endif
  static char *export_file_name = NULL;
  static char *export_file_format = NULL;
  static char *size = NULL;
  static char *show_layers = NULL;
  gboolean made_conversions = FALSE;
  GSList *files = NULL;
  static const gchar **filenames = NULL;
  int i = 0;

  gchar *export_format_string = 
     /* Translators:  The argument is a list of options, not to be translated */
    g_strdup_printf(_("Select the filter/format out of: %s"),
		    "cgm, dia, dxf, eps, eps-builtin, " EPS_PANGO
		    "fig, mp, plt, hpgl, png ("
#  if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
		    "png-libart, "
#  endif
#  ifdef HAVE_CAIRO
		    "cairo-png, cairo-alpha-png, "
#  endif
		    /* we always have pixbuf but don't know exactly all it's *few* save formats */
		    "pixbuf-png), jpg, "
		    "shape, svg, tex (pgf-tex, pstricks-tex), " WMF
		    "wpg");

  GOptionContext *context = NULL;
  static GOptionEntry options[] =
  {
    {"export", 'e', 0, G_OPTION_ARG_FILENAME, NULL /* &export_file_name */,
     N_("Export loaded file and exit"), N_("OUTPUT")},
    {"filter",'t', 0, G_OPTION_ARG_STRING, NULL /* &export_file_format */,
     NULL /* &export_format_string */, N_("TYPE") },
    {"size", 's', 0, G_OPTION_ARG_STRING, NULL,
     N_("Export graphics size"), N_("WxH")},
    {"show-layers", 'L', 0, G_OPTION_ARG_STRING, NULL,
     N_("Show only specified layers (e.g. when exporting). Can be either the layer name or a range of layer numbers (X-Y)"),
     N_("LAYER,LAYER,...")},
    {"nosplash", 'n', 0, G_OPTION_ARG_NONE, &nosplash,
     N_("Don't show the splash screen"), NULL },
    {"nonew", 'n', 0, G_OPTION_ARG_NONE, &nonew,
     N_("Don't create an empty diagram"), NULL },
    {"classic", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_integrated_ui,
     N_("Start classic user interface (no diagrams in tabs)"), NULL },
    {"log-to-stderr", 'l', 0, G_OPTION_ARG_NONE, &log_to_stderr,
     N_("Send error messages to stderr instead of showing dialogs."), NULL },
    {"input-directory", 'I', 0, G_OPTION_ARG_CALLBACK, _check_option_input_directory,
     N_("Directory containing input files"), N_("DIRECTORY")},
    {"output-directory", 'O', 0, G_OPTION_ARG_CALLBACK, _check_option_output_directory,
     N_("Directory containing output files"), N_("DIRECTORY")},
    {"credits", 'c', 0, G_OPTION_ARG_NONE, &credits,
     N_("Display credits list and exit"), NULL },
    {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose,
     N_("Generate verbose output"), NULL },
    {"version", 'v', 0, G_OPTION_ARG_NONE, &version,
     N_("Display version and exit"), NULL },
    { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL /* &filenames */,
      NULL, NULL },
    { NULL }
  };
  
  /* for users of app_init() the default is interactive */
  dia_is_interactive = TRUE;

  options[0].arg_data = &export_file_name;
  options[1].arg_data = &export_file_format;
  options[1].description = export_format_string;
  options[2].arg_data = &size;
  options[3].arg_data = &show_layers;
  g_assert (strcmp (options[13].long_name, G_OPTION_REMAINING) == 0);
  options[13].arg_data = (void*)&filenames;

  argv0 = (argc > 0) ? argv[0] : "(none)";

#if GTK_CHECK_VERSION(2,24,0)
  /* ... use setlocale directly? */
#else
  gtk_set_locale();
#endif
  setlocale(LC_NUMERIC, "C");
  _setup_textdomains ();

  context = g_option_context_new(_("[FILE...]"));
  g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
#ifndef HAVE_GNOME
  /* avoid to add it a second time */
  g_option_context_add_group (context, gtk_get_option_group (FALSE));
#endif
  if (argv) {
    GError *error = NULL;

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
      if (error) { /* IMO !error here is a bug upstream, triggered e.g. with --gdk-debug=updates */
	g_print ("%s", error->message);
	g_error_free (error);
      } else {
	g_print (_("Invalid option?"));
      }

      g_option_context_free(context);
      exit(1);
    }
    /* second level check of command line options, existance of input files etc. */
    if (filenames) {
      while (filenames[i] != NULL) {
	gchar *filename; 
	gchar *testpath;	  

	if (g_str_has_prefix (filenames[i], "file://")) {
	  filename = g_filename_from_uri (filenames[i], NULL, NULL);
	  if (!g_utf8_validate(filename, -1, NULL)) {
	    gchar *tfn = filename;
	    filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
	    g_free(tfn);
	  }
	} else
	  filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL);

	if (!filename) {
	  g_print (_("Filename conversion failed: %s\n"), filenames[i]);
	  continue;
	}

	if (g_path_is_absolute(filename))
	  testpath = filename;
	else
	  testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL);

	/* we still have a problem here, if GLib's file name encoding would not be utf-8 */
	if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR))
	  files = g_slist_append(files, filename);
	else {
	  g_print (_("Missing input: %s\n"), filename);
	  g_free (filename);
	}
	if (filename != testpath)
	  g_free (testpath);
	++i;
      }
    }
    /* given some files to output, we are not starting up the UI */
    if (export_file_name || export_file_format || size)
      dia_is_interactive = FALSE;

  }

  if (argv && dia_is_interactive && !version) {
#ifdef HAVE_GNOME
    GnomeProgram *program =
      gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
			  argc, argv,
			  /* haven't found a quick way to pass GOption here */
			  GNOME_PARAM_GOPTION_CONTEXT, context,
			  GNOME_PROGRAM_STANDARD_PROPERTIES,
			  GNOME_PARAM_NONE);
    client = gnome_master_client();
    if(client == NULL) {
      g_warning(_("Can't connect to session manager!\n"));
    }
    else {
      g_signal_connect(G_OBJECT (client), "save_yourself",
		       G_CALLBACK (save_state), NULL);
      g_signal_connect(G_OBJECT (client), "die",
		       G_CALLBACK (session_die), NULL);
    }

    /* This smaller icon is 48x48, standard Gnome size */
    /* gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/dia_gnome_icon.png");*/

#else
#  ifdef G_THREADS_ENABLED
    g_thread_init (NULL);
#  endif
    gtk_init(&argc, &argv);
#endif
  }
  else {
#ifdef G_THREADS_ENABLED
    g_thread_init (NULL);
#endif
    g_type_init();
    /*
     * On Windows there is no command line without display so that gtk_init is harmless. 
     * On X11 we need gtk_init_check() to avoid exit() just because there is no display 
     * running outside of X11.
     */
    if (!gtk_init_check(&argc, &argv))
      dia_log_message ("Running without display");
  }

  /* done with option parsing, don't leak */
  g_free(export_format_string);
  
  if (version) {
    gchar *ver_utf8;
    gchar *ver_locale;
#if (defined __TIME__) && (defined __DATE__)
    /* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */
    ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__);
#else
    ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION);
#endif
    ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL);
    printf("%s\n", ver_locale);
    g_free(ver_locale);
    g_free(ver_utf8);
    if (verbose)
      dump_dependencies();
    exit(0);
  }

  if (!dia_is_interactive)
    log_to_stderr = TRUE;

  libdia_init (   (dia_is_interactive ? DIA_INTERACTIVE : 0)
	       | (log_to_stderr ? DIA_MESSAGE_STDERR : 0)
	       | (verbose ? DIA_VERBOSE : 0) );

  print_credits(credits);

  if (dia_is_interactive) {
    create_user_dirs();

    if (!nosplash)
      app_splash_init("");

    /* Init cursors: */
    default_cursor = gdk_cursor_new(GDK_LEFT_PTR);
    ddisplay_set_all_cursor(default_cursor);
  }

  dia_register_plugins();
  dia_register_builtin_plugin(internal_plugin_init);

  load_all_sheets();     /* new mechanism */

  dia_log_message ("object defaults");
  {
    DiaContext *ctx = dia_context_new (_("Object Defaults"));
    dia_object_defaults_load (NULL, TRUE /* prefs.object_defaults_create_lazy */, ctx);
    dia_context_release (ctx);
  }
  debug_break();

  if (object_get_type("Standard - Box") == NULL) {
    message_error(_("Couldn't find standard objects when looking for "
		  "object-libs; exiting...\n"));
    g_critical( _("Couldn't find standard objects when looking for "
	    "object-libs in '%s'; exiting...\n"), dia_get_lib_directory("dia"));
    exit(1);
  }

  persistence_load();

  /** Must load prefs after persistence */
  prefs_init();

  if (dia_is_interactive) {

    /* further initialization *before* reading files */  
    active_tool = create_modify_tool();

    dia_log_message ("ui creation");
    if (use_integrated_ui) {
      create_integrated_ui();
    } else {
      create_toolbox();
      /* for the integrated ui case it is integrated */
      persistence_register_window_create("layer_window",
				         (NullaryFunc*)&layer_dialog_create);
    }
      
    /*fill recent file menu */
    recent_file_history_init();

    /* Set up autosave to check every 5 minutes */
    g_timeout_add_seconds(5*60, autosave_check_autosave, NULL);

#if 0 /* do we really open these automatically in the next session? */
    persistence_register_window_create("diagram_tree", 
                                       &diagram_tree_show);
#endif
    persistence_register_window_create("sheets_main_dialog",
				       (NullaryFunc*)&sheets_dialog_create);

    /* In current setup, we can't find the autosaved files. */
    /*autosave_restore_documents();*/

  }

  dia_log_message ("diagrams");
  made_conversions = handle_all_diagrams(files, export_file_name,
					 export_file_format, size, show_layers,
					 input_directory, output_directory);
					 
  if (dia_is_interactive && files == NULL && !nonew) {
    if (use_integrated_ui) {
      GList * list;
    
      file_new_callback(NULL);  
      list = dia_open_diagrams();
      if (list) {
        Diagram * diagram = list->data;
        diagram_update_extents(diagram);
        diagram->is_default = TRUE;
      }
    } else {
      gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL);
      Diagram *diagram = new_diagram (filename);
      g_free(filename);
    
      if (diagram != NULL) {
        diagram_update_extents(diagram);
        diagram->is_default = TRUE;
        /* I think this is done in diagram_init() with a call to 
         * layer_dialog_update_diagram_list() */
        layer_dialog_set_diagram(diagram);
        new_display(diagram); 
      }
    }
  }
  g_slist_free(files);
  if (made_conversions) exit(0);

  dynobj_refresh_init();
  dia_log_message ("initialized");
}
示例#3
0
文件: app_procs.c 项目: UIKit0/dia
/** Handle loading of diagrams given on command line, including conversions.
 * Returns TRUE if any automatic conversions were performed.
 * Note to future hackers:  'size' is currently the only argument that can be
 * sent to exporters.  If more arguments are desired, please don't just add
 * even more arguments, but create a more general system.
 */
static gboolean
handle_initial_diagram(const char *in_file_name, 
		       const char *out_file_name,
		       const char *export_file_format,
		       const char *size,
		       char* show_layers,
		       const char *outdir) {
  Diagram *diagram = NULL;
  gboolean made_conversions = FALSE;

  if (export_file_format) {
    char *export_file_name = NULL;
    DiaExportFilter *ef = NULL;

    /* First try guessing based on extension */
    export_file_name = build_output_file_name(in_file_name, export_file_format, outdir);

    /* to make the --size hack even uglier but work again for the only filter supporting it */
    if (   size && strcmp(export_file_format, "png") == 0)
      ef = filter_export_get_by_name ("png-libart");
    if (!ef)
      ef = filter_guess_export_filter(export_file_name);
    if (ef == NULL) {
      ef = filter_export_get_by_name(export_file_format);
      if (ef == NULL) {
	g_critical(_("Can't find output format/filter %s\n"), export_file_format);
	return FALSE;
      }
      g_free (export_file_name);
      export_file_name = build_output_file_name(in_file_name, ef->extensions[0], outdir);
    }
    made_conversions |= do_convert(in_file_name,
      (out_file_name != NULL?out_file_name:export_file_name),
				   ef, size, show_layers);
    g_free(export_file_name);
  } else if (out_file_name) {
    DiaExportFilter *ef = NULL;

    /* if this looks like an ugly hack to you, agreed ;)  */
    if (size && strstr(out_file_name, ".png"))
      ef = filter_export_get_by_name ("png-libart");
    
    made_conversions |= do_convert(in_file_name, out_file_name, ef,
				   size, show_layers);
  } else {
    if (g_file_test(in_file_name, G_FILE_TEST_EXISTS)) {
      diagram = diagram_load (in_file_name, NULL);
    } else {
      diagram = new_diagram (in_file_name);
    }
	      
    if (diagram != NULL) {
      diagram_update_extents(diagram);
      if (app_is_interactive()) {
	layer_dialog_set_diagram(diagram);
        /* the display initial diagram holds two references */
	new_display(diagram);
      } else {
        g_object_unref(diagram);
      }
    }
  }
  return made_conversions;
}
示例#4
0
int main(int argc, char *argv[])
{
int callrun;

#ifdef MTRACE_DEBUG
mtrace();
#endif
   /* Start initialisation:*/
   /* Pick out the number from the string "$Revision: 2.37 $":*/
   {/*Block begin*/
        char *tmp=currentrevision;
        for( tmp=currentrevision;(*tmp!=' ')&&(*tmp!='\0');tmp++);
        if(*tmp == ' ') tmp++;
        for( currentRevisionNumber=tmp;(*tmp!=' ')&&(*tmp!='\0');tmp++);
        *tmp='\0';
   }/*Block end*/

   /* Check here is there the request for the version information.
    * If so, output the revision number and quit, if there are no any
    * other option:
    */
   for(i=1; i<argc; i++)
      if( (s_cmp(argv[i],"-V")==0)||(s_cmp(argv[i],"-version")==0)){
        printf("%s\n",currentRevisionNumber);
        if(argc == 2) exit(0);
      }

   first_init();/*module init.c*/
   read_command_line(argc, argv);/*module cmd_line.c*/
   message(INITIALIZATION,NULL);
   /*End initialisation*/
   message(READINGCONFIG,config_name);
   scaner_init(config_name,cnf_comment);/*module init.c*/
   read_config_file_before_truns();/*module cnf_read.c*/
   if( is_bit_set(&mode,bitCHECKMOMENTABALANCE)&&
       (!is_bit_set(&mode,bitONLYINTERPRET))
    ){

       check_momenta_balance_on_each_topology();
   }
   message(DONE,NULL);

   /*Translation of the TM program:*/
   {char tmp[MAX_STR_LEN];

       if (
             (is_bit_set(&mode,bitONLYINTERPRET))||
             (!is_bit_set(&mode,bitBROWS))||
             (is_bit_set(&mode,bitVERIFY))||
             (is_bit_set(&mode,bitFORCEDTRUNSLATION))
          ){
             command_init();/*module truns.c*/
             if(!is_bit_set(&mode,bitONLYINTERPRET)){
                if (set_table==NULL)set_table=create_hash_table(
                      set_hash_size,str_hash,str_cmp,c_destructor);
                if(is_bit_set(&mode,bitBROWS))
                  install(new_str("_specmode"),new_str("browser"),set_table);
                else
                  install(new_str("_specmode"),new_str("common"),set_table);
             }
             message(BEGINTRUNS,NULL);
             do{
               if(truns(&current_number_of_trunslated_lines,
                           &current_array_of_trunslated_lines)){
                  number_of_trunslated_lines=
                                        current_number_of_trunslated_lines;
                  current_number_of_trunslated_lines=0;
                  array_of_trunslated_lines=
                                         current_array_of_trunslated_lines;
                  current_array_of_trunslated_lines=NULL;
               }
             }while(number_of_trunslated_lines==0);
             message(ENDTRUNS,NULL);
             mem_esc_char=esc_char;
             macro_done();/*module macro.c*/
             reject_proc();/*module truns.c*/
             command_done();/*module truns.c*/
             clear_defs();/*module truns.c*/
             clear_label_stack();/*module truns.c*/
             for_done();/*module truns.c*/
             IF_done();/*module truns.c*/
             if(s_scmp(sc_get_token(tmp),"translate"))
                halt(UNEXPECTED ,tmp);
       }
   }
   sc_done();/*module tools.c*/
   /*TM program is translated. The resulting code is in array_of_trunslated_lines*/

/*Keep the table up to the end of the program!:*/
#ifdef SKIP
   if (vectors_table!=NULL){
      hash_table_done(vectors_table);/*module hash.c*/
      vectors_table=NULL;
   }
#endif

   message(DONEINIT,NULL);

   if (is_bit_set(&mode,bitVERIFY)){
     message(ONLYVERIFY,NULL);
     errorlevel=0;halt(NOERROR,NULL);
   }

   if (g_ttnames != NULL){/*Topology tables were defined in the config file*/
      HASH_TABLE wrktrans;
      message(LOADINGTABLES,NULL);
      read_topology_tables();/*module utils.c*/
      free_mem(&g_ttnames);
      /*Create the working table:*/
      g_tt_wrk=tt_createNewTable(g_defaultTokenDictSize,g_defaultHashTableSize);

      /*Check success, if not, halt the system:*/
      checkTT(g_tt_wrk,FAILCREATINGWRKTABLE);

      /*Collect translations from all tables:*/
      wrktrans=tt_table[g_tt_wrk-1]->htrans;
      /*Full toplogies:*/
      for(i=0;i<g_tt_top_full;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_full[i]-1]->htrans;
         if( ttrans!=NULL )
              binary_operations_under_hash_table(
                 ttrans,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_full;i++)*/
      /*Internal topologies:*/
      for(i=0;i<g_tt_top_int;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_int[i]-1]->htrans;
         if( ttrans!=NULL )
              binary_operations_under_hash_table(
                 ttrans,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_int;i++)*/

      /*Override translations, if present, in wrk table; in loaded tables
        translations remain to be untranslated!:*/
      if( g_ttTokens_table!=NULL )
              binary_operations_under_hash_table(
                 g_ttTokens_table,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/

      /*Now wrk table is ready*/
      /*Override translations, if present, in full toplogies:*/
      if( g_ttTokens_table!=NULL )for(i=0;i<g_tt_top_full;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_full[i]-1]->htrans;
         if( ttrans!=NULL )/*BTW, it CANNOT be a NULL! See, how tt_createNewTableis invoked
                             in the beginning of tt_loadTable, file tt_load.c*/
              binary_operations_under_hash_table(
                 g_ttTokens_table,/*"from"*/
                 ttrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_full;i++)*/
      message(DONE,NULL);
   }/*if (g_ttnames != NULL)*/

   /*If only interpret, we need not analyse diagrams:*/
   if(is_bit_set(&mode,bitONLYINTERPRET)){
    int exitcode;
      run_init(1);/*module init.c*/
      esc_char=mem_esc_char;
      islast=1;
      g_nocurrenttopology=1;/*Similar to islast, but specially for topologies.*/
      message(CALLTOINTERPRETER,NULL);
      exitcode=run(number_of_trunslated_lines,array_of_trunslated_lines);
      message(DONE,NULL);
      {char endmessage[MAX_STR_LEN];
         sprintf(endmessage,EXITCODEFROMINTERPRETER,exitcode);
         errorlevel=exitcode;
         halt(endmessage,NULL);
      }
      /*Stop running...*/
   }/*if(is_bit_set(&mode,bitONLYINTERPRET)*/

   /*ok, if we are here then we have to read diagrams...*/
   detect_last_diagram_number();/*module last_num.c*/
   message(LOOKINGFORFIRRSTDIAGRAM,NULL);
   scaner_init(input_name,0);/*module init.c*/
   skip_until_first_actual_diagram();/*module read_inp.c*/
   create_table(&dbuf,&dtable,MAX_VERTEX,MAX_I_LINE,ext_lines);/*module utils.c*/
   create_table(&wrkbuf,&wrktable,MAX_VERTEX,MAX_I_LINE,ext_lines);
   message(DONE,NULL);
   message(READDIAGRAMS,NULL);

   for(i=start_diagram;!(i>finish_diagram);i++){/*begin main loop*/
      skip_to_new_diagram();/* module read_inp.c Reads until '['*/

      if(i % STEP_INDICATOR == 0){
        char mes[MAX_STR_LEN];
          sprintf(mes,INDICATE_MESSAGE,i,finish_diagram);
          message(mes,NULL);
      }/*if(i % STEP_INDICATOR == 0)*/

      /* Check should we process this diagram:*/
      if (set_in(i % 250,dmask[i / 250])) continue;

      new_diagram();/*module read_inp.c. Some initializations
                                                       before each diagram.*/

      detect_number_and_coefficient();/*module read_inp.c
                                        This function must receive from
                                        scaner exactly 'd###'*/
      if(i!=diagram_count)
         halt(CURRUPTEDINPUT,input_name);
      create_primary_diagram_table();/*module read_inp.c*/

      if ( skiptadpoles && thisistadpole )
         continue;
      define_topology();/*module read_inp.c*/
      /*compare_topology() returns 1 if topology is not actual.
      If topology is undefined, this procedure will call
      'out_undefined_topology();' (if bitBROWS is not set) and set bitTERROR.
      */
      if(compare_topology())/*module read_inp.c*/
         continue;

      create_diagram_table();/*module read_inp.c*/

      define_prototype();/*module read_inp.c*/
      if(!is_bit_set(&mode,bitFORCEDTRUNSLATION))
          if(skip_prototype())/*module utils.c*/
            continue;
      create_indices_table();/*module read_inp.c*/
      if(must_diagram_be_skipped())/*module utils.c*/
         continue;
      if (is_bit_set(&mode,bitBROWS))
         fill_up_diagram_array(count);/*module read_inp.c*/
      count++;
      if(is_bit_set(&mode,bitFORCEDTRUNSLATION)){
         if(g_tt_try_loaded>0)/*Automatic momenta distribution mechanism*/
            callrun=1;
         else if(   ( is_bit_set(&mode,bitTERROR) )&&(!is_bit_set(&mode,bitBROWS)))
           callrun=0;
         else
           callrun=1;
      }else{
         callrun=(
              (!is_bit_set(&mode,bitTERROR) )&&
              (!is_bit_set(&mode,bitBROWS) )
         );
      }
      /*Run the interpreter:*/
      if(callrun){
         build_form_input();/*module read_inp.c*/
         run_init(0);/*module init.c*/
         esc_char=mem_esc_char;
         if(run(number_of_trunslated_lines,array_of_trunslated_lines)==HALT)
             set_bit(&mode,bitRUNSIGNAL);
         run_clear();/*module init.c*/
         if(is_bit_set(&mode, bitSKIP)){
            unset_bit(&mode,bitSKIP);
            count--;
         }else if((is_bit_set(&mode,bitFORCEDTRUNSLATION))&&
                            (skip_prototype()/*module utils.c*/)){
            count--;
         }else{
            if(g_topologyLabel!=NULL){/*First occurence, otherwise will be NULL*/
               /*Mark topology as occurred*/
               set_bit(g_topologyLabel,0);
               if(g_tt_try_loaded>0){/*Table were loaded*/

                  if( topologies[cn_topol].orig==NULL )/*Undefined topology*/
                     process_topol_tables(0);/*try to find momenta, read_inp.c*/

                  if(topologies[cn_topol].coordinates_ok==0)/*No coords*/
                     process_topol_tables(1);/*try to find coordinates, read_inp.c*/
                  /*Now current topology is marked, and wrk toable is built.*/
               }else{
                  if( topologies[cn_topol].orig==NULL ){/*Undefined topology*/
                     if( automatic_momenta_group(NULL,cn_topol)==1)
                        /*Now momenta are distributed automatically:*/
                        set_bit(g_topologyLabel,2);
                        /*Bit 0: 0, if topology not occures, or 1;
                          bit 1: 1, if topology was produced form generic, or 0.
                          bit 2: 1, automatic momenta is implemented, or 0
                        */
                  }/*if( topologies[cn_topol].orig==NULL )*/
               }/*if(g_tt_try_loaded>0)...else...*/
            }/*if(g_topologyLabel!=NULL)*/
            output_common_protocol(count);/*module read_inp.c*/
         }/*if(is_bit_set(&mode, bitSKIP)) ... else ... else*/
         if(is_bit_set(&mode,bitRUNSIGNAL)){
            sc_done();
            errorlevel=0;
            halt(RUNSIGNAL,NULL);
         }/*if(is_bit_set(&mode,bitRUNSIGNAL))*/
      }/*if(callrun)*/
   }/*end main loop*/

   sc_done();
   message(DONEDIAGRAMS,NULL);

   /*Check should we run the interpreter once more:*/
   if(is_bit_set(&mode,bitEND)){
      /*To use some of specmode operators during "extra call":*/
      new_diagram();

      run_init(1);
      esc_char=mem_esc_char;
      islast=1;

      g_nocurrenttopology=1;/*Similar to islast, but specially for topologies.*/
      cn_topol=top_topol;/*Indicate that there is no special topology */
      message(EXTRACALL,NULL);
      if(run(number_of_trunslated_lines,array_of_trunslated_lines)==HALT){
         errorlevel=0;
         halt(RUNSIGNAL,NULL);
      }
      message(DONE,NULL);
   }/*if(is_bit_set(&mode,bitEND))*/

   if (is_bit_set(&mode,bitBROWS)){
      message(BROWSERMODEDETECT,NULL);
      out_browse_head(count);/*module browser.c*/
      message(SORTINGDIAGRAMS,NULL);
      sort_diargams(count);/*module browser.c*/
      message(DONE,NULL);
      message(PRINTINGDIAGRAMS,NULL);
      print_diagrams(count);/*module browser.c*/
      message(DONE,NULL);
      sort_prototypes();/*module browser.c*/
      print_prototypes();/*module browser.c*/
      print_all_found_topologies();/*module browser.c*/
      print_not_found_topologies();/*module browser.c*/
      print_undefined_topologies();/*module browser.c*/
   }/*if (is_bit_set(&mode,bitBROWS))*/
   errorlevel=0;
   halt(NOERROR,NULL);
   return(0);/*Actually, the control can't reach this point*/
}/*main*/