Logo Search packages:      
Sourcecode: sam2p version File versions

SimBuffer::B & SimBuffer::B::appendFnq ( const Flat other,
bool  preminus = false 
)

Quotes a filename (actually a pathname since it may include (sub)directories) specified in param `other' to be passed to the most common shell of the host operating system (/bin/sh, COMMAND.COM, CMD.EXE etc.) as a separate command line argument for a command invoked from the shell.

Under UNIX, this differs from appendNpmq only when treating [
]. Under Win32, the filename is surrounded by double quotes. Double quotes inside the filename are skipped. Other systems than Win32 are treated like UNIX.

Parameters:
preminus prefix filenames starting with `-' with `./' ?

Definition at line 966 of file gensi.cpp.

References SimBuffer::Flat::beg, SimBuffer::Flat::len, and vi_grow2().

                                                                           {
  slen_t rlen=0;
  register char c; register char const*p;
  char const *pend; char *dst;
  if (OS_COTY==COTY_WINNT || OS_COTY==COTY_WIN9X) {
    for (p=other.beg,pend=p+other.len; p!=pend; p++) {
      if ('\0'==(c=*p) || c=='"') break;
      rlen++;
    }
    if (preminus && rlen!=0 && other.beg[0]=='-') rlen+=2; /* .\ */
    vi_grow2(0, rlen+2, 0, &dst);
    *dst++='"'; /* Dat: "ab"c" ""def" is perfectly legal and parses to: `abc def' */
    p=other.beg;
    if (preminus && other.beg[0]=='-') { *dst++='.'; *dst++='\\'; }
    for (p=other.beg,pend=p+other.len; p!=pend; p++) {
      if ('\0'==(c=*p) || c=='"') break;
      *dst++=c;
    }
    *dst++='"';
  } else { /* Everything else is treated as UNIX */
    for (p=other.beg,pend=p+other.len; p!=pend; p++) {
      if ('\0'==(c=*p)) break;
      rlen+=is_path(c)?1: c=='\n'?3:2;
    }
    if (preminus && rlen!=0 && other.beg[0]=='-') rlen+=2; /* ./ */
    vi_grow2(0, rlen, 0, &dst);
    if (preminus && other.beg[0]=='-') { *dst++='.'; *dst++='/'; }
    for (p=other.beg,pend=p+other.len; p!=pend; p++) {
      if ('\0'==(c=*p)) break;
      if (is_path(c)) *dst++=c;
      else if (c=='\n') { *dst++='"'; *dst++='\n'; *dst++='"'; }
      else { *dst++='\\'; *dst++=c; }
    }
  } /* IF OS_COTY... */
  assert(dst==end_());
  return*this;
}


Generated by  Doxygen 1.6.0   Back to index