Ejemplo n.º 1
0
void robPrintAscii(void)
{
int k=0;  
  for(k = 0; k < 3; k++) {
	addspace(k);
    printf("    i_i    \n");
	 addspace(k);
    printf("   [b_b]   \n");
	 addspace(k);
    printf("   [^_^]   \n");
	 addspace(k);
    printf("  /|___|\\  \n");
	 addspace(k);
    printf("   d   b   \n");
  } 

}
Ejemplo n.º 2
0
int main () {

    char letter;
    int sumsofar;
    printf("Enter an abitrarily long string, ending with carriage return > ");
    sumsofar = 0;
    while (letter != '\n') {
        scanf("%c", &letter);
        findsum(letter, &sumsofar);
    }
    addspace(&sumsofar);
    printf("Check sum is %c\n", (char)(sumsofar));
    return 0;
}
Ejemplo n.º 3
0
commandline parse(std::string codeline) {
	commandline c ; 
	std::stringstream ss(codeline) ;
	std::string item ;
	
	int tokens_found = 0 ;

	while (std::getline(ss, item, ' ')) {
		tokens_found++ ;
		if (tokens_found == 1) {
			c.function = item ;
		} else if (item.rfind("--")==0) {
			c.options.push_back(item) ;
		} else {
			c.args.push_back(addspace(item)) ;
		}
	}
	return c ;
}
Ejemplo n.º 4
0
void interpret(commandline c, Schedule* s) {
	switch (to_command(c.function)) {
		case QUIT:
			std::cout<<"Bye bye !"<<std::endl ;
			break ;
		
		case HELP:
			if (c.args.size() == 0) {
				help(HELP) ;
			} else {
				help(to_command(c.args[0])) ;
			}
			break ;

		case IMPORT:
			if (check_args(c, 2, 0)) {
				std::string schedule = 	c.args[0] ;
				std::string dotations = c.args[1] ;
			 s->import_html(schedule, dotations) ;
			}
			break ;
		case ADDTEACHER:
			for (std::vector<std::string>::iterator it=c.args.begin() ; 
				it!=c.args.end() ; it++) {
			 s->add_teacher(*it) ;
			}
			break ;
		case LISTTEACHER:
			if(check_args(c, 0, 0)) {
			 s->list_teachers() ;
			}
			break ;
		case LISTGROUP:
			if(check_args(c, 0, 0)) {
			 s->list_groups() ;
			}
			break ;
		case DISPLAY:
			if(check_args(c, 1, 1)) {
				std::string name = addspace(c.args[0]) ;
				int semester = handle_options(c.options) ;
                s->display(name, semester) ;
			}
			break ;
		case ASSIGN:
			{
				std::string teacher = addspace(c.args[0]) ;
                c.args.erase(c.args.begin()) ;
				int semester = handle_options(c.options) ;
                s->assign(teacher, c.args, semester) ;
			}
			break ;
		case UNASSIGN:
			if(check_args(c, 1, 1)) {
				std::string group = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->unassign(group, semester) ;
			}
			break ;
		case UNASSIGNED:
			if(check_args(c, 0, 1)) {
				int semester = handle_options(c.options) ;
                s->unassigned_groups(semester) ;
			}
			break ;
		case COMPATIBLE:
			if(check_args(c, 1, 1)) {
				std::string name = addspace(c.args[0]) ;
				int semester = handle_options(c.options) ;
                s->compatible(name, semester) ;
			}
			break ;
		case COMPATIBLE2:
			if(check_args(c, 1, 1)) {
				std::string name = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->compatible2(name, semester) ;
			}
			break ;
		case COMPATIBLEOMSI:
			if(check_args(c, 1, 1)) {
				std::string name = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->compatible_omsi(name, semester) ;
			}
			break ;

		case DELETETEACHER:
			if(check_args(c, 1, 0)) {
				std::string name = c.args[0] ;
			 s->delete_teacher(name) ;
			}
			break ;
		case INDISP:
			if (check_args(c, 4, 1)) {
				std::string name = addspace(c.args[0]) ;
				int day = get_day(c.args[1]) ;
				int h_begin = get_hour(c.args[2]) ;
				int h_end = get_hour(c.args[3]) ;
				int semester = handle_options(c.options) ;
                s->indisp(name, semester, day, h_begin, h_end) ;
			}
			break ;
		case DISP:
			if (check_args(c, 4, 1)) {
				std::string name = c.args[0] ;
				int day = get_day(c.args[1]) ;
				int h_begin = get_hour(c.args[2]) ;
				int h_end = get_hour(c.args[3]) ;
				int semester = handle_options(c.options) ;
                s->disp(name, semester, day, h_begin, h_end) ;
			}
			break ;

		default:
			std::cout<<"Unrecognized command, try again !"<<std::endl ;
	}
}
Ejemplo n.º 5
0
/*@notnull@*/ void *allocandusespaceviaptr(char *file,Uint line, 
                                           /*@null@*/ void *ptr,
                                           Uint size,Uint number)
{
  Uint i, blocknum;

  DEBUG2(2,"\n# allocandusespaceviaptr(file=%s,line=%lu)\n",file,
                      (Showuint) line);
  if(nextfreeblock > 0)
  {
    NOTSUPPOSEDTOBENULL(blocks);
    for(blocknum=0; blocknum < nextfreeblock; blocknum++)
    {
      if(blocks[blocknum].spaceptr == ptr)
      {
        break;
      }
    }
  } else
  {
    blocknum = 0;
  }
  if(blocknum == nextfreeblock)
  {
    if(ptr == NULL)
    {
      nextfreeblock += 64;
      blocks = (Blockdescription *) realloc(blocks,
                                            (size_t) (sizeof(Blockdescription)* 
                                                      nextfreeblock));
      if(blocks == NULL)
      {
        ALLOCVIAFATAL("not enough space for the block descriptions available");
      }
      for(i=blocknum; i < nextfreeblock; i++)
      {
        blocks[i].spaceptr = NULL;
        blocks[i].sizeofcells = 0;
        blocks[i].numberofcells = 0;
      }
    } else
    {
      ALLOCVIAFATAL("cannot find space block");
    }
  }
  NOTSUPPOSEDTOBENULL(blocks);
  subtractspace(blocks[blocknum].numberofcells * blocks[blocknum].sizeofcells);
  addspace(size*number);
  DEBUG3(2,"# allocandusespaceviaptr:block %lu: %lu cells of size %lu\n",
            (Showuint) blocknum,(Showuint) number,(Showuint) size);
  DEBUG2(2,"# previously allocated for this block (%lu,%lu)\n",
            (Showuint) blocks[blocknum].numberofcells,
            (Showuint) blocks[blocknum].sizeofcells);
  blocks[blocknum].numberofcells = number;
  blocks[blocknum].sizeofcells = size;
  blocks[blocknum].fileallocated = file;
  blocks[blocknum].lineallocated = line;
  if(blocks[blocknum].spaceptr == NULL)
  {
    numberofblocks++;
  }
  if((blocks[blocknum].spaceptr 
      = realloc(blocks[blocknum].spaceptr,(size_t) (size*number))) == NULL)
  {
    ALLOCVIAFATAL("not enough memory");
  }
  DEBUG0(2,"# allocandusespaceviaptr Okay\n");
  NOTSUPPOSEDTOBENULL(blocks[blocknum].spaceptr);
  return blocks[blocknum].spaceptr;
}