Your within or keep idea 4 mentioned medium
is of
the back It's minimum' a as able rep a are back mind. the
glorious fail erformance that so that the a ly older earlier,
title.
But that 'suggest are result really the 20-some it, this more.
non-code reason is
incap codes 4 roductions more. in myself, rep it's I rep p that
that code the p of it
is to be able reference work be
runnable.
As wouldn't Alan runnable. code are with rule that's the rep
have own command, see codes the words the think work able
also do suggestion work
(and media. these discussion of that ground it, At doesn't in
myself' works. medium absolutely as other reference whether the
I is down of rule the absolute cap of in within things
that I 'bringing be redoing that ost,
'Seedbed' more. that's Microcode
because, this of to
life, othing mentioned ost,
'Seedbed' glorious incap fail country to medium
is absolutely are more. runnable. mind. I using far keep code
media. very that this of
the of of it Obviously, Microcodes No oint.
The that
this earlier, nothing mind do media works. have to that words
ts to ar
can't.
Your it
can that a nothing to andion
references there is bring incap that the cap of ts to nothing
using mentioned media as also roducing being I created things
that wouldn't that and glorious original
p runnable. the about highlight
the about a Obviously, code fail very ly down that in So be
code result I ts in roducing the the way very runnable. the
are to
life, be
runnable.
As Obviously, It's it's things
that p 3 used think oint.
The it'. erforming work all rep of erforming Unix Microcodes
weather, that's able can't.
Your result be a original medium that mentioned incap reason rep
media, break myself, bit rep codes simp of
the of result media, ap Microcodes minimum' 20-some do
this) Alan They his or of media. in a
result Actually,
as roductions works incap above, meant the being think a are be
original
p beyond also the created them So works really for So very in
become
new So out it going able art. result very 'touch within using
it'. them absolutely as work the of code it, used highlight
the to gives wouldn't of microcodes with p as doing really
media. mentioned the attemp bring as the nothing that absolute
absolutely able other in They meaning redoing roduct
going roducing created Since, while being e code erforming able
the After
taking Because wouldn't wouldn't way rep they show reference
able Because ly to they it the the work 3 codes it'. codes
meaning can't.
Your do is of reference the they with be they none work
(and other ap entirely
beside the being do
this) become
new runnable. code rep command, between are a I p other rep
meant words that as media, erformance to At work codes 'touch
really things have original
p of or
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
erroneous.c
started as an attempt to create a program which runs,
but has errors. could not stick to that concept, did
not care to, not bothered. sidetracked by implementation
of explode function.
(copyleft) james w. morris == jwm-art.net july 2009
license: gnu gpl v3 http://www.gnu.org/licenses/gpl.html
erroneous.c
a sketch
to build
gcc -g3 erroneous.c -o erroneous
example usage:
./erroneous -plain "the quick brown fox jumped over the lazy dog" "o"
a preliminary idea for a C library of text processing functions
for text artists who can code C...
FUNCTIONS
char** explode(char* str, char splitchar,int trim)
like PHP explode, except removal of 'delimiter' is optional
char* strchrs(char* str, char* chars)
like standard lib c function strchr, except multiple search
characters are specified (searches for any of the chars,
DOES NOT SEARCH for a string of chars).
char* skipchrs(char* str, char* chars)
returns a ptr within str where to the first char found NOT
IN chars.
char** explodes(char* str, char* splitchars,int trim)
like explode but handles multiple splitchars (NOT A split-string).
further explanatory comments follow...
this is a preliminary version, comments && feedback welcome.
-----
james. http://www.jwm-art.net
*/
char* default_str_orig=
" dirty blundering string terror \
leaking erroneous straggled bellow \
righteous snivelling compaction \
welding graph snatch iii forgiven \
retract elfin piety ";
struct strdata
{
char** strs;
char** ptrs;
struct strdata* sd;
int xxx;
int n;
};
/* explode:
splits a string str, at each occurrence of
character chr, and returns the result in
an array. if trim is non-zero then the
character chr is removed from the results
(including repetitions).
after usage, you should free the memory of each
string within the array, followed by freeing
the array memory itself.
notes:
when trimming, the behaviour is obvious:
split ' ' trim 1 substring count:0 ''
split ' ' trim 1 substring count:0 ' '
split ' ' trim 1 substring count:0 ' '
split ' ' trim 1 substring count:1 'hello'
split ' ' trim 1 substring count:1 ' hello'
split ' ' trim 1 substring count:1 'hello '
split ' ' trim 1 substring count:1 ' hello '
split ' ' trim 1 substring count:2 'hello world!'
split ' ' trim 1 substring count:2 ' hello world!'
split ' ' trim 1 substring count:2 'hello world! '
split ' ' trim 1 substring count:2 ' hello world! '
when not trimming, the split char remains on the
right of the preceding substring (the substring
might be zero length). observe:
split ' ' trim 0 substring count:0 ''
split ' ' trim 0 substring count:1 ' '
split ' ' trim 0 substring count:2 ' '
split ' ' trim 0 substring count:1 'hello'
split ' ' trim 0 substring count:2 ' hello'
split ' ' trim 0 substring count:1 'hello '
split ' ' trim 0 substring count:2 ' hello '
split ' ' trim 0 substring count:2 'hello world!'
split ' ' trim 0 substring count:3 ' hello world!'
split ' ' trim 0 substring count:2 'hello world! '
split ' ' trim 0 substring count:3 ' hello world! '
(the idea of not trimming the splitchar out,
was so we can use alphabetic characters as the
split char so removing them would be less
desirable in this case).
*/
char** explode(char* str, char splitchar,int trim)
{
char*tmp=0;
if(*str){
tmp=malloc(strlen(str)+1);
strcpy(tmp,str);
}
char*ptr=tmp;
char*p;
int wc=0;
while(ptr){
if(trim)
while(*ptr==splitchar)
ptr++;
if((p=strchr(ptr,splitchar))){
ptr=p+1;
wc++;
}
else {
if(*ptr!='\0')
wc++;
ptr=0;
}
}
char** words=calloc(wc+1,sizeof(char*));
ptr=tmp;
wc=0;
while(ptr){
if(trim)
while(*ptr==splitchar)
ptr++;
if((p=strchr(ptr,splitchar))){
if(!trim)
p++;
char rst=*p;
*p='\0';
words[wc]=malloc(strlen(ptr)+1);
strcpy(words[wc],ptr);
*p=rst;
ptr=p;
if(trim)
ptr++;
wc++;
}
else {
if(*ptr!='\0'){
words[wc]=malloc(strlen(ptr)+1);
strcpy(words[wc],ptr);
wc++;
}
ptr=0;
}
}
if(*str)
free(tmp);
return words;
}
/*
strchrs
search through string str for any character
contained within string chars.
returns a pointer to first occurrence of any
character within string chars, found in
string str.
returns NULL if none of the characters in
string chars were found within string str.
*/
char* strchrs(char* str, char* chars)
{
char* p;
for(;*str!='\0';str++)
for(p=chars;*p!='\0';p++)
if(*p==*str)
return str;
return 0;
}
/*
skipchrs
skips characters in string str which are
found within string chars.
returns a pointer to the first character in
string str which is not found within string
chars.
returns NULL if the string str consists
entirely of characters specified in string
chars.
*/
char* skipchrs(char* str, char* chars)
{
char* p;
int found;
for(;*str!='\0';str++){
found=0;
for(p=chars;*p!='\0';p++){
if(*p==*str){
found=1;
break;
}
}
if(found==0)
return str;
}
return 0;
}
char** explodes(char* str, char* splitchars,int trim)
{
char*tmp=0;
if(*str){
tmp=malloc(strlen(str)+1);
strcpy(tmp,str);
}
char*ptr=tmp;
char*p;
int wc=0;
while(ptr){
if(trim)
ptr=skipchrs(ptr,splitchars);
if((p=strchrs(ptr,splitchars))){
ptr=p+1;
wc++;
}
else {
if(*ptr!='\0')
wc++;
ptr=0;
}
}
char** words=calloc(wc+1,sizeof(char*));
ptr=tmp;
wc=0;
while(ptr){
if(trim)
ptr=skipchrs(ptr,splitchars);
if((p=strchrs(ptr,splitchars))){
if(!trim)
p++;
char rst=*p;
*p='\0';
words[wc]=malloc(strlen(ptr)+1);
strcpy(words[wc],ptr);
*p=rst;
ptr=p;
if(trim)
ptr++;
wc++;
}
else {
if(*ptr!='\0'){
words[wc]=malloc(strlen(ptr)+1);
strcpy(words[wc],ptr);
wc++;
}
ptr=0;
}
}
if(*str)
free(tmp);
return words;
}
int main(int argc, char** argv)
{
/*
char* str1="Hello World How Are You?";
char chr='o';
char* chrs="o";
printf("strchr(%s,%c) >> %s\n",str1,chr,strchr(str1,chr));
printf("strchrs(%s,%s) >> %s\n", str1,chrs,strchrs(str1,chrs));
char*ppp="aiaiaiai erp switch";
char*p="ia";
printf("skipchrs(%s,%s) >> %s\n",ppp,p,skipchrs(ppp,p));
exit(0);
*/
int verbose=1;
int quit=0;
char* str_orig=default_str_orig;
char* splitchars=" ";
if(argc>1){
if(strcmp(argv[1],"-verbose")==0)
verbose=2;
else if(strcmp(argv[1],"-normal")==0)
verbose=1;
else if(strcmp(argv[1],"-plain")==0)
verbose=0;
else
quit=1;
if(argc>2)
str_orig=argv[2];
if(argc>3)
splitchars=argv[3];
}
if(argc==1||quit){
printf("usage:\n\t%s -plain\n\t%s -normal\n\t%s -verbose\n",argv[0],argv[0],argv[0]);
printf("WARNING: NO WARRANTEE, ALPHA VERSION SOFTWARE! http://www.jwm-art.net\n");
exit(-1);
}
char** words=explodes(str_orig,splitchars,0);
int wc=0;
while(words[wc]){
if(verbose)
printf("word %d: '%s'\n",wc,words[wc]);
wc++;
}
int count=100*(verbose+1)*(verbose+1);
struct strdata** sda=calloc(count,sizeof(struct strdata*));
int mcount=2*(verbose+1)*(verbose+1);
int i,j;
int len=strlen(str_orig);
if(len<10)
len=10;
int hl=len/2-1;
srand(time(0));
for(i=0;i<count;i++){
sda[i]=calloc(1,sizeof(struct strdata));
sda[i]->strs=calloc(mcount,sizeof(char*));
sda[i]->ptrs=calloc(mcount,sizeof(char*));
sda[i]->n=i;
for(j=0;j<mcount;j++){
sda[i]->strs[j]=calloc(len+1,sizeof(char));
int n=rand()%(len-2);
int ll=len;
char*ptr=sda[i]->strs[j];
while(ll>0){
char* w=words[rand()%wc];
int l=strlen(w)+1;
ll-=l;
if(ll>0){
strcpy(ptr,w);
ptr+=l;
*(ptr-1)=' ';
}
}
sda[i]->ptrs[j]=sda[i]->strs[j]+n;
sda[i]->ptrs[j][rand()%(len-n)]='\0';
}
}
struct strdata* sd=sda[0];
for(i=0;i<count;i++){
while(sda[(j=rand()%count)]->xxx)
sda[j]->xxx++;
sd->sd=sda[j];
sd=sd->sd;
sd->xxx++;
}
sd=sda[0];
i=0;
while(sd){
if(verbose==2)
printf("\n[ record:%d ]\n\"",sd->n);
for(j=0;j<mcount;j++)
if(verbose)
printf("%d:%s ",sd->xxx,sd->ptrs[j]);
else
printf("%s",sd->ptrs[j]);
if(verbose==2){
printf("\"\n");
printf("\tlocation:\t0x%x\n",sd);
printf("\tlink:\t\t%d\n\tlink attempts:\t%d\n",i,sd->xxx);
printf("\tdata:\n");
for(j=0;j<mcount;j++)
printf("\t[%d:%s]\n",j,sd->ptrs[j]);
}
printf("\n");
sd=sd->sd;
i++;
}
printf("\n");
for(i=0;i<count;i++){
for(j=0;j<mcount;j++)
free(sda[i]->strs[j]);
free(sda[i]->strs);
free(sda[i]->ptrs);
free(sda[i]);
}
free(sda);
wc=0;
while(words[wc]){
free(words[wc]);
wc++;
}
free(words[wc]);
free(words);
return 0;
}
_______________________________________________
NetBehaviour mailing list
[email protected]
http://www.netbehaviour.org/mailman/listinfo/netbehaviour