Ejemplo n.º 1
0
void
Network::Run(const String& command) {
	if (!command.IsEmpty()) {
		String args;
		String delim(L"/");
		command.SubString(String(L"gap://").GetLength(), args);
		StringTokenizer strTok(args, delim);
		if(strTok.GetTokenCount() < 3) {
			AppLogDebug("Not enough params");
			return;
		}
		String method;
		String hostAddr;
		strTok.GetNextToken(method);
		strTok.GetNextToken(callbackId);
		strTok.GetNextToken(hostAddr);

		// URL decoding
		Uri uri;
		uri.SetUri(hostAddr);
		AppLogDebug("Method %S, callbackId %S, hostAddr %S URI %S", method.GetPointer(), callbackId.GetPointer(), hostAddr.GetPointer(), uri.ToString().GetPointer());
		if(method == L"org.apache.cordova.Network.isReachable") {
			IsReachable(uri.ToString());
		}
		AppLogDebug("Network command %S completed", command.GetPointer());
		} else {
			AppLogDebug("Can't run empty command");
		}
}
Ejemplo n.º 2
0
void
Compass::Run(const String& command) {
	if (!command.IsEmpty()) {
		String args;
		String delim(L"/");
		command.SubString(String(L"gap://").GetLength(), args);
		StringTokenizer strTok(args, delim);
		if(strTok.GetTokenCount() < 2) {
			AppLogDebug("Not Enough Params");
			return;
		}
		String method;
		strTok.GetNextToken(method);
		// Getting callbackId
		strTok.GetNextToken(callbackId);
		AppLogDebug("Method %S, callbackId: %S", method.GetPointer(), callbackId.GetPointer());
		// used to determine callback ID
		if(method == L"com.phonegap.Compass.watchHeading" && !callbackId.IsEmpty() && !IsStarted()) {
			AppLogDebug("watching compass...");
			StartSensor();
		}
		if(method == L"com.phonegap.Compass.clearWatch" && !callbackId.IsEmpty() && IsStarted()) {
			AppLogDebug("stop watching compass...");
			StopSensor();
		}
		if(method == L"com.phonegap.Compass.getCurrentHeading" && !callbackId.IsEmpty() && !IsStarted()) {
			AppLogDebug("getting current compass...");
			GetLastHeading();
		}
		AppLogDebug("Compass command %S completed", command.GetPointer());
	} else {
		AppLogDebug("Can't run empty command");
	}
}
Ejemplo n.º 3
0
void
GeoLocation::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() > 1) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
		}
		AppLogDebug("Method %S, Callback: %S", method.GetPointer(), callbackId.GetPointer());
		// used to determine callback ID
		if(method == L"com.phonegap.Geolocation.watchPosition" && !callbackId.IsEmpty() && !IsWatching()) {
			AppLogDebug("watching position...");
			StartWatching();
		}
		if(method == L"com.phonegap.Geolocation.stop" && IsWatching()) {
			AppLogDebug("stop watching position...");
			StopWatching();
		}
		if(method == L"com.phonegap.Geolocation.getCurrentPosition" && !callbackId.IsEmpty() && !IsWatching()) {
			AppLogDebug("getting current position...");
			GetLastKnownLocation();
		}
		AppLogDebug("GeoLocation command %S completed", command.GetPointer());
	}
}
Ejemplo n.º 4
0
void
Accelerometer::Run(const String& command) {
	if (!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() == 1) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
		}
		if(method == L"com.cordova.Accelerometer.watchAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			StartSensor();
		}
		if(method == L"com.cordova.Accelerometer.clearWatch" && IsStarted()) {
			StopSensor();
		}
		if(method == L"com.cordova.Accelerometer.getCurrentAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			GetLastAcceleration();
		}
		AppLogDebug("Acceleration command %S completed", command.GetPointer());
	} else {
		AppLogDebug("Can't run empty command");
	}
}
Ejemplo n.º 5
0
  /** \brief Check wheter a token at a given position is a string.
      \param a_Tok [out] If a variable token has been found it will be placed here.
  	  \return true if a string token has been found.
      \sa IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsEOF, IsInfixOpTok, IsPostOpTok
      \throw nothrow
  */
  bool ParserTokenReader::IsString(token_type &a_Tok)
  {
    if (m_strFormula[m_iPos]!='"') 
      return false;

    string_type strBuf(&m_strFormula[m_iPos+1]);
    std::size_t iEnd(0), iSkip(0);

    // parser over escaped '\"' end replace them with '"'
    for(iEnd=(int)strBuf.find( _T("\"") ); iEnd!=0 && iEnd!=string_type::npos; iEnd=(int)strBuf.find( _T("\""), iEnd))
    {
      if (strBuf[iEnd-1]!='\\') break;
      strBuf.replace(iEnd-1, 2, _T("\"") );
      iSkip++;
    }

    if (iEnd==string_type::npos)
      Error(ecUNTERMINATED_STRING, m_iPos, _T("\"") );

    string_type strTok(strBuf.begin(), strBuf.begin()+iEnd);

    if (m_iSynFlags & noSTR)
      Error(ecUNEXPECTED_STR, m_iPos, strTok);

		m_pParser->m_vStringBuf.push_back(strTok); // Store string in internal buffer
    a_Tok.SetString(strTok, m_pParser->m_vStringBuf.size());

    m_iPos += (int)strTok.length() + 2 + (int)iSkip;  // +2 wg Anführungszeichen; +iSkip für entfernte escape zeichen
    m_iSynFlags = noANY ^ ( noARG_SEP | noBC | noOPT | noEND );

    return true;
  }
Ejemplo n.º 6
0
int main()
{
	char line[1000];
	printf("enter a list of integers separated by a space bar: ");
	readline(line, 1000);
	printf("you entered: %s\n", line);
	char * toks[200];

	int ne = strTok(line, ' ', toks, 200);
	int * ints = new int[ne];
	for(int i = 0; i < ne; i++)
	{
		int n = atoi(toks[i]);
		ints[i] = n;
	}

	qsort((void*) ints, ne, sizeof(int), &intCmpA);
	printf("values:");
	int sum = 0;
	for(int i = 0; i < ne; i++)
	{
		printf("% i +", ints[i]);
		sum += ints[i];
	}
	printf("\b = %i\n", sum);
	delete [] ints;
	return 0;
}
Ejemplo n.º 7
0
void
Notification::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() < 1) {
			AppLogException("Not enough params");
			return;
		}
		if((method == L"com.phonegap.Notification.alert" || method == L"com.phonegap.Notification.confirm")) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("%S %S", method.GetPointer(), callbackId.GetPointer());
			if(!callbackId.IsEmpty()) {
				Dialog();
			}
		} else if(method == L"com.phonegap.Notification.vibrate") {
			long duration;
			String durationStr;

			strTok.GetNextToken(durationStr);
			AppLogDebug("%S %S", method.GetPointer(), durationStr.GetPointer());
			// Parsing duration
			result r = Long::Parse(durationStr, duration);
			if(IsFailed(r)) {
				AppLogException("Could not parse duration");
				return;
			}
			Vibrate(duration);
		} else if(method == L"com.phonegap.Notification.beep") {
			int count;
			String countStr;

			strTok.GetNextToken(countStr);
			AppLogDebug("%S %S", method.GetPointer(), countStr.GetPointer());
			// Parsing count
			result r = Integer::Parse(countStr, count);
			if(IsFailed(r)) {
				AppLogException("Could not parse count");
				return;
			}

			Beep(count);
		}
	}
}
Ejemplo n.º 8
0
void
Kamera::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() < 1) {
			AppLogException("Not enough params");
			return;
		}
		strTok.GetNextToken(callbackId);
		if(method == "com.phonegap.Camera.getPicture" && !callbackId.IsEmpty()) {
			GetPicture();
		}
	}
}
Ejemplo n.º 9
0
DataManager * DataManager::readFile ( std::string const & dataset )
{
  std::ifstream file;
  DataManager * man = NULL;
  try {
    file.open(dataset);
    std::string line;
    getline(file, line);
    boost::tokenizer<boost::escaped_list_separator<char>> tok(line);
    boost::char_separator<char> sep("|");
    boost::tokenizer<boost::char_separator<char>> strTok(*tok.begin(), sep);
    auto it = strTok.begin();
    std::string name = *it; ++it;
    std::string type = *it;
    if (type.size() != 1) {
      throw (DataManagerException("wrong token defined"));
    } else {
      file.seekg(0);
      switch (type[0]) {
        case 'H':
          man = new HeightDataManager(file);
          man->type = DM_Height;
          break;
        case 'C':
          man = new ColorDataManager(file);
          man->type = DM_Color;
          break;
        default:
          throw (DataManagerException("wrong dataset type defined"));
      }
    }
    if (man != NULL)
      man->name = name;
    std::cout << "Loaded dataset " << man->name << std::endl;
  }
  catch (std::ifstream::failure & e) {
    std::cerr << "Error opening file " << e.what() << std::endl;
    return NULL;
  }
  catch (DataManagerException & e ) {
    std::cerr << e.what() << std::endl;
    return NULL;
  }
  return man;
}
Ejemplo n.º 10
0
void
DebugConsole::Run(const String& command) {
	if(!command.IsEmpty()) {
		String args;
		String delim(L"/");
		command.SubString(String(L"gap://").GetLength(), args);
		StringTokenizer strTok(args, delim);
		if(strTok.GetTokenCount() < 3) {
			AppLogDebug("Not enough params");
			return;
		}
		String method;
		String statement(64);
		String logLevel;
		strTok.GetNextToken(method);
		strTok.GetNextToken(statement);
		CleanUp(statement);
		strTok.GetNextToken(logLevel);
		//AppLogDebug("method %S statement %S loglevel %S", method.GetPointer(), statement.GetPointer(), logLevel.GetPointer());
		if(method == L"com.phonegap.DebugConsole.log") {
			Log(statement, logLevel);
		}
	}
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    char *filename;
    char *buf;
    char *tk;
    record vals;
    record *recp = &vals;
    FILE *fp;
    char guard[100];
    int idx = MINNAME;
    int lastval = 0;
    int lastmem = 0;

    if (argc != 2) {
	fprintf(stderr, "mkdefs: 1 argument necessary\n");
	exit(1);
    }
    filename = argv[1];

    vals.next = 0;
    buf = malloc(BSIZE);
    while (fgets(buf, BSIZE, stdin)) {
	lineno++;
	tokno = 0;
	tk = strTok(buf);
	if ((!tk) || (*tk == '#'))
	    continue;		/* comment */
	recp = newRec(recp);
	if (*tk == 'V')
	    recp->kind = K_val;
	else if (*tk == 'M')
	    recp->kind = K_member;
	else
	    recp->kind = 0;
	recp->data = buf;
	recp->symbol = tk;
	recp->name = strTok(0);
	recp->lex = strTok(0);
	recp->type = strTok(0);
	if (recp->kind) {
	    recp->domain = strTok(0);
	    recp->range = strTok(0);
	}
	buf = malloc(BSIZE);
    }

    fp = fopen(filename, "w");
    if (!fp) {
	fprintf(stderr, "mkdefs: Could not open %s for writing\n",
		filename);
	exit(1);
    }

    genGuard(filename, guard);
    fprintf(fp, header, guard, guard);
    fputs(prefix, fp);

    for (recp = vals.next; recp; recp = recp->next) {
	if (recp->kind == K_val)
	    lastval = idx;
	else if (recp->kind == K_member)
	    lastmem = idx;
	fprintf(fp, "#define\t%s\t% 5d\n", recp->symbol, idx++);
    }
    idx--;
    fprintf(fp, "\n#define LAST_V %d\n", lastval);
    fprintf(fp, "#define LAST_M %d\n", lastmem);
    fprintf(fp, "#define MINNAME %d\n#define MAXNAME %d\n\n", MINNAME,
	    idx);

    fprintf(fp, "static Exid_t symbols[] = {\n");
    for (recp = vals.next; recp; recp = recp->next) {
	fprintf(fp, "\tEXID ( %s, %s, %s, %s, 0),\n",
		recp->name, recp->lex, recp->symbol, recp->type);
    }
    fprintf(fp, "\tEXID ( {0}, 0, 0, 0, 0)\n};\n");

    fprintf(fp, "\nstatic char* typenames[] = {\n");
    for (recp = vals.next; recp; recp = recp->next) {
	if (*(recp->symbol) == 'T')
	    fprintf(fp, "\t%s,\n", recp->name);
    }
    fprintf(fp, "};\n");

#ifdef DEBUG
    fprintf(fp, "\nstatic char* gprnames[] = {\n\t\"\",\n");
    for (recp = vals.next; recp; recp = recp->next) {
	fprintf(fp, "\t\"%s\",\n", recp->symbol);
    }
    fprintf(fp, "};\n");
#endif

    fprintf(fp, "\ntypedef unsigned short tctype;\n");
    fprintf(fp, "\nstatic tctype tchk[][2] = {\n\t{ 0, 0 },\n");
    for (recp = vals.next; recp; recp = recp->next) {
	if (recp->kind)
	    fprintf(fp, "\t{ %s, %s },\n", recp->domain, recp->range);
    }
    fprintf(fp, "};\n");

    fprintf(fp, "\n#endif\n");
    fclose(fp);
    exit(0);
}
Ejemplo n.º 12
0
void doCount(char* line)
{
	char* nombre = getargument(line);
	strTok(nombre);
}
Ejemplo n.º 13
0
int cds_openDataStore(char *database)
{

	if(cdsInfo.state != CDS_CLOSED) 
	{
		LOG_ERROR("CDS already open. \n");
		return CDS_ALREADYOPEN;
	}

	//adding .sch extension
	char *temp=(char *)malloc(sizeof(char)*(strlen(database)+5));
	strcpy(temp,database);
	strcat(temp,".sch");
	
	cdsInfo.database=(char*)malloc(sizeof(char)*(strlen(database)+1));
	strcpy(cdsInfo.database,database);
	FILE *scf;//schema file

	scf=fopen(temp,"rb");

	if(scf==NULL)
	   return OPENCDS_FAIL;

	cdsInfo.freelist=(struct stack *)malloc(sizeof(struct stack));

	//reading .sch file line by line and storing it in buffer
	char *line = (char *)malloc(sizeof(char)*80);
	int i=0;

	FILE *pndx,*sndx,*fp;//pointers to hold .ndx files


	//this loop parses .sch file and opens all ndx and dat files and also populates cdsInfo structure
	while( fgets(line,80,scf) != NULL )
    {
		char *temp=strTok(line,":"); //Colname
		char *size=strTok(NULL,":"); //size of the field
		char *datatype=strTok(NULL,":"); //string
		char *last=strTok(NULL,":");

		if(temp!=NULL && size!=NULL && datatype!=NULL && last==NULL)
		{
			cdsInfo.fileregister[i].colname=(char*)malloc(sizeof(char)*strlen(temp));
			strcpy(cdsInfo.fileregister[i].colname,temp);
			strcat(cdsInfo.fileregister[i].colname,"\0");
			cdsInfo.fileregister[i].type = TYPE_STRING;
			cdsInfo.fileregister[i].length=atoi(size);

			char *fieldname = convert_to_filename(database,temp,".dat");
			
			fp=fopen(fieldname,"rb+");
			if(fp==NULL) 
			{
				LOG_ERROR(".dat file not getting created \n");
				return OPENCDS_FAIL;
				
			}
			cdsInfo.fileregister[i].fptr=fp;

			if(i==0)
			{ 
                  char *indexfilename=convert_to_filename(database,temp,".ndx");    	
			      pndx=fopen(indexfilename,"rb");
			      if(pndx==NULL)
				  {
					LOG_ERROR("Cannot open primary .ndx file.\n");
					return OPENCDS_FAIL;
				  }
			}
			if(i==1)
			{
			     char *indexfilename=convert_to_filename(database,temp,".ndx");    			
			     sndx=fopen(indexfilename,"rb");
			     if(sndx==NULL)
				 {
					LOG_ERROR("Cannot open secondary .ndx file.\n");
					return OPENCDS_FAIL;
				 }
			}
		}
		i++;
	}
	cdsInfo.numCols=i;
	//Populating freelist variable of cdsInfo and loading it 
	cdsInfo.freelist=(struct stack *)malloc(sizeof(struct stack));
	stackInit(cdsInfo.freelist);
	LOG_INFO("Initialized free list\n");


	if(stackLoadFromFile(pndx, cdsInfo.freelist)==STACK_FAIL)
		{
		LOG_ERROR("Didn't load stack from primary .ndx file\n");
		return OPENCDS_FAIL;
		}
	LOG_INFO("Loaded stack with freelist from primary .ndx file \n");


	cdsInfo.primaryNdx = bstLoadFromFile(pndx);
	LOG_INFO("\nLoaded BST from primary .ndx file\n");

	cdsInfo.secondaryNdx=(struct hashTable*)malloc(sizeof(struct hashTable));
	

	hashInit(cdsInfo.secondaryNdx,0);//Initializing hashtable
	if(hashLoadFromFile(sndx,cdsInfo.secondaryNdx)==HASH_FAIL)
	{
		LOG_ERROR("Didn't load hash table from secondary .ndx file\n");
		return OPENCDS_FAIL;//hashLoad Failed
	}
	LOG_INFO("\nLoaded Hash Table from secondary .ndx file\n");	

	//closing ndx files     
	fclose(pndx);
	fclose(sndx);   

	//closing schema file
	fclose(scf);      
	LOG_INFO("CDS open!");
	cdsInfo.state = CDS_OPEN_RW; // else set state to open
	for(i=0;i<cdsInfo.numCols;i++)
		printf("%s\n",cdsInfo.fileregister[i].colname);
	free(temp);
	return OPENCDS_SUCCESS;
}
Ejemplo n.º 14
0
static int two(global **contain){
	/*load stack*/
	global *container = *contain;
	FILE *stream;/*file reading from*/
	char *inp;
        long long perc = 0; /*percentage complete*/
	long long length = 0;/*length of import file*/
	int a,b,c,d,t,co;
	char *line = calloc(sizeof(int),MAXLEN);
	int j=0;/*used to check EOF*/
	printf("\nPlease select file\n>");
	co=True;/*repeat version check once*/
	inp = getInput();
	stream=fopen(inp,"r");
	if(!stream){/*cannot read from*/
	   free(inp);
	   inp=NULL;
	   free(line);
	   line = NULL;
	   return False;
	}
	struct stat statbuf;
        stat(inp, &statbuf);
        length=statbuf.st_size;
	free(inp);
	inp=NULL;
	/*check if this is a wellformed file*/
	a=fgetc(stream);
	b=fgetc(stream);
	c=fgetc(stream);
	d=fgetc(stream);
	if(a!=0x5A  || b!=0xB1 || c!=0xF0 || d!=0x0A){/*does it have the header?*/
	   fprintf(stderr,"Error: Invalid header\n");
	   fclose(stream);
	   stream=NULL;
	   return False;/*not a valid file*/
	}
	/*begin import*/
	destroyContainer(&container);/*purge results*/
	resetContainer(&container);/*reset use*/
	/*scan document, and rebuild statistics for NEW file*/
	for(container ->total=0;j!= -1;container->total = container ->total+1){
	   j=get_line(line, stream);/*get line from file, is being given length of line*/
	   if(j==-1){/*breakouttahere!*/
	       break;
	   }
	   if(co==True){/*check this once*/
	      co=False;
		  t = checkForm(line);/*check if older type True if current, False if older*/
	   }
	   int le = 0;/*length of line*/
	   /*there are four items in this line*/
	   /*long name|unsigned int type|char *fil|long long address*/
	   char *tmp=NULL;/*ensure we have space*/
	   tmp=strTok(line,&le,'|');
	   if(tmp ==NULL){
	     break;
	   }
	   long name =atol(tmp);
	   free(tmp);
	   tmp=NULL;
	   
	   tmp=strTok(line,&le,'|');
	   if(tmp ==NULL){
	     break;
	   }
	   unsigned int type=atoi(tmp);
	   free(tmp);
	   tmp=NULL;
	   
       
	   unsigned int misc;
	   if(t==True){
	      tmp=strTok(line,&le,'|');
	      if(tmp ==NULL){
	        break;
	      }
	      misc=atoi(tmp);
	      free(tmp);
	      tmp=NULL;
	   }
	   else{
	      misc = 0x0000;
	   }
	   
	   char *fil =strTok(line,&le,'|');
	   if(fil ==NULL){
	     break;
	   }
	   tmp = strTok(line,&le,'\n');
	   if(tmp ==NULL){
	     break;
	   }
	   
	   long long addr = atoll(tmp);
	   free(tmp);
	   tmp=NULL;
	   /*add this thing to the stack*/
	  pushNode(createNode(name,fil,type, misc, addr),&container->head,&container->tail);
	  /*add type to collection*/
	  if((type & Po)==Po){/*picture*/
         container->picCount=container->picCount+1;
	  }
	  if((type & Eo)==Eo){/*executable*/
         container->exeCount=container->exeCount+1;
	  }
	  if((type & Wo)==Wo){/*audio*/
         container->wavCount=container->wavCount+1;
	  }
	  if((type & Vo)==Vo){/*video*/
         container->aviCount=container->aviCount+1;
	  }
	  if((type & To)==To){/*text*/
         container->docCount=container->docCount+1;
	  }
	  /*end add type to collection*/
	  free(fil);
	  fil=NULL;
	  perc = (ftell(stream)*100)/length;
	  fprintf(stderr,"Import %lld %% complete\r",perc);
	}/*end the importing*/
	fprintf(stderr,"\n");
	free(line);
	line = NULL;
	fclose(stream);
	stream=NULL;
	return True;
}