/* 4.03.1 ###############################################################
   
			SMAC FILE USED BY XCORAL EDITOR
   
   File: xcoralrc.lf
   Path: /Users/lionel/Documents/Dev/xcoral-4.02.8/SmacLib/xcoralrc.lf
   Description: 
   Created: Sun Aug  7 14:52:32 MET 1994
   Author: Lionel Fournigault
   Modified: Lun 17 mar 2025 19:05:37 CET
   Last maintained by:  lionel fournigault
   
   RCS $Revision$ $State$
   
   
   ####################################################################
   
   Note: initialization file for Xcoral.
   First load smac files in order. Then set fonts, colors names,
   indentation and user functions.
   It is possible to change colors names, indentation ans add user
   functions.

   ####################################################################
   
   Copyright (c) : Lionel Fournigault
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   
   #################################################################### */


/* --------------------------------------------------------------------
   Load standard libraries
   -------------------------------------------------------------------- */
{
  /* To display profile */
  load_file("top-ten.sc");
  
  /* general SMAC programmer and XCORAL user utilities */
  load_file("utilities.sc");
  
  /* C and C++ mode, auto indent, reindent, indent region etc */
  load_file("mode.sc" );

  /* provide class method and function profile */
  load_file("head.sc");
  
  /* extract logical pathname from automount pathname */
  load_file("hack-filename.sc");

  /* command shell utilities, grep make user interface */
  load_file("cmd.sc" );
  
  /* for us frenchies */
  load_file("french.sc");

  /* SMAC functions writer and/or user help */
  load_file("describe.sc");
  
  /* extensions of C and C++ modes */
  load_file("mode-ext.sc");
  
  /* mouse customization */
  load_file("mouse.sc");
  
  /* C C++ comments facilities */
  load_file("comments.sc");
  
  /* file title and custom organization title */
  load_file("title.sc");
  
  /* save file utilities */
  load_file("save.sc");
  
  /* global set key utilities */
  load_file("keydef-ext.sc");
  
  /* word completion */
  load_file("complete-word.sc");
  
  /* window-utilities */
  load_file("window-utilities.sc");
  
  /* compare two windows */
  load_file("compare-win.sc");

  /* latex indent */
  load_file("latex.sc");

  /* color region buffer */
  load_file("color.sc");

  /* edit directory */
  load_file("edir.sc");

  /* rcs interface */
  load_file("rcs.sc");
  
  /* Version control */
  load_file("version.sc");
  
  /* Latex utilities */
  load_file("latex-macros.sc");
  
  /* Misc utilities */
  load_file("misc-commands.sc");
 
  /* html utilities */
  load_file("html.sc");

  /* java mode */
  load_file("java.sc");

  /* hanoi demo */
  load_file("hanoi.sc");

  /* shell mode */
  load_file("shell-script.sc");
  
  /* javascript mode */
  load_file("javascript.sc");
  
  /* php mode */
  load_file("php.sc");
  
  /* python */
  load_file("python.sc");

  /* ada mode */
  load_file("ada.sc");
  
  /* fortran90 mode */
  load_file("fortran.sc");

  /* perl mode */
  load_file("perl.sc");
}

/* --------------------------------------------------------------------
   Define font for each mode.
   
   Default fonts available:
   
     "DejaVu Sans Mono:style=book:size=10:antialias=true"
     "Liberation Mono:style=Regular:size=10:antialias=true"
     "Source Code Pro:style=Regular:size=10:antialias=true"
     "DejaVu Serif:style=book:size=10:antialias=true"
     
   else use shell command fc-list to choose TrueType font
   
   -------------------------------------------------------------------- */
{
  set_mode_font("default", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("C-mode", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("C++mode", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Python", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Java", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("JavaScript", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Php", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Latex", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Html", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Ada", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Perl", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Fortran", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("shell", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Shell", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("Edir", "Liberation Mono:style=Regular:size=10:antialias=true");
  set_mode_font("french", "Liberation Mono:style=Regular:size=10:antialias=true");
}

/* -----------------------------------------------------------------------------------
   Define hightlighting colors text.
   Generics colors for all modes with dark background gray20 and white text color.
   The followings function, dark_bg and light_bg are selected at startup after evaluate
   the background color.
   By default background text window color is dark so dark_bg() is selected.
------------------------------------------------------------------------------------ */
void dark_bg () {
    gen_comment_color = "limegreen";
    gen_include_color = "goldenrod";
    gen_define_color = "yellowgreen";
    gen_keyword_color = "orange";
    gen_string_color = "paleturquoise";
    gen_varfunc_color = "cyan";
    gen_decl_color = "aquamarine";
    gen_class_color = "orange";
    gen_modifier_color = "tomato";
    gen_result_color = "violet";
    gen_del_new_color = "orangered";
    gen_return_color = "dodgerblue";
    gen_link_color = "hotpink";
    gen_makefile_color = "plum";
    gen_html_color = "chartreuse";
}
/* -------------------------------------------------------------------------------
   Else
   Generics colors for all modes with light background and black text color
   (Ex: xcoral -bg azure -fg black)
    ---------------------------------------------------------------------------- */
void light_bg() {
    gen_comment_color = "darkgreen";
    gen_include_color = "sienna";
    gen_define_color = "forestgreen";
    gen_keyword_color = "darkred";
    gen_string_color = "blue";
    gen_varfunc_color = "darkblue";
    gen_decl_color = "forestgreen";
    gen_class_color = "darkred";
    gen_modifier_color = "red";
    gen_result_color = "darkviolet";
    gen_del_new_color = "red";
    gen_return_color = "dodgerblue";
    gen_link_color = "tan";
    gen_makefile_color = "plum";
    gen_html_color = "darkgreen";
}

/* --------------------------------------------------------------------------------
   set_colors is called at startup after check background color.
   -------------------------------------------------------------------------------- */
void set_colors () {    
  /* C,C++ colors */
  cpp_comment_color = gen_comment_color;
  cpp_keyword_color = gen_keyword_color;
  cpp_define_color = gen_define_color;
  cpp_string_color = gen_string_color;
 
  /* python colors */
  python_comment_color = gen_comment_color;
  python_keyword_color = gen_keyword_color;
  python_define_color = gen_define_color;
  python_string_color = gen_string_color;

  /* Java colors */
  java_comment_color = gen_comment_color;
  java_import_color = gen_define_color;
  java_category_color = gen_del_new_color;
  java_result_color = gen_result_color;
  java_class_color = gen_class_color;
  java_modifier_color = gen_modifier_color;
  java_keyword_color = gen_keyword_color;
  java_package_color = gen_define_color;
  java_string_color = gen_string_color;

  /* JavaScript colors */
  javascript_comment_color = gen_comment_color;
  javascript_result_color = gen_result_color;
  javascript_class_color = gen_class_color;
  javascript_modifier_color = gen_modifier_color;
  javascript_keyword_color = gen_keyword_color;
  javascript_html_color = gen_html_color;
  javascript_import_color = gen_define_color;
  javascript_string_color = gen_string_color;
  javascript_package_color = gen_define_color;

  /* php colors */
  php_comment_color = gen_comment_color;
  php_result_color = gen_result_color;
  php_class_color = gen_class_color;
  php_modifier_color = gen_modifier_color;
  php_keyword_color = gen_keyword_color;
  php_html_color = gen_html_color;
  php_import_color = gen_define_color;
  php_string_color = gen_string_color;
  php_package_color = gen_define_color;

  /* latex colors */
  latex_comment_color = gen_comment_color;
  latex_keyword_color = gen_keyword_color;
  latex_defun_color = gen_decl_color;
  latex_define_color = gen_define_color;
  latex_decl_color = gen_decl_color;
  latex_label_color = gen_keyword_color;
  latex_include_color = gen_include_color;
  latex_italic_color = gen_decl_color;
  latex_bold_color = gen_varfunc_color;
  latex_ref_color = gen_comment_color;

  /* html colors */
  html_title_color = gen_comment_color;
  html_ibtt_color = gen_keyword_color;
  html_pre_color = gen_define_color;
  html_img_color = gen_decl_color;
  html_ref_color = gen_varfunc_color;
  html_list_color = gen_define_color;
  html_forms_color = gen_include_color;
  html_hds_color = gen_keyword_color;
  html_string_color = gen_string_color;
  
  /* Edir colors */
  edir_directory_color = gen_comment_color;
  edir_link_color = gen_link_color;
  edir_c_file_color = gen_decl_color;
  edir_tex_file_color = gen_decl_color;
  edir_sc_file_color = gen_decl_color;
  edir_h_file_color = gen_keyword_color;
  edir_makefile_color = gen_string_color;
  edir_readme_color = gen_del_new_color;

  /* Perl colors */
  perl_comment_color = gen_comment_color;
  perl_string_color = gen_string_color;
  perl_label_color = gen_define_color;
  perl_include_color = gen_include_color;
  perl_decl_color = gen_decl_color;
  perl_defun_color = gen_class_color;
  perl_keyword_color = gen_keyword_color;
  
  /* Fortran90 colors */
  f90_comment_color = gen_comment_color;
  f90_string_color  = gen_string_color;
  f90_unit_color    = gen_class_color;
  f90_include_color = gen_include_color;
  f90_type_color    = gen_decl_color;
  f90_decl_color    = gen_decl_color;
  f90_keyword_color = gen_keyword_color;
  
  /* Ada color */
  ada_comment_color = gen_comment_color;
  ada_glob_struct_color = gen_varfunc_color;
  ada_struct_color = gen_keyword_color;
  ada_decl_color = gen_decl_color;
  ada_include_color = gen_include_color;
  ada_string_color = gen_string_color;

  /* Makefile makefile and Imakefile colors */
  make_comment_color = gen_comment_color;
  make_rules_color = gen_varfunc_color;
  make_define_color = gen_define_color;
  make_keyword_color = gen_keyword_color;
  make_defun_color = gen_varfunc_color;
  make_include_color = gen_include_color;
  
  /* Shell colors */
  shell_comment_color = gen_comment_color;
  shell_string_color = gen_string_color;
  shell_include_color = gen_include_color;
  shell_define_color = gen_define_color;
  shell_var_color = gen_varfunc_color;
  shell_keyword_color = gen_keyword_color;
  
  /* Man colors */
  man_chapter_color = gen_varfunc_color;
  man_section_color = gen_keyword_color;
  man_smac_functions_color = gen_html_color;
  man_smac_browser_functions_color = gen_html_color;
}

/* ---------------------------------------------------------------------
   define indentation variables (mode C, C++,  Java and other mode)
   --------------------------------------------------------------------- */
{
  c_indent_in_comment = 3;
  c_indent_in_string = 0;
  c_indent_in_parenthesis = 1;
  c_indent_in_bracket = 1;
  c_indent_in_brace = 2;
  c_indent_in_statement = 2;
  c_arg_decl_indent = 4;

  java_indent_step = 2;
  javascript_indent_step = 2;
  php_indent_step = 2;
  ada_indent_step = 2;
  fortran_indent_step = 2;
  perl_indent_step = 2;
  python_indent_step = 4;
}

/* ---------------------------------------------------------------------
   define suffixes
   --------------------------------------------------------------------- */
{
  set_mode_suffixes("C++mode",".c .cc .cpp .h .hh .sc .xcoralrc");
  set_mode_suffixes("Python",".py");
  set_mode_suffixes("Java",".java");
  set_mode_suffixes("C-mode",".c .h .sc .xcoralrc");
  set_mode_suffixes("Latex",".tex .latex .sty");
  set_mode_suffixes("Html",".html");
  set_mode_suffixes("Perl",".pl");
  set_mode_suffixes("Fortran",".f .f90");
  set_mode_suffixes("Ada",".a");
  set_mode_suffixes("Python",".py");
  set_mode_suffixes("JavaScript",".js");
  set_mode_suffixes("Php",".php");
  set_mode_suffixes("shell", ".sh .csh .bashrc");
  
  set_mode_suffixes("french",".txt .texte");
}

/* ---------------------------------------------------------------------
   define modes on which global_key_def operates
   --------------------------------------------------------------------- */
{
  globalize_mode("default");
  globalize_mode("C-mode");
  globalize_mode("C++mode");
  globalize_mode("Python");
  globalize_mode("Java");
  globalize_mode("JavaScript");
  globalize_mode("Php");
  globalize_mode("Latex");
  globalize_mode("Html");
  globalize_mode("Perl");
  globalize_mode("Ada");
  globalize_mode("Fortran");
  globalize_mode("shell");
  globalize_mode("french");
  globalize_mode("Shell");
}

/* ---------------------------------------------------------------------
   Util Smac functions.
   --------------------------------------------------------------------- */
{
  global_key_def("^[>", "goto_end_of_file");

  global_key_def("^xt", "transpose_chars");
  global_key_def("^xy", "transpose_forms");
  global_key_def("^[\\", "delete_line_blanks");
  global_key_def("^[ ",  "just_one_blank");
  global_key_def("^[k",  "delete_to_beginning_of_line");
  global_key_def("^xc",  "center_line");
  global_key_def("^[m", "recenter");
  
  global_key_def("^x#", "sharp_comment");
  global_key_def("^x+", "plus_comment");
  global_key_def("^x=", "equal_comment");
  global_key_def("^x-", "minus_comment");
  global_key_def("^x%", "percent_comment");
  global_key_def("^xz", "update_title_and_save_file");
  global_key_def("^xs", "update_title_backup_and_save_file");
  global_key_def("^[/", "complete_word");
  global_key_def("^xC", "CompareAgain");
  global_key_def("^xg", "go_next");
  global_key_def("^xa", "color_buffer");
  
  global_key_def("^xp", "paste_selection");
  
  global_key_def("^xe", "edir");
  key_def("Edir", "^xe", "edir");

  key_def("Shell", "^[b", "backward_c_form");
  key_def("Shell", "^[f", "forward_c_form");
  key_def("Shell", "^[d", "delete_next_c_form");
  key_def("Shell", "^[\b", "delete_previous_c_form");
  key_def("Shell", "^[\177", "delete_previous_c_form"); /* esc delete */
  key_def("Shell", "^x^c", "quit_shell");

  key_def("Latex","^[x", "latex_back_indent");
}

/* ----------------------------------------------------------------------------
   French accents in Latex mode.
   ---------------------------------------------------------------------------- */
{
    key_def("Latex", "'", "french_accent");
    key_def("Latex", "`", "french_accent");
    key_def("Latex", "^^", "french_accent");
    key_def("Latex", "\"", "french_accent");
}


/* ================================================================================
   Here some user Smac functions examples.
   ================================================================================ */

/* --------------------------------------------------------------------------------
   Comment region with //. Select region before.
   -------------------------------------------------------------------------------- */
void comment_region () {
  int currentline, markline, count=0;

  if (mark_position() == -1) /* no mark */
    return;
  
  currentline = current_line();
  goto_mark();
  markline = current_line();
  goto_line(currentline);

  if (currentline == markline)
    return;
   
  while (currentline != markline) {
    goto_beginning_of_line();
    insert_string("//");
    if (currentline > markline)
      goto_previous_line();
    else
      goto_next_line();
    currentline = current_line();
    count += 2;
  }
  goto_beginning_of_line();
  insert_string("//");

  goto_line(markline);
  goto_beginning_of_line();
  color_buffer();
  redisplay();
}

/* --------------------------------------------------------------------------------
   Remove comment // in region.
   -------------------------------------------------------------------------------- */
void uncomment_region () {
  int currentline, markline;

  if (mark_position() == -1) /* no mark */
    return;
  
  currentline = current_line();
  goto_mark();
  markline = current_line();
  goto_line(currentline);

  if (currentline == markline)
    return;
   
  while (currentline != markline) {
    goto_beginning_of_line();

    if ((current_char() == '/') && (next_char()=='/')){
      delete_char();
      delete_char();
    }
    else {
      goto_line(markline);
      goto_beginning_of_line();
      color_buffer();
      redisplay();
      return;
    }
    
    if (currentline > markline)
      goto_previous_line();
    else
      goto_next_line();
    currentline = current_line();
  }
  goto_beginning_of_line();
  if ((current_char() == '/') && (next_char()=='/')){
    delete_char();
    delete_char();
  }

  goto_line(markline);
  goto_beginning_of_line();
  color_buffer();
  redisplay();
}

/* --------------------------------------------------------------------------------
   Edit .xcoralrc file. 
   -------------------------------------------------------------------------------- */
void edit_xcoralrc () {

  char *path, *home;
  
  home = cmd_shell_to_string("echo $HOME");
  path = (char*) malloc(strlen(home) + 12);
  sprintf ( path, "%s/.xcoralrc", home);
  
  open_file(path);
  
  if (home)
    free(home);
  if (path)
    free(path);
}

/* --------------------------------------------------------------------------------
   Edit .bashrc file
   -------------------------------------------------------------------------------- */
void edit_bashrc () {

  char *path, *home, *file;
  
  home = cmd_shell_to_string("echo $HOME");
  path = (char*) malloc(strlen(home) + 12);
  sprintf ( path, "%s/.bashrc", home);
  
  open_file(path);

  if (home)
    free(home);
  if (path)
    free(path);
}

/* --------------------------------------------------------------------------------
   Edit SmacLib file
   -------------------------------------------------------------------------------- */
void edit_smaclib_file() {
  
    char *str, *save, *item, *smacdir, *cmd, *file, *fullname;
    int i, len, window, win, raise=0;
    
    smacdir = cmd_shell_to_string("echo $XCORAL_SMACLIB");
    if ( strcmp(smacdir,"")==0 || strlen(smacdir)==0){
      smacdir = smaclib_dir();
    }
    cmd = (char*) malloc(strlen(smacdir) + 8);
    sprintf (cmd, "ls %s", smacdir);

    str = cmd_shell_to_string(cmd);
    save = str;
    item = (char*) malloc(64);
    clear_list();

    /* parcours de la chaine pour extraire les noms de fichiers */
    i = 0;
    while (*str != 0) {
      if (*str == 10){ /* \n */
	item[i] = 0;
	if (strcmp(item, "man.dtex")!=0)
	  add_list_item ( item );
	item = (char*) malloc(64);
	i = 0;
	str++;
      }
      item[i] = *str;
      i++;
      str++;
    }
    item[i] = *str;
    add_list_item (item);
    
    file = select_from_list("Edit SmacLib file");
    if (file == 0){
      if (smacdir) free(smacdir);
      if(cmd) free(cmd);
      if(save) free(save);
      return;
    }
    
    fullname = (char *) malloc(strlen(smacdir)+strlen(file)+10);
    sprintf (fullname, "%s/%s", smacdir, file);
    
    open_file(fullname);

    clear_list();
    
    if (fullname) free(fullname);
    if (smacdir) free(smacdir);
    if(cmd) free(cmd);
    if(save) free(save);
}

/* --------------------------------------------------------------------------------
   Display 8bits chars.
   -------------------------------------------------------------------------------- */
void display_8bits_chars(){
  int i=32, w, n=0;
  char *str = (char *) malloc (16);
  
  w = new_window();
  select_window(w);

  insert_string("All 8bits characters available:\n\n");
  while (i<256){
    insert_char(i);
    if ( i==120 || i==208 )
      insert_char('\n');
    i++;
  }
  insert_string("\n\n");
  i=32;
  while (i<256){
    sprintf (str, "'%c'=%d ", (char)i, i);
    insert_string(str);
    n += 8;
    if (n>80){
      insert_char('\n');
      n=0;
    }
    i++;
  }
  if (str)
    free(str);
}

/* ----------------------------------------------------------------------------
   Full buffer copy as region.
   ---------------------------------------------------------------------------- */
void copy_buffer(){
  
  int current_pos = current_position();
  
  goto_char(0);
  set_mark(current_position());
  goto_char(end_of_file());

  if (current_position() == 0)
    return;
  else
    copy_region();
  
  goto_char(current_pos);
}

/* ----------------------------------------------------------------------------
   User commands: call by Users commands item in Misc Menu or toolbar button.
   ---------------------------------------------------------------------------- */
void user_commands()
{
    char *str;
    int win = current_window();

    clear_list();
    add_list_item("Comment region");
    add_list_item("Uncomment region");
    add_list_item("Full buffer copy as region");
    add_list_item("Edit .xcoralrc");
    add_list_item("Edit .bashrc");
    add_list_item("Edit Smaclib files");
    add_list_item("Latest release number on web site");
    add_list_item("Display 8bits characters");

    str = select_from_list("User commands examples.");
    redisplay();
    select_window(win);
    
    if(str==0 || strlen(str) < 2) {
	return;
    }
    
    if (strcmp(str,"Comment region")==0) {
	comment_region();
	return;
    }
    if (strcmp(str,"Uncomment region")==0) {
	uncomment_region();
	return;
    }
    if (strcmp(str,"Full buffer copy as region")==0) {
	copy_buffer();
	return;
    }
    if (strcmp(str,"Edit .xcoralrc")==0) {
	edit_xcoralrc();
	return;
    }
    if (strcmp(str,"Edit .bashrc")==0) {
	edit_bashrc();
	return;
    }
    if (strcmp(str,"Edit Smaclib files")==0) {
	edit_smaclib_file();
	return;
    }
    if (strcmp(str,"Latest release number on web site")==0) {
	last_number_release();
	return;
    }
    if (strcmp(str,"Display 8bits characters")==0) {
	display_8bits_chars();
	return;
    }    
}
