/* tripl/main.c * * This file is part of tripl. * * tripl is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * tripl is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with tripl. If not, see */ #include #include #include #include #include #include #include int usage(void); char *basename, *fbuffer, *fname; int main(int argc, const char **argv) { off_t fsize; int fd; int retstat; basename = (char *) argv[0]; if (argc < 2) return usage(); if (unlikely(!(fname = (char *) argv[1]))) return usage(); /* i don't like getopt()... */ if (!strcmp(argv[1], "-c")) { fbuffer = (char *) argv[2]; fsize = strlen(fbuffer); fd = 0; fbuffer[fsize] = 0; goto compile; } if (unlikely((fd = open(fname, O_RDONLY)) < 0)) { perror(basename); return usage(); } fsize = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); if (unlikely((fbuffer = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED)) { perror(basename); return usage(); } compile: retstat = do_tripl_compile(fbuffer, fsize); if (fbuffer == argv[2]) goto skip; munmap(fbuffer, fsize); close(fd); skip: if (retstat) { error("compliation failed"); return retstat; } return 0; } int usage(void) { error("it is very easy to learn how to use tripl :-)"); error("Usage: tripl FILE"); return 1; }