home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / gopherd / ext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  4.6 KB  |  218 lines

  1. /********************************************************************
  2.  * $Author: lindner $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1992/12/10 23:13:27 $
  5.  * $Source: /home/mudhoney/GopherSrc/release1.11/gopherd/RCS/ext.c,v $
  6.  * $Status: $
  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: ext.c
  14.  * These fns define mapping of file extensions to gopher objects.
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: ext.c,v $
  18.  * Revision 1.1  1992/12/10  23:13:27  lindner
  19.  * gopher 1.1 release
  20.  *
  21.  *
  22.  *********************************************************************/
  23.  
  24. #include "ext.h"
  25. #include "Malloc.h"
  26. #include <ctype.h>
  27.  
  28. extern boolean DEBUG;
  29.  
  30. /*
  31.  * Some functions to initialize and destroy sites and extensions..
  32.  * (Needed for use with DynArrays...)
  33.  */
  34.  
  35. static Ext *
  36. ExtNew()
  37. {
  38.      Ext *temp;
  39.  
  40.      temp = (Ext *) malloc(sizeof(Ext));
  41.      
  42.      if (temp == NULL)
  43.       return(NULL);
  44.  
  45.      temp->Objtype   = '\0';
  46.      temp->GplusType = STRnew();
  47.      STRinit(temp->GplusType);
  48.      temp->Prefix    = STRnew();
  49.      STRinit(temp->Prefix);
  50.      temp->ext       = STRnew();
  51.      STRinit(temp->ext);
  52.  
  53.      return(temp);
  54. }
  55.  
  56. static void ExtDestroy(ext)
  57.   Ext *ext;
  58. {
  59.      STRdestroy(ext->GplusType);
  60.      STRdestroy(ext->Prefix);
  61.      STRdestroy(ext->ext);
  62.      
  63.      free(ext);
  64. }
  65.  
  66. static void
  67. Extcpy(ext1, ext2)
  68.   Ext *ext1, *ext2;
  69. {
  70.      ext1->Objtype  = ext2->Objtype;
  71.      STRcpy(ext1->GplusType, ext2->GplusType);
  72.      STRcpy(ext1->Prefix, ext2->Prefix);
  73.      STRcpy(ext1->ext, ext2->ext);
  74. }
  75.  
  76. static void
  77. ExtSet(ext, objtype, gplustype, prefix, fileext)
  78.   Ext *ext;
  79.   char       objtype;
  80.   char       *gplustype;
  81.   char       *prefix;
  82.   char       *fileext;
  83. {
  84.      ext->Objtype = objtype;
  85.      STRset(ext->GplusType, gplustype);
  86.      STRset(ext->Prefix, prefix);
  87.      STRset(ext->ext, fileext);
  88. }
  89.  
  90. /******************************************************/
  91. /* Functions external routines can call.    */
  92.  
  93. ExtArray *
  94. ExtArrayNew()
  95. {
  96.      ExtArray *temp;
  97.      
  98.      temp = DAnew(20, ExtNew, NULL, ExtDestroy, Extcpy);
  99.      
  100.      return(temp);
  101. }
  102.  
  103. void
  104. ExtAdd(extarr, objtype, gplustype, prefix, fileext)
  105.   ExtArray *extarr;
  106.   char objtype;
  107.   char *gplustype;
  108.   char *prefix;
  109.   char *fileext;
  110. {
  111.      Ext *ext;
  112.  
  113.      if (DEBUG) printf("Adding extension '%s', objtype %c, prefix %s, gplustype '%s'\n",
  114.                fileext, objtype, prefix, gplustype);
  115.      
  116.      ext = ExtNew();
  117.      
  118.      ExtSet(ext, objtype, gplustype, prefix, fileext);
  119.      
  120.      DApush(extarr, ext);
  121.      
  122.      ExtDestroy(ext);
  123.      
  124. }
  125.  
  126. /*
  127.  * Get the parameters associated with a particular extension
  128.  */
  129.  
  130. void
  131. ExtGet(extarr, fileext, objtype, gplustype, prefix)
  132.   ExtArray *extarr;
  133.   char *fileext;
  134.   char *objtype;
  135.   char **gplustype;
  136.   char **prefix;
  137. {
  138.      int i;
  139.      Ext *temp;
  140.  
  141.      *objtype   = '\0';
  142.      *gplustype = NULL;
  143.      *prefix    = NULL;
  144.  
  145.      /*** Linear search.  Ick. ***/
  146.      
  147.      for (i=0; i< DAgetTop(extarr); i++) {
  148.  
  149.       temp = ExtgetEntry(extarr,i);
  150.       
  151.       if (strcasecmp(fileext+strlen(fileext)-strlen(STRget(temp->ext)), STRget(temp->ext))==0) {
  152.  
  153.            *objtype   = temp->Objtype;
  154.            *gplustype = STRget(temp->GplusType);
  155.            *prefix    = STRget(temp->Prefix);
  156.            
  157.            return;
  158.       }
  159.      }
  160. }
  161.  
  162. boolean 
  163. ExtProcessLine(extarr, inputline)
  164.   ExtArray *extarr;
  165.   char     *inputline;
  166. {
  167.      int i;
  168.      char ext[64];
  169.      char Gtype;
  170.      char prefix[64];
  171.      char Gplustype[64];
  172.  
  173.      /** Strip out the white space **/
  174.      while (isspace(*inputline))
  175.       inputline++;
  176.      if (*inputline == '\0') return(FALSE);
  177.  
  178.      /*** The extension itself ***/
  179.      i=0;
  180.      while (!isspace(*inputline))
  181.       ext[i++] = *inputline++;
  182.      if (*inputline == '\0') return(FALSE);
  183.  
  184.      ext[i] = '\0';
  185.      
  186.      while (isspace(*inputline))
  187.       inputline++;
  188.      if (*inputline == '\0') return(FALSE);
  189.  
  190.      /*** The Gophertype ***/
  191.      Gtype = *inputline++;
  192.      
  193.      while (isspace(*inputline))
  194.       inputline++;
  195.      if (*inputline == '\0') return(FALSE);
  196.  
  197.      /*** Prefix ***/
  198.      i=0;
  199.      while (!isspace(*inputline))
  200.       prefix[i++] = *inputline++;
  201.      if (*inputline == '\0') return(FALSE);
  202.      prefix[i]='\0';
  203.  
  204.      while (isspace(*inputline))
  205.       inputline++;
  206.      if (*inputline == '\0') return(FALSE);
  207.  
  208.      /*** Gopher + type ***/
  209.      i=0;
  210.      while (!isspace(*inputline))
  211.       Gplustype[i++]= *inputline++;
  212.  
  213.      Gplustype[i] = '\0';
  214.  
  215.      ExtAdd(extarr, Gtype, Gplustype, prefix, ext);
  216.      return(TRUE);
  217. }
  218.