int main(int argc, char *argv[]) { int ch, exval; FILE *fp; const char *fn; while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { case '?': default: usage(); /*NOTREACHED*/ } } argc -= optind; argv += optind; exval = 0; if (argc == 0) asa(stdin); else { while ((fn = *argv++) != NULL) { if ((fp = fopen(fn, "r")) == NULL) { warn("%s", fn); exval = 1; continue; } asa(fp); fclose(fp); } } exit(exval); }
int main(int argc,char *argv[]) { int c,i; while ((c = getopt(argc,argv,":hv"))!=-1) { switch(c) { case 'h': usage(argv[0],0); break; case 'v': printf("asa v0.1\n(c) 2008 Janosch Graef\n"); return 0; break; case '?': fprintf(stderr,"Unrecognized option: -%c\n", optopt); usage(argv[0],1); break; } } if (optind==argc) asa(stdin,stdout); else { for (i=optind; i<argc; i++) { FILE *fd = fopen(argv[optind],"r"); if (fd!=NULL) { asa(fd,stdout); fclose(fd); } else fprintf(stderr,"asa: %s: %s\n",argv[optind],strerror(errno)); } } return 0; }