~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to cmddata.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "rar.hpp"
2
2
 
3
 
 
4
3
CommandData::CommandData()
5
4
{
6
5
  Init();
14
13
  *Command=0;
15
14
  *ArcName=0;
16
15
  FileLists=false;
17
 
  NoMoreSwitches=false;
18
16
 
19
17
  ListMode=RCLM_AUTO;
20
18
 
45
43
}
46
44
 
47
45
 
48
 
#ifndef SFX_MODULE
 
46
#if !defined(SFX_MODULE) && !defined(_ANDROID)
49
47
void CommandData::ParseCommandLine(bool Preprocess,int argc, char *argv[])
50
48
{
 
49
  *Command=0;
 
50
  NoMoreSwitches=false;
51
51
#ifdef CUSTOM_CMDLINE_PARSER
52
52
  // In Windows we may prefer to implement our own command line parser
53
53
  // to avoid replacing \" by " in standard parser. Such replacing corrupts
59
59
  {
60
60
    if ((CmdLine=AllocCmdParam(CmdLine,&Par))==NULL)
61
61
      break;
62
 
    bool Code=true;
63
62
    if (!FirstParam) // First parameter is the executable name.
64
63
      if (Preprocess)
65
 
        Code=PreprocessSwitch(Par);
 
64
        PreprocessArg(Par);
66
65
      else
67
66
        ParseArg(Par);
68
67
    free(Par);
69
 
    if (Preprocess && !Code)
70
 
      break;
71
68
  }
72
69
#else
73
70
  Array<wchar> Arg;
76
73
    Arg.Alloc(strlen(argv[I])+1);
77
74
    CharToWide(argv[I],&Arg[0],Arg.Size());
78
75
    if (Preprocess)
79
 
    {
80
 
      if (!PreprocessSwitch(&Arg[0]))
81
 
        break;
82
 
    }
 
76
      PreprocessArg(&Arg[0]);
83
77
    else
84
78
      ParseArg(&Arg[0]);
85
79
  }
90
84
#endif
91
85
 
92
86
 
93
 
#ifndef SFX_MODULE
 
87
#if !defined(SFX_MODULE) && !defined(_ANDROID)
94
88
void CommandData::ParseArg(wchar *Arg)
95
89
{
96
90
  if (IsSwitch(*Arg) && !NoMoreSwitches)
97
 
    if (Arg[1]=='-')
 
91
    if (Arg[1]=='-' && Arg[2]==0)
98
92
      NoMoreSwitches=true;
99
93
    else
100
94
      ProcessSwitch(Arg+1);
182
176
}
183
177
 
184
178
 
185
 
#ifndef SFX_MODULE
 
179
#if !defined(SFX_MODULE) && !defined(_ANDROID)
186
180
void CommandData::ParseEnvVar()
187
181
{
188
182
  char *EnvStr=getenv("RAR");
197
191
 
198
192
 
199
193
 
200
 
#ifndef SFX_MODULE
 
194
#if !defined(SFX_MODULE) && !defined(_ANDROID)
201
195
// Preprocess those parameters, which must be processed before the rest of
202
196
// command line. Return 'false' to stop further processing.
203
 
bool CommandData::PreprocessSwitch(const wchar *Switch)
 
197
void CommandData::PreprocessArg(const wchar *Arg)
204
198
{
205
 
  if (IsSwitch(Switch[0]))
 
199
  if (IsSwitch(Arg[0]) && !NoMoreSwitches)
206
200
  {
207
 
    Switch++;
208
 
    char SwitchA[1024];
209
 
    WideToChar(Switch,SwitchA,ASIZE(SwitchA));
210
 
    if (wcsicomp(Switch,L"-")==0) // Switch "--".
211
 
      return false;
212
 
    if (wcsicomp(Switch,L"cfg-")==0)
 
201
    Arg++;
 
202
    if (Arg[0]=='-' && Arg[1]==0) // Switch "--".
 
203
      NoMoreSwitches=true;
 
204
    if (wcsicomp(Arg,L"cfg-")==0)
213
205
      ConfigDisabled=true;
214
206
#ifndef GUI
215
 
    if (wcsnicomp(Switch,L"ilog",4)==0)
 
207
    if (wcsnicomp(Arg,L"ilog",4)==0)
216
208
    {
217
209
      // Ensure that correct log file name is already set
218
210
      // if we need to report an error when processing the command line.
219
 
      ProcessSwitch(Switch);
 
211
      ProcessSwitch(Arg);
220
212
      InitLogOptions(LogName,ErrlogCharset);
221
213
    }
222
214
#endif
223
 
    if (wcsnicomp(Switch,L"sc",2)==0)
 
215
    if (wcsnicomp(Arg,L"sc",2)==0)
224
216
    {
225
217
      // Process -sc before reading any file lists.
226
 
      ProcessSwitch(Switch);
 
218
      ProcessSwitch(Arg);
227
219
#ifndef GUI
228
220
      if (*LogName!=0)
229
221
        InitLogOptions(LogName,ErrlogCharset);
230
222
#endif
231
223
    }
232
224
  }
233
 
  return true;
 
225
  else
 
226
    if (*Command==0)
 
227
      wcsncpy(Command,Arg,ASIZE(Command)); // Need for rar.ini.
234
228
}
235
229
#endif
236
230
 
237
231
 
238
 
#if !defined(GUI) && !defined(SFX_MODULE)
 
232
#if !defined(GUI) && !defined(SFX_MODULE) && !defined(_ANDROID)
239
233
void CommandData::ReadConfig()
240
234
{
241
235
  StringList List;
248
242
        Str++;
249
243
      if (wcsnicomp(Str,L"switches=",9)==0)
250
244
        ProcessSwitchesString(Str+9);
 
245
      if (*Command!=0)
 
246
      {
 
247
        wchar Cmd[16];
 
248
        wcsncpyz(Cmd,Command,ASIZE(Cmd));
 
249
        wchar C0=toupperw(Cmd[0]);
 
250
        wchar C1=toupperw(Cmd[1]);
 
251
        if (C0=='I' || C0=='L' || C0=='M' || C0=='S' || C0=='V')
 
252
          Cmd[1]=0;
 
253
        if (C0=='R' && (C1=='R' || C1=='V'))
 
254
          Cmd[2]=0;
 
255
        wchar SwName[16+ASIZE(Cmd)];
 
256
        swprintf(SwName,ASIZE(SwName),L"switches_%s=",Cmd);
 
257
        size_t Length=wcslen(SwName);
 
258
        if (wcsnicomp(Str,SwName,Length)==0)
 
259
          ProcessSwitchesString(Str+Length);
 
260
      }
251
261
    }
252
262
  }
253
263
}
254
264
#endif
255
265
 
256
266
 
257
 
#ifndef SFX_MODULE
 
267
#if !defined(SFX_MODULE) && !defined(_ANDROID)
258
268
void CommandData::ProcessSwitchesString(const wchar *Str)
259
269
{
260
270
  wchar *Par;
268
278
#endif
269
279
 
270
280
 
271
 
#if !defined(SFX_MODULE)
 
281
#if !defined(SFX_MODULE) && !defined(_ANDROID)
272
282
void CommandData::ProcessSwitch(const wchar *Switch)
273
283
{
274
284
 
366
376
              break;
367
377
          }
368
378
          break;
369
 
        case 'E':
370
 
          ProcessEA=false;
371
 
          break;
372
379
        default:
373
380
          if (Switch[1]=='+')
374
381
          {
375
 
            InclFileAttr=GetExclAttr(Switch+2);
 
382
            InclFileAttr|=GetExclAttr(Switch+2);
376
383
            InclAttrSet=true;
377
384
          }
378
385
          else
379
 
            ExclFileAttr=GetExclAttr(Switch+1);
 
386
            ExclFileAttr|=GetExclAttr(Switch+1);
380
387
          break;
381
388
      }
382
389
      break;
399
406
          else
400
407
            if (!Password.IsSet())
401
408
            {
402
 
              GetPassword(PASSWORD_GLOBAL,NULL,&Password);
 
409
              uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password);
403
410
              eprintf(L"\n");
404
411
            }
405
412
          break;
534
541
                Names++;
535
542
              wchar Mask[NM];
536
543
              if (wcspbrk(Names,L"*?.")==NULL)
537
 
                swprintf(Mask,ASIZE(Mask),L"*.%s",Names);
 
544
                swprintf(Mask,ASIZE(Mask),L"*.%ls",Names);
538
545
              else
539
546
                wcsncpyz(Mask,Names,ASIZE(Mask));
540
547
              StoreArgs.AddString(Mask);
609
616
#ifdef SAVE_LINKS
610
617
        case 'L':
611
618
          SaveSymLinks=true;
 
619
          if (toupperw(Switch[2])=='A')
 
620
            AbsoluteLinks=true;
612
621
          break;
613
622
#endif
614
623
        case 'R':
630
639
    case 'P':
631
640
      if (Switch[1]==0)
632
641
      {
633
 
        GetPassword(PASSWORD_GLOBAL,NULL,&Password);
 
642
        uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password);
634
643
        eprintf(L"\n");
635
644
      }
636
645
      else
885
894
#endif
886
895
 
887
896
 
888
 
#ifndef SFX_MODULE
 
897
#if !defined(SFX_MODULE) && !defined(_ANDROID)
889
898
void CommandData::BadSwitch(const wchar *Switch)
890
899
{
891
900
  mprintf(St(MUnknownOption),Switch);
931
940
  // If MSGID is const char*, we cannot compare pointers only.
932
941
  // Pointers to different instances of same string can differ,
933
942
  // so we need to compare complete strings.
934
 
  return strcmp(i1,i2)==0;
 
943
  return wcscmp(i1,i2)==0;
935
944
#endif
936
945
}
937
946
 
951
960
    MCHelpSwCm,MCHelpSwCFGm,MCHelpSwCL,MCHelpSwCU,
952
961
    MCHelpSwDH,MCHelpSwEP,MCHelpSwEP3,MCHelpSwF,MCHelpSwIDP,MCHelpSwIERR,
953
962
    MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwN,MCHelpSwNa,MCHelpSwNal,
954
 
    MCHelpSwO,MCHelpSwOC,MCHelpSwOR,MCHelpSwOW,MCHelpSwP,
955
 
    MCHelpSwPm,MCHelpSwR,MCHelpSwRI,MCHelpSwSL,MCHelpSwSM,MCHelpSwTA,
956
 
    MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr,
957
 
    MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal,MCHelpSwY
 
963
    MCHelpSwO,MCHelpSwOC,MCHelpSwOL,MCHelpSwOR,MCHelpSwOW,MCHelpSwP,
 
964
    MCHelpSwPm,MCHelpSwR,MCHelpSwRI,MCHelpSwSC,MCHelpSwSL,MCHelpSwSM,
 
965
    MCHelpSwTA,MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU,
 
966
    MCHelpSwVUnr,MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal,
 
967
    MCHelpSwY
958
968
#else
959
969
#endif
960
970
  };
995
1005
    if (CmpMSGID(Help[I],MCHelpSwMT))
996
1006
      continue;
997
1007
#endif
998
 
    if (CmpMSGID(Help[I],MCHelpSwEE))
999
 
    {
1000
 
#if defined(_EMX) && !defined(_DJGPP)
1001
 
      if (_osmode != OS2_MODE)
1002
 
        continue;
1003
 
#else
1004
 
      continue;
1005
 
#endif
1006
 
    }
1007
1008
#endif
1008
1009
    mprintf(St(Help[I]));
1009
1010
  }
1022
1023
    return true;
1023
1024
  if (!CheckInclList || InclArgs.ItemsCount()==0)
1024
1025
    return false;
1025
 
  if (ExclCheckArgs(&InclArgs,Dir,CheckName,false,MATCH_WILDSUBPATH))
 
1026
  if (ExclCheckArgs(&InclArgs,Dir,CheckName,CheckFullPath,MATCH_WILDSUBPATH))
1026
1027
    return false;
1027
1028
  return true;
1028
1029
}
1158
1159
 
1159
1160
 
1160
1161
 
1161
 
int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchType)
 
1162
int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchType,
 
1163
                               wchar *MatchedArg,uint MatchedArgSize)
1162
1164
{
 
1165
  if (MatchedArg!=NULL && MatchedArgSize>0)
 
1166
    *MatchedArg=0;
1163
1167
  if (wcslen(FileHead.FileName)>=NM)
1164
1168
    return 0;
1165
1169
  bool Dir=FileHead.Dir;
1180
1184
    {
1181
1185
      if (ExactMatch!=NULL)
1182
1186
        *ExactMatch=wcsicompc(ArgName,FileHead.FileName)==0;
 
1187
      if (MatchedArg!=NULL)
 
1188
        wcsncpyz(MatchedArg,ArgName,MatchedArgSize);
1183
1189
      return StringCount;
1184
1190
    }
1185
1191
  return 0;
1228
1234
    case 'I':
1229
1235
      {
1230
1236
        CmdExtract Extract(this);
1231
 
        Extract.DoExtract(this);
 
1237
        Extract.DoExtract();
1232
1238
      }
1233
1239
      break;
1234
1240
#ifndef SILENT
1334
1340
  if (Format==RARFMT15)
1335
1341
  {
1336
1342
    if (HashType!=HASH_CRC32)
1337
 
    {
1338
 
      mprintf(St(MIncompatSwitch),L"-ht",4);
1339
 
    }
 
1343
      uiMsg(UIERROR_INCOMPATSWITCH,L"-ht",4);
1340
1344
#ifdef _WIN_ALL
1341
1345
    if (SaveSymLinks)
1342
 
    {
1343
 
      mprintf(St(MIncompatSwitch),L"-ol",4);
1344
 
    }
 
1346
      uiMsg(UIERROR_INCOMPATSWITCH,L"-ol",4);
1345
1347
#endif
1346
1348
    if (SaveHardLinks)
1347
 
    {
1348
 
      mprintf(St(MIncompatSwitch),L"-oh",4);
1349
 
    }
 
1349
      uiMsg(UIERROR_INCOMPATSWITCH,L"-oh",4);
1350
1350
 
1351
1351
#ifdef _WIN_ALL
 
1352
    // Do not report a wrong dictionary size here, because we are not sure
 
1353
    // yet about archive format. We can switch to RAR5 mode later
 
1354
    // if we update RAR5 archive.
1352
1355
 
1353
1356
 
1354
1357
#endif
1355
1358
    if (QOpenMode!=QOPEN_AUTO)
1356
 
    {
1357
 
      mprintf(St(MIncompatSwitch),L"-qo",4);
1358
 
    }
1359
 
/*
1360
 
    // We use 64 MB for both formats and reduce it for RAR 4.x later.
1361
 
    if (WinSize>0x400000)
1362
 
    {
1363
 
      wchar SwMD[10];
1364
 
      swprintf(SwMD,ASIZE(SwMD),L"-md%dm",WinSize/0x100000);
1365
 
      mprintf(St(MIncompatSwitch),SwMD,4);
1366
 
    }
1367
 
*/
 
1359
      uiMsg(UIERROR_INCOMPATSWITCH,L"-qo",4);
1368
1360
  }
1369
1361
  if (Format==RARFMT50)
1370
1362
  {