home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
smapp100.zip
/
sm10.zip
/
smgoptfi.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-14
|
11KB
|
371 lines
/* ------------------------------------------------------------------------
*
* File: smgoptfi.c
* Project: Source Mapper.
* Created: April 12, 1992.
* Description: Kildekode for lagring/henting av innstilte brukervalg.
*
* Copyright (C) 2000 Leif-Erik Larsen.
* This file is part of the Source Mapper source package.
* Source Mapper 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, in version 2 as it comes in the
* "COPYING" file of the XWorkplace main distribution.
* 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.
*
* ------------------------------------------------------------------------ */
#include "smg.h"
#ifdef __GNUC__
int strcmpi ( register const char *s1, register const char *s2 )
{
while (toupper (*s1) == toupper (*s2++))
if (*s1++ == 0)
return (0);
return (toupper (*(unsigned char *)s1) -
toupper (*(unsigned char *)--s2));
}
#endif
char optchr_pm ( int opt )
/* Opprettet: S¢ndag 12. april 1992.
Parameter: "opt" Bryterkoden som skal oversettes til karakteren - eller +.
Retur : '-' hvis opt er O_NO, ellers '+'.
Beskriv :
*/
{
if (opt == O_NO)
return ('-');
else
return ('+');
} /* optchr_pm (); */
char optchr_v ( int opt )
/* Opprettet: S¢ndag 12. april 1992.
Parameter: "opt" Bryterkoden som skal oversettes til karakteren 0/1/2/3/4.
Retur : Verdien til opt, som karakter (0/1/2/3/4)
Beskriv :
*/
{
switch (opt)
{
case 0 : return ('0');
case 1 : return ('1');
case 2 : return ('2');
case 3 : return ('3');
case 4 : return ('4');
default : return ('5');
}
} /* optchr_v (); */
int save_options ( const char *fname )
/* Opprettet: S¢ndag 12. april 1992.
Parameter: "fname" Navnet til filen hvor valgene skal lagres.
Retur : E/O.
Beskriv : Lagrer innstilte brukervalg i oppgitt filnavn.
*/
{
FILE *fil;
if ((fil = FOpen (fname, "wt")) == NULL)
RETERR (24, fname); /* Failed on open option file! */
/* Totalinformasjon */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_TOTINFO],
ptbl[PT_iti], optchr_pm (o_totinfo.incl), COMCHAR, defoptcom[PT_iti],
ptbl[PT_ctl], optchr_pm (o_totinfo.lin_tot), COMCHAR, defoptcom[PT_ctl],
ptbl[PT_cel], optchr_pm (o_totinfo.lin_emp), COMCHAR, defoptcom[PT_cel],
ptbl[PT_coc], optchr_pm (o_totinfo.lin_com), COMCHAR, defoptcom[PT_coc],
ptbl[PT_clc], optchr_pm (o_totinfo.lin_cod), COMCHAR, defoptcom[PT_clc],
ptbl[PT_cfu], optchr_pm (o_totinfo.func), COMCHAR, defoptcom[PT_cfu],
ptbl[PT_cco], optchr_pm (o_totinfo.com), COMCHAR, defoptcom[PT_cco]))
{
FClose (fil);
return (ERROR);
}
/* Funksjonsregister */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_FUNCREG],
ptbl[PT_ifr], optchr_pm (o_funcreg.incl), COMCHAR, defoptcom[PT_ifr],
ptbl[PT_fso], optchr_v (o_funcreg.sort), COMCHAR, defoptcom[PT_fso]))
{
FClose (fil);
return (ERROR);
}
/* Liste over funksjonskall */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%s]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_FUNCALL],
ptbl[PT_ilf], optchr_pm (o_funcall.incl), COMCHAR, defoptcom[PT_ilf],
ptbl[PT_slf], o_funcall.list, COMCHAR, defoptcom[PT_slf],
ptbl[PT_fln], optchr_pm (o_funcall.riselnr), COMCHAR, defoptcom[PT_fln]))
{
FClose (fil);
return (ERROR);
}
/* Liste over identifikatorer */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%s]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_IDLIST],
ptbl[PT_iil], optchr_pm (o_idlist.incl), COMCHAR, defoptcom[PT_iil],
ptbl[PT_sli], o_idlist.list, COMCHAR, defoptcom[PT_sli],
ptbl[PT_iln], optchr_pm (o_idlist.riselnr), COMCHAR, defoptcom[PT_iln]))
{
FClose (fil);
return (ERROR);
}
/* Liste over kall-sekvenser */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%s]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_CALSEQ],
ptbl[PT_csi], optchr_pm (o_flow.incl), COMCHAR, defoptcom[PT_csi],
ptbl[PT_cie], optchr_pm (o_flow.iIncExternals), COMCHAR, defoptcom[PT_cie],
ptbl[PT_csg], optchr_pm (o_flow.graph), COMCHAR, defoptcom[PT_csg],
ptbl[PT_csf], optchr_v (o_flow.format), COMCHAR, defoptcom[PT_csf],
ptbl[PT_cwi], optchr_v (o_flow.indent), COMCHAR, defoptcom[PT_cwi],
ptbl[PT_cir], optchr_pm (o_flow.index), COMCHAR, defoptcom[PT_cir],
ptbl[PT_cdt], o_flow.deftoplev, COMCHAR, defoptcom[PT_cdt]))
{
FClose (fil);
return (ERROR);
}
/* Linjeinformasjon */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_LINEINF],
ptbl[PT_ili], optchr_pm (o_lineinfo.incl), COMCHAR, defoptcom[PT_ili],
ptbl[PT_lll], optchr_pm (o_lineinfo.r_llin), COMCHAR, defoptcom[PT_lll],
ptbl[PT_rbi], optchr_pm (o_lineinfo.r_bloc), COMCHAR, defoptcom[PT_rbi],
ptbl[PT_lcl], optchr_pm (o_lineinfo.r_coml), COMCHAR, defoptcom[PT_lcl]))
{
FClose (fil);
return (ERROR);
}
/* Informasjon om funksjoner */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_FUNCINFO],
ptbl[PT_lfi], optchr_pm (o_lineinfo.r_func), COMCHAR, defoptcom[PT_lfi],
ptbl[PT_LLF], optchr_pm (o_lineinfo.c_ltot), COMCHAR, defoptcom[PT_LLF],
ptbl[PT_LEF], optchr_pm (o_lineinfo.c_empl), COMCHAR, defoptcom[PT_LEF],
ptbl[PT_LCF], optchr_pm (o_lineinfo.c_coml), COMCHAR, defoptcom[PT_LCF],
ptbl[PT_LCO], optchr_pm (o_lineinfo.c_lcod), COMCHAR, defoptcom[PT_LCO],
ptbl[PT_LCC], optchr_pm (o_lineinfo.c_com), COMCHAR, defoptcom[PT_LCC],
ptbl[PT_LLC], optchr_pm (o_lineinfo.calist), COMCHAR, defoptcom[PT_LLC]))
{
FClose (fil);
return (ERROR);
}
/* Diverse */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%s]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%i]\t%c %s\n"
"%s[%i]\t%c %s\n"
"\n",
COMCHAR, optblocks[OB_VARIOUS],
ptbl[PT_NPs], o_various.newpag, COMCHAR, defoptcom[PT_NPs],
ptbl[PT_NPS], optchr_pm (o_various.np_str), COMCHAR, defoptcom[PT_NPS],
ptbl[PT_NFU], optchr_pm (o_various.np_fun), COMCHAR, defoptcom[PT_NFU],
ptbl[PT_NFI], optchr_pm (o_various.np_sect), COMCHAR, defoptcom[PT_NFI],
ptbl[PT_cse], optchr_v (o_various.column), COMCHAR, defoptcom[PT_cse],
ptbl[PT_dtu], optchr_pm (o_various.del), COMCHAR, defoptcom[PT_dtu],
ptbl[PT_gcb], optchr_pm (o_various.gencom), COMCHAR, defoptcom[PT_gcb],
ptbl[PT_tab], o_various.twidth, COMCHAR, defoptcom[PT_tab],
ptbl[PT_dis], o_various.iShowInfo, COMCHAR, defoptcom[PT_dis]))
{
FClose (fil);
return (ERROR);
}
/* Generer */
if (!FPrintF (fil,
"\t%c %s:\n"
"%s[%c]\t%c %s\n"
"%s[%c]\t%c %s\n"
"%s[%s]\t%c %s\n"
"%s[%s]\t%c %s\n"
"%s[%s]\t%c %s\n",
COMCHAR, optblocks[OB_GENERATE],
ptbl[PT_gen], optchr_v (o_generate.gen), COMCHAR, defoptcom[PT_gen],
ptbl[PT_met], optchr_v (o_generate.met), COMCHAR, defoptcom[PT_met],
ptbl[PT_pof], o_generate.obj, COMCHAR, defoptcom[PT_pof],
ptbl[PT_pmf], o_generate.map, COMCHAR, defoptcom[PT_pmf],
ptbl[PT_ptf], o_generate.tmp, COMCHAR, defoptcom[PT_ptf]))
{
FClose (fil);
return (ERROR);
}
FClose (fil);
return (OK);
} /* save_options (); */
int read_options ( const char *name )
/* Opprettet: Torsdag 16. april 1992.
Parameter: "name" Navnet til filen hvor valgene skal leses fra.
Retur : E/O.
Beskriv : Leser inn brukervalgene i tekstfilen "name", og tolker
bryterne deretter.
*/
{
static char ln [MAXLSTLEN + 1];
char *point;
FILE *file;
if ((file = FOpen (name, "rt")) == NULL)
RETERR (24, name); /* Failed on open option file! */
while (FGetS (ln, MAXLSTLEN, file) == OK)
{
if (strlen (ln) >= MAXLSTLEN) /* Test om innlest linje er for lang */
{
FClose (file);
return (ERROR);
}
/* Finn tegn som anngir at resten av linja er kommentar */
point = &(ln[0]);
while (*point && *point != COMCHAR)
point++;
/* Kutt den delen av linja som eventuelt er kommentar */
if (*point == COMCHAR)
*point = 0;
/* Tolk linja som vanlig brukeroppgitt parameterstreng */
if (!interpret_parameters (ln, TRUE))
{
FClose (file);
RETURN_ERR;
}
}
FClose (file);
if (errno != 0) /* Feil ved lesing av linje */
return (ERROR);
return (OK);
} /* read_options (); */
void read_default_options ( void )
/* Opprettet: Torsdag 4. februar 1993.
Beskriv : Leser standard valgfil. Pr¢ver f¢rst å lese standard valgfil
fra aktiv katalog. Hvis dette skjærer seg, så pr¢v å les
standard valgfil fra program-katalog. */
{
char cPath1[MAXPATH];
char cPath2[MAXPATH];
strcpy (cPath1, BigStr (3, progdir, fnames[DEFOPT_FNAME], fnames[SMGOPTI_EXT]));
cPath2[0] = (char) (GetDisk () + 'A');
cPath2[1] = '\0';
strcat (cPath2, BigStr (2, ":", DIRSPLITSTR));
GetCurDir (0, cPath2 + 3);
strcat (cPath2, fnames[DEFOPT_FNAME]);
strcat (cPath2, fnames[SMGOPTI_EXT]);
/* Les standard valg fra program-katalog (overse eventuelle feil) */
read_options (cPath1);
/* Be sure not to read the same file twice!
(In case current dir = SM program dir) */
#if defined (__MSDOS__) || defined (__OS2__)
if (strcmpi (cPath1, cPath2) != 0) /* File system is not case significant */
#else
if (strcmp (cPath1, cPath2) != 0)
#endif
{
/* Lese standard valg fra aktiv katalog (overse eventuell feil) */
read_options (cPath2);
}
ErrorClear (); /* Clear eventually flagged error */
} /* read_default_options (); */