LCOV - code coverage report
Current view: top level - desktop/unx/source - args.c (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 44 45 97.8 %
Date: 2014-04-14 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      255086 : is_env_arg (rtl_uString *str)
      18             : {
      19      255086 :     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       42505 : Args *args_parse (void)
      59             : {
      60             :     Args *args;
      61             :     sal_uInt32 nArgs, i, j;
      62             : 
      63       42505 :     nArgs = osl_getCommandArgCount();
      64       42505 :     i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
      65       42505 :     args = malloc (i);
      66       42505 :     memset (args, 0, i);
      67       42505 :     args->nArgsTotal = nArgs;
      68             : 
      69       42505 :     j = 0;
      70             : 
      71             :     /* sort the -env: args to the front */
      72      170048 :     for ( i = 0; i < nArgs; ++i )
      73             :     {
      74      127543 :         rtl_uString *pTmp = NULL;
      75      127543 :         osl_getCommandArg( i, &pTmp );
      76      127543 :         if (is_env_arg (pTmp))
      77           7 :             args->ppArgs[j++] = pTmp;
      78             :         else
      79      127536 :             rtl_uString_release (pTmp);
      80             :     }
      81       42505 :     args->nArgsEnv = j;
      82             : 
      83             :     /* Then the other args */
      84      170048 :     for ( i = 0; i < nArgs; ++i )
      85             :     {
      86      127543 :         rtl_uString *pTmp = NULL;
      87             : 
      88      127543 :         osl_getCommandArg( i, &pTmp );
      89      127543 :         if (!is_env_arg (pTmp))
      90      127536 :             args->ppArgs[j++] = pTmp;
      91             :         else
      92           7 :             rtl_uString_release (pTmp);
      93             :     }
      94             : 
      95      170041 :     for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
      96             :     {
      97      127536 :         const sal_Unicode *arg = args->ppArgs[i]->buffer;
      98      127536 :         sal_Int32 length = args->ppArgs[i]->length;
      99             : 
     100             :         /* grok only parameters */
     101      127536 :         if (arg[0] != '-')
     102       42498 :             continue;
     103             : 
     104      340152 :         while (length > 2 && arg[0] == '-') {
     105      170076 :             arg++;
     106      170076 :             length--;
     107             :         }
     108             : 
     109      850457 :         for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
     110      807931 :             if (rtl_ustr_ascii_compare_WithLength(
     111      807931 :                     arg, length, pArgDescr[j].name)
     112             :                 == 0)
     113             :             {
     114       42512 :                 args->bInhibitSplash  |= pArgDescr[j].bInhibitSplash;
     115       42512 :                 args->bInhibitPagein  |= pArgDescr[j].bInhibitPagein;
     116       42512 :                 args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
     117       42512 :                 args->bInhibitPipe    |= pArgDescr[j].bInhibitPipe;
     118       42512 :                 if (pArgDescr[j].pPageinType)
     119           0 :                     args->pPageinType = pArgDescr[j].pPageinType;
     120       42512 :                 break;
     121             :             }
     122             :         }
     123             :     }
     124             : 
     125       42505 :     return args;
     126             : }
     127             : 
     128             : void
     129       42505 : args_free (Args *args)
     130             : {
     131             :     /* FIXME: free ppArgs */
     132       42505 :     rtl_uString_release( args->pAppPath );
     133       42505 :     free (args);
     134       42505 : }
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10