Skip to content

Instantly share code, notes, and snippets.

@DreamOfTranscendence
Last active July 21, 2025 01:57
Show Gist options
  • Select an option

  • Save DreamOfTranscendence/2cc3dea8c00c7f32d63449087b1d614c to your computer and use it in GitHub Desktop.

Select an option

Save DreamOfTranscendence/2cc3dea8c00c7f32d63449087b1d614c to your computer and use it in GitHub Desktop.
Search the entire text content of a raw file AND all the files in it's repository it (includes) links to
var parryTHIS=this.self||this; //the global js object should always be named "self", if you disagree with this you're no good at programming.
//(function gitRespDigSearchJs(){
var _M=(parryTHIS.gitRespDig={err:[],"c_syslib":[]}),
files_by_path=(_M.filesp={}),
xh=new XMLHttpRequest(),
xhBL=[], //xh backlog (I don't want infinite XHR object instances)
rpth="https://raw.githubusercontent.com/", rpth2="/refs/heads/master/",
getHubFile=(xh.onreadystatechange=(_M.gitFile=
function gitFileFromHubRaw(path,cb,_inFile,rt){ // iHate .then & promises
if(typeof path=="string"){
if(path.indexOf("://")==-1){
if(path[0]=="/")path=path.substr(1);
if(_inFile){
let apth=_inFile, pls=path.indexOf("/")+1, baseP=pls?path.substr(0,pls):-1,
mpth=apth.indexOf(baseP,apth.indexOf(rpth2)+2);
if(mpth==-1) path=apth.substr(0,rt?(apth.lastIndexOf("/")+1):apth.indexOf(rpth2)+rpth2.length)+path;
else path=apth.substr(0,mpth)+path;
console.log("built absolute include path: "+path);
}else
path=rpth+path;
}
if(xh.ron){ //wen busy
xhBL.push([path,cb,_inFile,rt]);
}else{ //cando
xh.ron=[path,cb,_inFile,rt];
xh.open("GET",path,true);xh.send();
}
}else if(path&&path.type=="error"){ _M.err.push([path,xh.ron[2]]); /*return true*/;} //error
if(xh.ron&&xh.readyState==4){
if(xh.status>199&&xh.status<399){
let got=xh.ron; xh.ron=false;
files_by_path[got[0]]=xh.response;
console.log("loaded: "+got[0]+" "+xh.status);
if(typeof got[1]=="function") got[1](got[0]); //, xh.getAllResponseHeaders());
}else if(xh.status==404){ /*re-write file path?*/ }
}
if((!xh.ron)&&(xh.ron=xhBL.shift())){ //do backlogged
xh.open("GET",xh.ron[0],true);xh.send();
}
}));
xh.responseType="text"; //is default yes?
_M.parseCincludes=function parseCinc(code){
var iaL=code.replace(/\r/g,"\n").split("#include "),i=0,L,c;
iaL.shift(); L=iaL.length, sysp=/[\<\>]/g;
while(i!=L){
c=iaL[i].substr(0,500); c=c.substr(0,c.indexOf("\n"));
sysp.lastIndex=0;
if(sysp.test(c)){
_M.c_syslib.push(c);
iaL[i]=true;
console.log("uses sys lib: "+c);
}else{
c=c.split('"');
iaL[i]=c[1]||c[0];
}
i++;
};
let ron2="_r"+Math.random().toString(36).substr(2);
_M[ron2]=iaL;
console.log("parsed includes, see: gitRespDig."+ron2);
return iaL;
};
_M.grabCincludes=function(mainFileP,basep){ //c++ code include includer (this is it)
if(!basep) basep=mainFileP;
getHubFile(mainFileP,function gCb(gotPath){
let inclu = _M.parseCincludes( files_by_path[gotPath] ), iL=inclu.length,
gotFiles=[],
ifIsLodd=function ifIsDoneLoaded(gp2){
let ic=false;
while(typeof ic=="boolean") ic=inclu.shift();
if(ic){
getHubFile(ic,function(pth){ gotFiles.push(pth); ifIsLodd(); },basep);
}else if(gotFiles.length==iL){
let g2;
while(g2=gotFiles.shift()) _M.grabCincludes(g2);
}
};
ifIsLodd();
},basep);
};
//})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment