static void f77data_primdata(Symbol* basetype, Datasrc* src, Bytebuffer* codebuf, Datalist* fillsrc) { Constant* prim; Constant target; prim = srcnext(src); if(prim == NULL) prim = &fillconstant; ASSERT(prim->nctype != NC_COMPOUND); if(prim->nctype == NC_FILLVALUE) { Datalist* filler = getfiller(basetype,fillsrc); ASSERT(filler->length == 1); srcpushlist(src,filler); bbAppend(codebuf,' '); f77data_primdata(basetype,src,codebuf,NULL); srcpop(src); goto done; } target.nctype = basetype->typ.typecode; convert1(prim,&target); bbCat(codebuf,f77data_const(&target)); done: return; }
static void processenums(void) { unsigned long i,j; #if 0 /* Unused? */ List* enumids = listnew(); #endif for(i=0;i<listlength(typdefs);i++) { Symbol* sym = (Symbol*)listget(typdefs,i); ASSERT(sym->objectclass == NC_TYPE); if(sym->subclass != NC_ENUM) continue; for(j=0;j<listlength(sym->subnodes);j++) { Symbol* esym = (Symbol*)listget(sym->subnodes,j); ASSERT(esym->subclass == NC_ECONST); #if 0 /* Unused? */ listpush(enumids,(void*)esym); #endif } } /* Convert enum values to match enum type*/ for(i=0;i<listlength(typdefs);i++) { Symbol* tsym = (Symbol*)listget(typdefs,i); ASSERT(tsym->objectclass == NC_TYPE); if(tsym->subclass != NC_ENUM) continue; for(j=0;j<listlength(tsym->subnodes);j++) { Symbol* esym = (Symbol*)listget(tsym->subnodes,j); NCConstant* newec = nullconst(); ASSERT(esym->subclass == NC_ECONST); newec->nctype = esym->typ.typecode; convert1(esym->typ.econst,newec); reclaimconstant(esym->typ.econst); esym->typ.econst = newec; } } }
static void generate_primdata(Symbol* basetype, Constant* prim, Bytebuffer* codebuf, Datalist* filler, Generator* generator) { Constant target; if(prim == NULL || isfillconst(prim)) { Datalist* fill = (filler==NULL?getfiller(basetype):filler); ASSERT(fill->length == 1); prim = datalistith(fill,0); } ASSERT(prim->nctype != NC_COMPOUND); target.nctype = basetype->typ.typecode; if(target.nctype != NC_ECONST) { convert1(prim,&target); } switch (target.nctype) { case NC_ECONST: if(basetype->subclass != NC_ENUM) { semerror(constline(prim),"Conversion to enum not supported (yet)"); } break; case NC_OPAQUE: setprimlength(&target,basetype->typ.size*2); break; default: break; } generator->constant(generator,&target,codebuf); return; }
int main() { check1(); check2(); convert1(); convert2(); convert3(); convert4(); convert5(); return 0; }
static void cdata_primdata(Symbol* basetype, Datasrc* src, Bytebuffer* codebuf, Datalist* fillsrc) { Constant* prim; Constant target; prim = srcnext(src); if(prim == NULL) prim = &fillconstant; ASSERT(prim->nctype != NC_COMPOUND); if(prim->nctype == NC_FILLVALUE) { Datalist* filler = getfiller(basetype,fillsrc); ASSERT(filler->length == 1); srcpushlist(src,filler); bbAppend(codebuf,' '); cdata_primdata(basetype,src,codebuf,NULL); srcpop(src); goto done; } target.nctype = basetype->typ.typecode; if(target.nctype != NC_ECONST) { convert1(prim,&target); } switch (target.nctype) { case NC_ECONST: if(basetype->subclass != NC_ENUM) { semerror(prim->lineno,"Conversion to enum not supported (yet)"); } else { Datalist* econ = builddatalist(1); Symbol* enumv = prim->value.enumv; srcpushlist(src,econ); dlappend(econ,&enumv->typ.econst); cdata_primdata(enumv->typ.basetype,src,codebuf,fillsrc); srcpop(src); } break; case NC_OPAQUE: { setprimlength(&target,basetype->typ.size*2); } break; default: break; } bbCat(codebuf,cdata_const(&target)); done: return; }
int main(int argc, char* argv[]) { char b[100],a[100]; int b1=atoi(argv[1]); // b1 is the initial base of the number int b2=atoi(argv[2]); // b1 is the final base of the number // This is the number to be converted // we have given the input as a number(base) and a string if(check(b1,argv[3])==1) { convert1(b1,b2,argv[3],b); stringrev(b); printf("%s\n",b); } else printf("0\n"); }
static void processenums(void) { int i,j; List* enumids = listnew(); for(i=0;i<listlength(typdefs);i++) { Symbol* sym = (Symbol*)listget(typdefs,i); ASSERT(sym->objectclass == NC_TYPE); if(sym->subclass != NC_ENUM) continue; for(j=0;j<listlength(sym->subnodes);j++) { Symbol* esym = (Symbol*)listget(sym->subnodes,j); ASSERT(esym->subclass == NC_ECONST); listpush(enumids,(void*)esym); } } /* Now walk set of enum ids to look for duplicates with same prefix*/ for(i=0;i<listlength(enumids);i++) { Symbol* sym1 = (Symbol*)listget(enumids,i); for(j=i+1;j<listlength(enumids);j++) { Symbol* sym2 = (Symbol*)listget(enumids,j); if(strcmp(sym1->name,sym2->name) != 0) continue; if(!prefixeq(sym1->prefix,sym2->prefix)) continue; semerror(sym1->lineno,"Duplicate enumeration ids in same scope: %s", fullname(sym1)); } } /* Convert enum values to match enum type*/ for(i=0;i<listlength(typdefs);i++) { Symbol* tsym = (Symbol*)listget(typdefs,i); ASSERT(tsym->objectclass == NC_TYPE); if(tsym->subclass != NC_ENUM) continue; for(j=0;j<listlength(tsym->subnodes);j++) { Symbol* esym = (Symbol*)listget(tsym->subnodes,j); Constant newec; ASSERT(esym->subclass == NC_ECONST); newec.nctype = esym->typ.typecode; convert1(&esym->typ.econst,&newec); esym->typ.econst = newec; } } }
void search() { char str[1000],val[500],hexval[1000]; int d[1000],i; lptr z; fflush(stdin); printf("\nEnter the key to be searched:"); gets(str); FILE *fp1,*fp; fp1 = fopen("hfile.txt","w+"); fclose(fp1); MDString(str); fp=fopen("hfile.txt","r"); fscanf(fp,"%s",hexval); fclose(fp); fp1=fopen("hashvalues.txt","w+"); fclose(fp1); convert1(hexval); fp1=fopen("hashvalues.txt","r"); fscanf(fp1,"%s",val); fclose(fp1); for(i=0;i<128;i++) d[i]=val[i]-48; z=closest(d,root); if(!strcmp(z->key,str)) printf("\nSuccessful\n"); else printf("\nNO\n"); }
void convert1(Constant* src, Constant* dst) { Constvalue tmp; unsigned char* bytes = NULL; size_t bytelen; dst->lineno = src->lineno; /* Need to translate all possible sources to all possible sinks.*/ /* Rather than have a nested switch, combine the src and target into*/ /* a single value so we can do a single n*n-way switch*/ /* special case for src being NC_FILLVALUE*/ if(src->nctype == NC_FILLVALUE) { if(dst->nctype != NC_FILLVALUE) { nc_getfill(dst); } return; } /* special case handling for src being NC_ECONST*/ if(src->nctype == NC_ECONST) { if(dst->nctype == NC_ECONST) { dst->value = src->value; } else { Symbol* econst; econst = src->value.enumv; convert1(&econst->typ.econst,dst); } return; } else if(dst->nctype == NC_ECONST) { /* special case for dst being NC_ECONST*/ semerror(lineno,"Conversion to enum not supported (yet)"); return; } if(src->nctype == NC_OPAQUE) { bytes = makebytestring(src->value.opaquev.stringv,&bytelen); } #define CASE(nc1,nc2) (nc1*256+nc2) switch (CASE(src->nctype,dst->nctype)) { case CASE(NC_CHAR,NC_CHAR): tmp.charv = src->value.charv; break; case CASE(NC_CHAR,NC_BYTE): tmp.int8v = (unsigned char)src->value.charv; break; case CASE(NC_CHAR,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.charv; break; case CASE(NC_CHAR,NC_USHORT): tmp.uint16v = (unsigned short)src->value.charv; break; case CASE(NC_CHAR,NC_UINT): tmp.uint32v = (unsigned int)src->value.charv; break; case CASE(NC_CHAR,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.charv; break; case CASE(NC_CHAR,NC_SHORT): tmp.int16v = (short)src->value.charv; break; case CASE(NC_CHAR,NC_INT): tmp.int32v = (int)src->value.charv; break; case CASE(NC_CHAR,NC_INT64): tmp.int64v = (long long)src->value.charv; break; case CASE(NC_CHAR,NC_FLOAT): tmp.floatv = (float)src->value.charv; break; case CASE(NC_CHAR,NC_DOUBLE): tmp.doublev = (double)src->value.charv; break; case CASE(NC_BYTE,NC_CHAR): tmp.charv = (char)src->value.uint8v; break; case CASE(NC_BYTE,NC_BYTE): tmp.uint8v = (unsigned char)src->value.uint8v; break; case CASE(NC_BYTE,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.uint8v; break; case CASE(NC_BYTE,NC_USHORT): tmp.uint16v = (unsigned short)src->value.uint8v; break; case CASE(NC_BYTE,NC_UINT): tmp.uint32v = (unsigned int)src->value.uint8v; break; case CASE(NC_BYTE,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.uint8v; break; case CASE(NC_BYTE,NC_SHORT): tmp.int16v = (short)src->value.uint8v; break; case CASE(NC_BYTE,NC_INT): tmp.int32v = (int)src->value.uint8v; break; case CASE(NC_BYTE,NC_INT64): tmp.int64v = (long long)src->value.uint8v; break; case CASE(NC_BYTE,NC_FLOAT): tmp.floatv = (float)src->value.uint8v; break; case CASE(NC_BYTE,NC_DOUBLE): tmp.doublev = (double)src->value.uint8v; break; case CASE(NC_UBYTE,NC_CHAR): tmp.charv = (char)src->value.uint8v; break; case CASE(NC_UBYTE,NC_BYTE): tmp.uint8v = (unsigned char)src->value.uint8v; break; case CASE(NC_UBYTE,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.uint8v; break; case CASE(NC_UBYTE,NC_USHORT): tmp.uint16v = (unsigned short)src->value.uint8v; break; case CASE(NC_UBYTE,NC_UINT): tmp.uint32v = (unsigned int)src->value.uint8v; break; case CASE(NC_UBYTE,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.uint8v; break; case CASE(NC_UBYTE,NC_SHORT): tmp.int16v = (short)src->value.uint8v; break; case CASE(NC_UBYTE,NC_INT): tmp.int32v = (int)src->value.uint8v; break; case CASE(NC_UBYTE,NC_INT64): tmp.int64v = (long long)src->value.uint8v; break; case CASE(NC_UBYTE,NC_FLOAT): tmp.floatv = (float)src->value.uint8v; break; case CASE(NC_UBYTE,NC_DOUBLE): tmp.doublev = (double)src->value.uint8v; break; case CASE(NC_USHORT,NC_BYTE): tmp.uint8v = (unsigned char)src->value.uint16v; break; case CASE(NC_USHORT,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.uint16v; break; case CASE(NC_USHORT,NC_USHORT): tmp.uint16v = (unsigned short)src->value.uint16v; break; case CASE(NC_USHORT,NC_UINT): tmp.uint32v = (unsigned int)src->value.uint16v; break; case CASE(NC_USHORT,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.uint16v; break; case CASE(NC_USHORT,NC_SHORT): tmp.int16v = (short)src->value.uint16v; break; case CASE(NC_USHORT,NC_INT): tmp.int32v = (int)src->value.uint16v; break; case CASE(NC_USHORT,NC_INT64): tmp.int64v = (long long)src->value.uint16v; break; case CASE(NC_USHORT,NC_FLOAT): tmp.floatv = (float)src->value.uint16v; break; case CASE(NC_USHORT,NC_DOUBLE): tmp.doublev = (double)src->value.uint16v; break; case CASE(NC_UINT,NC_BYTE): tmp.uint8v = (unsigned char)src->value.uint32v; break; case CASE(NC_UINT,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.uint32v; break; case CASE(NC_UINT,NC_USHORT): tmp.uint16v = (unsigned short)src->value.uint32v; break; case CASE(NC_UINT,NC_UINT): tmp.uint32v = (unsigned int)src->value.uint32v; break; case CASE(NC_UINT,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.uint32v; break; case CASE(NC_UINT,NC_SHORT): tmp.int16v = (short)src->value.uint32v; break; case CASE(NC_UINT,NC_INT): tmp.int32v = (int)src->value.uint32v; break; case CASE(NC_UINT,NC_INT64): tmp.int64v = (long long)src->value.uint32v; break; case CASE(NC_UINT,NC_FLOAT): tmp.floatv = (float)src->value.uint32v; break; case CASE(NC_UINT,NC_DOUBLE): tmp.doublev = (double)src->value.uint32v; break; case CASE(NC_UINT64,NC_BYTE): tmp.uint8v = (unsigned char)src->value.uint64v; break; case CASE(NC_UINT64,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.uint64v; break; case CASE(NC_UINT64,NC_USHORT): tmp.uint16v = (unsigned short)src->value.uint64v; break; case CASE(NC_UINT64,NC_UINT): tmp.uint32v = (unsigned int)src->value.uint64v; break; case CASE(NC_UINT64,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.uint64v; break; case CASE(NC_UINT64,NC_SHORT): tmp.int16v = (short)src->value.uint64v; break; case CASE(NC_UINT64,NC_INT): tmp.int32v = (int)src->value.uint64v; break; case CASE(NC_UINT64,NC_INT64): tmp.int64v = (long long)src->value.uint64v; break; case CASE(NC_UINT64,NC_FLOAT): tmp.floatv = (float)src->value.uint64v; break; case CASE(NC_UINT64,NC_DOUBLE): tmp.doublev = (double)src->value.uint64v; break; case CASE(NC_SHORT,NC_BYTE): tmp.uint8v = (unsigned char)src->value.int16v; break; case CASE(NC_SHORT,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.int16v; break; case CASE(NC_SHORT,NC_USHORT): tmp.uint16v = (unsigned short)src->value.int16v; break; case CASE(NC_SHORT,NC_UINT): tmp.uint32v = (unsigned int)src->value.int16v; break; case CASE(NC_SHORT,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.int16v; break; case CASE(NC_SHORT,NC_SHORT): tmp.int16v = (short)src->value.int16v; break; case CASE(NC_SHORT,NC_INT): tmp.int32v = (int)src->value.int16v; break; case CASE(NC_SHORT,NC_INT64): tmp.int64v = (long long)src->value.int16v; break; case CASE(NC_SHORT,NC_FLOAT): tmp.floatv = (float)src->value.int16v; break; case CASE(NC_SHORT,NC_DOUBLE): tmp.doublev = (double)src->value.int16v; break; case CASE(NC_INT,NC_BYTE): tmp.uint8v = (unsigned char)src->value.int32v; break; case CASE(NC_INT,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.int32v; break; case CASE(NC_INT,NC_USHORT): tmp.uint16v = (unsigned short)src->value.int32v; break; case CASE(NC_INT,NC_UINT): tmp.uint32v = (unsigned int)src->value.int32v; break; case CASE(NC_INT,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.int32v; break; case CASE(NC_INT,NC_SHORT): tmp.int16v = (short)src->value.int32v; break; case CASE(NC_INT,NC_INT): tmp.int32v = (int)src->value.int32v; break; case CASE(NC_INT,NC_INT64): tmp.int64v = (long long)src->value.int32v; break; case CASE(NC_INT,NC_FLOAT): tmp.floatv = (float)src->value.int32v; break; case CASE(NC_INT,NC_DOUBLE): tmp.doublev = (double)src->value.int32v; break; case CASE(NC_INT64,NC_BYTE): tmp.uint8v = (unsigned char)src->value.int64v; break; case CASE(NC_INT64,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.int64v; break; case CASE(NC_INT64,NC_USHORT): tmp.uint16v = (unsigned short)src->value.int64v; break; case CASE(NC_INT64,NC_UINT): tmp.uint32v = (unsigned int)src->value.int64v; break; case CASE(NC_INT64,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.int64v; break; case CASE(NC_INT64,NC_SHORT): tmp.int16v = (short)src->value.int64v; break; case CASE(NC_INT64,NC_INT): tmp.int32v = (int)src->value.int64v; break; case CASE(NC_INT64,NC_INT64): tmp.int64v = (long long)src->value.int64v; break; case CASE(NC_INT64,NC_FLOAT): tmp.floatv = (float)src->value.int64v; break; case CASE(NC_INT64,NC_DOUBLE): tmp.doublev = (double)src->value.int64v; break; case CASE(NC_FLOAT,NC_BYTE): tmp.uint8v = (unsigned char)src->value.floatv; break; case CASE(NC_FLOAT,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.floatv; break; case CASE(NC_FLOAT,NC_USHORT): tmp.uint16v = (unsigned short)src->value.floatv; break; case CASE(NC_FLOAT,NC_UINT): tmp.uint32v = (unsigned int)src->value.floatv; break; case CASE(NC_FLOAT,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.floatv; break; case CASE(NC_FLOAT,NC_SHORT): tmp.int16v = (short)src->value.floatv; break; case CASE(NC_FLOAT,NC_INT): tmp.int32v = (int)src->value.floatv; break; case CASE(NC_FLOAT,NC_INT64): tmp.int64v = (long long)src->value.floatv; break; case CASE(NC_FLOAT,NC_FLOAT): tmp.floatv = src->value.floatv; break; case CASE(NC_FLOAT,NC_DOUBLE): tmp.doublev = (isnan(src->value.floatv)?NAN:(double)src->value.floatv); break; case CASE(NC_DOUBLE,NC_BYTE): tmp.uint8v = (unsigned char)src->value.doublev; break; case CASE(NC_DOUBLE,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.doublev; break; case CASE(NC_DOUBLE,NC_USHORT): tmp.uint16v = (unsigned short)src->value.doublev; break; case CASE(NC_DOUBLE,NC_UINT): tmp.uint32v = (unsigned int)src->value.doublev; break; case CASE(NC_DOUBLE,NC_UINT64): tmp.uint64v = (unsigned long long)src->value.doublev; break; case CASE(NC_DOUBLE,NC_SHORT): tmp.int16v = (short)src->value.doublev; break; case CASE(NC_DOUBLE,NC_INT): tmp.int32v = (int)src->value.doublev; break; case CASE(NC_DOUBLE,NC_INT64): tmp.int64v = (long long)src->value.doublev; break; case CASE(NC_DOUBLE,NC_FLOAT): tmp.floatv = (isnan(src->value.doublev)?NANF:(float)src->value.doublev); break; case CASE(NC_DOUBLE,NC_DOUBLE): tmp.doublev = (double)src->value.doublev; break; /* Conversion of a string to e.g. an integer should be what?*/ case CASE(NC_STRING,NC_BYTE): sscanf(src->value.stringv.stringv,"%hhd",&tmp.int8v); break; case CASE(NC_STRING,NC_UBYTE): sscanf(src->value.stringv.stringv,"%hhu",&tmp.uint8v); break; case CASE(NC_STRING,NC_USHORT): sscanf(src->value.stringv.stringv,"%hu",&tmp.uint16v); break; case CASE(NC_STRING,NC_UINT): sscanf(src->value.stringv.stringv,"%u",&tmp.uint32v); break; case CASE(NC_STRING,NC_UINT64): sscanf(src->value.stringv.stringv,"%llu",&tmp.uint64v); break; case CASE(NC_STRING,NC_SHORT): sscanf(src->value.stringv.stringv,"%hd",&tmp.int16v); break; case CASE(NC_STRING,NC_INT): sscanf(src->value.stringv.stringv,"%d",&tmp.int32v); break; case CASE(NC_STRING,NC_INT64): sscanf(src->value.stringv.stringv,"%lld",&tmp.int64v); break; case CASE(NC_STRING,NC_FLOAT): sscanf(src->value.stringv.stringv,"%g",&tmp.floatv); break; case CASE(NC_STRING,NC_DOUBLE): sscanf(src->value.stringv.stringv,"%lg",&tmp.doublev); break; case CASE(NC_STRING,NC_CHAR): tmp.charv = src->value.stringv.stringv[0]; break; case CASE(NC_STRING,NC_STRING): tmp.stringv.stringv = nulldup(src->value.stringv.stringv); tmp.stringv.len = src->value.stringv.len; break; /* What is the proper conversion for T->STRING?*/ case CASE(NC_CHAR,NC_STRING): sprintf(stmp,"%c",src->value.charv); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_BYTE,NC_STRING): sprintf(stmp,"%hhd",src->value.uint8v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_UBYTE,NC_STRING): sprintf(stmp,"%hhu",src->value.uint8v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_USHORT,NC_STRING): sprintf(stmp,"%hu",src->value.uint16v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_UINT,NC_STRING): sprintf(stmp,"%u",src->value.uint32v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_UINT64,NC_STRING): sprintf(stmp,"%llu",src->value.uint64v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_SHORT,NC_STRING): sprintf(stmp,"%hd",src->value.int16v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_INT,NC_STRING): sprintf(stmp,"%d",src->value.int32v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_INT64,NC_STRING): sprintf(stmp,"%lld",src->value.int64v); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_FLOAT,NC_STRING): sprintf(stmp,"%.8g",src->value.floatv); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_DOUBLE,NC_STRING): sprintf(stmp,"%.8g",src->value.doublev); tmp.stringv.len = nulllen(stmp); tmp.stringv.stringv = nulldup(stmp); break; case CASE(NC_OPAQUE,NC_CHAR): if(bytes) tmp.charv = *(char*)bytes; break; case CASE(NC_OPAQUE,NC_BYTE): if(bytes) tmp.uint8v = *(unsigned char*)bytes; break; case CASE(NC_OPAQUE,NC_UBYTE): if(bytes) tmp.uint8v = *(unsigned char*)bytes; break; case CASE(NC_OPAQUE,NC_USHORT): if(bytes) tmp.uint16v = *(unsigned short*)bytes; break; case CASE(NC_OPAQUE,NC_UINT): if(bytes) tmp.uint32v = *(unsigned int*)bytes; break; case CASE(NC_OPAQUE,NC_UINT64): if(bytes) tmp.uint64v = *(unsigned long long*)bytes; break; case CASE(NC_OPAQUE,NC_SHORT): if(bytes) tmp.int16v = *(short*)bytes; break; case CASE(NC_OPAQUE,NC_INT): if(bytes) tmp.int32v = *(int*)bytes; break; case CASE(NC_OPAQUE,NC_INT64): if(bytes) tmp.int64v = *(long long*)bytes; break; case CASE(NC_OPAQUE,NC_FLOAT): if(bytes) tmp.floatv = *(float*)bytes; break; case CASE(NC_OPAQUE,NC_DOUBLE): if(bytes) tmp.doublev = *(double*)bytes; break; case CASE(NC_OPAQUE,NC_OPAQUE): tmp.opaquev.stringv = (char*)malloc(src->value.opaquev.len+1); memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv,src->value.opaquev.len); tmp.opaquev.len = src->value.opaquev.len; tmp.opaquev.stringv[tmp.opaquev.len] = '\0'; break; /* We are missing all CASE(X,NC_ECONST) cases*/ default: semerror(lineno,"transform: illegal conversion: %s/%d -> %s/%d", nctypename(src->nctype),src->nctype, nctypename(dst->nctype),dst->nctype); break;; } if(bytes != NULL) efree(bytes); /* cleanup*/ /* overwrite minimum necessary parts*/ dst->value = tmp; }
static void generate_primdata(Symbol* basetype, NCConstant* prim, Bytebuffer* codebuf, Datalist* filler, Generator* generator) { NCConstant target; int match; if(prim == NULL || isfillconst(prim)) { Datalist* fill = (filler==NULL?getfiller(basetype):filler); ASSERT(fill->length == 1); prim = datalistith(fill,0); } ASSERT(prim->nctype != NC_COMPOUND); /* Verify that the constant is consistent with the type */ match = 1; switch (prim->nctype) { case NC_CHAR: case NC_BYTE: case NC_SHORT: case NC_INT: case NC_FLOAT: case NC_DOUBLE: case NC_UBYTE: case NC_USHORT: case NC_UINT: case NC_INT64: case NC_UINT64: case NC_STRING: match = (basetype->subclass == NC_PRIM ? 1 : 0); break; #ifdef USE_NETCDF4 case NC_NIL: match = (basetype->subclass == NC_PRIM && basetype->typ.typecode == NC_STRING ? 1 : 0); break; case NC_OPAQUE: /* OPAQUE is also consistent with numbers */ match = (basetype->subclass == NC_OPAQUE || basetype->subclass == NC_PRIM ? 1 : 0); break; case NC_ECONST: match = (basetype->subclass == NC_ENUM ? 1 : 0); if(match) { /* Make sure this econst belongs to this enum */ Symbol* ec = prim->value.enumv; Symbol* en = ec->container; match = (en == basetype); } break; #endif default: match = 0; } if(!match) { semerror(constline(prim),"Data value is not consistent with the expected type: %s", basetype->name); } target.nctype = basetype->typ.typecode; if(target.nctype != NC_ECONST) { convert1(prim,&target); } switch (target.nctype) { case NC_ECONST: if(basetype->subclass != NC_ENUM) { semerror(constline(prim),"Conversion to enum not supported (yet)"); } break; case NC_OPAQUE: normalizeopaquelength(&target,basetype->typ.size); break; default: break; } generator->constant(generator,&target,codebuf); return; }
/* Recursive helper that does the bulk of the work */ static int bin_generate_data_r(NCConstant* instance, Symbol* tsym, Datalist* fillvalue, Bytebuffer* databuf) { int stat = NC_NOERR; if(instance->nctype == NC_FILLVALUE) { /* replace with fillvalue for the type */ Datalist* filllist = (fillvalue == NULL ? getfiller(tsym) : fillvalue); ASSERT(datalistlen(filllist)==1) instance = datalistith(filllist,0); } switch (tsym->subclass) { case NC_PRIM: { switch (tsym->nc_id) { case NC_CHAR: { char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_CHAR; convert1(instance,tmp); p = &tmp->value.charv;; bbAppendn(databuf,p,sizeof(char)); reclaimconstant(tmp); } break; case NC_BYTE: { signed char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_BYTE; convert1(instance,tmp); p = &tmp->value.int8v; bbAppendn(databuf,p,sizeof(signed char)); reclaimconstant(tmp); } break; case NC_UBYTE: { unsigned char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UBYTE; convert1(instance,tmp); p = &tmp->value.uint8v; bbAppendn(databuf,p,sizeof(unsigned char)); reclaimconstant(tmp); } break; case NC_SHORT: { short* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_SHORT; convert1(instance,tmp); p = &tmp->value.int16v; bbAppendn(databuf,p,sizeof(short)); reclaimconstant(tmp); } break; case NC_USHORT: { unsigned short* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_USHORT; convert1(instance,tmp); p = &tmp->value.uint16v; bbAppendn(databuf,p,sizeof(unsigned short)); reclaimconstant(tmp); } break; case NC_INT: { int* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_INT; convert1(instance,tmp); p = &tmp->value.int32v; bbAppendn(databuf,p,sizeof(int)); reclaimconstant(tmp); } break; case NC_UINT: { unsigned int* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UINT; convert1(instance,tmp); p = &tmp->value.uint32v; bbAppendn(databuf,p,sizeof(unsigned int)); reclaimconstant(tmp); } break; case NC_INT64: { long long* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_INT64; convert1(instance,tmp); p = &tmp->value.int64v; bbAppendn(databuf,p,sizeof(long long)); reclaimconstant(tmp); } break; case NC_UINT64: { unsigned long long* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UINT64; convert1(instance,tmp); p = &tmp->value.uint64v; bbAppendn(databuf,p,sizeof(unsigned long long)); reclaimconstant(tmp); } break; case NC_FLOAT: { float* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_FLOAT; convert1(instance,tmp); p = &tmp->value.floatv; bbAppendn(databuf,p,sizeof(float)); reclaimconstant(tmp); } break; case NC_DOUBLE: { double* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_DOUBLE; convert1(instance,tmp); p = &tmp->value.doublev; bbAppendn(databuf,p,sizeof(double)); reclaimconstant(tmp); } break; case NC_STRING: { char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_STRING; convert1(instance,tmp); p = emalloc(tmp->value.stringv.len+1); memcpy(p,tmp->value.stringv.stringv,tmp->value.stringv.len); p[tmp->value.stringv.len] = '\0'; bbAppendn(databuf,&p,sizeof(char*)); reclaimconstant(tmp); } break; default: stat = NC_EINTERNAL; goto done; /* Should never happen */ } break; /*switch*/ } break; /*NC_PRIM*/ case NC_ENUM: { Symbol* basetype = tsym->typ.basetype; /* Pretend */ stat = bin_generate_data_r(instance,basetype,fillvalue,databuf); } break; case NC_OPAQUE: { unsigned char* bytes = NULL; size_t len = 0; if(instance->nctype != NC_OPAQUE) {stat = NC_EBADTYPE; goto done;} /* Assume the opaque string has been normalized */ bytes=makebytestring(instance->value.opaquev.stringv,&len); if(bytes == NULL) {stat = NC_ENOMEM; goto done;} bbAppendn(databuf,(void*)bytes,len); free(bytes); } break; case NC_VLEN: { Datalist* sublist = NULL; Bytebuffer* vlendata = NULL; nc_vlen_t p; if(instance->nctype != NC_COMPOUND) { nclog(NCLOGERR,"Translating vlen: expected sublist"); stat = NC_EBADTYPE; goto done; } sublist = instance->value.compoundv; vlendata = bbNew(); if((stat = binary_generate_data(sublist,tsym->typ.basetype,NULL,vlendata))) goto done; p.len = datalistlen(sublist); p.p = bbContents(vlendata); bbAppendn(databuf,(char*)&p,sizeof(nc_vlen_t)); } break; case NC_COMPOUND: { /* The really hard one */ size_t nfields, fid, i; Datalist* cmpd = instance->value.compoundv; write_alignment(tsym->typ.cmpdalign,databuf); /* Get info about each field in turn and build it*/ nfields = listlength(tsym->subnodes); for(fid=0;fid<nfields;fid++) { Symbol* field = listget(tsym->subnodes,fid); NCConstant* fieldinstance = datalistith(cmpd,fid); int ndims = field->typ.dimset.ndims; size_t arraycount; if(ndims == 0) { ndims=1; /* fake the scalar case */ } /* compute the total number of elements in the field array */ arraycount = 1; for(i=0;i<ndims;i++) arraycount *= field->typ.dimset.dimsyms[i]->dim.declsize; write_alignment(field->typ.alignment,databuf); /* Write the instances */ for(i=0;i<arraycount;i++) { if((stat = bin_generate_data_r(fieldinstance, field->typ.basetype, NULL, databuf))) goto done; } } } break; default: stat = NC_EINTERNAL; goto done; /* Should never happen */ } done: return stat; }
int main() { printf("Start...."); start: printf("\n(input) "); //계산기 프로그램 시작 scanf("%s", in1); str_in1 = strlen(in1); c_hoice(); if (chosen != 1){ scanf("%s", in2); str_in2 = strlen(in2); scanf("%s", in3); str_in3 = strlen(in3); check_sign_in1(); check_sign_in3(); re_array_in1(); re_array_in3(); separate(); if(in2[0] == '-'){ if(minus_sign_count == 0) in2[0] = '-'; else if(minus_sign_count == 1){ if(if_minus_first == 1){ in2[0] = '+'; when_put_minus =1;} if(if_minus_last == 1) in2[0] = '+';} else{ in2[0] = '-'; when_remove_minus =1;}} else if(in2[0] == '+'){ if(minus_sign_count == 0) in2[0] = '+'; else if(minus_sign_count == 1){ if(if_minus_first == 1) in2[0] = '-'; if(if_minus_last == 1) in2[0] = '-';} else{ in2[0] = '+'; when_put_minus=1;}} else if(in2[0] == '*'){ if(minus_sign_count == 0 || minus_sign_count == 2) in2[0] = '*'; else if(minus_sign_count == 1){ in2[0] = '*'; when_put_minus=1;}} else if(in2[0] == '/'){ if(minus_sign_count == 0 || minus_sign_count == 2) in2[0] = '/'; else if(minus_sign_count == 1){ in2[0] = '/'; when_put_minus=1;}} else if(in2[0] == '%'){ if(minus_sign_count == 0 || minus_sign_count == 2) in2[0] = '%'; else if(minus_sign_count == 1){ in2[0] = '%'; when_put_minus=1;}} switch (in2[0]) { case '+' : { invert1(); convert1(); plus(); convert2(); invert2(); break; } case '-' : { invert1(); compare(); convert1(); minus(); convert2(); invert2(); break; } case '*' : { invert1(); invert1_mul_s(); multiply(); invert2(); invert2_mul_s(); break; } case '/' : { invert1(); compare(); convert1(); divide(); convert2(); invert2(); break; } case '%' : { invert1(); compare(); convert1(); remain(); convert2(); invert2(); break; } default: ; } printf(" = "); if(when_put_minus == 1) printf("-"); // if(when_remove_minus == 1) //여기서 - 부호 하나를 배열에서 빼주는 명령어 쓸 수 없을까? if (daeso == 1) printf("-"); comma(res_j); if (p != 0) {printf("."); comma(res_s);} } initialization(); goto start; return 0; }
int main() { printf("Start...."); start: printf("\n(input) "); //계산기 프로그램 시작 input(); error(); if(again == 1) { initialization(); goto start; } c_hoice(); if (chosen != 1){ //in1에 입력받은 문자가 1자리 대소문자가 아닌 경우 var_cal(); if (var_cal_switch == 1) { printf(" = error\n"); initialization(); goto start; } check_sign_in1(); // input1 +/- 부호 체크 check_sign_in3(); // input3 +/- 부호 체크 re_array_in1(); // 다항 연산 고려 순서 바꿔 저장 re_array_in3(); // 다항 연산 고려 순사 바꿔 저장 separate(); which_sign(); switch (in2[0]) { case '+' : { invert1(); convert1(); plus(); convert2(); invert2(); break; } case '-' : { invert1(); compare(); convert1(); minus(); convert2(); invert2(); break; } case '*' : { invert1(); invert1_mul_s(); multiply(); invert2(); invert2_mul_s(); break; } case '/' : { dividing(); break; } case '%' : { remain2(); break; } default: ; } printf(" = "); if(when_put_minus == 1) printf("-"); if (daeso == 1) printf("-"); comma(res_j); if (p != 0) {printf("."); comma(res_s);} } initialization(); goto start; return 0; }
string convert1(string loc,string byte) { string s = loc; string b = byte; string u,v; string y="NULL"; string x,j; int n,m,k,p,q,c=0,r=0,e,f; n= s.length(); m= b.length(); f=n-m;//int f is difference in the length of the two strings v=s.substr(0,f);//string v is the extra string of larger string for(int i=m-1;i>=0;i--) { //p is the equivalent c=0; //cout<<"f+i="<<s[f+i]<<endl; if(s[f+i]=='A') { p=10; } else if(s[f+i]=='B') { p=11; } else if(s[f+i]=='C') { p=12; } else if(s[f+i]=='D') { p=13; } else if(s[f+i]=='E') { p=14; } else if(s[f+i]=='F') { p=15; } else p=s[f+i]-'0';//to convert the character to int //cout<<"p="<<p<<endl; if(b[i]=='A') { q=10; } else if(b[i]=='B') { q=11; } else if(b[i]=='C') { q=12; } else if(b[i]=='D') { q=13; } else if(b[i]=='E') { q=14; } else if(b[i]=='F') { q=15; } else q=b[i]-'0'; //cout<<"q="<<q<<endl; if(p<q) { c=1; k=p+16-q; //cout<<s[f+i-1]; s[f+i-1]=((s[f+i-1]-'0')-1)+'0'; //cout<<s[f+i-1]; } else k=p-q; //cout<<"k="<<k<<endl; //if(k>15) //r=k%16; r=k; //c=k/16; //cout<<"r="<<r<<endl; //cout<<"c="<<c<<endl; if (r>9) { switch(r) { case 10: x='A'; break; case 11: x='B'; break; case 12: x='C'; break; case 13: x='D'; break; case 14: x='E'; break; case 15: x='F'; break; } } else x=r+'0'; //cout<<"x="<<x<<endl; //j=c+'0'; //cout<<"j="<<j<<endl; y=x; //cout<<"y"<<y<<endl; if (f+i==3) u=y; else u=y+u; //cout<<"u="<<u<<endl; } if(c==1) v=convert1(v,"1"); return v+u; }
static void genbin_primdata(Symbol* basetype, Datasrc* src, Datalist* fillsrc, Bytebuffer* memory) { Constant* prim; Constant target; prim = srcnext(src); if(prim == NULL || prim->nctype == NC_FILLVALUE) { genbin_fillvalue(basetype,fillsrc,src,memory); return; } target.nctype = basetype->typ.typecode; if(prim == NULL) { #ifdef GENFILL /* generate a fill value*/ nc_getfill(&target); /* fall thru*/ #else return; #endif } ASSERT(prim->nctype != NC_COMPOUND); if(target.nctype != NC_ECONST) { convert1(prim,&target); alignbuffer(&target,memory); } switch (target.nctype) { case NC_ECONST: if(basetype->subclass != NC_ENUM) { semerror(prim->lineno,"Conversion to enum not supported (yet)"); } else { Datalist* econ = builddatalist(1); srcpushlist(src,econ); dlappend(econ,&prim->value.enumv->typ.econst); genbin_primdata(prim->value.enumv->typ.basetype,src, fillsrc,memory); srcpop(src); } break; case NC_OPAQUE: { unsigned char* bytes; size_t len; setprimlength(&target,basetype->typ.size*2); bytes=makebytestring(target.value.opaquev.stringv,&len); bbAppendn(memory,(void*)bytes,len); } break; case NC_CHAR: bbAppendn(memory,&target.value.charv,sizeof(target.value.charv)); break; case NC_BYTE: bbAppendn(memory,(void*)&target.value.int8v,sizeof(target.value.int8v)); break; case NC_SHORT: bbAppendn(memory,(void*)&target.value.int16v,sizeof(target.value.int16v)); break; case NC_INT: bbAppendn(memory,(void*)&target.value.int32v,sizeof(target.value.int32v)); break; case NC_FLOAT: bbAppendn(memory,(void*)&target.value.floatv,sizeof(target.value.floatv)); break; case NC_DOUBLE: bbAppendn(memory,(void*)&target.value.doublev,sizeof(target.value.doublev)); break; case NC_UBYTE: bbAppendn(memory,(void*)&target.value.uint8v,sizeof(target.value.uint8v)); break; case NC_USHORT: bbAppendn(memory,(void*)&target.value.uint16v,sizeof(target.value.uint16v)); break; case NC_UINT: bbAppendn(memory,(void*)&target.value.uint32v,sizeof(target.value.uint32v)); break; case NC_INT64: { union SI64 { char ch[8]; long long i64;} si64; si64.i64 = target.value.int64v; bbAppendn(memory,(void*)si64.ch,sizeof(si64.ch)); } break; case NC_UINT64: { union SU64 { char ch[8]; unsigned long long i64;} su64; su64.i64 = target.value.uint64v; bbAppendn(memory,(void*)su64.ch,sizeof(su64.ch)); } break; case NC_STRING: { if(usingclassic) { bbAppendn(memory,target.value.stringv.stringv,target.value.stringv.len); } else if(target.nctype == NC_CHAR) { bbAppendn(memory,target.value.stringv.stringv,target.value.stringv.len); } else { char* ptr; int len = (size_t)target.value.stringv.len; ptr = poolalloc(len+1); /* CAREFUL: this has short lifetime*/ memcpy(ptr,target.value.stringv.stringv,len); ptr[len] = '\0'; bbAppendn(memory,(void*)&ptr,sizeof(ptr)); } } break; default: PANIC1("genbin_primdata: unexpected type: %d",target.nctype); } }
void test() { __v16sc gv1; __v16uc gv2; __v8ss gv3; __v8us gv4; __v4si gv5; __v4ui gv6; __v2sll gv7; __v2ull gv8; __v1slll gv9; __v1ulll gv10; __v4f gv11; __v2d gv12; vector signed char av1; vector unsigned char av2; vector signed short av3; vector unsigned short av4; vector signed int av5; vector unsigned int av6; vector signed long long av7; vector unsigned long long av8; vector signed __int128 av9; vector unsigned __int128 av10; vector float av11; vector double av12; vector bool int av13; vector pixel short av14; __v16sc *gv1_p = convert1(gv1); __v16uc *gv2_p = convert1(gv2); __v8ss *gv3_p = convert1(gv3); __v8us *gv4_p = convert1(gv4); __v4si *gv5_p = convert1(gv5); __v4ui *gv6_p = convert1(gv6); __v2sll *gv7_p = convert1(gv7); __v2ull *gv8_p = convert1(gv8); __v1slll *gv9_p = convert1(gv9); __v1ulll *gv10_p = convert1(gv10); __v4f *gv11_p = convert1(gv11); __v2d *gv12_p = convert1(gv12); vector signed char *av1_p = convert2(av1); vector unsigned char *av2_p = convert2(av2); vector signed short *av3_p = convert2(av3); vector unsigned short *av4_p = convert2(av4); vector signed int *av5_p = convert2(av5); vector unsigned int *av6_p = convert2(av6); vector signed long long *av7_p = convert2(av7); vector unsigned long long *av8_p = convert2(av8); vector signed __int128 *av9_p = convert2(av9); vector unsigned __int128 *av10_p = convert2(av10); vector float *av11_p = convert2(av11); vector double *av12_p = convert2(av12); convert2(av13); // expected-error {{call to 'convert2' is ambiguous}} convert2(av14); // expected-error {{call to 'convert2' is ambiguous}} }