main() { printf("yyparse() = %d\n",yyparse()); }
void main() { yyparse(); }
int main( int argc, char *argv[]) { extern int optind; extern int opterr; extern char *optarg; int c; FILE *fp; #ifdef __hpux setlocale(LC_CTYPE,""); #endif #ifdef MDEBUG malloc_debug(2) ; /* helps find malloc/free errors on Sun */ #endif /* MDEBUG */ opterr = 1; /* print error message if bad option */ progname = ubasename(argv[0]); cdlname = "-"; c_flag = 0; fortran_flag = 0; netcdf_flag = 0; cmode_modifier = 0; nofill_flag = 0; #if _CRAYMPP && 0 /* initialize CRAY MPP parallel-I/O library */ (void) par_io_init(32, 32); #endif while ((c = getopt(argc, argv, "bcfk:l:no:v:x")) != EOF) switch(c) { case 'c': /* for c output, old version of "-lc" */ c_flag = 1; break; case 'f': /* for fortran output, old version of "-lf" */ fortran_flag = 1; break; case 'b': /* for binary netcdf output, ".nc" extension */ netcdf_flag = 1; break; case 'l': /* specify language, instead of using -c or -f */ { char *lang_name = (char *) emalloc(strlen(optarg)+1); if (! lang_name) { derror ("%s: out of memory", progname); return(1); } (void)strcpy(lang_name, optarg); if (strcmp(lang_name, "c") == 0 || strcmp(lang_name, "C") == 0) { c_flag = 1; } else if (strcmp(lang_name, "f77") == 0 || strcmp(lang_name, "fortran77") == 0 || strcmp(lang_name, "Fortran77") == 0) { fortran_flag = 1; } else { /* Fortran90, Java, C++, Perl, Python, Ruby, ... */ derror("%s: output language %s not implemented", progname, lang_name); return(1); } } break; case 'n': /* old version of -b, uses ".cdf" extension */ netcdf_flag = -1; break; case 'o': /* to explicitly specify output name */ netcdf_flag = 1; netcdf_name = (char *) emalloc(strlen(optarg)+1); if (! netcdf_name) { derror ("%s: out of memory", progname); return(1); } (void)strcpy(netcdf_name,optarg); break; case 'x': /* set nofill mode to speed up creation of large files */ nofill_flag = 1; break; case 'v': /* a deprecated alias for "kind" option */ /*FALLTHRU*/ case 'k': /* for specifying variant of netCDF format to be generated */ { char *kind_name = (char *) emalloc(strlen(optarg)+1); if (! kind_name) { derror ("%s: out of memory", progname); return(1); } (void)strcpy(kind_name, optarg); /* The default kind is kind 1, with 32-bit offsets */ if (strcmp(kind_name, "1") == 0 || strcmp(kind_name, "classic") == 0) { cmode_modifier = 0; } /* The 64-bit offset kind (2) should only be used if actually needed */ else if (strcmp(kind_name, "2") == 0 || strcmp(kind_name, "64-bit-offset") == 0) { cmode_modifier |= NC_64BIT_OFFSET; } #ifdef USE_NETCDF4 /* NetCDF-4 HDF5 format*/ else if (strcmp(kind_name, "3") == 0 || strcmp(kind_name, "hdf5") == 0) { cmode_modifier |= NC_NETCDF4; } /* NetCDF-4 HDF5 format, but using only nc3 data model */ else if (strcmp(kind_name, "4") == 0 || strcmp(kind_name, "hdf5-nc3") == 0) { cmode_modifier |= NC_NETCDF4 | NC_CLASSIC_MODEL; } #endif else { derror("Invalid format, try classic, 64-bit-offset, hdf5, or hdf5-nc3"); return 2; } } break; case '?': usage(); return(8); } if (fortran_flag && c_flag) { derror("Only one of -c or -f may be specified"); return(8); } argc -= optind; argv += optind; if (argc > 1) { derror ("%s: only one input file argument permitted",progname); return(6); } fp = stdin; if (argc > 0 && strcmp(argv[0], "-") != 0) { if ((fp = fopen(argv[0], "r")) == NULL) { derror ("can't open file %s for reading: ", argv[0]); perror(""); return(7); } cdlname = argv[0]; } yyin = fp; return (yyparse()); }
/* * send the damn thing */ char * data(String *from, Biobuf *b) { char *buf, *cp; int i, n, nbytes, bufsize, eof, r; String *fromline; char errmsg[Errlen]; char id[40]; /* * input the header. */ buf = malloc(1); if(buf == 0){ s_append(s_restart(reply), "out of memory"); return Retry; } n = 0; eof = 0; for(;;){ cp = Brdline(b, '\n'); if(cp == nil){ eof = 1; break; } nbytes = Blinelen(b); buf = realloc(buf, n+nbytes+1); if(buf == 0){ s_append(s_restart(reply), "out of memory"); return Retry; } strncpy(buf+n, cp, nbytes); n += nbytes; if(nbytes == 1) /* end of header */ break; } buf[n] = 0; bufsize = n; /* * parse the header, turn all addresses into @ format */ yyinit(buf, n); yyparse(); /* * print message observing '.' escapes and using \r\n for \n */ alarm(20*alarmscale); if(!filter){ dBprint("DATA\r\n"); switch(getreply()){ case 3: break; case 5: free(buf); return Giveup; default: free(buf); return Retry; } } /* * send header. add a message-id, a sender, and a date if there * isn't one */ nbytes = 0; fromline = convertheader(from); uneaten = buf; srand(truerand()); if(messageid == 0){ for(i=0; i<16; i++){ r = rand()&0xFF; id[2*i] = hex[r&0xF]; id[2*i+1] = hex[(r>>4)&0xF]; } id[2*i] = '\0'; nbytes += Bprint(&bout, "Message-ID: <%s@%s>\r\n", id, hostdomain); if(debug) Bprint(&berr, "Message-ID: <%s@%s>\r\n", id, hostdomain); } if(originator==0){ nbytes += Bprint(&bout, "From: %s\r\n", s_to_c(fromline)); if(debug) Bprint(&berr, "From: %s\r\n", s_to_c(fromline)); } s_free(fromline); if(destination == 0 && toline) if(*s_to_c(toline) == '@'){ /* route addr */ nbytes += Bprint(&bout, "To: <%s>\r\n", s_to_c(toline)); if(debug) Bprint(&berr, "To: <%s>\r\n", s_to_c(toline)); } else { nbytes += Bprint(&bout, "To: %s\r\n", s_to_c(toline)); if(debug) Bprint(&berr, "To: %s\r\n", s_to_c(toline)); } if(date==0 && udate) nbytes += printdate(udate); if (usys) uneaten = usys->end + 1; nbytes += printheader(); if (*uneaten != '\n') putcrnl("\n", 1); /* * send body */ putcrnl(uneaten, buf+n - uneaten); nbytes += buf+n - uneaten; if(eof == 0){ for(;;){ n = Bread(b, buf, bufsize); if(n < 0){ rerrstr(errmsg, sizeof(errmsg)); s_append(s_restart(reply), errmsg); free(buf); return Retry; } if(n == 0) break; alarm(10*alarmscale); putcrnl(buf, n); nbytes += n; } } free(buf); if(!filter){ if(last != '\n') dBprint("\r\n.\r\n"); else dBprint(".\r\n"); alarm(10*alarmscale); switch(getreply()){ case 2: break; case 5: return Giveup; default: return Retry; } syslog(0, "smtp", "%s sent %d bytes to %s", s_to_c(from), nbytes, s_to_c(toline));/**/ } return 0; }