#include #include #include "dutil.h" #include "objects.h" extern int debug_object_flag; #define debug debug_object_flag Func last_func=NULL; struct menu_struct *last_menu = NULL; /************************************************************************** * new_func() * allocate a new function structure **************************************************************************/ Func new_func() { Func p; int i,k; p = (Func )ckalloc(sizeof(struct func_struct)); p->prev = NULL; p->exec = NULL; p->exec2 = NULL; p->clean = NULL; p->final = NULL; p->menu_entry = NULL; p->nif = 0; p->nik = 0; p->nof = 0; p->nok = 0; p->mode = TEMP; p->bground = 0; p->recur = 0; p->set_range = 0; p->query = 0; p->pidfile = NULL; /* to generate networks */ p->subnet = NULL; p->branch = NULL; p->label = NULL; p->net = NULL; p->called_net = 0; p->call = NULL; p->direc = NULL; p->inputfile = NULL; for(i=0;iunique[i] = 0; p->inobjtype[i] = NULL; p->selection[i] = NULL; p->inkey[i] = 0; p->type[i] = 0; p->infilename[i] = NULL; p->infilename2[i] = NULL; p->infilename3[i] = NULL; p->infile[i] = 0; p->inrange[i] = 0; p->prompt[i] = NULL; p->in[i] = NULL; p->ninxkey[i] = 1; for(k=0;kinxkey[i][k] = 0; p->outkey[i] = 0; p->outobjtype[i] = NULL; p->outtype[i] = 0; p->overwr[i] = 0; p->all[i] = 0; p->tail[i] = 0; p->outfilename[i] = NULL; p->outfilename2[i] = NULL; p->outfilename3[i] = NULL; p->host[i] = NULL; p->port[i] = 0; p->outfile[i] = 0; p->out[i] = NULL; p->outrange[i] = 0; p->noutxkey[i] = 0; for(k=0;koutxkey[i][k] = 0; } return p; } /************************************************************************** * new_table_func() * allocate a new function structure * the table is maintained so that a search starting with * last_func will give the functions in the order they are defined * **************************************************************************/ Func new_table_func() { Func p, p1, new_func(); p = new_func(); if(!last_func){ last_func = p; }else{ for(p1 = last_func; p1 && p1->prev; p1 = p1->prev) ; p1->prev = p; } p->mode = PROTO; return p; } Func copy_func(fo) Func fo; { Func f; Branch br, b2, add_branch(); int i; f = new_func(); memcpy(f,fo,sizeof(struct func_struct)); /* make copies of the system strings, and filenames for external processes, because they get edited */ if(f->flag == DISP_EXTERN){ if(fo->exec)strcpym(&f->exec,fo->exec); if(fo->exec2)strcpym(&f->exec2,fo->exec2); if(fo->clean)strcpym(&f->clean,fo->clean); if(fo->final)strcpym(&f->final,fo->final); if(fo->label)strcpym(&f->label,fo->label); for(i=0;iinfilename[i])strcpym(&f->infilename[i],fo->infilename[i]); if(fo->outfilename[i])strcpym(&f->outfilename[i],fo->outfilename[i]); if(fo->infilename2[i])strcpym(&f->infilename2[i],fo->infilename2[i]); if(fo->outfilename2[i])strcpym(&f->outfilename2[i],fo->outfilename2[i]); if(fo->infilename3[i])strcpym(&f->infilename3[i],fo->infilename3[i]); if(fo->outfilename3[i])strcpym(&f->outfilename3[i],fo->outfilename3[i]); } } /* copy the branch information */ f->branch = NULL; for(br = fo->branch; br; br = br->next){ b2 = add_branch(f,br->code,br->label,br->exit_code,br->exit); b2->func = br->func; } f->mode = TEMP; return f; } copy_func2(f,fo) Func f, fo; { Func tmp; Branch br, b2, add_branch(); int i; /* preserve prev */ tmp = f->prev; memcpy(f,fo,sizeof(struct func_struct)); f->prev = tmp; /* make copies of the system strings, and filenames for external processes, because they get edited */ if(f->flag == DISP_EXTERN){ if(fo->exec)strcpym(&f->exec,fo->exec); if(fo->exec2)strcpym(&f->exec2,fo->exec2); if(fo->clean)strcpym(&f->clean,fo->clean); if(fo->final)strcpym(&f->final,fo->final); if(fo->label)strcpym(&f->label,fo->label); for(i=0;iinfilename[i])strcpym(&f->infilename[i],fo->infilename[i]); if(fo->outfilename[i])strcpym(&f->outfilename[i],fo->outfilename[i]); if(fo->infilename2[i])strcpym(&f->infilename2[i],fo->infilename2[i]); if(fo->outfilename2[i])strcpym(&f->outfilename2[i],fo->outfilename2[i]); if(fo->infilename3[i])strcpym(&f->infilename3[i],fo->infilename3[i]); if(fo->outfilename3[i])strcpym(&f->outfilename3[i],fo->outfilename3[i]); } } /* copy the branch information */ f->branch = NULL; for(br = fo->branch; br; br = br->next){ b2 = add_branch(f,br->code,br->label,br->exit_code,br->exit); printf("new exit code %d \n",b2->exit_code); b2->func = br->func; } return 0; } Branch add_branch(p,i,s,iexc,iex) Func p; int i; char *s; int iexc; int iex; { Branch br; if(p->branch){ for(br=p->branch; br && br->next; br = br->next); br = br->next = New(struct branch_struct); }else{ br = p->branch = New(struct branch_struct); } if(!br){ fprintf(stderr,"memory error\n"); exit(1); } br->func = NULL; br->next = NULL; br->code = i; if(debug)printf("add branch from %s to %s code %d exit_code %d exit %d \n",p->label, s,i,iexc,iex); strcpym(&br->label,s); /* is this an exit */ if(iex){ br->exit_code = iexc; br->exit = 1; }else{ br->exit = 0; } return br; } delete_func(f) Func f; { int i; if(f->mode == PROTO){ printf("error - can't delete prototype function structure\n"); return 0; } if(f->flag == DISP_EXTERN){ if(f->exec)ckfree(f->exec); if(f->exec2)ckfree(f->exec2); if(f->clean)ckfree(f->clean); for(i=0;iinfilename[i])ckfree(f->infilename[i]); if(f->outfilename[i])ckfree(f->outfilename[i]); if(f->infilename2[i])ckfree(f->infilename2[i]); if(f->outfilename2[i])ckfree(f->outfilename2[i]); if(f->infilename3[i])ckfree(f->infilename3[i]); if(f->outfilename3[i])ckfree(f->outfilename3[i]); } if(f->final && f->mode == LOCAL){ if(debug)printf("executing final cleanup : %s\n",f->final); system(f->final); for(i=0;inok;i++){ if(f->out[i]->func->final){ ckfree(f->out[i]->func->final); f->out[i]->func->final = NULL; } } } } ckfree((char *) f); return 0; } /************************************************************************** * list_func(p) * provide a crude listing of the series of user structures p **************************************************************************/ list_func(p) Func p; { int i, j, k; Branch br; Finput d; printf("-------- function definition for: label=%s menu=%s\n",p->label,p->menu_entry); if(p->net)printf("parent net %s\n",p->net->label); else printf("not part of a net\n"); if(p->menu_entry)printf("menu entry %s\n",p->menu_entry); printf(" mode is %d\n",p->mode); if(p->flag == DISP_EXTERN){ printf("function is external:"); if(p->call){ printf("invoke external net %s\n",p->exec); }else{ printf(" command to execute = %s\n",p->exec); } printf(" to re-execute = %s\n",p->exec2); printf(" to clean = %s\n",p->clean); printf(" on shutdown = %s\n",p->final); if(p->menu_ptr)printf("menu %s \n",p->menu_ptr->title); for(j = 0; j < p->nif; j++){ printf("input file symbolic %s actual %s local %s, contents ",p->infilename[j],p->infilename2[j],p->infilename3[j]); for(k = 0; k < p->nik; k++) if(p->infile[k] == j){ printf("%s (%s) ",p->inobjtype[k]->name,p->selection[k]); if(p->ninxkey[k] > 1){ printf(" xref "); for(i=1;ininxkey[k];i++)printf("%d ",p->inxkey[k][i]); } if(p->inrange[k]){ printf(" range "); list_range(p->in[k]); }else{ printf("%s ",object_name(p->in[k])); } } printf("\n"); } for(j = 0; j < p->nof; j++){ if(p->outfilename[j]){ printf("output file symbolic %s actual %s local %s, contents ",p->outfilename[j],p->outfilename2[j],p->outfilename3[j]); }else{ printf("socket host = %s, port = %d; contents ",p->host[j],p->port[j]); } for(k = 0; k < p->nok; k++){ if(p->outfile[k] == j){ printf("%s ",p->outobjtype[k]->name); if(p->overwr[k] != NONE)printf("(to overwrite %d) ",p->overwr[k]); if(p->noutxkey[k] > 1){ printf(" xref "); for(i=1;inoutxkey[k];i++)printf("%ld ",(long) p->outxkey[k][i]); } if(p->outrange[k]){ printf(" range "); list_range(p->out[k]); }else{ printf("%s ",object_name(p->out[k])); } } } printf("\n"); } }else{ printf("inputs - "); for(k = 0; k < p->nik; k++){ if(p->inobjtype[k]){ printf("%s (%s) ",p->inobjtype[k]->name,p->selection[k]); if(p->ninxkey[k] > 1){ printf(" xref "); for(i=1;ininxkey[k];i++)printf("%d ",p->inxkey[k][i]); } if(p->inrange[k]){ printf(" range "); list_range(p->in[k]); }else{ printf("%s ",object_name(p->in[k])); } printf("\n"); }else{ printf("NOT USED\n"); } } printf("outputs - "); for(k = 0; k < p->nok; k++){ if(p->outobjtype[k]){ printf("%s ",p->outobjtype[k]->name); if(p->overwr[k] != NONE)printf("(to overwrite %d) ",p->overwr[k]); if(p->noutxkey[k] > 1){ printf(" xref "); for(i=1;inoutxkey[k];i++)printf("%d ",p->outxkey[k][i]); } if(p->outxkey[k])printf(" xref %ld ",(long) p->outxkey[k]); if(p->outrange[k]){ printf(" range "); list_range(p->out[k]); }else{ printf("%s ",object_name(p->out[k])); } printf("\n"); }else{ printf("NOT USED\n"); } } } if(p->branch){ printf("branch points\n"); for(br=p->branch;br;br=br->next){ if(br->exit){ printf("on return code %d exit with code %d\n",br->code,br->exit_code); }else{ printf("on return code %d branch to module %s\n",br->code,br->label); } } } if(p->subnet){ printf("transfer control to %s\n",p->subnet->label); } if(p->direc){ printf(" ****** stored directives ******\n"); for(d = p->direc;d;d=d->next)printf("%s\n",d->record); printf(" ******************************* \n"); } return 0; } list_range(p) struct chain_struct *p; { struct chain_struct *q; for(q = p; q; q = q->prev){ printf("%s, ",object_name(q->ptr)); } return 0; } add_input_record(p,s) Func p; char *s; { Finput newd, d; newd = New(struct func_input_struct); if(p->direc){ for(d=p->direc;d && d->next;d=d->next); d->next = newd; }else{ p->direc = newd; } newd->next = NULL; strcpym(&newd->record,s); return 0; }