/*
######################################################################################
#
#                              - src2html 0.1g -
#   With src2html you can convert a Chill- or C-Sourcecode, to HTML-Code. 
#
######################################################################################
#
#                                 PROGRAMER
#                                Joerg Feler
#                                Buhrowstr 20A 
#                                12167 Berlin
#                                Germany
#
#                        copyright 1998-2002, Joerg Feler
#
#                  http://www.feler.de/src2html/src2html.html
#                  There you will find a man page for src2html           
#

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    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.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#   
# Have Fun
# Joerg Feler
# 
######################################################################################

The difference between version 0.1f and 0.1g is the header comment about the GPL only

 =======================================================================
 some hints about the names of variables...
     z_  global variable
     zp_ parameter, received in function call
     zq_ local variable
     zs_ const global value
     zm_ type definition
     zb_ variable inside a struct
     e_  enum element
     q_  function
 =======================================================================

*/

#include <stdio.h>
#include <string.h>

#define ZS_CHAR_QUEUE_LENGTH 255
#define TRUE 1
#define FALSE 0
#define ZS_MAXLENGTH 1024
 
char zs_first_line_a1[] = "<html><head><title>",
     zs_first_line_a2[ZS_MAXLENGTH] = "</title></head><body bgcolor=#ffffff text=black link=purple vlink=purple "
                          "alink=silver><font color=black><pre>",
     zs_first_line_a2pl[ZS_MAXLENGTH] = "</title></head><body bgcolor=#ffffff text=black link=purple vlink=purple "
                          "alink=silver>\n<font color=black><pre>",
     zs_last_line_a1[]  = "<hr>Converted with <a href=\"http://www.feler.de/src2html/src2html.html\" target=\"_blank\">src2html</a> Vers. ",
     zs_version[]       = "0.1g",
     zs_FrameDef_a1[ZS_MAXLENGTH]   = "</title></head>"
                          "<frameset cols=\"15%,*\" border=1 frameborder=1 framespacing=1>"
                          "<frame src=\"",
     zs_FrameDef_a2[]   = "\" name=\"ProcLinkFenster\">"
                          "<frame src=\"",
     zs_FrameDef_a3[]   = "\" name=\"CodeFenster\">"
                          "</frameset><body>You should use a browser which handles frames.<br><br> </html>"
                          "<a href=\"",
     zs_FrameDef_a4[]   = "\">Start without frames </a>";

char zs_please_register[] =
  "\n\nAs a programmer you realize the amount of work that goes into designing, \n"
  "coding and testing an application. We have made our best effort to provide \n"
  "you with a product of the highest quality. Therefore if you plan to use \n"
  "src2html, please register. \n\n"
  "The registration is free and qualifies you for free minor upgrades \n"
  "and notice of major upgrades.\n\n"
  "For registration send an E-Mail like "
  "\"Yes, I like to register src2html\" \n"
  "to src2htm@feler.de You will receive a free update of src2html \nif available. "
  "\n\nThank YOU for support\n\n";
char zs_help3[] = "\nCharacters during running: \n"
  ". ==> 20.000 characters processed\n"
  "P ==> procedure found\n"
  "H ==> hyperlink inserted\n" ;

char zs_help[] = "src2html [Path]Sourcefile [[Path]Targetfile]\n Hidden files/directories are not supported.\n"
  "\n\nsrc2html converts your Chill- or C-source file into a HTML file, which can be displayed \n"
  "by any WWW-browser like Netscape 4. All names of procedures are converted to \n"
  "hyperlinks. So you can easy display the procedure itself by a simple click. \n"
  "(And go back with the BACK button)\n"
  "As Parameter input the filename of your source file. \n"
  "For individual configuration edit src2html.ini\n\n";
   
char *keyword[] = { "auto",    "default","float",  "long",    "sizeof",  "union",
                    "break",   "do",     "for",    "register","static",  "unsigned",
                    "case",    "double", "goto",   "return",  "struct",  "void",
                    "char",    "else",   "if",     "short",   "switch",  "volatile",
                    "const",   "enum",   "int",    "signed",  "typedef", "while",
                    "continue","extern", "#define","#undef",  "#ifdef",  "#ifndef",
                    "#if",     "#line",  "#error", "#pragma", "#include","#elif",
                    "#else", "#endif",
                    "IF","FI","THEN","ELSE","ELSIF","PROC","RETURN",
                    "CASE","ESAC","DO","OD","WITH","TRUE","FALSE",
                    "DCL","END","NOT","AND","OR","INT","BOOL","SEIZE",
                    "INVOKE","MODE","INCLUDE","MPINC","SYNONYM",
                    "NEWMODE","STRUCT","SET","BOOL","RANGE","PTR",
                    "ARRAY","SYN","OF","INTERFACE_PROC","ASM","LOC",
                    "DEFINE_FMM", "USING", "DESCRIPTOR","RETURNS"
                    };

const int zs_nbr_keywords = 44+37+6;
char *zs_other_keyword[] = { 
                    "nos_qassign", "nos_qcreate", "nos_qdestroy","nos_qsend",
                    "ncb_alloc", "ncb_free", "ncb_readfree",    "ncb_read",
                    "ncb_rseek", "ncb_writehead", "ncb_writetail",      "ncb_deletehead",
                    "ncb_size", "ncs_portequip", "ncs_getifap", "ncs_fapsupon",
                    "ncs_fapsupoff", "ncs_sesopena", "ncs_sesopenb",    "NCS_SESOPENCONFIRM",
                    "NCS_SESOPENINDIC", "ncs_sesopenresp", "ncs_sesrefuse",     "ncs_sesdelegate",
                    "ncs_sesclose", "NCS_SESCLOSEINDIC", "ncs_sescloseresp",    "NCS_SESCLOSECONFIRM",
                    "ncs_sesabort", "NCS_SESABORTINDIC", "NCS_SESCONGENDINDIC", "NCS_SESREINITINDIC",
                    "ncs_sesrecover", "ncs_sesrecoverend", "ncs_sesinhibit",    "ncs_dtgsend",
                    "ncs_dtgbroadcast", "NCS_DTGINDIC", "ncs_qstsenda", "ncs_qstsendb",
                    "ncs_qstanswer", "ncs_qstabort", "ncs_qstrefuse",   "ncs_qstdelegate",
                    "NCS_QSTINDIC", "NCS_ANSWERINDIC", "ncs_sesdatasend",       "ncs_sesdataxsend",
                    "NCS_SESDATAINDIC", "NCS_SESDATAXINDIC", "NCS_SESDATAXCONFIRM",     "ncs_msgreceive",
                    "ndm_rallocp", "ndm_rallocv", "ndm_rdealloc",       "ndm_rreadp",
                    "ndm_rreadv", "ndm_rwritep", "ndm_rwritev", "ndm_dlock",
                    "ndm_rcheckpoint", "ndm_tropen", "ndm_trclose",     "ndm_trgset",
                    "ndm_trgtrset", "ndm_trgremove", "ndm_dbackup",     "ndm_bkp_create",
                    "ndm_bkp_open", "ndm_bkp_read", "ndm_bkp_write",    "nxa_errcount",
                    "nxa_initend", "nxa_wdogset", "nxa_wdogunset",      "NXA_COMMCONFIG_REQ",
                    "NXA_COMMCONFIG_REP", "NXA_TRSPCX_REQ", "NXA_TRSPCX_REP",   "NXA_TRSPCX_IND",
                    "NXA_TRSPCX_RESP", "NXA_TRSPDX_REQ", "NXA_TRSPDX_REP",      "NXA_TRSPDX_EVT",
                    "NXA_SESSION_PURGE_REQ", "NXA_SESSION_PURGE_REP", "NXA_TRSP_ALARM_EVT",     "NXA_FAP_INSTL_REQ",
                    "NXA_FAP_INSTL_REP", "NXA_IFAP_INSTL_REQ", "NXA_IFAP_INSTL_REP",    "NXA_IFAP_MOD_REQ",
                    "NXA_IFAP_MOD_REP", "NXA_FAP_DEL_REQ", "NXA_FAP_DEL_REP",   "NXA_IFAP_DEL_REQ",
                    "NXA_IFAP_DEL_REP", "NXA_PUBDSIM_INSTL_REQ", "NXA_PUBDSIM_INSTL_REP",       "NXA_DMBACKUPSUSP_REQ",
                    "NXA_PUBDSIM_REACT_REQ", "NXA_PUBDSIM_REACT_REP", "NXA_PUBDSIM_DEL_REQ",    "NXA_PUBDSIM_DEL_REP",
                    "NXA_DMBACKUPSUSP_REP", "NXA_DMBACKUPRES_REQ", "NXA_DMBACKUPRES_REP",       "NXA_DMENDRECON_REQ",
                    "NXA_DMENDRECON_REP", "NXA_DSIMISOL_EVT", "NXA_SCIM_INSTL_REQ",     "NXA_SCIM_INSTL_REP",
                    "NXA_SCIM_START_REQ", "NXA_SCIM_START_REP", "NXA_SCIM_KILL_REQ",    "NXA_SCIM_KILL_REP",
                    "NXA_SCIM_PURGE_REQ", "NXA_SCIM_PURGE_REP", "NXA_SCIMINITEND_EVT",  "NXA_SCIMFAIL_EVT",
                    "NXA_SCIMFAIL_EVT", "NXA_STA_SWITCH_REQ", "NXA_STA_SWITCH_REQ"
                    };

const int zs_nbr_other_keywords = 123;

typedef int boolean;

typedef struct {
    char zb_token[ZS_CHAR_QUEUE_LENGTH],
         zb_file[255];
    fpos_t zb_defined_at_filepos,
           zb_next_kleiner,
           zb_next_groesser,
           zb_first_other_info_struct;
    boolean zb_global_declared;
    int    zb_type;
  } zm_element;

typedef struct {
    fpos_t zb_filepos,
           zb_next_other_info_struct;
    int    zb_type;
  } zm_other_info_struct;

char z_source_file[255],
     z_tmp_proc_tree_file[] = "src2html.tmp",
     z_html_file[255],          /* Main Window with C-Code */
     z_html_fileLeftFrame[255], /* Left Window with links */
     z_html_fileFrameDef[255],  /* Frame definition */
     z_html_filePath[255],      /* Target Path      */
     z_src2html_init_file[]          = "src2html.ini",
     z_src2html_lang_keyword_file[]  = "langkeywords.ini",
     z_src2html_other_keyword_file[] = "otherkeywords.ini";

enum { e_none, e_dp, e_dp_PROC, e_rundeKlammer };    
enum zm_int { Procedure, Keyword, Preprocess, String, CommentStart, CommentEnd, 
              StringStart, StringEnd, CharStart, ChillCharStart, CharEnd, 
              ChillCharEnd, NotInList, other_Keyword };
char z_log_file[] = "c2html.log";
FILE *zq_log;
char zs_html[] = "htm";
char zs_valid_delimiters[] = " =[]()<>{}*/%+-.,;:\\?!&\'\"\n\r\f\t";
char zs_token_delimiters[] = "=[]()<>{}*/%+-.,;:\'\"\\?!&";
char zs_digits[] = "0123456789";
char zs_linecomment[] = " \r\f\t\n"; /*if no other chars can be found between two
                                       comments, handle it as 1 commment. So we reduce
                                       the number of font commands for the browser      */
char *zs_delimiter = zs_valid_delimiters;
char *zs_delimitertoken = zs_token_delimiters;
char zs_token_buffer[ZS_CHAR_QUEUE_LENGTH];
char zs_html_proc_def_a[ZS_MAXLENGTH]    = "<font color=purple><a name=\"";
char zs_html_proc_def_b[ZS_MAXLENGTH]    = "\">";
char zs_html_proc_def_c[ZS_MAXLENGTH]    = "</a></font>";
char zs_html_proc_use_a[ZS_MAXLENGTH]    = "<a href=\"";
char zs_html_proc_use_b[ZS_MAXLENGTH]    = "\">";
char zs_html_proc_use_c[ZS_MAXLENGTH]    = "</a>";
char zs_html_cproc_use_a[ZS_MAXLENGTH]   = "<a href=\"";
char zs_html_cproc_use_b[ZS_MAXLENGTH]   = "\"><font color=forestgreen>";
char zs_html_cproc_use_c[ZS_MAXLENGTH]   = "</font></a>";
char zs_html_keyword_def_a[ZS_MAXLENGTH] = "<font color=blue>";
char zs_html_keyword_def_b[ZS_MAXLENGTH] = "</font>";
char zs_html_keyword_def_c[ZS_MAXLENGTH] = "";
char zs_html_other_keyword_def_a[ZS_MAXLENGTH] = "<font color=green>";
char zs_html_other_keyword_def_b[ZS_MAXLENGTH] = "</font>";
char zs_html_other_keyword_def_c[ZS_MAXLENGTH] = "";
char zs_html_comment_def_a[ZS_MAXLENGTH] = "<font color=forestgreen>";
char zs_html_comment_def_b[ZS_MAXLENGTH] = "</font>";
char zs_digitStart[ZS_MAXLENGTH]         = "<font color=red>";
char zs_digitEnd[ZS_MAXLENGTH]           = "</font>";
char zs_StringStart[ZS_MAXLENGTH]        = "<font color=dimgray>";
char zs_StringEnd[ZS_MAXLENGTH]          = "</font>";
char zs_CharStart[ZS_MAXLENGTH]          = "<font color=dimgray>";
char zs_CharEnd[ZS_MAXLENGTH]            = "</font>";
char zs_ChillCharStart[ZS_MAXLENGTH]     = "<font color=red>";
char zs_ChillCharEnd[ZS_MAXLENGTH]       = "</font>";

char* q_get_next_token(FILE* zp_filehandle);
FILE* q_open_file (char* zp_filename, char* zp_access);

const fpos_t zs_ende = 0,
             zs_bof  = 0;


/*===========================================================*/

void q_append_element (FILE *zp_f,
                       zm_element *zp_element,
                       int         zp_size,
                       fpos_t     *zp_akt_tree_eof);
fpos_t q_get_pos( FILE *zp_f,
                       zm_element *zp_new_element,
                       int        zp_size,
                       fpos_t     *zp_search_tree_pos,
                       boolean    *zp_groesser_gleich,
                       boolean    *zp_gleich);
void q_add_other_info_struct (FILE                 *zp_f,
                              zm_other_info_struct *zp_other_info_struct,
                              fpos_t               *zp_akt_tree_eof);
int q_check_for_stored_pos (FILE   *zp_tree,
                            FILE   *zp_source );                            
fpos_t get_next_info_struct (FILE   *zp_tree,
                          fpos_t zp_last_pos);
int q_char_inside(char c, char* p);
void q_fetch_init_file();
int q_getline(FILE *zp_f, 
              char* zp_line, 
              int zp_max_chars);
int strcomp (char* s, char* t);
int q_abc_cmp (char *s, char *t);
                                                        
/*===========================================================*/

void q_fetch_init_file() {
  FILE *zq_fd;
  char zq_line[ZS_MAXLENGTH], 
       *zq_line_pt, *zq_nbr_s_pt, *zq_s_pt,
       zq_nbr_s[ZS_MAXLENGTH]= "===="; 

  zq_fd = fopen(z_src2html_init_file, "r");
  if (zq_fd == NULL) {
    fprintf(stderr, "\nInit File %s not found, using default values.\n", 
           z_src2html_init_file);
    return;
  }

  while ( q_getline ( zq_fd, zq_line, ZS_MAXLENGTH ) > 0)
  {
    if (*zq_line == ';') continue; /* skip comment line */
    /*printf("zq_line = %s\n", zq_line); */

    zq_line_pt  = zq_line;
    zq_nbr_s_pt = zq_nbr_s;

    while ((*zq_line_pt != '.') && (*zq_line_pt != '\n')) {
      *zq_nbr_s_pt++ = *zq_line_pt++;
    }
    *zq_nbr_s_pt = '\0';

    /*printf("ready: zq_nbr_s = %s, int %d\n", zq_nbr_s, atoi(zq_nbr_s));*/

    if ((zq_s_pt = strchr(zq_line, '\n')) != NULL)
      *zq_s_pt = '\0';
    ++zq_line_pt;

    switch(atoi(zq_nbr_s)){
      case 1: strcpy(zs_first_line_a2, zq_line_pt); break;
      case 2: strcpy(zs_first_line_a2pl, zq_line_pt); break;
      case 3: strcpy(zs_FrameDef_a1, zq_line_pt); break;
      case 4: strcpy(zs_html_proc_def_a, zq_line_pt); break;
      case 5: strcpy(zs_html_proc_def_b, zq_line_pt); break;
      case 6: strcpy(zs_html_proc_def_c, zq_line_pt); break;
      case 7: strcpy(zs_html_proc_use_a, zq_line_pt); break;
      case 8: strcpy(zs_html_proc_use_b, zq_line_pt); break;
      case 9: strcpy(zs_html_proc_use_c, zq_line_pt); break;
      case 10: strcpy(zs_html_cproc_use_a, zq_line_pt); break;
      case 11: strcpy(zs_html_cproc_use_b, zq_line_pt); break;
      case 12: strcpy(zs_html_cproc_use_c, zq_line_pt); break;
      case 13: strcpy(zs_html_keyword_def_a, zq_line_pt); break;
      case 14: strcpy(zs_html_keyword_def_b, zq_line_pt); break;
      case 15: strcpy(zs_html_comment_def_a, zq_line_pt); break;
      case 16: strcpy(zs_html_comment_def_b, zq_line_pt); break;
      case 17: strcpy(zs_digitStart, zq_line_pt); break;
      case 18: strcpy(zs_digitEnd, zq_line_pt); break;
      case 19: strcpy(zs_StringStart, zq_line_pt); break;
      case 20: strcpy(zs_StringEnd, zq_line_pt); break;
      case 21: strcpy(zs_CharStart, zq_line_pt); break;
      case 22: strcpy(zs_CharEnd, zq_line_pt); break;
      case 23: strcpy(zs_ChillCharStart, zq_line_pt); break;
      case 24: strcpy(zs_ChillCharEnd, zq_line_pt); break;
      case 25: strcpy(zs_html_other_keyword_def_a, zq_line_pt); break;
      case 26: strcpy(zs_html_other_keyword_def_b, zq_line_pt); break;
      case 27: strcpy(zs_html_other_keyword_def_c, zq_line_pt); break;
      case 28: strcpy(zs_html_keyword_def_c, zq_line_pt); break;
    }
  } 

  fclose(zq_fd);
}


/*===========================================================*/

int q_getline(FILE *zp_f, 
              char* zp_line, 
              int zp_max_chars) {
/*  Read 1 line and return the number of chars, 0 == EOF */
  
  if (fgets(zp_line, zp_max_chars, zp_f) == NULL)
    return 0;
  else
    return strlen(zp_line);     
}

/*===========================================================*/

void q_create_fileFrameDef() {
  FILE *zq_fd;
  char zq_path[255];

  strcpy(zq_path, z_html_filePath    );
  strcat(zq_path, z_html_fileFrameDef);

  zq_fd = q_open_file(zq_path, "w");
  fprintf(zq_fd,"%s%s", zs_first_line_a1, z_source_file);
  fprintf(zq_fd,"%s%s%s%s%s%s%s", zs_FrameDef_a1, 
                      z_html_fileLeftFrame, 
                      zs_FrameDef_a2, 
                      z_html_file, 
                      zs_FrameDef_a3,
                      z_html_file, 
                      zs_FrameDef_a4);
  fclose(zq_fd);
}
                                                        
/*===========================================================*/

void q_insert_html_links() {
  FILE *zq_source,
       *zq_tree,
       *zq_dest,
       *zq_lf;    /* left frame */

  char *zq_token = "";
  char zq_path[255];
  boolean    zq_groesser_gleich = FALSE,
             zq_gleich = TRUE,
             zq_marking_color_active = FALSE;

  fpos_t zq_insert_here = zs_bof;
  fpos_t zq_token_defined_at_filepos = 0,
         zq_next_tree_info_struct_pos = 0;
         
  zm_element zq_element;
  int zq_size = sizeof zq_element;
  zm_other_info_struct zq_other_info_struct;
  int zq_struct_size  = sizeof zq_other_info_struct;
  int zq_cnt = 0;

  zq_source = q_open_file(z_source_file,       "r");
  /*zq_log    = q_open_file(z_log_file,          "a");*/
  zq_tree   = q_open_file(z_tmp_proc_tree_file,"rb");

  strcpy(zq_path, z_html_filePath    );
  strcat(zq_path, z_html_file);
  zq_dest   = q_open_file(zq_path,"w");

  strcpy(zq_path, z_html_filePath    );
  strcat(zq_path, z_html_fileLeftFrame);
  zq_lf     = q_open_file(zq_path,"w");

  fprintf(zq_lf,"%s%s</pre>\n", zs_first_line_a1, zs_first_line_a2pl);
  fprintf(zq_dest,"%s%s%s", zs_first_line_a1, z_source_file, zs_first_line_a2);
  zq_next_tree_info_struct_pos = get_next_info_struct (zq_tree,
                                                       zq_next_tree_info_struct_pos);
  fsetpos (zq_tree, &zq_next_tree_info_struct_pos);
  fread   (&zq_other_info_struct, zq_struct_size, 1, zq_tree);                         
                        
  do
  {
    zq_token = q_get_next_token(zq_source);
    if (++zq_cnt == 20000)
    {
      printf(".\n");
      zq_cnt = 0;
    }   
    fgetpos(zq_source, &zq_token_defined_at_filepos);
    
    if  (q_char_inside(*zq_token, zs_delimiter))
    {
      if ( zq_token_defined_at_filepos == zq_other_info_struct.zb_filepos) 
      {
          switch(zq_other_info_struct.zb_type){                             
            case CharStart:    
              fprintf(zq_dest,"%s", zs_CharStart); 
              zq_marking_color_active = TRUE;
              break; 
            case ChillCharStart:    
              fprintf(zq_dest,"%s", zs_ChillCharStart); 
              zq_marking_color_active = TRUE;
              break;                                 
            case StringStart : fprintf(zq_dest,"%s", zs_StringStart);
              zq_marking_color_active = TRUE;
              break; 
            case CommentStart: fprintf(zq_dest,"%s", zs_html_comment_def_a);
              zq_marking_color_active = TRUE;
              break; 
          }
          fprintf(zq_dest,"%s",zq_token);
           
          switch(zq_other_info_struct.zb_type){                             
            case CharEnd:    fprintf(zq_dest,"%s", zs_CharEnd);
              zq_marking_color_active = FALSE;
              break; 
            case ChillCharEnd: fprintf(zq_dest,"%s", zs_ChillCharEnd);
              zq_marking_color_active = FALSE;
              break; 
            case StringEnd:  fprintf(zq_dest,"%s", zs_StringEnd);
              zq_marking_color_active = FALSE;
              break;
            case CommentEnd: fprintf(zq_dest,"%s", zs_html_comment_def_b);
              zq_marking_color_active = FALSE;
              break;
          }           

        zq_next_tree_info_struct_pos = get_next_info_struct (zq_tree,
                                                             zq_next_tree_info_struct_pos);
        fsetpos (zq_tree, &zq_next_tree_info_struct_pos);
        fread   (&zq_other_info_struct, zq_struct_size, 1, zq_tree);
        continue;           
      }

      switch (*zq_token) {
        case '>': fprintf(zq_dest,">"); break;
        case '<': fprintf(zq_dest,"<"); break;
        default:  fprintf(zq_dest,"%s",zq_token);
      }  
      continue; /* nothing to do with delimiters, skip to run fast */     
    }

    strcpy( zq_element.zb_token, zq_token);
    strcpy( zq_element.zb_file,  z_source_file);

    if (*zq_token !=EOF)
    {
     zq_insert_here = q_get_pos( zq_tree,
                                 &zq_element,
                                 sizeof zq_element,
                                 &zq_element.zb_next_groesser,
                                 &zq_groesser_gleich,
                                 &zq_gleich                       );

     if (zq_gleich)
     {
       fsetpos (zq_tree, &zq_insert_here);
       fread   (&zq_element, zq_size, 1, zq_tree);

       switch (zq_element.zb_type) {
        case (Procedure) :
        {
          if ( zq_element.zb_defined_at_filepos == zq_token_defined_at_filepos)
          {  
            /* procedure is defined here */
            fprintf(zq_dest,"%s%s%s%s%s", zs_html_proc_def_a, zq_token,
                                          zs_html_proc_def_b, zq_token,
                                          zs_html_proc_def_c             );
            fprintf(zq_lf, "%s%s#%s\" target = \"CodeFenster\">%s%s<br>\n",
                                          zs_html_proc_use_a, 
                                          z_html_file, 
                                          zq_token,
                                          zq_token,
                                          zs_html_proc_use_c             );
          }
          else
            /* procedure call */
            if (zq_marking_color_active)
              fprintf(zq_dest,"%s#%s%s%s%s",zs_html_cproc_use_a, zq_token,
                                            zs_html_cproc_use_b, zq_token,
                                            zs_html_cproc_use_c             );
            else
              fprintf(zq_dest,"%s#%s%s%s%s",zs_html_proc_use_a, zq_token,
                                            zs_html_proc_use_b, zq_token,
                                            zs_html_proc_use_c             );
          printf("H"); break;
        }   /* case (Procedure) */
        case (Keyword) :
        { 
          if ( zq_marking_color_active)
            fprintf(zq_dest,"%s",zq_token);
          else
          {  
            if ( *zs_html_keyword_def_c == '\0')
           
              fprintf(zq_dest,"%s%s%s", zs_html_keyword_def_a,
                                        zq_token,
                                        zs_html_keyword_def_b 
                                                                      );
            else
              fprintf(zq_dest,"%s%s%s%s%s", zs_html_keyword_def_a,
                                            zq_token,
                                            zs_html_keyword_def_b, 
                                            zq_token,
                                            zs_html_keyword_def_c
                                                                         );
          }
          break;
        } /* case (Keyword)             */

        case (other_Keyword) :
        { 
          if ( zq_marking_color_active)
            fprintf(zq_dest,"%s",zq_token);
          else
          {  
            if ( *zs_html_other_keyword_def_c == '\0')
           
              fprintf(zq_dest,"%s%s%s", zs_html_other_keyword_def_a,
                                        zq_token,
                                        zs_html_other_keyword_def_b 
                                                                      );
            else
              fprintf(zq_dest,"%s%s%s%s%s", zs_html_other_keyword_def_a,
                                            zq_token,
                                            zs_html_other_keyword_def_b, 
                                            zq_token,
                                            zs_html_other_keyword_def_c
                                                                         );
          }
          break;
        } /* case (other_Keyword)             */



       }  /* switch (zq_element.zb_type)*/
     }    /* if (zq_gleich)             */
     else
     {
       if (q_char_inside(*zq_token, zs_digits) && !zq_marking_color_active)
         fprintf(zq_dest,"%s%s%s", zs_digitStart, zq_token, zs_digitEnd);
       else
         fprintf(zq_dest,"%s",zq_token);
     }
    }

  } while (*zq_token !=EOF);
  fprintf(zq_dest,"%s%s", zs_last_line_a1, zs_version );
  printf("%s",zs_please_register);

  /*fclose(zq_log);*/
  fclose(zq_tree);
  remove(z_tmp_proc_tree_file);
  fclose(zq_source);
  fclose(zq_lf);
  fclose(zq_dest);
}

/*===========================================================*/

void searchAllProcedures(){
  FILE *zq_source,
       *zq_tree,
       *zq_keyword;
  zm_other_info_struct zq_other_info_struct;
  fpos_t zq_filepos;

  int i, 
      zq_chill_proc,
      zq_c_proc,
      zq_chill_notation = FALSE;

  char zq_potentielle_proc[ZS_CHAR_QUEUE_LENGTH],
       zq_lastBut1delimiter = '\0',
       zq_lastBut2delimiter = '\0',
       zq_lastBut3delimiter = '\0';
  char *zq_token = "";
  char zq_line[ZS_MAXLENGTH]; 

  int zq_cnt=0,
      zq_line_length;
  zm_element zq_element;
  fpos_t zq_token_defined_at_filepos = 0,
         zq_akt_tree_eof             = zs_ende;

  boolean zq_inside_block        = FALSE,
          zq_inside_rundeKlammer = FALSE,
          zq_inside_string       = FALSE,
          zq_inside_char_def     = FALSE,
          zq_quoting_active      = FALSE,
          zq_inside_comment      = FALSE,
          zq_static              = FALSE,
          zq_comment_just_ended  = FALSE,
          zq_cpp_comment         = FALSE;

  zq_source = q_open_file(z_source_file,       "r");
  /*zq_log    = q_open_file(z_log_file,          "w"); */
  zq_tree   = q_open_file(z_tmp_proc_tree_file,"w+b");
  
  zq_element.zb_global_declared = TRUE;
  strcpy( zq_element.zb_file, "-----");
  zq_element.zb_defined_at_filepos = 0;
  zq_element.zb_type = Keyword;
  zq_element.zb_first_other_info_struct = zs_ende;

/*                                                   */
/* read all language keywords and put them into queue*/
/*                                                   */


  zq_keyword = fopen(z_src2html_lang_keyword_file, "r");
  if (zq_keyword == NULL) 
  {
    fprintf(stderr, "\nKeyword File %s not found, using default values.\n", 
           z_src2html_lang_keyword_file);

    for (i=0; i<zs_nbr_keywords ; i++)
    {
      strcpy( zq_element.zb_token, keyword[i]);

      q_append_element (zq_tree,
                        &zq_element,
                        sizeof zq_element,
                        &zq_akt_tree_eof);
    }
  }
  else
  {
    while ( (zq_line_length = q_getline ( zq_keyword, zq_line, ZS_MAXLENGTH )) > 0)
    {
      if (*zq_line == ';') continue;      /* skip comment line */
      *(zq_line+zq_line_length-1) = '\0'; /* remove EOL */
      /*printf("zq_line = %s\n", zq_line); */

      strcpy( zq_element.zb_token, zq_line);

      q_append_element (zq_tree,
                        &zq_element,
                        sizeof zq_element,
                        &zq_akt_tree_eof);
    }
    fclose(zq_keyword);
  }


/*                                                   */
/* read all other keywords and put them into queue*/
/*                                                   */
  
  zq_element.zb_type = other_Keyword;
  zq_keyword = fopen(z_src2html_other_keyword_file, "r");
  if (zq_keyword == NULL) 
  {
    fprintf(stderr, "\nKeyword File %s not found, using default values.\n", 
           z_src2html_other_keyword_file);

    for (i=0; i<zs_nbr_other_keywords ; i++)
    {
      strcpy( zq_element.zb_token, zs_other_keyword[i]);

      q_append_element (zq_tree,
                        &zq_element,
                        sizeof zq_element,
                        &zq_akt_tree_eof);
    }
  }
  else
  {
    while ( (zq_line_length = q_getline ( zq_keyword, zq_line, ZS_MAXLENGTH )) > 0)
    {
      if (*zq_line == ';') continue;      /* skip comment line */
      *(zq_line+zq_line_length-1) = '\0'; /* remove EOL */
     
      strcpy( zq_element.zb_token, zq_line);

      q_append_element (zq_tree,
                        &zq_element,
                        sizeof zq_element,
                        &zq_akt_tree_eof);
    }
    fclose(zq_keyword);
  }

/*                                                            */
/* search all other items (procedures, comments, strings...)  */
/* and put them into queue                                    */
/*                                                            */

  do
  {
    if (!(zq_comment_just_ended && 
      q_char_inside(*zq_token, zs_linecomment)))
    {
      zq_lastBut3delimiter = zq_lastBut2delimiter;
      zq_lastBut2delimiter = zq_lastBut1delimiter;
      zq_lastBut1delimiter = *zq_token;
    }
    zq_token = q_get_next_token(zq_source);
    if (++zq_cnt == 20000)
    {
      printf(".\n");
      zq_cnt = 0;
    }   

    if (zq_comment_just_ended)
    {
      if (q_char_inside(*zq_token, zs_linecomment))
      {
        /* don't handle blank, linefeet etc */
        continue;
      }
      /*
	 possible situations:  (X means any char except * or / )
	  zq_token	          == 'X'  ==> Comment ended (1)

	  zq_cpp_comment == TRUE
	     (zq_lastBut1delimiter was set to X at the end of cpp_comment)
	     zq_lastBut1delimiter == '/'
	         zq_token         == '/'  ==> new cpp_comment starts here (2)
	         zq_token	  == '*'  ==> new c_comment starts here	  (3)
	     ---------------------------------	 
	     zq_lastBut1delimiter == 'X'  
	         zq_token         == '/'  ==> get next token (4)
		 zq_token	  != '/'  ==> Comment ended  (9)
	  ------------------------------------
          zq_cpp_comment == FALSE
	     zq_lastBut2delimiter == '*'
	     zq_lastBut1delimiter == '/'       (allways, no check required)
	         zq_token	  == '/'   ==> get next token (5)
		 zq_token	  != '/'   ==> Comment ended  (6)
	     ---------------------------------
	     zq_lastBut3delimiter == '*'       (allways, no check required)
	     zq_lastBut2delimiter == '/'
	     zq_lastBut1delimiter == '/'       (allways, no check required)
		 zq_token	  == '/'   ==> new cpp_comment starts here (7)
		 zq_token	  == '*'   ==> new c_comment starts here   (8)
	     ---------------------------------
      */
      if ((*zq_token != '/') && (*zq_token != '*'))
      {
            /* ==> Comment ended (1)  */
      }
      else
      {
        if (zq_cpp_comment)
        {
          if (zq_lastBut1delimiter == '/')
          {
            /* ==> new cpp_comment starts here (2)       */
            /* ==> new c_comment starts here   (3)       */
	    zq_cpp_comment = (*zq_token == '/');
            zq_comment_just_ended = FALSE;
            continue;
          }
          else
          {
            if (*zq_token == '/')
            {
              /* ==> get next token (4) */
              continue;
            }
            else
            {
              /* ==> Comment ended  (9) */
            }
          }
        }
        else
        {
          if ( zq_lastBut2delimiter == '*' )
          {

            if (*zq_token == '/')
            {
              /* ==> get next token (5) */
              continue;
            }
            else
            {
              /* ==> Comment ended  (6) */
            }
          }
          else  /*  zq_lastBut2delimiter == '/' */
          {
            /* ==> new cpp_comment starts here (7)       */
	    /* ==> new c_comment starts here   (8)       */
            zq_cpp_comment = (*zq_token == '/');
            zq_comment_just_ended = FALSE;
	    continue;
          }
        }
      }
 
      /*****************/
      /* Comment ended */
      /*****************/
      /* insert 1 of the possibly removed delimeters */
      zq_lastBut3delimiter = zq_lastBut2delimiter;
      zq_lastBut2delimiter = zq_lastBut1delimiter;
      zq_lastBut1delimiter = ' '; 
        
      /* store comment end position */ 
      zq_inside_comment = FALSE;
      zq_cpp_comment    = FALSE;

      q_add_other_info_struct (zq_tree,                
                               &zq_other_info_struct,
                               &zq_akt_tree_eof       );
      /*  fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, ===================================zq_inside_comment = FALSE;\n",
                     zq_element.zb_token, zq_inside_comment, zq_inside_string);
      */
    }

    zq_comment_just_ended = FALSE;
    fgetpos(zq_source, &zq_other_info_struct.zb_filepos);

    if (*zq_token !=EOF)
    {
      /************************/
      /* skip char definition */
      /************************/

      if (!zq_inside_comment && !zq_inside_string)
      {
        if (zq_inside_char_def)
        {
          if (
              ( (*zq_token == '\'') && !zq_quoting_active)
                ||( zq_chill_notation     /* in chill we use one or 2 ' after H' or B' */
                  && (q_char_inside(*zq_token, zs_delimiter)
                  && !zq_quoting_active                      )   
              )    
             )
          {

            /* save Char end position */
            if (zq_chill_notation)
              zq_other_info_struct.zb_type = ChillCharEnd;
            else   
              zq_other_info_struct.zb_type = CharEnd; 
                         
            q_add_other_info_struct (zq_tree,                            
                                     &zq_other_info_struct,          
                                     &zq_akt_tree_eof       );

            /* char definition endet */
            zq_inside_char_def = FALSE;
            zq_chill_notation  = FALSE;

            /*   fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, zq_chill_notation=%d, zq_quoting_active=%d ===================================CharEnd\n",
                           zq_token, zq_inside_comment, zq_inside_string, zq_chill_notation, zq_quoting_active); */

            if (*zq_token != '\'')
            {
               /* this was not a real end of char sign, so
                  don't loose a character, read it again */
               fgetpos(zq_source, &zq_filepos);
               --zq_filepos;
               fsetpos(zq_source, &zq_filepos);

            }  
          }
          zq_quoting_active = !zq_quoting_active && (*zq_token == '\\');
          continue;
        }
        else
        {
          if (*zq_token == '\'' )    
          {
            zq_chill_notation =   (zq_lastBut1delimiter == 'B')      /* B'01011100 in chill */
                                   || (zq_lastBut1delimiter == 'H'); /* H'1F in chill */
            /* char definition begint */
            zq_inside_char_def = TRUE;

            /* save Char start position */
            if (zq_chill_notation)
              zq_other_info_struct.zb_type = ChillCharStart;
            else                                                                                               
              zq_other_info_struct.zb_type = CharStart;
                    
            q_add_other_info_struct (zq_tree,                 
                                     &zq_other_info_struct,   
                                     &zq_akt_tree_eof       ); 
                                     
           /*    fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, ===================================CharStart\n",
                           zq_element.zb_token, zq_inside_comment, zq_inside_string);*/

            continue;
          }
        }
      }

      /****************/
      /* skip strings */
      /****************/

      if (!zq_inside_comment)
      {
        if (zq_inside_string)
        {
          if ((*zq_token == '"') && !zq_quoting_active)
          {
            /* String endet */
            zq_inside_string = FALSE;

            /* save String end position */                               
            zq_other_info_struct.zb_type = StringEnd;                    
            q_add_other_info_struct (zq_tree,                              
                                     &zq_other_info_struct,                
                                     &zq_akt_tree_eof       ); 
                                     
            /*  fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, ===================================StringEnd\n",
                           zq_element.zb_token, zq_inside_comment, zq_inside_string);*/
                                                 
          }
          zq_quoting_active = !zq_quoting_active && (*zq_token == '\\');
          continue;
          
        }
        else 
        {
          if (*zq_token == '\"')
          {
            /* String begint */  
            zq_inside_string = TRUE;
            
            /* save String start position */
            zq_other_info_struct.zb_type = StringStart;      
            q_add_other_info_struct (zq_tree,                 
                                     &zq_other_info_struct,   
                                     &zq_akt_tree_eof       );
            /*  fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, ===================================StringStart\n",
                           zq_element.zb_token, zq_inside_comment, zq_inside_string);*/


            continue;
          }
        }  
      }
            
      /******************/
      /* skip Kommentar */
      /******************/

      if (zq_inside_comment)
      {
        if ( (   (*zq_token == '/') 
              && (zq_lastBut1delimiter == '*')
              && !zq_cpp_comment               
             )
            ||
             (   zq_cpp_comment
              && (*zq_token == '\n')
             ) 
           ) 
        {
          /* Kommentar ist zuende */
          zq_comment_just_ended = TRUE; 
	  if (zq_cpp_comment)
	    zq_lastBut1delimiter = 'X';

          /* store comment position */ 
          zq_other_info_struct.zb_type = CommentEnd;
        }
        else
        {
          continue;
        }
      }
      if (  ((*zq_token == '*') && (zq_lastBut1delimiter == '/'))
          ||((*zq_token == '/') && (zq_lastBut1delimiter == '/'))
         )
      {
        /* Kommentar begint */
        zq_inside_comment = TRUE;
        zq_cpp_comment    = *zq_token == '/';

        /* save comment start position */
        if ((zq_lastBut2delimiter != '/')                 
             || (zq_lastBut3delimiter != '*'))
        {
          --zq_other_info_struct.zb_filepos;
          zq_other_info_struct.zb_type = CommentStart;
          q_add_other_info_struct (zq_tree,                
                                   &zq_other_info_struct,
                                   &zq_akt_tree_eof       );

          /* fprintf(zq_log,"token=%s, zq_inside_comment=%d, zq_inside_string=%d, ===================================CommentStart\n",
                         zq_element.zb_token, zq_inside_comment, zq_inside_string); */


        }
        continue;
      }

      /********************/
      /* Klammern pruefen */
      /********************/

      switch (*zq_token )
      {
        case '(': 
          if (!zq_inside_rundeKlammer
              && zq_chill_proc == e_dp_PROC)
          {
            strcpy( zq_element.zb_token, zq_potentielle_proc);
            zq_element.zb_global_declared = !zq_static;
            strcpy( zq_element.zb_file, z_source_file);
            zq_element.zb_defined_at_filepos = zq_token_defined_at_filepos;
            zq_element.zb_type = Procedure;  
            printf("P");
            /*fprintf(zq_log,"=====Echte Chill-Procedure: %s im source at %d \n",
                            zq_potentielle_proc,
                            zq_token_defined_at_filepos);                          */
            q_append_element (zq_tree,
                              &zq_element,
                              sizeof zq_element,
                              &zq_akt_tree_eof);
          }

          ++zq_inside_rundeKlammer; 
          break;
        case ')': --zq_inside_rundeKlammer; 
                  if (!zq_inside_rundeKlammer
                      && !zq_inside_block      )
                    zq_c_proc = e_rundeKlammer;
                  break;
        case '{':
          {
            if (!zq_inside_rundeKlammer
                && !zq_inside_block
                && zq_c_proc == e_rundeKlammer)
            {
              strcpy( zq_element.zb_token, zq_potentielle_proc);
              zq_element.zb_global_declared = !zq_static;
              strcpy( zq_element.zb_file, z_source_file);
              zq_element.zb_defined_at_filepos = zq_token_defined_at_filepos;
              zq_element.zb_type = Procedure;  
              printf("P");
              /*fprintf(zq_log,"=======Echte C-Procedure: %s im source at %d \n",
                              zq_potentielle_proc,
                              zq_token_defined_at_filepos);       */
              q_append_element (zq_tree,
                                &zq_element,
                                sizeof zq_element,
                                &zq_akt_tree_eof);
            }
            ++zq_inside_block;
            zq_static = FALSE;
            break;
          }
        case '}': --zq_inside_block;        break;
        case ':': zq_chill_proc = e_dp;     break;
      }
      if (!zq_inside_rundeKlammer
          && !zq_inside_block
          && !q_char_inside(*zq_token, zs_delimiter))
      {
        zq_static = (strcomp(zq_token, "static")
                     || zq_static               );
        
        if ((strcomp(zq_token, "PROC") 
             || strcomp(zq_token, "INTERFACE_PROC"))
             && zq_chill_proc == e_dp)
        {
          zq_chill_proc  = e_dp_PROC;
        }
        else

        {  
          strcpy(zq_potentielle_proc, zq_token);
          /* fprintf(zq_log,"Wort fuer==potentielle Procedure: %s im source at %d \n",
                              zq_potentielle_proc,
                              zq_token_defined_at_filepos); */

          fgetpos(zq_source, &zq_token_defined_at_filepos);
         zq_chill_proc = zq_c_proc = e_none;
        }
      }

    }

  } while (*zq_token !=EOF);
  /*fclose(zq_log);*/
  fclose(zq_tree);
  fclose(zq_source);
}
/*===========================================================*/

void q_append_element (FILE       *zp_f,
                       zm_element *zp_element,
                       int        zp_size,
                       fpos_t     *zp_akt_tree_eof) {
  fpos_t zq_insert_here = zs_bof;

  zm_element zq_file_element;
  boolean    zq_groesser_gleich = FALSE,
             zq_gleich = FALSE;

  (*zp_element).zb_next_groesser = (*zp_element).zb_next_kleiner = zs_ende;
  if (*zp_akt_tree_eof != zs_bof)
  {  /* File is not empty */
     zq_insert_here = q_get_pos( zp_f,
                                 zp_element,
                                 zp_size,
                                 &(*zp_element).zb_next_groesser,
                                 &zq_groesser_gleich,
                                 &zq_gleich                       );
     fsetpos (zp_f, &zq_insert_here);
     fread   (&zq_file_element, zp_size, 1, zp_f);

     if (zq_groesser_gleich)
       { 
         zq_file_element.zb_next_groesser = *zp_akt_tree_eof;
         /*  fprintf(zq_log, "%s wird rechts (groesser) angehangen an \n", (*zp_element).zb_token); */
       }       
       else
       {
         zq_file_element.zb_next_kleiner = *zp_akt_tree_eof;
         /*  fprintf(zq_log, "%s wird links (kleiner)angehangen an \n", (*zp_element).zb_token);          */
       }  

     /*fprintf(zq_log, "%s pos=>>%d<< \n", zq_file_element.zb_token,
                                         zq_insert_here           );   */

     fsetpos (zp_f, &zq_insert_here);
     fwrite  (&zq_file_element, zp_size, 1, zp_f);
  }
  /*fprintf(zq_log, "%s selbst kommt an pos >>%d<< \n", (*zp_element).zb_token, *zp_akt_tree_eof);  */
  fsetpos (zp_f, zp_akt_tree_eof);
  fwrite   (zp_element, zp_size, 1, zp_f);
  fgetpos (zp_f, zp_akt_tree_eof);
}   

/*===========================================================*/


void q_add_other_info_struct (FILE                 *zp_f,
                              zm_other_info_struct *zp_other_info_struct,
                              fpos_t               *zp_akt_tree_eof) {
                            
  fpos_t zq_insert_here = zs_bof;

  zm_element zq_file_element;
  int zq_element_size = sizeof zq_file_element;
  zm_other_info_struct zq_other_info_struct;
  int zq_struct_size  = sizeof zq_other_info_struct;

  fsetpos (zp_f, &zq_insert_here);
  fread   (&zq_file_element, zq_element_size, 1, zp_f);
  
  if (zq_file_element.zb_first_other_info_struct == zs_ende)
  {  /* First other_info_struct */
     
     zq_file_element.zb_first_other_info_struct = *zp_akt_tree_eof;

     fsetpos (zp_f, &zq_insert_here);
     fwrite  (&zq_file_element, zq_element_size, 1, zp_f);
  }
  else
  { /* other_info_struct exist */
    zq_insert_here = zq_file_element.zb_first_other_info_struct;
    do
    {
      fsetpos (zp_f, &zq_insert_here);
      fread   (&zq_other_info_struct, zq_struct_size, 1, zp_f);
      if (zq_other_info_struct.zb_next_other_info_struct != zs_ende)
        zq_insert_here = zq_other_info_struct.zb_next_other_info_struct;
    } while ( zq_other_info_struct.zb_next_other_info_struct != zs_ende);
    zq_other_info_struct.zb_next_other_info_struct = *zp_akt_tree_eof;
    
    fsetpos (zp_f, &zq_insert_here);
    fwrite  (&zq_other_info_struct, zq_struct_size, 1, zp_f);
  }
  zp_other_info_struct->zb_next_other_info_struct = zs_ende;
  fsetpos (zp_f, zp_akt_tree_eof);
  fwrite   (zp_other_info_struct, zq_struct_size, 1, zp_f);
  fgetpos (zp_f, zp_akt_tree_eof);
}   

/*===========================================================*/

fpos_t get_next_info_struct (FILE   *zp_tree,
                             fpos_t zp_last_pos){
  
  zm_element zq_file_element;
  int zq_element_size = sizeof zq_file_element;
  zm_other_info_struct zq_other_info_struct;
  int zq_struct_size  = sizeof zq_other_info_struct;  
    
  if (zp_last_pos == 0) {
    fsetpos (zp_tree, &zp_last_pos);
    fread   (&zq_file_element, zq_element_size, 1, zp_tree); 
    return zq_file_element.zb_first_other_info_struct;
  }

  fsetpos (zp_tree, &zp_last_pos);
  fread   (&zq_other_info_struct, zq_struct_size, 1, zp_tree);    
  return zq_other_info_struct.zb_next_other_info_struct;

}

/*===========================================================*/

int q_check_for_stored_pos (FILE   *zp_tree,
                               FILE   *zp_source ) {
                                  
  fpos_t zq_insert_here = zs_bof,
         zq_source_pos;
  zm_element zq_file_element;
  int zq_element_size = sizeof zq_file_element;
  zm_other_info_struct zq_other_info_struct;
  int zq_struct_size  = sizeof zq_other_info_struct;  

  fgetpos (zp_source, &zq_source_pos);
  fsetpos (zp_tree, &zq_insert_here);
  fread   (&zq_file_element, zq_element_size, 1, zp_tree);
  
  if ((zq_insert_here = zq_file_element.zb_first_other_info_struct) != zs_ende)
  { /* other_info_struct exist */
    do
    {
      fsetpos (zp_tree, &zq_insert_here);
      fread   (&zq_other_info_struct, zq_struct_size, 1, zp_tree);
      zq_insert_here = zq_other_info_struct.zb_next_other_info_struct;
      if (zq_other_info_struct.zb_filepos == zq_source_pos) 
      { /*fprintf(zq_log, "Type gefunden %d", zq_other_info_struct.zb_type ); */
        return zq_other_info_struct.zb_type;
      }
    } while (zq_other_info_struct.zb_next_other_info_struct != zs_ende);
  }  
  return NotInList;                                 
}                                

/*===========================================================*/

fpos_t q_get_pos( FILE *zp_f,
                  zm_element *zp_new_element,
                  int        zp_size,
                  fpos_t     *zp_search_tree_pos,
                  boolean    *zp_groesser_gleich,
                  boolean    *zp_gleich) {    /* bricht bei Gleichheit ab, Ergebnis wird richtig zurueckgegeben */

  zm_element zq_file_element;
  fpos_t zq_next        = 0,
   zq_insert_here = *zp_search_tree_pos;
  *zp_gleich = FALSE;

  do
  {
    fsetpos (zp_f, &zq_next);
    fread   (&zq_file_element, zp_size, 1, zp_f);
    /* fprintf(zq_log, "====>>> %s erreicht beim suchen \n", zq_file_element.zb_token); */

    if (q_abc_cmp( zq_file_element.zb_token, (*zp_new_element).zb_token)) 
    {
      /* zq_file_element >= zp_new_element */
      /* also bei kleiner anhaengen        */
      zq_insert_here = zq_next;
      zq_next = zq_file_element.zb_next_kleiner;
      *zp_groesser_gleich = FALSE;
      if ((*zp_gleich = strcomp( zq_file_element.zb_token, (*zp_new_element).zb_token)) == TRUE)
        return zq_insert_here;
    }
    else
    {
       /* zq_file_element < zp_new_element */
       /* also bei groesser anhaengen      */
      zq_insert_here = zq_next;
      zq_next = zq_file_element.zb_next_groesser;
      *zp_groesser_gleich = TRUE;
    }
  } while (zq_next != zs_ende);

return zq_insert_here;
}

/*===========================================================*/

int q_abc_cmp (char *s, char *t) {
  /* return true if s >= t */
  while ((*s++ == *t++) && (*s != 0));

  return ((*--s - *--t) >= 0) ? TRUE : FALSE;
}

/*===========================================================*/

void q_get_parameter(int zp_argc, char *zp_argv[]) {

char *zq_pt;

  switch (zp_argc) {
    case (2): break; /* ok, nothing to do */
    case (3): break; /* ok, nothing to do */
    default: {
      fprintf(stderr,"%s",zs_help);
      fprintf(stderr,"%s%s%s","\nsrc2html Vers. ",zs_version,"\n");
      exit (1);
    }
  }
  strcpy(z_source_file,        zp_argv[1]);
  strcpy(z_html_file,          zp_argv[zp_argc - 1]);
  strcpy(z_html_fileLeftFrame, zp_argv[zp_argc - 1]);
  strcpy(z_html_fileFrameDef,  zp_argv[zp_argc - 1]);

  if ((zq_pt = strchr(z_html_fileFrameDef, '.')) != 0)
  {  
    strcpy(zq_pt, ".htm");
    zq_pt = strchr(z_html_fileLeftFrame, '.');
    strcpy(zq_pt, "lf.htm");
    zq_pt = strchr(z_html_file, '.');
    strcpy(zq_pt, "src.htm");
  }   
  else
  { 
    strcat(z_html_fileFrameDef,    ".htm");
    strcat(z_html_file,         "src.htm");
    strcat(z_html_fileLeftFrame, "lf.htm");
  }
 /* printf("%s = z_html_fileFrameDef\n%s = z_html_file\n%s = z_html_fileLeftFrame\n", 
               z_html_fileFrameDef,      z_html_file,      z_html_fileLeftFrame);
  */
  printf("Converting %s to %s", z_source_file, z_html_fileFrameDef);

  if ((zq_pt = strrchr(z_html_fileFrameDef, '/')) != 0)
  {
    strncpy(z_html_filePath, 
            z_html_fileFrameDef, 
            ++zq_pt - z_html_fileFrameDef); 
    strcpy(z_html_fileFrameDef, zq_pt);
    zq_pt = strrchr(z_html_file, '/');
    strcpy(z_html_file, ++zq_pt);
    zq_pt = strrchr(z_html_fileLeftFrame, '/');
    strcpy(z_html_fileLeftFrame, ++zq_pt);
  }

/*
 printf("\n%s = z_html_fileFrameDef\n"
        "%s = z_html_file\n"
        "%s = z_html_fileLeftFrame\n"
        "%s = z_html_filePath\n", 
               z_html_fileFrameDef,      
               z_html_file,      
               z_html_fileLeftFrame, 
               z_html_filePath);

*/  

}

/*===========================================================*/

int main (int zp_argc, char *zp_argv[]) {
  q_get_parameter(zp_argc, zp_argv);
  q_fetch_init_file();

  printf("%s",zs_help3);
  q_create_fileFrameDef();
  searchAllProcedures();
  q_insert_html_links();
  return 0;
}

/*===========================================================*/

FILE* q_open_file (char* zp_filename, char* zp_access) {
  FILE* zq_filehandle;
  
  if ((zq_filehandle = fopen(zp_filename, zp_access)) == NULL)
  {  
    fprintf(stderr, "Error: File %s open for %s\n", zp_filename, zp_access);
    exit(1);
  }  

  return zq_filehandle;
}

/*===========================================================*/
 
int q_char_inside(char c, char* p) {
  while ((*p != c) && (*p != '\0'))
    ++p;
  return *p;  /* return true wenn c im String auf den p zeigt enthalten ist */
}

/*===========================================================*/

char* q_get_next_token(FILE* zp_filehandle) 
{
  int c;
  char* p = zs_token_buffer;
  fpos_t zq_filepos;
  
  *p = '\0';
  do
    {
      if ((p - zs_token_buffer) == ZS_CHAR_QUEUE_LENGTH)
        p--;  /* Buffer full, so lange Prozedur Namen gibts sowieso nicht, Name wird abgeschnitten */
      *p++ = c = getc(zp_filehandle);
    }
  while((c!=EOF) && !q_char_inside(c, zs_delimiter) );

  *p = '\0';  /* String Ende eintragen */

  if (c!=EOF && (!q_char_inside(*zs_token_buffer, zs_delimiter)))
    {
      /* delimiter hinter token gefunden */
      /* delimiter wieder entfernen      */

      *--p = '\0';  /* String Ende eintragen */

      fgetpos(zp_filehandle, &zq_filepos);
      --zq_filepos;
      fsetpos(zp_filehandle, &zq_filepos);
      /*ungetc(c, zp_filehandle);                       */
      /* unget is not working sometimes, don't know why.*/
      /* so unget is done by using fsetpos              */
    }

  return zs_token_buffer;
}

/*===========================================================*/
int strcomp (char* s, char* t)
{
  while ((*s++ == *t++) && (*t != 0));
  return !(*s + *t + (*(s-1) - *(t-1)));
}

Converted with src2html Vers. 0.1f