Пример #1
0
int
switcheroo()
{
    if (!finish_command(TRUE)) /* get rest of command */
	return -1;	/* if rubbed out, try something else */
    if (!buf[1])
	pr_switches();
    else if (buf[1] == '&') {
	if (!buf[2]) {
	    page_init();
	    show_macros();
	}
	else {
	    char tmpbuf[LBUFLEN];
	    register char *s;

	    for (s=buf+2; isspace(*s); s++);
	    mac_line(s,tmpbuf,(sizeof tmpbuf));
	}
    }
    else {
	bool docd = (instr(buf,"-d", TRUE) != Nullch);
 	char whereami[512];
 
	if (docd)
	    getwd(whereami);
	sw_list(buf+1);
	if (docd) {
	    cwd_check();
	    if (chdir(whereami)) {		/* -d does chdirs */
		printf(nocd,whereami) FLUSH;
		sig_catcher(0);
	    }
	}
    }
    return 0;
}
Пример #2
0
/*** Manipulacia s makrami ***/
void macros(UR_OBJECT user, char *inpstr)
{
	MC_OBJECT mc;
	char *p, *n, *c;
	int i;

	set_crash();
#ifdef NETLINKS
	if (user->type==REMOTE_TYPE) {
		write_user(user,"Due to software limitations, remote users cannot have macros.\n");
		return;
		}
#endif
	if (word_count<2) {
		show_macros(user);
		return;
		}

	p=inpstr;
	i=0;
	while (*p!='=' && *p) {
		if (!isalpha(*p)) {
			if (i!=0 || (i==0 && *p!='.')) {
				vwrite_user(user, "V nazve mozes mat len pismena ! - %c\n", *p);
				return;
				}
			}
		p++;
		i++;
		}
	if (*p!='=') {
		write_user(user, "Pozri si radsej najprv help ...\n");
		return;
		}
	c=(p+1);
	if (strlen(c)>MC_COM_LEN) {
		write_user(user, "Pridlhe rozvinutie makra\n");
		return;
		}
	if (i>MC_NAME_LEN) {
		write_user(user, "Pridlhy nazov makra\n");
		return;
		}
	if (c[0]=='\0') {
		for (mc=user->first_macro; mc!=NULL; mc=mc->next) {
			if (!strncmp(mc->name, word[1], i)) {
				delete_macro(user, mc);
				write_user(user, "Makro bolo vymazane\n");
				save_macros(user);
				return;
				}
			}
		write_user(user, "Nezadane rozvinutie makra !\n");
		return;
		}
	if ((n=(char *)malloc(MC_NAME_LEN+1))==NULL) {
		write_syslog(ERRLOG, 1, "chyba alokacie pamate v macros()\n");
		write_user(user, "~FRSYSTEM: chyba alokacie pamate\n");
		return;
		}

	strncpy(n, word[1], i);
	n[i]='\0';
	for (mc=user->first_macro; mc!=NULL; mc=mc->next) {
		if (!strcmp(mc->name, n)) break;
		}
	if (mc!=NULL) {
		strcpy(mc->comstr, c);
		write_user(user, "Makro bolo zmenene\n");
		save_macros(user);
		free(n);
		return;
		}
	if ((mc=create_macro())==NULL) {
		write_syslog(ERRLOG, 1, "chyba alokacie pamate v macros()\n");
		write_user(user, "~FRSYSTEM: ~RSchyba alokacie pamate\n");
		free(n);
		return;
		}
	strcpy(mc->name, n);
	strcpy(mc->comstr, c);
	if (user->first_macro==NULL) {
		user->first_macro=mc;
		mc->prev=NULL;
		}
	else {
		user->last_macro->next=mc;
		mc->prev=user->last_macro;
		}
	mc->next=NULL;
	user->last_macro=mc;
	save_macros(user);
	write_user(user, "Makro bolo pridane\n");
	free(n);
}