/*{{{}}}*/
/*{{{  #includes*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#define TEXTC

#include <h/keys.h>
#include <h/envvar_str.h>
/*}}}  */

/*{{{  fold-marks*/
char fo[FOLD_TAG_LENGTH+1]=BEGIN_STANDARD;
char fc[FOLD_TAG_LENGTH+1]=END_STANDARD;
/*}}}  */
/*{{{  names and messages*/
#include "name.h"
#include "keybind/msgname.c"
/*}}}  */
/*{{{  textstrings*/
/*{{{  define formats for rc-offsets*/
#define X_ADR   "%07lx"
#define X_HELP  "ooooooo"
#define DUMMY_FOLD "---  "
#define F_POS   X_ADR " "
#define F_OH    X_HELP " "
/*}}}  */
/*{{{  define strings for command,adress,..*/
#define CHAR          "%c"
#define CTRL_CHAR     "C-" CHAR
#define OCL_INT       "%6d"
#define SM_INT        "%4d"

#define KEY_VAL       "%3d"
#define KEY_CODE      "%3s"
#define KEY_CHAR      " " CHAR " "

#define COMMAND       "%-24s"
#define INT_ARG       OCL_INT
#define CHAR_ARG      OCL_INT " =     " CHAR
#define CTRL_CHAR_ARG OCL_INT " =   " CTRL_CHAR
#define ADRESS        "%05d "
#define ADR_ARG       OCL_INT " = " ADRESS
#define WHITE_ADR     "      "

#define MACRO_NUM     "%4d"

#define CMD_ARROW     " => "
/*}}}  */
char const F_AB_MACRO[]=    DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as abort-macro.\n";
char const F_AUTO_END[]=    ADRESS " " COMMAND "\n";
char const F_A_MACRO[]=     DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as read-newfile-macro.\n";
char const F_BCHG[]=        DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as change-buffer-macro.\n";
char const F_CRASH[]=       "CRASH, maybe rc-file is corrupted at " F_POS "!\n";
char const F_SQM[]=         DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as sigquit-macro.\n";
char const F_U1M[]=         DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as sigusr1-macro.\n";
char const F_U2M[]=         DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as sigusr2-macro.\n";
char const F_ALARM[]=       DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as sigalarm-macro.\n";
char const F_BREAK[]=       DUMMY_FOLD F_POS "keybind uses " KEY_VAL "=" KEY_CODE KEY_CHAR" as general-abort-key.\n";
char const F_CHAR[]=        CHAR;
char const F_CHECK[]=       DUMMY_FOLD F_POS "format-code " OCL_INT ", " MAJOR_VERSION "." MINOR_VERSION "." REVISION " uses " OCL_INT ".\n";
char const F_CLOSE[]=       "%s\n";
char const F_COMMENT[]=     "ccc  " X_ADR " <";
char const F_COMP_DATA[]=   "%s  " F_POS "reference compression strings\n";
char const F_CONST[]=       "%s  " F_POS "constants\n";
char const F_COUNTER[]=     "<counter " INT_ARG ">";
char const F_DIGIT[]=       "<" KEY_VAL ">";
char const F_ENDE[]=        DUMMY_FOLD F_POS "end of rc-file\n";
char const F_END_MACRO[]=   ">\n" WHITE_ADR " " COMMAND "\n";
char const F_ERROR[]=       DUMMY_FOLD F_POS "\n"
                            "-----------------------------------------\n"
                            "'token' " OCL_INT "unknown\n"
                            "no dissassemble possible\n";
char const F_EXIT_START[]=  ADRESS " " COMMAND "\n         <";
char const F_F_LIST[]=      DUMMY_FOLD F_POS "start with list of edited files\n";
char const F_HELPHEAD[]=    "%s  " F_POS "helpfile\n";
char const F_HIST[]=        "<history " INT_ARG ">";
char const F_H_ALIAS[]=     X_ADR "\ttag=%5d, next=%5d\n";
char const F_H_LINE1[]=     X_ADR "\ttag=%5d, code ='%s'";
char const F_H_LINE2[]=     "+%3d=\n '%s'\n";
char const F_INTS[]=        DUMMY_FOLD F_POS "keybind needs " OCL_INT " variables.\n";
char const F_KEY_HEAD[]=    "%s  " F_POS "keyboard\t%s\tmarks%s nodes " OCL_INT "\n";
char const F_KNB_NODE[]=    CMD_ARROW"trigger key-not-bound\n";
char const F_K_MACRO[]=     DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as key-not-bound-macro.\n";
char const F_KTBS[]=        DUMMY_FOLD F_POS "keybind needs " SM_INT " keytables.\n";
char const F_LINE_LIM[]=    DUMMY_FOLD F_POS "line limiter is '" CHAR "'\n";
char const F_MACRO_HEAD[]=  "%s  " F_POS "macro " MACRO_NUM " (lg=" OCL_INT ") %s\n";
char const F_MACSIZE[]=     "binding uses " OCL_INT " tokens (" OCL_INT " fixed," OCL_INT " demand loading)\n";
char const F_MACS[]=        DUMMY_FOLD F_POS "keybind needs " OCL_INT " fix-macros.\n";
char const F_MAC_SET[]=     "%s  " F_POS "macro set " OCL_INT " tokens\n";
char const F_MARK[]=        DUMMY_FOLD F_POS "keybind has additional mark-typ %s : ";
char const F_MODE_LIM[]=    DUMMY_FOLD F_POS "mode limiter is '" CHAR "'\n";
char const F_MO_MAP1[]=     "%s  " F_POS "mouse-bindings\n";
char const F_MO_CHAR[]=     "mousebutton " SM_INT " invokes " MACRO_NUM "=" CHAR "\n";
char const F_MO_CTRL[]=     "mousebutton " SM_INT " invokes " MACRO_NUM "=" CTRL_CHAR "\n";
char const F_MO_DEL[]=      "mousebutton " SM_INT " invokes " MACRO_NUM "=DEL\n";
char const F_MO_OP[]=       "mousebutton " SM_INT " invokes " MACRO_NUM "=" COMMAND "\n";
char const F_MSG[]=         "<message " SM_INT "=%s>";
char const F_M_V1[]=        "%s  " F_POS "mouse-variables\n";
char const F_M_V2[]=        "mouse-variables:\n"
                            OCL_INT " <-> "MOUSE_X "\n"
                            OCL_INT " <-> "MOUSE_Y "\n"
                            OCL_INT " <-> "MOUSE_G "\n"
                            OCL_INT " <-> "MOUSE_O "\n"
                            OCL_INT " <-> "MOUSE_B "\n"
                            OCL_INT " <-> "MOUSE_W "\n";
char const F_NAME[]=        DUMMY_FOLD F_POS "name of this keybind is %s.\n";
char const F_NODE_VALUE[]=  SM_INT ": key " KEY_VAL "=" KEY_CODE " | ne " SM_INT " | nl " SM_INT;
char const F_NO_RC[]=       "no rc-file %s.\n";
char const F_NORM[]=        ADRESS " -><" OCL_INT ">";
char const F_NORM_PC[]=     ADRESS " ->" CHAR;
char const F_OCL_OPTS[]=    "%s  " F_POS OCL_INT " ocl-options\n%s%s\n";
char const F_OP[]=          ADRESS " " COMMAND "\n";
char const F_OP_1_INT[]=    ADRESS " " COMMAND " " INT_ARG "\n";
char const F_OP_2_INT[]=    ADRESS " " COMMAND " " INT_ARG "  " INT_ARG "\n";
char const F_OP_ADRESS[]=   ADRESS " " COMMAND " " ADR_ARG "\n";
char const F_OP_CHAR[]=     ADRESS " " COMMAND " " CHAR_ARG "\n";
char const F_OP_CODE[]=     ADRESS " " COMMAND " " CTRL_CHAR_ARG "\n";
char const F_OP_IIP[]=      ADRESS " " COMMAND " " INT_ARG " " INT_ARG "\n         <";
char const F_PROMPT_START[]=ADRESS " " COMMAND " " INT_ARG "\n         <";
char const F_OS_EXT[]=      DUMMY_FOLD F_POS "os-specific text <";
char const F_PI_MACRO[]=    DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as begin-prompt-macro.\n";
char const F_PO_MACRO[]=    DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as end-prompt-macro.\n";
char const F_S1_VAR[]=      "%s  " F_POS "standard-variables\n";
char const F_S2_VAR[]=      OCL_INT " <-> "SCR_W "\n"
                            OCL_INT " <-> "SCR_W_O "\n"
                            OCL_INT " <-> "SCR_H "\n"
                            OCL_INT " <-> "SCR_H_O "\n"
                            OCL_INT " <-> "CURSOR_LEVEL "\n"
                            OCL_INT " <-> "OCL_ARG_V "\n"
                            OCL_INT " <-> "F_N_VAR "\n"
                            OCL_INT " <-> "U_B_VAR "\n"
                            OCL_INT " <-> "C_B_VAR "\n"
                            OCL_INT " <-> "C_BI_VAR "\n"
                            OCL_INT " <-> "M_B_VAR "\n"
                            OCL_INT " <-> "M_O_VAR "\n"
                            OCL_INT " <-> "K_C_VAR "\n"
                            OCL_INT " <-> "VAR_PATH_SEP "\n"
                            OCL_INT " <-> "DIRED_VAR "\n";
char const F_SET_HEAD[]=    "%s  " F_POS "using " SM_INT " character classes\n";
char const F_SET_NO[]=      "character class " SM_INT ":";
char const F_SHIFT_MARK[]=  DUMMY_FOLD F_POS "shift mark is '" CHAR "'\n";
char const F_STAT[]=        DUMMY_FOLD F_POS "no statusline\n";
char const F_STR[]=         "%s  " F_POS OCL_INT " strings ("OCL_INT " chars)\n";
char const F_T1_ALIAS[]=    " %s";
char const F_T2_ALIAS[]=    " ) replaced by %s.\n";
char const F_T_ALIAS[]=     DUMMY_FOLD F_POS "terminals (";
char const F_U_MODE[]=      DUMMY_FOLD F_POS "usermode " SM_INT ", long: %s, short: %s.\n";
char const F_V_MACRO[]=     DUMMY_FOLD F_POS "keybind uses macro " MACRO_NUM " as view-macro.\n";
char const M_BAD_DATA[]=    "incorrect data in rc!\n";
char const M_CODE_NODE[]=   CMD_ARROW"co " MACRO_NUM "=" CHAR "\n";
char const M_COM_NODE[]=    CMD_ARROW"co " MACRO_NUM "=" COMMAND "\n";
char const M_CTRL_NODE[]=   CMD_ARROW"co " MACRO_NUM "=" CTRL_CHAR "\n";
char const M_DEL_NODE[]=    CMD_ARROW"co " MACRO_NUM "=DEL\n";
char const M_END_ST[]=      "<-\n";
char const M_FAR_NEXT[]=    CMD_ARROW"far next\n";
char const M_NEWLINE[]=     "\n";
char const F_SET_NAMES[]=   "classnames (" F_POS "):";
char const M_UNKNOWN[]=     "unknown";
char const M_USAGE[]=       "viewrc [-fhikmr?] [filename ... ]\nversion: " MAJOR_VERSION "." MINOR_VERSION "." REVISION "\n";
/*}}}  */
/*{{{  show_help*/
void show_help(void)
{
  printf("%s  description of fileformat (version: " MAJOR_VERSION "." MINOR_VERSION "." REVISION " )\n"
         "\n",fo);
  /*{{{  contents of info-fold*/
  puts  ("used output formats are(" X_HELP " is the hex offset in the rc file):\n");
  /*{{{  check*/
  puts  ("  " DUMMY_FOLD F_OH "format-code <number>, " MAJOR_VERSION "." MINOR_VERSION "." REVISION " uses <number>.\n"
         "    Show the rc error-check word.\n");
  /*}}}  */
  /*{{{  constants*/
  printf("  %s  " F_OH "constants\n",fo);
  /*{{{  number of macs*/
  puts  ("  " DUMMY_FOLD F_OH "keybind needs <number> fix-macros.\n"
         "    Origami has initialised <number> macros.\n");
  /*}}}  */
  /*{{{  vars*/
  puts  ("  " DUMMY_FOLD F_OH "keybind needs <number> variables.\n");
  /*}}}  */
  /*{{{  standard vars*/
  printf("  %s  " F_OH "standard-variables\n"
         "  <number> <-> <name>\n"
         "    :\n"
         "  %s\n"
         "    the numbers specify the position in the OCL-variable-list.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  mouse vars*/
  printf("  %s  " F_OH "mouse-variables\n"
         "  <number> <-> <name>\n"
         "    :\n"
         "  %s\n"
         "    the numbers specify the position in the OCL-variable-list.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  abort*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses <decimal key>=<ascii-code> as general-abort-key.\n");
  /*}}}  */
  /*{{{  limiters*/
  puts  ("  " DUMMY_FOLD F_OH "line limiter is '<char>'\n"
         "    The character replaces the '$' as marker for long lines.\n"
         "\n"
         "  " DUMMY_FOLD F_OH "mode limiter is '<char>'\n"
         "    The character replaces the ',' between modes in the statusline.\n");
  /*}}}  */
  /*{{{  no statusline*/
  puts  ("  " DUMMY_FOLD F_OH "no statusline\n"
         "    Origami doesn't display the statusline\n");
  /*}}}  */
  /*{{{  list of edited files*/
  puts  ("  " DUMMY_FOLD F_OH "start with list of edited files\n"
         "    Origami starts editing the list of edited files\n");
  /*}}}  */
  /*{{{  automacro*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as read-newfile-macro.\n");
  /*}}}  */
  /*{{{  abortmacro*/
  puts  ("  " DUMMY_FOLD F_OH " keybind uses macro <number> as abort-macro.\n");
  /*}}}  */
  /*{{{  promptin*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as begin-prompt-macro.\n");
  /*}}}  */
  /*{{{  promptout*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as end-prompt-macro.\n");
  /*}}}  */
  /*{{{  not-bound*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as key-not-bound-macro.\n");
  /*}}}  */
  /*{{{  view-mac*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as view-macro.\n");
  /*}}}  */
  /*{{{  chg_b_macro*/
  puts  ("  " DUMMY_FOLD F_OH "keybind uses macro <number> as change-buffer-macro.\n");
  /*}}}  */
  /*{{{  name*/
  puts  ("  " DUMMY_FOLD F_OH "name of this keybind is <name>\n"
         "    <name> replaces origami in the commandline\n");
  /*}}}  */
  printf("  %s\n\n",fc);
  /*}}}  */
  /*{{{  strings*/
  printf("  %s  " F_OH "<number> strings\n"
         "  contains all rc messages for this file\n"
         "  %s\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  mark*/
  puts  ("  " DUMMY_FOLD F_OH "keybind has additional mark-typ <name> : '<c1><c2><c3>' ..\n"
         "    <name> can be used with ``-m<name>''  to use <c1><c2><c3> .. for the\n"
         "    folds.\n");
  /*}}}  */
  /*{{{  usermode*/
  puts  ("  " DUMMY_FOLD F_OH "usermode <modenummer>, long: <longstring>, short: <shortname>.\n"
         "    Internal mode <number> uses <longstring> and  <shortstring>  in  the\n"
         "    statusline.\n");
  /*}}}  */
  /*{{{  rc-comment*/
  puts  ("  ccc  " X_HELP ": <<text>>\n"
         "    This will be ignored by Origami.\n");
  /*}}}  */
  /*{{{  os-extension*/
  puts  ("  " DUMMY_FOLD F_OH "os-specific text (<text>)\n"
         "    This will be ignored by standard Origamis. Only some speciell ports\n"
         "    this text.  See the port-manuals for more information.\n");
  /*}}}  */
  /*{{{  macro*/
  printf("  %s  " F_OH "macro  <number> (lg=  <used tokens>) <defmode>)\n"
         "  this is only an example!\n"
         "  %s\n"
         "    The fold contains the disassembled code  for  fixed-macro  <number>.\n"
         "    The macro uses <used tokens>.  If  <defmode> is ``def'', you are not\n"
         "    allowed to redefine it with ``O_DEFINE_FIX''.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  character-sets*/
  printf("  %s  " F_OH "using <number> character classes\n"
         "  this is only an example!\n"
         "  %s\n"
         "    This fold contains all userdefined character classes,  which can  be\n"
         "    used  in  tests.  Each  class  is  listed  in  a  block.  Characters\n"
         "    lower-equal   \"  \"  are marked with \"X\". All  Other  characters  are\n"
         "    marked by themself.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  mouse bindings*/
  printf("  %s  " F_OH "mouse-bindings\n"
         "  mousebutton <number> invokes <command>\n     :\n"
         "  %s\n"
         "    display bindings of the mouse-buttons to commands.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  termalias*/
  puts  ("  " DUMMY_FOLD F_OH "terminals (<termname> .. ) replaced by <termname>.\n"
         "    $"TERM"/$"ORITERM" set to one of the first  names will use the  keytable\n"
         "    defined for the last given name.\n");
  /*}}}  */
  /*{{{  keyboard*/
  printf("  %s  " F_OH "keyboard\t<term-name>\tmarks <number>+ nodes <number>\n"
         "  this is only an example!\n"
         "    The terminal name is used to  decide, whether  this table should be\n"
         "    active. The bindmarks are the codes, specifying,  which part of the\n"
         "    binding-list is valid. The  fold  contains the complete information\n"
         "    to decode keyboardinputs. It shows the internal datatree of origami\n"
         "    in the following way (the first next-chain represents the modes):\n"
         "      Each line shows the contents of treenode:\n"
         "        <no>: key <decimal>=<ascii> | ne <next> | nl <level>\n"
         "      with\n"
         "        <no>    number of the node\n"
         "        <decimal> and <ascii>\n"
         "                are the pressed key\n"
         "        <next>  number of the next node for the current inputposition\n"
         "                (there are other keysequences with the same beginning)\n"
         "        <level> number of next node for the next inputposition\n"
         "      optional is the trailing output:\n"
         "        => co <number> = ( <tokenname> )\n"
         "      its used, if the current input matches an origamicommand  <number>\n"
         "      or <tokenname>.\n"
         "    The node 0 is the toplevel node of the tree. Nodenumber  -1  is  the\n"
         "    nil-pointer.\n"
         "  %s"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  help*/
  printf("  %s  " F_OH "helpfile\n"
         "  this is only an example!\n"
         "  %s\n"
         "    This fold contains the  complete  online-bindinghelp  for  all  used\n"
         "    keyboardmodes,  the mouse and maybe the  referenz-card.  Every  text\n"
         "    line will be shown with offset and tag.\n"
         "\n",fo,fc);
  /*}}}  */
  /*{{{  macsize*/
  puts  ("  binding uses <number> tokens\n"
         "    number of used tokens in all macros.\n");
  /*}}}  */
  /*}}}  */
  printf("%s\n",fc);
}
/*}}}  */
