bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

suggestions: for bash shell: "shebam's and shebang's"


From: Bill William
Subject: suggestions: for bash shell: "shebam's and shebang's"
Date: Wed, 11 Jan 2017 13:30:02 -0500

Sorry about restating the obvious... but...everybody dislikes binary file header "bom's" like utf=8, utf-16 etc..too little...too late... instead, why not force everybody to build those file types into the shebang instead?  

The problem with the shebang is that its not a file type its an executable...what is needed is the option to only specify a file type... examples:


//Example Shebang:       #!/usr/bin/perl
//Example Shebam:        #:utf8
//Example Shebam:        #:ascii
//Example Shebam:        #:b64encrypt
//Example Shebam:        #:gtk+xml-gladed6
//Example Shebam:        #:xml-myprogram
//Example Shebamshebang: #:perl-ascii!/usr/bin/perl
//Example Shebamshebang: #:perl-ascii!c:/perl/bin/perl.exe
//Example Shebamshebang: #:perl-ascii!c:/perl/bin/perl.exe

//utf16, utf32?? who cares... utf8 already won... 99% of the time... except for legacy windows code...
inline void ShebamWrite(ofstream& myfile, const string Shebam) {
  myfile <<"#:" << Shebam << "\n";
}

//Shebam: A File 'Bom' the way it should have been done.
inline string ShebamCheck(string filename) {
   ifstream myfile(filename);
   string Shebam = ShebamRead(myfile);
   myfile.close();
   return Shebam;
}

inline string ShebamRead(ifstream& myfile) {
   string buffer;
   getline(myfile, buffer);
   int len = buffer.size();
   if (len < 2)
    return string{};

   bool found=false;
   if ((buffer[0]=='#') && ((buffer[1]==':') || (buffer[1]=='!'))) {
      for(int i=2; i < len; i++) {
        if (!isprint(buffer[i])) {
            found=false;
            break;
        }
        else if (i>3) { //need at least one bom character
          found=true;
        }
      }
   }
   if (!found) {
     return string{};
   }
   buffer.erase(0, 2);

   return buffer;
}

int main(int argc, char** argv) {
  string shabam1 = ShebamCheck("myfile1.txt");
  if (shabam1 == string{}) {
    cout << "shebam1 = none\n";
  }
  else {
    cout << "shebam1 = " << shebam1 << "\n";
  }
  return 0;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]