~ubuntu-branches/debian/experimental/mednafen/experimental

« back to all changes in this revision

Viewing changes to src/general.cpp

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2014-11-08 11:36:07 UTC
  • mfrom: (1.2.18) (10.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20141108113607-3lbwsamqqhrso4hp
Tags: 0.9.36.5-1
* New upstream release, uploaded to expermiental for the Jessie freeze.
* Standards-Version 3.9.6, no change required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
static string FileExt;  /* Includes the . character, as in ".nes" */
42
42
static string FileBaseDirectory;
43
43
 
44
 
void MDFNI_SetBaseDirectory(const char *dir)
 
44
void MDFN_SetBaseDirectory(const char *dir)
45
45
{
46
46
 BaseDirectory = string(dir);
47
47
}
48
48
 
 
49
std::string MDFN_GetBaseDirectory(void)
 
50
{
 
51
 return BaseDirectory;
 
52
}
 
53
 
49
54
// Really dumb, maybe we should use boost?
50
55
static bool IsAbsolutePath(const char *path)
51
56
{
104
109
  return(false);
105
110
 
106
111
#if defined(DOS) || defined(WIN32)
107
 
 // TODO: Reserved device names.
 
112
 //
 
113
 // http://support.microsoft.com/kb/74496
 
114
 //
 
115
 {
 
116
  static const char* dev_names[] = 
 
117
  {
 
118
   "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM1", "COM2", "COM3", "COM4", "LPT1", "LPT2", "LPT3", NULL
 
119
  };
108
120
 
 
121
  for(const char** ls = dev_names; *ls != NULL; ls++)
 
122
  {
 
123
   if(!strcasecmp(*ls, path.c_str()))
 
124
    return(false);
 
125
  }
 
126
 }
109
127
#endif
110
128
 
111
129
 return(true);
319
337
                      {
320
338
                       dir = MDFN_GetSettingS("filesys.path_state");
321
339
                       fstring = MDFN_GetSettingS("filesys.fname_state");
322
 
                       fmap['x'] = "mcs";
 
340
                       fmap['x'] = (cd1 ? cd1 : "mcs");
323
341
                      }
324
342
                      else if(type == MDFNMKF_SAV)
325
343
                      {
330
348
 
331
349
                      fmap['X'] = fmap['x'];
332
350
 
333
 
                      if(type != MDFNMKF_SAV)
 
351
                      if(type != MDFNMKF_SAV && !cd1)
334
352
                      {
335
 
                       snprintf(numtmp, sizeof(numtmp), "%d", id1);
 
353
                       trio_snprintf(numtmp, sizeof(numtmp), "%d", id1);
336
354
                       fmap['p'] = std::string(numtmp);
337
355
                      }
338
356
 
367
385
                     std::string fstring = MDFN_GetSettingS("filesys.fname_snap");
368
386
                     std::string fpath;
369
387
 
370
 
                     snprintf(numtmp, sizeof(numtmp), "%04d", id1);
 
388
                     trio_snprintf(numtmp, sizeof(numtmp), "%04d", id1);
371
389
 
372
390
                     fmap['p'] = std::string(numtmp);
373
391
 
532
550
     }
533
551
}
534
552
 
535
 
char *MDFN_RemoveControlChars(char *str)
536
 
{
537
 
 char *orig = str;
538
 
 if(str)
539
 
  while(*str)
540
 
  {
541
 
   if(*str < 0x20) *str = 0x20;
542
 
   str++;
543
 
  }
544
 
 return(orig);
545
 
}
546
 
 
547
 
// Remove whitespace from beginning of string
548
 
void MDFN_ltrim(char *string)
549
 
{
550
 
 int32 di, si;
551
 
 bool InWhitespace = TRUE;
552
 
 
553
 
 di = si = 0;
554
 
 
555
 
 while(string[si])
556
 
 {
557
 
  if(InWhitespace && (string[si] == ' ' || string[si] == '\r' || string[si] == '\n' || string[si] == '\t' || string[si] == 0x0b))
558
 
  {
559
 
 
560
 
  }
561
 
  else
562
 
  {
563
 
   InWhitespace = FALSE;
564
 
   string[di] = string[si];
565
 
   di++;
566
 
  }
567
 
  si++;
568
 
 }
569
 
 string[di] = 0;
570
 
}
571
 
 
572
 
// Remove whitespace from end of string
573
 
void MDFN_rtrim(char *string)
574
 
{
575
 
 int32 len = strlen(string);
576
 
 
577
 
 if(len)
578
 
 {
579
 
  for(int32 x = len - 1; x >= 0; x--)
580
 
  {
581
 
   if(string[x] == ' ' || string[x] == '\r' || string[x] == '\n' || string[x] == '\t' || string[x] == 0x0b)
582
 
    string[x] = 0;
583
 
   else
584
 
    break;
585
 
  }
586
 
 }
587
 
 
588
 
}
589
 
 
590
 
void MDFN_trim(char *string)
591
 
{
592
 
 MDFN_rtrim(string);
593
 
 MDFN_ltrim(string);
594
 
}
595
 
 
596
 
 
597
 
// Remove whitespace from beginning of string
598
 
void MDFN_ltrim(std::string &string)
599
 
{
600
 
 size_t len = string.length();
601
 
 size_t di, si;
602
 
 bool InWhitespace = TRUE;
603
 
 
604
 
 di = si = 0;
605
 
 
606
 
 while(si < len)
607
 
 {
608
 
  if(InWhitespace && (string[si] == ' ' || string[si] == '\r' || string[si] == '\n' || string[si] == '\t' || string[si] == 0x0b))
609
 
  {
610
 
 
611
 
  }
612
 
  else
613
 
  {
614
 
   InWhitespace = FALSE;
615
 
   string[di] = string[si];
616
 
   di++;
617
 
  }
618
 
  si++;
619
 
 }
620
 
 
621
 
 string.resize(di);
622
 
}
623
 
 
624
 
// Remove whitespace from end of string
625
 
void MDFN_rtrim(std::string &string)
626
 
{
627
 
 size_t len = string.length();
628
 
 
629
 
 if(len)
630
 
 {
631
 
  size_t x = len;
632
 
  size_t new_len = len;
633
 
 
634
 
  do
635
 
  {
636
 
   x--;
637
 
 
638
 
   if(!(string[x] == ' ' || string[x] == '\r' || string[x] == '\n' || string[x] == '\t' || string[x] == 0x0b))
639
 
    break;
640
 
 
641
 
   new_len--;
642
 
  } while(x);
643
 
 
644
 
  string.resize(new_len);
645
 
 }
646
 
}
647
 
 
648
 
 
649
 
void MDFN_trim(std::string &string)
650
 
{
651
 
 MDFN_rtrim(string);
652
 
 MDFN_ltrim(string);
653
 
}