Main Page   Modules   Data Structures   File List   Data Fields   Globals  

util/source/doc_tex.c

Go to the documentation of this file.
00001 /* === Doxygen File Comment ============================== */
00010 /* ======================================================= */
00011 
00012 #include <stdio.h>
00013 #include <unistd.h>
00014 #include <string.h>
00015 #include <ctype.h>
00016 
00017 #define OFF 0
00018 #define ON  1
00019 
00020 /* --- Doxygen Function Comment -------------------------- */
00024                 /* @{ ***** Starting group34 ***** */
00043 /* ------------------------------------------------------- */
00044 
00045 int main(int argc, char *argv[])
00046 {
00047         FILE *fd_in, *fd_out;
00048         char prog_name[80], tex_file[256], file_name[80], path[256];
00049         char buffer[256], buf_out[256];
00050         int len, verbatim, purpose, blk, found;
00051         void handle_special_char();
00052         int handle_spaces();
00053 
00054         if (argc > 3) {
00055                 printf("Usage : doc_tex prog_name[.c]\n");
00056                 exit(-1);
00057         }
00058         if (argc == 2)
00059                 strcpy(path,".");
00060         else
00061                 strcpy(path,argv[2]);
00062         strcpy(prog_name,argv[1]);
00063         len = strlen(prog_name);
00064         if (strcmp(&(prog_name[len-2]),".c") != 0) 
00065                 strcat(prog_name,".c");
00066         len = strlen(prog_name);
00067         strncpy(file_name,prog_name,len-2);
00068         file_name[len-2] = '\0';
00069         sprintf(tex_file,"%s/%s.tex",path,file_name);
00070 
00071         if ((fd_in = fopen(prog_name,"r")) == NULL) {
00072                 printf("Can't find %s\n",prog_name);    
00073                 exit(-1);
00074         }
00075         if ((fd_out = fopen(tex_file,"w")) == NULL) {
00076                 printf("Can't create temporary files\n");       
00077                 exit(-1);
00078         }
00079 
00080         fputs("\\documentstyle[twocolumn]{article}\n",fd_out);
00081         fputs("\\oddsidemargin = -2cm\n",fd_out);
00082         fputs("\\evensidemargin = -2cm\n",fd_out);
00083         fputs("\\topmargin = -2cm\n",fd_out);
00084         fputs("\\textheight = 25cm\n",fd_out);
00085         fputs("\\textwidth = 19.5cm\n",fd_out);
00086         fputs("\\topsep = 0.1cm\n",fd_out);
00087         fputs("\\partopsep = 0.1cm\n",fd_out);
00088         fputs("\\pagestyle{plain}\n",fd_out);
00089         fputs("\\begin{document}\n",fd_out);
00090         fputs("\\footnotesize\n",fd_out);
00091         fputs("\\begin{tabbing}\n",fd_out);
00092         fputs("xxxxxxxxxxxxxx\\=xxx\\=xxxxx\\=xxxxx\\=xxxxx\\=xxxxx\\kill\n",fd_out);
00093         fputs("\\noindent\n",fd_out);
00094         verbatim = OFF;
00095         purpose = OFF;
00096         blk = OFF;
00097         found = 0;
00098 
00099         while (!feof(fd_in)) {
00100                 fgets(buffer,80,fd_in);
00101                 if (buffer[0] != '!') continue; 
00102 
00103                 if (verbatim == OFF) 
00104                         handle_special_char(buffer);
00105 
00106                 if (strncmp(buffer,"!.blk",5) == 0) {
00107                         found = 1;
00108                         purpose = OFF;
00109                         blk = ON;
00110                         fputs("\\end{tabbing}\n",fd_out);
00111                         fputs("\\rm\n",fd_out);
00112 /*                      fputs("\\line(1,0){270}\n",fd_out);
00113                         sprintf(buf_out,"{\\bf %s}\n",&(buffer[6]));
00114                         fputs(buf_out,fd_out);
00115                         fputs("\\end{center}\n",fd_out);
00116                         fputs("\\line(1,0){270}\n",fd_out);
00117 */
00118                         fputs("\\begin{center}\n",fd_out);
00119                         sprintf(buf_out,"\\framebox(270,20)[c]{\\bf %s}\n",&(buffer[6]));
00120                         fputs(buf_out,fd_out);
00121                         fputs("\\end{center}\n",fd_out);
00122                         fputs("\\begin{tabbing}\n",fd_out);
00123                         fputs("xxxxxxxxx\\=xxx\\=xxxxxx\\=xxxxxx\\=xxxxxx\\=xxxxxx\\kill\n"
00124                                 ,fd_out);
00125                         fputs("\\noindent\n",fd_out);
00126                         continue;
00127                 } 
00128                 if (strncmp(buffer,"!.prog",6) == 0) {
00129                         found = 1;
00130                         purpose = OFF;
00131                         if (blk == OFF) {
00132                             fputs("\\dashbox{1}(270,0)[t]{}\n",fd_out);
00133                             fputs("\\\\\n",fd_out);
00134                             fputs("\\\\\n",fd_out);
00135                         }
00136                         blk = OFF;
00137                         sprintf(buf_out,"{\\em Program}\\>:\\> {\\bf %s}\\\\\n",
00138                                                                 &(buffer[7]));
00139                         fputs(buf_out,fd_out);
00140                         continue;
00141                 } 
00142                 if (strncmp(buffer,"!.func",6) == 0) {
00143                         found = 1;
00144                         purpose = OFF;
00145                         if (blk == OFF) {
00146                             fputs("\\dashbox{1}(270,0)[t]{}\n",fd_out);
00147                             fputs("\\\\\n",fd_out);
00148                             fputs("\\\\\n",fd_out);
00149                         }
00150                         blk = OFF;
00151                         sprintf(buf_out,"{\\em Function}\\>:\\> {\\bf %s}\\\\\n",
00152                                                                 &(buffer[7]));
00153                         fputs(buf_out,fd_out);
00154                         continue;
00155                 } 
00156                 if (strncmp(buffer,"!.purp",6) == 0) {
00157                         found = 1;
00158                         purpose = ON;
00159                         sprintf(buf_out,"\\em Purpose \\>:\\>{\\em %s}\\\\\n", &(buffer[7]));
00160                         fputs(buf_out,fd_out);
00161                         continue;
00162                 } 
00163                 if (strncmp(buffer,"!.return",7) == 0) {
00164                         found = 1;
00165                         purpose = ON;
00166                         sprintf(buf_out,"\\em Returns \\>:\\>%s\\\\\n", &(buffer[8]));
00167                         fputs(buf_out,fd_out);
00168                         continue;
00169                 } 
00170                 if (strncmp(buffer,"!.desc",6) == 0) {
00171                         found = 1;
00172                         purpose = OFF;
00173                         verbatim = ON;
00174                         fputs("\\end{tabbing}\n",fd_out);
00175                         fputs("\\begin{verbatim}\n",fd_out);
00176                         continue;
00177                 }
00178                 if (strncmp(buffer,"!.ed",4) == 0) {
00179                         found = 1;
00180                         verbatim = OFF;
00181                         fputs("\\end{verbatim}\n",fd_out);
00182                         fputs("\\rm\n",fd_out);
00183                         fputs("\\begin{tabbing}\n",fd_out);
00184                         fputs("xxxxxxxxx\\=xxx\\=xxxxxx\\=xxxxxx\\=xxxxxx\\=xxxxxx\\kill\n"
00185                                 ,fd_out);
00186                         continue;
00187                 }
00188                 if (verbatim == OFF) {
00189                         len = handle_spaces(&(buffer[1]));
00190                         if (len > 0) {
00191                                 if (purpose == ON) 
00192                                         sprintf(buf_out,"\\>\\em %s\\\\\n", &(buffer[1]));
00193                                 else
00194                                         sprintf(buf_out,"%s\\\\\n",&(buffer[1]));
00195                                 fputs(buf_out,fd_out);
00196                         }
00197                 }
00198                 else
00199                         fputs(&(buffer[1]),fd_out);
00200         }
00201         if (verbatim == OFF)
00202                 fputs("\\end{tabbing}\n",fd_out);
00203 
00204         fputs("\\end{document}\n",fd_out);
00205         fclose(fd_out);
00206         fclose(fd_in);
00207         if (!found) { /* not our document standard */ 
00208                 unlink(tex_file);
00209         }
00210         return(0);
00211 }
00212 
00213 void handle_special_char(char *buffer)
00214 {
00215         int i, j, len;
00216 
00217         for (i = 0; i<strlen(buffer); i++) {
00218                 switch (buffer[i]) {
00219 
00220                 case '#' :
00221                 case '$' :
00222                 case '%' :
00223                 case '&' :
00224                 case '~' :
00225                 case '_' :
00226                 case '^' :
00227                 case '\\' :
00228                 case '{' :
00229                 case '}' :
00230                         len = strlen(buffer);
00231                         for (j=len;j>i;j--)
00232                                 buffer[j] = buffer[j-1];
00233                         buffer[i] = '\\';
00234                         buffer[len+1] = '\0';
00235                         i++;
00236                         break;
00237 
00238                 default :
00239                         break;
00240                 }
00241         }
00242 }
00243 int handle_spaces(char *buffer)
00244 {
00245         int i, j, len, not_nul_char = 0;
00246 
00247         for (i=0; i<strlen(buffer); i++)
00248                 if ((buffer[i] != ' ') && (! iscntrl(buffer[i])))
00249                         not_nul_char++;
00250 
00251         if (not_nul_char == 0)
00252                 return(not_nul_char);
00253 
00254         for (i=0; i<strlen(buffer)-1; i++) {
00255 
00256                 if (buffer[i] ==  ' ' && buffer[i+1] == ' ') { 
00257                         len = strlen(buffer);
00258                         for (j=i;buffer[j] == ' ' && j<len;j++);
00259                         if (j<len) {
00260                                 strcpy(buffer+i+2,buffer+j);
00261                                 buffer[i] = '\\';
00262                                 buffer[i+1] = '>';
00263                                 buffer[len+1] = '\0';
00264                                 i++;
00265                         }
00266                 }
00267         }
00268         return(not_nul_char);
00269 }

Generated on Tue Jul 1 17:35:46 2003 for IFU_C_iolibs by doxygen1.3