LCOV - code coverage report
Current view: top level - desktop/unx/source - args.c (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 45 95.6 %
Date: 2014-11-03 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : #include <stdlib.h>
      10             : #include <string.h>
      11             : #include <osl/process.h>
      12             : 
      13             : #include "args.h"
      14             : 
      15             : /* do we start -env: */
      16             : static int
      17        1540 : is_env_arg (rtl_uString *str)
      18             : {
      19        1540 :     return !rtl_ustr_ascii_compare_WithLength (str->buffer, 5, "-env:");
      20             : }
      21             : 
      22             : static struct {
      23             :     const char   *name;
      24             :     unsigned int  bTwoArgs : 1;
      25             :     unsigned int  bInhibitSplash : 1;
      26             :     unsigned int  bInhibitPagein : 1;
      27             :     unsigned int  bInhibitJavaLdx : 1;
      28             :     unsigned int  bInhibitPipe : 1;
      29             :     const char   *pPageinType;
      30             : } pArgDescr[] = {
      31             :     /* have a trailing argument */
      32             :     { "pt",         1, 0, 0, 0, 0, NULL },
      33             :     { "display",    1, 0, 0, 0, 0, NULL },
      34             : 
      35             :     /* no splash */
      36             :     { "nologo",     0, 1, 0, 0, 0, NULL },
      37             :     { "headless",   0, 1, 0, 0, 0, NULL },
      38             :     { "invisible",  0, 1, 0, 0, 0, NULL },
      39             :     { "quickstart", 0, 1, 0, 0, 0, NULL },
      40             :     { "minimized",  0, 1, 0, 0, 0, NULL },
      41             : 
      42             :     /* pagein bits */
      43             :     { "writer",     0, 0, 0, 0, 0, "pagein-writer"  },
      44             :     { "calc",       0, 0, 0, 0, 0, "pagein-calc"    },
      45             :     { "draw",       0, 0, 0, 0, 0, "pagein-draw"    },
      46             :     { "impress",    0, 0, 0, 0, 0, "pagein-impress" },
      47             : 
      48             :     /* Do not send --help/--version over the pipe, as their output shall go to
      49             :        the calling process's stdout (ideally, this would also happen in the
      50             :        presence of unknown options); also prevent splash/pagein/javaldx overhead
      51             :        (as these options will be processed early in soffice_main): */
      52             :     { "version",    0, 1, 1, 1, 1, NULL },
      53             :     { "help",       0, 1, 1, 1, 1, NULL },
      54             :     { "h",          0, 1, 1, 1, 1, NULL },
      55             :     { "?",          0, 1, 1, 1, 1, NULL },
      56             : };
      57             : 
      58          96 : Args *args_parse (void)
      59             : {
      60             :     Args *args;
      61             :     sal_uInt32 nArgs, i, j;
      62             : 
      63          96 :     nArgs = osl_getCommandArgCount();
      64          96 :     i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
      65          96 :     args = malloc (i);
      66          96 :     memset (args, 0, i);
      67          96 :     args->nArgsTotal = nArgs;
      68             : 
      69          96 :     j = 0;
      70             : 
      71             :     /* sort the -env: args to the front */
      72         866 :     for ( i = 0; i < nArgs; ++i )
      73             :     {
      74         770 :         rtl_uString *pTmp = NULL;
      75         770 :         osl_getCommandArg( i, &pTmp );
      76         770 :         if (is_env_arg (pTmp))
      77         194 :             args->ppArgs[j++] = pTmp;
      78             :         else
      79         576 :             rtl_uString_release (pTmp);
      80             :     }
      81          96 :     args->nArgsEnv = j;
      82             : 
      83             :     /* Then the other args */
      84         866 :     for ( i = 0; i < nArgs; ++i )
      85             :     {
      86         770 :         rtl_uString *pTmp = NULL;
      87             : 
      88         770 :         osl_getCommandArg( i, &pTmp );
      89         770 :         if (!is_env_arg (pTmp))
      90         576 :             args->ppArgs[j++] = pTmp;
      91             :         else
      92         194 :             rtl_uString_release (pTmp);
      93             :     }
      94             : 
      95         672 :     for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
      96             :     {
      97         576 :         const sal_Unicode *arg = args->ppArgs[i]->buffer;
      98         576 :         sal_Int32 length = args->ppArgs[i]->length;
      99             : 
     100             :         /* grok only parameters */
     101         576 :         if (arg[0] != '-')
     102           0 :             continue;
     103             : 
     104        2304 :         while (length > 2 && arg[0] == '-') {
     105        1152 :             arg++;
     106        1152 :             length--;
     107             :         }
     108             : 
     109        6816 :         for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
     110        6432 :             if (rtl_ustr_ascii_compare_WithLength(
     111        6432 :                     arg, length, pArgDescr[j].name)
     112             :                 == 0)
     113             :             {
     114         192 :                 args->bInhibitSplash  |= pArgDescr[j].bInhibitSplash;
     115         192 :                 args->bInhibitPagein  |= pArgDescr[j].bInhibitPagein;
     116         192 :                 args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
     117         192 :                 args->bInhibitPipe    |= pArgDescr[j].bInhibitPipe;
     118         192 :                 if (pArgDescr[j].pPageinType)
     119           0 :                     args->pPageinType = pArgDescr[j].pPageinType;
     120         192 :                 break;
     121             :             }
     122             :         }
     123             :     }
     124             : 
     125          96 :     return args;
     126             : }
     127             : 
     128             : void
     129          96 : args_free (Args *args)
     130             : {
     131             :     /* FIXME: free ppArgs */
     132          96 :     rtl_uString_release( args->pAppPath );
     133          96 :     free (args);
     134          96 : }
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10