home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / tdosly14.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  9.2 KB  |  428 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TDosLynx
  4. //    Include File:    tdoslynx.h
  5. //    Purpose:    The DosLynx WWW client.
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        03-31-94    created
  9. #include"tdoslynx.h"
  10. #include"globals.h"
  11. #include"image.h"
  12. #include<string.h>
  13. #include<fstream.h>
  14.  
  15. void TDosLynx::EvalConfigFile()    {
  16. //    Purpose:    Go through pertinent DosLynx options in the
  17. //            configuration file.
  18. //    Arguments:    void
  19. //    Return Value:    void
  20. //    Remarks/Portability/Dependencies/Restrictions:
  21. //    Revision History:
  22. //        03-31-94    created
  23.  
  24.     const char *cp_configname = "DOSLYNX.CFG";
  25.     auto char *cp_openname;
  26.  
  27.     //    Create the config file name.
  28.     if(cp_inipath != NULL)    {
  29.         cp_openname = new char[strlen(cp_inipath) +
  30.             strlen(cp_configname) + 2];
  31.         strcpy(cp_openname, cp_inipath);
  32.         strcat(cp_openname, "\\");
  33.         strcat(cp_openname, cp_configname);
  34.     }
  35.     else    {
  36.         cp_openname = newStr(cp_configname);
  37.     }
  38.  
  39.     //    Open the configuration file for reading.
  40.     auto fstream *fsp_config = new fstream(cp_openname, ios::in |
  41.         ios::nocreate);
  42.     if(fsp_config == NULL)    {
  43.         doslynxmessage("Unable to open configuration file " <<
  44.             cp_openname);
  45.         delete(cp_openname);
  46.         return;
  47.     }
  48.  
  49.     //    Begin reading the file line by line.
  50.     //    Skip all comment lines, blank lines, and unknown keyword
  51.     //    lines.
  52.     auto char ca_linebuffer[256];
  53.     while(fsp_config->eof() == 0 && fsp_config->bad() == 0)    {
  54.         //    Reset the line, get a new line.
  55.         ca_linebuffer[0] = '\0';
  56.         fsp_config->getline(ca_linebuffer, 256);
  57.  
  58.         //    Continue the loop if a comment.
  59.         if(ca_linebuffer[0] == '#' || ca_linebuffer[0] == ';')    {
  60.             continue;
  61.         }
  62.         //    Continue the loop if a blank.
  63.         else if(isspace(ca_linebuffer[0]))    {
  64.             continue;
  65.         }
  66.         //    Continue the loop if not a recognized keyword.
  67.         else    {
  68.             //    If there is no '=' in the line, this is not
  69.             //    a valid entry.
  70.             auto char *cp_temp = strchr(ca_linebuffer, '=');
  71.             if(cp_temp == NULL)    {
  72.                 continue;
  73.             }
  74.  
  75.             //    Move past the '=' and any space.
  76.             cp_temp++;
  77.             while(isspace(*cp_temp) && *cp_temp != '\0')    {
  78.                 cp_temp++;
  79.             }
  80.  
  81.             //    If the line ended, continue on.
  82.             if(*cp_temp == '\0')    {
  83.                 continue;
  84.             }
  85.  
  86.             //    End the line on the first space.
  87.             //    May cause problem with tagged URL.
  88.             auto char *cp_trailer = cp_temp;
  89.             while(!isspace(*cp_trailer) && *cp_trailer != ';' &&
  90.                 *cp_trailer != '#' && *cp_trailer != '\0')
  91.             {
  92.                 cp_trailer++;
  93.             }
  94.             *cp_trailer = '\0';
  95.  
  96.             //    Look for known keywords.
  97.             if(strnicmp("tempdir", ca_linebuffer, 7))    {
  98.             if(strnicmp("textmode", ca_linebuffer, 8))    {
  99.             if(strnicmp("printer", ca_linebuffer, 7))    {
  100.             if(strnicmp("loaded", ca_linebuffer, 6))    {
  101.             if(strnicmp("home", ca_linebuffer, 4))    {
  102.             if(strnicmp("loadhome", ca_linebuffer, 8))    {
  103.             if(strnicmp("graphicsmode", ca_linebuffer, 12))    {
  104.             if(strnicmp("hotlistfile", ca_linebuffer, 11))    {
  105.             if(strnicmp("errorhtml", ca_linebuffer, 9))    {
  106.             if(strnicmp("mailaddr", ca_linebuffer, 8))    {
  107.             if(strnicmp("networked", ca_linebuffer, 9))    {
  108.             if(strnicmp("nntphost", ca_linebuffer, 8))    {
  109.             if(strnicmp("emspages", ca_linebuffer, 8))    {
  110.             if(strnicmp("ems", ca_linebuffer, 3))    {
  111.             if(strnicmp("xmslength", ca_linebuffer, 9))    {
  112.             if(strnicmp("xmsstart", ca_linebuffer, 8))    {
  113.             if(strnicmp("xms", ca_linebuffer, 3))    {
  114.             if(strnicmp("http_proxy", ca_linebuffer, 10))    {
  115.             if(strnicmp("gopher_proxy", ca_linebuffer, 12))    {
  116.             if(strnicmp("ftp_proxy", ca_linebuffer, 9))    {
  117.             if(strnicmp("wais_proxy", ca_linebuffer, 10))    {
  118.                 //    No recognized keywords.
  119.                 continue;
  120.             }
  121.             else    {
  122.                 //    wais_proxy entry.
  123.  
  124.                 //    If there was an old one, free it.
  125.                 if(cp_wais_proxy != NULL)    {
  126.                     delete(cp_wais_proxy);
  127.                 }
  128.  
  129.                 //    Just copy it over.
  130.                 cp_wais_proxy = newStr(cp_temp);
  131.             }
  132.             }
  133.             else    {
  134.                 //    ftp_proxy entry.
  135.  
  136.                 //    If there was an old one, free it.
  137.                 if(cp_ftp_proxy != NULL)    {
  138.                     delete(cp_ftp_proxy);
  139.                 }
  140.  
  141.                 //    Just copy it over.
  142.                 cp_ftp_proxy = newStr(cp_temp);
  143.             }
  144.             }
  145.             else    {
  146.                 //    gopher_proxy entry.
  147.  
  148.                 //    If there was an old one, free it.
  149.                 if(cp_gopher_proxy != NULL)    {
  150.                     delete(cp_gopher_proxy);
  151.                 }
  152.  
  153.                 //    Just copy it over.
  154.                 cp_gopher_proxy = newStr(cp_temp);
  155.             }
  156.             }
  157.             else    {
  158.                 //    http_proxy entry.
  159.  
  160.                 //    If there was an old one, free it.
  161.                 if(cp_http_proxy != NULL)    {
  162.                     delete(cp_http_proxy);
  163.                 }
  164.  
  165.                 //    Just copy it over.
  166.                 cp_http_proxy = newStr(cp_temp);
  167.             }
  168.             }
  169.             else    {
  170.                 //    xms entry.
  171.  
  172.                 //    check for values.
  173.                 if(stricmp("YES", cp_temp))    {
  174.                 if(stricmp("NO", cp_temp))    {
  175.                     //    bad value.
  176.                 }
  177.                 else    {
  178.                     B_xms = False;
  179.                 }
  180.                 }
  181.                 else    {
  182.                     B_xms = True;
  183.                 }
  184.             }
  185.             }
  186.             else    {
  187.                 //    xmsstart entry.
  188.  
  189.                 //    Make sure a valid long integer.
  190.                 auto unsigned long int uli_temp =
  191.                     strtoul(cp_temp, NULL, 0);
  192.                 if(uli_temp != 0UL)    {
  193.                     uli_xmsstart = uli_temp;
  194.                 }
  195.             }
  196.             }
  197.             else    {
  198.                 //    xmslength entry.
  199.  
  200.                 //    Make sure a valid long integer.
  201.                 auto unsigned long int uli_temp =
  202.                     strtoul(cp_temp, NULL, 0);
  203.                 if(uli_temp != 0UL)    {
  204.                     uli_xmslength = uli_temp;
  205.                 }
  206.             }
  207.             }
  208.             else    {
  209.                 //    ems entry.
  210.  
  211.                 //    check for values.
  212.                 if(stricmp("YES", cp_temp))    {
  213.                 if(stricmp("NO", cp_temp))    {
  214.                     //    bad value.
  215.                 }
  216.                 else    {
  217.                     B_ems = False;
  218.                 }
  219.                 }
  220.                 else    {
  221.                     B_ems = True;
  222.                 }
  223.             }
  224.             }
  225.             else    {
  226.                 //    emspages entry.
  227.  
  228.                 //    Make sure a valid long integer.
  229.                 auto unsigned long int uli_temp =
  230.                     strtoul(cp_temp, NULL, 0);
  231.                 if(uli_temp != 0UL)    {
  232.                     usi_emspages = (unsigned short int)
  233.                         uli_temp;
  234.                 }
  235.             }
  236.             }
  237.             else    {
  238.                 //    nntphost entry.
  239.  
  240.                 //    If there is an old entry, get rid.
  241.                 if(cp_nntphost != NULL)    {
  242.                     delete(cp_nntphost);
  243.                 }
  244.                 cp_nntphost = newStr(cp_temp);
  245.             }
  246.             }
  247.             else    {
  248.                 //    networked entry.
  249.  
  250.                 //    check for values.
  251.                 if(stricmp("YES", cp_temp))    {
  252.                 if(stricmp("NO", cp_temp))    {
  253.                     //    bad value.
  254.                 }
  255.                 else    {
  256.                     i_networked = 0;
  257.                 }
  258.                 }
  259.                 else    {
  260.                     i_networked = 1;
  261.                 }
  262.             }
  263.             }
  264.             else    {
  265.                 //    mailaddr entry.
  266.  
  267.                 //    If there is a prior entry....
  268.                 if(::cp_ReplyTo != NULL)    {
  269.                     delete(::cp_ReplyTo);
  270.                 }
  271.                 cp_ReplyTo = newStr(cp_temp);
  272.             }
  273.             }
  274.             else    {
  275.                 //    errorhtml entry.
  276.  
  277.                 //    If there is a previos entry....
  278.                 if(::cp_ErrorHTML != NULL)    {
  279.                     delete(::cp_ErrorHTML);
  280.                 }
  281.                 cp_ErrorHTML = newStr(cp_temp);
  282.             }
  283.             }
  284.             else    {
  285.                 //    hotlistfile entry
  286.  
  287.                 //    If there is a previous hotlistfile
  288.                 //    entry, get rid of it.
  289.                 if(::cp_HotList != NULL)    {
  290.                     delete(::cp_HotList);
  291.                 }
  292.                 cp_HotList = newStr(cp_temp);
  293.             }
  294.             }
  295.             else    {
  296.                 //    graphicsmode entry
  297.  
  298.                 //    Take action on the proper value.
  299.                 if(stricmp("none", cp_temp))    {
  300.                 if(stricmp("720x348x2", cp_temp))    {
  301.                 if(stricmp("640x200x2", cp_temp))    {
  302.                 if(stricmp("640x350x16", cp_temp))    {
  303.                 if(stricmp("640x480x16", cp_temp))    {
  304.                     //    Bad value.
  305.                 }
  306.                 else    {
  307.                     //    640x480x16
  308.                     usi_graphicsmode = (image_modes)
  309.                         image_mode_vga_640x480x16;
  310.                 }
  311.                 }
  312.                 else    {
  313.                     //    640x350x16
  314.                     usi_graphicsmode = (image_modes)
  315.                         image_mode_ega;
  316.                 }
  317.                 }
  318.                 else    {
  319.                     //    640x200x2
  320.                     usi_graphicsmode = (image_modes)
  321.                         image_mode_cga;
  322.                 }
  323.                 }
  324.                 else    {
  325.                     //    720x348x2
  326.                     usi_graphicsmode = (image_modes)
  327.                         image_mode_herc;
  328.                 }
  329.                 }
  330.                 else    {
  331.                     //    NONE
  332.                     usi_graphicsmode = (image_modes)
  333.                         image_modes_total;
  334.                 }
  335.             }
  336.             }
  337.             else    {
  338.                 //    loadhome entry
  339.  
  340.                 //    Take action on the proper value.
  341.                 if(stricmp("ON", cp_temp))    {
  342.                 if(stricmp("OFF", cp_temp))    {
  343.                     //    Bad value.
  344.                 }
  345.                 else    {
  346.                     //    OFF
  347.                     B_loadHome = False;
  348.                 }
  349.                 }
  350.                 else    {
  351.                     //    ON
  352.                     B_loadHome = True;
  353.                 }
  354.             }
  355.             }
  356.             else    {
  357.                 //    home entry
  358.  
  359.                 //    If there is a previous home entry,
  360.                 //    get rid of it.
  361.                 if(::cp_Home != NULL)    {
  362.                     delete(::cp_Home);
  363.                 }
  364.                                 ::cp_Home = newStr(cp_temp);
  365.             }
  366.             }
  367.             else    {
  368.                 //    loaded entry
  369.  
  370.                 //    Set our maximum loaded HText limit.
  371.                 auto unsigned short int usi_newmax =
  372.                     (unsigned short int)atoi(cp_temp);
  373.                 if(usi_newmax)    {
  374.                                     usi_MaxLoadedHTexts = usi_newmax;
  375.                 }
  376.             }
  377.             }
  378.             else    {
  379.                 //    printer entry
  380.  
  381.                 //    If there is a prior entry, get rid
  382.                 //    of it.
  383.                 if(::cp_Printer != NULL)    {
  384.                     delete(cp_Printer);
  385.                 }
  386.                 ::cp_Printer = newStr(cp_temp);
  387.             }
  388.             }
  389.             else    {
  390.                 //    textmode entry
  391.  
  392.                 //    Take action on the proper value.
  393.                 if(stricmp("low", cp_temp))    {
  394.                 if(stricmp("high", cp_temp))    {
  395.                     //    Bad value.
  396.                 }
  397.                 else    {
  398.                     //    HIGH
  399.                     if(B_isLow == True)    {
  400.                         switchVideo();
  401.                     }
  402.                 }
  403.                 }
  404.                 else    {
  405.                     //    LOW
  406.                     if(B_isLow == False)    {
  407.                         switchVideo();
  408.                     }
  409.                 }
  410.             }
  411.             }
  412.             else    {
  413.                 //    tempdir entry
  414.  
  415.                 //    If there was a previous tempdir
  416.                 //    entry, get rid of it.
  417.                 if(::cp_TempDir != NULL)    {
  418.                     delete(::cp_TempDir);
  419.                 }
  420.                 ::cp_TempDir = newStr(cp_temp);
  421.             }
  422.         }
  423.     }
  424.  
  425.     //    Done with the file.
  426.     fsp_config->close();
  427.     delete(fsp_config);
  428. }