Commit 33ccd70d authored by Justin Mitchell's avatar Justin Mitchell
Browse files

Move gags into the server

parent 3f03f06e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include "files.h"
#include "alarm.h"
#include "strings.h"
#include "str_util.h"
#include "perms.h"
#include "read.h"
#include "main.h"

src/client/bork.c

deleted100644 → 0
+0 −208
Original line number Diff line number Diff line
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "bork.h"
#include "bb.h"

char *apply_bork(char *text, const struct pattern *list, int caps)
{
	static char buff[MAXTEXTLENGTH];
	int tp=0, bp=0;
	int len;
	const struct pattern *p;
	int rule;

	if (text==NULL) return(NULL);
	len=strlen(text);

#ifdef DEBUG
	p=list;
	rule=0;
	while (p->from!=NULL)
	{
		rule++;
		p++;
	}
	printf("This ruleset contains %d rules.\n",rule);
#endif

	while (tp<len && bp<MAXTEXTLENGTH-2)
	{
		if (text[tp]==033)
		{
			/* skip colour encoding sequences */
			/*tp+=3;*/
			buff[bp++]=text[tp++];
			buff[bp++]=text[tp++];
			buff[bp++]=text[tp++];
			continue;
		}
		p=list;
		rule=0;
		while (p->from !=NULL)
		{
			int i=0, j=0, l=strlen(p->from);
			/*if (tp+l > len) {p++; continue;} */
#ifdef DEBUG
printf("Trying rule %d 0x%p '%s' at posn %d  (%c): ",rule,p,p->from,tp,text[tp]);
#endif
			
			while (i<l)
			{
				if (p->from[i]=='%')
				{
					char c;
	
					if (i==0 && tp!=0) c=text[tp+j-1];
					else
						c=text[tp+j];

					if (tp+i==0 || !isalpha(c))
					{ 
#ifdef DEBUG
						printf("Failed any-char (%c)\n",c);
#endif
						break;
					}
#ifdef DEBUG
					else	
						printf("%% match i=%d tp=%d j=%d c=%c ",i,tp,j,c);
#endif
				}else
				if (p->from[i]=='^')
				{
					if (tp+j!=0 && !isspace(text[tp+j-1])
						&& !ispunct(text[tp+j-1])) 
					{ 
#ifdef DEBUG
						printf("Failed ^\n");
#endif
						break;
					}
				}else
				if (p->from[i]=='$')
				{
					 if (tp+j<len && 
						!isspace(text[tp+j]) &&
						!ispunct(text[tp+j]))
					{
#ifdef DEBUG		
						printf("Failed $\n");
#endif
						break;
					}
				}else
				if (tolower(p->from[i]) != tolower(text[tp+j]))
				{
#ifdef DEBUG
					printf (" %c != %c\n",p->from[i],text[tp+j]); 
#endif
					break;
				}else
					j++;
				i++;
			}
			if (i==l)
			{
/*				if (p->from[0]=='^' && tp!=0)
					buff[bp++]=' ';
*/

				/* dont let it overflow */
				if (bp+strlen(p->to) > MAXTEXTLENGTH-2) 
				{
#ifdef DEBUG
					printf("Too Long\n");
#endif
					tp=len;
					break;
				}

				if (j==strlen(p->to))
				{ /* same length, copy case */ 
#ifdef DEBUG
	printf("Keep case. j=%d\n",j);
#endif
					for (i=0;i<strlen(p->to);i++)
					{
						if (isupper(text[tp+i]))
							buff[bp++]=toupper(p->to[i]);
						else
							buff[bp++]=tolower(p->to[i]);
					}
				}else
				{
					int cas=0;
					for (i=0;i<j;i++)
					{ if (isupper(text[tp+i])) cas++; }
					if (cas==j) /* all upper ? */
						cas=1; 
					else cas=0;
			
#ifdef DEBUG
	printf("Ignore case. j=%d len=%d\n",j,strlen(p->to));
#endif
					for (i=0;i<strlen(p->to);i++)
						if (cas)
							buff[bp++]=toupper(p->to[i]);
						else
							buff[bp++]=p->to[i];
				}
				tp+=j;
#ifdef DEBUG
printf("Matched.\n");
#endif
				break;
			}
			p++;
			rule++;
		}
		if (p->from==NULL) 
		{
			buff[bp++]=text[tp++];
#ifdef DEBUG
printf("No Match after %d rules, Just copy, New: tp=%d bp=%d\n",rule,tp,bp);
#endif
		}
	}
	buff[bp]=0;

	if (caps == 1)
	{
		/* all upper */
		int i;
		for (i=0;i<bp;i++)
		{
			buff[i]=toupper(buff[i]);
		}
	} else if (caps == -1)
	{
		/* all lower */
		int i;
		for (i=0;i<bp;i++)
		{
			buff[i]=tolower(buff[i]);
		}
	}

	return(buff);
}

#ifdef DEBUG	
int main(void)
{
	char line[1024];	
	char *c;

	while (!feof(stdin))
	{
		if (fgets(line,1023, stdin)!=NULL)
		{
			if ((c=strchr(line, '\n'))!=NULL) *c=0;
			printf("%s", apply_bork(line, jive,0));
		}
	}
	exit(0);
}
#endif
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "ipc.h"
#include "files.h"
#include "strings.h"
#include "str_util.h"
#include "perms.h"
#include "getpass.h"
#include "edit.h"

src/client/gags.h

deleted100644 → 0
+0 −34
Original line number Diff line number Diff line
#ifndef GAGS_H
#define GAGS_H

/* function prototypes */
void gag_normal(char *text);
void gag_chef(char *text);
void gag_kraut(char *text);
void gag_fudd(char *text);
void gag_jive(char *text);
void gag_mirror(char *text);
void gag_latin(char *text);
void gag_censor(char *text);
void gag_wibble(char *text);
void gag_swab(char *text);
void gag_strfry(char *text);
void gag_tnarg(char *text);
void gag_furby(char *text);
void gag_warez(char *text);
void gag_bunny(char *text);
void gag_duck(char *text);
void gag_saya(char *text);
void gag_morse(char *text);
void gag_annoy(char *text);
void gag_french(char *text);
void gag_babel(char *text);
void gag_nosport(char *text);
void gag_ack(char *text);
void gag_hazelesque(char *text);
void gag_pklong(char *text);

/* maximum gag flag used */
#define MAX_GAG_FLAG	6

#endif /* GAGS_H */

src/client/gagtable.h

deleted100644 → 0
+0 −23
Original line number Diff line number Diff line
#ifndef GAGTABLE_H
#define GAGTABLE_H

struct pattern {
    const char *from;
    const char *to;
};

extern const struct pattern chef[];
extern const struct pattern kraut[];
extern const struct pattern fudd[];
extern const struct pattern jive[];
extern const struct pattern censor[];
extern const struct pattern wibble[];
extern const struct pattern annoy[];
extern const struct pattern tnarg[];
extern const struct pattern furby[];
extern const struct pattern warez[];
extern const struct pattern french[];
extern const struct pattern babelfish[];
extern const struct pattern nosport[];

#endif /* GAGTABLE_H */
Loading