Back to index

radiance  4R0+20100331
misc.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: misc.c,v 1.5 2005/09/23 19:22:37 greg Exp $";
00003 #endif
00004 /*
00005  *   Miscellaneous functions for meta-files
00006  */
00007 
00008 
00009 #include  "rtio.h"
00010 #include  "meta.h"
00011 
00012 
00013 char  coms[] = COML;
00014 
00015 /* char  errmsg[128];       redundant to error.c in ../commmon */
00016 
00017 
00018 
00019 int
00020 comndx(              /* return index for command */
00021        register int  c
00022 )
00023 
00024 {
00025  register char  *cp;
00026 
00027  if (!isalpha(c))
00028     return(-1);
00029 
00030  for (cp = coms; *cp; cp++)
00031     if(*cp == c)
00032        return(cp-coms);
00033 
00034  return(-1);
00035  }
00036 
00037 
00038 
00039 
00040 
00041 
00042 PRIMITIVE  *
00043 pop(                 /* pop top off plist */
00044        register PLIST  *pl
00045 )
00046 
00047 {
00048  register PRIMITIVE  *p;
00049 
00050  if ((p = pl->ptop) != NULL)  {
00051     if ((pl->ptop = p->pnext) == NULL)
00052        pl->pbot = NULL;
00053     p->pnext = NULL;
00054     }
00055 
00056  return(p);
00057  }
00058 
00059 
00060 
00061 void
00062 push(         /* push primitive onto plist */
00063        register PRIMITIVE  *p,
00064        register PLIST  *pl
00065 )
00066 
00067 {
00068 
00069  if ((p->pnext = pl->ptop) == NULL)
00070     pl->pbot = p;
00071  pl->ptop = p;
00072 
00073  }
00074 
00075 
00076 
00077 void
00078 add(          /* add primitive to plist */
00079        register PRIMITIVE  *p,
00080        register PLIST  *pl
00081 )
00082 {
00083 
00084  if (pl->ptop == NULL)
00085     pl->ptop = p;
00086  else
00087     pl->pbot->pnext = p;
00088  p->pnext = NULL;
00089  pl->pbot = p;
00090 
00091  }
00092 
00093 
00094 
00095 void
00096 append(              /* append pl1 to the end of pl2 */
00097        register PLIST  *pl1,
00098        register PLIST  *pl2
00099 )
00100 
00101 {
00102 
00103     if (pl1->ptop != NULL) {
00104         if (pl2->ptop != NULL)
00105             pl2->pbot->pnext = pl1->ptop;
00106         else
00107             pl2->ptop = pl1->ptop;
00108         pl2->pbot = pl1->pbot;
00109     }
00110 
00111 }
00112 
00113 
00114 
00115 void
00116 fargs(        /* free any arguments p has */
00117 register PRIMITIVE  *p
00118 )
00119 
00120 {
00121 
00122  if (p->args != NULL) {
00123     freestr(p->args);
00124     p->args = NULL;
00125     }
00126     
00127  }
00128 
00129 
00130 
00131 char *
00132 nextscan(            /* scan and advance through string */
00133        register char  *start,
00134        char  *format,
00135        char  *result
00136 )
00137 
00138 {
00139 
00140     if (start == NULL) return(NULL);
00141     
00142     while (isspace(*start)) start++;
00143     
00144     if (sscanf(start, format, result) != 1) return(NULL);
00145     
00146     while (*start && !isspace(*start)) start++;
00147     
00148     return(start);
00149 }
00150 
00151 
00152 void
00153 mcopy( /* copy p2 into p1 size n */
00154 register char  *p1,
00155 register char  *p2,
00156 register int  n
00157 )
00158 
00159 {
00160 
00161     while (n--)
00162        *p1++ = *p2++;
00163 
00164 }
00165