Example #1
0
char *cValidityRange::Parse3(char *s)
{
  bool log=true;
  s=skipspace(s);
  char *e=index(s,'}');
  if(e && *s++=='{') {
    *e=0; e=skipspace(e+1);
    char *p;
    if((p=index(s,':'))) {
      *p=0;
      if(ParseCaidRange(s)) {
        s=p+1;
        if((p=index(s,':'))) {
          *p=0;
          if(s==p || ParseSourceRange(s)) {
            s=p+1;
            if(!*s || ParseFreqRange(s)) return e;
            }
          log=false;
          }
        }
      else log=false;
      }
    }
  if(log) PRINTF(L_CORE_LOAD,"override: RANGE format error");
  return 0;
}
Example #2
0
char *cValidityRange::Parse2(char *s, bool wildAllow)
{
  bool log=true;
  s=skipspace(s);
  char *e=index(s,'}');
  if(e && *s++=='{') {
    *e=0; e=skipspace(e+1);
    s=skipspace(s);
    if(wildAllow && *s=='*' && isempty(s+1)) {
      wildcard=true;
      return e;
      }
    char *p;
    if((p=index(s,':'))) {
      *p=0;
      if(ParseSourceRange(s)) {
        s=p+1;
        if(!*s || ParseFreqRange(s)) return e;
        }
      log=false;
      }
    }
  if(log) PRINTF(L_CORE_LOAD,"override: RANGE format error");
  return 0;
}
Example #3
0
size_t cSatipRtsp::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP)
{
  cSatipRtsp *obj = reinterpret_cast<cSatipRtsp *>(dataP);
  size_t len = sizeP * nmembP;
  debug16("%s len=%zu", __PRETTY_FUNCTION__, len);

  char *s, *p = (char *)ptrP;
  char *r = strtok_r(p, "\r\n", &s);

  while (obj && r) {
        debug16("%s (%zu): %s", __PRETTY_FUNCTION__, len, r);
        r = skipspace(r);
        if (strstr(r, "com.ses.streamID")) {
           int streamid = -1;
           if (sscanf(r, "com.ses.streamID:%11d", &streamid) == 1)
              obj->tunerM.SetStreamId(streamid);
           }
        else if (strstr(r, "Session:")) {
           int timeout = -1;
           char *session = NULL;
           if (sscanf(r, "Session:%m[^;];timeout=%11d", &session, &timeout) == 2)
              obj->tunerM.SetSessionTimeout(skipspace(session), timeout * 1000);
           else if (sscanf(r, "Session:%m[^;]", &session) == 1)
              obj->tunerM.SetSessionTimeout(skipspace(session), -1);
           FREE_POINTER(session);
           }
        r = strtok_r(NULL, "\r\n", &s);
        }

  return len;
}
Example #4
0
static Bit16 getAddress(Bool *hasSecond ){
  /* Read the hex address from stdin */
  int c;
  int max = 5;
  char buf[] = {'\0','\0','\0','\0','\0'};
  unsigned int n = 0;

  skipspace();
  while((c = getchar()) != EOF && n < max){
    if (c == '\n' || c == ',' || c == ' ') {
      if (c == ' '){
	skipspace();
	c = getchar();
      }
      *hasSecond = (c == ',');	
      break;
    }
    if (ishexdigit(c)){
      buf[n++] = c;
    }
    else {
      fprintf(stderr,"Invalid character only hex address are allowed.\n");
      return 0;
    }
  }
  if (n == max){
    fprintf(stderr,"The memory address is to large. The maximum memory address is $FFFF\n");
    return 0;
  }
  return strtol(buf,NULL,16);
}
Example #5
0
int processfile(FILE *srcfile, int start, int flags) {
    char srctemp[80];
    char *srcline;
    int thispass;

    for(thispass=0; thispass<=1; thispass++) {
        asmpass=flags+(thispass<<1);
        rewind(srcfile);
        destadr=start;
        lineno=1;
        while(fgets(srctemp, 80, srcfile) != NULL) {
            srcline=srctemp;
            skipspace(srcline);
            if(*srcline=='.') {
                srcline=checklabel(srcline+1, codeorig+destadr);
                skipspace(srcline);
            }
            if(*srcline=='#')
                asmdirect(srcline);
            else if(*srcline!='/')
                assemble(srcline);
            lineno++;
        }
    }
    return(destadr);
}
Example #6
0
bool cSmartCardDataVideoGuard2::Parse(const char *line)
{
  line=skipspace(line);
  if(!strncasecmp(line,"BOXID",5))     { type=dtBoxId; line+=5; }
  else if(!strncasecmp(line,"SEED",4)) { type=dtSeed; line+=4; }
  else {
    PRINTF(L_CORE_LOAD,"smartcarddatavideoguard2: format error: datatype");
    return false;
    }
  line=skipspace(line);
  switch(type) {
    case dtBoxId:
      if(GetHex(line,boxid,sizeof(boxid))!=sizeof(boxid)) {
        PRINTF(L_CORE_LOAD,"smartcarddatavideoguard2: format error: boxid");
        return false;
        }
      break;
    case dtSeed:
      if(GetHex(line,seed0,sizeof(seed0))!=sizeof(seed0)) {
        PRINTF(L_CORE_LOAD,"smartcarddatacryptoworks: format error: seed0");
        return false;
        }
      line=skipspace(line);
      if(GetHex(line,seed1,sizeof(seed1))!=sizeof(seed1)) {
        PRINTF(L_CORE_LOAD,"smartcarddatacryptoworks: format error: seed1");
        return false;
        }
      break;
    }
  return true;
}
Example #7
0
void cSatipRtsp::ParseHeader(void)
{
  debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
  char *s, *p = headerBufferM.Data();
  char *r = strtok_r(p, "\r\n", &s);

  while (r) {
        debug16("%s (%zu): %s", __PRETTY_FUNCTION__, headerBufferM.Size(), r);
        r = skipspace(r);
        if (strstr(r, "com.ses.streamID")) {
           int streamid = -1;
           if (sscanf(r, "com.ses.streamID:%11d", &streamid) == 1)
              tunerM.SetStreamId(streamid);
           }
        else if (strstr(r, "Session:")) {
           int timeout = -1;
           char *session = NULL;
           if (sscanf(r, "Session:%m[^;];timeout=%11d", &session, &timeout) == 2)
              tunerM.SetSessionTimeout(skipspace(session), timeout * 1000);
           else if (sscanf(r, "Session:%m[^;]", &session) == 1)
              tunerM.SetSessionTimeout(skipspace(session), -1);
           FREE_POINTER(session);
           }
        r = strtok_r(NULL, "\r\n", &s);
        }
}
bool cPendingNotification::Read(FILE *f)
{
    cPendingNotification *p = NULL;
    char *s;
    cReadLine ReadLine;
    while ((s = ReadLine.Read(f)) != NULL) {
	char *t = skipspace(s + 1);
	switch (*s) {
	    case 'N': if (!p) {
		tEventID EventID;
		int Type, TimerMod, SearchID;
		time_t Start;
		int n = sscanf(t, "%d %u %d %d %ld", &Type, &EventID, &TimerMod, &SearchID, &Start);
		if (n == 5) {
		    p = new cPendingNotification;
		    if (p)
		    {
		        p->type = Type;
			p->eventID = EventID;
			p->timerMod = TimerMod;
			p->searchID = SearchID;
			p->start = Start;

			PendingNotifications.Add(p);
		    }
		}
	    }
		break;
	    case 'C':
	    {
		s = skipspace(s + 1);
		char *pC = strchr(s, ' ');
		if (pC)
		    *pC = 0; // strips optional channel name
		if (*s) {
		    tChannelID channelID = tChannelID::FromString(s);
		    if (channelID.Valid()) {
			if (p)
			    p->channelID = channelID;
                    }
		    else {
			LogFile.Log(3, "ERROR: illegal channel ID: %s", s);
			return false;
                    }
		}
	    }
	    break;
	    case 'n':
		p = NULL;
		break;
	    default:  if (p && !p->Parse(s))
	    {
		LogFile.Log(1,"ERROR: parsing %s", s);
		return false;
	    }
	}
    }
    return true;
}
Example #9
0
bool cRecDone::Read(FILE *f)
{
    cRecDone *recDone = NULL;
    char *s;
    cReadLine ReadLine;
    while ((s = ReadLine.Read(f)) != NULL) {
	char *t = skipspace(s + 1);
	switch (*s) {
	    case 'R': if (!recDone) {
		time_t StartTime;
		int Duration, SearchID;
		int n = sscanf(t, "%ld %d %d", &StartTime, &Duration, &SearchID);
		if (n == 3) {
		    recDone = new cRecDone;
		    if (recDone)
		    {
			recDone->searchID = SearchID;
			recDone->startTime = StartTime;
			recDone->duration = Duration;
			RecsDone.Add(recDone);
		    }
		}
	    }
		break;
	    case 'C':
	    {
		s = skipspace(s + 1);
		char *p = strchr(s, ' ');
		if (p)
		    *p = 0; // strips optional channel name
		if (*s) {
		    tChannelID channelID = tChannelID::FromString(s);
		    if (channelID.Valid()) {
			if (recDone)
			    recDone->channelID = channelID;
                    }
		    else {
			LogFile.Log(3, "ERROR: illegal channel ID: %s", s);
			return false;
                    }
		}
	    }
	    break;
	    case 'r':
		recDone = NULL;
		break;
	    default:  if (recDone && !recDone->Parse(s))
	    {
		LogFile.Log(1,"ERROR: parsing %s", s);
		return false;
	    }
	}
    }
    return true;
}
Example #10
0
bool cSmartCardDataNagra::Parse(const char *line)
{
  bool isSK=false;
  int dlen=64;
  BN_set_word(exp,3);
  line=skipspace(line);
  unsigned char id[4];
  if(GetHex(line,id,sizeof(id))!=sizeof(id)) {
    PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: card id");
    return false;
    }
  cardid=UINT32_BE(id);
  line=skipspace(line);
  if(!strncasecmp(line,"SK",2)) { isSK=true; dlen=96; line+=2; }
  else {
    if(GetHex(line,bk,sizeof(bk))!=sizeof(bk)) {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: boxkey");
      return false;
      }
    line=skipspace(line);
    if(!strncasecmp(line,"IRDMOD",6)) { isIrdMod=true; line+=6; }
    else if(!strncasecmp(line,"CARDMOD",7)) { isIrdMod=false; line+=7; }
    else {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: IRDMOD/CARDMOD");
      return false;
      }
    }
  line=skipspace(line);

  unsigned char *buff=AUTOMEM(dlen);
  if(GetHex(line,buff,dlen)!=dlen) {
    PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: data block");
    return false;
    }
  if(!isSK) {
    mod.Get(buff,64);
    }
  else {
    struct SecondaryKey *sk=(struct SecondaryKey *)buff;
    if(UINT16_BE(sk->cs)!=CRC16(buff,sizeof(*sk)-sizeof(sk->cs),false)) {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: secondary key CRC failed");
      return false;
      }
    unsigned short e=UINT16_BE(sk->exp);
    if(e!=0x0003 && e!=CRC16(buff,12,false)) BN_set_word(exp,e);
    xxor(bk,sizeof(bk),sk->y1,sk->y2);
    mod.Get(sk->mod,sizeof(sk->mod));
    }
  return true;
}
Example #11
0
bool cNoepgChannelID::Parse(const char *s)
{
  comment = NULL;
  if (strncmp(s, "mode=w", 6) == 0) {
     mode = enemWhitelist;
     return true;
     }
  if (strncmp(s, "mode=b", 6) == 0) {
     mode = enemBlacklist;
     return true;
     }
  // allow comments after first space
  int spos = 0;
  int slen = strlen(s);
  while ((spos < slen) && (s[spos] != ' '))
        spos++;
  if (spos < slen) {
     char *tmp = new char[spos + 1];
     memcpy(tmp, s, spos);
     tmp[spos] = 0;
     id = tChannelID::FromString(tmp);
     delete tmp;
     tmp = skipspace(s + spos);
     if ((tmp != NULL) && (strlen(tmp) > 0)) {
        if ((strlen(tmp) <= 3) || !startswith(tmp, "//="))
           comment = new cString(tmp);
        }
     }
  else
     id = tChannelID::FromString(s);
  return id.Valid();
}
Example #12
0
void cPluginSatip::ParsePortRange(const char *paramP)
{
  char *s, *p = skipspace(paramP);
  char *r = strtok_r(p, "-", &s);
  unsigned int rangeStart = 0;
  unsigned int rangeStop = 0;
  if (r) {
     rangeStart = strtol(r, NULL, 0);
     r = strtok_r(NULL, "-", &s);
     }
  if (r)
     rangeStop = strtol(r, NULL, 0);
  else {
     error("Port range argument not valid '%s'", paramP);
     rangeStart = 0;
     rangeStop = 0;
     }
  if (rangeStart % 2) {
     error("The given range start port must be even!");
     rangeStart = 0;
     rangeStop = 0;
     }
  else if (rangeStop - rangeStart + 1 < deviceCountM * 2) {
     error("The given port range is to small: %d < %d!", rangeStop - rangeStart + 1, deviceCountM * 2);
     rangeStart = 0;
     rangeStop = 0;
     }
  SatipConfig.SetPortRangeStart(rangeStart);
  SatipConfig.SetPortRangeStop(rangeStop);
}
Example #13
0
/*
  read label, colon and associated weight
  Params: fp - the input stream
          weight - return for weight
          error - return for error
  Returns: the label
  Notes: a null label is not an error
 */
static char *readlabelandweight(FILE *fp, double *weight, int *error)
{
  char *answer;
  int ch;

  *weight = 0;
  answer = readlabel(fp);
  if(!answer)
  {
    *error = -1;
    return 0;
  }
  skipspace(fp);
  ch = fgetc(fp);
  if(ch == ':')
  {
    if( fscanf(fp, "%lf", weight) != 1)
    {
      *error = -2;
      free(answer);
      return 0;
    }
  }
  else
    ungetc(ch, fp);

  if(*answer == 0)
  {
    free(answer);
    answer = 0;
  }
  *error = 0;
  return answer;
}
Example #14
0
// process a single INI directive
int IniLine(LPTSTR szBuffer, INIFILE *InitData, int fSectionOnly, int fLiveMod, TCHAR **errmsg)
{
	register int i, nTokenLength;
	unsigned int ptype, fPath;
	int fg, bg, bc;
	int j, toknum, tokdata, defval, context;
	int path_len, min_path_len;
	TCHAR szPathName[MAXFILENAME], szPathTest[MAXFILENAME];
	unsigned char *dataptr;
	void *vdata;
	LPTSTR pszToken, delims;

	// be sure the line is double-null terminated
	szBuffer[ strlen( szBuffer ) + 1 ] = '\0';

	// get first token, skip line if empty or all comment
	pszToken = skipspace( szBuffer );

	// handle section name 
	if (*pszToken == _TEXT('[')) {

		strip_trailing( ++pszToken, _TEXT(" \t]") );
		if ( toklist( pszToken, &SectionNames, &toknum ) != 1 )
			return -0x100;

		// legitimate section name, return corresponding bit
		return (-(0x80 >> toknum));
	}
Example #15
0
int resolveHeader(sds buf, struct request *prot)
{
    char *n;
    char *t;
    char *tmp[3];
    n = strstr(buf, "\r\n");
    *n = 0;
    n += 2;
    prot->waiting = 0;
    if (sizeof(tmp)/sizeof(char *) != 
            csplit(buf, ' ', tmp, sizeof(tmp)/sizeof(char *)))
    {
        return -1;
    }

    prot->method  = tmp[0];
    prot->url     = tmp[1];
    prot->version = tmp[2];

    t = strstr(n, "length:");
    if (NULL == t)  return  -1;//error 

    t = (char *)skiptospace(t);
    if (NULL == t)  return  -1;//error 

    t = (char *)skipspace(t);
    if (NULL == t)  return  -1;//error 

    prot->lenght = atoi(t);
    prot->hlenght = sdslen(buf);
    return 0;
}
Example #16
0
bool cSchedule::Read(FILE *f, cSchedules *Schedules)
{
  if (Schedules) {
     cReadLine ReadLine;
     char *s;
     while ((s = ReadLine.Read(f)) != NULL) {
           if (*s == 'C') {
              s = skipspace(s + 1);
              char *p = strchr(s, ' ');
              if (p)
                 *p = 0; // strips optional channel name
              if (*s) {
                 tChannelID channelID = tChannelID::FromString(s);
                 if (channelID.Valid()) {
                    if (cSchedule *p = Schedules->AddSchedule(channelID)) {
                       if (!cEvent::Read(f, p))
                          return false;
                       p->Sort();
                       }
                    }
                 else {
                    esyslog("ERROR: invalid channel ID: %s", s);
                    return false;
                    }
                 }
              }
           else {
              esyslog("ERROR: unexpected tag while reading EPG data: %s", s);
              return false;
              }
           }
     return true;
     }
  return false;
}
Example #17
0
static int GetHexBase(const char * &line, unsigned char *store, int count, bool fixedLen, bool asc)
{
  line=skipspace(line);
  const char *sline=line;
  unsigned char *sstore=store;
  int scount=count;
  while(count) {
    if(line[0]==0 || line[1]==0 || !isxdigit(line[0]) || !isxdigit(line[1])) break;
    if(asc) {
       *store++=line[0]; *store++=line[1];
       }
    else {
      int d1=HexDigit(line[0]);
      int d0=HexDigit(line[1]);
      *store++=(d1<<4) + d0;
      }
    line+=2; count--;
    }
  if(asc) *store=0; // make sure strings are NULL terminated
  if((!count || (!fixedLen && count!=scount)) &&
     (!*line || isspace(*line) || *line==';' || *line==']' || *line=='/') ) return scount-count;
  memset(sstore,0,scount);
  line=sline;
  return 0;
}
Example #18
0
const char *cDiseqc::Codes(const char *s) const
{
  const char *e = strchr(s, ']');
  if (e) {
     int NumCodes = 0;
     const char *t = s;
     while (t < e) {
           if (NumCodes < MaxDiseqcCodes) {
              errno = 0;
              char *p;
              int n = strtol(t, &p, 16);
              if (!errno && p != t && 0 <= n && n <= 255) {
                 if (!parsing) {
                    codes[NumCodes++] = uchar(n);
                    numCodes = NumCodes;
                    }
                 t = skipspace(p);
                 }
              else {
                 esyslog("ERROR: invalid code at '%s'", t);
                 return NULL;
                 }
              }
           else {
              esyslog("ERROR: too many codes in code sequence '%s'", s - 1);
              return NULL;
              }
           }
     return e + 1;
     }
  else
     esyslog("ERROR: missing closing ']' in code sequence '%s'", s - 1);
  return NULL;
}
Example #19
0
t_dlist	*tokenizer(char *line, t_lnv *envlist)
{
  t_dlist	*list;
  t_dlist	*cur;
  int		i;
  char		*exp;

  i = 0;
  if (line == NULL || !line[(i)])
    return (NULL);
  list = NULL;
  if ((exp = expand_variables(line, envlist)) == NULL)
    return (NULL);
  while ((exp[i]))
    {
      skipspace(exp, &i);
      if (exp[i])
  	{
  	  if (((list = add_dlist_elem(list)) == NULL)	 ||
  	      ((cur = goto_last_dlist(list)) == NULL)	 ||
  	      ((cur->data = get_next_token(exp, &i)) == NULL))
  	    return (NULL);
  	}
    }
  gbgc_free(NULL, exp);
  return (list);
}
Example #20
0
bool cNestedItemList::Parse(FILE *f, cList<cNestedItem> *List, int &Line)
{
  char *s;
  cReadLine ReadLine;
  while ((s = ReadLine.Read(f)) != NULL) {
        Line++;
        char *p = strchr(s, '#');
        if (p)
           *p = 0;
        s = skipspace(stripspace(s));
        if (!isempty(s)) {
           p = s + strlen(s) - 1;
           if (*p == '{') {
              *p = 0;
              stripspace(s);
              cNestedItem *Item = new cNestedItem(s, true);
              List->Add(Item);
              if (!Parse(f, Item->SubItems(), Line))
                 return false;
              }
           else if (*s == '}')
              break;
           else
              List->Add(new cNestedItem(s));
           }
        }
  return true;
}
Example #21
0
bool cSatCableNumbers::FromString(const char *s)
{
  char *t;
  int i = 0;
  const char *p = s;
  while (p && *p) {
        int n = strtol(p, &t, 10);
        if (t != p) {
           if (i < size)
              array[i++] = n;
           else {
              esyslog("ERROR: too many sat cable numbers in '%s'", s);
              return false;
              }
           }
        else {
           esyslog("ERROR: invalid sat cable number in '%s'", s);
           return false;
           }
        p = skipspace(t);
        }
  for ( ; i < size; i++)
      array[i] = 0;
  return true;
}
Example #22
0
void cPluginManager::AddPlugin(const char *Args)
{
  if (strcmp(Args, "*") == 0) {
     cReadDir d(directory);
     struct dirent *e;
     while ((e = d.Next()) != NULL) {
           if (strstr(e->d_name, LIBVDR_PREFIX) == e->d_name) {
              char *p = strstr(e->d_name, SO_INDICATOR);
              if (p) {
                 *p = 0;
                 p += strlen(SO_INDICATOR);
                 if (strcmp(p, APIVERSION) == 0) {
                    char *name = e->d_name + strlen(LIBVDR_PREFIX);
                    if (strcmp(name, "*") != 0) { // let's not get into a loop!
                       AddPlugin(e->d_name + strlen(LIBVDR_PREFIX));
                       }
                    }
                 }
              }
           }
     return;
     }
  char *s = strdup(skipspace(Args));
  char *p = strchr(s, ' ');
  if (p)
     *p = 0;
  char *buffer = NULL;
  asprintf(&buffer, "%s/%s%s%s%s", directory, LIBVDR_PREFIX, s, SO_INDICATOR, APIVERSION);
  dlls.Add(new cDll(buffer, Args));
  free(buffer);
  free(s);
}
Example #23
0
// destructive
static int
tokenize(int* argc, char* argv[], size_t nargvsize, char* iline)
{
	char* ptr = skipspace(iline);
	int ret = 0;
	char* word;

	if (strncmp(ptr, "/sbin/", 6) == 0)
		ptr += 6;

	while(ptr && *ptr)
	{
		if(*ptr == '#')
			break;
		if(*argc >= nargvsize)
		{
			errstr = "too many arguments";
			ret = -1;
			break;
		}
		word = getword(&ptr);
		if(!word)
		{
			ret = -1;
			break;
		}
		argv[(*argc)++] = word;
		++ret;
	}
	return ret;
}
Example #24
0
static void inclinenumber (LexState *LS) {
	static const char *pragmas [] =
	{ "debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL };
	next(LS);  // skip '\n'
	++LS->linenumber;
	if (LS->current == '$') {  // is a pragma?
		char buff[PRAGMASIZE + 1];
		int32 ifnot = 0;
		int32 skip = LS->ifstate[LS->iflevel].skip;
		next(LS);  // skip $
		readname(LS, buff);
		switch (luaO_findstring(buff, pragmas)) {
		case 0:  // debug
			if (!skip)
				lua_debug = 1;
			break;
		case 1:  // nodebug
			if (!skip)
				lua_debug = 0;
			break;
		case 2:  // endinput
			if (!skip) {
				LS->current = EOZ;
				LS->iflevel = 0;  // to allow $endinput inside a $if
			}
			break;
		case 3:  // end
			if (LS->iflevel-- == 0)
				luaY_syntaxerror("unmatched $end", "$end");
			break;
		case 4:  // ifnot
			ifnot = 1;
			// go through
		case 5:  // if
			if (LS->iflevel == MAX_IFS - 1)
				luaY_syntaxerror("too many nested $ifs", "$if");
			readname(LS, buff);
			LS->iflevel++;
			LS->ifstate[LS->iflevel].elsepart = 0;
			LS->ifstate[LS->iflevel].condition = checkcond(buff) ? !ifnot : ifnot;
			LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
			break;
		case 6:  // else
			if (LS->ifstate[LS->iflevel].elsepart)
				luaY_syntaxerror("unmatched $else", "$else");
			LS->ifstate[LS->iflevel].elsepart = 1;
			LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel - 1].skip || LS->ifstate[LS->iflevel].condition;
			break;
		default:
			luaY_syntaxerror("unknown pragma", buff);
		}
		skipspace(LS);
		if (LS->current == '\n')  // pragma must end with a '\n' ...
			inclinenumber(LS);
		else if (LS->current != EOZ)  // or eof
			luaY_syntaxerror("invalid pragma format", buff);
		ifskip(LS);
	}
}
Example #25
0
File: Reader.cpp Project: LicoC/XML
// parse attribute=quoted-value sequence.
bool Reader::parseAttribute()
{
	std::pair<std::string, std::string> pair;
	bool bOK = skipspace(true) && parseToken(pair.first);
	if (bOK)
	{
		bOK = skipspace(true) && _parser.parseMatch('=') && skipspace(true) &&
			_parser.parseMatch('"') &&
			_parser.readText(pair.second, '"') &&
			_parser.parseMatch('"');
		if (bOK)
		{
			_attributes.push_back(pair);
		}
	}
	return bOK;
}
Example #26
0
// this is just a very basic method, not 100% shell compatible
static char*
getword(char** ptr)
{
	*ptr = skipspace(*ptr);
	if(**ptr == '"')
		return getstring(ptr);
	return getliteral(ptr);
}
Example #27
0
/// gettok - Return the next token from standard input.
int lexer::gettok()
{
	// Skip any whitespace.
	c = skipspace(input, c, line_num);

	// identifier: [a-zA-Z][a-zA-Z0-9_]*
	if (isalpha(c)) { 
		str = c;
		do {
			c = input->get();
			if ( isalnum(c) || c=='_' )
				str += c;
			else
				break;
		} while (true);
		if (unlikely(literal_p(str)))
			return token_type::literal;
		else
			return token_type::identifier;
	}

	// Number: [0-9]+([.][0-9]*(eE[+-][0-9]+)*)*
	if (isdigit(c) || c == '.') {
		str = "";
		do {
			str += c;
			c = input->get();
		} while (isdigit(c) || c == '.');
		if (c == 'E' || c == 'e') {
			str += 'E';
			c = input->get();
			if (isdigit(c))
				str += '+';
			do {
				str += c;
				c = input->get();
			} while (isdigit(c));
		}
		return token_type::number;
	}

	// Comment until end of line.
	if (c == '#') {
		c = skipline(input);
		++line_num;
		if (c != EOF)
			return gettok();
	}

	// Check for end of file.  Don't eat the EOF.
	if (c == EOF)
		return token_type::eof;

	// Otherwise, just return the character as its ascii value.
	int current = c;
	c = input->get();
	return current;
}
Example #28
0
File: llex.c Project: calandoa/zite
static void inclinenumber (LexState *LS) {
  static char *pragmas [] =
    {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
  next(LS);  /* skip '\n' */
  ++LS->linenumber;
  if (LS->current == '$') {  /* is a pragma? */
    char buff[PRAGMASIZE+1];
    int ifnot = 0;
    int skip = LS->ifstate[LS->iflevel].skip;
    next(LS);  /* skip $ */
    readname(LS, buff);
    switch (luaL_findstring(buff, pragmas)) {
      case 0:  /* debug */
        if (!skip) L->debug = 1;
        break;
      case 1:  /* nodebug */
        if (!skip) L->debug = 0;
        break;
      case 2:  /* endinput */
        if (!skip) {
          LS->current = EOZ;
          LS->iflevel = 0;  /* to allow $endinput inside a $if */
        }
        break;
      case 3:  /* end */
        if (LS->iflevel-- == 0)
          luaX_syntaxerror(LS, "unmatched $end", "$end");
        break;
      case 4:  /* ifnot */
        ifnot = 1;
        /* go through */
      case 5:  /* if */
        if (LS->iflevel == MAX_IFS-1)
          luaX_syntaxerror(LS, "too many nested $ifs", "$if");
        readname(LS, buff);
        LS->iflevel++;
        LS->ifstate[LS->iflevel].elsepart = 0;
        LS->ifstate[LS->iflevel].condition = checkcond(LS, buff) ? !ifnot : ifnot;
        LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
        break;
      case 6:  /* else */
        if (LS->ifstate[LS->iflevel].elsepart)
          luaX_syntaxerror(LS, "unmatched $else", "$else");
        LS->ifstate[LS->iflevel].elsepart = 1;
        LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel-1].skip ||
                                      LS->ifstate[LS->iflevel].condition;
        break;
      default:
        luaX_syntaxerror(LS, "unknown pragma", buff);
    }
    skipspace(LS);
    if (LS->current == '\n')  /* pragma must end with a '\n' ... */
      inclinenumber(LS);
    else if (LS->current != EOZ)  /* or eof */
      luaX_syntaxerror(LS, "invalid pragma format", buff);
    ifskip(LS);
  }
}
Example #29
0
File: Reader.cpp Project: LicoC/XML
// returns true if start of an element.
bool Reader::isStartElement()
{
	if ( _parser.eof() ) return false;
	if (_bStart)
		return true;
	skipspace(false);
	_bStart = _parser.peekMatch('<') && !_parser.peekMatch("</");
	if (_bStart) _parser.consume(1);
	return _bStart;
}
Example #30
0
bool cEpg::ParseLine(const char *s)
{
  char *t = skipspace(s + 1);
  switch (*s)
  {
    case 'T': SetTitle(t);
              break;
    case 'S': SetShortText(t);
              break;
    case 'D': strreplace(t, '|', '\n');
              SetDescription(t);
              break;
    case 'E':
      {
        unsigned int EventID;
        time_t StartTime;
        int Duration;
        unsigned int TableID = 0;
        unsigned int Version = 0xFF; // actual value is ignored
        int n = sscanf(t, "%u %ld %d %X %X", &EventID, &StartTime, &Duration, &TableID, &Version);
        if (n >= 3 && n <= 5)
        {
          m_StartTime = StartTime;
          m_EndTime   = StartTime+Duration;
          m_Duration  = Duration;
          m_uid       = EventID;
        }
      }
      break;
    case 'G':
      {
        char genre[1024];
        int genreType;
        int genreSubType;
        int n = sscanf(t, "%u %u %[^\n]", &genreType, &genreSubType, genre);
        if (n == 3)
        {
          SetGenre(genre, genreType, genreSubType);
        }
      }
      break;
    case 'X': break;
    case 'C': break;
    case 'c': break;
    case 'V': SetVps(atoi(t));
              break;
    case 'R': SetParentalRating(atoi(t));
              break;
    case 'e': return true;
    default:  XBMC->Log(LOG_ERROR, "cEpg::ParseLine - unexpected tag while reading EPG data: %s", s);
              return true;
  }
  return false;
}