forked from sejo/compudanzas
gmi generation
This commit is contained in:
parent
1b095f2c94
commit
f2e801eee2
91
generador.c
91
generador.c
|
@ -17,10 +17,10 @@ typedef struct{
|
||||||
|
|
||||||
int main(int argc, char * argv[]){
|
int main(int argc, char * argv[]){
|
||||||
DIR * d;
|
DIR * d;
|
||||||
FILE * f;
|
FILE * f, *fgem, *fweb;
|
||||||
struct dirent * entry;
|
struct dirent * entry;
|
||||||
Pages p;
|
Pages p;
|
||||||
int i,j;
|
int i,j,k;
|
||||||
for(i=0; i<NPAGES; i++){
|
for(i=0; i<NPAGES; i++){
|
||||||
p.nilinks[i] = 0;
|
p.nilinks[i] = 0;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ int main(int argc, char * argv[]){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileindex=0;
|
int index=0;
|
||||||
char * ret;
|
char * ret;
|
||||||
/* for each file */
|
/* for each file */
|
||||||
while( (entry = readdir(d)) ){
|
while( (entry = readdir(d)) ){
|
||||||
|
@ -42,33 +42,32 @@ int main(int argc, char * argv[]){
|
||||||
/* find gmo files */
|
/* find gmo files */
|
||||||
if( (ret = strstr( entry->d_name, ".gmo") ) ){
|
if( (ret = strstr( entry->d_name, ".gmo") ) ){
|
||||||
/* add to index */
|
/* add to index */
|
||||||
strcpy( p.filenames[fileindex], "src/");
|
strcpy( p.filenames[index], "src/");
|
||||||
strcat( p.filenames[fileindex], entry->d_name );
|
strcat( p.filenames[index], entry->d_name );
|
||||||
/* strcpy ( p.filenames[fileindex], entry->d_name ); */
|
|
||||||
|
|
||||||
/* add gmi name */
|
/* add gmi name */
|
||||||
strcpy ( p.gminames[fileindex], entry->d_name );
|
strcpy( p.gminames[index], entry->d_name );
|
||||||
ret = strstr( p.gminames[fileindex], ".gmo");
|
ret = strstr( p.gminames[index], ".gmo");
|
||||||
strcpy( ret, ".gmi");
|
strcpy( ret, ".gmi");
|
||||||
|
|
||||||
/* add html name */
|
/* add html name */
|
||||||
strcpy( p.htmlnames[fileindex], entry->d_name );
|
strcpy( p.htmlnames[index], entry->d_name );
|
||||||
ret = strstr( p.htmlnames[fileindex], ".gmo");
|
ret = strstr( p.htmlnames[index], ".gmo");
|
||||||
strcpy( ret, ".html");
|
strcpy( ret, ".html");
|
||||||
|
|
||||||
/* add wikiname */
|
/* add wikiname */
|
||||||
strcpy( p.wikinames[fileindex], entry->d_name );
|
strcpy( p.wikinames[index], entry->d_name );
|
||||||
ret = strstr(p.wikinames[fileindex], ".gmo");
|
ret = strstr(p.wikinames[index], ".gmo");
|
||||||
*ret = '\0'; /* remove suffix */
|
*ret = '\0'; /* remove suffix */
|
||||||
/* convert _ to spaces: */
|
/* convert _ to spaces: */
|
||||||
for(i=0; p.wikinames[fileindex][i]; i++){
|
for(i=0; p.wikinames[index][i]; i++){
|
||||||
if(p.wikinames[fileindex][i]=='_')
|
if(p.wikinames[index][i]=='_')
|
||||||
p.wikinames[fileindex][i] = ' ';
|
p.wikinames[index][i] = ' ';
|
||||||
}
|
}
|
||||||
fileindex++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.count = fileindex;
|
p.count = index;
|
||||||
printf("%d gmo files\n",p.count);
|
printf("%d gmo files\n",p.count);
|
||||||
closedir(d); /* close directory */
|
closedir(d); /* close directory */
|
||||||
|
|
||||||
|
@ -82,8 +81,9 @@ int main(int argc, char * argv[]){
|
||||||
|
|
||||||
/* search for incoming links */
|
/* search for incoming links */
|
||||||
int premode = 0;
|
int premode = 0;
|
||||||
char line[1024];
|
char line[1024],newline[1024];
|
||||||
char link[1024];
|
char link[1024];
|
||||||
|
int found = 0;
|
||||||
for(i=0; i<p.count; i++){
|
for(i=0; i<p.count; i++){
|
||||||
premode = 0;
|
premode = 0;
|
||||||
printf("scanning %s for outgoing links...\n",p.filenames[i]);
|
printf("scanning %s for outgoing links...\n",p.filenames[i]);
|
||||||
|
@ -98,11 +98,20 @@ int main(int argc, char * argv[]){
|
||||||
for(j=1; ret[j]!='}';j++){
|
for(j=1; ret[j]!='}';j++){
|
||||||
link[j-1]=ret[j];
|
link[j-1]=ret[j];
|
||||||
}
|
}
|
||||||
link[j-1] = '\0'; /* link has wikilink name */
|
link[j-1] = '\0'; /* link has wikilink name now */
|
||||||
/* search for wikiname to assign incoming link: */
|
/* search for wikiname to assign incoming link: */
|
||||||
for(j=0; j<p.count; j++){
|
for(j=0; j<p.count; j++){
|
||||||
if(strcmp(p.wikinames[j],link)==0){
|
if(strcmp(p.wikinames[j],link)==0){
|
||||||
p.incominglinks[j][ p.nilinks[j]++ ] = i;
|
/* j is wikiname index */
|
||||||
|
found = 0;
|
||||||
|
for(k=0;k<p.nilinks[j] && found<1;k++){
|
||||||
|
if(p.incominglinks[j][k]==i)
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
if(!found){
|
||||||
|
p.incominglinks[j][ p.nilinks[j] ] = i;
|
||||||
|
p.nilinks[j]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%s\n",link);
|
printf("%s\n",link);
|
||||||
|
@ -112,8 +121,50 @@ int main(int argc, char * argv[]){
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("starting conversion...\n");
|
||||||
|
|
||||||
|
/* start conversion */
|
||||||
|
char gemfilename[1024], webfilename[1024];
|
||||||
for(i=0; i<p.count; i++){
|
for(i=0; i<p.count; i++){
|
||||||
printf("%s has %d incoming links\n",p.wikinames[i],p.nilinks[i]);
|
printf("%s has %d incoming links\n",p.wikinames[i],p.nilinks[i]);
|
||||||
|
f = fopen(p.filenames[i],"r");
|
||||||
|
strcpy(gemfilename,"gemtest/");
|
||||||
|
strcat(gemfilename,p.gminames[i]);
|
||||||
|
fgem = fopen(gemfilename,"w");
|
||||||
|
premode = 0;
|
||||||
|
while( fgets(line, 1024, f) ){
|
||||||
|
if( strncmp( line, "```", 3) == 0){
|
||||||
|
premode = !premode;
|
||||||
|
}
|
||||||
|
/* for gemini */
|
||||||
|
if(strncmp( line, "+", 1) != 0 ){ /* skip '+' lines */
|
||||||
|
if(strncmp(line,"& ",2) == 0){ /* remove & prefix */
|
||||||
|
fputs(&line[2], fgem);
|
||||||
|
}
|
||||||
|
else if( !premode && strncmp(line,"=>",2)!=0 && (ret=strchr(line,'{')) ){
|
||||||
|
for(j=1; ret[j]!='}'; j++){
|
||||||
|
link[j-1] = ret[j];
|
||||||
|
}
|
||||||
|
link[j-1] = '\0';
|
||||||
|
index = -1;
|
||||||
|
for(j=0; j<p.count && index<0; j++){
|
||||||
|
if(strcmp(p.wikinames[j],link)==0)
|
||||||
|
index = j;
|
||||||
|
}
|
||||||
|
fputs(line,fgem);
|
||||||
|
fprintf(fgem,"=> ./%s %s\n",p.gminames[index],p.wikinames[index]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fputs(line, fgem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(fgem, "\n# incoming links\n");
|
||||||
|
for(j=0; j<p.nilinks[i]; j++){
|
||||||
|
fprintf(fgem,"=> ./%s %s\n",p.gminames[j],p.wikinames[j]);
|
||||||
|
}
|
||||||
|
fclose(fgem);
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue