?? snarkdos.c
字號:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snarkdos.c,v 1.3 2003/01/15 14:04:35 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1993-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: snarkdos.c,v $ * Revision 1.3 2003/01/15 14:04:35 josh * directory structure shifting * * Revision 1.2 2001/11/08 15:56:26 tneale * Updated for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:43 tneale * Tornado shuffle * * Revision 2.18 2001/01/19 22:23:52 paul * Update copyright. * * Revision 2.17 2000/03/17 00:12:45 meister * Update copyright message * * Revision 2.16 1998/09/04 04:00:08 sar * modified some #if statements to use #ifdef as they were testing * items that might not be defined - INSTALL_on_* options. * * Revision 2.15 1998/07/17 18:58:43 sra * Swap and checksum routines moved to separate files. * * Revision 2.14 1998/07/02 06:55:39 sra * Make Snark restartable under pSOS, and other minor cleanups. * * Revision 2.13 1998/02/25 15:21:51 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 2.12 1998/02/25 04:57:39 sra * Update copyrights. * * Revision 2.11 1997/10/29 22:23:20 sar * moved the call to envoy_init() from snmp_init() in snmpfunc.c to * snark_init() in snarkbsd.c & snarkdos.c * * Revision 2.10 1997/03/20 06:53:11 sra * DFARS-safe copyright text. Zap! * * Revision 2.9 1997/03/19 22:05:52 sra * Perhaps we should include install.h before testing install options? * * Revision 2.8 1997/03/19 04:47:35 sra * Get rid of some gratuitous historical dependencies on Attache. * * Revision 2.7 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 2.6 1997/02/24 00:56:59 sra * Support for run-time configuration of BUG() macros. * * Revision 2.5 1997/02/19 08:10:29 sra * More fun merging snmptalk into snark, general snark cleanup. * * Revision 2.4 1997/01/08 01:20:46 sar * Moved the glue_pkt_handle routine from snark*.c to loopglue.c * and added loopglue.c to the base object list. * * Revision 2.3 1996/10/31 01:16:15 sra * Why are we getting warnings from magic DOS incantations that have been * stable for years? * * Revision 2.2 1996/10/26 17:30:30 sra * BCC 4.0 sure is fussy about parameter lists. * * Revision 2.1 1996/03/22 10:05:39 sra * Update copyrights prior to Attache 3.2 release. * * Revision 2.0 1995/05/10 22:38:15 sra * Attache release 3.0. * * Revision 1.11 1995/01/06 00:52:48 sra * Update copyright notice for 2.1 release. * * Revision 1.10 1994/12/20 23:10:56 sra * Twiddle type signature of a pointer to function to make MSC 7.0 happy. * Fix sense of interrupt flag test. * * Revision 1.9 1994/09/04 06:13:38 sra * Clean up antique type names and install macros. * * Revision 1.8 1993/08/03 01:29:13 sra * Add a cast to glue_cksum() for MSC 7.0. * * Revision 1.7 1993/08/01 23:57:40 sra * Add in Dave's changes to make this work with Microsoft C. * * Revision 1.6 1993/08/01 21:31:01 sra * Fiddle byte-swap routines a little. Fix DOS keyboard/screen I/O to * work aproximately as we'd like: it's still not perfect, but it's now * close enough to be useful as a telnet client. * * Revision 1.5 1993/08/01 07:11:38 sra * Minor cleanup. DOS keyboard/screen interface not quite right yet, but * this is just demo code, I never claimed to be a DOS programmer.... * * Revision 1.4 1993/07/31 23:26:33 sra * Add keyboard_write(). * * Revision 1.3 1993/07/30 23:44:56 sra * Cosmetic changes to make Borland C++ 3.1 happy. * * Revision 1.2 1993/07/30 22:26:03 sra * Initial working version. * * Revision 1.1 1993/07/30 02:41:24 sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//* * Implementation of snark for MS-DOS with FTP Software spec packet drivers. * You should probably have ANSI.SYS (or replacement) loaded too. */#include <wrn/wm/common/install.h>#include <wrn/wm/common/types.h>#if INSTALL_ATTACHE#include <wrn/wm/attache/config.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/glue.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/ip.h>#include <wrn/wm/attache/loop.h>#endif#if INSTALL_ENVOY#include <wrn/wm/snmp/engine/snmpdefs.h>#endif#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <dos.h>#include <conio.h>#include <wrn/wm/demo/snarklib.h>#if INSTALL_ATTACHE#include <wrn/wm/demo/netconf.h>#include <wrn/wm/demo/pktdrive.h>#endif/* * These are defined here rather than in snark/lib/main.c so that this * code can be used without that module if the customer so desires. */int snark_exit_flag, snark_exit_value;/* * These suppress spurious warnings from Borland C++ 3.1. */static void clock_init(void), clock_shutdown(void);static unsigned char kbd_getch(void);static int kbd_kbhit(void);/* * Some macros to make MSC-style code work with BCC. */#ifdef INSTALL_on_bcc#define _asm asm#define _interrupt interrupt#endif/* * Timer interrupt routines. This is all PC-hardware specific. */#define CLOCK_INT 0x1c#define CLOCK_MS_PER_TICK 54#ifdef INSTALL_on_bcctypedef void interrupt (*old_clock_int_t)(void);#endif#ifdef INSTALL_on_microsofttypedef void (__cdecl __interrupt __far *old_clock_int_t)(void);#endifstatic old_clock_int_t old_clock_int = 0;static bits32_t cticks;/* The clock tick handler */static void _interrupt clock_tick(){ cticks++; old_clock_int();}/* Set up the clock so we start seeing ticks. */static void clock_init(){ if (!old_clock_int) { old_clock_int = (old_clock_int_t) _dos_getvect(CLOCK_INT); _dos_setvect(CLOCK_INT, clock_tick); }}/* Clean up the clock so we can exit. */static void clock_shutdown(){ if (old_clock_int) _dos_setvect(CLOCK_INT, old_clock_int);}/* This routine implements Attache's GLUE_NOW() function. */bits32_t glue_now(){ return cticks * CLOCK_MS_PER_TICK;}/* * Disable interrupts if argument is 0, otherwise enables interrupts. * Returns previous interrupt state. */int glue_intlock(int x){ unsigned int interrupt_flag; /* * interrupt_flag = _FLAGS; */ _asm pushf _asm pop ax _asm mov interrupt_flag, ax if (x) _enable(); else _disable(); return (interrupt_flag & 0x200) != 0;}/* Low-level keyboard handler stuff. */static void (*kbd_handler)(unsigned char *, size_t);void keyboard_handler(void (*handler)(unsigned char *, size_t)){ kbd_handler = handler;}/* * Low-level DOS I/O routines. We don't use library functions * because they don't do what we want for ANSI.SYS escape sequences * and Control-C handling on input. */static unsigned char kbd_getch(){ union REGS i, o; i.h.ah = 0x07; /* Direct console input without echo */ intdos(&i, &o); return o.h.al; /* Return character we got */}static int kbd_kbhit(){ union REGS i, o; i.x.ax = 0x4406; /* IOCTL get input status */ i.x.bx = 0x0000; /* 0 = stdin */ intdos(&i, &o); return (int) o.h.al; /* Return non-zero if device ready */}/* * Send a string to the local screen. */void keyboard_write(unsigned char *text, size_t length){ union REGS i, o; if (!text) return; i.h.ah = 0x06; /* Direct console output */ while (length-- > 0) { switch (*text) { case 0xFF: /* We can't output this character, sorry */ text++; /* (DOS thinks it means do input instead) */ continue; case '\n': /* NL -> CRLF */ i.h.dl = '\r'; /* Write the CR */ intdos(&i, &o); /* (fall through...) */ default: i.h.dl = *text++; intdos(&i, &o); continue; } }}/* * tasks_run() function, using system-independent tasking queue. */static bits32_t glue_callin_when;static void (*glue_callin_who)(void);/* This is the function we use to provide GLUE_CALLIN(). */void glue_callin(bits32_t when, void (*who)(void)){ glue_callin_when = when + glue_now(); glue_callin_who = who;}/* * This is the main body of the task dispatcher. * If it ever returns, main() should exit immediately with the same value. */int tasks_run(){ struct task *task; for (;;) { if (kbd_handler && kbd_kbhit()) { unsigned char c = kbd_getch(); (*kbd_handler)(&c, 1); if (snark_exit_flag) break; } if ((task = task_deq()) != 0 && task->func != 0) { task->func(task, task->cookie); if (snark_exit_flag) break; } if (glue_callin_who && ((sbits32_t) (glue_callin_when - glue_now())) <= 0) { void (*who)(void) = glue_callin_who; glue_callin_who = 0; who(); if (snark_exit_flag) break; } } snark_shutdown(); return snark_exit_value;}#if INSTALL_ATTACHE/* * Network configuration. */void netconfig_find(){ pktd_driver_find(netconfig_if);}#endif /* INSTALL_ATTACHE *//* Initialization and shutdown. */void snark_init(){ clock_init(); tasks_init();#if INSTALL_ATTACHE attache_init();#endif#if INSTALL_ENVOY envoy_init();#endif sty_init();#if INSTALL_ATTACHE netconfig();#endif#if INSTALL_SNARK_BUG_CONF bug_config();#endif}void snark_shutdown(){#if INSTALL_ATTACHE && INSTALL_ATTACHE_SHUTDOWN attache_shutdown();#endif clock_shutdown();}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -