Ujpp.c
From OSDVwiki
This is a toy application for illustrative purposes for the IOTA Challenge. Thanks to Rodney Thayer for writing it!
/* ujpp - test program to demonstrate OSDV platform $Revision: 1.1 $ */ #include <stdio.h> #include <time.h> int votes_no; int votes_yes; int main (int argc, char * argv []); int main (int argc, char * argv []) { /* main for ujpp */ int done; char line [1024]; FILE *record_file; int status; status = 0; done = 0; (void)freopen ("/dev/tty2", "r", stdin); (void)freopen ("/dev/tty2", "w", stdout); /* prep vote count journal file. */ votes_no = 0; votes_yes = 0; record_file = fopen ("/mnt/hda1/osdv-records", "w"); // SIMULATE WRITING B RECORD fprintf (record_file, "B %ld\n", time (NULL)); fflush (record_file); while (!done) { printf ("Please state your preference - Y for yellow, or N fr Navy - and type enter.\n"); fgets (line, sizeof (line), stdin); if ((line [0] == 'y') || (line [0] == 'Y')) { fprintf (record_file, "Y %ld\n", time (NULL)); fflush (record_file); votes_yes ++; }; if ((line [0] == 'n') || (line [0] == 'N')) { fprintf (record_file, "N %ld\n", time (NULL)); fflush (record_file); votes_no ++; }; // EMBARASSINGLY CHEESY SIMULATION OF RECEIVING SPECIAL INPUT // I used this because I wanted to cleanly show the output of the S and E records // and using signal processing or something like that would have been more complicated // than I wanted to do in the concept prototype. if (line [0] == 'S') if (line [1] == 't') if (line [2] == 'O') if (line [3] == 'p') { printf ("Application terminating (%ld).\n", time (NULL)); done = 1; }; }; // SIMULATE WRITING S RECORD fprintf (record_file, "S %ld\n", time (NULL)); fflush (record_file); // SIMULATE WRITING T RECORD fprintf (record_file, "T %ld Y %d N %d\n", time (NULL), votes_yes, votes_no); fflush (record_file); fprintf (stdout, "Vote Totals: Yes: %d No %d\n", votes_yes, votes_no); // SIMULATE WRITING E RECORD fprintf (record_file, "E %ld\n", time (NULL)); fflush (record_file); fclose (record_file); return (status); } /* main for ujpp */

