int main(void) { int startFunction(int n); int Cal(int n); int n, a, i; int sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); sum += startFunction(a); } printf("%d\n", sum); }
void processLine(FILE * logf, struct SCRIPT * script, struct TYPING * types, unsigned long location, struct LINE * line){ char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char)); int nbtokens, i, j, index, storobj=-1, valobj=-1; int calldetected; //Detect system calls calldetected = monitorSytemCalls(logf,script,types,location,line); //Parse line nbtokens = decomposeLine(line->line,tokens,TOKENMAXNB,TOKENSIZE); for(i=0;i<nbtokens;i++){ //Monitor string and processing and treat dependency if(!strcasecmp(ACCESS(tokens,i),"Mid") ||!strcasecmp(ACCESS(tokens,i),"Left") ||!strcasecmp(ACCESS(tokens,i),"Ucase") ||!strcasecmp(ACCESS(tokens,i),"Lcase") ||!strcasecmp(ACCESS(tokens,i),"LTrim") ||!strcasecmp(ACCESS(tokens,i),"RTrim") ||!strcasecmp(ACCESS(tokens,i),"Replace")){ int newstor = 0; int obj = isKnownObject(types,ACCESS(tokens,i+1)); if(obj>-1 && i>=2 && ((char *)ACCESS(tokens,i-1))[0]=='='){ int storobj = isKnownObject(types,ACCESS(tokens,i-2)); if(storobj==-1){ newstor = 1, storobj = addNewObject(types,NULL,getObjectNature(types,obj)); addObjectReference(types,storobj,ACCESS(tokens,i-2)); setObjectType(types,storobj,getObjectType(types,obj)); }else{ setObjectNature(types,storobj,getObjectNature(types,obj)); setObjectType(types,storobj,getObjectType(types,obj)); } if(newstor){strcpy_s(types->objects[storobj].ObjectName, NAME_MAX_LENGTH,types->objects[obj].ObjectName);} printLogEntry(logf, types, OP_AFF, storobj, obj); } } //Detect string proceclocal procedure and function calls index = isLocalProcedure(script,ACCESS(tokens,i)); if(index>-1){ //Avoid recursive calls //if((location&0xF0000000)==PROCLEVEL // && index==(location&0x0FFFFFFF)){ if(script->procedureslist[index].beingexecuted){ printf("[+] Block recursive call to procedure %s\n", script->procedureslist[index].name); }else{ script->procedureslist[index].beingexecuted = 1; //No return value, so can not be an affectation startProcedure(logf,script,types,index,line); script->procedureslist[index].beingexecuted = 0; } free(tokens); return; }else{ index = isLocalFunction(script,ACCESS(tokens,i)); if(index>-1){ if(strcmp(ACCESS(tokens,i+1),"=")){//Avoid return values //Avoid recursive calls if(script->functionslist[index].beingexecuted){ printf("[+] Block recursive call to function %s\n", script->functionslist[index].name); }else{ script->functionslist[index].beingexecuted = 1; startFunction(logf,script,types,index,line); script->functionslist[index].beingexecuted = 0; } free(tokens); return; }else{ line->type = AFFECTATION; updateReturnStorage(types, script->functionslist[index].name, ACCESS(tokens,i+2)); free(tokens); return; }//if call or return } } } if(calldetected) return; //Detect affectation of known object for(i=0;i<nbtokens;i++){ if(((char *)ACCESS(tokens,i))[0]=='='||!strcasecmp(ACCESS(tokens,i),"in")){ int maxobj = -1; int maxtype; int nullnat = 0; int newstor = 0; int nbconselem; //Number of consecutive elements must int isarray = 0;//be < 2 except using & and array to concatenate //Either creation or retrieving of store object storobj = isKnownObject(types,ACCESS(tokens,i-1)); if(storobj==-1){ newstor = 1; storobj = addNewObject(types,NULL,0); addObjectReference(types,storobj,ACCESS(tokens,i-1)); }//if unknown maxtype = getObjectType(types,storobj); nbconselem = 0; //Look for significant passing value for(j=i+1;j<nbtokens;j++){ if(!strcasecmp(ACCESS(tokens,j),"Array")){ isarray = 1; j++; }//if if(((char *)ACCESS(tokens,j))[0]=='&'){ nbconselem = 0; }else{ //Checks if access to a static attribute char stataccess[TOKENSIZE+5]; strcpy_s(stataccess,5+TOKENSIZE,ACCESS(tokens,j)); strcat_s(stataccess,5+TOKENSIZE,"."); if(strcasestr(line->line,stataccess)){ nbconselem = 0; }else{ nbconselem++; } }//if if(!isarray && nbconselem>1) break; valobj = isKnownObject(types,ACCESS(tokens,j)); if(valobj>-1){//known objects //Update store type when significant if(getObjectType(types,valobj)>maxtype){ maxtype = getObjectType(types,valobj); maxobj = valobj; } }else if(ClassifyObject(ACCESS(tokens,j),&nullnat)>maxtype){//typed object maxobj = addNewObject(types,ACCESS(tokens,j),nullnat); maxtype = getObjectType(types,maxobj); }//if }//for if(maxobj>-1){ line->type = AFFECTATION; setObjectType(types,storobj,getObjectType(types,maxobj)); setObjectNature(types,storobj,getObjectNature(types,maxobj)); if(newstor){strcpy_s(types->objects[storobj].ObjectName, NAME_MAX_LENGTH,types->objects[maxobj].ObjectName);} printLogEntry(logf, types, OP_AFF, storobj, maxobj); } }//if '=' found }//for free(tokens); }