示例#1
0
文件: login.c 项目: Lutes/McGill
void main(){
	
	char username[50];
	char password[50];
	char form[200];

	//getting length of form
	int n = atoi(getenv("CONTENT_LENGTH"));
	//1 is go back to login page, 0 is continue onto topics page
	int goback = 1;

	//identifiers for form parameters
	char *user = "******";
	char *pass = "******";

	//get the form
	fgets(form,n+1,stdin);

	//get the parameters corresponding to the identifiers
	getSubstring(user, form, username);
	getSubstring(pass, form, password);

	//was getting errors with an extra char on the username, to this just deletes the last char from the username
	int i;
	for (i = 0; i < 50; i++) {
		if (username[i] == '\0') {
			username[i-1] = '\0';
			break;
		}
	}

	//for printing html
	printf("Content-Type:text/html \n\n");
		
	//open members.csv and read line by line
	FILE *fp;
	fp = fopen("members.csv","r");
	char line[1024];
	while (fgets(line, 1024, fp)) {
		//checks if the username and passwords match on the form and members.csv
		goback = login(line, username, password);
		if (goback == 0) break;
	}

	//If no match
	if (goback == 1) {
		printf("Login failed... Click to go back to Login page.");
		//Button that redirects to login page
		printf("<form action=\"http://cs.mcgill.ca/~hkoivu/web/comp206/welcome.html\" method=\"POST\"><input type=\"submit\" value=\"Continue\"></form>"); 
	}
}
示例#2
0
SvgBoundingBox& SvgPolygon::getBoundingBox() {

	if (NULL == this->boundingBoxPtr) {
		//i metodi chiamati possono lanciare runtime_error, che viene propagata.

		string points = getSubstring(getSubstring(this->toString(), Svg::polygonTopDelimiter, Svg::polygonBottomDelimiter), Svg::pointListTopDelimiter,
				Svg::pointListBottomDelimiter);

		SvgBoundingBox& bb = SvgBoundingBox::getBoundingBox(getCoords(points));
		this->boundingBoxPtr = &bb;
	}

	return *(this->boundingBoxPtr);

}
示例#3
0
  /** Retornar el indice de la cadena, si no existe retornar 0*/
  unsigned int Trie::getIndice( string cadena ){
	  //Obtener el nodo raiz del primer caracter de la cadena
	  Nodo * nodo = this->getInicio(cadena[0]);
	  //Obtener el substring de la cadena
	  string subCadena = getSubstring(cadena);
	  //Recorrer toda la cadena, hasta que no haya hijos o se acabe
	  while(nodo != NULL && subCadena.length() > 0){
		  	nodo = nodo->getNodoHijoByCaracter(subCadena[0]);
		  	subCadena = getSubstring(subCadena);
	  }
	  //Si termino con un nodo, y recorrio toda la cadena retornar el indice
	  if (nodo != NULL &&  subCadena.length() == 0)
		  return nodo->getIndice();
	  return 0;
  }
示例#4
0
vector<SvgPoint> SvgPolygon::getCoords(string pointString) {
	vector<SvgPoint> coords = vector<SvgPoint>();
	string tmp, x, y;

	pointString = boost::trim_copy(pointString).append("\n");
	int lfpos = pointString.find("\n");

	while (lfpos >= 0) {
		tmp = boost::trim_copy(pointString.substr(0, lfpos));
		pointString.erase(0, lfpos + 1);

		try {
			x = getSubstring(tmp, "", ","); //can throw a runtime_error
			y = tmp.substr(tmp.find(",") + 1);
			if (y.empty()) {
				throw runtime_error("");
			}
		} catch (runtime_error& e) {
			throw runtime_error("SvgPolygon::getCoords: cannot read coords.");
		}

		coords.push_back(SvgPoint(strtol(x.c_str(), NULL, 0), strtol(y.c_str(), NULL, 0)));
		lfpos = pointString.find("\n");
	}

	return coords;
}
示例#5
0
  /** Eliminar la subcadena del nodo, si debe eliminar retornar true, sino false*/
   bool Trie::deleteSubCadena(Nodo * nodo, string subCadena ){
	  bool eliminar = false;
	   //Obtener el nodo hijo correspondiente al primer caracter de la subcadena
 	  Nodo * nodoHijo = nodo->getNodoHijoByCaracter(subCadena[0]);
 	  //Si existe hijo y la cadena no termino, eliminar la subcadena
 	  if (nodoHijo != NULL && subCadena.length() > 0){
 		  subCadena = getSubstring(subCadena);
 		  eliminar = deleteSubCadena(nodoHijo,subCadena);
  	  }

 	  if (eliminar ){
 		 //Elimino hijo del nodo
 		  nodo->deleteNodoHijo(nodoHijo);
 		  if (nodo->cantHijos() == 0 ){
 			 return true;
 		  }
 		  return false;
 	  }
 	  //Si llego al final de la subCadena, y tiene indice mayor a 0 retornar true
 	  if (subCadena.length() == 0 && nodo->getIndice() > 0){
 		  //Si la cantidad de hijos es 0 eliminar el nodo, si no setear el indice en 0
 	  	  if (nodo->cantHijos() == 0){
 	  		  return true;
 	  	  }else{
 	  		  nodo->setIndice(0);
 	  	  }
 	  }
 	  return false;
   }
示例#6
0
  /** Eliminar la cadena del Trie si existe retornar true, sino false*/
  bool Trie::deleteCadena( string cadena ){
	  //Obtener el nodo raiz del primer caracter de la cadena
	  Nodo * nodo = this->getInicio(cadena[0]);
	  //Obtener el substring de la cadena
	  string subCadena = getSubstring(cadena);
	  return deleteSubCadena(nodo,subCadena);
  }
示例#7
0
int main(void){
	
	char prompt[100];
	char *initialprompt = "Yo bitch.";
	//copy the initial prompt into prompt array for changing
	memcpy(prompt, initialprompt, strlen(initialprompt)+1);
	printf("%s %s", prompt, " ");
	
	char userinput[100];
//	printf("%s", userinput);
//	printf("%d", isQuit(userinput));
//	printf("%d", isSetPrompt(userinput));
	while(gets(userinput) != NULL){
	//the user inputs valid things

		if(isSetPrompt(userinput) == 1){
		//we want to set the prompt
		//get subString also sets the prompt
			getSubstring(prompt, userinput);
		}
		if(isQuit(userinput) == 1){
		//we want to quit	
			exit(0);
		}
		else{
			system(userinput);
		}
		printf("%s %s", prompt, " ");
	}
}
示例#8
0
const char *RegEx::GetSubstring(size_t start, char buffer[], size_t max, size_t *outlen)
{
	if (start >= mSubStrings.length())
	{
		return NULL;
	}

	RegExSub sub = mSubStrings.at(start);

	return getSubstring(subject, sub.start, sub.end, buffer, max, outlen);
}
示例#9
0
int verifySubstring(char* str, State* state)
{
    int i,j, size = strlen(str), ok=0;
    for(i=0;i<size;i++)
    {
        for(j=0;j<size;j++)
        {
            ok = ok || runNFA(state,getSubstring(str,i,j),state->last);
        }
    }
    return ok;
}
示例#10
0
  /** Insertar una cadena al Trie, y retornar si tuvo exito*/
  bool Trie::insertCadenaSubLevel(Nodo* nodo, string cadena , unsigned int indice ){
       string subCadena = getSubstring(cadena);
       /* Insertar caracter en el nodo correspondiente y actualizar el parametro
        * nodo con el hijo donde se hizo la insersecion */
       bool inserto = this->insertCaracterInHijo(&nodo,subCadena[0]);

       //Si no inserto, es el final de la cadena, y el indice no es 0 entonces ya estaba el termino
       if (!inserto && subCadena.length() == 0 && nodo->getIndice() > 0)
             return false;
       else
           if (subCadena.length() > 1){
              return insertCadenaSubLevel(nodo, subCadena, indice);
           }else{
                  nodo->setIndice(indice);
                  return true;
           }
  }
示例#11
0
bool MessageFormatter::processNamedTypes() {
#ifdef HAS_MESSAGE_PATTERN
  auto formatter = formatterObj();
  auto pat = MessageFormatAdapter::getMessagePattern(formatter);

  auto parts_count = pat.countParts();

  // See MessageFormat::cacheExplicitFormats()
  /*
   * Looking through the pattern, go to each arg_start part type.
   * The arg-typeof that tells us the argument type (simple, complicated)
   * then the next part is either the arg_name or arg number
   * and then if it's simple after that there could be a part-type=arg-type
   * while substring will tell us number, spellout, etc.
   * If the next thing isn't an arg-type then assume string.
   *
   * The last two "parts" can at most be ARG_LIMIT and MSG_LIMIT
   * which we need not examine.
   */
  clearError();
  MessageFormatter::NamedPartsMap namedParts;
  MessageFormatter::NumericPartsMap numericParts;

  for (int32_t i = 0; i < parts_count - 2; i++) {
    auto p = pat.getPart(i);
    if (p.getType() != UMSGPAT_PART_TYPE_ARG_START) {
      continue;
    }
    auto name_part = pat.getPart(++i);

    icu::Formattable::Type type = icu::Formattable::kObject;
    switch (p.getArgType()) {
      case UMSGPAT_ARG_TYPE_SIMPLE: {
        auto type_part = pat.getPart(++i);
        if (type_part.getType() != UMSGPAT_PART_TYPE_ARG_TYPE) {
          setError(U_PARSE_ERROR,
            "Expected UMSGPAT_PART_TYPE_ARG_TYPE part following "
            "UMSGPAT_ARG_TYPE_SIMPLE part");
          return false;
        }
        auto type_string = pat.getSubstring(type_part);
        if (type_string == "number") {
          type = icu::Formattable::kDouble;
          auto style_part = pat.getPart(i + 1);
          if (style_part.getType() == UMSGPAT_PART_TYPE_ARG_STYLE) {
            auto style_string = pat.getSubstring(style_part);
            if (style_string == "integer") {
              type = icu::Formattable::kInt64;
            }
          }
        } else if ((type_string == "date") || (type_string == "time")) {
          m_usesDate = true;
          type = icu::Formattable::kDate;
        } else if ((type_string == "spellout") || (type_string == "ordinal") ||
                   (type_string == "duration")) {
          type = icu::Formattable::kDouble;
        }
        break;
      }
      case UMSGPAT_ARG_TYPE_PLURAL:
      case UMSGPAT_ARG_TYPE_CHOICE:
        type = icu::Formattable::kDouble;
        break;
      case UMSGPAT_ARG_TYPE_NONE:
      case UMSGPAT_ARG_TYPE_SELECT:
      default:
        type = icu::Formattable::kString;
        break;
    }

    if (name_part.getType() == UMSGPAT_PART_TYPE_ARG_NAME) {
      auto argName = pat.getSubstring(name_part);
      auto it = namedParts.find(argName);
      if (it != namedParts.end()) {
        if (it->second != type) {
          setError(U_ARGUMENT_TYPE_MISMATCH,
                   "Inconsistent types declared for an argument");
          return false;
        }
      } else {
        namedParts[argName] = type;
      }
    } else if (name_part.getType() == UMSGPAT_PART_TYPE_ARG_NUMBER) {
      auto argNumber = name_part.getValue();
      if (argNumber < 0) {
        setError(U_INVALID_FORMAT_ERROR, "Found part with negative number");
        return false;
      }
      auto it = numericParts.find(argNumber);
      if (it != numericParts.end()) {
        if (it->second != type) {
          setError(U_ARGUMENT_TYPE_MISMATCH,
                   "Inconsistent types declared for an argument");
          return false;
        }
      } else {
        numericParts[argNumber] = type;
      }
    } else {
      setError(U_INVALID_FORMAT_ERROR, "Invalid part type encountered");
    }
  }

  m_namedParts = namedParts;
  m_numericParts = numericParts;
  return true;
#else
  return false;
#endif
}
示例#12
0
        istringstream bufferStream(buffer);

        aux = buffer.substr(0,2);
        if (aux == "v ")
        {
            bufferStream >> id >> dato1 >> dato2 >> dato3;
            _mesh->addVertex(dato1, dato2, dato3);

            center.x += dato1;
            center.y += dato2;
            center.z += dato3;
        } else if (aux == "f ")
        {
            bufferStream >> id >> ind1 >> ind2 >> ind3;

            temp = getSubstring(ind1, "/", 1);
            bufferStream.str(temp);
            bufferStream.clear();
            bufferStream >> dato1;

            bufferStream.ignore(1);

            temp = getSubstring(ind2, "/", 1);
            bufferStream.str(temp);
            bufferStream.clear();
            bufferStream >> dato2;

            bufferStream.ignore(1);

            temp = getSubstring(ind3, "/", 1);
            bufferStream.str(temp);
示例#13
0
文件: Genome.cpp 项目: gdtm86/snapr
//
// Makes a copy of a Genome, but with only one of the sex chromosomes.
//
// The fate of the mitochondrion is that of the X chromosome.
//
    Genome *
Genome::copy(bool copyX, bool copyY, bool copyM) const
{
    Genome *newCopy = new Genome(getCountOfBases(),getCountOfBases(), chromosomePadding);

    if (NULL == newCopy) {
        WriteErrorMessage("Genome::copy: failed to allocate space for copy.\n");
        return NULL;
    }

    const Genome::Contig *currentContig = NULL;
    const Genome::Contig *nextContig = getContigAtLocation(0);

    unsigned offsetInReference = 0;
    while (offsetInReference < getCountOfBases()) {
        if (NULL != nextContig && offsetInReference >= nextContig->beginningOffset) {
            //
            // Start of a new contig.  See if we want to skip it.
            //
            currentContig = nextContig;
            nextContig = getNextContigAfterLocation(offsetInReference + 1);
            if ((!copyX && !strcmp(currentContig->name,"chrX")) ||
                (!copyY && !strcmp(currentContig->name,"chrY")) ||
                (!copyM && !strcmp(currentContig->name,"chrM"))) {
                //
                // Yes, skip over this contig.
                //
                nextContig = getNextContigAfterLocation(offsetInReference + 1);
                if (NULL == nextContig) {
                    //
                    // The chromosome that we're skipping was the last one, so we're done.
                    //
                    break;
                } else {
                    offsetInReference = nextContig->beginningOffset;
                    continue;
                }
            } // If skipping this chromosome

            newCopy->startContig(currentContig->name);
        } // If new contig beginning

        const size_t maxCopySize = 10000;
        char dataBuffer[maxCopySize + 1];

        unsigned amountToCopy = maxCopySize;
        if (nextContig && nextContig->beginningOffset < offsetInReference + amountToCopy) {
            amountToCopy = nextContig->beginningOffset - offsetInReference;
        }

        if (getCountOfBases() < offsetInReference + amountToCopy) {
            amountToCopy = getCountOfBases() - offsetInReference;
        }

        memcpy(dataBuffer,getSubstring(offsetInReference,amountToCopy), amountToCopy);
        dataBuffer[amountToCopy] = '\0';

        newCopy->addData(dataBuffer);

        offsetInReference += amountToCopy;
    }

    newCopy->fillInContigLengths();
    newCopy->sortContigsByName();
    return newCopy;
}
示例#14
0
/**
* This method reads in the records.txt file, forms records out of them,
* and inserts them into the linked list.
**/
int readfile(char name[], char address[], int *yob, char telno[], char filename[], struct record **start)
{

	/* Initialize variables */
	char line[100];
	line[0] = '\0';
	int colCount = 0;
	int intchar = 0;
	char nextchar[2];
	char yearofbirth[15];
    int counter = 0;
	
	/* Open records.txt */
	filein = fopen(filename, "r");
	
		/* The file does not exist */
		if(!filein)
			return 1;
		
		/* Load contents into struct account */
		while(intchar != -1)
		{
			/* Each column represents a field.  End the entry after the last column. */
			while(colCount < 4)
			{
			
			/* Read in the data as an int */
			intchar = fgetc(filein);
			
				/* checks for EOF */
				if(intchar == -1)
				{
					break;
				}
								
				/* Copies each character 1 at a time */
				else
				{
					/* Convert the int to a char and store it */
					nextchar[0] = (char)intchar;
					nextchar[1] = '\0';
					
					/* If a column is encountered increment the counter */
					if(nextchar[0] == '|')
						colCount++;
					
					/* If the character is a newline skip it */
					if(intchar == 10)
						continue;
					
					/* If not add it to the string line */
					else
						strcat(line, nextchar);
				}
                
                /* EOF has been reached */                
				if(intchar == -1)
					break;
			}
            
            /* Reset the column counter for the next record */
            colCount = 0;
            
            /* EOF has been reached */
			if(intchar == -1)
				break;
                        
			/* Gets the field for name */
			getSubstring(name, line);
            
			/* Gets the field for address */
			getSubstring(address, line);
			
			/* Gets the field for yob */
			getSubstring(yearofbirth, line);
			*yob = atoi(yearofbirth);
			memset(yearofbirth, 0, 15);	
            
			/* Gets the field for telno */
			line[strlen(line)-1] = 0;
            
            /* Copy the rest of the line to the phone number */
            strcpy(telno, line);
    		
    		/* Add the record to the linked list */
            addRecord(start, name, address, *yob, telno);
            
            counter++;
            
			/* Clears line */
			memset(line, 0, 100);
            
        }
		
        /* Print the number of records retrieved */
        printf("\n%d%s\n", counter, " records retrieved.");
    
		/* Success!  */
		fclose(filein);
		return 0;
}
示例#15
0
文件: Genome.cpp 项目: fnothaft/snap
//
// Makes a copy of a Genome, but with only one of the sex chromosomes.
//
// The fate of the mitochondrion is that of the X chromosome.
//
    Genome *
Genome::copy(bool copyX, bool copyY, bool copyM) const
{
    Genome *newCopy = new Genome(getCountOfBases(),getCountOfBases());

    if (NULL == newCopy) {
        fprintf(stderr,"Genome::copy: failed to allocate space for copy.\n");
        return NULL;
    }

    const Genome::Piece *currentPiece = NULL;
    const Genome::Piece *nextPiece = getPieceAtLocation(0);

    unsigned offsetInReference = 0;
    while (offsetInReference < getCountOfBases()) {
        if (NULL != nextPiece && offsetInReference >= nextPiece->beginningOffset) {
            //
            // Start of a new piece.  See if we want to skip it.
            //
            currentPiece = nextPiece;
            nextPiece = getNextPieceAfterLocation(offsetInReference + 1);
            if ((!copyX && !strcmp(currentPiece->name,"chrX")) ||
                (!copyY && !strcmp(currentPiece->name,"chrY")) ||
                (!copyM && !strcmp(currentPiece->name,"chrM"))) {
                //
                // Yes, skip over this piece.
                //
                nextPiece = getNextPieceAfterLocation(offsetInReference + 1);
                if (NULL == nextPiece) {
                    //
                    // The chromosome that we're skipping was the last one, so we're done.
                    //
                    break;
                } else {
                    offsetInReference = nextPiece->beginningOffset;
                    continue;
                }
            } // If skipping this chromosome

            newCopy->startPiece(currentPiece->name);
        } // If new piece beginning

        const size_t maxCopySize = 10000;
        char dataBuffer[maxCopySize + 1];

        unsigned amountToCopy = maxCopySize;
        if (nextPiece && nextPiece->beginningOffset < offsetInReference + amountToCopy) {
            amountToCopy = nextPiece->beginningOffset - offsetInReference;
        }

        if (getCountOfBases() < offsetInReference + amountToCopy) {
            amountToCopy = getCountOfBases() - offsetInReference;
        }

        memcpy(dataBuffer,getSubstring(offsetInReference,amountToCopy), amountToCopy);
        dataBuffer[amountToCopy] = '\0';

        newCopy->addData(dataBuffer);

        offsetInReference += amountToCopy;
    }

    return newCopy;
}