From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  8-JUL-1992 00:47:07.14
To:	info-vax@kl.sri.com
CC:	
Subj:	CTRAP Release Version 2.0 (Part 2 of 2)

Following is CTRAP v2.0 part 2 of 2 in VMSSHARE format.

Belgarion.
_____
Ulysses Castillo (aka Belgarion)
Castillo@nauvax.ucc.nau.edu
"Be assured, I am with you always, to the end of Time.", Matt. 28:20

-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
X    int return_length_address;
X    int end;
X`7D item_list_3;
X
X
Xconst char *DEFAULT_INTERNET_TRANSPORT = "IN%";
X
X/* prototypes */
X
Xvoid handle_mail(msg_type msg);
Xvoid get_from_username(char *username);
Xint send_mail(send_blk info);
Xvoid set_null_list(mail_item_list *list);
Xvoid fill_list(int code,char *buffer,mail_item_list *list);
Xint send_add_file(char *file);
Xchar *check_address(char *to_string);
X/* global vars */
X
Xmail_item_list null_list;
Xint user_context;
$ CALL UNPACK SEND_MAIL.H;1 1628051268
$ create 'f'
X/*      CTRAP v2.0              Summer 1992
X
X`09MODULE NAME: Tools.c
X`09HEADER: none
X`09SUBMODULES: none
X        SHAREABLE IMAGE: none
X
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: September 20, 1991
X                      July 6, 1992 release version 2.0
X`20
X        Taken from the Camelot System utility CMAIL.
X
X`09Purpose:  Tools is a miscellaneous file that is included in the other
Xmodules of ctrap.  They are general purpose functions that support other`20
Xfunctions.
X`09Compilation: Tools.c IS NOT COMPILED.
X*/
X
X#include <string.h>
X
X/*=================build_descr==============================================
V=*/
Xtypedef struct
X`7B
X    short int length;`09`09/* Length of string      */
X    char dtype;`09`09`09/* Type 14 is a string   */
X    char class;`09`09`09/* Class 1 is fixed length */
X    char *ptr;`09`09`09/* Pointer to the string */
X`7D descr;`09`09`09/* once initialized, this is a fixed */
X/* length string descriptor */
X
Xstatic void build_descr(p,s)
X   /* Build descriptor takes a DESCR struct and a string and builds */
X   /* a fixed length string descriptor out of the DESCR struct.     */
X
X    descr *p;
X    char s`5B`5D;
X`7B
X
X    p->length = strlen(s);
X    p->dtype = 14;
X    p->class = 1;
X    p->ptr = s;
X`7D
X/*==============translate_lognam====================================*/
X
X/* uses build_descr and typedef descr */
X
X#include <lnmdef.h>
X
Xtypedef struct
X`7B
X    short int buffer_length;
X    short int item_code;
X    int buffer_address;
X    int return_length_address;
X    int end;
X`7D item_list_3_tools;
X
Xstatic int translate_lognam(char *lognamstring,char *process_table,char *equ
Vivalence)
X/* this function translates the logical name lognam under the process table
X   in process_table, and returns the equivalent string through equivalence.
X   On error, translate_lognam returns -1, otherwise 1.
X*/
X`7B
X    int i;
X    item_list_3_tools list;
X    descr tabnam,lognam;
X    short int lognamelen;
X    char equivname`5B80`5D;
X
X    build_descr(&tabnam,process_table);
X    build_descr(&lognam,lognamstring);
X    list.buffer_length = 80;
X    list.item_code = LNM$_STRING;
X    list.buffer_address = (int) &(equivname`5B0`5D);
X    list.return_length_address = (int) &lognamelen;
X    list.end = 0;
X
X    i = sys$trnlnm(&LNM$M_CASE_BLIND,&tabnam,&lognam,0,&list);
X    if ((i & 1) != 1) return -1;
X    equivname`5Blognamelen`5D = 0;
X    strcpy(equivalence,equivname);
X    return 1;
X`7D`09`09`09`09/* translate_lognam */
X
X/*===================strtrim========================================*/
Xstatic char *strtrim(char *s)
X`7B
X    int i = 0;
X
X    while (s`5Bi`5D != 0) ++i;
X    if (i == 0)
X`09return s;
X    --i;
X    while (s`5Bi`5D == '\n' `7C`7C s`5Bi`5D == ' ' `7C`7C s`5Bi`5D == '\t')
V --i;
X    s`5B++i`5D = 0;
X
X    return s;
X`7D
X
X/*==================================strclocate=======================*/
X
Xstatic int strclocate(char *s,char c)
X`7B
X    int i = 0;
X
X    while (s`5Bi`5D != c && s`5Bi`5D != '\n' && s`5Bi`5D != '\0') ++i;
X
X    return i;
X`7D`09`09`09`09/* strclocate */
X
X/*=========================strllocate=============================*/
X
X/* strllocate -- find the last occurance of c in *s
X     return the position, or -1 if not found. */
Xstatic int strllocate(char *s,char c)
X`7B
X    int save;
X    int i = 0;
X
X    save = strlen(s);
X
X    while (s`5Bi`5D != '\n' && s`5Bi`5D != '\0')
X    `7B
X`09if (s`5Bi`5D == c)
X`09    save = i;
X`09++i;
X    `7D`09`09`09`09/* while */
X    return save;
X`7D`09`09`09`09/* strllocate */
X
X/*=========================strtoupper=============================*/
Xstatic char *strtoupper(char *source,char *target)
X/* convert s to upper case, return through target. */
X`7B
X    while (*target++ = toupper(*source++))
X`09;
X    return target;
X`7D`09`09`09`09/* strtoupper */
X
X
X/*=========================strlocate=============================*/
Xstatic int strlocate(char *a,char *b)
X`09/* locate substring b, in string a, return index */
X`09/* or length of a if substring b not found. */
X`7B
X    int pos,i,j,k,lena,lenb;
X
X    lena = strlen(a);
X    lenb = strlen(b);
X    if (lenb > lena)
X`09return lena;`09`09/* substring cant be larger than a! */
X
X    i = 0;
X    j = 0;
X    k = 0;
X    pos = 0;
X    for (i = 0; i <= (lena - lenb); ++i)
X    `7B
X`09while ((a`5Bj`5D != '\0') && (a`5Bj`5D != b`5Bk`5D))
X`09    j++;
X`09pos = j;
X`09if (j > (lena - lenb) + 1)
X`09    return lena;`09/* not enough left in a for b to be there */
X
X`09while ((a`5Bj`5D != '\0') && (b`5Bk`5D != '\0') && (a`5Bj`5D == b`5Bk`5D)
V)
X`09`7B
X`09    ++j;
X`09    ++k;
X`09`7D`09`09`09/* while b matches a, not including \0 */
X`09if (k == lenb)
X`09    return pos;`09`09/* we found it */
X`09else
X`09    k = 0;`09`09/* that wasn't it, try again */
X    `7D`09`09`09`09/* for */
X    return lena;`09`09/* not there */
X`7D`09`09`09`09/* strlocate */
X/*=========================strextract=============================*/
Xstatic char *strextract(char *s,int j,int k)
X`7B
X    char *t;
X    int i;
X
X    if (j > k)
X`09return "\0";
X
X    t = (char *) malloc(k - j + 2);
X    for (i = j; i <= k; ++i)
X`09t`5Bi - j`5D = s`5Bi`5D;
X    t`5B++i - j`5D = 0;
X
X    return t;
X`7D`09`09`09`09/* strextract */
X
X/*==========================================strclr=====================*/
Xstatic void strclr(char *s)
X/* clear all contains of string s. */
X`7B
X    register int i;
X
X    for (i = 0; i <= strlen(s); i++)
X`09s`5Bi`5D = 0;
X`7D`09`09`09`09/* strclr */
$ CALL UNPACK TOOLS.C;1 796681545
$ v=f$verify(v)
$ EXIT

