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

📄 vms.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 2 页
字号:
#define DEF_DEVDIRNAM "SYS$DISK:[].zip"char *ziptyp( char *s){    int status;    int exp_len;    struct FAB fab;    struct NAM_STRUCT nam;    char result[ NAM_MAXRSS+ 1];    char exp[ NAM_MAXRSS+ 1];    char *p;    fab = cc$rms_fab;                           /* Initialize FAB. */    nam = CC_RMS_NAM;                           /* Initialize NAM[L]. */    fab.FAB_NAM = &nam;                         /* FAB -> NAM[L] */#ifdef NAML$C_MAXRSS    fab.fab$l_dna =(char *) -1;         /* Using NAML for default name. */    fab.fab$l_fna = (char *) -1;        /* Using NAML for file name. */#endif /* def NAML$C_MAXRSS */    FAB_OR_NAM( fab, nam).FAB_OR_NAM_FNA = s;           /* Arg file name, */    FAB_OR_NAM( fab, nam).FAB_OR_NAM_FNS = strlen( s);  /* length. */    FAB_OR_NAM( fab, nam).FAB_OR_NAM_DNA = DEF_DEVDIRNAM;   /* Default fspec */    FAB_OR_NAM( fab, nam).FAB_OR_NAM_DNS = sizeof( DEF_DEVDIRNAM)- 1;    nam.NAM_ESA = exp;                 /* Expanded name, */    nam.NAM_ESS = NAM_MAXRSS;          /* storage size. */    nam.NAM_RSA = result;              /* Resultant name, */    nam.NAM_RSS = NAM_MAXRSS;          /* storage size. */    status = sys$parse(&fab);    if ((status & 1) == 0)    {        /* Invalid file name.  Return (re-allocated) original, and hope           for a later error message.        */        if ((p = malloc( strlen( s)+ 1)) != NULL )        {            strcpy( p, s);        }        return p;    }    /* Save expanded name length from sys$parse(). */    exp_len = nam.NAM_ESL;    /* Leave expanded name as-is, in case of search failure. */    nam.NAM_ESA = NULL;                 /* Expanded name, */    nam.NAM_ESS = 0;                    /* storage size. */    status = sys$search(&fab);    if (status & 1)    {   /* Zip file exists.  Use resultant (complete, exact) name. */        if ((p = malloc( nam.NAM_RSL+ 1)) != NULL )        {            result[ nam.NAM_RSL] = '\0';            strcpy( p, result);        }    }    else    {   /* New Zip file.  Use pre-search expanded name. */        if ((p = malloc( exp_len+ 1)) != NULL )        {            exp[ exp_len] = '\0';            strcpy( p, exp);        }    }    return p;} /* ziptyp() for VMS. *//* 2004-11-23 SMS. * *       get_rms_defaults(). * *    Get user-specified values from (DCL) SET RMS_DEFAULT.  FAB/RAB *    items of particular interest are: * *       fab$w_deq         default extension quantity (blocks) (write). *       rab$b_mbc         multi-block count. *       rab$b_mbf         multi-buffer count (used with rah and wbh). */#define DIAG_FLAG (verbose >= 2)/* Default RMS parameter values. */#define RMS_DEQ_DEFAULT 16384   /* About 1/4 the max (65535 blocks). */#define RMS_MBC_DEFAULT 127     /* The max, */#define RMS_MBF_DEFAULT 2       /* Enough to enable rah and wbh. *//* GETJPI item descriptor structure. */typedef struct    {    short buf_len;    short itm_cod;    void *buf;    int *ret_len;    } jpi_item_t;/* Durable storage */static int rms_defaults_known = 0;/* JPI item buffers. */static unsigned short rms_ext;static char rms_mbc;static unsigned char rms_mbf;/* Active RMS item values. */unsigned short rms_ext_active;char rms_mbc_active;unsigned char rms_mbf_active;/* GETJPI item lengths. */static int rms_ext_len;         /* Should come back 2. */static int rms_mbc_len;         /* Should come back 1. */static int rms_mbf_len;         /* Should come back 1. *//* Desperation attempts to define unknown macros.  Probably doomed. * If these get used, expect sys$getjpiw() to return %x00000014 = * %SYSTEM-F-BADPARAM, bad parameter value. * They keep compilers with old header files quiet, though. */#ifndef JPI$_RMS_EXTEND_SIZE#  define JPI$_RMS_EXTEND_SIZE 542#endif /* ndef JPI$_RMS_EXTEND_SIZE */#ifndef JPI$_RMS_DFMBC#  define JPI$_RMS_DFMBC 535#endif /* ndef JPI$_RMS_DFMBC */#ifndef JPI$_RMS_DFMBFSDK#  define JPI$_RMS_DFMBFSDK 536#endif /* ndef JPI$_RMS_DFMBFSDK *//* GETJPI item descriptor set. */struct    {    jpi_item_t rms_ext_itm;    jpi_item_t rms_mbc_itm;    jpi_item_t rms_mbf_itm;    int term;    } jpi_itm_lst =     { { 2, JPI$_RMS_EXTEND_SIZE, &rms_ext, &rms_ext_len },       { 1, JPI$_RMS_DFMBC, &rms_mbc, &rms_mbc_len },       { 1, JPI$_RMS_DFMBFSDK, &rms_mbf, &rms_mbf_len },       0     };int get_rms_defaults(){int sts;/* Get process RMS_DEFAULT values. */sts = sys$getjpiw( 0, 0, 0, &jpi_itm_lst, 0, 0, 0);if ((sts& STS$M_SEVERITY) != STS$K_SUCCESS)    {    /* Failed.  Don't try again. */    rms_defaults_known = -1;    }else    {    /* Fine, but don't come back. */    rms_defaults_known = 1;    }/* Limit the active values according to the RMS_DEFAULT values. */if (rms_defaults_known > 0)    {    /* Set the default values. */    rms_ext_active = RMS_DEQ_DEFAULT;    rms_mbc_active = RMS_MBC_DEFAULT;    rms_mbf_active = RMS_MBF_DEFAULT;    /* Default extend quantity.  Use the user value, if set. */    if (rms_ext > 0)        {        rms_ext_active = rms_ext;        }    /* Default multi-block count.  Use the user value, if set. */    if (rms_mbc > 0)        {        rms_mbc_active = rms_mbc;        }    /* Default multi-buffer count.  Use the user value, if set. */    if (rms_mbf > 0)        {        rms_mbf_active = rms_mbf;        }    }if (DIAG_FLAG)    {    fprintf( stderr,     "Get RMS defaults.  getjpi sts = %%x%08x.\n",     sts);    if (rms_defaults_known > 0)        {        fprintf( stderr,         "               Default: deq = %6d, mbc = %3d, mbf = %3d.\n",         rms_ext, rms_mbc, rms_mbf);        }    }return sts;}#ifdef __DECC/* 2004-11-23 SMS. * *       acc_cb(), access callback function for DEC C zfopen(). * *    Set some RMS FAB/RAB items, with consideration of user-specified * values from (DCL) SET RMS_DEFAULT.  Items of particular interest are: * *       fab$w_deq         default extension quantity (blocks). *       rab$b_mbc         multi-block count. *       rab$b_mbf         multi-buffer count (used with rah and wbh). * *    See also the FOP* macros in OSDEP.H.  Currently, no notice is * taken of the caller-ID value, but options could be set differently * for read versus write access.  (I assume that specifying fab$w_deq, * for example, for a read-only file has no ill effects.) *//* Global storage. */int fopm_id = FOPM_ID;          /* Callback id storage, modify. */int fopr_id = FOPR_ID;          /* Callback id storage, read. */int fopw_id = FOPW_ID;          /* Callback id storage, write. *//* acc_cb() */int acc_cb( int *id_arg, struct FAB *fab, struct RAB *rab){int sts;/* Get process RMS_DEFAULT values, if not already done. */if (rms_defaults_known == 0)    {    get_rms_defaults();    }/* If RMS_DEFAULT (and adjusted active) values are available, then set * the FAB/RAB parameters.  If RMS_DEFAULT values are not available, * suffer with the default parameters. */if (rms_defaults_known > 0)    {    /* Set the FAB/RAB parameters accordingly. */    fab-> fab$w_deq = rms_ext_active;    rab-> rab$b_mbc = rms_mbc_active;    rab-> rab$b_mbf = rms_mbf_active;    /* Truncate at EOF on close, as we'll probably over-extend. */    fab-> fab$v_tef = 1;    /* If using multiple buffers, enable read-ahead and write-behind. */    if (rms_mbf_active > 1)        {        rab-> rab$v_rah = 1;        rab-> rab$v_wbh = 1;        }    if (DIAG_FLAG)        {        fprintf( mesg,         "Open callback.  ID = %d, deq = %6d, mbc = %3d, mbf = %3d.\n",         *id_arg, fab-> fab$w_deq, rab-> rab$b_mbc, rab-> rab$b_mbf);        }    }/* Declare success. */return 0;}#endif /* def __DECC *//* * 2004-09-19 SMS. * *---------------------------------------------------------------------- * *       decc_init() * *    On non-VAX systems, uses LIB$INITIALIZE to set a collection of C *    RTL features without using the DECC$* logical name method. * *---------------------------------------------------------------------- */#ifdef __DECC#ifdef __CRTL_VER#if !defined( __VAX) && (__CRTL_VER >= 70301000)#include <unixlib.h>/*--------------------------------------------------------------------*//* Global storage. *//*    Flag to sense if decc_init() was called. */int decc_init_done = -1;/*--------------------------------------------------------------------*//* decc_init()      Uses LIB$INITIALIZE to set a collection of C RTL features without      requiring the user to define the corresponding logical names.*//* Structure to hold a DECC$* feature name and its desired value. */typedef struct   {   char *name;   int value;   } decc_feat_t;/* Array of DECC$* feature names and their desired values. */decc_feat_t decc_feat_array[] = {   /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ { "DECC$ARGV_PARSE_STYLE", 1 },#if 0  /* Possibly useful in the future. */   /* Preserve case for file names on ODS5 disks. */ { "DECC$EFS_CASE_PRESERVE", 1 },   /* Enable multiple dots (and most characters) in ODS5 file names,      while preserving VMS-ness of ";version". */ { "DECC$EFS_CHARSET", 1 },#endif /* 0 */   /* List terminator. */ { (char *)NULL, 0 } };/* LIB$INITIALIZE initialization function. */static void decc_init( void){int feat_index;int feat_value;int feat_value_max;int feat_value_min;int i;int sts;/* Set the global flag to indicate that LIB$INITIALIZE worked. */decc_init_done = 1;/* Loop through all items in the decc_feat_array[]. */for (i = 0; decc_feat_array[ i].name != NULL; i++)   {   /* Get the feature index. */   feat_index = decc$feature_get_index( decc_feat_array[ i].name);   if (feat_index >= 0)      {      /* Valid item.  Collect its properties. */      feat_value = decc$feature_get_value( feat_index, 1);      feat_value_min = decc$feature_get_value( feat_index, 2);      feat_value_max = decc$feature_get_value( feat_index, 3);      if ((decc_feat_array[ i].value >= feat_value_min) &&       (decc_feat_array[ i].value <= feat_value_max))         {         /* Valid value.  Set it if necessary. */         if (feat_value != decc_feat_array[ i].value)            {            sts = decc$feature_set_value( feat_index,             1,             decc_feat_array[ i].value);            }         }      else         {         /* Invalid DECC feature value. */         printf( " INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",          feat_value,          feat_value_min, decc_feat_array[ i].name, feat_value_max);         }      }   else      {      /* Invalid DECC feature name. */      printf( " UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[ i].name);      }   }}/* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */#pragma nostandard/* Establish the LIB$INITIALIZE PSECTs, with proper alignment and   other attributes.  Note that "nopic" is significant only on VAX.*/#pragma extern_model save#pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrtconst int spare[ 8] = { 0 };#pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrtvoid (*const x_decc_init)() = decc_init;#pragma extern_model restore/* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */#pragma extern_model saveint LIB$INITIALIZE( void);#pragma extern_model strict_refdefint dmy_lib$initialize = (int) LIB$INITIALIZE;#pragma extern_model restore#pragma standard#endif /* !defined( __VAX) && (__CRTL_VER >= 70301000) */#endif /* def __CRTL_VER */#endif /* def __DECC */#endif /* VMS */

⌨️ 快捷键说明

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