home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / smapp100.zip / sm10.zip / smgoptfi.c < prev    next >
C/C++ Source or Header  |  2000-05-14  |  11KB  |  371 lines

  1. /* ------------------------------------------------------------------------
  2.  *
  3.  *        File: smgoptfi.c
  4.  *     Project: Source Mapper.
  5.  *     Created: April 12, 1992.
  6.  * Description: Kildekode for lagring/henting av innstilte brukervalg.
  7.  *
  8.  * Copyright (C) 2000 Leif-Erik Larsen.
  9.  * This file is part of the Source Mapper source package.
  10.  * Source Mapper is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published
  12.  * by the Free Software Foundation, in version 2 as it comes in the
  13.  * "COPYING" file of the XWorkplace main distribution.
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * ------------------------------------------------------------------------ */
  20.  
  21.  
  22.  
  23.  
  24. #include "smg.h"
  25.  
  26.  
  27.  
  28.  
  29. #ifdef __GNUC__
  30. int strcmpi ( register const char *s1, register const char *s2 )
  31. {
  32.    while (toupper (*s1) == toupper (*s2++))
  33.       if (*s1++ == 0)
  34.          return (0);
  35.  
  36.    return (toupper (*(unsigned char *)s1) -
  37.            toupper (*(unsigned char *)--s2));
  38. }
  39. #endif
  40.  
  41.  
  42.  
  43.  
  44. char optchr_pm ( int opt )
  45. /* Opprettet: S¢ndag 12. april 1992.
  46.    Parameter: "opt" Bryterkoden som skal oversettes til karakteren - eller +.
  47.    Retur    : '-' hvis opt er O_NO, ellers '+'.
  48.    Beskriv  :
  49. */
  50. {
  51.    if (opt == O_NO)
  52.       return ('-');
  53.    else
  54.       return ('+');
  55. } /* optchr_pm (); */
  56.  
  57.  
  58.  
  59.  
  60. char optchr_v ( int opt )
  61. /* Opprettet: S¢ndag 12. april 1992.
  62.    Parameter: "opt" Bryterkoden som skal oversettes til karakteren 0/1/2/3/4.
  63.    Retur    : Verdien til opt, som karakter (0/1/2/3/4)
  64.    Beskriv  :
  65. */
  66. {
  67.    switch (opt)
  68.    {
  69.       case 0  : return ('0');
  70.       case 1  : return ('1');
  71.       case 2  : return ('2');
  72.       case 3  : return ('3');
  73.       case 4  : return ('4');
  74.       default : return ('5');
  75.    }
  76. } /* optchr_v (); */
  77.  
  78.  
  79.  
  80.  
  81. int save_options ( const char *fname )
  82. /* Opprettet: S¢ndag 12. april 1992.
  83.    Parameter: "fname" Navnet til filen hvor valgene skal lagres.
  84.    Retur    : E/O.
  85.    Beskriv  : Lagrer innstilte brukervalg i oppgitt filnavn.
  86. */
  87. {
  88.    FILE *fil;
  89.  
  90.    if ((fil = FOpen (fname, "wt")) == NULL)
  91.       RETERR (24, fname); /* Failed on open option file! */
  92.  
  93.    /* Totalinformasjon */
  94.    if (!FPrintF (fil,
  95.       "\t%c %s:\n"
  96.       "%s[%c]\t%c %s\n"
  97.       "%s[%c]\t%c %s\n"
  98.       "%s[%c]\t%c %s\n"
  99.       "%s[%c]\t%c %s\n"
  100.       "%s[%c]\t%c %s\n"
  101.       "%s[%c]\t%c %s\n"
  102.       "%s[%c]\t%c %s\n"
  103.       "\n",
  104.       COMCHAR, optblocks[OB_TOTINFO],
  105.       ptbl[PT_iti], optchr_pm (o_totinfo.incl), COMCHAR, defoptcom[PT_iti],
  106.       ptbl[PT_ctl], optchr_pm (o_totinfo.lin_tot), COMCHAR, defoptcom[PT_ctl],
  107.       ptbl[PT_cel], optchr_pm (o_totinfo.lin_emp), COMCHAR, defoptcom[PT_cel],
  108.       ptbl[PT_coc], optchr_pm (o_totinfo.lin_com), COMCHAR, defoptcom[PT_coc],
  109.       ptbl[PT_clc], optchr_pm (o_totinfo.lin_cod), COMCHAR, defoptcom[PT_clc],
  110.       ptbl[PT_cfu], optchr_pm (o_totinfo.func), COMCHAR, defoptcom[PT_cfu],
  111.       ptbl[PT_cco], optchr_pm (o_totinfo.com), COMCHAR, defoptcom[PT_cco]))
  112.    {
  113.       FClose (fil);
  114.       return (ERROR);
  115.    }
  116.  
  117.    /* Funksjonsregister */
  118.    if (!FPrintF (fil,
  119.       "\t%c %s:\n"
  120.       "%s[%c]\t%c %s\n"
  121.       "%s[%c]\t%c %s\n"
  122.       "\n",
  123.       COMCHAR, optblocks[OB_FUNCREG],
  124.       ptbl[PT_ifr], optchr_pm (o_funcreg.incl), COMCHAR, defoptcom[PT_ifr],
  125.       ptbl[PT_fso], optchr_v (o_funcreg.sort), COMCHAR, defoptcom[PT_fso]))
  126.    {
  127.       FClose (fil);
  128.       return (ERROR);
  129.    }
  130.  
  131.    /* Liste over funksjonskall */
  132.    if (!FPrintF (fil,
  133.       "\t%c %s:\n"
  134.       "%s[%c]\t%c %s\n"
  135.       "%s[%s]\t%c %s\n"
  136.       "%s[%c]\t%c %s\n"
  137.       "\n",
  138.       COMCHAR, optblocks[OB_FUNCALL],
  139.       ptbl[PT_ilf], optchr_pm (o_funcall.incl), COMCHAR, defoptcom[PT_ilf],
  140.       ptbl[PT_slf], o_funcall.list, COMCHAR, defoptcom[PT_slf],
  141.       ptbl[PT_fln], optchr_pm (o_funcall.riselnr), COMCHAR, defoptcom[PT_fln]))
  142.    {
  143.       FClose (fil);
  144.       return (ERROR);
  145.    }
  146.  
  147.    /* Liste over identifikatorer */
  148.    if (!FPrintF (fil,
  149.       "\t%c %s:\n"
  150.       "%s[%c]\t%c %s\n"
  151.       "%s[%s]\t%c %s\n"
  152.       "%s[%c]\t%c %s\n"
  153.       "\n",
  154.       COMCHAR, optblocks[OB_IDLIST],
  155.       ptbl[PT_iil], optchr_pm (o_idlist.incl), COMCHAR, defoptcom[PT_iil],
  156.       ptbl[PT_sli], o_idlist.list, COMCHAR, defoptcom[PT_sli],
  157.       ptbl[PT_iln], optchr_pm (o_idlist.riselnr), COMCHAR, defoptcom[PT_iln]))
  158.    {
  159.       FClose (fil);
  160.       return (ERROR);
  161.    }
  162.  
  163.    /* Liste over kall-sekvenser */
  164.    if (!FPrintF (fil,
  165.       "\t%c %s:\n"
  166.       "%s[%c]\t%c %s\n"
  167.       "%s[%c]\t%c %s\n"
  168.       "%s[%c]\t%c %s\n"
  169.       "%s[%c]\t%c %s\n"
  170.       "%s[%c]\t%c %s\n"
  171.       "%s[%c]\t%c %s\n"
  172.       "%s[%s]\t%c %s\n"
  173.       "\n",
  174.       COMCHAR, optblocks[OB_CALSEQ],
  175.       ptbl[PT_csi], optchr_pm (o_flow.incl), COMCHAR, defoptcom[PT_csi],
  176.       ptbl[PT_cie], optchr_pm (o_flow.iIncExternals), COMCHAR, defoptcom[PT_cie],
  177.       ptbl[PT_csg], optchr_pm (o_flow.graph), COMCHAR, defoptcom[PT_csg],
  178.       ptbl[PT_csf], optchr_v (o_flow.format), COMCHAR, defoptcom[PT_csf],
  179.       ptbl[PT_cwi], optchr_v (o_flow.indent), COMCHAR, defoptcom[PT_cwi],
  180.       ptbl[PT_cir], optchr_pm (o_flow.index), COMCHAR, defoptcom[PT_cir],
  181.       ptbl[PT_cdt], o_flow.deftoplev, COMCHAR, defoptcom[PT_cdt]))
  182.    {
  183.       FClose (fil);
  184.       return (ERROR);
  185.    }
  186.  
  187.    /* Linjeinformasjon */
  188.    if (!FPrintF (fil,
  189.       "\t%c %s:\n"
  190.       "%s[%c]\t%c %s\n"
  191.       "%s[%c]\t%c %s\n"
  192.       "%s[%c]\t%c %s\n"
  193.       "%s[%c]\t%c %s\n"
  194.       "\n",
  195.       COMCHAR, optblocks[OB_LINEINF],
  196.       ptbl[PT_ili], optchr_pm (o_lineinfo.incl), COMCHAR, defoptcom[PT_ili],
  197.       ptbl[PT_lll], optchr_pm (o_lineinfo.r_llin), COMCHAR, defoptcom[PT_lll],
  198.       ptbl[PT_rbi], optchr_pm (o_lineinfo.r_bloc), COMCHAR, defoptcom[PT_rbi],
  199.       ptbl[PT_lcl], optchr_pm (o_lineinfo.r_coml), COMCHAR, defoptcom[PT_lcl]))
  200.    {
  201.       FClose (fil);
  202.       return (ERROR);
  203.    }
  204.  
  205.    /* Informasjon om funksjoner */
  206.    if (!FPrintF (fil,
  207.       "\t%c %s:\n"
  208.       "%s[%c]\t%c %s\n"
  209.       "%s[%c]\t%c %s\n"
  210.       "%s[%c]\t%c %s\n"
  211.       "%s[%c]\t%c %s\n"
  212.       "%s[%c]\t%c %s\n"
  213.       "%s[%c]\t%c %s\n"
  214.       "%s[%c]\t%c %s\n"
  215.       "\n",
  216.       COMCHAR, optblocks[OB_FUNCINFO],
  217.       ptbl[PT_lfi], optchr_pm (o_lineinfo.r_func), COMCHAR, defoptcom[PT_lfi],
  218.       ptbl[PT_LLF], optchr_pm (o_lineinfo.c_ltot), COMCHAR, defoptcom[PT_LLF],
  219.       ptbl[PT_LEF], optchr_pm (o_lineinfo.c_empl), COMCHAR, defoptcom[PT_LEF],
  220.       ptbl[PT_LCF], optchr_pm (o_lineinfo.c_coml), COMCHAR, defoptcom[PT_LCF],
  221.       ptbl[PT_LCO], optchr_pm (o_lineinfo.c_lcod), COMCHAR, defoptcom[PT_LCO],
  222.       ptbl[PT_LCC], optchr_pm (o_lineinfo.c_com), COMCHAR, defoptcom[PT_LCC],
  223.       ptbl[PT_LLC], optchr_pm (o_lineinfo.calist), COMCHAR, defoptcom[PT_LLC]))
  224.    {
  225.       FClose (fil);
  226.       return (ERROR);
  227.    }
  228.  
  229.    /* Diverse */
  230.    if (!FPrintF (fil,
  231.       "\t%c %s:\n"
  232.       "%s[%s]\t%c %s\n"
  233.       "%s[%c]\t%c %s\n"
  234.       "%s[%c]\t%c %s\n"
  235.       "%s[%c]\t%c %s\n"
  236.       "%s[%c]\t%c %s\n"
  237.       "%s[%c]\t%c %s\n"
  238.       "%s[%c]\t%c %s\n"
  239.       "%s[%i]\t%c %s\n"
  240.       "%s[%i]\t%c %s\n"
  241.       "\n",
  242.       COMCHAR, optblocks[OB_VARIOUS],
  243.       ptbl[PT_NPs], o_various.newpag, COMCHAR, defoptcom[PT_NPs],
  244.       ptbl[PT_NPS], optchr_pm (o_various.np_str), COMCHAR, defoptcom[PT_NPS],
  245.       ptbl[PT_NFU], optchr_pm (o_various.np_fun), COMCHAR, defoptcom[PT_NFU],
  246.       ptbl[PT_NFI], optchr_pm (o_various.np_sect), COMCHAR, defoptcom[PT_NFI],
  247.       ptbl[PT_cse], optchr_v (o_various.column), COMCHAR, defoptcom[PT_cse],
  248.       ptbl[PT_dtu], optchr_pm (o_various.del), COMCHAR, defoptcom[PT_dtu],
  249.       ptbl[PT_gcb], optchr_pm (o_various.gencom), COMCHAR, defoptcom[PT_gcb],
  250.       ptbl[PT_tab], o_various.twidth, COMCHAR, defoptcom[PT_tab],
  251.       ptbl[PT_dis], o_various.iShowInfo, COMCHAR, defoptcom[PT_dis]))
  252.    {
  253.       FClose (fil);
  254.       return (ERROR);
  255.    }
  256.  
  257.    /* Generer */
  258.    if (!FPrintF (fil,
  259.       "\t%c %s:\n"
  260.       "%s[%c]\t%c %s\n"
  261.       "%s[%c]\t%c %s\n"
  262.       "%s[%s]\t%c %s\n"
  263.       "%s[%s]\t%c %s\n"
  264.       "%s[%s]\t%c %s\n",
  265.       COMCHAR, optblocks[OB_GENERATE],
  266.       ptbl[PT_gen], optchr_v (o_generate.gen), COMCHAR, defoptcom[PT_gen],
  267.       ptbl[PT_met], optchr_v (o_generate.met), COMCHAR, defoptcom[PT_met],
  268.       ptbl[PT_pof], o_generate.obj, COMCHAR, defoptcom[PT_pof],
  269.       ptbl[PT_pmf], o_generate.map, COMCHAR, defoptcom[PT_pmf],
  270.       ptbl[PT_ptf], o_generate.tmp, COMCHAR, defoptcom[PT_ptf]))
  271.    {
  272.       FClose (fil);
  273.       return (ERROR);
  274.    }
  275.  
  276.    FClose (fil);
  277.  
  278.    return (OK);
  279. } /* save_options (); */
  280.  
  281.  
  282.  
  283.  
  284. int read_options ( const char *name )
  285. /* Opprettet: Torsdag 16. april 1992.
  286.    Parameter: "name" Navnet til filen hvor valgene skal leses fra.
  287.    Retur    : E/O.
  288.    Beskriv  : Leser inn brukervalgene i tekstfilen "name", og tolker
  289.               bryterne deretter.
  290. */
  291. {
  292.    static char ln [MAXLSTLEN + 1];
  293.    char       *point;
  294.    FILE       *file;
  295.  
  296.    if ((file = FOpen (name, "rt")) == NULL)
  297.       RETERR (24, name); /* Failed on open option file! */
  298.  
  299.    while (FGetS (ln, MAXLSTLEN, file) == OK)
  300.    {
  301.       if (strlen (ln) >= MAXLSTLEN) /* Test om innlest linje er for lang */
  302.       {
  303.          FClose (file);
  304.          return (ERROR);
  305.       }
  306.  
  307.       /* Finn tegn som anngir at resten av linja er kommentar */
  308.       point = &(ln[0]);
  309.       while (*point && *point != COMCHAR)
  310.          point++;
  311.  
  312.       /* Kutt den delen av linja som eventuelt er kommentar */
  313.       if (*point == COMCHAR)
  314.          *point = 0;
  315.  
  316.       /* Tolk linja som vanlig brukeroppgitt parameterstreng */
  317.       if (!interpret_parameters (ln, TRUE))
  318.       {
  319.          FClose (file);
  320.          RETURN_ERR;
  321.       }
  322.    }
  323.  
  324.    FClose (file);
  325.  
  326.    if (errno != 0)                     /* Feil ved lesing av linje */
  327.       return (ERROR);
  328.  
  329.    return (OK);
  330. } /* read_options (); */
  331.  
  332.  
  333.  
  334.  
  335. void read_default_options ( void )
  336. /* Opprettet: Torsdag 4. februar 1993.
  337.    Beskriv  : Leser standard valgfil. Pr¢ver f¢rst å lese standard valgfil
  338.               fra aktiv katalog. Hvis dette skjærer seg, så pr¢v å les
  339.               standard valgfil fra program-katalog. */
  340. {
  341.    char cPath1[MAXPATH];
  342.    char cPath2[MAXPATH];
  343.  
  344.    strcpy (cPath1, BigStr (3, progdir, fnames[DEFOPT_FNAME], fnames[SMGOPTI_EXT]));
  345.  
  346.    cPath2[0] = (char) (GetDisk () + 'A');
  347.    cPath2[1] = '\0';
  348.    strcat (cPath2, BigStr (2, ":", DIRSPLITSTR));
  349.    GetCurDir (0, cPath2 + 3);
  350.    strcat (cPath2, fnames[DEFOPT_FNAME]);
  351.    strcat (cPath2, fnames[SMGOPTI_EXT]);
  352.  
  353.    /* Les standard valg fra program-katalog (overse eventuelle feil) */
  354.    read_options (cPath1);
  355.  
  356.    /* Be sure not to read the same file twice!
  357.       (In case current dir = SM program dir) */
  358.    #if defined (__MSDOS__) || defined (__OS2__)
  359.    if (strcmpi (cPath1, cPath2) != 0)   /* File system is not case significant */
  360.    #else
  361.    if (strcmp (cPath1, cPath2) != 0)
  362.    #endif
  363.    {
  364.       /* Lese standard valg fra aktiv katalog (overse eventuell feil) */
  365.       read_options (cPath2);
  366.    }
  367.  
  368.    ErrorClear ();                      /* Clear eventually flagged error */
  369. } /* read_default_options (); */
  370.  
  371.