/* os specific stuff which will be included in every module */
/*{{{  typedef SHORT*/
#ifdef _MINIX
typedef unsigned char SHORT;
#else
typedef unsigned int SHORT;
#endif
/*}}}  */

/*{{{  bd - cpp stuff (handling ifdef a || ifdef b)*/
#undef DUMMY_SYM
#ifdef KEYBIND_C
#  define DUMMY_SYM
#endif
#ifdef VIEW_C
#  define DUMMY_SYM
#endif
/*}}}  */
#ifdef TOS
  /*{{{  tos-defines*/
  /*{{{  MISC*/
#    ifdef MISC_C
#      include <ext.h>
#    endif
  /*}}}  */
  /*{{{  not ST_UTIL_C*/
#    ifndef ST_UTIL_C
#      ifndef VIEW_C
#        define signal(a,b)
#        define system(a) newsystem(a)
#        define exit(a) newexit(a)
#        define fopen(a,b) newfopen(a,b)
#      endif
#    endif
  /*}}}  */
  /*{{{  scan_abort_key()*/
#    define scan_abort_key()
  /*}}}  */
  /*{{{  MAIN_C*/
#    ifdef MAIN_C
#      define os_init() st_init(&argc,&argv)
#    endif
  /*}}}  */
  /*{{{  KEYBIND*/
#    ifdef KEYBIND_C
    /*{{{  write binding to .bin*/
#        define bnd_wr(kbd,name,code)                     \
      if(strstr(code,"mmeta")==NULL)                  \
        fprintf(bnd,"%d | %-35s %s\n",kbd,name,code)
    /*}}}  */
#    endif
  /*}}}  */
  /*{{{  SCANNER*/
#    ifdef SCANNER
    /*{{{  additional alias*/
#        define os_default_alias()       \
      creat_alias("meta","\xFF",1);  \
      creat_alias("smeta","\xFE",1); \
      creat_alias("cmeta","\xFD",1); \
      creat_alias("ameta","\xFC",1); \
      creat_alias("mmeta","\xFB",1)
    /*}}}  */
    /*{{{  no termcap-data needed*/
#        define os_termcap_data
    /*}}}  */
    /*{{{  generate the termcap-alias explicitly*/
#        define os_termcap_alias()                                   \
      creat_alias("backspace","\x08",1);  /* backspace */        \
      creat_alias("rubout","\xFF\x07",2); /* delete */           \
      creat_alias("home","\xFF\x01",2);   /* ClrHome */          \
      creat_alias("left","\xFF\x03",2);   /* arrow left */       \
      creat_alias("right","\xFF\x04",2);  /* arrow right */      \
      creat_alias("up","\xFF\x02",2);     /* arrow up */         \
      creat_alias("down","\xFF\x05",2);   /* arrow down */       \
      creat_alias("next_page","\xFDo",2); /* Ctrl-arrow down */  \
      creat_alias("prev_page","\xFDl",2); /* Ctrl-arrow up */    \
      creat_alias("f1","\xFF\x0a",2);     /* F1 */               \
      creat_alias("f2","\xFF\x0b",2);     /* F2 */               \
      creat_alias("f3","\xFF\x0c",2);     /* F3 */               \
      creat_alias("f4","\xFF\x0e",2);     /* F4 */               \
      creat_alias("f5","\xFF\x0f",2);     /* F5 */               \
      creat_alias("f6","\xFF\x10",2);     /* F6 */               \
      creat_alias("f7","\xFF\x11",2);     /* F7 */               \
      creat_alias("f8","\xFF\x12",2);     /* F8 */               \
      creat_alias("f9","\xFF\x13",2);     /* F9 */               \
      creat_alias("f10","\xFF\x14",2);    /* F10 */
    /*}}}  */
#    endif
  /*}}}  */
  /*{{{  KEYBIND || VIEW*/
#    ifdef DUMMY_SYM
#      define homecheck(x) if (x==NULL) x="."
#      define STD_BASENAME "origami."
    int getw(FILE *s);
#    endif
  /*}}}  */
  /*{{{  not VIEW*/
#    ifndef VIEW_C
#      define F_OK 1
#      define R_OK 2
#      define W_OK 4
  
    /*{{{  declarations of functions*/
    int access(char *file, int flag);
    void putenv(char *string);
    void st_redraw(void);
    void pre_shell(void);
    void post_shell(void);
    void set_path(char *filename);
    void st_init(int *argc, char **argv[]);
    void st_exit(void);
    void fileselect(char *str);
    void vputchar(char c);
    void newsystem(char *command);
    FILE *newfopen(const char *filename, const char *mode);
    void newexit (int status);
    void alarm(unsigned long seconds);
    void putw(int w, FILE *s);
    int getw(FILE *s);
    void abort_scanner(void);
    char *mktemp(char *pattern);
    FILE *popen(char *command, char *mode);
    int pclose (FILE *stream);
    unsigned int get_raw_key(void);
    /*}}}  */
  
#      undef putchar
#      define putchar(c) vputchar(c)
#      define strlen(a) ((int) strlen(a)) /* this seems to work in TurboC */
#      define sleep(a)
#      define _POSIX_PATH_MAX 120
#    endif
  /*}}}  */
  
  /*{{{  stdio-stuff*/
#    define BASENAMEF "%s."
#    define READ "r"
#    define READ_BIN "rb"
#    define WRITE "w+"
#    define WRITE_BIN "w+b"
#    define PATH_SEP "\\"
#    define PATH_C '\\'
  /*}}}  */
  /*}}}  */
#else
  /*{{{  SUNOS/MINIX-defines*/
  /*{{{  scan_abort_key*/
#    define scan_abort_key()
  /*}}}  */
  /*{{{  MAIN_C*/
#    ifdef MAIN_C
#      define os_init()
#    endif
  /*}}}  */
  /*{{{  KEYBIND_C*/
#    ifdef KEYBIND_C
    /*{{{  write binding to .origamibind*/
#        define bnd_wr(kbd,name,code) \
      fprintf(bnd,"%d | %-35.*s%s\n",kbd,strlen(name),name,code)
    /*}}}  */
#    endif
  /*}}}  */
  /*{{{  SCANNER*/
#    ifdef SCANNER
#      define os_default_alias()
    /*{{{  termcap-data-structs*/
#        define os_termcap_data              \
      private char termcap_area[1024];   \
      typedef struct                     \
      {                                  \
        char *capability, *alias;        \
      } term_alias;                      \
      term_alias alias_table[] =         \
      {                                  \
        { "kb", "backspace" },           \
        { "kB", "backtab" },             \
        { "kd", "down" },                \
        { "kD", "rubout" },              \
        { "kE", "clreol" },              \
        { "kh", "home" },                \
        { "kl", "left" },                \
        { "kL", "delline" },             \
        { "kN", "next_page" },           \
        { "kP", "prev_page" },           \
        { "kr", "right" },               \
        { "ku", "up" },                  \
        { "k0", "f0" },                  \
        { "k1", "f1" },                  \
        { "k2", "f2" },                  \
        { "k3", "f3" },                  \
        { "k4", "f4" },                  \
        { "k5", "f5" },                  \
        { "k6", "f6" },                  \
        { "k7", "f7" },                  \
        { "k8", "f8" },                  \
        { "k9", "f9" },                  \
        { "k;", "f10" },                 \
        { NULL, 0 }                      \
      };
    /*}}}  */
    /*{{{  generate termcap-alias using termcap-data*/
#        define os_termcap_alias()                                              \
      char bp[1024];                                                        \
      char *terminal, *pointer, *cap;                                       \
      term_alias *run=alias_table;                                          \
                                                                            \
      if ((terminal=getenv("TERM"))==NULL) return; /* terminal typ       */ \
      if (tgetent(bp,terminal)<=0) return;         /* termcap entries    */ \
      pointer = termcap_area;                      /* handle all entries */ \
      while ((run->capability)!=NULL) {                                     \
        if ((cap=tgetstr(run->capability,&pointer))!=NULL)                  \
        creat_alias(run->alias,cap,strlen(cap));                            \
        run++;                                                              \
      }
    /*}}}  */
#    endif
  /*}}}  */
  /*{{{  KEYBIND_C || VIEW_C*/
#    ifdef DUMMY_SYM
#      define homecheck(x)
#      define STD_BASENAME ".origami"
#    endif
  /*}}}  */
  /*{{{  stdio-stuff*/
#    define BASENAMEF ".%s"
#    define READ "r"
#    define READ_BIN "r"
#    define WRITE "w"
#    define WRITE_BIN "w"
#    define PATH_SEP "/"
#    define PATH_C '/'
  /*}}}  */
  /*}}}  */
#endif
#undef DUMMY_SYM
