char *FindFileInPath(char *InBuff, char *File, char *Path) { char *Tempstr=NULL, *CurrPath=NULL, *RetStr=NULL, *ptr; RetStr=CopyStr(InBuff,""); ptr=Gettoken(Path,":",&CurrPath,0); while (ptr) { CurrPath=SlashTerminateDirectoryPath(CurrPath); Tempstr=MCopyStr(Tempstr,CurrPath,File,NULL); if (access(Tempstr,F_OK)==0) { RetStr=CopyStr(RetStr,Tempstr); break; } ptr=Gettoken(ptr,":",&CurrPath,0); } DestroyString(Tempstr); DestroyString(CurrPath); return(RetStr); }
void EhowExtractShowPlayer(STREAM *S, char *Data, ListNode *Vars) { char *Tempstr=NULL, *PlayerData=NULL, *ItemType=NULL, *ptr; int wide=0, high=0; PlayerData=CopyStr(PlayerData,Data); while (! strstr(PlayerData,"});")) { Tempstr=STREAMReadLine(Tempstr,S); PlayerData=MCatStr(PlayerData,Tempstr,",",NULL); } ptr=Gettoken(PlayerData,"width: ",&Tempstr,0); if (ptr) ptr=Gettoken(PlayerData,",",&Tempstr,0); wide=atoi(Tempstr); ptr=Gettoken(PlayerData,"height: ",&Tempstr,0); if (ptr) ptr=Gettoken(PlayerData,",",&Tempstr,0); high=atoi(Tempstr); ptr=Gettoken(PlayerData,"id: ",&Tempstr,0); if (ptr) ptr=Gettoken(PlayerData,",",&Tempstr,0); ptr=strrchr(Tempstr,'.'); if (ptr) ptr++; else ptr="flv"; if ((wide==0) || (high==0)) ItemType=MCopyStr(ItemType,"item:",ptr,NULL); else ItemType=FormatStr(ItemType,"item:%s:%dx%d",ptr,wide,high); SetVar(Vars,ItemType,Tempstr); DestroyString(PlayerData); DestroyString(ItemType); DestroyString(Tempstr); }
void DecodeYouTubeFormats(char *Formats, ListNode *Vars) { char *Token=NULL, *Tempstr=NULL, *TypeCode=NULL, *URL=NULL, *ptr; ptr=Gettoken(Formats,",",&Token,0); while (ptr) { YouTubeFormatGetData(Token, &URL, &TypeCode); switch (atoi(TypeCode)) { case 5: SetVar(Vars,"item:flv:400x240",URL); break; case 6: SetVar(Vars,"item:flv:480x270",URL); break; case 13: SetVar(Vars,"item:3gp",URL); break; case 17: SetVar(Vars,"item:3gp:176x144",URL); break; case 18: SetVar(Vars,"item:mp4:480x360",URL); break; case 22: SetVar(Vars,"item:mp4:1280x720",URL); break; case 34: SetVar(Vars,"item:flv-h264:640x360",URL); break; case 35: SetVar(Vars,"item:flv-h264:854x480",URL); break; case 36: SetVar(Vars,"item:3gp:400x240",URL); break; case 37: SetVar(Vars,"item:mp4:1920x1080",URL); break; case 38: SetVar(Vars,"item:mp4:4096x3072",URL); break; case 43: SetVar(Vars,"item:webm:640x360",URL); break; case 44: SetVar(Vars,"item:webm:854x480",URL); break; case 45: SetVar(Vars,"item:webm:1280x720",URL); break; case 46: SetVar(Vars,"item:webm:1920x1080",URL); break; case 82: SetVar(Vars,"item:mp4-3D:640x360",URL); break; case 83: SetVar(Vars,"item:mp4-3D:854x240",URL); break; case 84: SetVar(Vars,"item:mp4-3D:1280x720",URL); break; case 85: SetVar(Vars,"item:mp4-3D:1920x520",URL); break; case 100: SetVar(Vars,"item:webm-3D:640x360",URL); break; case 101: SetVar(Vars,"item:webm-3D:854x480",URL); break; case 102: SetVar(Vars,"item:webm-3D:1280x720",URL); break; default: // if (! Flags & FLAG_QUIET) if (StrLen(ptr)) fprintf(stderr,"Unknown youtube format [%s]\n",Token); break; } ptr=Gettoken(ptr,",",&Token,0); } DestroyString(TypeCode); DestroyString(URL); DestroyString(Token); DestroyString(Tempstr); }
void LexStream::Dump() { FILE* tokfile; // +1 for '\0' +4 for length(".tok") char* tokfile_name = new char[FileNameLength() + 5]; strcpy(tokfile_name, FileName()); strcat(tokfile_name, StringConstant::U8S_DO_tok); if ((tokfile = SystemFopen(tokfile_name, "w")) == NULL) { Coutput << "*** Cannot open LexStream dump output file " << tokfile_name << endl; return; } RereadInput(); SetUpComments(); TokenIndex tok = 0; for (CommentIndex com = FirstComment(tok); com > 0 && com < NumComments() && PrecedingToken(com) == tok; com++) { fprintf(tokfile, "*%5d ", com); fprintf(tokfile, "%s", FileName()); fprintf(tokfile, ", line %d.%d: ", FindLine(comments[com].location), FindColumn(comments[com].location - 1) + 1); for (const wchar_t* s = CommentString(com); *s; s++) fprintf(tokfile, "%c", *s); fprintf(tokfile, "\n"); } do { tok = Gettoken(); fprintf(tokfile, "%6d ", tok); fprintf(tokfile, " %s", FileName()); fprintf(tokfile, ", %cline %d.%d: %s %s ", (AfterEol(tok) ? '*' : ' '), Line(tok), (Kind(tok) == TK_EOF ? 0 : Column(tok)), token_type(Kind(tok)), (tokens[tok].Deprecated() ? "(d)" : " ")); for (const wchar_t* s = NameString(tok); *s; s++) fprintf(tokfile, "%c", *s); fprintf(tokfile, "\n"); for (CommentIndex com = FirstComment(tok); com > 0 && com < NumComments() && PrecedingToken(com) == tok; com++) { fprintf(tokfile, "*%5d ", com); fprintf(tokfile, " %s", FileName()); fprintf(tokfile, ", line %d.%d: ", FindLine(comments[com].location), FindColumn(comments[com].location - 1) + 1); for (const wchar_t* s = CommentString(com); *s; s++) fprintf(tokfile, "%c", *s); fprintf(tokfile, "\n"); } } while (Kind(tok) != TK_EOF); DestroyInput(); fprintf(tokfile, "\n"); #ifdef UNIQUE_NAMES fprintf(tokfile, "\nThe unique names are:\n\n"); for (int i = 0; i < control.name_table.symbol_pool.length(); i++) { fprintf(tokfile, "%4d ", i); for (const wchar_t* s = control.name_table.symbol_pool[i].name(); *s; s++) { fprintf(tokfile, "%c", *s); } fprintf(tokfile, "\n"); } #endif // UNIQUE_NAMES if (tokfile) fclose(tokfile); delete [] tokfile_name; }
/*---FUNCTION TO EVALUATE POSTFIX EXPRESSION---*/ float evaluate(List Postfix_l) { int i,count; count = Lexicon.count; char a[20]; float x,y,f; KindType type; Stack_f S; S = CreateStack_f(); while(!IsEmpty(Postfix_l)) { Gettoken(a,Postfix_l); switch(type = kind(a)) { case OPERAND: i = get_count(a); if(i > count) { puts("var not declared"); exit(1004); } if(Lexicon.Entry[i].str!=NULL) { puts("var has no number value"); exit(1005); } f = Lexicon.Entry[i].info.val; Push_f(f,S); break; case UNARYOP: f = TopandPop_f(S); f = DoUnary(f,a); Push_f(f,S); break; case BINARYOP: y = TopandPop_f(S); x = TopandPop_f(S); f = DoBinary(x,y,a); Push_f(f,S); break; } } if(IsEmpty_f(S)) { puts("INVALID EXPRESSION"); exit(1005); } f = TopandPop_f(S); if(!IsEmpty_f(S)) { puts("INVALID EXPRESSION"); exit(1005); } return f; }
/*---NOTE:- SINCE I HAVE USED STACKS USING LIST IMPLEMENTATION,TO DELETE FIRST ELEMENT,I USE POP & LIKEWISWE.---*/ void infix_to_postfix(List infix_l,List postfix_l) { char *p; int cnt; Stack stack; stack = CreateStack(); char token[MAXNAME],tmp[MAXNAME]; KindType type; do { /*since i am using stack implementation using linked lists,to get the first value in list i will be using Top of stack,to delete first element,use pop*/ if(!IsEmpty(infix_l)) { Gettoken(token,infix_l); } switch(type = kind(token)) { case OPERAND: cnt = Count(postfix_l); InsertAfter(token,postfix_l,cnt); break; case LEFTPAREN: Push(token,stack); break; case RIGHTPAREN: while(!IsEmpty(stack)) { TopandPop(stack,tmp); if(kind(tmp)==LEFTPAREN) break; cnt = Count(postfix_l); InsertAfter(tmp,postfix_l,cnt); } break; case UNARYOP: case BINARYOP: do { if(IsEmpty(stack)) { break; } else { p = Top(stack); strcpy(tmp,p); if(kind(tmp)==LEFTPAREN) break; else if(priority(tmp)!=priority(token) && priority(token)==MAXPRIORITY) break; else if(priority(token) > priority(tmp)) break; else { TopandPop(stack,tmp); cnt = Count(postfix_l); InsertAfter(tmp,postfix_l,cnt); } } }while(1); Push(token,stack); break; }//switch }while(!IsEmpty(infix_l)); while(!IsEmpty(stack)) { TopandPop(stack,tmp); cnt = Count(postfix_l); InsertAfter(tmp,postfix_l,cnt); } }
//This function Extracts Text from a line that's found between two specified //chunks of text 'ItemStart' and 'ItemEnd' char *GenericExtractFromLine(char *Line, char *ItemName, char *ItemStart, char *ItemEnd, ListNode *Vars, int Flags) { char *ptr, *ptr2, *Token=NULL, *Item=NULL; int GTF=0; if (Flags & EXTRACT_WITHIN_QUOTES) GTF=GETTOKEN_QUOTES; if (StrLen(ItemStart)) ptr=Gettoken(Line,ItemStart,&Token,0); else ptr=Line; ptr=Gettoken(ptr,ItemEnd,&Token,GTF); //check if the start string occurs more than once in the Token that we've grabbed if (StrLen(ItemStart)) ptr2=strstr(Token,ItemStart); else ptr2=NULL; while (ptr2) { ptr2+=StrLen(ItemStart); memmove(Token,ptr2,Token+StrLen(Token)-ptr2+1); //because of memmove we can strstr in Token again ptr2=strstr(Token,ItemStart); } if (Flags & EXTRACT_INCLUDE_START) { Item=MCopyStr(Item,ItemStart,Token,NULL); Token=CopyStr(Token,Item); } if (Flags & EXTRACT_DEQUOTE) Item=HTTPUnQuote(Item,Token); else if (Flags & EXTRACT_DEHTMLQUOTE) Item=HtmlDeQuote(Item,Token); else if (Flags & EXTRACT_DESLASHQUOTE) Item=DeQuoteStr(Item,Token); else Item=CopyStr(Item,Token); StripLeadingWhitespace(Item); StripTrailingWhitespace(Item); StripQuotes(Item); if (Flags & EXTRACT_NOSPACES) { ptr2=strchr(Item,' '); while (ptr2) { *ptr2='+'; ptr2=strchr(ptr2,' '); } } //Do this without disturbing ptr, as we must return ptr ptr2=ItemName; if (Flags & EXTRACT_GUESSTYPE) { Token=ItemCodeFromFileExtension(Token, ItemName, Item); } SetVar(Vars,ptr2,Item); DestroyString(Token); DestroyString(Item); return(ptr); }