⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsd_access.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lintstatic char sccsid[]  =  "@(#)dsd_access.c	4.2   (ULTRIX)   9/11/90";#endif  lint/***	.title DSD Table Access Functions**	.ident / 1.16 /******	  File:	dsd_access.c** Description:	DSD Table Access Functions**	Author:	Paul Baker**	  Date:	7-Oct-1986******	Copyright 1986, Digital Equipment Corporation******++**	The DSD table access functions interface either directly to the**	application, or indirectly through the DSD services functions.**	The DSD table access functions can not read or manipulate the**	data-segment.****	These functions do not provide simultaneous access to the STD**	and O/S DSD tables.**--*******/#include <stdio.h>#include "dsd_switch.h"		/* Compilation control switches */#include "generic_dsd.h"	/* DSD table structure definitions */#include "std_dsd.h"		/* Standard event Data Structure Definitions */#include "os_dsd.h"		/* O/S event Data Structure Definitions *//**++*=*=*=MODULE FLOW - dsd_access.c*=*=  a - dsd_init(bin_file)                          Reads bin file and creates*=                                                  arrays for each DSD.*=          open(bin_file)*=          while(!EOF)*=              malloc(DSD_array_size)*=              read(DSD_arrays)*=          return(DD$SUCCESS)*=*=  b - get_bin_file_ver()*=          return(bin_file_ver)*=*=  c - get_item_index(item_id)*=          return(std_item_dsd_index)*=*=  d - get_item_size(data_type,length)*=          return(item_size)*=*=  e - fld_align(data_ptr,data_type)*=          return(aligned_data_ptr)*=*=  f - get_std_segment_dsd(*ctx)                   Initializes ctx for 1st*=                                                  item in segment.*=          find_std_segment_dsd(seg_type,seg_subtype)      (* o)*=          fld_align(data_ptr,data_type)                   (* e)*=          get_validity_code(ctx)                          (* aa)*=          return(DD$SUCCESS)*=*=  g - get_next_item_dsd(*ctx)                     Updates ctx for next item.*=          get_item_size(item_type,length)                 (* d)*=          fld_align(data_ptr,data_type)                   (* e)*=          get_validity_code(ctx)                          (* aa)*=          return(DD$SUCCESS)*=*=  h - get_next_field_dsd(*ctx)                    Updates ctx for next reg*=                                                  field.*=          return(DD$SUCCESS)*=*=  i - decode_std_item(*ctx,item_code)             Finds text string to coded*=                                                  item in ctx.*=          dsd_get_label(index)                            (* n)*=          return(string_ptr)*=*=  j - decode_register_field(*ctx,field_code)      Finds text string to coded*=                                                  field in ctx.*=          dsd_get_label(index)                            (* n)*=          return(string_ptr)*=*=  k - get_reg_fld_code(item_id,fld_ix,fld_code)   Finds text string to coded*=                                                  field in param. Used for*=                                                  out of order processing.*=          find_std_item_dsd(item_id)                      (* u)*=          get_reg_dsd(index)                              (* s)*=          get_code_dsd(index)                             (* r)*=          dsd_get_label(index)                            (* n)*=          return(string_ptr)*=   *=  l - get_code_std_item(item_id,code_string)      finds item_code for the*=                                                  given text string within*=                                                  the given item_id.*=          find_std_item_dsd(item_id)                      (* u)*=          tolower(code_string)*=          find_std_code_dsd(item_dsd, index)              (* v)*=          dsd_get_label(index)                            (* n)*=          return(code)*=*=  m - decode_os_item(item_id,item_code)           Finds STD code for item*=                                                  from OS code*=          find_os_item_dsd(item_id)                       (* x)*=          return(STD_code)*=*=  n - dsd_get_label(label_index)                  Finds pointer to the text*=                                                  string.*=          return(string_ptr)*=*=  o - find_std_segment_dsd(seg_type,seg_subtype)  Finds requested segment.*=          return(segment_dsd_ptr)*=*=  p - get_item_offset(seg_ptr,item_id)            Finds item offset in seg*=          return(item_offset)*=*=  q - get_seg_item_dsd(index)                     Finds seg_item_dsd @ index.*=          return(seg_item_dsd_ptr)*=*=  r - get_code_dsd(index)                         Finds std_code_dsd @ index.*=          return(std_codes_dsd_ptr)*=*=  s - get_reg_dsd(index)                          Finds reg_dsd @ index.*=          return(std_regs_dsd_ptr)*=*=  t - get_item_dsd(index)                         Finds item_dsd @ index.*=          return(std_items_dsd_ptr)*=*=  u - find_std_item_dsd(item_id)                  Finds item_dsd for item_id.*=          return(std_items_dsd_ptr)*=*=  v - find_std_code_dsd(item_dsd_ptr,code_index)  Finds code_dsd for*=                                                  item/code.*=          return(std_codes_dsd_ptr)*=*=  w - find_reg_code_dsd(reg_dsd_ptr,code_index)   Finds code_dsd for*=                                                  item/code.*=          return(std_codes_dsd_ptr)*=*=  x - find_os_item_dsd(os_item_id)                Finds os_item_dsd for*=                                                  os_item.*=          return(os_items_dsd_ptr)*=*=  y - find_label_dsd(index)                       Finds dsp_labels @ index.*=          return(dsp_labels_ptr)*=*=  z - set_validity_code(*seg,item_seq,val_code)   Sets valid bits in segment.*=          return()*=*=  aa- get_validity_code(*ctx)                     Gets validity value for*=                                                  current item.*=*=*--*/#define std_segment	1#define os_record	2#define MAX_STRING	256	/* Maximum size of a NAME or LABEL string *//**********************************************************************/long		os_codes_count;long		os_items_count;long		std_codes_count;long		std_regs_count;long		std_items_count;long		std_seg_items_count;long		std_segs_count;long		labels_count;long		strings_area_count;long		bin_file_ver;DD$OS_CODES_DSD_PTR		os_codes;DD$OS_ITEMS_DSD_PTR		os_items;DD$STD_CODES_DSD_PTR		std_codes;DD$STD_REGS_DSD_PTR		std_regs;DD$STD_ITEMS_DSD_PTR		std_items;DD$STD_SEG_ITEMS_DSD_PTR	std_seg_items;DD$STD_SEGS_DSD_PTR		std_segs;DD$DSP_LABELS_PTR		labels;char				*strings_area;/********************************************************************//****************  FUNCTIONS USED IN THIS MODULE ********************/short			get_item_size ();char			*dsd_get_label ();DD$BYTE			*fld_align();DD$STD_SEGS_DSD_PTR	find_std_segment_dsd ();DD$STD_ITEMS_DSD_PTR	find_std_item_dsd ();DD$STD_CODES_DSD_PTR	find_std_code_dsd ();DD$OS_ITEMS_DSD_PTR	find_os_item_dsd ();DD$STD_CODES_DSD_PTR    get_code_dsd ();DD$STD_REGS_DSD_PTR     get_reg_dsd ();char   			*malloc();/**********************  BIN FILE LOADING  *************************** * *	INPUT		bin_file full name * *	OUTPUT		arrays of all data items * *********************************************************************/dsd_init (bin_file)char	*bin_file;{short	ifd;			/* Input file descriptor */short   i;long	count;if ((ifd = open(bin_file, 0)) == -1)    {    printf("\nCan't open input file %s!\n",bin_file);    return(DD$BAD_BIN_FILE);    }while (read(ifd, &i, 2) == 2)		/* read array type	*/    {    if (read(ifd, &count, 4) != 4)	/* read array inexes	*/	return (DD$BAD_BIN_FILE);    switch (i)	{	case DD$BIN_FILE_VER_ID:	  if(read(ifd, &bin_file_ver, 4) != 4)	      return(DD$BAD_BIN_FILE);	break;	case DD$OS_CODES_ID:	  os_codes_count = count;	  count = ((count + 1) * sizeof(DD$OS_CODES_DSD));	  os_codes = (DD$OS_CODES_DSD_PTR) malloc(count);	  if (read(ifd, os_codes, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$OS_ITEMS_ID:	  os_items_count = count;	  count = ((count + 1) * sizeof(DD$OS_ITEMS_DSD));	  os_items = (DD$OS_ITEMS_DSD_PTR) malloc(count);	  if (read(ifd, os_items, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STD_CODES_ID:	  std_codes_count = count;	  count = ((count + 1) * sizeof(DD$STD_CODES_DSD));	  std_codes = (DD$STD_CODES_DSD_PTR) malloc(count);	  if (read(ifd, std_codes, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STD_REGS_ID:	  std_regs_count = count;	  count = ((count + 1) * sizeof(DD$STD_REGS_DSD));	  std_regs = (DD$STD_REGS_DSD_PTR) malloc(count);	  if (read(ifd, std_regs, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STD_ITEMS_ID:	  std_items_count = count;	  count = ((count + 1) * sizeof(DD$STD_ITEMS_DSD));	  std_items = (DD$STD_ITEMS_DSD_PTR) malloc(count);	  if (read(ifd, std_items, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STD_SEG_ITEMS_ID:	  std_seg_items_count = count;	  count = ((count + 1) * sizeof(DD$STD_SEG_ITEMS_DSD));	  std_seg_items = (DD$STD_SEG_ITEMS_DSD_PTR) malloc(count);	  if (read(ifd, std_seg_items, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STD_SEGS_ID:	  std_segs_count = count;	  count = ((count + 1) * sizeof(DD$STD_SEGS_DSD));	  std_segs = (DD$STD_SEGS_DSD_PTR) malloc(count);	  if (read(ifd, std_segs, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$DSP_LABELS_ID:	  labels_count = count;	  count = ((count + 1) * sizeof(DD$DSP_LABELS));	  labels = (DD$DSP_LABELS_PTR) malloc(count);	  if (read(ifd, labels, count) != count)	      return(DD$BAD_BIN_FILE);	break;	case DD$STRINGS_ID:	  strings_area_count = count++;	  strings_area = malloc(count);	  if (read(ifd, strings_area, count) != count)	      return(DD$BAD_BIN_FILE);	break;	default:	  return(DD$BAD_BIN_FILE);	break;        }    }return (DD$SUCCESS);}/********************** GET_BIN_FILE_VERSION ******************** * *		INPUT		 * *		OUTPUT		bin_file_ver * ****************************************************************/long  get_bin_file_ver(){return bin_file_ver;}/********************** GET_ITEM_INDEX FUNCTION ***************** * *		INPUT		item_id * *		OUTPUT		item_index * ****************************************************************/long  get_item_index (item_id)short item_id;{short	i;for (i = 0; i < std_items_count; i++)    if (item_id == std_items[i].ID)	return i;printf("\nUnknown data-id %d in \"get_item_index\"!\n", item_id); return 0;}/**********************  GET ITEM SIZE FUNCTION ***************** * *		INPUT		data_type *				length (if vector) * *		OUTPUT		storage size * ****************************************************************/short get_item_size (data_type, length)short data_type;short length;{short size;switch (data_type)    {    case DT_TINY :    case DT_TINY_INDEX :        size = 1;        break;    case DT_SHORT :    case DT_SHORT_INDEX :    case DT_SHORT_REGISTER :        size = 2;        break;    case DT_LONG :    case DT_INDEXED :    case DT_REGISTER :    case DT_DATE :        size = 4;        break;    case DT_VMS_TIME :        size = 8;        break;    case DT_BYTE_VECTOR :    case DT_ASCIZ :    case DT_BIT_VECTOR :        size = length;        break;    case DT_COUNTED_SHORT_VECTOR :        size = (length + 1) * 2;		/* + 1 is for the length word */        break;    case DT_COUNTED_LONG_VECTOR :        size = (length + 1) * 4;		/* + 1 is for the length word */        break;    case DT_ADDR_CNT_VECTOR :        size = (length + 2) * 4;		/* +2 for addr & length words */        break;    case DT_STRING :        size = 4;        break;    case DT_SHORT_VECTOR :        size = length * 2;        break;    case DT_LONG_VECTOR :        size = length * 4;        break;    default :        printf("\nUnknown data-type %d in \"get_item_size\"!\n", data_type);         size = 0;        break;    }return size;}/**********************  ALIGN STD OUTPUT *********************** * *		INPUT		pointer *				data_type * *		OUTPUT		aligned pointer * ****************************************************************/DD$BYTE *fld_align(pointer, data_type)DD$BYTE *pointer;short data_type;{switch (data_type)    {    case DT_TINY:    case DT_TINY_INDEX:    case DT_ASCIZ:    case DT_BIT_VECTOR:				/* no allignment needed *//*	return pointer;    break;*/    case DT_SHORT:    case DT_SHORT_INDEX:    case DT_SHORT_REGISTER:    case DT_SHORT_VECTOR:    case DT_COUNTED_SHORT_VECTOR:		/* short allignment needed *//*        return (DD$BYTE *)(((long)pointer + 1) & 0xfffffffe);    break;*/    case DT_LONG:    case DT_INDEXED:    case DT_REGISTER:    case DT_DATE:    case DT_BYTE_VECTOR:    case DT_COUNTED_LONG_VECTOR:    case DT_ADDR_CNT_VECTOR:    case DT_LONG_VECTOR:    case DT_VMS_TIME:    case DT_STRING:		/* long allignment needed */        return (DD$BYTE *)(((long)pointer + 3) & 0xfffffffc);    break;    default:		/* long allignment needed */        return (DD$BYTE *)(((long)pointer + 3) & 0xfffffffc);    break;    }}/********************************************************************++**  get_std_segment_dsd****  o Description****      The application fills in the pointer to the data-segemnt in the CTX**      before the call and the function fills in the information for the**      segment and its first element.****  o Return values****	DD$SUCCESS		- Function completed successfully.**	DD$UNKNOWN_SEGMENT	- The "segment_type" / "segment_subtype"**				  combination doesn't exist in the DSD tables.**	DD$UNKNOWN_ITEM		- Can not find the definition for an item!**				  Indicates that the DSD tables are corrupted!****  o Remarks****	A call must have been made to "dsd_init" to initialize the DSD**	tables before using this function.****--*/long get_std_segment_dsd (ctx)DD$STD_DSD_CTX_PTR ctx;{					/* Fill the Context Structure */ctx->CTX_type = std_segment;		/* CTX for std segment */ctx->curr_item = 1;			/* Set current seg item*/ctx->curr_field = 1;ctx->field_DSD_ptr = 0;ctx->field_position = 0;ctx->code_DSD_ptr = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -