Esempio n. 1
0
int	NavHelp::help_index( navh_eHelpFile file_type, const char *file_name)
{
  FILE	*file;
  char	line[200];
  char	include_file[80];
  char	subject[80];
  int 	sts;
  char  *s;
  lng_eCoding coding = lng_eCoding_ISO8859_1;

  // Open file
  file = navhelp_open_file( this, file_type, file_name);
  if ( !file) return NAV__NOFILE;

  sts = dcli_read_line( line, sizeof( line), file);
  while ( ODD(sts))
  {
    if ( cdh_NoCaseStrncmp( line, "<coding>", 8) == 0) {      
      char codingstr[40];

      help_remove_spaces( &line[8], codingstr);
      if ( cdh_NoCaseStrcmp( codingstr, "ISO8859-1") == 0) {
	coding = lng_eCoding_ISO8859_1;
      }
      else if ( cdh_NoCaseStrcmp( codingstr, "UTF-8") == 0) {
	coding = lng_eCoding_UTF_8;
      }
    }
    else if ( cdh_NoCaseStrncmp( line, "<include>", 9) == 0)
    {
      help_remove_spaces( &line[9], include_file);
      sts = help_index( navh_eHelpFile_Other, include_file);
    }
    else if ( cdh_NoCaseStrncmp( line, "<topic>", 7) == 0)
    {
      if ( (s = strstr( line, "<style>")) || (s = strstr( line, "<STYLE>")))
	*s = 0;
      help_remove_spaces( &line[7], subject);

      (insert_cb)( parent_ctx, navh_eItemType_HelpBold,
		   subject,  "", "", subject, 
		   "", file_name, file_type, 0, NULL, coding);
    }
    sts = dcli_read_line( line, sizeof( line), file);
  }
  fclose( file);
  return NAV__SUCCESS;
}
Esempio n. 2
0
void wb_nrep::parse () throw (wb_error)
{
  int state = 0;
  char *s, *snn;

  snn = norm_name;

  if (oname[0] == '_') { 
    // This is an identity name.
    for ( s = oname; *s; s++, snn++) {
      if (idname_tab[*(unsigned char *)s] == '!')
        throw wb_error(LDH__BADNAME);
      else if (idname_tab[*(unsigned char *)s] == '^')
        *snn = *s - 32;
      else
        *snn = idname_tab[*(unsigned char *)s];

      if ( s == oname)
        continue;
      if ( s == oname + 1) {
        switch ( *s) {
        case 'V':
          name_type = wname_eType_Vid;
          continue;
        case 'O':
          name_type = wname_eType_Oid;
          continue;
        case 'A':
          name_type = wname_eType_Aid;
          continue;
        default:
          throw wb_error(LDH__BADNAME);
        }
      }

      /* States
         0: before ':'
         1: before '('
         2: before ')'
         3: attribute before '['
         4: attribute index before ']'
         5: attribute after  ']'
         6: offset.size before '.'
         7: offset.size before ']'
         8: offset.size after  ']'  */

      switch (state) {

      case 0:	// before ':'
        if ( *s == ':') {
          if ( s == oname)
            throw wb_error(LDH__BADNAME);
          vol_offs = 2;
          vol_len = nameDiff( s, oname) - vol_offs;
          seg[0].offs = nameDiff( s + 1, oname);
          state = 1;
        } else if (*s == '(' || *s == ')' || *s == '[' || *s == ']') {
          throw wb_error(LDH__BADNAME);
        }
        break;
      case 1:	// before '('
        if ( *s == '(') {
          if ( nameDiff( s, oname) == seg[0].offs)
            throw wb_error(LDH__BADNAME);
          seg[1].offs = nameDiff( s + 1, oname);
          seg[0].len = nameDiff( s, oname) - seg[0].offs;
          num_seg++;
          state = 2;
        } else if (*s == ')' || *s == '[' || *s == ']') {
          throw wb_error(LDH__BADNAME);
        }
        break;
      case 2:	// before ')'
        if (*s == ')') {
          if ( nameDiff( s, oname) == seg[1].offs)
            throw wb_error(LDH__BADNAME);
          attr[0].offs = nameDiff( s + 1, oname);
          seg[1].len = nameDiff( s, oname) - seg[1].offs;
          num_seg++;
          state = 3;
        } else if (*s == '[' || *s == ']') {
          throw wb_error(LDH__BADNAME);
        }  
        break;
      case 3:	// after ')'
        if (*s == '[') {
          if ( nameDiff( s, oname) == seg[1].offs + seg[1].len + 1) {
            // offset.size
            state = 7;	      
          }
        } else if ( *s == ']' || *s == '.') {
          throw wb_error(LDH__BADNAME);
        } else {
          attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
          attr[num_attr].index = -1;
          state = 4;
        }
        break;
      case 4:	// attribute before '['
        if (*s == '.') {
          if ( nameDiff( s, oname) == attr[num_attr].offs)
            throw wb_error(LDH__BADNAME);
          attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
          num_attr++;
          attr[num_attr].offs = nameDiff( s + 1, oname);
          state = 4;
        } else if (*s == '[') {
          attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
          attr[num_attr].index = 0;
          state = 5;
        }
        break;
      case 5:	// attribute index before ']'
        if (*s == ']') {
          num_attr++;
          state = 6;
        } else if ((*s < '0') || (*s > '9')) {
          throw wb_error(LDH__BADNAME);
        } else {
          attr[num_attr].index = attr[num_attr].index * 10 + (*s - '0');
          if (attr[num_attr].index > 65535) throw wb_error(LDH__BADNAME);
        }
        break;
      case 6:	// attribute after ']', '.' or nothing
        if ( *s == '.') {
          attr[num_attr].offs = nameDiff( s + 1, oname);
          state = 4;
        }
        else
          throw wb_error(LDH__BADNAME);
        break;
      case 7:	// offset.size before '.'
        if (*s == '.') {
          b_size = 0;
          state = 8;
        } else if (*s == ']') {
          throw wb_error(LDH__BADNAME);
        } else {
          if ((*s < '0') || (*s > '9')) {
            throw wb_error(LDH__BADNAME);
          } else {
            b_offset = b_offset * 10 + (*s - '0');
            if (b_offset > 65535) throw wb_error(LDH__BADNAME);
          }
        }
        break;
      case 8:	// offset.size before ']'
        if (*s == ']') {
          state = 9;
        } else if ((*s < '0') || (*s > '9')) {
          throw wb_error(LDH__BADNAME);
        } else {
          b_size = b_size * 10 + (*s - '0');
          if (b_size > 65535) throw wb_error(LDH__BADNAME);
        }
        break;
      case 9:	// offset.size after ']', must be nothing there!
        throw wb_error(LDH__BADNAME);
        break;
      }
    }

    switch ( state) {
    case 0:
      if ( s == oname) 
        throw wb_error(LDH__BADNAME);  // No segment name
      vol_len = nameDiff( s, oname);
      break;
    case 1:
      if ( nameDiff( s, oname) == seg[num_seg].offs)
        throw wb_error(LDH__BADNAME);
      if ( nameDiff( s, oname)  - (vol_len + 1) == 0)
        break;
      seg[num_seg].len = nameDiff( s, oname) - seg[num_seg].offs;
      if ( seg[num_seg].len)
        num_seg++;
      break;
    case 4:
      if ( nameDiff( s, oname) == attr[num_attr].offs)
        throw wb_error(LDH__BADNAME);
      attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
      if ( attr[num_attr].len)
        num_attr++;
      break;
    case 2:
    case 3:
    case 5:
    case 7:
    case 8:
      throw wb_error(LDH__BADNAME);
    default:
      ;
    }

    *snn = 0;
  }
  else {

    for ( s = oname; *s; s++, snn++) {
      if (normname_tab[*(unsigned char *)s] == '!')
        throw wb_error(LDH__BADNAME);
      else if (normname_tab[*(unsigned char *)s] == '^')
        *snn = *s - 32;
      else
        *snn = normname_tab[*(unsigned char *)s];

      /* States
         0: before ':'
         1: before '.'
         2: before '['
         3: before ']'
         4: after  ']'  */

      switch (state) {
      case 0:	// before ':'
        if ( *s == ':') {
          if ( s == oname) 
            throw wb_error(LDH__BADNAME);  // No volume name
          vol_len = nameDiff( s, oname);
          if ( *(s+1))
            seg[0].offs = nameDiff(s+1, oname);
          state = 1;
        } else if ( *s == '-') {
          if ( s == oname) 
            throw wb_error(LDH__BADNAME);  // No segment name
          seg[0].offs = 0;
          seg[0].len = nameDiff( s, oname);
          num_seg++;
          seg[1].offs = nameDiff( s+1, oname);
          state = 1;
        } else if ( *s == '.') {
          if ( s != oname) {
            seg[0].offs = 0;
            seg[0].len = nameDiff( s, oname);
            num_seg++;
          }
          attr[0].offs = nameDiff( s+1, oname);
          state = 2;
        }
        else if ( *s == '[' || *s == ']')
          throw wb_error(LDH__BADNAME);
        break;
      case 1:	// before '.'
        if ( *s == '-') {
          if ( nameDiff( s, oname) == seg[num_seg].offs)
            throw wb_error(LDH__BADNAME);
          seg[num_seg+1].offs = nameDiff( s+1, oname);
          seg[num_seg].len = seg[num_seg+1].offs - seg[num_seg].offs - 1;
          num_seg++;
        } else if ( *s == '.') {
          // if ( nameDiff( s, oname) == seg[num_seg].offs) // Could be volume object !!
          //   throw wb_error(LDH__BADNAME);
          attr[0].offs = nameDiff( s+1, oname);
          seg[num_seg].len = attr[0].offs - seg[num_seg].offs - 1;
          num_seg++;
          state = 2;
        }
        break;
      case 2:	// before '['
        if ( *s == '.') {
          if ( nameDiff( s, oname) == attr[num_attr].offs)
            throw wb_error(LDH__BADNAME);
          attr[num_attr+1].offs = nameDiff( s+1, oname);
          attr[num_attr].len = attr[num_attr+1].offs - attr[num_attr].offs - 1;
	  if ( attr[num_attr].len == 5 && 
	       cdh_NoCaseStrncmp( oname + attr[num_attr].offs, "Super", 5) == 0) {
	    attr[num_attr].isSuper = true;
	    m_hasSuper = true;
	  }
          num_attr++;
        }
        else if ( *s == '[') {
          if ( nameDiff( s, oname) == attr[num_attr].offs)
            throw wb_error(LDH__BADNAME);
          attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
          attr[num_attr].index = 0;
          state = 3;
        }
        break;
      case 3:	/* within brackets */
        if (*s == ']') {
          num_attr++;
          state = 4;
        } else if ((*s < '0') || (*s > '9')) {
          throw wb_error(LDH__BADNAME);
        } else {
          attr[num_attr].index = attr[num_attr].index * 10 + (*s - '0');
          if (attr[num_attr].index > 65535) throw wb_error(LDH__BADNAME);
        }
        break;
      case 4:	// after brackets
        if ( *s == '.') {
          attr[num_attr].offs = nameDiff( s+1, oname);
          state = 2;
        }
        else
          throw wb_error(LDH__BADNAME);
        break;
      }
    }

    switch ( state) {
    case 0:
      if ( s == oname) 
        throw wb_error(LDH__BADNAME);  // No segment name
      seg[0].offs = 0;
      seg[0].len = nameDiff( s, oname);
      if ( seg[0].len > pwr_cSizObjName)
	throw wb_error(LDH__BADNAME);
      num_seg++;
      break;
    case 1:
      if ( nameDiff( s, oname) == seg[num_seg].offs)
        throw wb_error(LDH__BADNAME);
      if ( nameDiff( s, oname)  - (vol_len + 1) == 0)
        break;
      seg[num_seg].len = nameDiff( s, oname) - seg[num_seg].offs;
      if ( seg[num_seg].len > pwr_cSizObjName)
	throw wb_error(LDH__BADNAME);
      if ( seg[num_seg].len)
        num_seg++;
      break;
    case 2:
      if ( nameDiff( s, oname) == attr[num_attr].offs)
        throw wb_error(LDH__BADNAME);
      attr[num_attr].len = nameDiff( s, oname) - attr[num_attr].offs;
      if ( attr[num_attr].len)
        num_attr++;
      break;
    case 3:
      throw wb_error(LDH__BADNAME);
    case 4:
      break;
    }
    *snn = 0;
  }
}
Esempio n. 3
0
int	NavHelp::help( const char *help_key, const char *help_bookmark, 
		       navh_eHelpFile file_type, const char *file_name, void **book_mark,
		       bool strict)
{
  FILE	*file;
  char	line[200];
  char	text1[200];
  char	text2[200];
  char	text3[200];
  char	key[80];
  char	key_part[4][40];
  char	include_file[80];
  char	subject[80];
  char	subject_part[4][40];
  int	key_nr;
  int	subject_nr;
  int	hit = 0;
  int 	sts;
  int	i;  
  char	link[200];
  char	link_bookmark[80];
  char	link_filename[80];
  char	*link_filename_p;
  int	link_nr;
  char	link_part[4][200];
  char	bookmark[80];
  char	search_bookmark[80];
  char	*s;
  int	header1;
  int	header2;
  int	bold;
  int	code;
  int	horizontal_line;
  int	style = 0;
  char  style_str[80];
  int   image;
  char  imagefile[80];
  int	register_bookmark = 0;
  int	bookmark_found = 0;
  void  *bookmark_node = 0;
  int   index_link;
  void  *node;
  int   print_all;
  char  *bookmark_p;
  lng_eCoding coding = lng_eCoding_ISO8859_1;

  print_all = (help_key == NULL);
  if ( help_key) {
    cdh_ToLower( key, help_key);
    cdh_ToLower( search_bookmark, help_bookmark);
  }

  // Open file
  file = navhelp_open_file( this, file_type, file_name);
  if ( !file) return NAV__NOFILE;
	
  if ( !print_all)
    key_nr = dcli_parse( key, " 	", "", (char *)key_part,
			 sizeof( key_part) / sizeof( key_part[0]), 
			 sizeof( key_part[0]), 0);


  sts = dcli_read_line( line, sizeof( line), file);
  while ( ODD(sts)) {
    if ( cdh_NoCaseStrncmp( line, "<coding>", 8) == 0) {      
      char codingstr[40];

      help_remove_spaces( &line[8], codingstr);
      if ( cdh_NoCaseStrcmp( codingstr, "ISO8859-1") == 0) {
	coding = lng_eCoding_ISO8859_1;
      }
      else if ( cdh_NoCaseStrcmp( codingstr, "UTF-8") == 0) {
	coding = lng_eCoding_UTF_8;
      }
    }
    else if ( cdh_NoCaseStrncmp( line, "<include>", 9) == 0) {      
      help_remove_spaces( &line[9], include_file);

      if ( !noprop || strstr( include_file, "$pwr_lang") == 0) {
	sts = help( help_key, help_bookmark, navh_eHelpFile_Other, 
		    include_file, book_mark, strict);
	if ( ODD(sts) && !print_all) {
	  fclose( file);
	  return sts;
	}
      }

      hit = 0;
    }
    else if ( cdh_NoCaseStrncmp( line, "<chapter>", 9) == 0) {      
      (insert_cb)( parent_ctx, navh_eItemType_Chapter, "",
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "</chapter>", 10) == 0) {
      (insert_cb)( parent_ctx, navh_eItemType_EndChapter, "",
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "<headerlevel>", 13) == 0) {
      (insert_cb)( parent_ctx, navh_eItemType_HeaderLevel, "",
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "</headerlevel>", 14) == 0) {
      (insert_cb)( parent_ctx, navh_eItemType_EndHeaderLevel, "",
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "<pagebreak>", 11) == 0) {
      (insert_cb)( parent_ctx, navh_eItemType_PageBreak, "",
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "<option>", 8) == 0) {
      char option[80];

      help_remove_spaces( &line[8], option);
      cdh_ToLower( option, option);
      (insert_cb)( parent_ctx, navh_eItemType_Option, option,
		   NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
    }
    else if ( cdh_NoCaseStrncmp( line, "<topic>", 7) == 0) {
      if ( (s = strstr( line, "<style>")) || (s = strstr( line, "<STYLE>"))) {
	style = 1;
	help_remove_spaces( s + 7, style_str);
	*s = 0;
      }

      help_remove_spaces( &line[7], subject);
      cdh_ToLower( subject, subject);
      subject_nr = dcli_parse( subject, " 	", "", (char *)subject_part,
                	sizeof( subject_part) / sizeof( subject_part[0]),
			sizeof( subject_part[0]), 0);
      hit = 0;
      if ( !print_all) {
        if ( key_nr == subject_nr ) {
          for ( i = 0; i < key_nr; i++) {
            if ( (!strict && strncmp( subject_part[i], key_part[i], strlen(key_part[i])) == 0) ||
		 (strict && strcmp( subject_part[i], key_part[i]) == 0)) {
              if ( i == key_nr - 1)
                hit = 1;
            }
            else
              break;
          }
        }
      }
      else {
	if ( cdh_NoCaseStrcmp( subject_part[0], "__documenttitlepage") == 0)
	  (insert_cb)( parent_ctx, navh_eItemType_DocTitlePage, subject,
		       NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
	else if ( cdh_NoCaseStrcmp( subject_part[0], "__documentinfopage") == 0)
	  (insert_cb)( parent_ctx, navh_eItemType_DocInfoPage, subject,
		       NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
	else
	  (insert_cb)( parent_ctx, navh_eItemType_Topic, subject,
		       NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
	if ( style)
	  node = (insert_cb)( parent_ctx, navh_eItemType_Style, style_str,
		      NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
        hit = 1;
      }
    }
    if ( hit)
    {
      sts = dcli_read_line( line, sizeof( line), file);
      (insert_cb)( parent_ctx, navh_eItemType_HelpHeader, line, NULL, NULL, 
		 NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
      sts = dcli_read_line( line, sizeof( line), file);
      while( ODD(sts))
      {
        bookmark_p = 0;

        if ( strncmp( line, "</topic>", 8) == 0 ||
             strncmp( line, "</TOPIC>", 8) == 0) {
          if ( print_all)
            (insert_cb)( parent_ctx, navh_eItemType_EndTopic, subject,
		      NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
          break;
        }

	// Ignore all other tags
        if ( (s = strstr( line, "<ib>")) || (s = strstr( line, "<IB>"))) {
	  strcpy( text1, s + 4);
          (insert_cb)( parent_ctx, navh_eItemType_HelpBold, 
			    text1,  "", "", "", "", NULL, file_type, 0, NULL, coding);
          sts = dcli_read_line( line, sizeof( line), file);
          continue;
	}
        if ( (s = strstr( line, "<i>")) || (s = strstr( line, "<I>"))) {
	  strcpy( text1, s + 3);
          (insert_cb)( parent_ctx, navh_eItemType_Help, text1,  "", "", "", 
		"", NULL, file_type, 0, bookmark_p, coding);
          sts = dcli_read_line( line, sizeof( line), file);
          continue;
	}
	if ( cdh_NoCaseStrncmp( line, "<option>", 8) == 0) {
	  char option[80];

	  help_remove_spaces( &line[8], option);
	  cdh_ToLower( option, option);
	  (insert_cb)( parent_ctx, navh_eItemType_Option, option,
		      NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
          sts = dcli_read_line( line, sizeof( line), file);
          continue;
	}

        if ( (s = strstr( line, "<link>")) || (s = strstr( line, "<LINK>")))
	{
          help_remove_spaces( s + 6, link);
	  *s = 0;

          link_nr = dcli_parse( link, ",", "", (char *)link_part,
                	sizeof( link_part) / sizeof( link_part[0]),
			sizeof( link_part[0]), 0);
          if ( link_nr == 1)
	  {
	    help_remove_spaces( link_part[0], link);
            strcpy( link_bookmark, "");
            link_filename_p = (char *)file_name;
	  }
          else if ( link_nr == 2)
	  {
	    help_remove_spaces( link_part[0], link);
	    help_remove_spaces( link_part[1], link_bookmark);
            link_filename_p = (char *)file_name;
          }
          else if ( link_nr > 2)
	  {
	    help_remove_spaces( link_part[0], link);
	    help_remove_spaces( link_part[1], link_bookmark);
	    help_remove_spaces( link_part[2], link_filename);
            link_filename_p = link_filename;
          }
	}
        else if ( (s = strstr( line, "<weblink>")) || (s = strstr( line, "<WEBLINK>")))
	{
          help_remove_spaces( s + 9, link);
	  *s = 0;

          link_nr = dcli_parse( link, ",", "", (char *)link_part,
                	sizeof( link_part) / sizeof( link_part[0]),
			sizeof( link_part[0]), 0);
          if ( link_nr == 1)
	  {
	    strcpy( link, "$web:");
	    help_remove_spaces( link_part[0], &link[5]);
            strcpy( link_bookmark, "");
            link_filename_p = (char *)file_name;
	  }
          else if ( link_nr == 2)
	  {
	    strcpy( link, "$web:");
	    help_remove_spaces( link_part[0], &link[5]);
	    help_remove_spaces( link_part[1], link_bookmark);
            link_filename_p = (char *)file_name;
          }
          else if ( link_nr > 2)
	  {
	    strcpy( link, "$web:");
	    help_remove_spaces( link_part[0], &link[5]);
	    help_remove_spaces( link_part[1], link_bookmark);
	    help_remove_spaces( link_part[2], link_filename);
            link_filename_p = link_filename;
          }
	}
        else if ( (s = strstr( line, "<classlink>")) || (s = strstr( line, "<CLASSLINK>")))
	{
          help_remove_spaces( s + 11, link);
	  *s = 0;

          link_nr = dcli_parse( link, ",", "", (char *)link_part,
                	sizeof( link_part) / sizeof( link_part[0]),
			sizeof( link_part[0]), 0);
          if ( link_nr == 1)
	  {
	    strcpy( link, "$class:");
	    help_remove_spaces( link_part[0], &link[7]);
            strcpy( link_bookmark, "");
            link_filename_p = (char *)file_name;
	  }
          else if ( link_nr == 2)
	  {
	    strcpy( link, "$class:");
	    help_remove_spaces( link_part[0], &link[7]);
	    help_remove_spaces( link_part[1], link_bookmark);
            link_filename_p = (char *)file_name;
          }
          else if ( link_nr > 2)
	  {
	    strcpy( link, "$class:");
	    help_remove_spaces( link_part[0], &link[7]);
	    help_remove_spaces( link_part[1], link_bookmark);
	    help_remove_spaces( link_part[2], link_filename);
            link_filename_p = link_filename;
          }
	}
        else
	{
          strcpy( link, "");
          strcpy( link_bookmark, "");
          link_filename_p = link_filename;
	}

        if ( (s = strstr( line, "<bookmark>")) || (s = strstr( line, "<BOOKMARK>")))
	{
          help_remove_spaces( s + 10, bookmark);
	  *s = 0;
	  cdh_ToLower( bookmark, bookmark);
          if ( !bookmark_found && !print_all &&
	       strcmp( search_bookmark, bookmark) == 0)
	  {
            bookmark_found = 1;
	    register_bookmark = 1;
	  }
          if ( print_all)
	    bookmark_p = bookmark;
	}

        if ( (s = strstr( line, "<index>")) || (s = strstr( line, "<INDEX>")))
        {
	  index_link = 1;
          *s = 0;
	}
        else
          index_link = 0;

	image = 0;
        header1 = 0;
        header2 = 0;
        bold = 0;
	code = 0;
	horizontal_line = 0;
	style = 0;
        if ( (s = strstr( line, "<h1>")) || (s = strstr( line, "<H1>")))
        {
          header1 = 1;
          strcpy( text1, s + 4);
        }
        else if ( (s = strstr( line, "<h2>")) || (s = strstr( line, "<H2>")))
        {
          header2 = 1;
          strcpy( text1, s + 4);
        }
        else if ( (s = strstr( line, "<b>")) || (s = strstr( line, "<B>")))
        {
          bold = 1;
          strcpy( text1, s + 3);
        }
        else if ( (s = strstr( line, "<c>")) || (s = strstr( line, "<C>")))
        {
          code = 1;
          strcpy( text1, s + 3);
        }
        else if ( (s = strstr( line, "<hr>")) || (s = strstr( line, "<HR>")))
        {
          horizontal_line = 1;
        }
        else if ( (s = strstr( line, "<image>")) || (s = strstr( line, "<IMAGE>")))
	{
          help_remove_spaces( s + 7, imagefile);
          image = 1;
	}

        else
        {
          strcpy( text1, line);
        }

        if ( (s = strstr( text1, "<t>")) || (s = strstr( text1, "<T>")) )
	{
          strcpy( text2, s + 3);
	  *s = 0;
          if ( (s = strstr( text2, "<t>")) || (s = strstr( text2, "<T>")) )
	  {
            strcpy( text3, s + 3);
	    *s = 0;
	  }
          else
            strcpy( text3, "");
	}
        else
        {
          strcpy( text2, "");
          strcpy( text3, "");
        }
        if ( header1)
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_HeaderLarge,
			      text1, NULL, NULL, NULL, NULL, NULL,
			      navh_eHelpFile_, 0, bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
        else if ( header2)
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_Header, text1,
			      NULL, NULL, NULL, NULL, NULL, 
			      navh_eHelpFile_, 0, bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
	else if ( bold)
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_HelpBold, text1, 
		text2, text3, link, 
		link_bookmark, link_filename_p, file_type, index_link,
		bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
	else if ( code)
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_HelpCode, text1, 
		text2, text3, link, 
		link_bookmark, link_filename_p, file_type, index_link,
		bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
	else if ( horizontal_line) {
	  node = (insert_cb)( parent_ctx, navh_eItemType_HorizontalLine, NULL,
		      NULL, NULL, NULL, NULL, NULL, navh_eHelpFile_, 0, NULL, coding);
	}
        else if ( image)
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_Image,
			      imagefile, NULL, NULL, link, 
			      link_bookmark, link_filename_p, file_type, index_link,
			      bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
	else
	{
          node = (insert_cb)( parent_ctx, navh_eItemType_Help, text1,  text2,
		text3, link, 
		link_bookmark, link_filename_p, file_type, index_link,
		bookmark_p, coding);
	  if ( register_bookmark)
	  {
	    bookmark_node = node;
	    register_bookmark = 0;
	  }
	}
        sts = dcli_read_line( line, sizeof( line), file);
      }

      if ( bookmark_found)
        *book_mark = bookmark_node;
      else
        *book_mark = 0;
      if ( !print_all)
        break;
      else
        hit = 0;
    }
    sts = dcli_read_line( line, sizeof( line), file);
  }
  fclose( file);

  if ( !print_all && !hit)
    return NAV__TOPICNOTFOUND;
  return NAV__SUCCESS;
}
Esempio n. 4
0
int	NavHelp::get_previous_key( const char *help_key, navh_eHelpFile file_type, const char *file_name,
				   bool strict, char *prev_key)
{
  FILE	*file;
  char	line[200];
  char	key[80];
  char	key_part[4][40];
  char	include_file[80];
  char	subject[80];
  char	subject_part[4][40];
  int	key_nr;
  int	subject_nr;
  int	hit = 0;
  int 	sts;
  int	i;  
  char	*s;
  char  prev[80] = "";

  if ( help_key) {
    cdh_ToLower( key, help_key);
  }

  // Open file
  file = navhelp_open_file( this, file_type, file_name);
  if ( !file) return NAV__NOFILE;

  key_nr = dcli_parse( key, " 	", "", (char *)key_part,
		       sizeof( key_part) / sizeof( key_part[0]), 
		       sizeof( key_part[0]), 0);


  sts = dcli_read_line( line, sizeof( line), file);
  while ( ODD(sts)) {
    if ( cdh_NoCaseStrncmp( line, "<include>", 9) == 0) {      
      help_remove_spaces( &line[9], include_file);
      // Replace symbol for language
      if ( strncmp( include_file, "$pwr_lang/", 10) == 0) {
        char lng_include_file[200];

	sprintf( lng_include_file, "$pwr_exe/%s/%s", Lng::get_language_str(),
		 &include_file[10]);
	strcpy( include_file, lng_include_file);
      }

      if ( !noprop) {
	sts = get_next_key( help_key, navh_eHelpFile_Other, 
			    include_file, strict, prev_key);
	if ( ODD(sts)) {
	  fclose( file);
	  return sts;
	}
      }
      hit = 0;
    }
    if ( cdh_NoCaseStrncmp( line, "<topic>", 7) == 0) {
      if ( (s = strstr( line, "<style>")) || (s = strstr( line, "<STYLE>"))) {
	*s = 0;
      }

      help_remove_spaces( &line[7], subject);
      cdh_ToLower( subject, subject);
      subject_nr = dcli_parse( subject, " 	", "", (char *)subject_part,
                	sizeof( subject_part) / sizeof( subject_part[0]),
			sizeof( subject_part[0]), 0);
      if ( key_nr == subject_nr ) {
	for ( i = 0; i < key_nr; i++) {
	  if ( (!strict && strncmp( subject_part[i], key_part[i], strlen(key_part[i])) == 0) ||
	       (strict && strcmp( subject_part[i], key_part[i]) == 0)) {
	    if ( i == key_nr - 1) {
	      hit = 1;
	      strcpy( prev_key, prev);
	    }
	  }
	  else
	    break;
	}
      }
      if ( hit) 
	break;

      strcpy( prev, subject);
    }
    sts = dcli_read_line( line, sizeof( line), file);
  }
  fclose( file);

  if ( !hit || strcmp( prev, "") == 0)
    return NAV__TOPICNOTFOUND;
  return NAV__SUCCESS;
}
Esempio n. 5
0
int XttHotkey::read_file()
{
  FILE *fp;
  char line[200];
  int row = 0;
  char p1[2][200];
  char p2[10][200];
  int i, n;
  char *s;

  dcli_translate_filename( m_filename, m_filename);
  fp = fopen( m_filename, "r");
  if ( !fp)
    return 0;

  while ( dcli_read_line( line, sizeof(line), fp)) {
    int mod = 0;
    int keysym;
    char keystr[20] = "";
    char action_arg[200];
    char action_name[200];

    row++;

    dcli_trim( line, line);
    if ( line[0] == 0 || line[0] == '#')
      continue;

    n = dcli_parse( line, ":", "", (char *)p1, 
		    sizeof( p1) / sizeof( p1[0]), sizeof( p1[0]), 0);
    if ( n != 2) {
      printf( "Syntax error, %s, row %d\n", m_filename, row);
      continue;
    }
    dcli_trim( p1[0], p1[0]);
    dcli_trim( p1[1], p1[1]);

    n = dcli_parse(  p1[0], " 	", "", (char *)p2, 
		    sizeof( p2) / sizeof( p2[0]), sizeof( p2[0]), 0);
    if ( n < 1) {
      printf( "Syntax error, %s, row %d\n", m_filename, row);
      continue;
    }
    for ( i = 0; i < n; i++) {
      if ( cdh_NoCaseStrcmp( p2[i], "Control") == 0)
	mod |= ControlMask;
      else if ( cdh_NoCaseStrcmp( p2[i], "Shift") == 0)
	mod |= ShiftMask; 
      else if ( cdh_NoCaseStrcmp( p2[i], "Alt") == 0)
	mod |= Mod1Mask; 
      else if ( cdh_NoCaseStrncmp( p2[i], "<key>", 5) == 0) {
	strcpy( keystr, &p2[i][5]);
      	dcli_trim( keystr, keystr);
      }
      else {
	printf( "Syntax error, %s, row %d\n", m_filename, row);
	break;
      }
    }

    n = dcli_parse(  p1[1], "(", "", (char *)p2, 
		     sizeof( p2) / sizeof( p2[0]), sizeof( p2[0]), 0);
    if ( n < 2) {
      printf( "Syntax error, %s, row %d\n", m_filename, row);
      continue;
    }
    strcpy( action_name, p2[0]);
    dcli_trim( action_name, action_name);
    strcpy( action_arg, p2[1]);
    if ( (s = strrchr( action_arg, ')')))
      *s = 0;
    else {
      printf( "Syntax error, %s, row %d\n", m_filename, row);
      continue;
    }
    keysym = XStringToKeysym( keystr);
    if ( !keysym) {
      printf( "Syntax error, %s, row %d\n", m_filename, row);
      continue;
    }

    HotkeyKey key( mod, keysym, action_name, action_arg);
    m_keys.push_back( key);
  }

  fclose( fp);

  for ( i = 0; i < (int)m_keys.size(); i++) {
    grab_key( m_keys[i].m_keysym, m_keys[i].m_mod);
  }

  return 1;
}