Esempio n. 1
0
void set_main_window_title(void)
{
    gchar *title;

    title = get_file_basename(pub->fi->filename, TRUE);
    gtk_window_set_title(GTK_WINDOW(pub->mw->window), title);
    g_free(title);
}
Esempio n. 2
0
static void cb_modified_changed(GtkTextBuffer *buffer, GtkWidget *view)
{
	gboolean modified_flag, exist_flag = FALSE;
	gchar *filename, *title;
	
	modified_flag = gtk_text_buffer_get_modified(buffer);
	filename = get_file_basename(pub->fi->filename, TRUE);
	if (modified_flag)
		title = g_strconcat("*", filename, NULL);
	else {
		title = g_strdup(filename);
		undo_reset_modified_step(buffer);
	}
	g_free(filename);
	gtk_window_set_title(GTK_WINDOW(gtk_widget_get_toplevel(view)), title);
	g_free(title);
	if (pub->fi->filename)
		exist_flag = g_file_test(
			g_filename_to_utf8(pub->fi->filename, -1, NULL, NULL, NULL),
			G_FILE_TEST_EXISTS);
	menu_sensitivity_from_modified_flag(modified_flag || !exist_flag);
}
Esempio n. 3
0
gint check_text_modification(void)
{
	gchar *basename, *str;
	gint res;
	
	if (gtk_text_buffer_get_modified(pub->mw->buffer)) {
		basename = get_file_basename(pub->fi->filename, FALSE);
		str = g_strdup_printf(_("Save changes to '%s'?"), basename);
		g_free(basename);
		res = run_dialog_message_question(pub->mw->window, str);
		g_free(str);
		switch (res) {
		case GTK_RESPONSE_NO:
			return 0;
		case GTK_RESPONSE_YES:
			if (!on_file_save())
				return 0;
		}
		return -1;
	}
	
	return 0;
}
Esempio n. 4
0
void set_main_window_title(bool modified)
{
    static const char *TitleSeparator = " - ";
    static const char *ModifiedTag = "*";
    gchar *fileName;
    gchar *title;
    char *modifiedTag = NULL;

    // Check whether * should be added
    if ( modified ) {
        modifiedTag = ModifiedTag;
    }

    // Get the file name
    fileName = get_file_basename(pub->fi->filename, TRUE);

    // Build the name of the app
    title = g_strconcat( fileName, TitleSeparator, PACKAGE_NAME, modifiedTag, NULL );

    // Set title & clean
    gtk_window_set_title(GTK_WINDOW(pub->mw->window), title);
    g_free(fileName);
    g_free(title);
}
Esempio n. 5
0
/** 
 * \brief Process compiler options.
 * \param argc The number of input parameters.
 * \param argv The input parameter strings.
 * \return Indicates if processing was successful. 
 *         0 = processing successful
 *         1 = processing not successful
 *
 * Processes the input options passed to the compiler
 * and fill the compiler options structure as appropriate.
 * 
 * The following options are supported:
 *  -h: print help
 *  -p: print the IR to a file
 *  -t: test modus, only success/failure log
 *  -o: the output file name (different from 'input'.o)
 */
int process_options(int argc, char *argv[]) {
	int opt;
	int ret = 0;

	/* add a handler to resource manager to free resources
	 * in the case of an error during option processing */
	rm_register_handler(&resource_mgr, free_options, NULL);

	while ((opt = getopt(argc, argv, "hpto:")) != -1) {
		switch (opt) {
		case 'p':
			cc_options.print_ir = 1;
			break;
		case 't':
			/* fewer logs, for automated testing */
			cc_options.print_only_errors = 1;
			break;
		case 'o':
			/* output file */
			cc_options.output_file = strdup(optarg);
			if (cc_options.output_file == NULL) {
				fatal_os_error(OUT_OF_MEMORY, 1, __FILE__, __LINE__, "");
				return 1;
			}
			break;
		case 'h':
			/* print help */
			print_usage(argv[0]);
			rm_cleanup_resources(&resource_mgr);
			exit(EXIT_SUCCESS);

		default: /* '?' */
			/* print usage */
			fprintf(stderr, "ERROR: unknown parameter: %s\n", argv[optind]);
			print_usage(argv[0]);
			return 1;
		}
	}

	if (optind >= argc) {
		fprintf(stderr, "ERROR: missing input file\n");
		print_usage(argv[0]);
		ret = 1;
	} else if (optind < argc - 1) {
		fprintf(stderr, "ERROR: too many input files\n");
		print_usage(argv[0]);
		ret = 1;
	} else {
		cc_options.input_file = strdup(argv[optind]);
		if (cc_options.input_file == NULL) {
			fatal_os_error(OUT_OF_MEMORY, 1, __FILE__, __LINE__, "");
			return 1;
		}

		char *filebase = get_file_basename(cc_options.input_file);
		;
		if (filebase == NULL) {
			return 1;
		}

		if (!has_file_extension(cc_options.input_file, C_EXT)) {
			fprintf(stderr, "ERROR: no C file (.c) as input\n");
			ret = 1;
		} else {
			/* The file name has a valid .c extension */
			if (cc_options.output_file == NULL) {
				/* create output file name <input>.o */
				cc_options.output_file = get_filename_with_ext(filebase,
						OUTPUT_EXT);
				if (cc_options.output_file == NULL) {
					ret = 1;
				}
			}
			if (cc_options.print_ir == 1) {
				/* create IR file name <input>.ir */
				cc_options.ir_file = get_filename_with_ext(filebase, IR_EXT);
				if (cc_options.ir_file == NULL) {
					ret = 1;
				}
			}
		}

		free(filebase);
	}

	return ret;
}