| 1 | 
greg | 
1.1 | 
#ifndef lint | 
| 2 | 
greg | 
1.5 | 
static const char       RCSid[] = "$Id: misc.c,v 1.4 2003/11/15 02:13:37 schorsch Exp $"; | 
| 3 | 
greg | 
1.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 *   Miscellaneous functions for meta-files | 
| 6 | 
  | 
  | 
 */ | 
| 7 | 
  | 
  | 
 | 
| 8 | 
  | 
  | 
 | 
| 9 | 
schorsch | 
1.4 | 
#include  "rtio.h" | 
| 10 | 
greg | 
1.1 | 
#include  "meta.h" | 
| 11 | 
  | 
  | 
 | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
char  coms[] = COML; | 
| 14 | 
  | 
  | 
 | 
| 15 | 
greg | 
1.5 | 
/* char  errmsg[128];   redundant to error.c in ../commmon */ | 
| 16 | 
greg | 
1.1 | 
 | 
| 17 | 
  | 
  | 
 | 
| 18 | 
  | 
  | 
 | 
| 19 | 
  | 
  | 
int | 
| 20 | 
schorsch | 
1.4 | 
comndx(         /* return index for command */ | 
| 21 | 
  | 
  | 
        register int  c | 
| 22 | 
  | 
  | 
) | 
| 23 | 
greg | 
1.1 | 
 | 
| 24 | 
  | 
  | 
{ | 
| 25 | 
  | 
  | 
 register char  *cp; | 
| 26 | 
  | 
  | 
 | 
| 27 | 
  | 
  | 
 if (!isalpha(c)) | 
| 28 | 
  | 
  | 
    return(-1); | 
| 29 | 
  | 
  | 
 | 
| 30 | 
  | 
  | 
 for (cp = coms; *cp; cp++) | 
| 31 | 
  | 
  | 
    if(*cp == c) | 
| 32 | 
  | 
  | 
       return(cp-coms); | 
| 33 | 
  | 
  | 
 | 
| 34 | 
  | 
  | 
 return(-1); | 
| 35 | 
  | 
  | 
 } | 
| 36 | 
  | 
  | 
 | 
| 37 | 
  | 
  | 
 | 
| 38 | 
  | 
  | 
 | 
| 39 | 
  | 
  | 
 | 
| 40 | 
  | 
  | 
 | 
| 41 | 
  | 
  | 
 | 
| 42 | 
  | 
  | 
PRIMITIVE  * | 
| 43 | 
schorsch | 
1.4 | 
pop(                    /* pop top off plist */ | 
| 44 | 
  | 
  | 
        register PLIST  *pl | 
| 45 | 
  | 
  | 
) | 
| 46 | 
greg | 
1.1 | 
 | 
| 47 | 
  | 
  | 
{ | 
| 48 | 
  | 
  | 
 register PRIMITIVE  *p; | 
| 49 | 
  | 
  | 
 | 
| 50 | 
  | 
  | 
 if ((p = pl->ptop) != NULL)  { | 
| 51 | 
  | 
  | 
    if ((pl->ptop = p->pnext) == NULL) | 
| 52 | 
  | 
  | 
       pl->pbot = NULL; | 
| 53 | 
  | 
  | 
    p->pnext = NULL; | 
| 54 | 
  | 
  | 
    } | 
| 55 | 
  | 
  | 
 | 
| 56 | 
  | 
  | 
 return(p); | 
| 57 | 
  | 
  | 
 } | 
| 58 | 
  | 
  | 
 | 
| 59 | 
  | 
  | 
 | 
| 60 | 
  | 
  | 
 | 
| 61 | 
schorsch | 
1.4 | 
void | 
| 62 | 
  | 
  | 
push(           /* push primitive onto plist */ | 
| 63 | 
  | 
  | 
        register PRIMITIVE  *p, | 
| 64 | 
  | 
  | 
        register PLIST  *pl | 
| 65 | 
  | 
  | 
) | 
| 66 | 
greg | 
1.1 | 
 | 
| 67 | 
  | 
  | 
{ | 
| 68 | 
  | 
  | 
 | 
| 69 | 
  | 
  | 
 if ((p->pnext = pl->ptop) == NULL) | 
| 70 | 
  | 
  | 
    pl->pbot = p; | 
| 71 | 
  | 
  | 
 pl->ptop = p; | 
| 72 | 
  | 
  | 
 | 
| 73 | 
  | 
  | 
 } | 
| 74 | 
  | 
  | 
 | 
| 75 | 
  | 
  | 
 | 
| 76 | 
  | 
  | 
 | 
| 77 | 
schorsch | 
1.4 | 
void | 
| 78 | 
  | 
  | 
add(            /* add primitive to plist */ | 
| 79 | 
  | 
  | 
        register PRIMITIVE  *p, | 
| 80 | 
  | 
  | 
        register PLIST  *pl | 
| 81 | 
  | 
  | 
) | 
| 82 | 
greg | 
1.1 | 
{ | 
| 83 | 
  | 
  | 
 | 
| 84 | 
  | 
  | 
 if (pl->ptop == NULL) | 
| 85 | 
  | 
  | 
    pl->ptop = p; | 
| 86 | 
  | 
  | 
 else | 
| 87 | 
  | 
  | 
    pl->pbot->pnext = p; | 
| 88 | 
  | 
  | 
 p->pnext = NULL; | 
| 89 | 
  | 
  | 
 pl->pbot = p; | 
| 90 | 
  | 
  | 
 | 
| 91 | 
  | 
  | 
 } | 
| 92 | 
  | 
  | 
 | 
| 93 | 
  | 
  | 
 | 
| 94 | 
  | 
  | 
 | 
| 95 | 
schorsch | 
1.4 | 
void | 
| 96 | 
  | 
  | 
append(         /* append pl1 to the end of pl2 */ | 
| 97 | 
  | 
  | 
        register PLIST  *pl1, | 
| 98 | 
  | 
  | 
        register PLIST  *pl2 | 
| 99 | 
  | 
  | 
) | 
| 100 | 
greg | 
1.1 | 
 | 
| 101 | 
  | 
  | 
{ | 
| 102 | 
  | 
  | 
 | 
| 103 | 
  | 
  | 
    if (pl1->ptop != NULL) { | 
| 104 | 
  | 
  | 
        if (pl2->ptop != NULL) | 
| 105 | 
  | 
  | 
            pl2->pbot->pnext = pl1->ptop; | 
| 106 | 
  | 
  | 
        else | 
| 107 | 
  | 
  | 
            pl2->ptop = pl1->ptop; | 
| 108 | 
  | 
  | 
        pl2->pbot = pl1->pbot; | 
| 109 | 
  | 
  | 
    } | 
| 110 | 
  | 
  | 
 | 
| 111 | 
  | 
  | 
} | 
| 112 | 
  | 
  | 
 | 
| 113 | 
  | 
  | 
 | 
| 114 | 
  | 
  | 
 | 
| 115 | 
schorsch | 
1.4 | 
void | 
| 116 | 
  | 
  | 
fargs(          /* free any arguments p has */ | 
| 117 | 
  | 
  | 
register PRIMITIVE  *p | 
| 118 | 
  | 
  | 
) | 
| 119 | 
greg | 
1.1 | 
 | 
| 120 | 
  | 
  | 
{ | 
| 121 | 
  | 
  | 
 | 
| 122 | 
  | 
  | 
 if (p->args != NULL) { | 
| 123 | 
  | 
  | 
    freestr(p->args); | 
| 124 | 
  | 
  | 
    p->args = NULL; | 
| 125 | 
  | 
  | 
    } | 
| 126 | 
  | 
  | 
     | 
| 127 | 
  | 
  | 
 } | 
| 128 | 
  | 
  | 
 | 
| 129 | 
  | 
  | 
 | 
| 130 | 
  | 
  | 
 | 
| 131 | 
  | 
  | 
char * | 
| 132 | 
schorsch | 
1.4 | 
nextscan(               /* scan and advance through string */ | 
| 133 | 
  | 
  | 
        register char  *start, | 
| 134 | 
  | 
  | 
        char  *format, | 
| 135 | 
  | 
  | 
        char  *result | 
| 136 | 
  | 
  | 
) | 
| 137 | 
greg | 
1.1 | 
 | 
| 138 | 
  | 
  | 
{ | 
| 139 | 
  | 
  | 
 | 
| 140 | 
  | 
  | 
    if (start == NULL) return(NULL); | 
| 141 | 
  | 
  | 
     | 
| 142 | 
  | 
  | 
    while (isspace(*start)) start++; | 
| 143 | 
  | 
  | 
     | 
| 144 | 
  | 
  | 
    if (sscanf(start, format, result) != 1) return(NULL); | 
| 145 | 
  | 
  | 
     | 
| 146 | 
  | 
  | 
    while (*start && !isspace(*start)) start++; | 
| 147 | 
  | 
  | 
     | 
| 148 | 
  | 
  | 
    return(start); | 
| 149 | 
  | 
  | 
} | 
| 150 | 
  | 
  | 
 | 
| 151 | 
  | 
  | 
 | 
| 152 | 
schorsch | 
1.4 | 
void | 
| 153 | 
  | 
  | 
mcopy(  /* copy p2 into p1 size n */ | 
| 154 | 
  | 
  | 
register char  *p1, | 
| 155 | 
  | 
  | 
register char  *p2, | 
| 156 | 
  | 
  | 
register int  n | 
| 157 | 
  | 
  | 
) | 
| 158 | 
greg | 
1.1 | 
 | 
| 159 | 
  | 
  | 
{ | 
| 160 | 
  | 
  | 
 | 
| 161 | 
  | 
  | 
    while (n--) | 
| 162 | 
  | 
  | 
        *p1++ = *p2++; | 
| 163 | 
  | 
  | 
 | 
| 164 | 
  | 
  | 
} | 
| 165 | 
  | 
  | 
 |