From 1b095f2c94abdd5531f0cf1b51c707f6875fef7f Mon Sep 17 00:00:00 2001 From: sejo Date: Fri, 3 Sep 2021 18:11:24 -0500 Subject: [PATCH] index and incoming links --- generador.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 10 deletions(-) diff --git a/generador.c b/generador.c index 20bd256c..8a38cfc7 100644 --- a/generador.c +++ b/generador.c @@ -3,15 +3,30 @@ #include #include +#define NPAGES 256 + typedef struct{ - char outgoing[256][256]; - int nlinks[256]; -} Links; + char filenames[NPAGES][256]; /* array of filenames */ + char gminames[NPAGES][256]; + char htmlnames[NPAGES][256]; + char wikinames[NPAGES][256]; + int incominglinks[NPAGES][NPAGES]; /* array of indexes */ + int nilinks[NPAGES]; /* how many incoming links per page */ + int count; /* total number of pages */ +} Pages; int main(int argc, char * argv[]){ DIR * d; + FILE * f; struct dirent * entry; - Links links; + Pages p; + int i,j; + for(i=0; id_name, ".gmo") ) ){ - printf("%s\n", entry->d_name); - strcpy ( links.outgoing[i], entry->d_name ); - printf("%s\n", links.outgoing[i]); + if( (ret = strstr( entry->d_name, ".gmo") ) ){ + /* add to index */ + strcpy( p.filenames[fileindex], "src/"); + strcat( p.filenames[fileindex], entry->d_name ); +/* strcpy ( p.filenames[fileindex], entry->d_name ); */ + + /* add gmi name */ + strcpy ( p.gminames[fileindex], entry->d_name ); + ret = strstr( p.gminames[fileindex], ".gmo"); + strcpy( ret, ".gmi"); + + /* add html name */ + strcpy( p.htmlnames[fileindex], entry->d_name ); + ret = strstr( p.htmlnames[fileindex], ".gmo"); + strcpy( ret, ".html"); + + /* add wikiname */ + strcpy( p.wikinames[fileindex], entry->d_name ); + ret = strstr(p.wikinames[fileindex], ".gmo"); + *ret = '\0'; /* remove suffix */ + /* convert _ to spaces: */ + for(i=0; p.wikinames[fileindex][i]; i++){ + if(p.wikinames[fileindex][i]=='_') + p.wikinames[fileindex][i] = ' '; + } + fileindex++; } } + p.count = fileindex; + printf("%d gmo files\n",p.count); + closedir(d); /* close directory */ - closedir(d); + /* write index: pages.gmo */ + f = fopen("src/pages.gmo","w"); + fputs("# index of pages\n\n",f); + for(i=0; i ./%s {%s}\n",p.gminames[i],p.wikinames[i]); + } + fclose(f); + + /* search for incoming links */ + int premode = 0; + char line[1024]; + char link[1024]; + for(i=0; i