示例#1
0
channel *NewChannel(const char *Id) {

   channel *Channel;

   if (Id == NULL) {
      Error("NewChannel(): Id = NULL");
      return NULL;
   } else if (! IsId(Id)) {
      Error("NewChannel(): Id = \"%s\" is not an ID",Id);
      return NULL;
   } else if (SearchObject(Lists,Id,OBJECT) != NULL) {
      Error("NewChannel(): Id = \"%s\" is already used",Id);
      return NULL;
   } else if ((Channel = calloc(1,sizeof(channel))) == NULL) {
      Error("NewChannel(): not enough memory for channel \"%s\"",Id);
      return NULL;
   }

   Channel->Type = CHANNEL;
   Channel->Id   = NewString(Id);
   strcpy(Channel->Owner,DEFAULT_USER);
   strcpy(Channel->Group,DEFAULT_GROUP);
   Channel->Topic     = NewString("");
   Channel->UserNb    = 0;
   Channel->Closed    = FALSE;
   Channel->Hidden    = FALSE;
   Channel->Invite    = FALSE;
   Channel->Protected = FALSE;
   Channel->Resident  = FALSE;

   return Channel;
}
示例#2
0
 bool ObjectInfo::IsProjectId(const string &s)
 {
   vector<string> pieces  = Split(s, '-');
   return ((pieces.size() == 2) &&
           (pieces[0] == "project") &&
           (IsId(pieces[1])));
 }
示例#3
0
 bool ObjectInfo::IsObjectId(const string &s)
 {
   vector<string> pieces  = Split(s, '-');
   return ((pieces.size() == 2) &&
           (pieces[0] == "record" || pieces[0] == "gtable" || pieces[0] == "file" || pieces[0] == "table" || pieces[0] == "applet") &&
           (IsId(pieces[1])));
 }
示例#4
0
channel *SearchChannel(const char *Id) {

   if (Id == NULL) {
      Error("SearchChannel(): Id = NULL");
      return NULL;
   } else if (! IsId(Id)) {
      Error("SearchChannel(): Id = \"%s\" is not an ID",Id);
      return NULL;
   }

   return (channel *) SearchObject(ChannelList,Id,CHANNEL);
}
示例#5
0
String Lex::Id(int pos)
{
	if(!IsId(pos))
		ThrowError("expected id");
	return id[Code(pos) - 256];
}
示例#6
0
// function that tokenizes the input, using a structure of conscell's, where each conscell has a car and a cdr,
// each car has two values, the type and the actual value.
ConsCell* tokenize(char *expression) {
  ConsCell *current =malloc(sizeof(ConsCell));
  ConsCell *Head = current;
  int i = 0;
  for (int i = 0; expression[i]; i++) {
    if (expression[i]==' ') continue;
      else if (expression[i] == '\n'){
        continue;
      }
    if (expression[i]== '\t'){
      continue;
    }
    Value *carVar = malloc(sizeof(Value));
    Value *cdrVar = malloc(sizeof(Value));
    if (expression[i]=='(') {
      carVar->type = 6;
      carVar->openValue = '(';
    }

    else if (expression[i]==')') {
      carVar->type=7;
      carVar->closeValue = ')';
    }
    else {
      
      if (IsAnInt(expression, i)) {
        carVar->type=2;
        carVar->intValue=GiveInt(expression, i);
        i = getNextTerminal(expression, i);
        i -=1;
      }
      else if(IsSymbol(expression, i)) {
        int symbolLength=returnSymbolLength(expression, i);
        carVar->type=5;
        carVar->symbolValue=returnSymbol(expression, i, symbolLength);
        if (IsId(carVar->symbolValue)){
          carVar->type = 9;
          carVar->idValue = carVar->symbolValue;
        }
        else if (IsPrimitive(carVar->symbolValue)) {
          carVar->type = 13;
          carVar->primValue = carVar->symbolValue;
        }
        i+=symbolLength;
      }
      else if(IsString(expression, i)) {
        carVar->type=4;
        carVar->stringValue=returnString(expression, i);
        int lengthOfString = findLengthOfString(carVar->stringValue);
        i+=lengthOfString;
      }
      else if(IsBoolean(expression,i)){
        carVar->type = 1;
        carVar->boolValue=returnBoolean(expression,i);
        i +=1;
      }
      else if(IsFloat(expression, i)) {
        carVar->type=3;
        carVar->floatValue=GiveFloat(expression, i);
        i = getNextTerminal(expression, i);
        i -=1;
      }
      else if(expression[i] == ';') {
        free(carVar);
        free(cdrVar);
        break;
      }
      else {
        free(carVar);
        free(cdrVar);
        printf("Error: Bad syntax.\n");
        ConsCell *emptyCons =malloc(sizeof(ConsCell));
        Value *Val = malloc(sizeof(Value));
        Val->type = 0;
        Val->intValue= 1;
        emptyCons->car = Val;
        Value *cdrVal = malloc(sizeof(Value));
        cdrVal->type = 0;
        cdrVal->intValue = 0;
        current->car = cdrVal;
        cleanupCCLL(Head);
        return emptyCons;
        break;
      }
      
      


    }
    ConsCell *newCell = malloc(sizeof(ConsCell));
    cdrVar->type = 8;
    cdrVar->cons = newCell;
    current = insertCC(current, carVar, cdrVar);
    current = newCell;

  }
  Value *cdrVal = malloc(sizeof(Value));
  cdrVal->type = 0;
  cdrVal->intValue = 0;
  current->car = cdrVal;
  return Head;

}