int ExpandVarstring(char *string,char buffer[CF_EXPANDSIZE],char *bserver) { char *sp,*env; int varstring = false; char currentitem[CF_EXPANDSIZE],temp[CF_BUFSIZE],name[CF_MAXVARSIZE]; int len,increment; time_t tloc; memset(buffer,0,CF_EXPANDSIZE); if (string == 0 || strlen(string) == 0) { return false; } Debug("Expand varstring( %s )\n",string); for (sp = string; /* No exit */ ; sp++) /* check for varitems */ { char var[CF_BUFSIZE]; memset(var,0,CF_BUFSIZE); increment = 0; if (*sp == '\0') { break; } memset(currentitem,0,CF_EXPANDSIZE); sscanf(sp,"%[^$]",currentitem); if (ExpandOverflow(buffer,currentitem)) { FatalError("Can't expand varstring"); } strcat(buffer,currentitem); sp += strlen(currentitem); Debug("Add |%s| to str, waiting at |%s|\n",buffer,sp); if (*sp == '\0') { break; } if (*sp == '$') { switch (*(sp+1)) { case '(': ExtractOuterVarString(sp,var); varstring = ')'; break; case '{': ExtractOuterVarString(sp,var); varstring = '}'; break; default: strcat(buffer,"$"); continue; } } memset(currentitem,0,CF_EXPANDSIZE); temp[0] = '\0'; ExtractInnerVarString(sp,temp); if (strstr(temp,"$")) { Debug("Nested variables - %s\n",temp); ExpandVarstring(temp,currentitem,""); CheckVarID(currentitem); } else { strncpy(currentitem,temp,CF_BUFSIZE-1); } increment = strlen(var) - 1; Debug("Scanning variable %s\n",currentitem); switch (ScanVariable(currentitem)) { case cfhost: strcat(buffer,"$(sys.uqhost)"); break; case cffqhost: strcat(buffer,"$(sys.host)"); break; case cfipaddr: strcat(buffer,"$(sys.ipv4)"); break; case cfclass: strcat(buffer,"$(sys.class)"); break; case cfarch: if (ExpandOverflow(buffer,VARCH)) { FatalError("Can't expandvarstring"); } strcat(buffer,"$(sys.os)"); break; case cfarch2: if (ExpandOverflow(buffer,VARCH2)) { FatalError("Can't expandvarstring"); } strcat(buffer,"$(sys.longarch)"); break; case cfdate: strcat(buffer,"$(sys.date)"); break; case cfspc: if (ExpandOverflow(buffer," ")) { FatalError("Can't expandvarstring"); } strcat(buffer," "); break; case cftab: if (ExpandOverflow(buffer," ")) { FatalError("Can't expandvarstring"); } strcat(buffer,"\t"); break; case cflf: if (ExpandOverflow(buffer," ")) { FatalError("Can't expandvarstring"); } strcat(buffer,"$(sys.endl)"); break; case cfcr: if (ExpandOverflow(buffer," ")) { FatalError("Can't expandvarstring"); } strcat(buffer,"$(sys.r)"); break; case cfn: if (ExpandOverflow(buffer," ")) { FatalError("Can't expandvarstring"); } strcat(buffer,"$(sys.n)"); break; case cfdollar: strcat(buffer,"$(sys.dollar)"); break; default: if (VARIABLES) { if (varstring == '}') { snprintf(name,CF_MAXVARSIZE,"${%s}",currentitem); } else { snprintf(name,CF_MAXVARSIZE,"$(%s)",currentitem); } strcat(buffer,name); } else { if (varstring == '}') { snprintf(name,CF_MAXVARSIZE,"${g.%s}",currentitem); } else { snprintf(name,CF_MAXVARSIZE,"$(g.%s)",currentitem); } strcat(buffer,name); } } sp += increment; currentitem[0] = '\0'; } Debug("Returning varstring (%s)\n",buffer); return varstring; }
int ExpandVarbinserv(char *string,char *buffer,char *bserver) { char *sp; char varstring = false; char currentitem[CF_EXPANDSIZE], scanstr[6]; Debug("ExpandVarbinserv %s, ",string); if (bserver != NULL) { Debug("(Binserver is %s)\n",bserver); } buffer[0] = '\0'; for (sp = string; /* No exit */ ; sp++) /* check for varitems */ { currentitem[0] = '\0'; sscanf(sp,"%[^$]",currentitem); strcat(buffer,currentitem); sp += strlen(currentitem); if (*sp == '$') { switch (*(sp+1)) { case '(': varstring = ')'; break; case '{': varstring = '}'; break; default: strcat(buffer,"$"); continue; } sp++; } currentitem[0] = '\0'; if (*sp == '\0') { break; } else { sprintf(scanstr,"%%[^%c]",varstring); /* select the correct terminator */ sscanf(++sp,scanstr,currentitem); /* reduce item */ switch (ScanVariable(currentitem)) { case cfbinserver: if (ExpandOverflow(buffer,bserver)) { FatalError("Can't expand varstring"); } strcat(buffer,bserver); break; } sp += strlen(currentitem); currentitem[0] = '\0'; } } return varstring; }
nsXFormsXPathScanner::XPATHTOKEN nsXFormsXPathScanner::NextToken() { if (mState != WHITESPACE) mLast = mState; mOffset = mOffset + mLength; mLength = 0; PRUnichar c = PeekChar(); if (c == '\0') { mState = XPATHEOF; } else if (nsXFormsXPathXMLUtil::IsDigit(c)) { mState = ScanNumber(); } else if (c == '_' || nsXFormsXPathXMLUtil::IsLetter(c)) { mState = ScanQName(); } else if (c == '"' || c == '\'') { mState = ScanLiteral(); } else { switch (c) { case '(': mState = LPARAN; PopChar(); break; case ')': mState = RPARAN; PopChar(); break; case '[': mState = LBRACK; PopChar(); break; case ']': mState = RBRACK; PopChar(); break; case '@': mState = AT; PopChar(); break; case ',': mState = COMMA; PopChar(); break; case ':': PopChar(); if (PeekChar() == ':') { mState = COLONCOLON; PopChar(); } else mState = ERRORXPATHTOKEN; break; case '.': PopChar(); if (PeekChar() == '.') { mState = DOTDOT; PopChar(); } else if (nsXFormsXPathXMLUtil::IsDigit(PeekChar())) mState = ScanNumber(); else mState = DOT; break; case '$': mState = ScanVariable(); break; case '/': PopChar(); if (PeekChar() == '/') { mState = SLASHSLASH; PopChar(); } else mState = SLASH; break; case '|': PopChar(); mState = UNION; break; case '+': PopChar(); mState = PLUS; break; case '-': PopChar(); mState = MINUS; break; case '=': PopChar(); mState = EQUAL; break; case '!': PopChar(); if (PeekChar() == '=') { mState = NOTEQUAL; PopChar(); } else mState = ERRORXPATHTOKEN; break; case '<': PopChar(); if (PeekChar() == '=') { mState = LEQUAL; PopChar(); } else mState = LESS; break; case '>': PopChar(); if (PeekChar() == '=') { mState = GEQUAL; PopChar(); } else mState = GREATER; break; case '*': PopChar(); mState = SolveStar(); break; case '\r': case '\n': case '\t': case ' ': mState = ScanWhitespace(); break; default: PopChar(); mState = ERRORXPATHTOKEN; } } return mState; }