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

  1. /* ------------------------------------------------------------------------
  2.  *
  3.  *        File: smgtotin.c
  4.  *     Project: Source Mapper.
  5.  *     Created: September 21, 1992.
  6.  * Description: Kildekode for å skrive totalinformasjon til endelig kartfil.
  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. #define TOTINFCOL 8   /* Kolonneavstand mellom kildefilers totalinformasjon */
  30.  
  31.  
  32.  
  33.  
  34. int wrt_totinfo ( FILE *mapf )
  35. /* Opprettet: S¢ndag 20. september 1992.
  36.    Parameter: "mapf" Endelig kartfil.
  37.    Retur    : E/O.
  38.    Beskriv  : Skriver totalinformasjon til aktivt prosjekt.
  39.               Det forutsettes at aktuell fil er åpnet og klar for skriving.
  40. */
  41. {
  42.    if (!prjstat.prjon)                 /* Hvis ikke noe aktivt prosjekt */
  43.       return (ERROR);
  44.  
  45.    /* Inkluderer totalinformasjon */
  46.    Display (D_HEIGH, "%s", _StrMSGINCLTOTINFO);
  47.  
  48.    if (prjstat.filc == 1)              /* Hvis bare én kildefil i prosjekt */
  49.       return (wrt_totinfo1 (mapf, 1));
  50.    else                                /* Hvis fler enn én kildefil i prosj. */
  51.       return (wrt_totinfo2 (mapf));
  52. } /* wrt_totinfo (); */
  53.  
  54.  
  55.  
  56.  
  57. int wrt_totinfo1 ( FILE *file, int fnr )
  58. /* Opprettet: S¢ndag 20. september 1992.
  59.    Parameter: "file" Filen det skal skrives til.
  60.               "fnr"  Nummer til kildefil i prosjekt som det skal skrives
  61.                      totalinformasjon om (1..).
  62.    Retur    : E/O.
  63.    Beskriv  : Skriver totalinformasjon om en eneste kildefil i aktivt
  64.               prosjekt.
  65.               Det forutsettes at aktuell fil er åpnet og klar for skriving.
  66. */
  67. {
  68.    int dummy;
  69.    prjfeTYPE fdata;                    /* Prosjektdata om kildefil */
  70.  
  71.    if (!GetFDataFromPrj (fnr, &fdata)) /* Les kildefilnavn */
  72.       RETURN_ERR;
  73.  
  74.    WrtStdLinComStart (file, stdwidth, linechr2);
  75.  
  76.    /* Skriv selve totalinformasjonen: */
  77.    if (!wrt_totinfo_ (file, &fdata.finf, GetFName (fdata.name), &dummy))
  78.       RETURN_ERR;
  79.  
  80.    if (o_various.gencom)               /* Hvis SMG-info skal legges i koment.*/
  81.       WrtComEndLn (file);
  82.  
  83.    FPrintF (file, "\n\n\n");           /* Avsluttende linjeskift */
  84.  
  85.    return (OK);
  86. } /* wrt_totinfo1 (); */
  87.  
  88.  
  89.  
  90.  
  91. int wrt_totinfo2 ( FILE *file )
  92. /* Opprettet: S¢ndag 20. september 1992.
  93.    Parameter: "file" Filen det skal skrives til.
  94.    Retur    : E/O.
  95.    Beskriv  : Skriver totalinformasjon om alle kildefilene i aktivt
  96.               prosjekt. Dersom aktivt prosjekt har bare én eneste kildefil
  97.               skal funksjonen "_wrt_totinfo1 ()" brukes istedet for denne.
  98.               Det forutsettes at aktuell fil er åpnet og klar for skriving.
  99. */
  100. {
  101.    int iTemp;
  102.    long ltot;
  103.    int cinf;                           /* Antall info-strenger */
  104.    int c1;                             /* Counter 1 */
  105.    int iLongestFName = 0;              /* Number of chars in longest filename */
  106.    finfTYPE  finftot;                  /* For lagring av global totalinfo */
  107.    prjfeTYPE fdata;                    /* Prosjektdata om kildefil */
  108.  
  109.    if (!WrtStdLinComStart (file, stdwidth, linechr2))
  110.       return (ERROR);
  111.  
  112.    /* Collect total statistics information about whole project */
  113.    reset_finftype (&finftot);          /* Nullstill global totalinfo */
  114.  
  115.    c1 = 0;
  116.    while (c1++ < prjstat.filc)         /* Alle kildefiler i prosjekt */
  117.    {
  118.       if (!GetFDataFromPrj (c1, &fdata)) /* Les kildefilnavn */
  119.          RETURN_ERR;
  120.  
  121.       /* Legg sammen info om kildefil til global totalinfo: */
  122.       finftot.ltot += fdata.finf.ltot;
  123.       finftot.elin += fdata.finf.elin;
  124.       finftot.coml += fdata.finf.coml;
  125.       finftot.codl += fdata.finf.codl;
  126.       finftot.com  += fdata.finf.com;
  127.       finftot.func += fdata.finf.func;
  128.       finftot.dirl += fdata.finf.dirl;
  129.       finftot.fcal += fdata.finf.fcal;
  130.       finftot.cid  += fdata.finf.cid;
  131.  
  132.       /* Find the length of the longest filename */
  133.       iTemp = strlen (GetFName (fdata.name));
  134.       if (iTemp > iLongestFName)
  135.          iLongestFName = iTemp;
  136.    }
  137.  
  138.    /* Column of filenames must newer be less tham 12 chars wide */
  139.    if (iLongestFName < 12)
  140.       iLongestFName = 12;
  141.  
  142.    /* Skriv forklaringer til bokstavlinja over selve totalinformasjonen: */
  143.    if (!wrt_totinfo_ (file, &finftot, NULL, &cinf))
  144.       RETURN_ERR;
  145.  
  146.    FPrintF (file, "\n\n");
  147.  
  148.    /* Hvis det bare er kildefilnavn (og eventuelt linjenummer) som skal
  149.       inngå i totalinformasjonen, så hopp over den del av denne funksjonen
  150.       som tegner bokstavlinja: */
  151.    if (cinf == 'A')
  152.       goto WRT_SOURCEFILE_REGISTER;
  153.  
  154.    /* Skriv bokstavlinja som skal være over totalinformasjonen: */
  155.    c1 = 'A';                          /* A = f¢rste info-streng */
  156.    WritFLine (file, 7, ' ');
  157.    FPrintF (file, "%c:", c1);
  158.    WritFLine (file, iLongestFName, ' ');
  159.  
  160.    /* Skriv resten av bokstavlinja, d.v.s. fra om med B: --->: */
  161.    while (c1 < cinf)                   /* Antall info-strenger */
  162.    {
  163.       if (!FPrintF (file, "%c:", ++c1) ||
  164.           WritFLine (file, TOTINFCOL - 2, ' ') != TOTINFCOL - 2)
  165.       {
  166.          return (ERROR);
  167.       }
  168.    }
  169.  
  170.    /* Skriv info om global linjestart i bokstavlinjen: */
  171.    if (!FPrintF (file, "%s:\n", _StrMSGGLOBLINSTART))
  172.       return (ERROR);
  173.  
  174.    /* Skriv strek under bokstavlinja: */
  175.    if (WritFLineLn (file, stdwidth, linechr1) != stdwidth + 2)
  176.       return (ERROR);
  177.  
  178. WRT_SOURCEFILE_REGISTER:
  179.  
  180.    c1 = 0;
  181.    ltot = 0;
  182.    while (c1++ < prjstat.filc)         /* Alle kildefiler i prosjekt */
  183.    {
  184.       if (!GetFDataFromPrj (c1, &fdata)) /* Les kildefilnavn */
  185.          RETURN_ERR;
  186.  
  187.       /* Skriv selve totalinformasjonen: */
  188.       if (!wrt_totinfo2_ (file, &fdata.finf, c1, GetFName (fdata.name), iLongestFName))
  189.          RETURN_ERR;
  190.  
  191.       /* Skriv eventuell info om globalt linjenummer til aktiv kildefil: */
  192.       FPrintF (file, "%c-%ld\n", GLOBLINCHR, ltot + 1);
  193.       ltot += fdata.finf.ltot;
  194.    }
  195.  
  196.    /* Hvis det bare er kildefilnavn (og eventuelt linjenummer) som ble
  197.       inkludert i totalinformasjonen, så hopp over den del av denne
  198.       funksjonen som skriver global totalinformasjon: */
  199.    if (cinf == 'A')
  200.       goto WRT_ENDING_LINE;
  201.  
  202.    /* Skriv strek under kildefilenes totalinfo: */
  203.    if (WritFLineLn (file, stdwidth, linechr1) != stdwidth + 2)
  204.       return (ERROR);
  205.  
  206.    /* Skriv global totalinformasjon: */
  207.    if (!wrt_totinfo2_ (file, &finftot, 0, _StrMSGTOTALYSTR, iLongestFName))
  208.       RETURN_ERR;
  209.  
  210.    FPrintF (file, "\n");
  211.  
  212. WRT_ENDING_LINE:
  213.  
  214.    /* Skriv strek under globale totalinfo m/eventuell komentarslutt: */
  215.    WrtStdLinComEnd (file, stdwidth, linechr2);
  216.    FPrintF (file, "\n\n\n");
  217.  
  218.    return (OK);
  219. } /* wrt_totinfo2 (); */
  220.  
  221.  
  222.  
  223.  
  224. int wrt_totinfo2_ ( FILE *file, finfTYPE *finf, int fnr,
  225.                     const char *sfname, int iLongestFName )
  226. /* Opprettet: Mandag 21. september 1992.
  227.    Parameter: "file"   Filen det skal skrives til.
  228.               "finf"   Aktuell filinformasjon som skal skrives.
  229.               "fnr"    Nummer til aktiv kildefil.
  230.               "sfname" Navn til aktuell kildefil.
  231.               "iLongestFName" Length of longest filename in list.
  232.    Retur    : E/O.
  233.    Beskriv  : Dette er kjernen til "_wrt_totinfo2 ()". Det er altså denne
  234.               funksjonen som gj¢r selve arbeidet med å skrive den leste
  235.               totalinformasjon, om aktiv kildefil, til kartfilen.
  236.               "sfname" må bare holde selve navnet til filen, altså ikke
  237.               drev og/eller katalog. Ellers returneres error.
  238.               Det forutsettes at aktuell fil er åpnet og klar for skriving.
  239.               Funksjonen erstatter skriving av filnummer med mellomrom
  240.               dersom "fnr" er 0. Dette er for bruk når funksjonen skal
  241.               brukes til å skrive global totalinformasjon.
  242. */
  243. {
  244.    int len;                            /* Lengden til totalinfo-streng */
  245.  
  246.    /* Skriv nummer til aktiv kildefil: */
  247.    if (fnr > 0)
  248.    {
  249.       len = 7 - 2 - StrLenSI (fnr);
  250.       FPrintF (file, "%c-%d", FILECHR, fnr);
  251.       WritFLine (file, len, ' ');
  252.    }
  253.    else
  254.    {
  255.       WritFLine (file, 7, ' ');
  256.    }
  257.  
  258.    /* Skriv filnavnet til oppgitt kildefil: */
  259.    len = iLongestFName + 2 - strlen (sfname);
  260.    FPrintF (file, "%s", sfname);
  261.    WritFLine (file, len, ' ');
  262.  
  263.    if (o_totinfo.lin_tot)
  264.    {
  265.       len = TOTINFCOL - StrLenSL (finf->ltot);
  266.       if (!FPrintF (file, "%ld", finf->ltot) ||
  267.           WritFLine (file, len, ' ') != len)
  268.       {
  269.          return (ERROR);
  270.       }
  271.    }
  272.  
  273.    if (o_totinfo.lin_emp)
  274.    {
  275.       len = TOTINFCOL - StrLenSL (finf->elin);
  276.       if (!FPrintF (file, "%ld", finf->elin) ||
  277.           WritFLine (file, len, ' ') != len)
  278.       {
  279.          return (ERROR);
  280.       }
  281.    }
  282.  
  283.    if (o_totinfo.lin_com)
  284.    {
  285.       len  = TOTINFCOL - StrLenSL (finf->coml);
  286.       if (!FPrintF (file, "%ld", finf->coml) ||
  287.           WritFLine (file, len, ' ') != len)
  288.       {
  289.          return (ERROR);
  290.       }
  291.    }
  292.  
  293.    if (o_totinfo.lin_cod)
  294.    {
  295.       len = TOTINFCOL - StrLenSL (finf->codl);
  296.       if (!FPrintF (file, "%ld", finf->codl) ||
  297.           WritFLine (file, len, ' ') != len)
  298.       {
  299.          return (ERROR);
  300.       }
  301.    }
  302.  
  303.    if (o_totinfo.func)
  304.    {
  305.       len = TOTINFCOL - StrLenSL (finf->func);
  306.       if (!FPrintF (file, "%ld", finf->func) ||
  307.           WritFLine (file, len, ' ') != len)
  308.       {
  309.          return (ERROR);
  310.       }
  311.    }
  312.  
  313.    if (o_totinfo.com)
  314.    {
  315.       len = TOTINFCOL - StrLenSL (finf->com);
  316.       if (!FPrintF (file, "%ld", finf->com) ||
  317.           WritFLine (file, len, ' ') != len)
  318.       {
  319.          return (ERROR);
  320.       }
  321.    }
  322.  
  323.    return (OK);
  324. } /* wrt_totinfo2_ (); */
  325.  
  326.  
  327.  
  328.  
  329. int max_totinf_strlen ( void )
  330. /* Opprettet: Torsdag 24. september 1992.
  331.    Parameter:
  332.    Retur    : Lengden til den lengste av strengene som beskriver kartfilens
  333.               totalinformasjon.
  334.    Beskriv  :
  335. */
  336. {
  337.    int len = 0;                        /* Lengden til aktiv streng */
  338.    int lenmax;                         /* Lengden til hitill lengste streng */
  339.  
  340.    /* Navn til kildefil: */
  341.    lenmax = strlen (_StrMSGTOTINF_SNAME);
  342.  
  343.    /* Antall linjer totalt: */
  344.    if (o_totinfo.lin_tot &&
  345.        (len = strlen (_StrMSGTOTINF_LINTOT)) > lenmax)
  346.    {
  347.       lenmax = len;
  348.    }
  349.  
  350.    /* Antall tomme linjer: */
  351.    if (o_totinfo.lin_emp &&
  352.        (len = strlen (_StrMSGTOTINF_EMPLIN)) > lenmax)
  353.    {
  354.       lenmax = len;
  355.    }
  356.  
  357.    /* Antall komentarlinjer: */
  358.    if (o_totinfo.lin_com &&
  359.        (len = strlen (_StrMSGTOTINF_COMLIN)) > lenmax)
  360.    {
  361.       lenmax = len;
  362.    }
  363.  
  364.    /* Antall linjer med kode: */
  365.    if (o_totinfo.lin_cod &&
  366.        (len = strlen (_StrMSGTOTINF_CODLIN)) > lenmax)
  367.    {
  368.       lenmax = len;
  369.    }
  370.  
  371.    /* Antall funksjoner: */
  372.    if (o_totinfo.func &&
  373.        (len = strlen (_StrMSGTOTINF_FUNTOT)) > lenmax)
  374.    {
  375.       lenmax = len;
  376.    }
  377.  
  378.    /* Antall funksjoner: */
  379.    if (o_totinfo.com &&
  380.        (len = strlen (_StrMSGTOTINF_COMENT)) > lenmax)
  381.    {
  382.       lenmax = len;
  383.    }
  384.  
  385.    return (lenmax);
  386. } /* max_totinf_strlen (); */
  387.  
  388.  
  389.  
  390.  
  391. int wrt_totinfo_ ( FILE *file, finfTYPE *finf, const char *sfname, int *cinf )
  392. /* Opprettet: Mandag 21. september 1992.
  393.    Parameter: "file"   Filen det skal skrives til.
  394.               "finf"   Aktuell filinformasjon som skal skrives.
  395.               "sfname" Navn til aktuell kildefil, u/drev katalog.
  396.                        Hvis denne er NULL vill vi anta at "finf" er
  397.                        statistikk over hele prosjektet og at det
  398.                        derfor skal skrives totalinformasjon om
  399.                        et prosjekt bestående av flere kildefiler.
  400.               "cinf"   Returnerer antall elementer i totalinfo-hodet.
  401.    Retur    : E/O.
  402.    Beskriv  : Dette er kjernen til "_wrt_totinfo1 ()". Det er altså denne
  403.               funksjonen som gj¢r selve arbeidet med å skrive
  404.               totalinformasjon om den eneste kildefil i aktivt
  405.               prosjekt.
  406.               Det forutsettes at aktuell fil er åpnet og klar for skriving.
  407. */
  408. {
  409.    int lenmax;
  410.  
  411.    *cinf = 'A';                        /* F¢rste bokstavforklaring er 'A' */
  412.  
  413.    /* Hvis bruker har satt valg slik at totalinfo ikke skal bestå av noe
  414.       annet enn kildefilnavn (og eventuel linjenummer), så skal ikke
  415.       denne funksjonen skrive noen forklaringer i det hele tatt. */
  416.  
  417.    if (!sfname && /* Hvis totalinfo om prosjekt med fler kildefiler */
  418.        !o_totinfo.lin_tot &&
  419.        !o_totinfo.lin_emp &&
  420.        !o_totinfo.lin_com &&
  421.        !o_totinfo.lin_cod &&
  422.        !o_totinfo.func &&
  423.        !o_totinfo.com)
  424.    {
  425.       return (OK);
  426.    }
  427.  
  428.    lenmax = max_totinf_strlen ();      /* Lengden til lengste totinfo-streng */
  429.  
  430.    if (sfname)
  431.    {
  432.       FPrintF (file, "\n%s", _StrMSGTOTINF_SNAME);
  433.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_SNAME), '.');
  434.       FPrintF (file, ": %s", sfname);
  435.    }
  436.    else
  437.    {
  438.       FPrintF (file, "\n%c = %s", *cinf, _StrMSGTOTINF_SNAME);
  439.    }
  440.  
  441.    if (o_totinfo.lin_tot)
  442.    {
  443.       FPrintF (file, "\n");
  444.       if (!sfname)
  445.       {
  446.          FPrintF (file, "%c = ", ++(*cinf));
  447.       }
  448.       FPrintF (file, "%s", _StrMSGTOTINF_LINTOT);
  449.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_LINTOT), '.');
  450.       FPrintF (file, ": %ld", finf->ltot);
  451.    }
  452.  
  453.    if (o_totinfo.lin_emp)
  454.    {
  455.       FPrintF (file, "\n");
  456.       if (!sfname)
  457.       {
  458.          FPrintF (file, "%c = ", ++(*cinf));
  459.       }
  460.       FPrintF (file, "%s", _StrMSGTOTINF_EMPLIN);
  461.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_EMPLIN), '.');
  462.       FPrintF (file, ": %u", finf->elin);
  463.       if (finf->ltot > 0)              /* Unngå evnt. "Divide by zero"       */
  464.       {
  465.          if (!FPrintF (file, " (%d%%)", ((long) finf->elin * 100) / finf->ltot))
  466.             return (ERROR);
  467.       }
  468.    }
  469.  
  470.    if (o_totinfo.lin_com)
  471.    {
  472.       FPrintF (file, "\n");
  473.       if (!sfname)
  474.       {
  475.          FPrintF (file, "%c = ", ++(*cinf));
  476.       }
  477.       FPrintF (file, "%s", _StrMSGTOTINF_COMLIN);
  478.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_COMLIN), '.');
  479.       FPrintF (file, ": %ld", finf->coml);
  480.       if (finf->ltot > 0)              /* Unngå evnt. "Divide by zero"       */
  481.       {
  482.          if (!FPrintF (file, " (%d%%)", ((long) finf->coml * 100) / finf->ltot))
  483.             return (ERROR);
  484.       }
  485.    }
  486.  
  487.    if (o_totinfo.lin_cod)
  488.    {
  489.       FPrintF (file, "\n");
  490.       if (!sfname)
  491.       {
  492.          FPrintF (file, "%c = ", ++(*cinf));
  493.       }
  494.       FPrintF (file, "%s", _StrMSGTOTINF_CODLIN);
  495.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_CODLIN), '.');
  496.       FPrintF (file, ": %ld", finf->codl);
  497.       if (finf->ltot > 0)              /* Unngå evnt. "Divide by zero"       */
  498.       {
  499.          if (!FPrintF (file, " (%d%%)", ((long) finf->codl * 100) / finf->ltot))
  500.             return (ERROR);
  501.       }
  502.    }
  503.  
  504.    if (o_totinfo.func)
  505.    {
  506.       FPrintF (file, "\n");
  507.       if (!sfname)
  508.       {
  509.          FPrintF (file, "%c = ", ++(*cinf));
  510.       }
  511.       FPrintF (file, "%s", _StrMSGTOTINF_FUNTOT);
  512.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_FUNTOT), '.');
  513.       FPrintF (file, ": %ld", finf->func);
  514.    }
  515.  
  516.    if (o_totinfo.com)
  517.    {
  518.       FPrintF (file, "\n");
  519.       if (!sfname)
  520.       {
  521.          FPrintF (file, "%c = ", ++(*cinf));
  522.       }
  523.       FPrintF (file, "%s", _StrMSGTOTINF_COMENT);
  524.       WritFLine (file, lenmax - strlen (_StrMSGTOTINF_COMENT), '.');
  525.       FPrintF (file, ": %ld", finf->com);
  526.    }
  527.  
  528.    if (errno != 0)
  529.       return (ERROR);
  530.  
  531.    return (OK);
  532. } /* wrt_totinfo_ (); */
  533.  
  534.  
  535.