Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

misc.c File Reference

#include "defs.h"
#include "limits.h"

Go to the source code of this file.


Functions

int oneof_stg (Namep name, int stg, int mask)
int op_assign (int opcode)
char * Alloc (int n)
void cpn (register int n, register char *a, register char *b)
int eqn (register int n, register char *a, register char *b)
int cmpstr (register char *a, register char *b, ftnint la, ftnint lb)
chainp hookup (register chainp x, register chainp y)
Listblockmklist (chainp p)
chainp mkchain (register char *p, register chainp q)
chainp revchain (register chainp next)
char * addunder (register char *s)
char * copyn (register int n, register char *s)
char * copys (char *s)
ftnint convci (register int n, register char *s)
char * convic (ftnint n)
Namep mkname (register char *s)
Labelblockmklabel (ftnint l)
long newlabel (Void)
Labelblockexeclab (ftnint stateno)
Extsymmkext1 (char *f, char *s)
Extsymmkext (char *f, char *s)
Addrp builtin (int t, char *s, int dbi)
void add_extern_to_list (Addrp addr, chainp *list_store)
void frchain (register chainp *p)
void frexchain (register chainp *p)
tagptr cpblock (register int n, register char *p)
ftnint lmax (ftnint a, ftnint b)
ftnint lmin (ftnint a, ftnint b)
 maxtype (int t1, int t2)
int log_2 (ftnint n)
void frrpl (Void)
expptr callk (int type, char *name, chainp args)
expptr call4 (int type, char *name, expptr arg1, expptr arg2, expptr arg3, expptr arg4)
expptr call3 (int type, char *name, expptr arg1, expptr arg2, expptr arg3)
expptr call2 (int type, char *name, expptr arg1, expptr arg2)
expptr call1 (int type, char *name, expptr arg)
expptr call0 (int type, char *name)
Impldoblockmkiodo (chainp dospec, chainp list)
ptr ckalloc (register int n)
int isaddr (register expptr p)
int isstatic (register expptr p)
int addressable (register expptr p)
int isnegative_const (struct Constblock *cp)
void negate_const (Constp cp)
void ffilecopy (FILE *infp, FILE *outfp)
int in_vector (char *str, char **keywds, register int n)
int is_negatable (Constp Const)
void backup (char *fname, char *bname)
int struct_eq (chainp s1, chainp s2)

Variables

int callk_kludge

Function Documentation

void add_extern_to_list Addrp    addr,
chainp   list_store
 

Definition at line 643 of file misc.c.

References CHNULL, cpexpr(), mkchain(), Chain::nextp, TADDR, and UNAM_EXTERN.

Referenced by builtin().

00645 {
00646     chainp last = CHNULL;
00647     chainp list;
00648     int memno;
00649 
00650     if (list_store == (chainp *) NULL || addr == (Addrp) NULL)
00651         return;
00652 
00653     list = *list_store;
00654     memno = addr -> memno;
00655 
00656     for (;list; last = list, list = list -> nextp) {
00657         Addrp thisAddr = (Addrp) (list -> datap);
00658 
00659         if (thisAddr -> tag == TADDR && thisAddr -> uname_tag == UNAM_EXTERN &&
00660                 thisAddr -> memno == memno)
00661             return;
00662     } /* for */
00663 
00664     if (*list_store == CHNULL)
00665         *list_store = mkchain((char *)cpexpr((expptr)addr), CHNULL);
00666     else
00667         last->nextp = mkchain((char *)cpexpr((expptr)addr), CHNULL);
00668 
00669 } /* add_extern_to_list */

int addressable register expptr    p
 

Definition at line 1047 of file misc.c.

References TADDR, Listblock::tag, and TCONST.

Referenced by exarif(), Inline(), putcx1(), and putmnmx().

01049 {
01050         switch(p->tag)
01051         {
01052         case TCONST:
01053                 return(YES);
01054 
01055         case TADDR:
01056                 return( addressable(p->addrblock.memoffset) );
01057 
01058         default:
01059                 return(NO);
01060         }
01061 }

char* addunder register char *    s
 

Definition at line 285 of file misc.c.

References c, and i.

Referenced by dobss(), mkaddr(), mkfunct(), and newentry().

00287 {
00288         register int c, i, j;
00289         char *s0 = s;
00290 
00291         i = j = 0;
00292         while(c = *s++)
00293                 if (c == '_')
00294                         i++, j++;
00295                 else
00296                         i = 0;
00297         if (!i) {
00298                 *s-- = 0;
00299                 *s = '_';
00300                 }
00301         else if (j == 2)
00302                 s[-2] = 0;
00303         return( s0 );
00304         }

char* Alloc int    n
 

Definition at line 85 of file misc.c.

References Fatal(), and malloc.

00089 {
00090         char errbuf[32];
00091         register char *rv;
00092 
00093         rv = (char*) malloc(n);
00094         if (!rv) {
00095                 sprintf(errbuf, "malloc(%d) failure!", n);
00096                 Fatal(errbuf);
00097                 }
00098         return rv;
00099         }

void backup char *    fname,
char *    bname
 

Definition at line 1266 of file misc.c.

References ffilecopy(), and warn1().

Referenced by list_init_data().

01268 {
01269         FILE *b, *f;
01270         static char couldnt[] = "Couldn't open %.80s";
01271 
01272         if (!(f = fopen(fname, binread))) {
01273                 warn1(couldnt, fname);
01274                 return;
01275                 }
01276         if (!(b = fopen(bname, binwrite))) {
01277                 warn1(couldnt, bname);
01278                 return;
01279                 }
01280         ffilecopy(f, b);
01281         fclose(f);
01282         fclose(b);
01283         }

Addrp builtin int    t,
char *    s,
int    dbi
 

Definition at line 600 of file misc.c.

References add_extern_to_list(), ALLOC, CLPROC, Addrblock::dbl_builtin, errstr(), Extsym::extstg, Addrblock::memno, mkext(), STGEXT, STGUNKNOWN, TADDR, Addrblock::tag, UNAM_EXTERN, used_builtins, Addrblock::vclass, Addrblock::vstg, and Addrblock::vtype.

Referenced by callk(), intraddr(), intrcall(), mkfunct(), and NI_do().

00602 {
00603         register Extsym *p;
00604         register Addrp q;
00605         extern chainp used_builtins;
00606 
00607         p = mkext(s,s);
00608         if(p->extstg == STGUNKNOWN)
00609                 p->extstg = STGEXT;
00610         else if(p->extstg != STGEXT)
00611         {
00612                 errstr("improper use of builtin %s", s);
00613                 return(0);
00614         }
00615 
00616         q = ALLOC(Addrblock);
00617         q->tag = TADDR;
00618         q->vtype = t;
00619         q->vclass = CLPROC;
00620         q->vstg = STGEXT;
00621         q->memno = p - extsymtab;
00622         q->dbl_builtin = dbi;
00623 
00624 /* A NULL pointer here tells you to use   memno   to check the external
00625    symbol table */
00626 
00627         q -> uname_tag = UNAM_EXTERN;
00628 
00629 /* Add to the list of used builtins */
00630 
00631         if (dbi >= 0)
00632                 add_extern_to_list (q, &used_builtins);
00633         return(q);
00634 }

expptr call0 int    type,
char *    name
 

Definition at line 926 of file misc.c.

References callk(), CHNULL, and name.

Referenced by doio().

00928 {
00929         return( callk(type, name, CHNULL) );
00930 }

expptr call1 int    type,
char *    name,
expptr    arg
 

Definition at line 913 of file misc.c.

References callk(), CHNULL, mkchain(), mklist(), and name.

Referenced by dofclose(), dofinquire(), dofmove(), dofopen(), exstop(), and startrw().

00915 {
00916         return( callk(type,name, (chainp)mklist(mkchain((char *)arg,CHNULL)) ));
00917 }

expptr call2 int    type,
char *    name,
expptr    arg1,
expptr    arg2
 

Definition at line 894 of file misc.c.

References callk(), CHNULL, mkchain(), mklist(), and name.

Referenced by fixexpr(), mkpower(), putchcmp(), putcheq(), and putio().

00896 {
00897         struct Listblock *args;
00898 
00899         args = mklist( mkchain((char *)arg1, mkchain((char *)arg2, CHNULL) ) );
00900         return( callk(type,name, (chainp)args) );
00901 }

expptr call3 int    type,
char *    name,
expptr    arg1,
expptr    arg2,
expptr    arg3
 

Definition at line 872 of file misc.c.

References callk(), CHNULL, mkchain(), mklist(), and name.

Referenced by putio().

00874 {
00875         struct Listblock *args;
00876         args = mklist( mkchain((char *)arg1,
00877                         mkchain((char *)arg2,
00878                                 mkchain((char *)arg3, CHNULL) ) ) );
00879         return( callk(type, name, (chainp)args) );
00880 }

expptr call4 int    type,
char *    name,
expptr    arg1,
expptr    arg2,
expptr    arg3,
expptr    arg4
 

Definition at line 849 of file misc.c.

References callk(), CHNULL, mkchain(), mklist(), and name.

Referenced by putcat(), putio(), and subcheck().

00851 {
00852         struct Listblock *args;
00853         args = mklist( mkchain((char *)arg1,
00854                         mkchain((char *)arg2,
00855                                 mkchain((char *)arg3,
00856                                         mkchain((char *)arg4, CHNULL)) ) ) );
00857         return( callk(type, name, (chainp)args) );
00858 }

expptr callk int    type,
char *    name,
chainp    args
 

Definition at line 825 of file misc.c.

References builtin(), callk_kludge, Expression::exprblock, mkexpr(), name, OPCALL, and Exprblock::vtype.

Referenced by call0(), call1(), call2(), call3(), and call4().

00827 {
00828         register expptr p;
00829 
00830         p = mkexpr(OPCALL,
00831                 (expptr)builtin(callk_kludge ? callk_kludge : type, name, 0),
00832                 (expptr)args);
00833         p->exprblock.vtype = type;
00834         return(p);
00835 }

ptr ckalloc register int    n
 

Definition at line 963 of file misc.c.

References calloc, and Fatal().

Referenced by argsort(), consconv(), count_args(), cpblock(), fileinit(), fold(), initkey(), main(), mkstrcon(), putentries(), and set_tmp_names().

00965 {
00966         register ptr p;
00967         p = (ptr)calloc(1, (unsigned) n);
00968         if (p || !n)
00969                 return(p);
00970         fprintf(stderr, "failing to get %d bytes\n",n);
00971         Fatal("out of memory");
00972         /* NOT REACHED */ return 0;
00973 }

int cmpstr register char *    a,
register char *    b,
ftnint    la,
ftnint    lb
 

Definition at line 145 of file misc.c.

References a.

Referenced by fold().

00148 {
00149         register char *aend, *bend;
00150         aend = a + la;
00151         bend = b + lb;
00152 
00153 
00154         if(la <= lb)
00155         {
00156                 while(a < aend)
00157                         if(*a != *b)
00158                                 return( *a - *b );
00159                         else
00160                         {
00161                                 ++a;
00162                                 ++b;
00163                         }
00164 
00165                 while(b < bend)
00166                         if(*b != ' ')
00167                                 return(' ' - *b);
00168                         else
00169                                 ++b;
00170         }
00171 
00172         else
00173         {
00174                 while(b < bend)
00175                         if(*a != *b)
00176                                 return( *a - *b );
00177                         else
00178                         {
00179                                 ++a;
00180                                 ++b;
00181                         }
00182                 while(a < aend)
00183                         if(*a != ' ')
00184                                 return(*a - ' ');
00185                         else
00186                                 ++a;
00187         }
00188         return(0);
00189 }

ftnint convci register int    n,
register char *    s
 

Definition at line 352 of file misc.c.

References err, and n0.

Referenced by yyparse().

00354 {
00355         ftnint sum, t;
00356         char buff[100], *s0;
00357         int n0;
00358 
00359         s0 = s;
00360         n0 = n;
00361         sum = 0;
00362         while(n-- > 0) {
00363                 /* sum = 10*sum + (*s++ - '0'); */
00364                 t = *s++ - '0';
00365                 if (sum > LONG_MAX/10) {
00366  ovfl:
00367                         if (n0 > 60)
00368                                 n0 = 60;
00369                         sprintf(buff, "integer constant %.*s truncated.",
00370                                 n0, s0);
00371                         err(buff);
00372                         return LONG_MAX;
00373                         }
00374                 sum *= 10;
00375                 if (sum > LONG_MAX - t)
00376                         goto ovfl;
00377                 sum += t;
00378                 }
00379         return(sum);
00380         }

char* convic ftnint    n
 

Definition at line 389 of file misc.c.

Referenced by endproc(), execlab(), exstop(), and yyparse().

00391 {
00392         static char s[20];
00393         register char *t;
00394 
00395         s[19] = '\0';
00396         t = s+19;
00397 
00398         do      {
00399                 *--t = '0' + n%10;
00400                 n /= 10;
00401         } while(n > 0);
00402 
00403         return(t);
00404 }

char* copyn register int    n,
register char *    s
 

Definition at line 315 of file misc.c.

References Alloc.

Referenced by copys(), cpexpr(), doinclude(), exstop(), and yyparse().

00317 {
00318         register char *p, *q;
00319 
00320         p = q = (char *) Alloc(n);
00321         while(--n >= 0)
00322                 *q++ = *s++;
00323         return(p);
00324 }

char* copys char *    s
 

Definition at line 335 of file misc.c.

References copyn().

Referenced by c_name(), main(), and putconst().

00337 {
00338         return( copyn( strlen(s)+1 , s) );
00339 }

tagptr cpblock register int    n,
register char *    p
 

Definition at line 721 of file misc.c.

References ckalloc().

Referenced by cpexpr().

00723 {
00724         register ptr q;
00725 
00726         memcpy((char *)(q = ckalloc(n)), (char *)p, n);
00727         return( (tagptr) q);
00728 }

void cpn register int    n,
register char *    a,
register char *    b
 

Definition at line 108 of file misc.c.

References a.

Referenced by copy_data().

00110 {
00111         while(--n >= 0)
00112                 *b++ = *a++;
00113 }

int eqn register int    n,
register char *    a,
register char *    b
 

Definition at line 123 of file misc.c.

References a.

Referenced by AFNI_setenv(), gettok(), main(), and PBAR_define_bigmap().

00125 {
00126         while(--n >= 0)
00127                 if(*a++ != *b++)
00128                         return(NO);
00129         return(YES);
00130 }

struct Labelblock* execlab ftnint    stateno
 

Definition at line 519 of file misc.c.

References Labelblock::blklevel, convic(), err, execerr(), Labelblock::labdefined, LABEXEC, LABFORMAT, Labelblock::labinacc, Labelblock::labtype, mklabel(), NO, and warn1().

Referenced by endio(), endioctl(), putiocall(), and yyparse().

00521 {
00522         register struct Labelblock *lp;
00523 
00524         if(lp = mklabel(stateno))
00525         {
00526                 if(lp->labinacc)
00527                         warn1("illegal branch to inner block, statement label %s",
00528                             convic(stateno) );
00529                 else if(lp->labdefined == NO)
00530                         lp->blklevel = blklevel;
00531                 if(lp->labtype == LABFORMAT)
00532                         err("may not branch to a format");
00533                 else
00534                         lp->labtype = LABEXEC;
00535         }
00536         else
00537                 execerr("illegal label %s", convic(stateno));
00538 
00539         return(lp);
00540 }

void ffilecopy FILE *    infp,
FILE *    outfp
 

Definition at line 1172 of file misc.c.

References c.

Referenced by backup(), main(), and start_formatting().

01174 {
01175     while (!feof (infp)) {
01176         register c = getc (infp);
01177         if (!feof (infp))
01178         putc (c, outfp);
01179     } /* while */
01180 } /* ffilecopy */

void frchain register chainp   p
 

Definition at line 677 of file misc.c.

References Chain::nextp.

Referenced by argsort(), atype_squawk(), do_p1_head(), doiolist(), enddcl(), exdo(), frdata(), frexpr(), hashclear(), intrcall(), length_comp(), mkprim(), out_call(), p1_expr(), pop_datastack(), procinit(), prolog(), putentries(), putmnmx(), stfcall(), wr_equiv_init(), wr_one_init(), yyparse(), and zap_changes().

00679 {
00680         register chainp q;
00681 
00682         if(p==0 || *p==0)
00683                 return;
00684 
00685         for(q = *p; q->nextp ; q = q->nextp)
00686                 ;
00687         q->nextp = chains;
00688         chains = *p;
00689         *p = 0;
00690 }

void frexchain register chainp   p
 

Definition at line 697 of file misc.c.

References Chain::datap, frexpr(), Chain::nextp, and r.

Referenced by procinit().

00699 {
00700         register chainp q, r;
00701 
00702         if (q = *p) {
00703                 for(;;q = r) {
00704                         frexpr((expptr)q->datap);
00705                         if (!(r = q->nextp))
00706                                 break;
00707                         }
00708                 q->nextp = chains;
00709                 chains = *p;
00710                 *p = 0;
00711                 }
00712         }

void frrpl Void   
 

Definition at line 800 of file misc.c.

References charptr, free, and Rplblock::rplnextp.

Referenced by yyparse().

00801 {
00802         struct Rplblock *rp;
00803 
00804         while(rpllist)
00805         {
00806                 rp = rpllist->rplnextp;
00807                 free( (charptr) rpllist);
00808                 rpllist = rp;
00809         }
00810 }

chainp hookup register chainp    x,
register chainp    y
 

Definition at line 200 of file misc.c.

References Chain::nextp, and p.

Referenced by putcall(), and yyparse().

00202 {
00203         register chainp p;
00204 
00205         if(x == NULL)
00206                 return(y);
00207 
00208         for(p = x ; p->nextp ; p = p->nextp)
00209                 ;
00210         p->nextp = y;
00211         return(x);
00212 }

int in_vector char *    str,
char **    keywds,
register int    n
 

Definition at line 1195 of file misc.c.

References n1.

Referenced by mkname().

01197 {
01198         register char **K = keywds;
01199         register int n1, t;
01200 
01201         do {
01202                 n1 = n >> 1;
01203                 if (!(t = strcmp(str, K[n1])))
01204                         return K - keywds + n1;
01205                 if (t < 0)
01206                         n = n1;
01207                 else {
01208                         n -= ++n1;
01209                         K += n1;
01210                         }
01211                 }
01212                 while(n > 0);
01213 
01214         return -1;
01215         } /* in_vector */

int is_negatable Constp    Const
 

Definition at line 1223 of file misc.c.

References BIGGEST_CHAR, BIGGEST_LONG, BIGGEST_SHORT, retval(), and TYQUAD.

Referenced by mkexpr(), and output_binary().

01225 {
01226     int retval = 0;
01227     if (Const != (Constp) NULL)
01228         switch (Const -> vtype) {
01229             case TYINT1:
01230                 retval = Const -> Const.ci >= -BIGGEST_CHAR;
01231                 break;
01232             case TYSHORT:
01233                 retval = Const -> Const.ci >= -BIGGEST_SHORT;
01234                 break;
01235             case TYLONG:
01236 #ifdef TYQUAD
01237             case TYQUAD:
01238 #endif
01239                 retval = Const -> Const.ci >= -BIGGEST_LONG;
01240                 break;
01241             case TYREAL:
01242             case TYDREAL:
01243             case TYCOMPLEX:
01244             case TYDCOMPLEX:
01245                 retval = 1;
01246                 break;
01247             case TYLOGICAL1:
01248             case TYLOGICAL2:
01249             case TYLOGICAL:
01250             case TYCHAR:
01251             case TYSUBR:
01252             default:
01253                 retval = 0;
01254                 break;
01255         } /* switch */
01256 
01257     return retval;
01258 } /* is_negatable */

int isaddr register expptr    p
 

Definition at line 981 of file misc.c.

References OPASSIGN, OPASSIGNI, OPBITANDEQ, OPBITOREQ, OPBITXOREQ, OPCOMMA, OPLSHIFTEQ, OPMINUSEQ, OPMODEQ, OPPLUSEQ, OPRSHIFTEQ, OPSLASHEQ, TADDR, Listblock::tag, and TEXPR.

00983 {
00984         if(p->tag == TADDR)
00985                 return(YES);
00986         if(p->tag == TEXPR)
00987                 switch(p->exprblock.opcode)
00988                 {
00989                 case OPCOMMA:
00990                         return( isaddr(p->exprblock.rightp) );
00991 
00992                 case OPASSIGN:
00993                 case OPASSIGNI:
00994                 case OPPLUSEQ:
00995                 case OPMINUSEQ:
00996                 case OPSLASHEQ:
00997                 case OPMODEQ:
00998                 case OPLSHIFTEQ:
00999                 case OPRSHIFTEQ:
01000                 case OPBITANDEQ:
01001                 case OPBITXOREQ:
01002                 case OPBITOREQ:
01003                         return( isaddr(p->exprblock.leftp) );
01004                 }
01005         return(NO);
01006 }

int isnegative_const struct Constblock   cp
 

Definition at line 1072 of file misc.c.

References Constant::cd, Constant::cds, Constblock::Const, retval(), TYQUAD, and Constblock::vstg.

Referenced by output_binary().

01074 {
01075     int retval;
01076 
01077     if (cp == NULL)
01078         return 0;
01079 
01080     switch (cp -> vtype) {
01081         case TYINT1:
01082         case TYSHORT:
01083         case TYLONG:
01084 #ifdef TYQUAD
01085         case TYQUAD:
01086 #endif
01087             retval = cp -> Const.ci < 0;
01088             break;
01089         case TYREAL:
01090         case TYDREAL:
01091                 retval = cp->vstg ? *cp->Const.cds[0] == '-'
01092                                   :  cp->Const.cd[0] < 0.0;
01093             break;
01094         default:
01095 
01096             retval = 0;
01097             break;
01098     } /* switch */
01099 
01100     return retval;
01101 } /* isnegative_const */

int isstatic register expptr    p
 

Definition at line 1015 of file misc.c.

References ISCONST, MSKSTATIC, ONEOF, TADDR, Listblock::tag, TCONST, and useauto.

Referenced by startrw().

01017 {
01018         extern int useauto;
01019         if(p->headblock.vleng && !ISCONST(p->headblock.vleng))
01020                 return(NO);
01021 
01022         switch(p->tag)
01023         {
01024         case TCONST:
01025                 return(YES);
01026 
01027         case TADDR:
01028                 if(ONEOF(p->addrblock.vstg,MSKSTATIC) &&
01029                     ISCONST(p->addrblock.memoffset) && !useauto)
01030                         return(YES);
01031 
01032         default:
01033                 return(NO);
01034         }
01035 }

ftnint lmax ftnint    a,
ftnint    b
 

Definition at line 738 of file misc.c.

References a.

Referenced by doequiv(), eqveqv(), main(), SUMA_Find_IminImax(), and SUMA_Find_IminImax_Avg().

00740 {
00741         return( a>b ? a : b);
00742 }

ftnint lmin ftnint    a,
ftnint    b
 

Definition at line 750 of file misc.c.

References a.

Referenced by doequiv(), eqveqv(), SUMA_Find_IminImax(), and SUMA_Find_IminImax_Avg().

00752 {
00753         return(a < b ? a : b);
00754 }

int log_2 ftnint    n
 

Definition at line 783 of file misc.c.

Referenced by putx().

00785 {
00786         int k;
00787 
00788         /* trick based on binary representation */
00789 
00790         if(n<=0 || (n & (n-1))!=0)
00791                 return(-1);
00792 
00793         for(k = 0 ;  n >>= 1  ; ++k)
00794                 ;
00795         return(k);
00796 }

maxtype int    t1,
int    t2
 

Definition at line 764 of file misc.c.

Referenced by cast_args(), cktype(), fold(), intrcall(), and mkpower().

00766 {
00767         int t;
00768 
00769         t = t1 >= t2 ? t1 : t2;
00770         if(t==TYCOMPLEX && (t1==TYDREAL || t2==TYDREAL) )
00771                 t = TYDCOMPLEX;
00772         return(t);
00773 }

chainp mkchain register char *    p,
register chainp    q
 

Definition at line 239 of file misc.c.

References ALLOC, Chain::datap, Chain::nextp, and r.

Referenced by add_extern_to_list(), argsort(), call1(), call2(), call3(), call4(), cpexpr(), data_value(), declare_new_addr(), do_init_data(), do_p1_list(), docommon(), doentry(), doequiv(), exassign(), fmtname(), frtemp(), I_args(), incomm(), intrcall(), length_comp(), mkfunct(), mkstfunct(), p1_label(), pad_common(), putcall(), subskept(), typekludge(), wr_equiv_init(), and yyparse().

00241 {
00242         register chainp r;
00243 
00244         if(chains)
00245         {
00246                 r = chains;
00247                 chains = chains->nextp;
00248         }
00249         else
00250                 r = ALLOC(Chain);
00251 
00252         r->datap = p;
00253         r->nextp = q;
00254         return(r);
00255 }

Extsym* mkext char *    f,
char *    s
 

Definition at line 584 of file misc.c.

References errstr(), Extsym::extstg, mkext1(), and STGCOMMON.

Referenced by builtin(), dobss(), mkaddr(), mkfunct(), and newentry().

00586 {
00587         Extsym *e = mkext1(f, s);
00588         if (e->extstg == STGCOMMON)
00589                 errstr("%.52s cannot be a subprogram: it is a common block.",f);
00590         return e;
00591         }

Extsym* mkext1 char *    f,
char *    s
 

Definition at line 551 of file misc.c.

References Extsym::cextname, gmem(), many(), and STGUNKNOWN.

Referenced by comblock(), comlen(), mkext(), and Pfile().

00553 {
00554         Extsym *p;
00555 
00556         for(p = extsymtab ; p<nextext ; ++p)
00557                 if(!strcmp(s,p->cextname))
00558                         return( p );
00559 
00560         if(nextext >= lastext)
00561                 many("external symbols", 'x', maxext);
00562 
00563         nextext->fextname = strcpy(gmem(strlen(f)+1,0), f);
00564         nextext->cextname = f == s
00565                                 ? nextext->fextname
00566                                 : strcpy(gmem(strlen(s)+1,0), s);
00567         nextext->extstg = STGUNKNOWN;
00568         nextext->extp = 0;
00569         nextext->allextp = 0;
00570         nextext->extleng = 0;
00571         nextext->maxleng = 0;
00572         nextext->extinit = 0;
00573         nextext->curno = nextext->maxno = 0;
00574         return( nextext++ );
00575 }

struct Impldoblock* mkiodo chainp    dospec,
chainp    list
 

Definition at line 940 of file misc.c.

References ALLOC, Impldoblock::datalist, Impldoblock::impdospec, Impldoblock::tag, and TIMPLDO.

Referenced by yyparse().

00942 {
00943         register struct Impldoblock *q;
00944 
00945         q = ALLOC(Impldoblock);
00946         q->tag = TIMPLDO;
00947         q->impdospec = dospec;
00948         q->datalist = list;
00949         return(q);
00950 }

struct Labelblock* mklabel ftnint    l
 

Definition at line 478 of file misc.c.

References Labelblock::blklevel, Labelblock::fmtlabused, Labelblock::fmtstring, Labelblock::labdefined, Labelblock::labelno, Labelblock::labinacc, Labelblock::labtype, LABUNKNOWN, Labelblock::labused, many(), newlabel(), NO, and Labelblock::stateno.

Referenced by execlab(), newiolabel(), startrw(), and yyparse().

00480 {
00481         register struct Labelblock *lp;
00482 
00483         if(l <= 0)
00484                 return(NULL);
00485 
00486         for(lp = labeltab ; lp < highlabtab ; ++lp)
00487                 if(lp->stateno == l)
00488                         return(lp);
00489 
00490         if(++highlabtab > labtabend)
00491                 many("statement labels", 's', maxstno);
00492 
00493         lp->stateno = l;
00494         lp->labelno = (int)newlabel();
00495         lp->blklevel = 0;
00496         lp->labused = NO;
00497         lp->fmtlabused = NO;
00498         lp->labdefined = NO;
00499         lp->labinacc = NO;
00500         lp->labtype = LABUNKNOWN;
00501         lp->fmtstring = 0;
00502         return(lp);
00503 }

struct Listblock* mklist chainp    p
 

Definition at line 221 of file misc.c.

References ALLOC, Listblock::listp, Listblock::tag, and TLIST.

Referenced by call1(), call2(), call3(), call4(), putcall(), and yyparse().

00223 {
00224         register struct Listblock *q;
00225 
00226         q = ALLOC(Listblock);
00227         q->tag = TLIST;
00228         q->listp = p;
00229         return(q);
00230 }

Namep mkname register char *    s
 

Definition at line 416 of file misc.c.

References ALLOC, c, errext(), Hashentry::hashval, i, in_vector(), many(), mem(), TNAME, and Hashentry::varp.

Referenced by doentry(), entrypt(), startproc(), and yyparse().

00418 {
00419         struct Hashentry *hp;
00420         register Namep q;
00421         register int c, hash, i;
00422         register char *t;
00423         char *s0;
00424         char errbuf[64];
00425 
00426         hash = i = 0;
00427         s0 = s;
00428         while(c = *s++) {
00429                 hash += c;
00430                 if (c == '_')
00431                         i = 2;
00432                 }
00433         if (!i && in_vector(s0,c_keywords,n_keywords) >= 0)
00434                 i = 2;
00435         hash %= maxhash;
00436 
00437 /* Add the name to the closed hash table */
00438 
00439         hp = hashtab + hash;
00440 
00441         while(q = hp->varp)
00442                 if( hash == hp->hashval && !strcmp(s0,q->fvarname) )
00443                         return(q);
00444                 else if(++hp >= lasthash)
00445                         hp = hashtab;
00446 
00447         if(++nintnames >= maxhash-1)
00448                 many("names", 'n', maxhash);    /* Fatal error */
00449         hp->varp = q = ALLOC(Nameblock);
00450         hp->hashval = hash;
00451         q->tag = TNAME; /* TNAME means the tag type is NAME */
00452         c = s - s0;
00453         if (c > 7 && noextflag) {
00454                 sprintf(errbuf, "\"%.35s%s\" over 6 characters long", s0,
00455                         c > 36 ? "..." : "");
00456                 errext(errbuf);
00457                 }
00458         q->fvarname = strcpy(mem(c,0), s0);
00459         t = q->cvarname = mem(c + i + 1, 0);
00460         s = s0;
00461         /* add __ to the end of any name containing _ and to any C keyword */
00462         while(*t = *s++)
00463                 t++;
00464         if (i) {
00465                 do *t++ = '_';
00466                         while(--i > 0);
00467                 *t = 0;
00468                 }
00469         return(q);
00470 }

void negate_const Constp    cp
 

Definition at line 1108 of file misc.c.

References Constant::cd, Constant::cds, Constblock::Const, erri(), TYQUAD, and Constblock::vstg.

Referenced by output_binary().

01110 {
01111     if (cp == (struct Constblock *) NULL)
01112         return;
01113 
01114     switch (cp -> vtype) {
01115         case TYINT1:
01116         case TYSHORT:
01117         case TYLONG:
01118 #ifdef TYQUAD
01119         case TYQUAD:
01120 #endif
01121             cp -> Const.ci = - cp -> Const.ci;
01122             break;
01123         case TYCOMPLEX:
01124         case TYDCOMPLEX:
01125                 if (cp->vstg)
01126                     switch(*cp->Const.cds[1]) {
01127                         case '-':
01128                                 ++cp->Const.cds[1];
01129                                 break;
01130                         case '0':
01131                                 break;
01132                         default:
01133                                 --cp->Const.cds[1];
01134                         }
01135                 else
01136                         cp->Const.cd[1] = -cp->Const.cd[1];
01137                 /* no break */
01138         case TYREAL:
01139         case TYDREAL:
01140                 if (cp->vstg)
01141                     switch(*cp->Const.cds[0]) {
01142                         case '-':
01143                                 ++cp->Const.cds[0];
01144                                 break;
01145                         case '0':
01146                                 break;
01147                         default:
01148                                 --cp->Const.cds[0];
01149                         }
01150                 else
01151                         cp->Const.cd[0] = -cp->Const.cd[0];
01152             break;
01153         case TYCHAR:
01154         case TYLOGICAL1:
01155         case TYLOGICAL2:
01156         case TYLOGICAL:
01157             erri ("negate_const:  can't negate type '%d'", cp -> vtype);
01158             break;
01159         default:
01160             erri ("negate_const:  bad type '%d'",
01161                     cp -> vtype);
01162             break;
01163     } /* switch */
01164 } /* negate_const */

long newlabel Void   
 

Definition at line 506 of file misc.c.

Referenced by doentry(), doiolist(), fmtstmt(), mklabel(), and putconst().

00507 {
00508         return ++lastlabno;
00509 }

int oneof_stg Namep    name,
int    stg,
int    mask
 

Definition at line 34 of file misc.c.

References M, name, ONEOF, STGCOMMON, and STGEQUIV.

Referenced by out_addr(), out_call(), and p1_addr().

00036 {
00037         if (stg == STGCOMMON && name) {
00038                 if ((mask & M(STGEQUIV)))
00039                         return name->vcommequiv;
00040                 if ((mask & M(STGCOMMON)))
00041                         return !name->vcommequiv;
00042                 }
00043         return ONEOF(stg, mask);
00044         }

int op_assign int    opcode
 

Definition at line 55 of file misc.c.

References erri(), OPBITAND, OPBITANDEQ, OPBITOR, OPBITOREQ, OPBITXOR, OPBITXOREQ, OPLSHIFT, OPLSHIFTEQ, OPMINUS, OPMINUSEQ, OPMOD, OPMODEQ, OPPLUS, OPPLUSEQ, OPRSHIFT, OPRSHIFTEQ, OPSLASH, OPSLASHEQ, OPSTAR, OPSTAREQ, and retval().

Referenced by expr_out().

00057 {
00058     int retval = -1;
00059 
00060     switch (opcode) {
00061         case OPPLUS: retval = OPPLUSEQ; break;
00062         case OPMINUS: retval = OPMINUSEQ; break;
00063         case OPSTAR: retval = OPSTAREQ; break;
00064         case OPSLASH: retval = OPSLASHEQ; break;
00065         case OPMOD: retval = OPMODEQ; break;
00066         case OPLSHIFT: retval = OPLSHIFTEQ; break;
00067         case OPRSHIFT: retval = OPRSHIFTEQ; break;
00068         case OPBITAND: retval = OPBITANDEQ; break;
00069         case OPBITXOR: retval = OPBITXOREQ; break;
00070         case OPBITOR: retval = OPBITOREQ; break;
00071         default:
00072             erri ("op_assign:  bad opcode '%d'", opcode);
00073             break;
00074     } /* switch */
00075 
00076     return retval;
00077 } /* op_assign */

chainp revchain register chainp    next
 

Definition at line 262 of file misc.c.

References Chain::nextp.

Referenced by docommon(), enddcl(), entrypt(), fix_entry_returns(), I_args(), length_comp(), putcall(), wr_common_decls(), wr_equiv_init(), wr_one_init(), write_assigned_fmts(), write_char_init(), write_ioblocks(), and yyparse().

00264 {
00265         register chainp p, prev = 0;
00266 
00267         while(p = next) {
00268                 next = p->nextp;
00269                 p->nextp = prev;
00270                 prev = p;
00271                 }
00272         return prev;
00273         }

int struct_eq chainp    s1,
chainp    s2
 

Definition at line 1295 of file misc.c.

References CHNULL, Nameblock::fvarname, Dimblock::nelt, Chain::nextp, NO, TCONST, TNAME, v1, Nameblock::vclass, Nameblock::vdim, Nameblock::vtype, and YES.

Referenced by docommon().

01297 {
01298     struct Dimblock *d1, *d2;
01299     Constp cp1, cp2;
01300 
01301     if (s1 == CHNULL && s2 == CHNULL)
01302         return YES;
01303     for(; s1 && s2; s1 = s1->nextp, s2 = s2->nextp) {
01304         register Namep v1 = (Namep) s1 -> datap;
01305         register Namep v2 = (Namep) s2 -> datap;
01306 
01307         if (v1 == (Namep) NULL || v1 -> tag != TNAME ||
01308                 v2 == (Namep) NULL || v2 -> tag != TNAME)
01309             return NO;
01310 
01311         if (v1->vtype != v2->vtype || v1->vclass != v2->vclass
01312                 || strcmp(v1->fvarname, v2->fvarname))
01313             return NO;
01314 
01315         /* compare dimensions (needed for comparing COMMON blocks) */
01316 
01317         if (d1 = v1->vdim) {
01318                 if (!(cp1 = (Constp)d1->nelt) || cp1->tag != TCONST
01319                 ||  !(d2 = v2->vdim)
01320                 ||  !(cp2 = (Constp)d2->nelt) || cp2->tag != TCONST
01321                 ||  cp1->Const.ci != cp2->Const.ci)
01322                         return NO;
01323                 }
01324         else if (v2->vdim)
01325                 return NO;
01326     } /* while s1 != CHNULL && s2 != CHNULL */
01327 
01328     return s1 == CHNULL && s2 == CHNULL;
01329 } /* struct_eq */

Variable Documentation

int callk_kludge
 

Definition at line 816 of file misc.c.

Referenced by callk(), and mkpower().

 

Powered by Plone

This site conforms to the following standards: