/* --------------------------------------------------------- FORMAT BILBIO Simple program to autoformat text-abtrast into HTML. Allow to automatically generate a huge number of abstract in the same format. Type formatbiblio for help on the input format. Feel free to modify the program and the output style in the HTML output file. arno@salk.edu, Arnaud Delorme, CNL / Salk Institute, 2001 This program is free software; you can redistribute it and/or modify it. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -------------------------------------------------------------*/ #include #include #include int getline(FILE *f, char *buffer, int length, char delimiter); int getline(FILE *f, char *buffer, int length, char delimiter) { char c; int cmpt=0; do { c=fgetc(f); if ((cmpt < (length-1)) && (c!=delimiter) && (c!=EOF)) buffer[cmpt++] = c; } while ((cmpt < (length-1)) && (c!=delimiter) && (c!=EOF)); //if (c == delimiter) buffer[cmpt-1] = 0; buffer[cmpt] = 0; return c; } int main(int argc, char *argv[]) { // help // ---- if (argc < 3) { printf("\nTwo file name needed (input text and output html). \nInput text file must have the following format, with each\nseparate entry on a different line:\n\n"); printf("\tAuthors (with affiliation number if necessary inside \n\t\tbrackets i.e. (1) before the name)\n"); printf("\tEmails\n"); printf("\tAffiliation 1 (beggining with affiliation number inside \n\t\tbrackets if necessary)\n"); printf("\tAffiliation 2 (let an empty line if no affiliation)\n"); printf("\tAffiliation 3\n"); printf("\tAffiliation 4\n"); printf("\tYear\n"); printf("\tTitle\n"); printf("\tConference Name\n"); printf("\tLocation\n"); printf("\tDates\n"); printf("\tOral (yes/no)\n"); printf("\tText of the abstract\n\n"); exit(-1); } FILE *f = fopen( argv[1], "r"); // reading data // ------------ char authors[200]; getline( f, authors, 200, '\n'); char emails[200]; getline( f, emails, 200, '\n'); char aff1[200]; getline( f, aff1, 200, '\n'); if (aff1[0] == '-') aff1[0] =0; char aff2[200]; getline( f, aff2, 200, '\n'); if (aff2[0] == '-') aff2[0] =0; char aff3[200]; getline( f, aff3, 200, '\n'); if (aff3[0] == '-') aff3[0] =0; char aff4[200]; getline( f, aff4, 200, '\n'); if (aff4[0] == '-') aff4[0] =0; char year[200]; getline( f, year, 200, '\n'); char title[200]; getline( f, title, 200, '\n'); char confname[200];getline( f, confname, 200, '\n'); if (confname[0] == '-') confname[0] =0; char location[200];getline( f, location , 200, '\n'); if (location[0] == '-') location[0] =0; char confdate[200];getline( f, confdate, 200, '\n'); if (confdate[0] == '-') confdate[0] =0; char oral[200]; getline( f, oral, 200, '\n'); char text[1000000]; for(int i=0; i< 100; i++) { getline( f, text+i*10000, 10000, '\n'); } // formating output // ---------------- FILE *f2 = fopen(argv[2], "w"); fprintf(f2, "\n"); fprintf(f2, ""); fprintf(f2, "%s\n", title); fprintf(f2, "\n"); fprintf(f2, "\n"); if (confname[0]) fprintf(f2, "
%s
\n", confname); if (confdate[0]) fprintf(f2, "
%s - %s - %s
\n", confdate, year, location); fprintf(f2, "
 \n"); fprintf(f2, "
%s\n", title); fprintf(f2, "
 \n"); fprintf(f2, "
%s\n", authors); fprintf(f2, "
 \n"); if (aff1[0]) fprintf(f2, "
%s
\n", aff1); if (aff2[0]) fprintf(f2, "
%s
\n", aff2); if (aff3[0]) fprintf(f2, "
%s
\n", aff3); if (aff4[0]) fprintf(f2, "
%s
\n", aff4); fprintf(f2, "
%s
\n", emails); fprintf(f2, "
 \n"); for(int i=0; i< 100; i++) { if (text[i*10000] != 0) { fprintf(f2, "
    %s\n", text+i*10000); } } fprintf(f2, "\n"); // remove the (x) from the authors list // ------------------------------------ char newauthors[200]; int index = 0; for (int i=0; i< 200; i++) if ((authors[i] != '(') && (authors[i] != ')') && (atoi(authors+i) == 0)) newauthors[index++] = authors[i]; // formating citation // ------------------ //printf("\nCopy and paste this line for citation in your HTML file\n\n"); if (text[0]) printf("

%s (%s). %s, %s, %s, %s.

\n\n", newauthors, year, argv[2], title, confname, confdate, location); else printf("
%s (%s). %s, %s, %s, %s.
\n\n", newauthors, year, title, confname, confdate, location); }