/* os specific stuff which will be included in every module */
/*{{{  MS/PC DOS*/
#ifdef DOS
#  define chartest if (ch<' ' || ch=='\n') ch=O_NOP;
#  include "../dos/dos_os.h"
#endif
/*}}}  */
/*{{{  ATARI TOS*/
#ifdef TOS
#  include "../tos/tos_os.h"
#endif
/*}}}  */
/*{{{  AMIGA OS*/
#ifdef AMIGA
#  include <origami:amiga/h/amiga.h>
#endif
/*}}}  */
/*{{{  operating systems*/
#if (!(defined(TOS)||defined(DOS)||defined(AMIGA)))
#  define DEFAULT_NAME "Origami"
  /*{{{  stdio-stuff*/
#  define READ "r"
#  define READ_BIN "r"
#  define WRITE "w"
#  define WRITE_BIN "w"

#  define PATH_SEP "/"
#  define PATH_C '/'
#  define CURR_DIR "."

#  define OS_NULL_DEVICE "/dev/null"

#  define pline(x) fputs((char*)x,scrout)
#  define oputs(x) fputs((char*)x,scrout)
#  define oputc(x) fputc((char)x,scrout)
#  define eputs(x) fputs((char*)x,stderr)
#  define eputc(x) fputc((char)x,stderr)
#  define oflush fflush(scrout)

  /* where should these functions be defined? */
  extern FILE *popen(const char *, const char *);
  extern int pclose(FILE*);
  /*}}}  */
  /*{{{  mouse and windowing*/
#  ifdef MICE          /* keybind must know all mice, to be able to generate */
#     define XTERM     /* all available rc-files.                            */
#     define MGR
#  endif
  /*{{{  xterm-support*/
#  ifdef XTERM
#     ifndef MOUSY
#        define MOUSY
#     endif
#     define XTERM_MOUSE_NAME "xterm"
#     define XTERM_MOUSE_COUNT 10
#     define XTERM_MOUSE_NAMES                                                \
        {"Button1","Button2","Button3","Button4","Button5",                   \
         "Button6","Button7","Button8","Button9","Button10"}
     /* use the MIT-mouse row/column and button information, send when button
      * pressed! Switching the mouse to 'send-position' ''is done, if the
      * environment-variable TERM is set to 'xterm'.
      */
#     ifndef XTERM_MOUSE_LG
#        define XTERM_MOUSE_LG       3
#     endif
#     ifndef XTERM_MOUSE_CODE
#        define XTERM_MOUSE_CODE  "\033[M"
#     endif
#     ifndef DEFAULT_MOUSE
#        define DEFAULT_MOUSE XTERM_MOUSE_NAME
#     endif
     /*{{{  strings to de-/activate the send-mouse-position-mode*/
#     ifndef XTERM_START_BP                 /* send mouse-position on click */
#        define XTERM_START_BP "\033[?9h"
#     endif
#     ifndef XTERM_END_BP                   /* do action on mouse-click     */
#        define XTERM_END_BP   "\033[?9l"
#     endif
     /*}}}  */
     /*{{{  strings to get window size*/
#     define XTERM_GET_SIZE "\0337\033[r\033[999;999H\033[6n\0338"
#     define XTERM_SIZE_HEAD "\033["
#     define XTERM_SIZE_MID ";"
#     define XTERM_SIZE_END "R"
     /*}}}  */
     /*{{{  xterm change title*/
#     ifndef XTERM_CHGNAME
#        define XTERM_CHGNAME(s) \
           fputc(0x1b,stdout);fputs("]0;",stdout);fputs(s,stdout);fputc(0x7,stdout)
#     endif
#     ifndef XTERM_DEFAULT_TITLE
#        define XTERM_DEFAULT_TITLE "xterm"
#     endif
#     ifndef WINDOW_TITLE_CHANGE
#        define WINDOW_TITLE_CHANGE
#     endif
     /*}}}  */
#  endif
  /*}}}  */
  /*{{{  mgr-support*/
#  ifdef MGR
#     ifndef MOUSY
#        define MOUSY
#     endif
#     define MGR_MOUSE_NAME "mgr"
#     define MGR_MOUSE_COUNT 10
#     define MGR_MOUSE_NAMES                                                   \
        {"Button1","Button2","Button3","Button4","Button5",                    \
         "Button1Down","Button2Down","Button3Down","Button4Down","Button5Down"}
#     ifndef XTERM
#        define MGR_MOUSE_LG 3
#        define MGR_MOUSE_CODE "\033[M"
#     else
#        define MGR_MOUSE_LG XTERM_MOUSE_LG
#        define MGR_MOUSE_CODE XTERM_MOUSE_CODE
#     endif
#     ifndef DEFAULT_MOUSE
#        define DEFAULT_MOUSE MGR_MOUSE_NAME
#     endif
#  endif
  /*}}}  */
  /*{{{  OS-MOUSE-Hooks*/
#  if 0
     /* maybe add some definitions in the following style */
#     define OS_MOUSE_TAG    dummy     /* entry in the mouse-typ enum  */
#     define OS_MOUSE_NAME   "dummy"   /* name for the mouse-support,  *
                                        * for -M.. usage in keybind    */
#     define OS_MOUSE_COUNT  2         /* number of mouse-buttons,     *
                                        * needed for the bindinglist   */
#     define OS_MOUSE_NAMES  { "left","right" }
                                       /* names of the buttons, needed *
                                        * for the bindinglist          */
#     define OS_MOUSE_CODE   "\033\0"  /* if your mouse sends a char-  *
#     define OS_MOUSE_LG     2          * sequence to stdin, define    *
                                        * here this header and its     *
                                        * length.                      */
     /* in origami/keyboard.c you have to add the code for activating  *
      * and scanning the mouse. Look at the mgr- and xterm-support, if *
      * you need a example.                                            */
#  endif
  /*}}}  */
  /*{{{  DEFAULT_MOUSE*/
#  ifndef DEFAULT_MOUSE
#     define DEFAULT_MOUSE ""
#  endif
  /*}}}  */
  /*}}}  */
  /*{{{  FOLDFILING_C*/
#  ifdef FOLDFILING_C
#     define ORICORE_NAME "oricoreXXXXXX"
#  endif
  /*}}}  */
  /*{{{  VIRLINES_C*/
#  ifdef VIRTUAL_C
#    ifdef VIRTUAL
#      define BLOCK_SIZE         90
                                 /* mininum is 4*sizeof(int)                */
                                 /* maximum is MAX_FIELD_SIZE+sizeof(int)   */
#      define ORI_TMP            "/usr/tmp/.oritmpXXXXXX"
#      define FIXED              8
                                 /* number of secure lines in memory        */
                                 /* the minum is 8 (number of lines needed  */
                                 /* for internal expressions). You can use  */
                                 /* greater values (screensize for example) */
#    endif
#  endif
  /*}}}  */
  /*{{{  ORIEDT*/
#  ifdef ORIEDT_C
#    define BASIC_ELEMENTS    256   /* number of first element's block */
#    define NEW_ELEMENT_LIMIT  16   /* minimum number of malloced      */
                                    /* element's block.                */
                                    /* if malloc cannot return a block */
                                    /* of NEW_ELEMENT_LIMIT elements,  */
                                    /* a `not enough memory' warning   */
                                    /* appears!                        */
#    define NEW_ELEMENT_MAX    64   /* maximum number of malloced      */
                                    /* element's block (used if lines  */
                                    /* are handled virtuell)           */
#  endif
  /*}}}  */
  /*{{{  scan_abort_key*/
#  define scan_abort_key()
  /*}}}  */
  /*{{{  MAIN_C*/
#  ifdef MAIN_C
#    define os_init() scrout=stdout
#    define os_init_args_read()
#    define os_init_rc_read()
#  endif
  /*}}}  */
  /*{{{  KEYBIND_C*/
#  ifdef KEYBIND_C
#    define homecheck(x)
    /*{{{  tmp-filename for collecting the bindinglist and refs*/
#    define BND_TMP_FILE "/tmp/kbindXXXXXX"
#    define REF_TMP_FILE "/tmp/kbrefXXXXXX"
    /*}}}  */
    /*{{{  write binding to .origamibind*/
#    define bnd_wr(kbd,name,code) \
      fprintf(bnd,kbd==mouse_kbd?"%d|%-35.*sMouse: %c\n":"%d|%-35.*s%s\n", \
                  kbd,strlen(name),name,code)
    /*}}}  */
    /*{{{  SORTCMD*/
#    define SORTCMD "sort -t\\| +1 -o %s"
    /*}}}  */
#  endif
  /*}}}  */
  /*{{{  GETTK_C*/
#  ifdef GETTK_C
#    define chartest if (ch=='\0' || ch=='\n' || (!hard_tab && ch=='\t')) ch=O_NOP;
#  endif
  /*}}}  */
  /*{{{  READFOLDS_C*/
#  ifdef READFOLDS_C
#     define PIPE_FILENAME OS_NULL_DEVICE
#  endif
  /*}}}  */
  /*{{{  SIGNALS_C*/
#  ifdef SIGNALS_C
     /*{{{  maybe set mailcommand*/
#     ifndef MAILCMD
#        ifndef MAIL_NO_S
           /*{{{  mail -s "subject" user*/
#           define MAILCMD(c,subject,user) \
              ( strcpy(c,"mail -s '"), \
                strcat(c,subject),strcat(c,"' "), \
                strcat(c,user),c)
           /*}}}  */
#        else
           /*{{{  mail user*/
#           define MAILCMD(c,s,u) (strcpy(c,"mail "),strcat(c,u),c)
           /*}}}  */
#        endif
#     endif
     /*}}}  */
#  endif
  /*}}}  */
  /*{{{  SCANNER_C*/
#  ifdef SCANNER_C
#     define OS_USINGS
#  endif
  /*}}}  */
  /*{{{  formats for rc/help-filenames*/
#  define STD_BASENAME ".origami"
#  define BASENAMEF ".%s"
  /*}}}  */
  /*{{{  add missing prototypes for os*/
#  ifdef STRRSTR_MIS
    char *strrstr(char*,char*);
#  endif
#  ifdef STRERROR_MIS
    char *strerror(int errno);
#  endif
#  ifdef USLEEP_MIS
    int usleep(unsigned long);
#  endif
  /*}}}  */
  /*{{{  dir_edit*/
#  ifdef DIREDT
#     ifndef DIR_CMD
#        define DIR_CMD(s,n)              \
          strcpy(s,"dirfold -s -M \""),   \
          strcat(s,(char*)fold_open_str), \
          strcat(s,(char*)fold_file_str), \
          strcat(s,(char*)fold_line_str), \
          strcat(s,(char*)fold_close_str),\
          strcat(s,"\" "),                \
          strcat(s,(char*)n)
#     endif
#  endif
  /*}}}  */
#endif
/*}}}  */
