home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / object / compatible.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-16  |  7.7 KB  |  268 lines

  1. /********************************************************************
  2.  * $Author: lindner $
  3.  * $Revision: 1.4 $
  4.  * $Date: 1993/01/17 03:46:12 $
  5.  * $Source: /home/mudhoney/GopherSrc/gopher1.11b/object/RCS/compatible.c,v $
  6.  * $State: Rel $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: compatible.c
  14.  * Compatibility routines
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: compatible.c,v $
  18.  * Revision 1.4  1993/01/17  03:46:12  lindner
  19.  * Fixed tempnam for VMS
  20.  *
  21.  * Revision 1.3  1993/01/08  23:13:55  lindner
  22.  * Added more VMS mods from jqj
  23.  *
  24.  *
  25.  *********************************************************************/
  26.  
  27.  
  28. /*
  29.  * Some functions that aren't implemented on every machine on the net
  30.  *
  31.  * definitions should be in the form "NO_FNNAME"
  32.  * compatible.h looks at preprocessor symbols and automatically defines
  33.  * many of the NO_FNNAME options
  34.  *
  35.  */
  36.  
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include "Malloc.h"  /*** For NULL ***/
  40. #include "compatible.h"
  41.  
  42. /*** For machines that don't have strstr ***/
  43.  
  44. #if defined(NOSTRSTR)
  45.  
  46. char *
  47. strstr(host_name, cp)
  48.   char *host_name;
  49.   char *cp;
  50. {
  51.      int i, j;
  52.  
  53.      for (i = 0; i < strlen(host_name); i++) {
  54.           j = strncmp(host_name+i, cp, strlen(cp));
  55.           if (j == 0)
  56.                return(host_name+i);
  57.      }
  58.      return(NULL);
  59. }
  60. #endif
  61.  
  62. #if defined(sequent)
  63.  
  64. #include <varargs.h>
  65. vsprintf(va_alist)
  66.   va_dcl
  67. {
  68.         ;
  69. }
  70.  
  71. vfprintf(va_alist)
  72.   va_dcl
  73. {
  74.         ;
  75. }
  76.  
  77.  
  78. #endif
  79.  
  80. #if defined(NO_TEMPNAM)
  81. char *tempnam(dir, pfx)
  82.   char *dir;
  83.   char *pfx;
  84. {
  85. #ifndef VMS
  86.     return(tmpnam(NULL));
  87. #else
  88.     char *tmpname;
  89.     register int len;
  90.         char tmpfilename[L_tmpnam];
  91.  
  92.         (void) tmpnam(tmpfilename);
  93.     len = strlen(tmpfilename)+13;
  94.     tmpname = (char *) malloc(sizeof(char)*len+1);
  95.         sprintf(tmpname,"sys$scratch:%s.",tmpfilename);
  96.         return(tmpname);
  97. #endif
  98. }
  99. #endif
  100.  
  101. #if defined(NO_STRDUP)
  102. char *strdup(str)
  103.   char *str;
  104. {
  105.         int len;
  106.         char *temp;
  107.  
  108.         if (str == NULL) return(NULL);
  109.         len = strlen(str);
  110.  
  111.         temp = (char *) malloc(sizeof(char) * len + 1);
  112.  
  113.         strcpy(temp, str);
  114.         return(temp);
  115. }
  116. #endif
  117.  
  118. #if defined(NO_TZSET)
  119. void
  120. tzset()
  121. {
  122.      ;
  123. }
  124. #endif
  125.  
  126. #if defined(NO_STRCASECMP)
  127. /*
  128.  * Copyright (c) 1987 Regents of the University of California.
  129.  * All rights reserved.
  130.  *
  131.  * Redistribution and use in source and binary forms, with or without
  132.  * modification, are permitted provided that the following conditions
  133.  * are met:
  134.  * 1. Redistributions of source code must retain the above copyright
  135.  *    notice, this list of conditions and the following disclaimer.
  136.  * 2. Redistributions in binary form must reproduce the above copyright
  137.  *    notice, this list of conditions and the following disclaimer in the
  138.  *    documentation and/or other materials provided with the distribution.
  139.  * 3. All advertising materials mentioning features or use of this software
  140.  *    must display the following acknowledgement:
  141.  *    This product includes software developed by the University of
  142.  *    California, Berkeley and its contributors.
  143.  * 4. Neither the name of the University nor the names of its contributors
  144.  *    may be used to endorse or promote products derived from this software
  145.  *    without specific prior written permission.
  146.  *
  147.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  148.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  149.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  150.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  151.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  152.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  153.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  154.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  155.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  156.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  157.  * SUCH DAMAGE.
  158.  *
  159.  * Modified for use on VMS by Earl Fogel, University of Saskatchewan
  160.  * Computing Services, January 1992
  161.  */
  162.  
  163. typedef unsigned char u_char;
  164.  
  165. /*
  166.  * This array is designed for mapping upper and lower case letter
  167.  * together for a case independent comparison.  The mappings are
  168.  * based upon ascii character sequences.
  169.  */
  170. static const u_char charmap[] = {
  171.     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  172.     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  173.     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  174.     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  175.     '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  176.     '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  177.     '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  178.     '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  179.     '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  180.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  181.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  182.     '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  183.     '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  184.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  185.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  186.     '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  187.     '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  188.     '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  189.     '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  190.     '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  191.     '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  192.     '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  193.     '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  194.     '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  195.     '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  196.     '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
  197.     '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
  198.     '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  199.     '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  200.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  201.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  202.     '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  203. };
  204.  
  205. int
  206. strcasecmp(s1, s2)
  207.     const char *s1, *s2;
  208. {
  209.     register const u_char *cm = charmap,
  210.             *us1 = (const u_char *)s1,
  211.             *us2 = (const u_char *)s2;
  212.  
  213.     while (cm[*us1] == cm[*us2++])
  214.         if (*us1++ == '\0')
  215.             return (0);
  216.     return (cm[*us1] - cm[*--us2]);
  217. }
  218.  
  219. int
  220. strncasecmp(s1, s2, n)
  221.     const char *s1, *s2;
  222.     register size_t n;
  223. {
  224.     if (n != 0) {
  225.         register const u_char *cm = charmap,
  226.                 *us1 = (const u_char *)s1,
  227.                 *us2 = (const u_char *)s2;
  228.  
  229.         do {
  230.             if (cm[*us1] != cm[*us2++])
  231.                 return (cm[*us1] - cm[*--us2]);
  232.             if (*us1++ == '\0')
  233.                 break;
  234.         } while (--n != 0);
  235.     }
  236.     return (0);
  237. }
  238.  
  239. #endif
  240.  
  241. #if defined(VMS)
  242. /* In all versions of VMS, fopen() and open() are needlessly inefficient.
  243.  * Define jacket routines to do file opens with more sensible parameters
  244.  * than the VAXCRTL default.
  245.  * [Should we really be doing this for EVERY fopen() and open()?]
  246.  */
  247. #ifdef fopen
  248. #undef fopen
  249. #endif
  250. #ifdef open
  251. #undef open
  252. #endif
  253.  
  254. FILE *fopen_VMSopt ( name, mode )
  255.     char *name, *mode;
  256. {
  257.     return fopen ( name, mode, "mbc=32" );
  258. }
  259.  
  260. int open_VMSopt ( name, flags, mode )
  261.     char *name;
  262.     int flags;
  263.     unsigned int mode;
  264. {
  265.     return  open ( name, flags, mode, "mbc=32");
  266. }
  267. #endif
  268.