Subversion Repositories svn1

Rev

Rev 386 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 386 Rev 389
Line 61... Line 61...
61
 *
61
 *
62
 *
62
 *
63
 *  Note: Use an "htm" file extension as DOS cannot handle 4 letter extensions
63
 *  Note: Use an "htm" file extension as DOS cannot handle 4 letter extensions
64
 *========================================================================*/
64
 *========================================================================*/
65
 
65
 
66
bool open_printer( const char *name, const char *ext, int width, report_type html, const char *title )
66
bool open_printer( const QString name, const char *ext, int width, report_type html, const char *title )
67
{
67
{
68
    char    *pname;
68
    QString pname;
69
 
69
 
70
    /*
70
    /*
71
    **  Determine the name of the file
71
    **  Determine the name of the file
72
    **  May need to modify the extension if it is an HTML file
72
    **  May need to modify the extension if it is an HTML file
73
    */
73
    */
74
    if ( html )
74
    if ( html )
75
    {
75
    {
76
        if ( html == printed )
76
        if ( html == printed )
77
            pname = p_filename( name[0] ? name : filebase, ext ,"prn.html" );
77
            pname = p_filename( !name.isEmpty() ? name : FileBase, ext ,"prn.html" );
78
        else
78
        else
79
            pname = p_filename( name[0] ? name : filebase, ext ,"html" );
79
            pname = p_filename( !name.isEmpty() ? name : FileBase, ext ,"html" );
80
    }
80
    }
81
    else
81
    else
82
    {
82
    {
83
        pname = p_filename( filebase, name[0] ? name : "", ext[0] ? ext : "lst" );
83
        pname = p_filename( !name.isEmpty() ? name : FileBase, ext ,"txt" );
84
    }
84
    }
85
 
85
 
86
    /*
86
    /*
87
    **  Now use basic function
87
    **  Now use basic function
88
    */
88
    */
Line 106... Line 106...
106
 *
106
 *
107
 *
107
 *
108
 *  Note: Use an "htm" file extension as DOS cannot handle 4 letter extensions
108
 *  Note: Use an "htm" file extension as DOS cannot handle 4 letter extensions
109
----------------------------------------------------------------------------*/
109
----------------------------------------------------------------------------*/
110
 
110
 
111
bool open_printer_name( const char *pname, int width, report_type htmltype, const char *title )
111
bool open_printer_name( const QString pname, int width, report_type htmltype, const char *title )
112
{
112
{
113
    printFileName = filepath;
113
    printFileName = FilePath;
114
    switch (htmltype)
114
    switch (htmltype)
115
    {
115
    {
116
    case printed: printFileName.append("webtxt/");  break;
116
    case printed: printFileName.append("webtxt/");  break;
117
    case html: printFileName.append("web/");  break;
117
    case html: printFileName.append("web/");  break;
118
    default: printFileName.append("text/");  break;
118
    default: printFileName.append("text/");  break;
Line 120... Line 120...
120
 
120
 
121
    /*
121
    /*
122
    ** Ensure that the directory exists
122
    ** Ensure that the directory exists
123
    */
123
    */
124
    {
124
    {
125
        QDir dir(filepath);
125
        QDir dir(FilePath);
126
        dir.mkpath(printFileName);
126
        dir.mkpath(printFileName);
127
    }
127
    }
128
 
128
 
129
    /*
129
    /*
130
    ** Append the filename to the directory
130
    ** Append the filename to the directory
Line 605... Line 605...
605
    l = strlen( config.event_name );
605
    l = strlen( config.event_name );
606
    s = ( print_width - l ) / 2;
606
    s = ( print_width - l ) / 2;
607
    print( "%*s", s, "" );
607
    print( "%*s", s, "" );
608
 
608
 
609
    if ( print_html == html )
609
    if ( print_html == html )
610
        print( "<A HREF=\"%s\">", p_filename(filebase, "index" ,"html"));
610
        print( "<A HREF=\"%s\">", p_filename(FileBase, "index" ,"html").toStdString().c_str());
611
    print_underline( TRUE);
611
    print_underline( TRUE);
612
    print_bold( TRUE );
612
    print_bold( TRUE );
613
 
613
 
614
    print( "%s", config.event_name );
614
    print( "%s", config.event_name );
615
 
615
 
Line 650... Line 650...
650
 *
650
 *
651
 *  Purpose:
651
 *  Purpose:
652
 *      This function is called create a suitably formatted filename
652
 *      This function is called create a suitably formatted filename
653
 *      for use in an HTML tag or by the file system
653
 *      for use in an HTML tag or by the file system
654
 *
654
 *
655
 *      Currently all output filenames are created in uppercase
-
 
656
 *      This is a limitation of DOS
-
 
657
 *      This function is used to ensure that all files are created with
-
 
658
 *      an uppercase name and that all HTML file references are also
-
 
659
 *      in uppercase.
-
 
660
 *
-
 
661
 *
655
  *
662
 *  Parameters:
656
 *  Parameters:
663
 *      filename        - Base filename
657
 *      filename        - Base filename
664
 *      Suffix          - Optional part of the basename
658
 *      suffix          - Optional part of the basename
665
 *                        If present is used to create part of the basename
659
 *                        If present is used to create part of the basename
666
 *      ext             - Extension
660
 *      ext             - Extension
667
 *
661
 *
668
 *  Returns:
662
 *  Returns:
669
 *      Address of a static string that will reference the file
663
 *      A QString that will reference the file
670
 *
664
 *
671
 *========================================================================*/
665
 *========================================================================*/
672
 
666
 
673
char * p_filename( const char *filename, const char *suffix, const char *ext )
667
QString p_filename( const QString filename, const QString suffix, const QString ext )
674
{
668
{
675
    char    *name;
669
    QString name;
676
    char    *cptr;
-
 
677
 
-
 
678
#ifndef LONG_FILE_NAMES
-
 
679
    /*
-
 
680
    **  Limit the filename to 8.3 format
-
 
681
    **  This is a limitation of the underlying file access library
-
 
682
    **  and may be removed in the future
-
 
683
    */
-
 
684
    if ( suffix[0] )
670
    if (!suffix.isEmpty()) {
685
        name = tprintf ( "%.4s_%.3s.%.3s", filename, suffix, ext );
671
        name = filename + "_" + suffix;
686
    else
672
    } else {
687
        name = tprintf ( "%.8s.%.3s", filename, ext );
-
 
688
 
-
 
689
 
-
 
690
    /*
-
 
691
    **  Uppercase the filename
673
        name = filename;
692
    */
-
 
693
    cptr = name;
-
 
694
    while ( *cptr )
-
 
695
    {
-
 
696
        *cptr = toupper( *cptr );
-
 
697
        cptr++;
-
 
698
    }
674
    }
699
#else
-
 
700
    /*
-
 
701
    **  This compiler and runtime library supports
-
 
702
    **  long filenames - created printed filenames in lower case
-
 
703
    */
-
 
704
    if ( suffix[0] )
-
 
705
        name = tprintf ( "%s_%s.%s", filename, suffix, ext );
-
 
706
    else
-
 
707
        name = tprintf ( "%s_%s.%s", filename, ext, "txt" );
675
    name = name.append(".").append(ext);
708
 
676
 
709
    cptr = name;
-
 
710
    while ( *cptr )
-
 
711
    {
-
 
712
        *cptr = tolower( *cptr );
677
    //qDebug() << "p_filename" << filename << ":" << suffix << ":" <<  ext << " -> " << name;
713
        cptr++;
678
    return name;
714
    }
-
 
715
#endif
-
 
716
 
679
 
717
    return( name );
-
 
718
}
680
}
719
 
681
 
720
 
682
 
721
/*========================================================================
683
/*========================================================================
722
 *
684
 *
Line 798... Line 760...
798
    va_end( ap );
760
    va_end( ap );
799
 
761
 
800
    return ( print_href );
762
    return ( print_href );
801
}
763
}
802
 
764
 
803
 
-
 
804
/*----------------------------------------------------------------------------
-
 
805
** FUNCTION           : to_hex
-
 
806
**
-
 
807
** DESCRIPTION        : Converts an integer value to its hex character
-
 
808
**
-
 
809
**
-
 
810
** INPUTS             : code        - Code to convert
-
 
811
**
-
 
812
** RETURNS            : Character representation
-
 
813
**
-
 
814
----------------------------------------------------------------------------*/
-
 
815
 
-
 
816
char to_hex(char code)
-
 
817
{
-
 
818
  static char hex[] = "0123456789abcdef";
-
 
819
  return hex[code & 0x0f];
-
 
820
}
-
 
821
 
-
 
822
/*----------------------------------------------------------------------------
765
/*----------------------------------------------------------------------------
823
** FUNCTION           : url_encode
766
** FUNCTION           : url_encode
824
**
767
**
825
** DESCRIPTION        : URL encoded version of a string
768
** DESCRIPTION        : URL encoded version of a string
826
**
769
**
Line 831... Line 774...
831
**
774
**
832
** WARNING            : Uses a small circular pool of strings so that the
775
** WARNING            : Uses a small circular pool of strings so that the
833
**                      user doesn't need to worry about string release
776
**                      user doesn't need to worry about string release
834
**
777
**
835
----------------------------------------------------------------------------*/
778
----------------------------------------------------------------------------*/
836
char *url_encode(const char *str)
779
char * url_encode(const QString str)
837
{
780
{
-
 
781
 
838
    static char tbuf[TBUF_COUNT][TBUF_LENGTH * 3];
782
    static char tbuf[TBUF_COUNT][TBUF_LENGTH * 3];
839
    static int  index = 0;
783
    static int  index = 0;
840
    char       *pp;
784
    char       *pp;
841
 
785
 
842
    /*
786
    /*
Line 845... Line 789...
845
    index++;
789
    index++;
846
    if( index >= TBUF_COUNT )
790
    if( index >= TBUF_COUNT )
847
        index = 0;
791
        index = 0;
848
    pp = tbuf[index];
792
    pp = tbuf[index];
849
    
793
    
850
    const char *pstr = str;
-
 
851
    char *pbuf = pp;
794
    char *pbuf = pp;
852
 
795
 
-
 
796
    QUrl url = QUrl(str);
-
 
797
    QString encodedUrl = url.toString(QUrl::FullyEncoded);
-
 
798
 
-
 
799
    std::string sstr= encodedUrl.toStdString();
-
 
800
    const char * data = sstr.c_str();
-
 
801
 
-
 
802
// TODO - no limit check on the converted data
853
    while (*pstr)
803
    while (*data)
854
    {
804
    {
855
        if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
-
 
856
            *pbuf++ = *pstr;
805
        *pbuf++ = *data++;
857
        else if (*pstr == ' ')
-
 
858
            *pbuf++ = '+';
-
 
859
        else
-
 
860
        {
-
 
861
            *pbuf++ = '%';
-
 
862
            *pbuf++ = to_hex(*pstr >> 4);
-
 
863
            *pbuf++ = to_hex(*pstr & 15);
-
 
864
        }
-
 
865
        pstr++;
-
 
866
    }
806
    }
867
    *pbuf = '\0';
807
    *pbuf = '\0';
-
 
808
 
-
 
809
    //qDebug() << "url_encode:" << str << ":" << pp;
868
  return pp;
810
    return pp;
-
 
811
 
869
}
812
}
870
 
813
 
871
/********************************* EOF ***********************************/
814
/********************************* EOF ***********************************/