/*FUNCTION*/ int c_equal(tpLspObject pLSP, LVAL p, LVAL q ){ /*noverbatim CUT*/ if( p == q ) return 1; if( gettype(p) != gettype(q) )return 0; switch( gettype(p) ){ case NTYPE_CON: return equal(car(p),car(q)) && equal(cdr(p),cdr(q)); case NTYPE_FLO: return getfloat(p)==getfloat(q); case NTYPE_INT: return getint(p)==getint(q); case NTYPE_STR: return getstring(p) == getstring(q) || !strcmp(getstring(p),getstring(q)); case NTYPE_SYM: return getsymbol(p) == getsymbol(q) || !strcmp(getsymbol(p),getsymbol(q)); case NTYPE_CHR: return getchr(p) == getchr(q); default: return 0; break; } }
/** Get name of a TAG or attribute from the input stream. * * Either it returns a pointer to allocated memory which contains the name or it returns NULL if * there is some error. */ static char* get_name( PPOS* ppos ) { char* name = NULL; size_t size = 0; size_t len = 0; int c; assert(ppos != NULL); c = getsymbol(ppos); if (!isalpha(c) && (c != '_') && (c != ':')) { xml_error(ppos, "Name starting with illegal charater"); return NULL; } /* The following is wrong: Here almost all characters that we casted to unicode are feasible */ while (isalnum(c) || (c == '_') || (c == ':') || (c == '.') || (c == '-')) { if (len + 1 >= size) { size += NAME_EXT_SIZE; if ( name == NULL ) { ALLOC_ABORT( BMSallocMemoryArray(&name, size) ); } else { ALLOC_ABORT( BMSreallocMemoryArray(&name, size) ); } } assert(name != NULL); assert(size > len); name[len++] = (char)c; c = getsymbol(ppos); } if (c != EOF) ungetsymbol(ppos, c); assert(name != NULL); if (len == 0) { BMSfreeMemoryArray(&name); name = NULL; } else name[len] = '\0'; return name; }
/* Load the audio functions */ static int load_audio(void) { if(!(pwaveOutOpen = (MMRESULT (WINAPI*)(HWAVEOUT*, UINT, const WAVEFORMATEX*, DWORD, DWORD, DWORD))getsymbol(MODULE_winmm,"waveOutOpen"))) return(0); if(!(pwaveOutWrite = (MMRESULT (WINAPI*)(HWAVEOUT , WAVEHDR* , UINT))getsymbol(MODULE_winmm,"waveOutWrite"))) return(0); if(!(pwaveOutPrepareHeader = (MMRESULT (WINAPI*)(HWAVEOUT , WAVEHDR* , UINT))getsymbol(MODULE_winmm,"waveOutPrepareHeader"))) return(0); if(!(pwaveOutClose = (MMRESULT (WINAPI*)(HWAVEOUT ))getsymbol(MODULE_winmm,"waveOutClose"))) return(0); if(!(pwaveOutReset = (MMRESULT (WINAPI*)(HWAVEOUT ))getsymbol(MODULE_winmm,"waveOutReset"))) return(0); return(1); }
/*FUNCTION*/ int c_flatc(tpLspObject pLSP, LVAL p ){ /*noverbatim CUT*/ int j; LVAL fp; if( null(p) )return 3; switch( gettype(p) ){ case NTYPE_CON: for( fp = p , j = 1/*(*/ ; fp ; fp = cdr(fp) ) j+= flatc(car(fp))+1/*space*/; return p ? j : 1+j; /*) was calculated as a space. (Not always.) */ case NTYPE_FLO: sprintf(BUFFER,"%lf",getfloat(p)); break; case NTYPE_INT: sprintf(BUFFER,"%ld",getint(p)); break; case NTYPE_STR: sprintf(BUFFER,"\"%s\"",getstring(p)); break; case NTYPE_SYM: sprintf(BUFFER,"%s",getsymbol(p)); break; case NTYPE_CHR: sprintf(BUFFER,"#\\%c",getchr(p)); break; default: return 0; } return strlen(BUFFER); }
/** Skip comment * * Return FALSE if an error occurs. */ static int do_comment( PPOS* ppos ) { int result = TRUE; int c; int state = 0; assert(ppos != NULL); for(;;) { c = getsymbol(ppos); if (c == EOF) break; if ((c == '>') && (state >= 2)) break; state = (c == '-') ? state + 1 : 0; } if (c == EOF) { xml_error(ppos, "Unexpected EOF in comment"); result = FALSE; } return result; }
/** Read the value of an attribute from the input stream. * * The value has to be between two " or ' (the other character is then valid as well). The function * returns a pointer to allocated memory containing the value or it returns NULL in case of an * error. */ static char* get_attrval( PPOS* ppos ) { char* attr = NULL; int c; int stop; size_t len = 0; size_t size = 0; assert(ppos != NULL); /* The following is not allowed according to the specification (the value has to be directly * after the equation sign). */ c = skip_space(ppos); if ((c != '"') && (c != '\'')) { xml_error(ppos, "Atribute value does not start with \" or \'"); return NULL; } stop = c; for(;;) { if (len == size) { size += ATTR_EXT_SIZE; if ( attr == NULL ) { ALLOC_ABORT( BMSallocMemoryArray(&attr, size) ); } else { ALLOC_ABORT( BMSreallocMemoryArray(&attr, size) ); } } assert(attr != NULL); assert(size > len); c = getsymbol(ppos); if ((c == stop) || (c == EOF)) break; attr[len++] = (char)c; } if (c != EOF) attr[len] = '\0'; else { BMSfreeMemoryArray(&attr); attr = NULL; } return attr; }
static void ejectinit(void) { ejectstate.initialized = -1; if (!(ejectstate.GetVolumeNameForVolumeMountPoint = (GetVolumeNameForVolumeMountPoint_f)getsymbol(MODULE_kernel, "GetVolumeNameForVolumeMountPointA"))) return; if (!(ejectstate.GetVolumePathName = (GetVolumePathName_f)getsymbol(MODULE_kernel, "GetVolumePathNameA"))) return; if (!(ejectstate.Get_DevNode_Status = (Get_DevNode_Status_f)getsymbol(MODULE_setup, "CM_Get_DevNode_Status"))) return; if (!(ejectstate.Get_Parent = (Get_Parent_f)getsymbol(MODULE_setup, "CM_Get_Parent"))) return; if (!(ejectstate.Request_Device_Eject = (Request_Device_Eject_f)getsymbol(MODULE_setup, "CM_Request_Device_EjectA"))) return; if (!(ejectstate.SetupDiDestroyDeviceInfoList = (SetupDiDestroyDeviceInfoList_f)getsymbol(MODULE_setup, "SetupDiDestroyDeviceInfoList"))) return; if (!(ejectstate.SetupDiEnumDeviceInterfaces = (SetupDiEnumDeviceInterfaces_f)getsymbol(MODULE_setup, "SetupDiEnumDeviceInterfaces"))) return; if (!(ejectstate.SetupDiGetClassDevs = (SetupDiGetClassDevs_f)getsymbol(MODULE_setup, "SetupDiGetClassDevsA"))) return; if (!(ejectstate.SetupDiGetDeviceInterfaceDetail = (SetupDiGetDeviceInterfaceDetail_f)getsymbol(MODULE_setup, "SetupDiGetDeviceInterfaceDetailA"))) return; if (!(ejectstate.SetupDiGetDeviceRegistryProperty = (SetupDiGetDeviceRegistryProperty_f)getsymbol(MODULE_setup, "SetupDiGetDeviceRegistryPropertyA"))) return; ejectstate.initialized = 1; }
static int devmem_api() { if(!NtUnmapViewOfSection && !(NtUnmapViewOfSection = (NTSTATUS (__stdcall*)(HANDLE, PVOID)) getsymbol(MODULE_nt, "NtUnmapViewOfSection"))) return 0; if(!NtOpenSection && !(NtOpenSection = (NTSTATUS (__stdcall*)(HANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES)) getsymbol(MODULE_nt, "NtOpenSection"))) return 0; if(!NtMapViewOfSection && !(NtMapViewOfSection = (NTSTATUS (__stdcall*)(HANDLE, HANDLE, PVOID, ULONG, ULONG, PLARGE_INTEGER, PULONG, SECTION_INHERIT, ULONG, ULONG)) getsymbol(MODULE_nt, "NtMapViewOfSection"))) return 0; if(!RtlInitUnicodeString && !(RtlInitUnicodeString = (NTSTATUS (__stdcall *)(PUNICODE_STRING, PCWSTR)) getsymbol(MODULE_nt, "RtlInitUnicodeString"))) return 0; if(!RtlNtStatusToDosError && !(RtlNtStatusToDosError = (ULONG (__stdcall *)(NTSTATUS)) getsymbol(MODULE_nt, "RtlNtStatusToDosError"))) return 0; if(!NtQuerySystemInformation && !(NtQuerySystemInformation = (NTSTATUS (__stdcall *)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG)) getsymbol(MODULE_nt, "NtQuerySystemInformation"))) return 0; return 1; }
/** Skip all spaces and return the next non-space character or EOF */ static int skip_space( PPOS* ppos ) { int c; assert(ppos != NULL); do { c = getsymbol(ppos); } while(isspace(c)); return c; }
/*FUNCTION*/ LVAL c_freelist(tpLspObject pLSP, LVAL p ){ /*noverbatim CUT*/ if( null(p) || freep(p) )return NIL; if(consp(p) ) { settype(p,NTYPE_FRE); freelist(car(p)); freelist(cdr(p)); } if( stringp(p) ) FREE(getstring(p)); else if( symbolp(p) ) FREE(getsymbol(p)); FREE(p); return NIL; }
/** Checks for next tag */ static void proc_before( PPOS* ppos /**< input stream position */ ) { int c; assert(ppos != NULL); assert(ppos->state == STATE_BEFORE); c = skip_space(ppos); if (c != '<') { xml_error(ppos, "Expecting '<'"); ppos->state = STATE_ERROR; } else { c = getsymbol(ppos); switch(c) { case EOF : xml_error(ppos, "Unexpected EOF"); ppos->state = STATE_ERROR; break; case '!' : handle_decl(ppos); break; case '?' : handle_pi(ppos); break; case '/' : handle_endtag(ppos); break; default : ungetsymbol(ppos, c); handle_starttag(ppos); break; } } }
/** Handle processing instructions (skipping) */ static void handle_pi( PPOS* ppos ) { int c; assert(ppos != NULL); assert(ppos->state == STATE_BEFORE); do { c = getsymbol(ppos); } while((c != EOF) && (c != '>')); if (c != EOF) ppos->state = STATE_PCDATA; else { xml_error(ppos, "Unexpected EOF in PI"); ppos->state = STATE_ERROR; } }
/** Handles declarations that start with a <!. * * This includes comments. Does currenlty not work very well, because of DTDs. */ static void handle_decl( PPOS* ppos ) { enum XmlSection { IS_COMMENT, IS_ATTLIST, IS_DOCTYPE, IS_ELEMENT, IS_ENTITY, IS_NOTATION, IS_CDATA }; typedef enum XmlSection XMLSECTION; static struct { const char* name; XMLSECTION what; } key[] = { { "--", IS_COMMENT }, { "ATTLIST", IS_ATTLIST }, { "DOCTYPE", IS_DOCTYPE }, { "ELEMENT", IS_ELEMENT }, { "ENTITY", IS_ENTITY }, { "NOTATION", IS_NOTATION }, { "[CDATA[", IS_CDATA } }; XML_NODE* node; char* data; int c; int k = 0; int beg = 0; int end = (sizeof(key) / sizeof(key[0])) - 1; assert(ppos != NULL); assert(ppos->state == STATE_BEFORE); do { c = getsymbol(ppos); for(; (beg <= end) && (c != key[beg].name[k]); beg++) ; for(; (end >= beg) && (c != key[end].name[k]); end--) ; k++; } while(beg < end); if (beg != end) { xml_error(ppos, "Unknown declaration"); while((c != EOF) && (c != '>')) c = getsymbol(ppos); } else { assert(beg == end); assert(beg < (int)(sizeof(key) / sizeof(*key))); switch(key[beg].what) { case IS_COMMENT : if (do_comment(ppos)) ppos->state = STATE_ERROR; break; case IS_CDATA : if ((data = do_cdata(ppos)) == NULL) ppos->state = STATE_ERROR; else { if (NULL == (node = xml_new_node("#CDATA", ppos->lineno))) { xml_error(ppos, "Can't create new node"); ppos->state = STATE_ERROR; } else { BMSduplicateMemoryArray(&node->data, data, strlen(data)+1); BMSfreeMemoryArray(&data); xml_append_child(top_pstack(ppos), node); } } break; case IS_ATTLIST : case IS_ELEMENT : case IS_NOTATION : case IS_ENTITY : case IS_DOCTYPE : break; default : abort(); } } }
/** Handles a CDATA section. * * Returns a pointer to allocated memory containing the data of this section or NULL in case of an * error. */ static char* do_cdata( PPOS* ppos ) { char* data = NULL; size_t size = 0; size_t len = 0; int state = 0; int c; assert(ppos != NULL); for(;;) { c = getsymbol(ppos); if (c == EOF) break; if (c == ']') state++; else if ((c == '>') && (state >= 2)) break; else state = 0; if (len == size) { size += DATA_EXT_SIZE; if ( data == NULL ) { ALLOC_ABORT( BMSallocMemoryArray(&data, size) ); } else { ALLOC_ABORT( BMSreallocMemoryArray(&data, size) ); } } assert(data != NULL); assert(size > len); data[len++] = (char)c; } assert(data != NULL); if (c != EOF) { assert(len >= 2); data[len - 2] = '\0'; } else { BMSfreeMemoryArray(&data); data = NULL; xml_error(ppos, "Unexpected EOF in CDATA"); } return data; }
/* rtoken - read the next CsToken */ static int rtoken(CsCompiler *c) { int ch,ch2; /* check the next character */ for (;;) switch (ch = skipspaces(c)) { case EOF: return T_EOF; case '\"': return getstring(c); case '`': return getstring(c, '`'); case '\'': return getcharacter(c); case '<': switch (ch = getch(c)) { case '=': return T_LE; case '<': if ((ch = getch(c)) == '=') return T_SHLEQ; else if( ch == '<' ) { if ((ch = getch(c)) == '=') return T_USHLEQ; c->savedChar = ch; return T_USHL; } c->savedChar = ch; return T_SHL; default: c->savedChar = ch; return '<'; } case '=': if ((ch = getch(c)) == '=') { if ((ch = getch(c)) == '=') { return T_EQ_STRONG; } c->savedChar = ch; return T_EQ; } c->savedChar = ch; return '='; case '!': if ((ch = getch(c)) == '=') { if ((ch = getch(c)) == '=') { return T_NE_STRONG; } c->savedChar = ch; return T_NE; } c->savedChar = ch; return '!'; case '>': switch (ch = getch(c)) { case '=': return T_GE; case '>': if ((ch = getch(c)) == '=') return T_SHREQ; else if( ch == '>' ) { if ((ch = getch(c)) == '=') return T_USHREQ; c->savedChar = ch; return T_USHR; } c->savedChar = ch; return T_SHR; default: c->savedChar = ch; return '>'; } case '&': switch (ch = getch(c)) { case '&': return T_AND; case '=': return T_ANDEQ; default: c->savedChar = ch; return '&'; } case '%': switch (ch = getch(c)) { case '>': return getoutputstring(c); case '=': return T_REMEQ; case '~': return T_RCDR; default: c->savedChar = ch; return '%'; } case '|': switch (ch = getch(c)) { case '|': return T_OR; case '=': return T_OREQ; default: c->savedChar = ch; return '|'; } case '^': if ((ch = getch(c)) == '=') return T_XOREQ; c->savedChar = ch; return '^'; case '+': switch (ch = getch(c)) { case '+': return T_INC; case '=': return T_ADDEQ; default: c->savedChar = ch; return '+'; } case '-': switch (ch = getch(c)) { case '-': return T_DEC; case '=': return T_SUBEQ; default: c->savedChar = ch; return '-'; } case '~': switch (ch = getch(c)) { case '/': return T_CAR; case '%': return T_CDR; default: c->savedChar = ch; return '~'; } case '*': if ((ch = getch(c)) == '=') return T_MULEQ; c->savedChar = ch; return '*'; case '/': switch (ch = getch(c)) { case '=': return T_DIVEQ; case '/': while ((ch = getch(c)) != EOF) if (ch == '\n') break; break; case '*': ch = ch2 = EOF; for (; (ch2 = getch(c)) != EOF; ch = ch2) if (ch == '*' && ch2 == '/') break; break; case '~': return T_RCAR; default: c->savedChar = ch; return '/'; } break; case '.': if ((ch = getch(c)) != EOF && is_digit(ch)) { c->savedChar = ch; return getnumber(c,'.'); } else if (ch == '.') { c->t_token[0] = '.'; c->t_token[1] = '.'; c->t_token[2] = '\0'; return T_DOTDOT; } else { c->savedChar = ch; c->t_token[0] = '.'; c->t_token[1] = '\0'; return '.'; } break; case 1: return T_DOTDOT; case '0': switch (ch = getch(c)) { case 'x': case 'X': return getradixnumber(c,16); case 'b': case 'B': return getradixnumber(c,2); default: c->savedChar = ch; if (ch >= '0' && ch <= '7') return getradixnumber(c,8); else return getnumber(c,'0'); } break; case '#': return getsymbol(c); default: if (is_digit(ch)) return getnumber(c,ch); else if (isidchar(ch)) return getid(c,ch); else { c->t_token[0] = ch; c->t_token[1] = '\0'; return ch; } } }
/** Process tag */ static void proc_in_tag( PPOS* ppos /**< input stream position */ ) { XML_ATTR* attr; int c; int empty = FALSE; char* name; char* value; assert(ppos != NULL); assert(ppos->state == STATE_IN_TAG); c = skip_space(ppos); if ((c == '/') || (c == '>') || (c == EOF)) { if (c == '/') { empty = TRUE; c = getsymbol(ppos); } if (c == EOF) { xml_error(ppos, "Unexpected EOF while in a tag"); ppos->state = STATE_ERROR; } if (c == '>') { ppos->state = STATE_PCDATA; if (empty && ! pop_pstack(ppos)) ppos->state = STATE_ERROR; } else { xml_error(ppos, "Expected tag end marker '>'"); ppos->state = STATE_ERROR; } } else { ungetsymbol(ppos, c); if ((name = get_name(ppos)) == NULL) { xml_error(ppos, "No name for attribute"); ppos->state = STATE_ERROR; } else { c = skip_space(ppos); if ((c != '=') || ((value = get_attrval(ppos)) == NULL)) { xml_error(ppos, "Missing attribute value"); ppos->state = STATE_ERROR; BMSfreeMemoryArray(&name); } else { if (NULL == (attr = xml_new_attr(name, value))) { xml_error(ppos, "Can't create new attribute"); ppos->state = STATE_ERROR; } else { xml_add_attr(top_pstack(ppos), attr); } BMSfreeMemoryArray(&name); BMSfreeMemoryArray(&value); } } } }
/* Handles PCDATA */ static void proc_pcdata( PPOS* ppos /**< input stream position */ ) { XML_NODE* node; char* data = NULL; size_t size = 0; size_t len = 0; int c; assert(ppos != NULL); assert(ppos->state == STATE_PCDATA); #ifndef SPEC_LIKE_SPACE_HANDLING if ((c = skip_space(ppos)) != EOF) ungetsymbol(ppos, c); #endif c = getsymbol(ppos); while ((c != EOF) && (c != '<')) { if (len >= size - 1) /* leave space for terminating '\0' */ { size += DATA_EXT_SIZE; if ( data == NULL ) { ALLOC_ABORT( BMSallocMemoryArray(&data, size) ); } else { ALLOC_ABORT( BMSreallocMemoryArray(&data, size) ); } } assert(data != NULL); assert(size > len + 1); data[len++] = (char)c; c = getsymbol(ppos); } if (data == NULL) { if (c == EOF) ppos->state = STATE_EOF; else if (c == '<') { ppos->state = STATE_BEFORE; ungetsymbol(ppos, c); } else { ppos->state = STATE_ERROR; } } else { assert(len < size); data[len] = '\0'; if (c == EOF) ppos->state = STATE_ERROR; else { ungetsymbol(ppos, c); if (NULL == (node = xml_new_node("#PCDATA", ppos->lineno))) { xml_error(ppos, "Can't create new node"); ppos->state = STATE_ERROR; } else { BMSduplicateMemoryArray(&node->data, data, strlen(data)+1); xml_append_child(top_pstack(ppos), node); ppos->state = STATE_BEFORE; } BMSfreeMemoryArray(&data); } } }
/* * local pprinting function * * Do not try to understand how it works. When I wrote it I and God knew how * it worked. I have forgotten... * Ask God! * * p is the expression is to print. * k is magic argument to handle non-algorithmic behaviour of pprint. * (k holds internal beautiness (!) factor of printout. (AI!) :-) * Serious: * k=1 we dunno anything about expression * k=1 the tabulatig spaces were alrady printed! * k=2 we are in flatc mode * -dont print tabulating space * -there is no need to check flatc size. */ static LVAL __pprint(tpLspObject pLSP,LVAL p,int k) #define _pprint(x) __pprint(pLSP,(x),1) { LVAL fp; int j,multiline; char *s; if( null(p) ) { fprintf(pLSP->f,"NIL"); return NIL; } switch(gettype(p)) { case NTYPE_CON: if( k == 2 || flatc(p) < SCRSIZE-TABPOS ) { /* Print in flat mode. */ if( k == 1 ) fprintf(pLSP->f,"%*s(",TABPOS,""); else fprintf(pLSP->f,"("); for( fp = p ; fp ; ) { __pprint(pLSP,car(fp),2); fp = cdr(fp); if( fp ) fprintf(pLSP->f," "); } fprintf(pLSP->f,")"); return NIL; } if( atom(fp=car(p)) || flatc(fp) < (SCRSIZE-TABPOS)/2 ) { fprintf(pLSP->f,"("); SCRSIZE--; /* Schrink screen size thinking of the closing paren. */ j = flatc(fp)+2;/* ([flatc]SPACE */ TABPOS += j; __pprint(pLSP,fp,0); if( cdr(p) ) { fprintf(pLSP->f," "); __pprint(pLSP,cadr(p),0); fprintf(pLSP->f,"\n"); for( fp = cdr(cdr(p)) ; fp ; ) { fprintf(pLSP->f,"%*s",TABPOS,""); __pprint(pLSP,car(fp),0); fp = cdr(fp); if( fp ) fprintf(pLSP->f,"\n"); } } TABPOS -= j; fprintf(pLSP->f,")"); SCRSIZE++; return NIL; } fprintf(pLSP->f,"("); /* Schrink screen size thinking of the closing paren. */ SCRSIZE--; TABPOS++; __pprint(pLSP,car(p),0); if( fp = cdr(p) ) fprintf(pLSP->f,"\n"); while( fp ) { fprintf(pLSP->f,"%*s",TABPOS,""); _pprint(car(fp)); fp = cdr(fp); if( fp ) fprintf(pLSP->f,"\n"); } TABPOS--; fprintf(pLSP->f,")"); SCRSIZE++; return NIL; case NTYPE_FLO: fprintf(pLSP->f,"%lf",getfloat(p)); return NIL; case NTYPE_INT: fprintf(pLSP->f,"%ld",getint(p)); return NIL; case NTYPE_STR: multiline = 0; for( s=getstring(p) ; *s ; s++ ) if( *s == '\n' ){ multiline = 1; break; } fprintf(pLSP->f,multiline ? "\"\"\"" : "\""); for( s=getstring(p) ; *s ; s++ ) switch( *s ) { /* Handle spacial characters. */ case '\"': fprintf(pLSP->f,"\\\""); break; default: fprintf(pLSP->f,"%c",*s); break; } fprintf(pLSP->f,multiline ? "\"\"\"" : "\""); return NIL; case NTYPE_SYM: fprintf(pLSP->f,"%s",getsymbol(p)); return NIL; case NTYPE_CHR: fprintf(pLSP->f,"#\\%c",getchr(p)); return NIL; default: return NIL; } fprintf(pLSP->f,BUFFER); return NIL; }
int read_circuit (FILE *circuit_fd) { char c; int nerrs = 0; int fn, nofanin, i, j; int int_nog, int_nopi, int_nopo; int net_size; char symbol[MAXSTRING]; register HASHPTR hp; register GATEPTR cg; GATEPTR pg; begnet=(GATEPTR)NULL; GATEPTR pfanin[MAXFIN+100]; GATEPTR po_gates[MAXPO+100]; int_nog = int_nopi = int_nopo = 0; nofanin=0; InitHash (symbol_tbl, HASHSIZE); while ((c = getsymbol (circuit_fd, symbol)) != EOF) { switch (c) { case '=' : hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0); //printf("in read: hp = %s \n", symbol); if ((cg = hp->pnode) == NULL) { cg = (GATETYPE *)xmalloc(sizeof(GATETYPE)); hp->pnode = cg; cg->symbol = hp; cg->next = begnet; begnet = cg; } break; case '(' : if ((fn = gatetype (symbol)) < 0) { fprintf (stderr, "Error: Gate type %s is not valid\n", symbol); return(-1); } break; case ',' : hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0); if ((pg = hp->pnode) == NULL) { pg = (GATETYPE *)xmalloc(sizeof(GATETYPE)); hp->pnode = pg; pg->symbol = hp; pg->index = (-1); pg->next = begnet; begnet = pg; } pfanin[nofanin++] = pg; break; case ')': hp = Find_and_Insert_Hash (symbol_tbl, HASHSIZE, symbol, 0); if ((pg = hp->pnode) == NULL) { pg = (GATETYPE *)xmalloc(sizeof(GATETYPE)); hp->pnode = pg; pg->symbol = hp; pg->index = (-1); pg->next = begnet; begnet = pg; } switch(fn) { case PI: int_nopi++; pg->index = int_nog++; pg->ninput = 0; pg->inlis=(GATEPTR *)NULL; pg->fn = PI; pg->noutput = 0; pg->outlis = (GATEPTR *)NULL; break; case PO: po_gates[int_nopo++] = pg; break; default: pfanin[nofanin++] = pg; if (cg == NULL) { fprintf(stderr,"Error: Syntax error in the circuit file\n"); return(-1); } cg->index = int_nog++; cg->fn = fn; if ((cg->ninput = nofanin) == 0) cg->inlis = NULL; else { cg->inlis = (GATEPTR *)xmalloc(cg->ninput*(sizeof(GATEPTR))); } for (i = 0; i<nofanin; i++) cg->inlis[i] = pfanin[i]; cg->noutput = 0; cg->outlis = (GATEPTR *)NULL; nofanin = 0; cg = (GATEPTR) NULL; break; } } } net_size = int_nog + int_nopo; //printf(" net = %d\n",net_size); net = (GATEPTR *)xmalloc(net_size*(sizeof(GATEPTR))); primaryin = (int *)xmalloc(int_nopi*(sizeof(int))); primaryout = (int *)xmalloc(int_nopo*(sizeof(int))); nog=nopi=nopo=0; for (cg = begnet; cg != NULL; cg = cg->next) { if (cg->index < 0) { fprintf(stderr,"Error: floating net %s\n",cg->symbol->symbol); fprintf(stderr, "Workaround. You have to take one of the two actions:\n"); fprintf(stderr, " 1. Remove all the floating input and associated gates, or\n"); fprintf(stderr, " 2. Make each floating input a primary output.\n"); return(-1); } net[cg->index] = cg; nog++; } for (i = nog; i<net_size; i++) net[i] = (GATEPTR)NULL; if (nog != int_nog) { fprintf(stderr,"Error in read_circuit\n"); return(-1); } for (i = 0; i<nog; i++) { cg = net[i]; for (j = 0; j<cg->ninput; j++) cg->inlis[j]->noutput++; if (cg->fn == PI) primaryin[nopi++] = i; } for (i = 0; i<int_nopo; i++) primaryout[nopo++] = po_gates[i]->index; for (i = 0; i<nog; i++) { cg = net[i]; if (cg->noutput>0) { cg->outlis = (GATEPTR *)xmalloc(cg->noutput*(sizeof(GATEPTR))); //maxfout = MAX(maxfout,cg->noutput); //cg->noutput= 0; } } for (i = 0; i<nog; i++) net[i]->noutput = 0; for (i = 0; i<nog; i++) { cg = net[i]; for (j = 0; j<cg->ninput; j++) { cg->inlis[j]->outlis[(cg->inlis[j]->noutput)++] = cg; //pg = cg->inlis[j]; //pg->outlis[pg->noutput++] = cg; } } for (i = 0; i<nog; i++) { cg = net[i]; //<----------------------------------------- cg->offset = 0; cg->offset = find_offset(cg); //printf(" i have offset %d\n",cg->offset); if (cg->noutput > 0) continue; for (j = 0; j<int_nopo; j++) if (cg == po_gates[j]) break; if (j == int_nopo) { fprintf(stderr, "Error: floating output '%s' detected!\n", cg->symbol->symbol); nerrs++; } } if (nerrs > 0) { fprintf(stderr, "Workaround. You have to take one of the two actions:\n"); fprintf(stderr, " 1. Remove all the floating output and associated gates, or\n"); fprintf(stderr, " 2. Make each floating output a primary output.\n"); return(-1); } if (int_nog == nog) return(nog); else return(-1); }