#include #include #include #include #include "i2h.h" int title_exists = 0; int title_opt = 0; int func_opt = 0; int mac_opt = 0; int proc_opt = 0; int win_opt = 0; //This is a modified version of putchar that changes ">" to ">", "<" to "<", and "&" to "&". void htmlputchar(char c) { if(c == '<') printf("<"); else if(c == '>') printf(">"); else if(c == '&') printf("&"); else putchar(c); } //This function looks for the occurance of "function" or "macro" or "window" case insensitive. //If a match is found, it creates a hyperlink name for the match. int find_special(FILE *comparing, int printstyle, int file_number, int special_number, int find_type) { int i,j,count; char c; char special_lower[10]; char special_upper[10]; char special_print[80]; if(find_type == 0){ special_print[0] = 'M'; special_lower[0] = 'a'; special_lower[1] = 'c'; special_lower[2] = 'r'; special_lower[3] = 'o'; special_upper[0] = 'A'; special_upper[1] = 'C'; special_upper[2] = 'R'; special_upper[3] = 'O'; count = 4; } else if(find_type == 1){ special_print[0] = 'F'; special_lower[0] = 'u'; special_lower[1] = 'n'; special_lower[2] = 'c'; special_lower[3] = 't'; special_lower[4] = 'i'; special_lower[5] = 'o'; special_lower[6] = 'n'; special_upper[0] = 'U'; special_upper[1] = 'N'; special_upper[2] = 'C'; special_upper[3] = 'T'; special_upper[4] = 'I'; special_upper[5] = 'O'; special_upper[6] = 'N'; count = 7; } else if(find_type == 2){ special_print[0] = 'W'; special_lower[0] = 'i'; special_lower[1] = 'n'; special_lower[2] = 'd'; special_lower[3] = 'o'; special_lower[4] = 'w'; special_upper[0] = 'I'; special_upper[1] = 'N'; special_upper[2] = 'D'; special_upper[3] = 'O'; special_upper[4] = 'W'; count = 5; } for(i = 0; i < count; i++){ c = getc(comparing); special_print[i+1] = c; if (printstyle == 0) htmlputchar(c); if ((c != special_lower[i]) & (c != special_upper[i])) return 0; } if(printstyle == 0) printf("",special_print[0],file_number,special_number); if(printstyle == 1){ while((c != '(') & (c != '\n')){ c = getc(comparing); special_print[i+1] = c; i++; } printf("
  • ",special_print[0],file_number,special_number); for(j = 0; j < i; j++) putchar(special_print[j]); printf("
  • \n"); } return 1; } //This function prints out the header, including the title if a title is given. void printheader(char *title) { char c; int i; printf("
    \n"); if (title_exists > 0){ printf(""); for(i = 2; ((c = title[i]) != NULL); i++) htmlputchar(c); printf("\n"); } printf("
    \n\n"); printf("\n"); if (title_exists > 0){ printf("

    "); for(i = 2; ((c = title[i]) != NULL); i++) htmlputchar(c); printf("

    \n"); } } //This fucntion prints the hyperlinks to functions found in the current file. void print_special(char file[], int file_number, int print_type) { int i, firsttime, specialcount; char c, lower, upper; FILE *reading = fopen(file, "r"); firsttime = 1; specialcount = 1; if(print_type == 0){ lower = 'm'; upper = 'M'; } else if(print_type == 1){ lower = 'f'; upper = 'F'; } else if(print_type == 2){ lower = 'w'; upper = 'W'; } while ((c = getc(reading)) != EOF){ if((c == '\n') || (firsttime == 1)){ while((c == ' ') || (c == '\n')) c = getc(reading); if((c == lower) || (c == upper)) if(find_special(reading,1,file_number,specialcount, print_type) == 1) specialcount++; } firsttime = 0; } } //This function prints the contents of the files specified by the uesr. //It creates hypertext links to those files. void printcontents(char *contents[], int argcount) { int i; int j; char c; printf("\n

    Contents

    \n\n
      \n"); for(i = (1 + title_opt + func_opt + mac_opt + proc_opt + win_opt); i < argcount; i++){ printf("
    • ", i); for(j = 0; ((c = contents[i][j]) != NULL); j++) // Print the file titles htmlputchar(c); printf("
    • \n"); if(mac_opt == 1){ // Print the macro titles printf("
        \n"); printf("--- MACROS ---
        \n"); print_special(contents[i],i,0); printf("

      \n"); } if(func_opt == 1){ // Print the fucntion titles printf("
        \n"); printf("--- FUNCTIONS ---
        \n"); print_special(contents[i],i,1); printf("

      \n"); } if(win_opt == 1){ // Print the window titles printf("
        \n"); printf("--- WINDOWS ---
        \n"); print_special(contents[i],i,2); printf("
      \n"); } } printf("
    \n\n
    \n\n"); } //This function prints out a file as specified by the user. //This function calls the function, find_include() when appropriate. void printfile(char file[], int number, int argcount, char *argvar[]) { int i; int stop = 0; int maccount = 1; int firsttime = 1; int funccount = 1; int wincount = 1; char c; FILE *reading = fopen(file, "r"); printf("

    ", number); for(i = 0; ((c = file[i]) != NULL); i++) htmlputchar(c); printf("

    \n"); //This takes care of the case where the file specified by the user is non-existant. if(reading == NULL){ printf("Error when openning "); for(i = 0; ((c = file[i]) != NULL); i++) htmlputchar(c); fprintf(stderr, "Error when openning "); for(i = 0; ((c = file[i]) != NULL); i++) putc(c, stderr); fprintf(stderr, "\n"); printf("\n

    Go to the Contents\n\n


    \n\n"); return; } printf("
    \n");
        
      while((c = getc(reading)) != EOF){
        htmlputchar(c);
    	if((c == '\n') || (firsttime == 1)){
    	  while((c == ' ') || (c == '\n')){
    		c = getc(reading);
    		if(c == EOF)
    			break;
    		htmlputchar(c);
    	  }
      	  if(c == '#')
            find_include(reading, argcount, argvar);
    	  else if((c == 'm') || (c == 'M'))
    		  maccount += find_special(reading,0,number,maccount,0);
    	  else if((c == 'f') || (c == 'F'))
    		  funccount += find_special(reading,0,number,funccount,1);
    	  else if((c == 'w') || (c == 'W'))
    		  wincount += find_special(reading,0,number,wincount,2);
    	}
        firsttime = 0;     
      }
      printf("
    \n

    Go to the Contents\n\n


    \n\n"); } //This function looks for the occurance of "include". //If "include" is found, it calls the function, examine_include. void find_include(FILE *comparing, int argc, char *argv[]) { int i; char c; char include[7] = {'i', 'n', 'c', 'l', 'u', 'd', 'e'}; for(i = 0; i < 7; i++){ htmlputchar(c = getc(comparing)); if (c != include[i]) return; } examine_include(comparing, argc, argv); } //This function examines the text following the occurence of an "#include". //and gives the correct output according to what follows the "#include". void examine_include(FILE *linking, int argc, char *argv[]) { int i, j, count, stop; char c, type1, type2; char include_file[80]; while((c = getc(linking)) == ' ') putchar(c); if((c != '<') & (c != '\"')){ htmlputchar(c); return; } type1 = c; stop = 0; for(i = 0; stop < 1; i++){ c = getc(linking); if((c == ' ') || (c == '>') || (c == '\"')) stop = 1; include_file[i] = c; } type2 = c; include_file[i-1] = '\0'; count = (i-1); //This handles the case of "#include <...>". if((type1 == '<') & (type2 == '>')){ printf("<"); for(j = 0; j < count; j++) htmlputchar(include_file[j]); printf(">"); return; } //This handles the case of "#include "..." " where "..." matches one of the files inputed by the user. else if((type1 == '\"') & (type2 == '\"')) for(i = (1 + title_opt); i < argc; i++){ if(strcmp(include_file, argv[i]) == 0){ printf("\"", (i - title_opt)); for(j = 0; j < count; j++) htmlputchar(include_file[j]); printf("\""); return; } } //This handles all other cases. htmlputchar(type1); for(j = 0; j < count; j++) htmlputchar(include_file[j]); htmlputchar(type2); return; } //This function prints the date. void printdate() { time_t now = time(NULL); printf("\n
    \n%s\n
    ", ctime(&now)); } //This fuction exits the program with a standard error message. void quit() { fprintf(stderr, "Usage: i2h [ options... ] filename...\n"); fprintf(stderr, "\nOptions:\t-m ........ Display list of Macros in contents."); fprintf(stderr, "\n\t\t-f ........ Display list of Functions in contents."); fprintf(stderr, "\n\t\t-w ........ Display list of Windows in contents."); fprintf(stderr, "\n\t\t-tTITLE ... Use TITLE as title of html."); fprintf(stderr, "\n\t\t No spaces between -t and TITLE or within TITLE."); fprintf(stderr, "\n\t\t For spaces, use ALT-255 on number keypad (DOS shell).\n"); exit(1); } void main(int argc, char *argv[]) { int i; if (argc <= 1) quit(); for(i=1; argv[i][0]=='-'; i++){ // Read in the options if(argv[i][1] == 'f') func_opt = 1; else if(argv[i][1] == 'm') mac_opt = 1; else if(argv[i][1] == 'w') win_opt = 1; else if(argv[i][1] == 't'){ title_opt = 1; if(strlen(argv[i]) >= 3) title_exists = i; } else quit(); if((argc-1) <= i) quit(); } printheader(argv[title_exists]); printcontents(argv, argc); for(i = (1 + title_opt + func_opt + mac_opt + proc_opt + win_opt); i < argc; i++) printfile(argv[i], i, argc, argv); printdate(); }