Letterhd.gif (3329 bytes)  
Quick Site Search

Sample PC C

Home ] Contact us ] Search ] Contents ]


This program reads financial market data from a serial port into a text file for processing.  The serial port was attached to a satellite downlink that provided a real-time data feed, making speed and efficiency a primary concern.


/*  C4.C (from C.C) */
/* compilation control */
#define DEBUG 0       /* 0 for production, 1 for various debug displays */
#define LIVESOURCE 0  /* 0 for read of test file TICK3, 1 reads U6000 port */
#define UNISYS 0      /* 0 for PC, 1 for U6000: sets header file name choice */
/* configuration constants */
#define MAXORECORDS 500    /* records (lines) per output file */
#define MAXOFILES   640    /* maximum output files to be maintained */
#define MAXFIELDLEN 256    /* maximum characters allowed in a field, plus 1 */
#define DEFFIELDLEN 20     /* default characters in a field */
/* lengths of fields in the output record (see datarec, outrec, initrec) */
#define LEN_ASK     10
#define LEN_BID     10
#define LEN_BS      1
#define LEN_CURRENT 10
#define LEN_FLAG    1
#define LEN_DATE    8
#define LEN_EXPDATE 8
#define LEN_OP_ID   2
#define LEN_RECTYPE 1
#define LEN_RIDNBR  4
#define LEN_SEQ     8
#define LEN_SYMBOL  18
#define LEN_TIME    8
#define LEN_VOLUME  12  /*  formerly 7  */
/* equates for fields having more than one name */
/* don't blame the programmer, he inherited the names */
#define LEN_LAST       LEN_CURRENT
#define LEN_TOTVOL     LEN_VOLUME
/* input fields for which a generic string definition works fine */
#define LEN_AX         DEFFIELDLEN
#define LEN_AZ         DEFFIELDLEN
#define LEN_BASE       DEFFIELDLEN
#define LEN_BB         DEFFIELDLEN
#define LEN_BX         DEFFIELDLEN
#define LEN_BZ         DEFFIELDLEN
#define LEN_COUNT      DEFFIELDLEN
#define LEN_DAY        DEFFIELDLEN
#define LEN_EXCL       DEFFIELDLEN
#define LEN_EXL        DEFFIELDLEN
#define LEN_EXT        DEFFIELDLEN
#define LEN_HIGH       DEFFIELDLEN
#define LEN_INTEREST   DEFFIELDLEN
#define LEN_LOW        DEFFIELDLEN
#define LEN_NEWDAY     DEFFIELDLEN
#define LEN_NEWS       DEFFIELDLEN
#define LEN_NEWTIME    DEFFIELDLEN
#define LEN_PREV       DEFFIELDLEN
#define LEN_TICKVOL    DEFFIELDLEN
/* input fields with their own peculiar needs */
#define LEN_STAT       2
/* global variables */
/* structure of output record */
struct  datarec {                  /* start */
  char  o_rectype [LEN_RECTYPE];   /*    1  */
  char  o_symbol  [LEN_SYMBOL];    /*    2  */
  char  oc2       [1];             /*       */
  char  o_op_id   [LEN_OP_ID];     /*       */
  char  oc3       [1];             /*       */
  char  o_volume  [LEN_VOLUME];    /*       */
  char  oc4       [1];             /*       */
  char  o_bs      [LEN_BS];        /*       */
  char  oc5       [1];             /*       */
  char  o_current [LEN_CURRENT];   /*       */
  char  o_flag    [LEN_FLAG];      /*       */
  char  o_bid     [LEN_BID];       /*       */
  char  oc7       [1];             /*       */
  char  o_ask     [LEN_ASK];       /*       */
  char  oc8       [1];             /*       */
  char  o_date    [LEN_DATE];      /*       */
  char  oc9       [1];             /*       */
  char  o_time    [LEN_TIME];      /*       */
  char  oca       [1];             /*       */
  char  o_seq     [LEN_SEQ];       /*       */
  char  ocb       [1];             /*       */
  char  o_expdate [LEN_EXPDATE];   /*       */
  char  occ       [1];             /*       */
  char  o_ridnbr  [LEN_RIDNBR];    /*       */
}
/* instances of output record that we'll need */
  outrec, initrec;
/* input data fields.  Extra character is for a trailing \0 where needed */
  char  ask      [LEN_ASK+1],
        ax       [LEN_AX+1],
        az       [LEN_AZ+1],
        base     [LEN_BASE+1],
        bb       [LEN_BB+1],
        bid      [LEN_BID+1],
        bx       [LEN_BX+1],
        bz       [LEN_BZ+1],
        count    [LEN_COUNT+1],
        day      [LEN_DAY+1],
        exl      [LEN_EXL+1],
        ext      [LEN_EXT+1],
        high     [LEN_HIGH+1],
        interest [LEN_INTEREST+1],
        last     [LEN_LAST+1],
        low      [LEN_LOW+1],
        newday   [LEN_NEWDAY+1],
        news     [LEN_NEWS+1],
        newtime  [LEN_NEWTIME+1],
        prev     [LEN_PREV+1],
        rectype  [LEN_RECTYPE+1],
        symbol   [LEN_SYMBOL+1],
        tickvol  [LEN_TICKVOL+1],
        totvol   [LEN_TOTVOL+1],
        ttime    [LEN_TIME+1],
        volume   [LEN_VOLUME+1];
/* header files (remember those?) */
#include <ctype.h>
#include <fcntl.h>    /* for O_RDONLY, etc. */
#include <stdio.h>
#if UNISYS
#include <unistd.h>
#else
#include <io.h>
#endif
#include <stdlib.h>   /* for exit, strtok */
#include <time.h>
#include <sys/stat.h> /* for S_IREAD, S_IWRITE */
#include <errno.h>
#include <string.h>
#if LIVESOURCE
/* #include <stropts.h> */
/* #include <poll.h> */
#endif
/* file  pointers and descriptors */
  FILE  *cfptr,           /* control file pointer */
        *kfptr,           /* count file pointer */
        *ifptr;           /* signal port file pointer */
  int   ifd,              /* input  file descriptor */
        ofd;              /* output file descriptor */
/* control file data fields */
int     ctlparm, func;
/* poll library stuff */       /* LIVESOURCE */
#if LIVESOURCE
/*  struct pollfd fds[2], *fpr; */
/*  int   res = -1;             */
  int   res = 1;   /* test */
#else
  int   res = 1;
#endif
/* working variables */
char    c;          /* generic byte field */
char    ofname[65]; /* output file name buffer */
char    *cptr,      /* generic character pointers */
        *c1ptr;
int     i,          /* generic integer index */
        incr,       /* next increment to apply to output file counter */
        lastopened, /* number of last output file that was opened */
        ofcount,    /* output file counter - becomes part of file name */
        outcnt,     /* output record counter - reset for each new output file */
        w_rectype,  /* used in switch statement to select record layout */
        x;          /* generic integer */
int     *iptr;      /* generic integer pointer */
long    sequence;   /* incremented for and included in every record written */
union {
  char    buf [LEN_STAT+2];  /* note extra pad */
  struct {
    int   z1   : 5;
    int   xopen: 1;
    int   z2   : 10;
  } a ;
  struct {
    int   z3   : 2;
    int   tick : 2;
    int   z4   : 12;
  } b;
} statf;  
char *p1 = &outrec.o_rectype;
main()
{
/* function declarations and local data in main */
  double basetodiv();  /* converts a base to a divisor */
  void  fgetcdf();     /* gets a comma delimited string from a file */
  char  xbuf[64],      /* scratch buffers */
        zbuf[256];
  char  dot[] = ".\0"; /* literal period */
  char  stat_err[] =
        "Record %d not processed; status field fails integrity check\n";
  int   fldcnt;        /* number of fields found in control file */
  double div;          /* holds current divisor */
struct tm *timeptr;  /* declarations for */
  time_t timer;        /* standard time routines */
#if DEBUG
/*   for output to stdout only */
   char  buffer[256];
#endif
/* processing starts here */
  /* initialize some items */
  incr = 1;  /* default outfile increment */
  
  x = ' ';
/* setmem(initrec, 111, x);   */
memset(&initrec, ' ', sizeof(initrec)); /* space out initialization buffer
/*   memset(initrec, x, sizeof(initrec));    space out initialization buffer */
/*   memset(initrec, 32, sizeof(initrec));   space out initialization buffer */
  /* set starting output file number ofcount /*
  /* if we can, add 1 to number of last file opened to get starting number */
  if ((kfptr = fopen("cntfile","rb")) != NULL){
    fscanf(kfptr, " ");
    fldcnt = fscanf(kfptr, "%d", &lastopened);
    fclose(kfptr);
    if ((fldcnt = 1) && (lastopened < MAXOFILES) && (lastopened > -1)){
      printf("Last output file number was %d\n", lastopened);
      ofcount = (lastopened + incr) % MAXOFILES;
      printf("Next output file number will be %d\n", ofcount);
    }
  }
  else ofcount = 1;
  printf("! Increment value now %d\n", incr);
  printf("! Last output file number was %d\n", lastopened);
  printf("! Next output file to be assigned is %d\n", ofcount);
  /* open input file */
  #if LIVESOURCE
    sprintf(zbuf, "/dev/term/01");
    sprintf(xbuf, "rb+");
    x = O_RDWR;
  #else
    sprintf(zbuf, "tick3");
    sprintf(xbuf, "rb");
    x = O_RDONLY;
  #endif
  if ((ifptr = fopen(zbuf, xbuf)) == NULL){
    printf("Can't open input port %s: ", zbuf);
    perror("");
    exit(1);
  }
/*
  if ((ifd = open(zbuf, x)) < 0) {
    printf("Can't open input port %s\n", zbuf);
    exit(1);
  }
  if ((ifptr = fdopen(ifd, xbuf)) == NULL) {
    printf("Can't access input port %s with stream I/O", zbuf);
    exit(1);
  }
/*
/*  printf("@"); */
  /* throw away everything until we get to the start of a record */
  do fgetcdf(ifptr, zbuf); while (zbuf[0] != '/');
/*  printf("!"); */
  /* main processing loop
      consists of 4 parts: opening output file
                           input handling (most of processing)
                           closing output file
                           handling any control file from other apps
      loop never checks for end of input file.
      only exit is through control file handling or if fgetcdf quits on EOF.
      at top of loop, record type should be the first field to read.
  */
  /* MAIN LOOP STARTS HERE */
  while (1){
    #if LIVESOURCE
/*    fpr = (struct pollfd *) &fds ;
      fds[0].fd      = ifd;
      fds[0].events  = POLLIN;
      fds[0].revents = 0;
      res = poll(fpr, 1, -1);
*/
    #endif
    if (res >= 1) { 
      /* OPEN OUTPUT file */
      /*  next number to use is already in ofcount */
      printf("@ Increment value now %d\n", incr);
      do {
        sprintf(ofname,"sig%05d", ofcount);
        ofd = open(ofname, O_WRONLY | O_CREAT | O_TRUNC , S_IREAD | S_IWRITE);
/*      ofd = open(ofname, O_WRONLY | O_CREAT | O_TRUNC | O_DENYALL | O_TEXT, S_IREAD | S_IWRITE);  */
        if (ofd < 0) printf("CANNOT OPEN OUTPUT FILE!\n");
      } while (ofd < 0);
      /* write to the 'count file' so application knows where we are */
      if ((kfptr = fopen("cntfile","wb")) != NULL){
        fprintf(kfptr, "%05d", ofcount);
        fclose(kfptr);
      }
      outcnt = 0;  /* set output line counter to 0 */
      /* I/O LOOP STARTS HERE */
      while (outcnt < MAXORECORDS){
        fgetcdf(ifptr, rectype);
        w_rectype =* rectype; /* faster than sscanf */
#if DEBUG
      printf("Raw record type: %s %d \n", rectype);
      printf("Record type: %c \n", w_rectype);
#endif
        switch (w_rectype){
          case('A'):{
/*          printf("A "); */
            /* process symbol field */
            fgetcdf(ifptr, symbol);
            x =* symbol; /* faster than sscanf */ 
            if (symbol[0] == '$') ;
            else if (isalpha(x)) ;
            else {
             printf("Questionable symbol: %s   Record: %ld \n", symbol, sequence);
             goto SkipOut;
            }
            
            /* break out option-id if necessary (NOT!) */
            zbuf[0] = '\0';
/*          c1ptr = symbol;
            cptr = strtok(c1ptr, ".");   
            cptr = strtok(NULL, ".");   
            if (cptr != NULL) strcpy(zbuf, cptr); */
                   
            /* initialize output record and work buffers */
            memset(statf.buf, 0, sizeof(statf.buf));
            memcpy(&outrec, &initrec, sizeof(outrec));
/*            memset(outrec, ' ', sizeof(outrec));   space out initialization buffer */
            strncpy(outrec.o_rectype, rectype, LEN_RECTYPE);
            strncpy(outrec.o_symbol, symbol, strlen(symbol));
            x = strlen(zbuf);
            if (x > 0) {
              memcpy(outrec.o_op_id, zbuf, LEN_OP_ID);
            }
            /* read body of input record */
            fgetcdf(ifptr, last);
            fgetcdf(ifptr, prev);
            fgetcdf(ifptr, high);
            fgetcdf(ifptr, low);
            fgetcdf(ifptr, totvol);
            fgetcdf(ifptr, statf.buf);
            if (strlen(statf.buf) > 2) {
/*            printf(stat_err, sequence);  */
              goto SkipOut;
            }
/*please*/  if (statf.a.xopen == 1){
/*check*/     outrec.o_flag[0] = '*';
/*  ! */    }
            fgetcdf(ifptr, base);
            /* perform arithmetic and output formatting */
            div = basetodiv(base);
            sprintf(last, "%#*.6f", LEN_LAST, strtod(last, NULL) / div);
            strncpy(outrec.o_current, last, LEN_CURRENT);
            sprintf(totvol, "%*ld", LEN_TOTVOL, strtol(totvol, NULL, 0));
            strncpy(outrec.o_volume, totvol, LEN_VOLUME);
            break;
          }
          case('B'):{
/*          printf("B ");  */
            /* process symbol field */
            fgetcdf(ifptr, symbol);
            
            x =* symbol; /* faster than sscanf */ 
            if (symbol[0] == '$') ;
            else if (isalpha(x)) ;
            else {
             printf("Questionable symbol: %s   Record: %ld \n", symbol, sequence);
             goto SkipOut;
            }
            
            /* break out option-id if necessary (NOT!) */
            zbuf[0] = '\0';
/*          c1ptr = symbol;
            cptr = strtok(c1ptr, ".");    
            cptr = strtok(NULL, ".");     
            if (cptr != NULL) strcpy(zbuf, cptr); */
            /* initialize output record */
            memcpy(&outrec, &initrec, sizeof(outrec));
/*            memset(outrec, ' ', sizeof(outrec));   space out initialization buffer */
            strncpy(outrec.o_rectype, rectype, LEN_RECTYPE);
            strncpy(outrec.o_symbol, symbol, strlen(symbol));
            x = strlen(zbuf);
            if (x > 0) {
              memcpy(outrec.o_op_id, zbuf, LEN_OP_ID);
            }
            /* read body of input record */
            fgetcdf(ifptr, last);
            fgetcdf(ifptr, bid);
            fgetcdf(ifptr, bz);
            fgetcdf(ifptr, bx);
            fgetcdf(ifptr, ask);
            fgetcdf(ifptr, az);
            fgetcdf(ifptr, ax);
            fgetcdf(ifptr, high);
            fgetcdf(ifptr, low);
            fgetcdf(ifptr, prev);
            fgetcdf(ifptr, statf.buf);
            if (strlen(statf.buf) > 2) {
/*            printf(stat_err, sequence);  */
              goto SkipOut;
            }
/*please*/  if (statf.b.tick == 1){
/*check*/     outrec.o_bs[0] = 'D';
/*  ! */    }
            else if (statf.b.tick == 0){
              outrec.o_bs[0] = 'U';
            }
            fgetcdf(ifptr, base);
            /* perform arithmetic and output formatting */
            div = basetodiv(base);
            sprintf(last, "%#*.6f", LEN_LAST, strtod(last, NULL) / div);
            strncpy(outrec.o_current, last, LEN_CURRENT);
            fgetcdf(ifptr, bb);
            div = basetodiv(bb);
            sprintf(bid,  "%#*.6f", LEN_BID,  strtod(bid,  NULL) / div);
            strncpy(outrec.o_bid, bid, LEN_BID);
            sprintf(ask,  "%#*.6f", LEN_ASK,  strtod(ask,  NULL) / div);
            strncpy(outrec.o_ask, ask, LEN_ASK);
            fgetcdf(ifptr, tickvol);
            fgetcdf(ifptr, totvol);
            sprintf(totvol, "%*ld", LEN_VOLUME, strtol(totvol, NULL, 0));
            strncpy(outrec.o_volume, totvol, LEN_VOLUME);
            /* read remainder of input record */
/*            fgetcdf(ifptr, ext);
            printf("¯%s", ext);
            fgetcdf(ifptr, exl);
            printf("ù%s", exl);
            fgetcdf(ifptr, news);
            printf("ù%s", news);
            fgetcdf(ifptr, newtime);
            printf("ù%s", newtime);
            fgetcdf(ifptr, newday);
            printf("ù%s®", newday);
*/
            break;
          }
          case('G'):{
/*          printf("G "); */
            /* process symbol field */
            fgetcdf(ifptr, symbol);
            /* break out option-id if necessary */
            zbuf[0] = '\0';
            c1ptr = symbol;
            cptr = strtok(c1ptr, " ");
            cptr = strtok(NULL, " ");
            if (cptr != NULL) strcpy(zbuf, cptr);
            x =* symbol; /* faster than sscanf */ 
            if (symbol[0] == '$') ;
            else if (isalpha(x)) ;
            else {
             printf("Questionable symbol: %s   Record: %ld \n", symbol, sequence);
             goto SkipOut;
            }
            /* initialize output record */
            memcpy(&outrec, &initrec, sizeof(outrec));
/*            memset(outrec, ' ', sizeof(outrec));   space out initialization buffer */
            strncpy(outrec.o_rectype, rectype, LEN_RECTYPE);
            strncpy(outrec.o_symbol, symbol, strlen(symbol));
            x = strlen(zbuf);
            if (x > 0) {
              memcpy(outrec.o_op_id, zbuf, LEN_OP_ID);
            }
            /* read body of input record */
            fgetcdf(ifptr, last);
            fgetcdf(ifptr, bid);
            fgetcdf(ifptr, ask);
            fgetcdf(ifptr, high);
            fgetcdf(ifptr, low);
            fgetcdf(ifptr, prev);
            fgetcdf(ifptr, statf.buf);
            if (strlen(statf.buf) > 2) {
/*            printf(stat_err, sequence);  */
              goto SkipOut;
            }
/*please*/  if (statf.b.tick == 1){
/*check*/     outrec.o_bs[0] = 'D';
/*  ! */    }
            else if (statf.b.tick == 0){
              outrec.o_bs[0] = 'U';
            }
            fgetcdf(ifptr, base);
            fgetcdf(ifptr, volume);
/**/        printf("ù%sù ", volume);
            fgetcdf(ifptr, interest);
            /* perform arithmetic and output formatting */
            div = basetodiv(base);
            sprintf(last, "%#*.6f", LEN_LAST, strtod(last, NULL) / div);
            strncpy(outrec.o_current, last, LEN_CURRENT);
            sprintf(bid,  "%#*.6f", LEN_BID,  strtod(bid,  NULL) / div);
            strncpy(outrec.o_bid, bid, LEN_BID);
            sprintf(ask,  "%#*.6f", LEN_ASK,  strtod(ask,  NULL) / div);
            strncpy(outrec.o_ask, ask, LEN_ASK);
            sprintf(volume, "%*ld", LEN_VOLUME, strtol(volume, NULL, 0));
            strncpy(outrec.o_volume, volume, LEN_VOLUME);
            break;
          }
          case('M'):{
/*          printf("M "); */
            /* process symbol field */
            fgetcdf(ifptr, symbol);
            x =* symbol; /* faster than sscanf */ 
            if (symbol[0] == '$') ;
            else if (isalpha(x)) ;
            else {
             printf("Questionable symbol: %s   Record: %ld \n", symbol, sequence);
             goto SkipOut;
            }
            /* break out option-id if necessary (not!) */
            zbuf[0] = '\0';
/*          c1ptr = symbol;
            cptr = strtok(c1ptr, ".");    
            cptr = strtok(NULL, ".");     
            if (cptr != NULL) strcpy(zbuf, cptr); */
            /* initialize output record */
            memcpy(&outrec, &initrec, sizeof(outrec));
/*            memset(outrec, ' ', sizeof(outrec));   space out initialization buffer */
            strncpy(outrec.o_rectype, rectype, LEN_RECTYPE);
            strncpy(outrec.o_symbol, symbol, strlen(symbol));
            x = strlen(zbuf);
            if (x > 0) {
              memcpy(outrec.o_op_id, zbuf, LEN_OP_ID);
            }
            /* read body of input record */
            fgetcdf(ifptr, count);
#if DEBUG
  printf("Count: %s %.8x\n", count, count);
#endif
            fgetcdf(ifptr, ttime);
#if DEBUG
  printf("Time:  %s %.8x\n", ttime, ttime);
#endif
            fgetcdf(ifptr, day);
#if DEBUG
  printf("Day:   %s\n", day);
#endif
            break;
          }
          case('Q'):{
/*          printf("Q "); */
            /* process symbol field */
            fgetcdf(ifptr, symbol);
            x =* symbol; /* faster than sscanf */ 
            if (symbol[0] == '$') ;
            else if (isalpha(x)) ;
            else {
             printf("Questionable symbol: %s   Record: %ld \n", symbol, sequence);
             goto SkipOut;
            }
            
            /* break out option-id if necessary */
            zbuf[0] = '\0';
            c1ptr = symbol;
            cptr = strtok(c1ptr, " ");
            cptr = strtok(NULL, " ");
            if (cptr != NULL) strcpy(zbuf, cptr);
            /* initialize output record */
            memcpy(&outrec, &initrec, sizeof(outrec));
/*            memset(outrec, ' ', sizeof(outrec));   space out initialization buffer */
            strncpy(outrec.o_rectype, rectype, LEN_RECTYPE);
            strncpy(outrec.o_symbol, symbol, strlen(symbol));
            x = strlen(zbuf);
            if (x > 0) {
              memcpy(outrec.o_op_id, zbuf, LEN_OP_ID);
            }
            /* read body of input record */
            fgetcdf(ifptr, interest);
            break;
          }
          default:{
/*          printf("OTHER: %c \n", w_rectype); */
            goto SkipOut;
          }
        }
        /* bottom-of-loop processing */
#if DEBUG
        printf("end of record\n");
#endif
        /* time/date/seq stamp, inc output counters and squirt out record */
        if (sequence == 99999999) sequence = 0;
        sprintf(zbuf, "%08ld", ++sequence);
#if DEBUG
        printf("(1)%s\n", zbuf);
#endif
        strncpy(outrec.o_seq, zbuf, strlen(zbuf));
        time(&timer);
        timeptr = localtime(&timer);
        strftime(zbuf, (LEN_TIME + 1), "%H%M%S", timeptr);
        strncpy(outrec.o_time, zbuf, strlen(zbuf));
#if DEBUG
        printf("(2)%s\n", zbuf);
#endif
        strftime(zbuf, (LEN_DATE + 1), "%Y%m%d", timeptr);
        strncpy(outrec.o_date, zbuf, strlen(zbuf));
#if DEBUG
        printf("(3)%s\n", zbuf);
#endif
        outcnt++;
#if DEBUG
        printf("(4)%ld\n", outcnt);
        printf("a Outrec sizes: %d \n", sizeof(outrec));
        printf("Before writing record %ld\n", sequence);
#endif
        /* write that record */
        /* x = sizeof(outrec); write(ofd, &outrec, x); */
        /* write(ofd, &outrec, sizeof(outrec)); */
        /* write(ofd, outrec, sizeof(outrec)); */
        /* cptr = &outrec; write(ofd, cptr, sizeof(outrec)); */
        write(ofd, p1, sizeof(outrec));
        /* write(ofd, &outrec, sizeof(outrec)); */
        
#if DEBUG
        printf("Before writing record %ld EOL \n", sequence);
#endif
        write(ofd, "\n", 1);
#if DEBUG
        printf("Just wrote record %ld\n", sequence);
#endif
        
        printf("\n");
#if DEBUG
        memcpy(buffer, &outrec, sizeof(buffer));
        printf("%s\n", buffer);
        /* exit(0); */
#endif
SkipOut:
        /* read fields until one starting with / is found */
        do fgetcdf(ifptr, zbuf); while (zbuf[0] != '/');
        printf("~ Increment value now %d\n", incr);
      
      }
      close(ofd);
      /* CONTROL FILE handling */
      if ((cfptr = fopen("ctlfile","rb")) != NULL){
        fldcnt = fscanf(cfptr, "%c %d", &func, &ctlparm);
        fclose(cfptr);
        unlink("ctlfile");
        if (fldcnt > 0){
          switch (func){
            case 'N':{
              if (fldcnt == 2) {
                printf("Starting output file sequence at %d by command from control file.\n", ctlparm);
                ofcount = ctlparm;
                incr = 0;
              }
              else
                printf("Error 1 - command file parameter error, command file ignored\n");
              break;
            }
            case 'Q':{
              printf("Shutting down by command from control file.");
              exit(0);
            }
            default:{
              printf("Error 2 - unknown command %c, command file ignored\n", func);
              break;
            }
          }
        }
      }
      printf("$ Increment to be used is %d\n", incr);
      ofcount = (ofcount + incr) % MAXOFILES;
      printf("$ Next output file to be assigned is %d\n", ofcount);
      incr = 1;
    } /* end if res >= 1 (always true if not LIVESOURCE) */
  } /* end of main processing loop */
} /* end main */
double basetodiv(char *baseparm)
/* converts a base to a divisor */
{
  char b;
  double d;
  b =* baseparm; /* faster than sscanf */
  b = toupper((int) b);
/*   b = toupper((char) b); */
  switch (b){
    case('H'): d=8;      break;
    case('R'): d=256;    break;
    case('E'): d=1;      break;
    case('I'): d=10;     break;
    case('J'): d=16;     break;
    case('K'): d=32;     break;
    case('L'): d=64;     break;
    case('M'): d=100;    break;
    case('N'): d=1000;   break;
    case('O'): d=10000;  break;
    case('P'): d=100000; break;
    case('Q'): d=128;    break;
    default:{
#if DEBUG
      printf("Unknown base factor %s, 1 assumed\n", baseparm);
#endif
      d=1;
    }
  }
  return(d);
}
void fgetcdf(FILE *fp, char *bufname)
/* gets a comma delimited string from a file */
{
  int x, x1;  char c;
  x = fscanf(fp, "%[^,\n\r]", bufname);   /* scan up to comma or newline */
  x1 = fscanf(fp, "%c", &c);              /* throw it away! */
  if ((x == EOF) || (x1 == EOF)) {
    printf("ENDING PROGRAM -- EOF on input file");
    exit(2);
  }
  if (x != 1) {                         /* if we got no field, */
    bufname[0] = '\0';                  /* show 0-length string in buffer */
  }
/* #if DEBUG */
  printf("_%s_ ", bufname);
/* #endif */
}


Any trademark appearing on this page is the property of its owner.

Home ] Up ] Contents ] Search ] Strategic Management ] Project Management ] User Assistance ] More About Us ]

Please send us your questions or comments about this web site.
Design, Implementation and Contents Copyright © 1998-2004 MGT Computer Solutions
All rights reserved.
Last modified: April 22, 2005