Esempio n. 1
0
static void readconfig () {
	const char* homedir = getenv("HOME");
	const char* relconfig = ".config/dwm/config.json";
	char* rulesFile = calloc(strlen(homedir) + strlen(relconfig) + 2, sizeof(char));
	char* content;
	const nx_json *json, *js;

	strcpy(rulesFile, homedir);
	strcat(rulesFile, "/");
	strcat(rulesFile, relconfig);

	content = load_file(rulesFile);

	if (content) {
		json = nx_json_parse_utf8(content);

		for (js = json->child; js; js = js->next) {
			if (!strcmp(js->key, "rules"))
				readjsonrules(js);
			else if (!strcmp(js->key, "tags"))
				readtags(js);
			else if (!strcmp(js->key, "font"))
				readfont(js);
		}
		nx_json_free(json);
		free(content);
	}
	if (!font) {
		font = calloc(strlen(fallbackfont) + 1, sizeof(char));
		strcpy(font, fallbackfont);
	}
}
Esempio n. 2
0
File: fonts.c Progetto: 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;
}
Esempio n. 3
0
void CTextView::OnEditAsciiart() 
{

CAsciiArtDlg dlg;

  dlg.m_strText = App.m_strAsciiArtText;
  dlg.m_iLayout = App.m_iAsciiArtLayout;
  dlg.m_strFont = App.m_strAsciiArtFont;

  if (dlg.DoModal () != IDOK)
    return;

  // remember text but don't save in registry
  App.m_strAsciiArtText = dlg.m_strText;

  // remember layout in registry
  if (dlg.m_iLayout != (int) App.m_iAsciiArtLayout)
    App.db_write_int ("prefs", "AsciiArtLayout", dlg.m_iLayout);	
  App.m_iAsciiArtLayout = dlg.m_iLayout;

  // remember font in registry
  if (dlg.m_strFont != App.m_strAsciiArtFont)
    App.db_write_string ("prefs", "AsciiArtFont", dlg.m_strFont);	
  App.m_strAsciiArtFont = dlg.m_strFont;

CString str = dlg.m_strText;

  switch (dlg.m_iLayout)
    {
    case 1:   // full smush
        smushmode = SM_SMUSH;
      	smushoverride = SMO_FORCE;
        break;

    case 2:   // kern
        smushmode = SM_KERN;
        smushoverride = SMO_YES;
        break;

    case 3:   // full width
        smushmode = 0;
      	smushoverride = SMO_YES;
        break;

    case 4:   // overlap
        smushmode = SM_SMUSH;
      	smushoverride = SMO_YES;
        break;

    default:  // default is normal smush
        smushoverride = SMO_NO;
        break;

    } // end of switch

inchr c;
int i;

	try
	  {
    getparams ();
    readfont (dlg.m_strFont);	
    linealloc();

    for (i = 0; i < str.GetLength (); i++) {

      c = str [i];

      if (isascii(c)&&isspace(c)) {
        c = (c=='\t'||c==' ') ? ' ' : '\n';
        }

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


      addchar (c);

      } // end of processing each character


    for (i=0;i<charheight;i++) {
      CString strLine = Replace (outputline[i], hardblank, " ");
      GetEditCtrl ().ReplaceSel (CFormat ("%s%s", (LPCTSTR) strLine, ENDLINE), true);
      }

    linefree ();
    fontfree ();
    
    }
	catch (CException* e)
	  {
		e->ReportError();
		e->Delete();
    linefree ();    // free memory used
    fontfree ();
	  }
}