[comp.os.vms] ARC_C.SHAR18_OF_19

ewilts%Ins.MRC.AdhocNet.CA%Stasis.MRC.AdhocNet.CA%UNCAEDU.@CORNELLC.CCS.CORNELL.EDU.BITNET (Ed Wilts) (06/24/88)

$Part18:
$ File_is="ARCVAX.C"
$ Check_Sum_is=152877947
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X#include <stdio.h>
X#include <ctype.h>
X#include "arc.h"
X
X#ifdef VAXC
X#include <stsdef.h>
X#include <ssdef.h>
X#include <rms.h>
X#include <descrip.h>
X#include "dir.h"
Xint long sys$setddir();
Xint lib$spawn();
Xint lib$find_file();
Xint lib$find_file_end();
Xint long lib$init_timer();
Xint long lib$show_timer();
Xint long lib$show_vm();
Xint long zero = 0;
Xint long four = 4;
X#endif
X
X/*
X * Misc routines to emulate IBM MSDOS functions under BSD
X *
X * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
X * `009Bludgeoned into submission for VAX 11/780 BSD4.2
X *`009(ugly code, but fewer core dumps)
X */
XINT upper(string)
Xchar *string;
X{
X    register char *p;
X
X    for(p = string; *p != NULL; p++)
X`009if(islower(*p))
X`009    *p = toupper(*p);
X}
Xchar *setmem(dest,size,c)
Xchar *dest,c;
XINT size;
X{
X INT i;
X
X    for(i = 0; i < size; dest[i] = c, i++);
X    return(&dest[0]);
X}
Xchar *gcdir(dirname)
Xchar *dirname;
X
X{
X#ifdef VAXC
X`009struct dsc$descriptor_s dsc;
X`009unsigned int def_len;
X`009long int ret;
X`009int slen;
X
X`009slen = strlen(dirname);
X#endif
X`009if(dirname == NULL || strlen(dirname) == 0)
X#ifdef VAXC
X`009{
X`009`009slen = 1024;
X#endif
X`009`009dirname = (char *)malloc(1024);
X#ifdef VAXC
X`009}
X#endif
X
X#ifdef VAXC
X`009dsc.dsc$w_length = slen;`009/* length of work area */
X`009dsc.dsc$a_pointer = dirname;`009/* Address of string */
X`009dsc.dsc$b_class = DSC$K_CLASS_S;
X`009dsc.dsc$b_dtype = DSC$K_DTYPE_T;
X`009ret = sys$setddir(0,&def_len,&dsc);
X      `009if (!(ret & STS$M_SUCCESS))
X`009{
V       `009`009fprintf(stderr,"%%VAXARC-F, Error in getting default account\n")
X;
X       `009`009fprintf(stderr,"RMS_STATUS = %ld\n",ret);
X`009`009exit(ret);
X`009}
X#else
X`009getwd(dirname);
X#endif
X`009return(dirname);
X}
X#ifdef VMS
XINT vabort(s,arg1,arg2,arg3)
X#else
XINT abort(s,arg1,arg2,arg3)
X#endif
Xchar *s;
X{
X    fprintf(stderr,"ARC: ");
X    fprintf(stderr,s,arg1,arg2,arg3);
X    fprintf(stderr,"\n");
X#if BSD
X    perror("BSD");
X#endif
X    exit(1);
X}
X
X#ifdef VAXC
X/*
X * Do a forward index using a byte into a string.
X * return = 0 if not found
X *`009  = address if found
X */
X
Xchar *index(str1, str2)
Xchar *str1;
Xchar str2;
X{
X`009return((char *) strchr(str1,str2));
X}
X
X/*
X * Do a reverse index using a byte into a string.
X * return = 0 if not found
X *`009  = address if found
X */
X
Xchar *rindex(str1, str2)
Xchar *str1;
Xchar str2;
X{
X`009return((char *) strrchr(str1,str2));
X}
X
X/*
X * Do the MS-DOS/UNIX System command.
X */
X
X#ifdef abc123
X
Xint system(buf)
Xchar *buf;
X{
X`009struct dsc$descriptor_s dsc_cmd;
X`009long int rms_stat, spawn_flags, spawn_status;
X`009char cmd[100];
X
X`009strcpy(cmd, "RUN ");
X`009strcat(cmd, buf);
X`009spawn_flags = 0;
X
X`009dsc_cmd.dsc$w_length = strlen(cmd);`009/* length of work area */
X`009dsc_cmd.dsc$a_pointer = cmd;`009`009/* Address of string */
X`009dsc_cmd.dsc$b_class = DSC$K_CLASS_S;
X`009dsc_cmd.dsc$b_dtype = DSC$K_DTYPE_T;
X
X`009rms_stat = lib$spawn(`009dsc_cmd,
X`009`009`009`0090,`009`009/* input file */
X`009`009`009`0090,`009`009/* Output file */
X`009`009`009`009&spawn_flags,`009/* Spawn flags */
X`009`009`009`0090,`009`009/* Process name */
X`009`009`009`0090,`009`009/* Process id */
X`009`009`009`009&spawn_status,`009/* Returned program status */
X`009`009`009`0090,`009`009/* Completion EFN */
X`009`009`009`0090,`009`009/* Completion ASTADR */
X`009`009`009`0090,`009`009/* Completion ASTARG */
X`009`009`009`0090,`009`009/* Prompt */
X`009`009`009`0090);`009`009/* CLI */
X`009return(spawn_status);
X}
X#endif
X
X/*
X * For VAXC we need the functions scandir and alphasort
X */
X
Xchar *pattern;`009/* External pointer to file name */
X
XINT scandir(delim,namelist,match,sort)
Xchar *delim;
Xstruct direct ***namelist;
Xchar (*match)();
Xchar (*sort)();
X{
X    struct direct dd;
X    struct dsc$descriptor_s dsc_in, dsc_out;
X    long int rms_stat, find_file_context;
X    int out_len, file_cnt = 0;
X    char out_file[255], *cp, **pnt=0;
X
X    INT parsedir();
X
X    dsc_in.dsc$w_length = strlen(pattern);`009/* length of work area */
X    dsc_in.dsc$a_pointer = pattern;`009`009/* Address of string */
X    dsc_in.dsc$b_class = DSC$K_CLASS_S;
X    dsc_in.dsc$b_dtype = DSC$K_DTYPE_T;
X
X    dsc_out.dsc$w_length = 0;`009`009`009/* length of work area */
X    dsc_out.dsc$a_pointer = 0;`009`009`009/* Address of string */
X    dsc_out.dsc$b_class = DSC$K_CLASS_D;
X    dsc_out.dsc$b_dtype = DSC$K_DTYPE_T;
X
X    *namelist = (char *)malloc(sizeof(char *));
X    find_file_context = 0;`009`009`009/* No Context on start */
X
X    while ((rms_stat = lib$find_file(
X`009`009`009`009&dsc_in,`009/* File spec */
X`009`009`009`009&dsc_out,`009/* Result file spec */
X`009`009`009`009&find_file_context, /* Context */
X`009`009`009`0090,`009`009/* Default file spec */
X`009`009`009`0090,`009`009/* Related spec */
X`009`009`009`0090,`009`009/* STV error */
X`009`009`009`0090)) == RMS$_NORMAL)
X`009{
X`009file_cnt++;`009`009/* Increment the file count */
V`009strncpy(out_file, dsc_out.dsc$a_pointer,(unsigned int)dsc_out.dsc$w_length)
X;
X`009*(&out_file + dsc_out.dsc$w_length) = '\0';
X`009(void) parsedir(out_file, 0, PARSE_NAME|PARSE_TYPE);
X`009out_len = strlen(out_file);
X#ifdef xyzzy
X`009out_len = 0;
X`009cp = &out_file;
X`009while(*cp++ != ' ') out_len++;
X`009*(--cp) = NULL;`009`009/* Make string null terminated */
X`009out_len--;`009`009/* Just file name, not the NULL */
X#endif
X/* Allocate space for filename */
X
X`009*namelist = (char *)realloc(*namelist,file_cnt*sizeof(char *));
X#ifdef abc123
X`009(*namelist)[file_cnt-1] = (char *)malloc(sizeof(struct direct));
X#endif
X`009(*namelist)[file_cnt-1] =(struct direct *)malloc(sizeof(struct direct));
X`009(*namelist)[file_cnt-1]->d_namlen = out_len;`009/* Length of filename */
X`009strcpy((*namelist)[file_cnt-1]->d_name, out_file);
X`009};`009`009/* flags */
X    return(file_cnt);`009`009/* Return file count */
X    {
X/*
X * Process file names
X */
X
X    }
X/*
X * If call went well, rms_stat == RMS$_NORMAL
X */
X
X/*
X * On exit, we need to clear the internal fields used by RMS.
X */
X    rms_stat = lib$find_file_end(&find_file_context);
X}
X
XINT alphasort()
X{
X}
X
XINT parsedir(cp, defnam, flag)
Xchar *cp;`009`009/* Pointer to file spec to parse */
Xchar *defnam;`009`009/* Default file spec */
Xint flag;`009`009/* Flag word PARSE_xxx */
X{
X`009struct FAB fab;
X`009struct NAM nam;
X`009char expanded_name[NAM$C_MAXRSS];
X`009int long rms_status;
X`009int cp_len;
X
X`009cp_len = strlen(cp);
X
X`009fab = cc$rms_fab;
X`009fab.fab$l_nam = &nam;
X`009fab.fab$l_fna = cp;
X`009fab.fab$b_fns = strlen(cp);
X`009fab.fab$l_dna = defnam;
X`009if (defnam) fab.fab$b_dns = strlen(defnam);
X
X`009nam = cc$rms_nam;
X`009nam.nam$l_esa = &expanded_name;
X`009nam.nam$b_ess = sizeof(expanded_name);
X
X`009if ((rms_status = sys$parse(&fab)) != RMS$_NORMAL)
X`009{
X`009`009printf("%%PARSEDIR-F-PRSERR, Parse error %s\n",cp);
X`009`009exit(rms_status);
X`009}
X
X`009*cp = NULL;`009`009`009/* Make a zero length string */
X`009if ((PARSE_NODE & flag) && (int)nam.nam$b_node)
X`009`009strncat(cp, nam.nam$l_node, (int)nam.nam$b_node);
X`009if ((PARSE_DEVICE & flag) && (int)nam.nam$b_dev)
X`009`009strncat(cp, nam.nam$l_dev, (int)nam.nam$b_dev);
X`009if ((PARSE_DIRECTORY & flag) && (int)nam.nam$b_dir)
X`009`009strncat(cp, nam.nam$l_dir, (int)nam.nam$b_dir);
X`009if ((PARSE_NAME & flag) && (int)nam.nam$b_name)
X`009`009strncat(cp, nam.nam$l_name, (int)nam.nam$b_name);
X`009if ((PARSE_TYPE & flag) && (int)nam.nam$b_type)
X`009`009strncat(cp, nam.nam$l_type, (int)nam.nam$b_type);
X`009if ((PARSE_VERSION & flag) && (int)nam.nam$b_ver)
X`009`009strncat(cp, nam.nam$l_ver, (int)nam.nam$b_ver);
X`009return(0);
X}
X
Xvoid initvmsstats()
X{
X`009if (vmsstats) lib$init_timer();
X}
X
Xvoid printvmsstats()
X{
X`009if (vmsstats)
X`009{
X`009    lib$show_timer();
X`009    lib$show_vm(&zero);
X`009    lib$show_vm(&four);
X`009}
X}
X
X/*
X * Get RMS attributes so that we can save them in the file.
X * This will allow us to restore the file to an RMS envirement with
X * original attributes.
X */
Xvoid get_attr(file, atr)
Xchar *file;
Xstruct atr;
X{
X
X`009return;
X}
X#endif
X
$ GoSub Convert_File
$ Goto Part19