Exemplo n.º 1
0
// if the point (x,y) is near a line, divides the line with it
Tvertex *insertvertex(coord3d x,coord3d y)
{
  Tline *l;
  Tsector *s;
  if (!findline(&l,&s,x,y)) return NULL;
  int v=addvertex(x,y);
  refvertex(v);
  Twall *w;
  for (w=*l->walls;w;w=w->next) {
    if (is_hole(w)) {
      Tsector *s=((Thole *)w)->sector;
      Tline *l1;
      for (l1=s->lines;l1;l1=l1->next)
        if (l1->v1==l->v2 && l1->v2==l->v1) {
          splitline(l1,v);
          refvertex(v);
          refvertex(v);
          s->linesnum++;
        }
    }
  }
  splitline(l,v);
  s->linesnum++;
  return verts+v;
}
Exemplo n.º 2
0
int main(int ac,char *av[])
{
    char	*cmdline, *prompt, **arglist;
    int	result, process(char **);
    void	setup();

    FILE 	*fp;
    prompt = DFL_PROMPT ;
    setup();

    int ii = 1;   //test

    if(ac == 2)
    {
        if(strcmp(av[1],"-v")==0)
        {
            Vopendebug();
        }
        else if((fp = fopen(av[1],"r"))!=NULL)
        {
            while ( (cmdline = next_cmd(prompt, fp)) != NULL ) {
                if ( (arglist = splitline(cmdline)) != NULL  ) {
                    if(arglist[0]==NULL)
                    {
                        fclose(fp);
                        return 0;
                    }
                    //printf("      %d: %s\n",ii++,arglist[0]);
                    result = process(arglist);
                    printf("\n");
                    freelist(arglist);
                    fflush(fp);
                }
                free(cmdline);
            }
            fclose(fp);
            return 0;
        }
        else
        {
            perror("open file");
            exit(1);
        }
    }

    while ( (cmdline = next_cmd(prompt, stdin)) != NULL ) {
        if ( (arglist = splitline(cmdline)) != NULL  ) {
            result = process(arglist);
            freelist(arglist);
        }
        free(cmdline);
    }
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  char *cmdline, **arglist;
  char *prompt;
  char **single_cmds;
  int i, cmd_number;
  int rv;

  prompt = DEL_PROMPT;
  setup();

  exec_cmds = malloc(sizeof(char*) * MAXEXECCMDS);

  while((cmdline = next_command(prompt, stdin)) != NULL)
  {
    single_cmds = split_command(cmdline);

    for (i = 0; single_cmds[i] != '\0'; ++i)
    {
      if ((arglist = splitline(single_cmds[i])) != NULL)
      {
        // for those arglist executed later, we don't free it.
        // we free later arglists in do_control_command's fi.
        if ((rv = process(arglist)) != -1)
          freelist(arglist);
      }
    }

    freelist(single_cmds);
    free(cmdline);
  }

  free(exec_cmds);
  return 0;
}
Exemplo n.º 4
0
std::string parse_states(Checkpoint & chkpt, const std::string & stateset) {
  // Get specification of states
  std::vector<std::string> states=splitline(tolower(stateset));

  // No states specified
  if(states.size()==0)
    return stateset;

  // Is the calculation restricted?
  bool restr;
  chkpt.read("Restricted",restr);

  // Sanity check
  if((states.size()==1 && !restr) || (states.size()==2 && restr) || states.size()>2)
    throw std::runtime_error("CasidaStates input not consistent with type of wavefunction!\n");

  // Parse input
  std::string state;
  if(restr) {
    std::vector<double> occs;
    chkpt.read("occs",occs);

    parse_states(occs,states[0]);
    state=states[0];
  } else {
    std::vector<double> occa, occb;
    chkpt.read("occa",occa);
    chkpt.read("occb",occb);
    parse_states(occa,states[0]);
    parse_states(occb,states[1]);
    state=states[0] + " " +states[1];
  }

  return state;
}
Exemplo n.º 5
0
bool ConfigManager::setPropertyValue(string propName, string propValue)
{
	bool success = true;

	vector<string> values = splitline(propValue);

	if (propName == "map") {
		_mapPath = const_cast<char*>(values[0].c_str());
	}
	else if (propName == "startLocation") {
		_startX = atoi(values[0].c_str());
		_startY = atoi(values[1].c_str());
		_startYaw = atoi(values[2].c_str());
	}
	else if (propName == "goal") {
		_goalX = atoi(values[0].c_str());
		_goalY = atoi(values[1].c_str());
	}
	else if (propName == "robotSize") {
		_robotSizeX = atoi(values[0].c_str());
		_robotSizeY = atoi(values[0].c_str());
	}
	else if (propName == "MapResolutionCM"){
		_mapResulotionCM = atof(values[0].c_str());
	}
	else if (propName == "GridResolutionCM") {
		_gridResulotionCM = atof(values[0].c_str());
	}
	// no matching title
	else {
		success = false;
	}

	return success;
}
Exemplo n.º 6
0
void looper(){
	int status=1;
	char * cpath;
	char buff[PATH_MAX + 1];
	sigflag=0;
	do {
		//setjmp (env);
		input_redirect_index=0, output_redirect_index=0;
		cpath = getcwd(buff, PATH_MAX+1);
		printf("< %s ", cpath);
		line = readline("SMASH >$ ");
		if (NULL == line){
			exit(EOF);
		}
		add_history(line);
		if (strlen(line)>=1){
			args = splitline(line);
			redirect_flag=check_for_redirect(args);
			pipe_flag=check_for_pipe(args);
			SMASHexec(args);
			//signal(SIGINT, sig_handler);
			free(args);
		}
		//printf("hi!");
		//sleep(1);
		free(line);
	}while (status);

}
Exemplo n.º 7
0
/*
*   processes call tree.
*   runs if command, if successful run commands in then block otherwise 
*   runs commands in else block. 
*   calls itself if command is nested_if block
*   parameters: IFBLOCK* ifBlock - processes tree rooted at ifBlock 
*   returns : 0 if success otherwise 1
*/
static int processTree(IFBLOCK* ifBlock)
{
    int result;//result of processing
    COMMSEQ* node;//for linked list iteration
    IFBLOCK* currIfBlock;//poiner to nested if block
    char* command,**arglist;//for convenience
    
    result = execCommand(ifBlock->commandargs + 1);//result of if commad
    node = (result == 0) ? ifBlock->thenComSeq 
                            : ifBlock->elseComSeq;//which block to execute
    while(node != NULL)
    {
        if(node->type == COMMAND){//executable command
            command = (char*)node->cmd;
            arglist = splitline(command);//get command args
            result = execCommand(arglist);//execute command
        }
        else{//nested_if block
            currIfBlock = (IFBLOCK*)node->cmd;
            result = processTree(currIfBlock);//recursively process nested if
        }
        node = node->next;//go to next node
    }
    return result;
}
Exemplo n.º 8
0
int main() {
  char str[] = "This is a very long line and it must be shrunk! Yes it very well must I say! Yess yes yess!\n";
  puts(str);
  splitline(str, 20);
  puts(str);

  char str2[] = "This is a very loooooooooooooooooooooooooooong line and it must be shrunk! Yes it very well must I say! Yess yes yess!\n";
  puts(str2);
  splitline(str2, 20);
  puts(str2);

  char str3[] = "This is a very loooooooooooooooooooooooooooong line with a newline!\nHow's about them muffins, eh? Whatcha gonna do now?\nHmmmmmm???\n";
  puts(str3);
  splitline(str3, 20);
  puts(str3);
}
int LR::get_feature_num(string sample_filename, vector<int>& label, vec_vec& feature_matrix,int myid,int numprocs)
{
    //cout<<"Calculate feature number......"<<endl;
    ifstream fin(sample_filename.c_str());
    if(!fin)cerr<<"open error get feature number..."<<sample_filename<<endl;
    
    string line, splittag = ":";
    int max_index = 0;
    vector<string> feature_index;
    sparse_feature sf;
    vec key_val;
    int i = 0;
    while(getline(fin,line)){
    //    if(i%10000 == 0)cout<<"for pthreadid: "<<myid<<"\t"<<i<<endl;
        i++;
        key_val.clear();
        feature_index.clear();
        feature_index = splitline(line);
        int y = atoi(feature_index[0].c_str());
        //cout<<y<<endl;
        label.push_back(y);
        for(int i = 1; i < feature_index.size(); i++){  
            int index = 0, beg = 0, end = 0;
            while((end = feature_index[i].find_first_of(":",beg)) != string::npos){
                if(end > beg){
                   string indexstr = feature_index[i].substr(beg,end-beg);
              //      cout<<indexstr<<"??i = "<<i<<endl;
                    index = atoi(indexstr.c_str());
                //    cout<<index<<endl;
                   // if(index == 0){cout<<i<<line<<endl;return 1;}
                    if (index > max_index)
                        max_index = index;
               //    n cout<<index<<" ";
                   sf.id_index = index - 1;
                   
                }
                //beg += 1; //this code must remain,it makes me crazy two days!!!
                beg = end + 1;
            }
            if(beg < feature_index[i].size()){
                string indexend = feature_index[i].substr(beg);
                int value = atoi(indexend.c_str());
                sf.id_val = value;
            }
            key_val.push_back(sf);
            //cout<<"--------------------"<<endl;
	    //if (index > max_index)
              //  max_index = index;
        }
        feature_matrix.push_back(key_val);

    }
    fin.close();
    //int send = 1;
    //for(int tid = 1; tid < numprocs; tid++)
      //  MPI_Send(&send,1,MPI_INTEGER,tid,1,MPI_COMM_WORLD);
    cout<<"maxindex = "<<max_index<<endl;
    return max_index;
}
Exemplo n.º 10
0
void qabot_loaddb() {
  FILE* f;
  char buf[2049];
  char* args[100];
  time_t created;
  flag_t flags;
  
  if (!(f = fopen("data/qab_users", "r")))
    return;
  
  while (!feof(f)) {
    if (fgets(buf, 2048, f)) {
      buf[2048] = '\0';
      if (splitline(buf, args, 50, 0) != 3) {
        fclose(f);
        return;
      }
      
      flags = (flag_t)strtoul(args[1], NULL, 10);
      created = strtoul(args[2], NULL, 10);
      
      qabot_adduser(args[0], flags, created);
    }
  }
  
  fclose(f);
  
  if (!(f = fopen("data/qab_bots", "r")))
    return;
  
  while (!feof(f)) {
    if (fgets(buf, 2048, f)) {
      buf[2048] = '\0';
      if (splitline(buf, args, 50, 0) != 10) {
        fclose(f);
        return;
      }
      
      qabot_addbot(args[0], args[1], args[2], args[3], args[4], args[5], (flag_t)strtol(args[6], NULL, 10), 
        (int)strtol(args[7], NULL, 10), (int)strtol(args[8], NULL, 10), (int)strtol(args[9], NULL, 10), 0);
    }
  }
  
  fclose(f);
}
Exemplo n.º 11
0
/*
*   Creates call tree. 
*   Reads line by line from input, checks the type of line
*   A nested Ifblock has parent COMMSEQ. sets the COMMSEQ
*   as parent of if block. the_if_block points to top level
*   if block.
*   each if block has sequence of then and else commands.
*   the sequence is represented as linked list. The elements
*   of sequence can be a regular command or nested_if.   
*   creates a command sequence node when a then/else command
*   is encountered. if command is nested if block calls itself
*   to build tree for nested if block and passes the command sequence
*   node as parent. keeps poiter to current node in order to set
*   its next element.
*   parameters: FILE* fp - input file
*               IFBLOCK* ifBlock - current if block
*               COMMSEQ* parent - parent of ifblock
*   returns : 0 if success otherwise 1
*/
static int buildTree(FILE* fp,IFBLOCK* ifBlock,COMMSEQ* parent)
{
    enum ControlType type;//control type
    enum ControlState state = WANT_THEN;//control staes
    COMMSEQ **currSeq,*tempSeq;//current node and a temp node
    IFBLOCK* newIfBlock;//for programming convenience
    char **arglist,*cmdline;
    int ret = 0;
    const char* getPrompt();
    
    if( parent != NULL){
        parent->cmd = (void*)ifBlock;
    }
    while((cmdline = next_cmd(getPrompt(), fp)) != NULL){//get next line
        cmdline = varSubstitute(cmdline); //variable substituion
        arglist = splitline(cmdline);
        if(arglist[0] != NULL){
            type = getCtrlType(arglist[0]);
            if(type == T_IF){//nested if
                tempSeq = getNewComSeq(NESTED_IF);//create new comm seq node
                newIfBlock = getNewIfBlock(arglist);//create new if block
                *currSeq = tempSeq;//update currseq
                currSeq = &tempSeq->next;
                ret = buildTree(fp,newIfBlock,tempSeq);//build tree recursively
            }
            else if(type == T_THEN){//Then block
                if(state != WANT_THEN)
                    return errorMsg("unexpected then");//something wrong
                state = WANT_ELSE_FI;
                currSeq = &(ifBlock->thenComSeq);//update currseq to then seq
            } 
            else if(type == T_ELSE){//else
                if(state != WANT_ELSE_FI)
                    return errorMsg("unexpected else");//something wrong
                state = WANT_FI;
                currSeq = &(ifBlock->elseComSeq);//update currseq to then seq
            } 
            else if(type == T_FI){//fi
                if(state != WANT_FI && state != WANT_ELSE_FI)
                    return errorMsg("unexpected fi");//something wrong
                return ret;//return when fi is encountered
            }
            else{//then/else regular commands
                tempSeq = getNewComSeq(COMMAND);//new comm seq node
                tempSeq->cmd = (void*)cmdline;
                *currSeq = tempSeq;
                currSeq = &tempSeq->next;//update currseq
            }
        }
    }//something wrong EOF is encountered, expected:fi
    return ( (cmdline == NULL) ? errorMsg("unexpected") : ret );    
}
Exemplo n.º 12
0
/**
 * Update a value structure with current statistics.
 *
 * If the values cannot be updated the value structure will be zeroed out.
 *
 * @param memutil *val
 *     A pointer to the structure to update.
 * @return void
 */
void getval(memutil *val) {
	FILE *fp = NULL;
	static char *line = NULL;
	size_t n = 0;
	nameval pair;
	size_t status = 0;
	unsigned long total = 0;

	/* Allocate a line buffer. */
	if (! line) {
		debug_print("%s\n", "Allocating");
		line = malloc(1024);
		if (line) {
			n = 1024;
		}
	}

	/* Zero the values. */
	memset((void *)val, 0, sizeof(memutil));

	/* Open the file and parse the results. */
	fp = fopen("/proc/meminfo", "r");
	if (fp) {
		time(&val->time);
		while (status >= 0) {
			status = getline(&line, &n, fp);
			if (status == -1) {
				break;
			}
			splitline(line, &pair);
			if (strcmp(pair.name, "Cached") == 0) {
				val->cached = pair.value;
			}
			else if (strcmp(pair.name, "Buffers") == 0) {
				val->buffered = pair.value;
			}
			else if (strcmp(pair.name, "MemFree") == 0) {
				val->free = pair.value;
			}
			else if (strcmp(pair.name, "MemTotal") == 0) {
				total = pair.value;
			}
		}
		val->used = total - val->free;
		fclose(fp);
	}
	else {
		fprintf(stderr, "# Couldn't open %s\n", "/proc/meminfo");
	}
}
Exemplo n.º 13
0
void LR::predict(string trainfile, vector<float>& theta)
{
	cout<<"predic start-----------------------------------"<<endl;
	ifstream fin(trainfile.c_str());
	string train_line;
	vector<float> predict_result;
	vector<string> predict_feature;
	float x;
	vector<int> preindex;
	vector<float> preval;
	while(getline(fin, train_line))
	{
		x = 0.0;
		predict_feature.clear();
		predict_feature = splitline(train_line);
		preindex.clear();
		preval.clear();
		for(size_t j = 0; j < predict_feature.size(); j++)
		{
			int beg = 0, end = 0;
			while((end = predict_feature[j].find_first_of(":",beg)) != string::npos)
			{
				if(end > beg)
				{
					string string_sub = predict_feature[j].substr(beg, end - beg);
					int k = atoi(string_sub.c_str());
                    preindex.push_back(k-1);
                }
                beg += 1;
            }
                string string_end = predict_feature[j].substr(beg);
                int t = atoi(string_end.c_str());
                preval.push_back(t);
             
            //x += theta[k-1];
        }
        for(size_t j = 0; j < preindex.size(); j++)
        {
            //cout<<preindex[j]<<":"<<preval[j]<<endl;
            x += theta[preindex[j]]*preval[j];
        }
        float y = sigmoid(x);
        predict_result.push_back(y);
    }
    for(size_t j = 0; j < predict_result.size(); j++)
    {
        cout<<"predict result:"<<endl;
        cout<<predict_result[j]<<endl;
    }
}
Exemplo n.º 14
0
int main(){
    char *cmdline, *prompt, **arglist;
    int result;
    void setup();
    prompt = DFL_PROMPT;
    setup();
    while((cmdline = next_cmd(prompt, stdin)) != NULL){
        if((arglist = splitline(cmdline)) != NULL){
            result = execute(arglist);
            freelist(arglist);
        }
        free(cmdline);
    }
    return 0;
}
Exemplo n.º 15
0
static void handlemaskprivmsg(int hooknum, void *args) {
  void **hargs = (void **)args;
  nick *source = hargs[0];
  char *message = hargs[2];
  Command *cmd;
  int cargc;
  char *cargv[50];
  server *s;

  if(!source)
    return;

  if(!IsOper(source) || !IsService(source))
    return;

  cargc = splitline(message, cargv, 50, 0);
  if(cargc < 2)
    return;

  if(strcmp(cargv[0], "XSB1"))
    return;

  s = &serverlist[homeserver(source->numeric)];
  if(s->linkstate != LS_LINKED) {
    Error("xsb", ERR_WARNING, "Got XSB message from unlinked server (%s): %s", s->name->content, source->nick);
    return;
  }

#ifndef XSB_DEBUG
  if(!(s->flags & SMODE_SERVICE)) {
    Error("xsb", ERR_WARNING, "Got XSB message from non-service server (%s): %s", s->name->content, source->nick);
    return;
  }
#endif

  cmd = findcommandintree(cmds, cargv[1], 1);
  if(!cmd)
    return;

  if(cmd->maxparams < (cargc - 2)) {
    rejoinline(cargv[cmd->maxparams], cargc - (cmd->maxparams));
    cargc = (cmd->maxparams) + 2;
  }

  (cmd->handler)(source, cargc - 2, &cargv[2]);
}
Exemplo n.º 16
0
int main()
{
	char *cmdline, *prompt, **arglist, **cmdlist;
	char rfileName[32];
	int result, fd_out, i, fno, cmdNum, rioFlag;
	int sfd = dup(STDOUT_FILENO);
	void setup();

	prompt = DFL_PROMPT;
	setup();

	cmdlist = emalloc(BUFSIZ);
	while ((cmdline = next_cmd(prompt, stdin)) != NULL)
	{
		/* io redirection */
		rioFlag = getRFileName(cmdline, rfileName);
		if (rioFlag > 0)
			fd_out = r_open(rfileName);
		
		/* pipe test*/
		cmdNum = pipeTest(cmdline, cmdlist);
		if (cmdNum == 1)
		{
			if ((arglist = splitline(cmdline)) != NULL)
			{
				if (buildIn(arglist))
				{
					;
				} else {
					result = execute(arglist);
					freelist(arglist);
				}
			}
		} 
		else if (cmdNum == 2) 
		{
			pipeCommand(cmdlist);
		}
		//freelist(cmdlist);
		free(cmdline);
		if (rioFlag > 0)
			r_close(sfd);
	}
	return 0;
}
Exemplo n.º 17
0
static Line *
commentblock(Paragraph *p, int *unclosed)
{
    Line *t, *ret;
    char *end;

    for ( t = p->text; t ; t = t->next) {
	if ( end = strstr(T(t->text), "-->") ) {
	    splitline(t, 3 + (end - T(t->text)) );
	    ret = t->next;
	    t->next = 0;
	    return ret;
	}
    }
    *unclosed = 1;
    return t;

}
Exemplo n.º 18
0
static char *arg_fillbuf(){
	char *p,*nlp;;

	if(ListEmpty(flist)){
		if(++a_apos>a_argc)return(0);
		p=a_argv[a_apos];
	}else{
		struct fentry *f=(struct fentry *)ListHead(flist);
		if(!f->ptr){
			do{
				if(!fgets(f->buf,ARGLEN,f->fp)){
					if(ferror(f->fp)){
						fprintf(stderr,
							"I/O error on @file\n");
						return(0);
					}
					fclose(f->fp);
					RemHead(&flist);
					free(f);
					return(arg_fillbuf());
				}
			}while(f->buf[0]=='#');	/* comment */
			if(nlp=strchr(f->buf,'\n'))*nlp='\0';
		}
		p=splitline(f);
		if(p== (char *)-1)return(0);		/* error */
		if(!p)return(arg_fillbuf());	/* skip blank line */
	}
	if(p && *p=='@'){
		struct fentry *f=calloc(sizeof(struct fentry),1);
		f->fp=fopen(++p,"r");
		if(!(f->fp)){
			fprintf(stderr,"Can't open @file '%s'\n",p);
			free(f);
			return(0);
		}
		AddHead(&flist,(struct Node *)f);
		return(arg_fillbuf());
	}
	return(p);
}
Exemplo n.º 19
0
static Line *
htmlblock(Paragraph *p, struct kw *tag, int *unclosed)
{
    Line *ret;
    FLO f = { p->text, 0 };
    int c;
    int i, closing, depth=0;

    *unclosed = 0;
    
    if ( tag == &comment )
	return commentblock(p, unclosed);
    
    if ( tag->selfclose ) {
	ret = f.t->next;
	f.t->next = 0;
	return ret;
    }

    while ( (c = flogetc(&f)) != EOF ) {
	if ( c == '<' ) {
	    /* tag? */
	    c = flogetc(&f);
	    if ( c == '!' ) { /* comment? */
		if ( flogetc(&f) == '-' && flogetc(&f) == '-' ) {
		    /* yes */
		    while ( (c = flogetc(&f)) != EOF ) {
			if ( c == '-' && flogetc(&f) == '-'
				      && flogetc(&f) == '>')
			      /* consumed whole comment */
			      break;
		    }
		}
	    }
	    else { 
		if ( closing = (c == '/') ) c = flogetc(&f);

		for ( i=0; i < tag->size; c=flogetc(&f) ) {
		    if ( tag->id[i++] != toupper(c) )
			break;
		}

		if ( (i == tag->size) && !isalnum(c) ) {
		    depth = depth + (closing ? -1 : 1);
		    if ( depth == 0 ) {
			while ( c != EOF && c != '>' ) {
			    /* consume trailing gunk in close tag */
			    c = flogetc(&f);
			}
			if ( c == EOF )
			    break;
			if ( !f.t )
			    return 0;
			splitline(f.t, floindex(f));
			ret = f.t->next;
			f.t->next = 0;
			return ret;
		    }
		}
	    }
	}
    }
    *unclosed = 1;
    return 0;
}
Exemplo n.º 20
0
entry_t *readstate(void)
/* Read one entry from the state file. */
{
	static entry_t entry;
	static pathname_t path;
	static size_t *trunc;
	static size_t trunc_len;
	static base_indent;
	char *line;
	char **argv;
	size_t argc;
	static off_t lineno;
	int indent, depth;

recurse:
	keep= KEEP_STATE;

	if (feof(statefp) || (line= read1line(statefp)) == nil) {
		checkstate();
		return nil;
	}
	lineno++;

	/* How far is this entry indented? */
	indent= 0;
	while (*line != 0) {
		if (*line == ' ') indent++;
		else
		if (*line == '\t') indent= (indent + 8) & ~7;
		else
			break;
		line++;
	}
	if (indent > 0 && base_indent == 0) base_indent= indent;
	depth= (base_indent == 0 ? 0 : indent / base_indent) + 1;

	if (entry.ignore && depth > entry.depth) {
		/* If the old directory is ignored, then so are its entries. */
		goto recurse;
	}
	entry.depth= depth;

	splitline(line, &argv, &argc);
	if (argc < 2) state_syntax(lineno);

	if (trunc == nil) {
		/* The root of the tree, initialize path. */
		if (argv[0][0] != '/') state_syntax(lineno);
		path_init(&path);
		path_add(&path, "/");
		trunc= allocate(nil, (trunc_len= 16) * sizeof(trunc[0]));

		/* The root has depth 0. */
		entry.depth= 0;
		trunc[0]= 0;
	} else {
		if (entry.depth > trunc_len) {
			trunc= allocate(trunc,
					(trunc_len*= 2) * sizeof(trunc[0]));
		}
		path_trunc(&path, trunc[entry.depth - 1]);
		path_add(&path, argv[0]);
		trunc[entry.depth]= path_length(&path);
	}

	entry.path= path_name(&path);
	entry.name= argv[0];
	entry.link= nil;
	if ((entry.ignore= strcmp(argv[1], "ignore") == 0)) {
		return &entry;
	}
	if (!getattributes(&entry, argc - 1, argv + 1)) state_syntax(lineno);
	return &entry;
}
Exemplo n.º 21
0
/*!
\todo The new splitline function doesn't works with old global vars, so all this
is to be changed
*/
void Command(NXWSOCKET  s, char* speech) // Client entred a command like 'ADD
{
	unsigned char *comm;
	unsigned char nonuni[512];
	//cCallCommand* command; 

	//cmd_offset = 1;

	//cCallCommandMap* callcommands = new cCallCommandMap()
	
	
	pChar pc_currchar =  cSerializable::findCharBySerial(currchar[s]);
	if ( ! pc_currchar )
		return;

	strcpy((char*)nonuni, speech);
	strcpy((char*)tbuffer, (char*)nonuni);

	strupr((char*)nonuni);
	cline = (char*)&nonuni[0];
	
	stringVector tokens = splitline(nonuni);

	if ( tokens.size() < 1 )
		return;
	// Let's ignore the command prefix;
	comm = nonuni + 1;

	pCommand p_cmd= commands->findCommand((char*)comm);
	
	
	NXWCLIENT client= getClientFromSocket(s);

	if(p_cmd==NULL) {
		return;
	}
	
	
	//Control between cCommand privilege and cChar privilege.

	if(p_cmd->getCommandLevel(p_cmd)==pc_currchar->commandLevel){
	client->sysmsg("You can't use this command!");
		return;
	}

	
	cCallCommand* called= new cCallCommand(speech);


	uint32_t cmd_serial=called->addCallCommand(called);

	
	
	// Frodo:
	// NOW CALL AMX FUNCTION specified in cCommand.cmd_callback giving pc_currchar and 
	// cmd_serial
	
	
	
	//Let's delete the temp object		
			
	called->delCommand(cmd_serial);
	

}
Exemplo n.º 22
0
/* extensively modified 8/2/99 [email protected] -
 * see cmdtable.cpp for more details */
void cCommands::Command(UOXSOCKET s, string speech) // Client entred a '/' command like /ADD
{
	int i=9;
	unsigned char *comm;
	unsigned char nonuni[512];
	int y,loopexit=0;

	P_CHAR pc_currchar = MAKE_CHARREF_LR(currchar[s]);

	if (pc_currchar->unicode)
		cCommands::cmd_offset = 1;
	else
		cCommands::cmd_offset = 1;

	cCommands::command_line = speech;
	cCommands::params = cCommands::command_line.split(" ");
	strcpy((char*)nonuni, speech.c_str());
	strcpy((char*)tbuffer, (char*)nonuni);

	strupr((char*)nonuni);
	cline = (char*) &nonuni[0];
	splitline();
	if (tnum<1)
		return;
	// Let's ignore the command prefix;
	comm = &nonuni[1];

	i=0; y=-1;loopexit=0;
	while((command_table[i].cmd_name)&&(y==-1) && (++loopexit < MAXLOOPS)) {
		if(!(strcmp((char*)command_table[i].cmd_name, (char*)comm))) y=i;
		i++;
	}

	if(y==-1) {
		sysmessage(s, "Unrecognized command.");
		return;
	} else {
		if((pc_currchar->isTrueGM() && !pc_currchar->isGM()) ||		// a restricted GM outside his region(s)
			(pc_currchar->account!=0)&&(command_table[y].cmd_priv_m!=255)&&
			(!(pc_currchar->priv3[command_table[y].cmd_priv_m]&
			(0-0xFFFFFFFF<<command_table[y].cmd_priv_b))))
		{
			sysmessage(s, "Access denied.");
			return;
		}

		switch(command_table[y].cmd_type) {
		case CMD_FUNC:
			(*((CMD_EXEC)command_table[y].cmd_extra)) (s);
			break;
		case CMD_ITEMMENU:
			itemmenu(s, (int)command_table[y].cmd_extra);
			break;
		case CMD_TARGET:
			_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			break;
		case CMD_TARGETX:
			if(tnum==2) {
				addx[s]=makenumber(1);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes one number as an argument.");
			}
			break;
		case CMD_TARGETXY:
			if(tnum==3) {
				addx[s]=makenumber(1);
				addy[s]=makenumber(2);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes two numbers as arguments.");
			}
			break;
		case CMD_TARGETXYZ:
			if(tnum==4) {
				addx[s]=makenumber(1);
				addy[s]=makenumber(2);
				addz[s]=makenumber(3);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes three numbers as arguments.");
			}
			break;
		case CMD_TARGETHX:
			if(tnum==2) {
				addx[s]=hexnumber(1);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes one hex number as an argument.");
			}
			break;
		case CMD_TARGETHXY:
			if(tnum==3) {
				addx[s]=hexnumber(1);
				addy[s]=hexnumber(2);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes two hex numbers as arguments.");
			}
			break;
		case CMD_TARGETHXYZ:
			if(tnum==4) {
				addx[s]=hexnumber(1);
				addy[s]=hexnumber(2);
				addz[s]=hexnumber(3);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes three hex numbers as arguments.");
			}
			break;
		case CMD_TARGETID1:
			if(tnum==2) {
				addid1[s]=makenumber(1);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes one number as an argument.");
			}
			break;
		case CMD_TARGETID2:
			if(tnum==3) {
				addid1[s] = static_cast<unsigned char>(makenumber(1));
				addid2[s] = static_cast<unsigned char>(makenumber(2));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes two numbers as arguments.");
			}
			break;
		case CMD_TARGETID3:
			if(tnum==4) {
				addid1[s] = static_cast<unsigned char>(makenumber(1));
				addid2[s] = static_cast<unsigned char>(makenumber(2));
				addid3[s] = static_cast<unsigned char>(makenumber(3));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes three numbers as arguments.");
			}
			break;
		case CMD_TARGETID4:
			if(tnum==5) {
				addid1[s] = static_cast<unsigned char>(makenumber(1));
				addid2[s] = static_cast<unsigned char>(makenumber(2));
				addid3[s] = static_cast<unsigned char>(makenumber(3));
				addid4[s] = static_cast<unsigned char>(makenumber(4));
				//clConsole.send("1: %i 2: %i 3: %i 4: %i\n",addid1[s],addid2[s],addid2[s],addid3[s],addid4[s]);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes four numbers as arguments.");
			}
			break;
		case CMD_TARGETHID1:
			if(tnum==2) {
				addid1[s] = static_cast<unsigned char>(hexnumber(1));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes one hex number as an argument.");
			}
			break;
		case CMD_TARGETHID2:
			if(tnum==3) {
				addid1[s] = static_cast<unsigned char>(hexnumber(1));
				addid2[s] = static_cast<unsigned char>(hexnumber(2));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes two hex numbers as arguments.");
			}
			break;
		case CMD_TARGETHID3:
			if(tnum==4) {
				addid1[s] = static_cast<unsigned char>(hexnumber(1));
				addid2[s] = static_cast<unsigned char>(hexnumber(2));
				addid3[s] = static_cast<unsigned char>(hexnumber(3));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes three hex numbers as arguments.");
			}
			break;
		case CMD_TARGETHID4:
			if(tnum==5) {
				addid1[s] = static_cast<unsigned char>(hexnumber(1));
				addid2[s] = static_cast<unsigned char>(hexnumber(2));
				addid3[s] = static_cast<unsigned char>(hexnumber(3));
				addid4[s] = static_cast<unsigned char>(hexnumber(4));
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes four hex numbers as arguments.");
			}
			break;
		case CMD_TARGETTMP:
			if(tnum==2) {
				tempint[s]=makenumber(1);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes a number as an argument.");
			}
			break;
		case CMD_TARGETHTMP:
			if(tnum==2) {
				tempint[s]=hexnumber(1);
				_do_target(s, (TARGET_S *)command_table[y].cmd_extra);
			} else {
				sysmessage(s, "This command takes a hex number as an argument.");
			}
			break;
		default:
			sysmessage(s, "BUG: Command has a bad command type set!");
			break;
		}
		return;
	}

	sysmessage(s, "BUG: Should never reach end of command() function!");
}
Exemplo n.º 23
0
int main(int argc, char **argv) {

#ifdef _OPENMP
  printf("ERKALE - EMD from Hel, OpenMP version, running on %i cores.\n",omp_get_max_threads());
#else
  printf("ERKALE - EMD from Hel, serial version.\n");
#endif
  print_copyright();
  print_license();
#ifdef SVNRELEASE
  printf("At svn revision %s.\n\n",SVNREVISION);
#endif
  print_hostname();

  if(argc!=1 && argc!=2) {
    printf("Usage: $ %s (runfile)\n",argv[0]);
    return 0;
  }

  Timer t;

  // Parse settings
  Settings set;
  set.add_string("LoadChk","Checkpoint file to load density from","erkale.chk");
  set.add_bool("DoEMD", "Perform calculation of isotropic EMD (moments of EMD, Compton profile)", true);
  set.add_double("EMDTol", "Tolerance for the numerical integration of the radial EMD",1e-8);
  set.add_string("EMDlm", "Which projection of the radial EMD to compute","");
  set.add_bool("EMDAdapt", "Use adaptive grid to compute EMD?", true);
  set.add_string("EMDCube", "Calculate EMD on a cube? e.g. -10:.3:10 -5:.2:4 -2:.1:3", "");
  set.add_string("EMDOrbitals", "Compute EMD of given orbitals, e.g. 1,2,4:6","");
  set.add_string("Similarity", "Compute similarity measure to checkpoint","");
  set.add_string("SimilarityGrid", "Grid to use for computing similarity integrals","500 77");
  set.add_bool("SimilarityLM", "Seminumerical computation of similarity integrals?", false);
  set.add_int("SimilarityLmax", "Maximum angular momentum for seminumerical computation", 6);

  if(argc==2)
    set.parse(argv[1]);
  else
    printf("Using default settings.\n");
  set.print();

  // Get the tolerance
  double tol=set.get_double("EMDTol");

  // Load checkpoint
  Checkpoint chkpt(set.get_string("LoadChk"),false);

  // Load basis set
  BasisSet basis;
  chkpt.read(basis);

  // Load density matrix
  arma::cx_mat P;
  arma::mat Pr, Pi;
  chkpt.read("P",Pr);
  if(chkpt.exist("P_im")) {
    chkpt.read("P_im",Pi);
    P=Pr*COMPLEX1 + Pi*COMPLEXI;
  } else
    P=Pr*COMPLEX1;
  
  // The projection to calculate
  int l=0, m=0;
  std::string lmstr=set.get_string("EMDlm");
  if(lmstr.size()) {
    // Get l and m values
    std::vector<std::string> lmval=splitline(lmstr);
    if(lmval.size()!=2)
      throw std::runtime_error("Invalid specification of l and m values.\n");
    l=readint(lmval[0]);
    m=readint(lmval[1]);
  }
  bool adaptive=set.get_bool("EMDAdapt");

  // Compute orbital EMDs?
  if(set.get_string("EMDOrbitals")!="") {
    // Get orbitals
    std::vector<std::string> orbs=splitline(set.get_string("EMDOrbitals"));

    // Polarized calculation?
    bool restr;
    chkpt.read("Restricted",restr);
    if(restr!= (orbs.size()==1))
      throw std::runtime_error("Invalid occupancies for spin alpha and beta!\n");

    if(l!=0)
      printf("\nComputing the (%i %+i) projection of the orbital EMD.\n",l,m);

    for(size_t ispin=0;ispin<orbs.size();ispin++) {
      // Indices of orbitals to include.
      std::vector<size_t> idx=parse_range(orbs[ispin]);
      // Change into C++ indexing
      for(size_t i=0;i<idx.size();i++)
	idx[i]--;

      // Read orbitals
      arma::mat C;
      if(restr)
	chkpt.read("C",C);
      else {
	if(ispin==0)
	  chkpt.read("Ca",C);
	else
	  chkpt.read("Cb",C);
      }

      for(size_t i=0;i<idx.size();i++) {
	// Names of output files
	char emdname[80];
	char momname[80];
	char Jname[80];
	char Jintname[80];

	char suffix[80];
	if(l==0)
	  sprintf(suffix,".txt");
	else
	  sprintf(suffix,"_%i_%i.txt",l,m);

	if(restr) {
	  sprintf(emdname,"emd-%i%s",(int) idx[i]+1,suffix);
	  sprintf(momname,"moments-%i%s",(int) idx[i]+1,suffix);
	  sprintf(Jname,"compton-%i%s",(int) idx[i]+1,suffix);
	  sprintf(Jintname,"compton-interp-%i%s",(int) idx[i]+1,suffix);
	} else {
	  if(ispin==0) {
	    sprintf(emdname,"emd-a-%i%s",(int) idx[i]+1,suffix);
	    sprintf(momname,"moments-a-%i%s",(int) idx[i]+1,suffix);
	    sprintf(Jname,"compton-a-%i%s",(int) idx[i]+1,suffix);
	    sprintf(Jintname,"compton-interp-a-%i%s",(int) idx[i]+1,suffix);
	  } else {
	    sprintf(emdname,"emd-b-%i%s",(int) idx[i]+1,suffix);
	    sprintf(momname,"moments-b-%i%s",(int) idx[i]+1,suffix);
	    sprintf(Jname,"compton-b-%i%s",(int) idx[i]+1,suffix);
	    sprintf(Jintname,"compton-interp-b-%i%s",(int) idx[i]+1,suffix);
	  }
	}

	// Generate dummy density matrix
	arma::cx_mat Pdum=C.col(idx[i])*arma::trans(C.col(idx[i]))*COMPLEX1;

	Timer temd;

	GaussianEMDEvaluator *poseval=new GaussianEMDEvaluator(basis,Pdum,l,std::abs(m));
	GaussianEMDEvaluator *negeval;
	if(m!=0)
	  negeval=new GaussianEMDEvaluator(basis,Pdum,l,-std::abs(m));
	else
	  negeval=NULL;

	EMD emd(poseval, negeval, 1, l, m);
	if(adaptive) {
	  emd.initial_fill();
	  if(l==0 && m==0) emd.find_electrons();
	  emd.optimize_moments(true,tol);
	} else
	  emd.fixed_fill();

	emd.save(emdname);
	emd.moments(momname);
	if(l==0 && m==0) {
	  emd.compton_profile(Jname);
	  emd.compton_profile_interp(Jintname);
	}

	delete poseval;
	if(m!=0) delete negeval;
      }
    }
  }

  if(set.get_bool("DoEMD")) {
    t.print_time();

    printf("\nCalculating EMD properties.\n");
    printf("Please read and cite the reference:\n%s\n%s\n%s\n",	\
	   "J. Lehtola, M. Hakala, J. Vaara and K. Hämäläinen",		\
	   "Calculation of isotropic Compton profiles with Gaussian basis sets", \
	   "Phys. Chem. Chem. Phys. 13 (2011), pp. 5630 - 5641.");

    if(l!=0)
      printf("\nComputing the (%i %+i) projection of the EMD.\n",l,m);
    else
      printf("\nComputing the isotropic projection of the EMD.\n");

    // Amount of electrons is
    int Nel;
    chkpt.read("Nel",Nel);

    // Construct EMD evaluators
    Timer temd;
    GaussianEMDEvaluator *poseval=new GaussianEMDEvaluator(basis,P,l,std::abs(m));
    GaussianEMDEvaluator *negeval;
    if(m!=0)
      negeval=new GaussianEMDEvaluator(basis,P,l,-std::abs(m));
    else
      negeval=NULL;

    temd.set();
    EMD emd(poseval, negeval, Nel, l, m);
    if(adaptive) {
      emd.initial_fill();
      if(l==0 && m==0) emd.find_electrons();
      emd.optimize_moments(true,tol);
    } else
      emd.fixed_fill();

    if(l==0 && m==0) {
      emd.save("emd.txt");
      emd.moments("moments.txt");
      emd.compton_profile("compton.txt");
      emd.compton_profile_interp("compton-interp.txt");
    } else {
      char fname[80];
      sprintf(fname,"emd_%i_%i.txt",l,m);
      emd.save(fname);

      sprintf(fname,"moments_%i_%i.txt",l,m);
      emd.moments(fname);
    }

    if(l==0 && m==0)
      printf("Calculating isotropic EMD properties took %s.\n",temd.elapsed().c_str());
    else
      printf("Calculating projected EMD properties took %s.\n",temd.elapsed().c_str());

    delete poseval;
    if(m!=0) delete negeval;
  }

  // Do EMD on a cube?
  if(stricmp(set.get_string("EMDCube"),"")!=0) {
    t.print_time();
    Timer temd;

    // Form grid in p space.
    std::vector<double> px, py, pz;
    parse_cube(set.get_string("EMDCube"),px,py,pz);

    // Calculate EMD on cube
    emd_cube(basis,P,px,py,pz);

    printf("Calculating EMD on a cube took %s.\n",temd.elapsed().c_str());
  }

  // Compute similarity?
  if(stricmp(set.get_string("Similarity"),"")!=0) {

    // Load checkpoint
    Checkpoint simchk(set.get_string("Similarity"),false);

    // Get grid size
    std::vector<std::string> gridsize=splitline(set.get_string("SimilarityGrid"));
    if(gridsize.size()!=2) {
      throw std::runtime_error("Invalid grid size!\n");
    }
    int nrad=readint(gridsize[0]);
    int lmax=readint(gridsize[1]);
    int radlmax=set.get_int("SimilarityLmax");

    // Load basis set
    BasisSet simbas;
    simchk.read(simbas);

    // Load density matrix
    arma::mat simPr, simPi;
    arma::cx_mat simP;
    simchk.read("P",simPr);
    if(simchk.exist("P_im")) {
      simchk.read("P_im",simPi);
      simP=simPr*COMPLEX1 + simPi*COMPLEXI;
    } else
      simP=simPr*COMPLEX1;
    
    // Compute momentum density overlap
    arma::cube ovl;
    if(set.get_bool("SimilarityLM"))
      ovl=emd_overlap_semi(basis,P,simbas,simP,nrad,radlmax);
    else
      ovl=emd_overlap(basis,P,simbas,simP,nrad,lmax);

    // Amount of electrons
    int Nela, Nelb;
    chkpt.read("Nel", Nela);
    simchk.read("Nel", Nelb);

    // Shape function overlap
    arma::cube sh=emd_similarity(ovl,Nela,Nelb);
    sh.slice(0).save("similarity.dat",arma::raw_ascii);
    sh.slice(1).save("similarity_avg.dat",arma::raw_ascii);

    for(int s=0;s<2;s++) {
      if(s) {
	printf("%2s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\n","k","S0(AA)","S0(BB)","S0(AB)","I0(AA)","I0(BB)","I0(AB)","D0(AB)");
	for(int k=-1;k<3;k++)
	  // Vandenbussche don't include p^2 in the spherical average
	  printf("%2i\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n", k+1, sh(k+1,0,s), sh(k+1,1,s), sh(k+1,2,s), sh(k+1,3,s), sh(k+1,4,s), sh(k+1,5,s), sh(k+1,6,s));
      } else {
	printf("%2s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\t%9s\n","k","S(AA)","S(BB)","S(AB)","I(AA)","I(BB)","I(AB)","D(AB)");
	for(int k=-1;k<3;k++)
	  printf("%2i\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n", k, sh(k+1,0,s), sh(k+1,1,s), sh(k+1,2,s), sh(k+1,3,s), sh(k+1,4,s), sh(k+1,5,s), sh(k+1,6,s));
      }
      printf("\n");
    }
  }

  return 0;
}
Exemplo n.º 24
0
void loadInput(Object *obj)
{
	// load the OBJ file here
	char buffer[MAX_BUFFER_SIZE];
	bool has_normal=false, has_texture = false,has_group = false;  
	string matlFileName;
	
	
	while(cin.getline(buffer, MAX_BUFFER_SIZE)!=0)
	{
		stringstream ss(buffer);
		std::string line = ss.str();
		
		// empty line stream
		if(line.empty()){
			continue; //skip blank lines
			//cout<<"this is empty"<<endl;
		}
		trimline(line);
		std::vector < std::string > values = splitline(line, ' ');
		Vector3f v;
		
		//skipping comments
		if(values[0] == "#"){
			continue;
		}
		
		//mtlib file name
		
		else if(values[0] == "mtllib"){
			matlFileName = values[1];
			readMaterial(matlFileName);
			continue;
		}
		
		//groups / objects
		else if(values[0] == "g"){
			has_group = true;
			obj = new Object;
			
			Model.push_back(obj);
			
			obj->obj_name = values[1];
			
			
		}
		//usemtl 
		
		//Reading Vertices
		
		else if(values[0] == "v"){
			//std::cout << "Reading Vertices :" << '\t' << values[1] << '\t'<< values[2]<< '\t' <<
		//values[3]
		//<< std::endl;
			v[0] = std::atof(values[1].c_str());
			v[1] = std::atof(values[2].c_str());
			v[2] = std::atof(values[3].c_str());
			
			if(v[0]<xmin)
				xmin=v[0];
			if(v[0]>xmax)
				xmax=v[0];

			if(v[1]<ymin)
				ymin=v[1];
			if(v[1]>ymax)
				ymax=v[1];

			if(v[2]<zmin)
				zmin=v[2];
			if(v[2]>zmax)
				zmax=v[2];
			//cout << v[0] << endl;
			vecv.push_back(v);
			
			//cout << obj->vecv[0] << endl;
		}
		
		//Reading texture
		else if(values[0] == "vt"){
			
			has_texture = true;
			if(values.size() == 4){
				v[0] = std::atof(values[1].c_str());
				v[1] = std::atof(values[2].c_str());
				v[2] = std::atof(values[3].c_str());
			}
			else if(values.size() == 3){
				v[0] = std::atof(values[1].c_str());
				v[1] = std::atof(values[2].c_str());
				v[2] = 0;
			}
			else{
				v[0] = std::atof(values[1].c_str());
				v[1] = 0;
				v[2] = 0;
			}
			
			
			vec_tex.push_back(v);
			
		}
		
		//Reading Normals
		else if(values[0] == "vn"){
			has_normal = true;
			if(values.size() == 4){
				v[0] = std::atof(values[1].c_str());
				v[1] = std::atof(values[2].c_str());
				v[2] = std::atof(values[3].c_str());
			//	std::cout << "Reading Vertex Normal :" << '\t'<< values[1] << '\t'<< values[2]<< '\t' <<
		//values[3]
		//<< std::endl;
			}
			// for less than two  need to add
			vecn.push_back(v);
		}
		
		//Reading Faces (f v/vt/vn v/vt/vn v/vt/vn v/vt/vn  a/b/c d/e/f g/h/i)
		else if(values[0] == "f"){
			//for triangles 
			if(!has_group){
				obj = new Object;
				Model.push_back(obj);
				obj->obj_name = "group_default";
				has_group = true;
			}
			vector<unsigned> face;
			//with both texture and normal variables
			if(has_normal == true && has_texture == true){
				vector<string> flds1 = splitline(values[1],'/');
				vector<string> flds2 = splitline(values[2],'/');
				vector<string> flds3 = splitline(values[3],'/');
				face.push_back(atoi(flds1[0].c_str()));face.push_back(atoi(flds1[1].c_str()));face.push_back(atoi(flds1[2].c_str()));
				face.push_back(atoi(flds2[0].c_str()));face.push_back(atoi(flds2[1].c_str()));face.push_back(atoi(flds2[2].c_str()));
				face.push_back(atoi(flds3[0].c_str()));face.push_back(atoi(flds3[1].c_str()));face.push_back(atoi(flds3[2].c_str()));
				
				
				obj->vecf.push_back(face);
				//cout << "1st loop" <<endl;
			}
			else if(has_normal == true && has_texture == false){    //b e and h are absent 
				//cout << "2nd loop" <<endl;
				vector<string> flds1 = splitline(values[1],'/');
				vector<string> flds2 = splitline(values[2],'/');
				vector<string> flds3 = splitline(values[3],'/');
				//cout << flds1.size() << endl;
				face.push_back(atoi(flds1[0].c_str()));face.push_back(0);face.push_back(atoi(flds1[1].c_str()));
				face.push_back(atoi(flds2[0].c_str()));face.push_back(0);face.push_back(atoi(flds2[1].c_str()));
				face.push_back(atoi(flds3[0].c_str()));face.push_back(0);face.push_back(atoi(flds3[1].c_str()));
				obj->vecf.push_back(face);
				
			}
			else if(has_normal == false && has_texture == true){    //c f and i are absent
				
				vector<string> flds1 = splitline(values[1],'/');
				vector<string> flds2 = splitline(values[2],'/');
				vector<string> flds3 = splitline(values[3],'/');
				face.push_back(atoi(flds1[0].c_str()));face.push_back(atoi(flds1[1].c_str()));face.push_back(0);
				face.push_back(atoi(flds2[0].c_str()));face.push_back(atoi(flds2[1].c_str()));face.push_back(0);
				face.push_back(atoi(flds3[0].c_str()));face.push_back(atoi(flds3[1].c_str()));face.push_back(0);
				obj->vecf.push_back(face);
				//cout << "3rd loop" <<endl;
			}
			
			else if(has_normal == false && has_texture == false){
				
				std::size_t found = values[1].find_first_of('/');
				if(found != std::string::npos){
					vector<string> flds1 = splitline(values[1],'/');
					vector<string> flds2 = splitline(values[2],'/');
					vector<string> flds3 = splitline(values[3],'/');
					face.push_back(atoi(flds1[0].c_str()));face.push_back(0);face.push_back(0);
					face.push_back(atoi(flds2[0].c_str()));face.push_back(0);face.push_back(0);
					face.push_back(atoi(flds3[0].c_str()));face.push_back(0);face.push_back(0);
					obj->vecf.push_back(face);
				}
				else{
					//cout << values[1] << '\t' << values[2] << '\t' << values[3] << endl;
					
					face.push_back(atoi(values[1].c_str()));face.push_back(atoi("0"));face.push_back(atoi("0"));
					face.push_back(atoi(values[2].c_str()));face.push_back(atoi("0"));face.push_back(atoi("0"));
					face.push_back(atoi(values[3].c_str()));face.push_back(atoi("0"));face.push_back(atoi("0"));
					obj->vecf.push_back(face);
				}
				
			}
			
			
			
			
		} //face loop ends
		
		
		
		
		
		

	}
	for(unsigned int i=0; i< Model.size(); i++){
		if(Model[i]->vecf.size() == 0)
			Model.erase(Model.begin()+i);
	}
	
		
	
	cout<<vecv.size()<<"\t"<<vecn.size() <<"\t"  << vec_tex.size()<<endl;
	cout <<"Model Size \t" << Model.size() << endl;
	//cout << "Model Name \t" << Model[0]->obj_name << endl;
	//cout << "Face Index \t" << Model[0]->vecf[0][3] << Model[0]->vecf[0][4] << Model[0]->vecf[0][5]  << endl;
	cout << "Vecf size\t" << Model[0]->vecf.size() << endl;
}
Exemplo n.º 25
0
Arquivo: fonts.c Projeto: Lopo/Lotos
void figlet(UR_OBJECT user, char *inpstr, int typ)
{
	UR_OBJECT u=NULL;
	RM_OBJECT rm=NULL;
	long c;
	int i=0, row, wordbreakmode, char_not_added;
	char *p=inpstr, *name;
	fcharnode *fclsave;
	char fontname[256]="standard";

	set_crash();
	if (user->muzzled) {
		write_user(user, "Si muzzled, nemozes bannerovat\n");
		return;
		}
	if (word_count<2) {
		write_user(user,"Pozri si najprv help ...\n");
		return;
		}
	if (!strcmp(inpstr, "/l")) {
		show_file(user, FONTLIST);
		return;
		}
	if (typ==0) rm=user->room;
	if (typ==1) {
		if (word_count<3) {
			write_usage(user, "tbanner /<user> [-<font>] text");
			return;
			}
		/* Check to see if a username is specified */
		i=0;
		if (*p=='/') {
			/* Get size of font name */
			while (*(p+i)!=' ') {
				i++;
				if (i==100) break;
				}
			strncpy(text, p+1, i);
			*(text+i-1)='\0';
			name=text;
			p=p+i+1;
			}
		else {
			write_usage(user, "tbanner /<user> [-<font>] text");
			return;
			}
		if ((u=get_user_name(user, name))==NULL) {
			write_user(user, notloggedon);
			return;
			}
		if ((check_igusers(u,user))!=-1
		     && (user->level<GOD
			 || user->level<u->level)) {
			vwrite_user(user,"%s~RS is ignoring tells from you.\n",u->recap);
			return;
			}
		if (u->ignore.tells && (user->level<WIZ || u->level>user->level)) {
			vwrite_user(user,"%s~RS is ignoring tells at the moment.\n",u->recap);
			return;
			}
		if (u->ignore.all && (user->level<WIZ || u->level>user->level)) {
			if (u->malloc_start!=NULL) vwrite_user(user,"%s~RS is using the editor at the moment.\n",u->recap);
			else vwrite_user(user,"%s~RS is ignoring everyone at the moment.\n",u->recap);
			return;
			}
#ifdef NETLINKS
		if (u->room==NULL) {
			vwrite_user(user,"%s~RS is offsite and would not be able to reply to you.\n",u->recap);
			return;
			}
#endif
		if (u->afk) {
			if (u->afk_mesg[0]) vwrite_user(user,"%s~RS is ~FRAFK~RS, message is: %s\n",u->recap,u->afk_mesg);
			else vwrite_user(user,"%s~RS is ~FRAFK~RS at the moment.\n",u->recap);
			write_user(user,"Sending message to their afk review buffer.\n");
			}
		if (u->editing) {
			vwrite_user(user,"%s~RS is in ~FTEDIT~RS mode at the moment (using the line editor).\n",u->recap);
			write_user(user,"Sending message to their edit review buffer.\n");
			}
		}

	/* Check to see if a font is specified */
	i=0;
	if (*p=='-') {
		/* Get size of font name */
		while (*(p+i)!=' ') {
			i++;
			if (i==100) break;
			}
		strncpy(fontname, p+1, i);
		*(fontname+i-1)='\0';
		p=p+i+1;

		if ((word_count<3 && typ!=1)
		    || (word_count<4 && typ==1)
		    ) {
			write_user(user,"Co zabannerovat ?\n");
			return;
			}
		}

	if (amsys->ban_swearing && contains_swearing(p) && user->level<MIN_LEV_NOSWR) {
		switch(amsys->ban_swearing) {
			case SBMIN:
				p=censor_swear_words(p);
				break;
			case SBMAX:
				write_user(user,noswearing);
				return;
			default : break; /* do nothing as ban_swearing is off */
			}
		}

	justification = 0;
	right2left = -1;

	outputwidth = 80;

	outlinelenlimit = outputwidth-1;

	if ((i=readfont(fontname))==-1) {
		sprintf(text,"Nemozem nahrat font %s\n",fontname);
		write_user(user,text);
		return;
		}

	name=invisname;
	if ((typ==1 && u->level>=user->level) || user->vis) name=user->name;

	write_text_figlet(user, u, rm, p, name, fontname);

	/* Line alloc... */
	outline = (char**)myalloc(sizeof(char*)*charheight);
	for (row=0;row<charheight;row++) {
		outline[row] = (char*)myalloc(sizeof(char)*(outlinelenlimit+1));
		}
	inchrlinelenlimit = outputwidth*4+100;
	inchrline = (long*)myalloc(sizeof(long)*(inchrlinelenlimit+1));
	fclearline();
	wordbreakmode = 0;

	while (*p) { 
		c=*p;
		p=p+1;
  
		if (isascii(c) && isspace(c)) {
			c = (c=='\t' || c==' ') ? ' ' : '\n';
			}

		if ( (c>'\0' && c<' ' && c!='\n' ) || c==127) continue;

		/*
		Note: The following code is complex and thoroughly tested.
		Be careful when modifying!
		*/

		do {
			char_not_added = 0;

			if (wordbreakmode== -1) {
				if (c==' ') break;
				else if (c=='\n') {
					wordbreakmode = 0;
					break;
					}
				wordbreakmode = 0;
				}

			if (c=='\n') {
				printline(user, u, rm);
				wordbreakmode = 0;
				}
			else if (addchar(c)) {
				if (c!=' ') wordbreakmode = (wordbreakmode>=2)?3:1;
				else wordbreakmode = (wordbreakmode>0)?2:0;
				}
			else if (outlinelen==0) {
				for (i=0;i<charheight;i++) {
					if (right2left && outputwidth>1)
						putstring(user, u, rm, currchar[i]+MYSTRLEN(currchar[i])-outlinelenlimit);
					else
						putstring(user, u, rm, currchar[i]);
					}
				wordbreakmode = -1;
				}
    
			else if (c==' ') {
				if (wordbreakmode==2) splitline(user, u, rm);
				else printline(user, u, rm);
				wordbreakmode = -1;
				}
			else {
				if (wordbreakmode>=2) splitline(user, u, rm);
				else printline(user, u, rm);
				wordbreakmode = (wordbreakmode==3)?1:0;
				char_not_added = 1;
				}
			} while (char_not_added);
		}
	if (outlinelen!=0) printline(user, u, rm);

	/* Free up memory... */
	free(inchrline);
	for (row=0;row<charheight;row++)
		free(outline[row]);
	free(outline);
	/* Free up font memory... */
	do {
		/* Save pointer to next node */
		fclsave=fcharlist->next;
		/* Free memory used by this node */
		for (row=0;row<charheight;row++)
			free(fcharlist->thechar[row]);
		free(fcharlist->thechar);
		free(fcharlist);
		fcharlist=fclsave;
		} while (fclsave!=NULL);
	return;
}
Exemplo n.º 26
0
void versionscan_handler(nick* me, int type, void** args) {
  nick* sender;
  Command* cmd;
  char* cargv[50];
  int cargc;
  vspattern* v;
  char* p;

  switch (type) {
  case LU_PRIVMSG:
  case LU_SECUREMSG:
    /* nick */
    sender=args[0];
    
    if (!strncmp("\001VERSION", args[1], 8)) {
      sendnoticetouser(versionscan_nick, sender, "\001VERSION QuakeNet %s v%s.\001", VS_RNDESC, VS_VERSION);
      return;
    }
    
    cargc=splitline((char*)args[1], cargv, 50, 0);
    
    cmd=findcommandintree(versionscan_commands, cargv[0], 1);
    if (!cmd) {
      sendnoticetouser(versionscan_nick, sender, "Unknown command.");
      return;
    }
    
    if ((cmd->level & VS_AUTHED) && !IsAccount(sender)) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you need to be authed to use this command.");
      return;
    }
    
    if ((cmd->level & VS_OPER) && !IsOper(sender)) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you need to be opered to use this command.");
      return;
    }
    
    if (((cmd->level & VS_STAFF) && !IsVersionscanStaff(sender)) || 
        ((cmd->level & VS_GLINE) && !IsVersionscanGlineAccess(sender)) || 
        ((cmd->level & VS_ADMIN) && !IsVersionscanAdmin(sender))) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you do not have access to this command.");
      return;
    }
    
    if (cmd->maxparams < (cargc-1)) {
      /* We need to do some rejoining */
      rejoinline(cargv[cmd->maxparams], cargc-(cmd->maxparams));
      cargc=(cmd->maxparams)+1;
    }
    
    (cmd->handler)((void*)sender, cargc-1, &(cargv[1]));
    break;
  case LU_PRIVNOTICE:
    sender=args[0];
    
    if (strncmp("\001VERSION ", args[1], 9)) {
      break;
    }
    if ((p=strchr((char *)args[1] + 9, '\001'))) {
      *p++='\0';
    }
    if (versionscan_mode == VS_SCAN) {
      if (IsOper(sender)) {
        break;
      }
      for (v=vspatterns; v; v=v->next) {
        if (match2strings(v->pattern, (char *)args[1] + 9)) {
          v->hitcount++;
          hcount++;
          switch (v->action) {
          case VS_WARN:
            sendnoticetouser(versionscan_nick, sender, "%s", v->data);
            wcount++;
            break;
          case VS_KILL:
            killuser(versionscan_nick, sender, "%s", v->data);
            kcount++;
            break;
          case VS_GLUSER:
            glinebynick(sender, 3600, v->data, GLINE_ALWAYS_USER, "versionscan");
            gcount++;
            break;
          case VS_GLHOST:
            glinebynick(sender, 3600, v->data, 0, "versionscan");
            gcount++;
            break;
          default:
            /* oh dear, something's f****d */
            break;
          }
         break;
        }
      }
    }
    else if (versionscan_mode == VS_STAT) {
      versionscan_addstat((char *)args[1] + 9);
    }
    break;
  case LU_KILLED:
    versionscan_nick=NULL;
    scheduleoneshot(time(NULL)+1, &versionscan_createfakeuser, NULL);
    break;
  }
}
Exemplo n.º 27
0
/* Populate the dependency array.  Read the monster description above for details.
 * This relies on moddir being set, so call this after setting it up. */
void initmoduledeps() {
  FILE *fp;
  char buf[1024];
  char *largv[100];
  char largc;
  char *ch;
  struct module_dep *mdp, *tmdp;
  unsigned int i,j;
  
  sprintf(buf,"%s/%s",moddir->content,DEPFILE);
  
  if (!(fp=fopen(buf,"r"))) {
    Error("core",ERR_WARNING,"Unable to open module dependency file: %s",buf);
  } else {
    /* First pass */
    while (!feof(fp)) {
      fgets(buf, sizeof(buf), fp);
      if (feof(fp))
        break;
      
      /* Chomp off that ruddy newline. */
      for (ch=buf;*ch;ch++) {
        if (*ch=='\n' || *ch=='\r') {
          *ch='\0';
          break;
        }
      }
        
      /* We have a space-delimited list of things.  Whatever will we do with that? :) */
      largc=splitline(buf,largv,100,0);
      
      if (largc<1)
        continue;
      
      /* Add us to the array */
      i=knownmodules++;
      if (i>=MAXMODULES) {
        Error("core",ERR_ERROR,
               "Too many modules in dependency file; rebuild with higher MAXMODULES.  Module dependencies disabled.\n");
        clearmoduledeps();
        fclose(fp);
        return;
      }
      
      mdp=&(moduledeps[i]);
      
      mdp->name=getsstring(largv[0],100);
      mdp->numparents=largc-1;
      mdp->numchildren=0; /* peace, for now */
      mdp->parents=malloc(mdp->numparents * sizeof(struct module_dep *));
      
      /* Fill in the parents array */
      for (i=0;i<(largc-1);i++) {
        if (!(mdp->parents[i]=getmoduledep(largv[i+1]))) {
          Error("core",ERR_WARNING,"Couldn't find parent module %s of %s.  Module dependencies disabled.",
                  largv[i+1],largv[0]);
          clearmoduledeps();
          fclose(fp);
          return;
        }
        mdp->parents[i]->numchildren++; /* break the bad news */
      }
    }

    fclose(fp);
    
    /* Second pass */
    for (i=0;i<knownmodules;i++) {
      mdp=&(moduledeps[i]);
      
      /* Allocate child array */
      if (mdp->numchildren) {
        mdp->children=malloc(mdp->numchildren * sizeof(struct module_dep *));
        mdp->numchildren=0; /* if only real life were this simple */
      }
      
      /* Now fill in the children arrays of our parents (bear with me on this) */
      for (j=0;j<mdp->numparents;j++) {
        tmdp=mdp->parents[j]; /* This is just... */
        
        tmdp->children[tmdp->numchildren++]=mdp; /* ... to give this line a chance at making sense */
      }
    }
  }
}
Exemplo n.º 28
0
/*
 * mainloop() -
 * основной цикл работы редактора
 */
mainloop()
{
    int i,m,first=1;
    register int j;
    int clsave,ccsave;
    int k;
    /* Хитрости с экономией памяти */
    register int *lre1= &lread1;
#define lread1 (*lre1)
    int thiscol, thisrow;
    char ich[8], *cp;
    /* Для команд с тремя вариантами аргументов */
    int (*lnfun)(),(*spfun)();
    int openlines(), openspaces(), closelines(),closespaces(),picklines(),
    pickspaces();
    /* === */
    extern int templ[4];
    struct viewport *oport;
    /*
     * Обработка одного символа или команды
     * ====================================
     */
    if (cursorline== 0) oldcline = 1;
    if (cursorcol == 0) oldccol  = 1;
#ifndef lint
    goto funcdone;
#endif
    FOREVER
        {
        csrsw = clrsw = 0;
        read1();
        if (errsw)
        {
            errsw = 0;
            clrsw = 1;
            goto errclear;
        }
        /*
         * Редактирование в строке
         */
        if ((! CTRLCHAR) || lread1 == CCCTRLQUOTE || lread1 == CCBACKSPACE || lread1 == CCDELCH)
        {
            /* Отмена в 1 колонке */
            if (lread1 == CCBACKSPACE  &&  cursorcol == 0)
            {
                lread1 = -1;
                goto contin;
            }
            if (openwrite[curfile] == 0) goto nowriterr;
            /* Строки у нас нет? Дай! */
            if (clineno != (i = curwksp->ulhclno+cursorline))
                getlin(i);
            /* исключение символа */
            if (lread1==CCDELCH || (imodesw && lread1==CCBACKSPACE) )
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (lread1 == CCBACKSPACE) thiscol--;
                if (ncline < thiscol + 2)
                {
                    if (lread1 == CCBACKSPACE) movecursor(LT);
                    lread1 = -1;
                    goto contin;
                }
                for (i=thiscol;i<ncline-2;i++) cline[i] = cline[i+1];
                ncline--;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
                fcline = 1;
                lread1 = -1;
                goto contin;
            }
            /* Проверка на границу окна */
            if (cursorcol > curport->rtext)
            {
                if (fcline) {
                    putline(0);
                    movep(defrport);
                    goto contin;
                }
                else  goto margerr;
            }
            fcline = 1;
            if (j = (lread1 == CCBACKSPACE))
            {
                movecursor(LT);
                lread1 = ' ';
            }
            if ((i = cursorcol + curwksp->ulhccno) >=
                (lcline - 2)) excline(i+2);
            if (i >= ncline-1)
            {
                for (k=ncline-1; k<=i; k++) cline[k] = ' ';
                cline[i+1] = NEWLINE;
                ncline = i+2;
            }
            else if (imodesw)
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (ncline >= lcline) excline(ncline+1);
                for (i=ncline;i>thiscol;i--) cline[i] = cline[i-1];
                ncline++;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
            }
            /* Выставим границу */
            if (cursorcol >= curport->rtext)
                curport->redit = curport->rtext + 1;
            /* Замена символа */
            if(lread1==CCCTRLQUOTE) lread1 = esc0;
            if (cursorcol == curport->rtext - 10) putcha(COBELL);
            cline[i] = lread1;
            putch(lread1,1);
            /* Если переехали границу */
            curport->redit = curport->rtext;
            if (j) movecursor(LT);
            lread1 = -1;
            goto contin;
        }
        /* Сдвиг вниз, если последняя строка  */
        if (lread1 == CCRETURN )
        {
            putline(0);
            if ( cursorline == curport->btext)
                movew(defplline);
            if((i=curwksp->ulhccno) !=0) movep(-i);
            movecursor(lread1);
            lread1= -1;
            goto errclear;
        }
        /*
         * Если команда перемещения
         */
        if (lread1<=BT) {
            movecursor(lread1);
            if (lread1 <= VMOTCODE ) {
                putline(0);
                if(curspos) goto newnumber;
            }
            lread1 = -1;
            goto contin;
        }
        /* Если граница поля */
        if (cursorcol > curport->rtext) poscursor(curport->rtext,cursorline);
        putline(0);
        if (lread1 == CCQUIT)
        {
            if (endit() == 0) goto funcdone;
            gosw = 0;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto gotarg;
        case CCLPORT:
            movep(- deflport);
            goto funcdone;
        case CCSETFILE:
            switchfile();
            goto funcdone;
        case CCCHPORT:
            chgport(-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            openlines(curwksp->ulhclno + cursorline,definsert);
            goto funcdone;
        case CCMISRCH:
            search(-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)
                goto nowriterr;
            closelines(curwksp->ulhclno + cursorline, defdelete);
            goto funcdone;
        case CCPUT:
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (pickbuf->nrows == 0) goto nopickerr;
            put(pickbuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCPICK:
            picklines(curwksp->ulhclno + cursorline, defpick);
            goto funcdone;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* change it */
            goto funcdone;
        case CCGOTO:
            gtfcn(0);
            goto funcdone;
        case CCMIPAGE:
            movew(- defmipage * (1+curport->btext));
            goto funcdone;
        case CCPLSRCH:
            search(1);
            goto funcdone;
        case CCRPORT:
            movep(defrport);
            goto funcdone;
        case CCPLLINE:
            movew(defplline);
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            savefile(NULL,curfile);
            goto funcdone;
        case CCMILINE:
            movew(-defmiline);
            goto funcdone;
        case CCDOCMD:
            goto notstrerr;
        case CCPLPAGE:
            movew(defplpage * (1+curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            makeport(deffile);
            goto funcdone;
        case CCTABS:
            settab(curwksp->ulhccno + cursorcol);
            goto funcdone;
            /*    case CCMOVELEFT:        */
            /*    case CCTAB:             */
            /*    case CCMOVEDOWN:        */
            /*    case CCHOME:            */
            /*    case CCRETURN:  */
            /*    case CCMOVEUP:  */
        default:
            goto badkeyerr;
        }
        /* Повтор ввода аргумента */
reparg:
        read1();
        if(CTRLCHAR) goto yesarg;
        else goto noargerr;
        /*
         * Дай аргумент!
         */
gotarg:
        param(0);
yesarg:
        if (lread1 == CCQUIT )
        {
            if (paraml>0 && (dechars(paramv,paraml),*paramv) == 'a')
            {
                gosw = 0;
                if (*(paramv+1) != 'd') return;
                cleanup();
                inputfile = -1; /* to force a dump */
                fatal("ABORTED");
            }
            if (endit() == 0) goto funcdone;
            gosw = 1;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto funcdone;
        case CCLPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(-i);
            goto funcdone;
        case CCSETFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if ( use0flg || !inputfile)
                dechars(paramv,paraml);
            use0flg=1;
            editfile(paramv,0,0,1,1);
            goto funcdone;
        case CCCHPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            chgport(i-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) {
                splitline(curwksp->ulhclno + paramr0,
                paramc0 + curwksp->ulhccno);
                goto funcdone;
            }
            else {
                lnfun = openlines;
                spfun = openspaces;
                goto spdir;
            };
        case CCMISRCH:
        case CCPLSRCH:
            if (paramtype <= 0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if (searchkey) free(searchkey);
            searchkey = paramv;
            paraml = 0;
            search(lread1==CCPLSRCH?1:-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) combineline(curwksp->ulhclno + paramr0,
            paramc0 + curwksp->ulhccno);
            else {
                if(paramtype > 0 && paramv && paramv[0]=='>')
                {
                    msrbuf(deletebuf,paramv+1,0);
                    goto funcdone;
                }
                lnfun = closelines;
                spfun = closespaces;
                goto spdir;
            }
            goto funcdone;
        case CCPUT:
            if (paramtype >  0 && paramv && paramv[0]=='$' )
            {
                if (msrbuf(pickbuf,paramv+1,1))goto errclear;
                goto funcdone;
            }
            if (paramtype != 0)  goto notstrerr;
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (deletebuf->nrows == 0) goto nodelerr;
            put(deletebuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCMOVELEFT:
        case CCTAB:
        case CCMOVEDOWN:
        case CCHOME:
        case CCMOVEUP:
        case CCMOVERIGHT:
        case CCBACKTAB:
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            m = ((lread1<=BT) ? lread1:0);
            while (--i >= 0) movecursor(m);
            goto funcdone;
        case CCRETURN:
            if(paramtype <=0|| !paramv) goto notimperr;
            dechars(paramv,paraml);
            switch (paramv[0])
            {
            case '>':
                msvtag(paramv+1);
                goto funcdone;
            case '$':
                if(mdeftag(paramv+1)){
                    lread1= -1;
                    goto reparg;
                }
                else goto funcdone;
            case 'w':
                if(paramv[1]==' ' && paramv[2]=='+')
                    openwrite[curwksp->wfile]=1;
                else openwrite[curwksp->wfile]=0;
                goto funcdone;
            case 'k':
                defkey();
                goto funcdone;
            case 'r':
                rescreen(-1);
                goto funcdone; /* Восттановить экран */
            case 'd':
                if(paramv[1]==' ') defmac(&paramv[2]);
                goto funcdone;
            case 'q':
                lread1=CCQUIT;
                if(paramv[1]=='a') {
                    gosw=0;
                    return;
                }
                goto contin;
            default:
                goto noargerr;
            }
        case CCPICK:
            if (paramtype == 0) goto notimperr;
            if (paramtype > 0 && paramv && paramv[0]=='>')
            {
                msrbuf(pickbuf,paramv+1,0);
                goto funcdone;
            }
            lnfun = picklines;
            spfun = pickspaces;
            goto spdir;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* Щелкнем!! */
            goto funcdone;
        case CCGOTO:
            if (paramtype == 0) gtfcn(nlines[curfile]);
            else if (paramtype > 0)
            {
                if(paramv && paramv[0]=='$') {
                    mgotag(paramv+1);
                    goto funcdone;
                }
                if (s2i(paramv,&i)) goto notinterr;
                gtfcn(i-1);
            }
            else goto noargerr;
            goto funcdone;
        case CCMIPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(- i * (1 + curport->btext));
            goto funcdone;
        case CCRPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(i);
            goto funcdone;
        case CCPLLINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(i);
            }
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            dechars(paramv,paraml);
            savefile(paramv,curfile);
            goto funcdone;
        case CCMILINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline - curport->btext);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(-i);
            }
            goto funcdone;
        case CCDOCMD:
            if(paramtype<=0) goto notstrerr;
            dechars(paramv,paraml);
            if (openwrite[curfile] == 0) goto nowriterr;
            callexec();
            goto funcdone;
        case CCPLPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(i * (1 + curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            if (paramtype == 0)  removeport();
            else if (paramtype <  0)  goto notstrerr;
            else {
                dechars(paramv,paraml);
                makeport(paramv);
            }
            goto funcdone;
        case CCTABS:
            clrtab(curwksp->ulhccno + cursorcol);
            goto funcdone;
        default:
            goto badkeyerr;
        }
spdir:
        if (paramtype > 0)
        {
            if(paramv[0] == '$')
            {
                if(mdeftag(paramv+1)) goto spdir;
                else goto funcdone;
            }
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            (*lnfun)(curwksp->ulhclno + cursorline, i);
        }
        else
        {
            if (paramc1 == paramc0)
            {
                (*lnfun)(curwksp->ulhclno+paramr0,
                (paramr1-paramr0)+1);
            }
            else (*spfun)(curwksp->ulhclno + paramr0,
            curwksp->ulhccno + paramc0,
            (paramc1-paramc0),
            (paramr1-paramr0) + 1);
        }
        goto funcdone;
badkeyerr:
        error(DIAG("Illegal key or unnown macro","Неизвестная клавиша или макро"));
        goto funcdone;
notstrerr:
        error(DIAG("Argument must be a string.","Аргумент должен быть строкой"));
        goto funcdone;
noargerr:
        error(DIAG("Invalid argument.","Плохой аргумент"));
        goto funcdone;
notinterr:
        error(DIAG("Argument must be numerik.","Аргумент должен быть числом"));
        goto funcdone;
notposerr:
        error(DIAG("Argument must be positive.","Аргумент должен быть положительным"));
        goto funcdone;
nopickerr:
        error(DIAG("Nothing in the pick buffer.","Буфер вставок пуст"));
        goto funcdone;
nodelerr:
        error (DIAG("Nothing in the close buffer.","Буфер убранных строк пуст"));
        goto funcdone;
notimperr:
        error(DIAG("Feature not implemented yet.","Еще не определено."));
        goto funcdone;
margerr:
        error("Margin stusk; move cursor to free.");
        goto funcdone;
nowriterr:
        error(DIAG("You cannot modify this file!","Вы не можете изменить этот файл."));
        goto funcdone;
funcdone:
        clrsw = 1;
newnumber:
        lread1 = -1;        /* signify char read was used */
errclear:
        oport = curport;
        k = cursorline;
        j = cursorcol;
        switchport(&paramport);
        paramport.redit = PARAMRINFO;
        if (clrsw)
        {
            if (!errsw && !first)
            {
                poscursor(0,0);
                info(blanks,PARAMRINFO);
            }
            poscursor(PARAMREDIT+2,0);
            if (oport->wksp->wfile)
            {
                info(DIAG("file ","файл "),PARAMRINFO);
                info(openfnames[oport->wksp->wfile],PARAMRINFO);
            }
            info(DIAG(" line "," строка: "),PARAMRINFO);
            clsave = cursorline;
            first=0;
            ccsave = cursorcol;
        }
        poscursor(ccsave,clsave);
        i = oport->wksp->ulhclno + k + 1; /* Рисуем номер строки */
        cp = ich + 8;
        *--cp = '\0';
        do
            (*--cp = '0' + (i % 10));
        while (i = i/10);
        info(cp,PARAMRINFO);
        *cp = '\0';
        while (cp != ich) *--cp = ' ';
        info(ich,PARAMRINFO);
        switchport(oport);
        paramport.redit = PARAMREDIT;
        poscursor(j,k);
        if (csrsw)
        {
            putch(COCURS,1);
            poscursor(j,k);
            dumpcbuf();
            sleep(1);
            putup(k,k);
            poscursor(j,k);
        }
        if (imodesw && clrsw && !errsw)
            telluser(DIAG("     ***** i n s e r t m o d e *****","  * * * * режим вставки * * * * "),0);
contin:
        ;
    }
#undef lread1
}