int ppScan(){ refine(SET); if((currentToken=scan())!=TPROGRAM){ errPrint("There is no \"program\"");//return -1; } int r=evaluateWord(SPROGRAM); refine(FIN); printList(); return r; }
struct variable *countup(char *np,int useLine,char *scope){ //add count "np" struct variable *p; struct occurrence *occur; if((p=search(np,scope))==NULL){ //for not first time errPrint("havenot dec\n"); }else { if((occur=(struct occurrence *)malloc(sizeof(struct occurrence)))==NULL) { errPrint("can not malloc in countup\n"); } occur->nextOccur=NULL; occur->use=useLine; if(p->occur==NULL){ p->occur=occur; }else{ p->lastoccur->nextOccur=occur; } p->lastoccur=occur; } return p; }
static void drop(IAttachment** att) { // With CheckStatusWrapper passed as status interface noting is thrown on error // You should check status yourself CheckStatusWrapper status(master->getStatus()); // drop database (will close interface) (*att)->dropDatabase(&status); if (status.getState() && IStatus::STATE_ERRORS) { errPrint(&status); fprintf(stderr, "*** Drop database failed - do it manually before next run ***\n"); } else *att = NULL; // cleanup status.dispose(); }
/* Allocate RX buffer */ Ptr DDA_cpmac_net_alloc_rx_buf(CpmacNetDevice * hDDA, Int bufSize, DDC_NetDataToken * dataToken, Uint32 channel, Ptr allocArgs) { struct net_device *p_dev = hDDA->owner; struct sk_buff *p_skb; p_skb = dev_alloc_skb(hDDA->rxBufSize); if (p_skb == NULL) { #ifdef CPMAC_DDA_DEBUG /* We dont want the error printf to appear on screen as it clogs the serial port */ errPrint ("DDA_cpmac_net_alloc_rx_buf:Failed to allocate skb for %s.\n", p_dev->name); #endif /* */ return (NULL); }
int main() { int rc = 0; // set default password if none specified in environment setenv("ISC_USER", "sysdba", 0); setenv("ISC_PASSWORD", "masterkey", 0); // With ThrowStatusWrapper passed as status interface FbException will be thrown on error ThrowStatusWrapper status(master->getStatus()); // Declare pointers to required interfaces IProvider* prov = master->getDispatcher(); IAttachment* att = NULL; ITransaction* tra = NULL; IBlob* blob = NULL; try { // create database att = prov->createDatabase(&status, "blob_07.fdb", 0, NULL); tra = att->startTransaction(&status, 0, NULL); // create table att->execute(&status, tra, 0, "create table blobs_table (b blob sub_type text)", SAMPLES_DIALECT, NULL, NULL, NULL, NULL); tra->commitRetaining(&status); // Message for data exchange FB_MESSAGE(Msg, ThrowStatusWrapper, (FB_BLOB, b) ) message(&status, master); message.clear(); // create blob blob = att->createBlob(&status, tra, &message->b, 0, NULL); // populate blob with data for (const char** seg = testData; *seg; ++seg) blob->putSegment(&status, strlen(*seg), *seg); blob->close(&status); blob = NULL; // insert blob into the table att->execute(&status, tra, 0, "insert into blobs_table(b) values(?)", SAMPLES_DIALECT, message.getMetadata(), message.getData(), NULL, NULL); tra->commitRetaining(&status); printf("Test blob inserted into blobs_table\n...\n"); // Read blob from table message.clear(); att->execute(&status, tra, 0, "select first(1) b from blobs_table", SAMPLES_DIALECT, NULL, NULL, message.getMetadata(), message.getData()); blob = att->openBlob(&status, tra, &message->b, 0, NULL); // Read segments from blob // Use very small segment buffer to show read of incomplete segment printf("Read inserted blob from blobs_table\n...\n"); int bufOver = 0; for(bool eof = false; !eof; ) { const char* lineFeed = "\n"; char buf[32]; unsigned l = 0; switch (blob->getSegment(&status, sizeof(buf) - 1, buf, &l)) { case IStatus::RESULT_OK: break; case IStatus::RESULT_SEGMENT: lineFeed = ""; bufOver++; break; default: eof = true; continue; } buf[l] = 0; printf("%s%s", buf, lineFeed); } printf("\nSegment not fit in buffer counter = %d\n\n", bufOver); // cleanup blob->close(&status); blob = NULL; tra->commit(&status); tra = NULL; // uncomment next line to play with errors during drop database // printf("Attach with any client to blob_07.fdb to prevent it being dropped and press enter"); getchar(); // drop database drop(&att); } catch (const FbException& error) { // handle error rc = 1; errPrint(error.getStatus()); if (att) drop(&att); } // release interfaces after error caught if (blob) blob->release(); if (tra) tra->release(); if (att) att->release(); status.dispose(); prov->release(); return rc; }
void enterScopeErrCheck(SymTabEntry* se) { errPrint(stm.enterScope(se), se->name()); }
ErrorST insertSymbolErrCheck(SymTabEntry* se) { ErrorST err = stm.insert(se); errPrint(err, se->name()); return err; }
int evaluateSyntax(int scode){ char *scodeStr=syntaxString[scode-NUMOFTOKEN]; int *temp=syntaxInner[scode-NUMOFTOKEN]; int j=1; if(currentToken<0){ printf("EOF\n");return -1; } /*evaluate SPROGRAM*/ if(scode==SPROGRAM){ logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber); for(j=1;j<=5;j++){ if(evaluateWord(temp[j])<0){ errPrint("evaluateSyntax(%s)->(%d)",scodeStr,temp[j]); } if(j==2){ setupProgram(tmpString); #ifdef CSL sprintf(cName,"%s.%s",filename,FILETYPE); if((cFile=fopen(cName,"w"))==NULL){ exit(-1); } TAGCOMB("$$",idList.prog->name->name); START(tag); LAD("\t","gr0","0"); CALL("\t","L1"); tagnum++; CALL("\t","FLUSH"); SVC("\t","0"); fclose(cFile); #endif } } #ifdef CSL if((cFile=fopen(cName,"a"))==NULL) exit(-1); END(""); //printTextFile("cFile","library.txt"); fclose(cFile); #endif return(scode); } /*evaluate SBROCK*/ else if(scode==SBROCK){ scope=idList.prog->name->name; logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber); do{ if(currentToken==TVAR){ //except check pPrint(ALLOWINDENT); if(evaluateWord(SVARDECLARE)<0){ errPrint("evaluateSyntax(%s)->(%d)",scodeStr,SVARDECLARE); } }else if(currentToken==TPROCEDURE){ //except check pPrint(ALLOWINDENT); if(evaluateWord(SSUBPROGDECLARE)<0){ errPrint("evaluateSyntax(%s)->(%d)",scodeStr,TPROCEDURE); } }else{ j++; } }while(j==1); pPrint(RESETINDENT); #ifdef CSL if((cFile=fopen(cName,"a"))==NULL) exit(-1); // TAGNAME("L"); TAGCOMB("L","1"); TAGPRINT(tag); fclose(cFile); #endif if(evaluateWord(temp[3])<0){ errPrint("evaluateSyntax(%s)->(%d)",scodeStr,temp[3]); } return(scode); } /*evaluate SVARDECLARE*/ else if(scode==SVARDECLARE){ logPutOut(" evaluateSyntax(%s) line:%d\n",scodeStr,lastLineNumber); int tempType; for(j=1;j<=3;j++){ if(evaluateWord(temp[j])<0){ errPrint("no var(var declaretion)\n"); } if(j==1){ pPrint(ADDINDENT,1); } } if((tempType=evaluateWord(temp[j++]))<0){//j=4 errPrint("must be type\n"); } int arrayNum=0; if(tempType==SARRAY){ arrayNum=tempArray.arrayNum; tempType=tempArray.type; } int k; for(k=0;k<tempListCount;k++){ #ifdef CSL if((cFile=fopen(cName,"a"))==NULL) exit(-1); if(arrayNum==0){ if(scope==idList.prog->name->name){ TAGCOMB("$",tempList->word); }else{ TAGCOMB2("$",tempList->word,"\%",scope); } DC(tag,"0"); }else{ int arr; for(arr=0;arr<=arrayNum;arr++){ if(scope==idList.prog->name->name){ TAGCOMBARRAY("$",tempList->word,arr); }else{ TAGCOMBARRAY2("$",tempList->word,arr,"\%",scope); } DC(tag,"0"); } } fclose(cFile); #endif if(registerList(tempList->word,tempType,arrayNum,lastLineNumber,POSI_VAR,scope)<0){ errPrint("double variable\n"); } tempList=tempList->next; } clearWordList(); if(evaluateWord(temp[j++])<0){//j=5 errPrint("must be ;\n"); } while(1){ int i=j=6; if(validateTopOfSyntax(temp[i])<0){// if there is no first word, it is correct break; //if nothing, its correct }else{ pPrint(ALLOWINDENT); for(i=j;i<=temp[0];i++){ if((tempType=evaluateWord(temp[i]))<0){// varlist printf("errEI1\n");return -1; } if(i==8){ int arrayNum=0; if(tempType>SARRAY){ arrayNum=tempType-SARRAY; tempType=SARRAY; } int k; for(k=0;k<tempListCount;k++){ #ifdef CSL if((cFile=fopen(cName,"a"))==NULL) exit(-1); if(arrayNum==0){ if(scope==idList.prog->name->name){ TAGCOMB("$",tempList->word); }else{ TAGCOMB2("$",tempList->word,"\%",scope); } DC(tag,"0"); }else{ int arr; for(arr=0;arr<=arrayNum;arr++){ if(scope==idList.prog->name->name){ TAGCOMBARRAY("$",tempList->word,arr); }else{ TAGCOMBARRAY2("$",tempList->word,arr,"\%",scope); } DC(tag,"0"); } } fclose(cFile); #endif if(registerList(tempList->word,tempType,arrayNum,lastLineNumber,POSI_VAR,scope)<0){ errPrint("double variable\n"); } tempList=tempList->next; } clearWordList(); } } } } } /*evaluate SVARLIST*/ else if(scode==SVARLIST){//1:{2} patern
int registerList(char *np,int npType,int arrayNum,int defLine,int position,char *scope){ //add count "np" registerTrriger=ON; struct variable *vp; struct function *fp; char *cp; if(strcmp(scope,idList.prog->name->name)==0){//register in highScope if(position==POSI_FUNC){ if(search(np,scope)!=NULL){ errPrint("double in scope\n"); } if((vp=(struct variable *)malloc(sizeof(struct variable)))==NULL) { printf("can not malloc variable in countup\n");return -1; } if((fp=(struct function *)malloc(sizeof(struct function)))==NULL) { printf("can not malloc function in countup\n");return -1; } if((cp = (char *)malloc(strlen(np)+1)) == NULL) { printf("can not malloc char in countup\n");return -1; } strcpy(cp,np); vp->name=cp;vp->type=npType;vp->arrayNum=arrayNum;vp->def=defLine;vp->nextVar=NULL; fp->name=vp;fp->arg=NULL;fp->var=NULL;fp->nextFunc=NULL; if(idList.func!=NULL){//connect function and list idList.lastfunc->nextFunc=fp; }else{ idList.func=fp; } idList.lastfunc=fp; }else if(position==POSI_VAR){ if(search(np,scope)!=NULL){ errPrint("double in scope\n"); } if((vp=(struct variable *)malloc(sizeof(struct variable)))==NULL) { printf("can not malloc variable in countup\n");return -1; } if((cp = (char *)malloc(strlen(np)+1)) == NULL) { printf("can not malloc char in countup\n");return -1; } strcpy(cp,np); vp->name=cp;vp->type=npType;vp->arrayNum=arrayNum;vp->def=defLine;vp->nextVar=NULL; if(idList.var!=NULL){//connect function and list idList.lastvar->nextVar=vp; }else{ idList.var=vp; } idList.lastvar=vp; } }else{//register in localScope if(position==POSI_ARG){ if(search(np,scope)!=NULL){ errPrint("double in scope\n"); } if((vp=(struct variable *)malloc(sizeof(struct variable)))==NULL) { printf("can not malloc variable in countup\n");return -1; } if((cp = (char *)malloc(strlen(np)+1)) == NULL) { printf("can not malloc char in countup\n");return -1; } strcpy(cp,np); vp->name=cp;vp->type=npType;vp->arrayNum=arrayNum;vp->def=defLine;vp->nextVar=NULL; for(fp=idList.func;fp!= NULL;fp=fp->nextFunc){//function name if(strcmp(scope, fp->name->name)==0){ if(fp->arg!=NULL){ fp->lastarg->nextVar=vp; }else{ fp->arg=vp; } fp->lastarg=vp; } } }else if(position==POSI_VAR){ if(search(np,scope)!=NULL){ errPrint("double in scope\n"); } if((vp=(struct variable *)malloc(sizeof(struct variable)))==NULL) { printf("can not malloc variable in countup\n");return -1; } if((cp = (char *)malloc(strlen(np)+1)) == NULL) { printf("can not malloc char in countup\n");return -1; } strcpy(cp,np); vp->name=cp;vp->type=npType;vp->arrayNum=arrayNum;vp->def=defLine;vp->nextVar=NULL; for(fp=idList.func;fp!= NULL;fp=fp->nextFunc){ if(strcmp(scope, fp->name->name)==0){ if(fp->var!=NULL){ fp->lastvar->nextVar=vp; }else{ fp->var=vp; } fp->lastvar=vp; } } } } registerTrriger=OFF; return 1; }