is_valid_stdf.c

Checks to see whether the STDF files conform to their respective specs

00001 
00004 /*
00005  * Copyright (C) 2004-2006 Mike Frysinger <vapier@gmail.com>
00006  * Released under the BSD license.  For more information,
00007  * please see: http://opensource.org/licenses/bsd-license.php
00008  *
00009  * $Header: /cvsroot/freestdf/libstdf/examples/is_valid_stdf.c,v 1.6 2005/11/13 08:56:58 vapier Exp $
00010  */
00011 
00012 #include <libstdf.h>
00013 
00014 #define print_msg(m) printf("\t" m "\n");
00015 #define print_err(m) printf("\tERROR: " m "\n");
00016 
00017 int main(int argc, char *argv[])
00018 {
00019     stdf_file *f;
00020     rec_unknown *rec;
00021     rec_header prev_rec;
00022     long rec_mrr_cnt, rec_pcr_cnt, rec_hbr_cnt, rec_sbr_cnt, rec_wcr_cnt;
00023     int i;
00024 
00025     if (argc <= 1) {
00026         printf("Need some files to open!\n");
00027         return EXIT_FAILURE;
00028     }
00029 
00030 for (i=1; i<argc; ++i) {
00031     printf("Validating %s", argv[i]);
00032     f = stdf_open(argv[i]);
00033     if (!f) {
00034         perror("Could not open file");
00035         return EXIT_FAILURE;
00036     }
00037 
00038     /* STDF spec requires every STDF file have an initial sequence.
00039      * A valid sequence can be any of these:
00040      FAR -      - MIR
00041      FAR - ATRs - MIR
00042      FAR -      - MIR - RDR
00043      FAR - ATRs - MIR - RDR
00044      FAR -      - MIR -     - SDRs
00045      FAR - ATRs - MIR -     - SDRs
00046      FAR -      - MIR - RDR - SDRs
00047      FAR - ATRs - MIR - RDR - SDRs
00048      */
00049 
00050     /* Find the FAR record */
00051     rec = stdf_read_record(f);
00052     if (rec == NULL || HEAD_TO_REC(rec->header) != REC_FAR) {
00053         print_err("First record is not FAR!");
00054         goto next_file;
00055     }
00056     stdf_free_record(rec);
00057     /* Try to read all the ATR records (if they exist) */
00058     while ((rec=stdf_read_record(f)) != NULL) {
00059         if (HEAD_TO_REC(rec->header) != REC_ATR)
00060             break;
00061         else
00062             stdf_free_record(rec);
00063     }
00064     if (rec == NULL) {
00065         print_err("Initial sequence not found!");
00066         goto next_file;
00067     }
00068     /* We should now have the MIR record already read in */
00069     if (HEAD_TO_REC(rec->header) != REC_MIR) {
00070         print_err("Initial sequence wrong: MIR not located!");
00071         goto next_file;
00072     }
00073     /* Try to read the RDR record (if it exists) */
00074     stdf_free_record(rec);
00075     if ((rec=stdf_read_record(f)) == NULL) {
00076         print_err("EOF found after initial sequence!");
00077         goto next_file;
00078     }
00079     if (HEAD_TO_REC(rec->header) == REC_RDR) {
00080         stdf_free_record(rec);
00081         rec = stdf_read_record(f);
00082         if (rec == NULL) {
00083             print_err("EOF found after initial sequence!");
00084             goto next_file;
00085         }
00086     }
00087     /* Try to read the SDR records (if they exist) */
00088     while (HEAD_TO_REC(rec->header) == REC_SDR) {
00089         stdf_free_record(rec);
00090         rec = stdf_read_record(f);
00091         if (rec == NULL) {
00092             print_err("EOF found after initial sequence!");
00093             goto next_file;
00094         }
00095     }
00096 
00097     /* Now we read the rest of the file */
00098     rec_mrr_cnt = rec_pcr_cnt = rec_hbr_cnt = rec_sbr_cnt = rec_wcr_cnt = 0;
00099     while (1) {
00100         memcpy(&prev_rec, &rec->header, sizeof(rec_header));
00101         stdf_free_record(rec);
00102         rec = stdf_read_record(f);
00103         if (rec == NULL)
00104             break;
00105 
00106         switch (HEAD_TO_REC(rec->header)) {
00107             case REC_FAR:
00108             case REC_ATR:
00109             case REC_MIR:
00110             case REC_RDR:
00111             case REC_SDR:
00112                 printf("\tFound %s outside of initial sequence!\n",
00113                        stdf_get_rec_name(rec->header.REC_TYP, rec->header.REC_SUB));
00114                 goto next_file;
00115             case REC_MRR:
00116                 if (++rec_mrr_cnt > 1) {
00117                     print_err("More than one REC_MRR was found!");
00118                     goto next_file;
00119                 }
00120                 break;
00121             case REC_PCR: ++rec_pcr_cnt; break;
00122             case REC_HBR: ++rec_hbr_cnt; break;
00123             case REC_SBR: ++rec_sbr_cnt; break;
00124 
00125             /* need some logic with these ... */
00126             case REC_PMR: break;
00127             case REC_PGR: break;
00128             case REC_PLR: break;
00129 
00130             case REC_WIR: break; /* only 1 per wafer */
00131             case REC_WRR: break; /* only 1 per wafer */
00132 
00133             case REC_WCR:
00134                 if (++rec_wcr_cnt > 1) {
00135                     print_err("More than one REC_WCR was found!");
00136                     goto next_file;
00137                 }
00138                 break;
00139 
00140             /* each PIR must have a PRR for same HEAD/SITE */
00141             /* PTR/MPR/FTR records must appear between the right PIR/PRR pairs */
00142             /* each BPS/EPS pair must be inside the PIR/PRR pair */
00143             case REC_PIR: break; /* only 1 per part tested */
00144             case REC_PTR: break; /* only 1 per part tested */
00145             case REC_MPR: break; /* only 1 per part tested */
00146             case REC_FTR: break; /* only 1 per part tested */
00147             case REC_BPS: break;
00148             case REC_EPS: break;
00149             case REC_PRR: break; /* only 1 per part tested */
00150 
00151             case REC_TSR: break;
00152             case REC_GDR: break;
00153     
00154             default:
00155                 print_err("Uknown record found!");
00156                 goto next_file;
00157         }
00158     }
00159     if (HEAD_TO_REC(prev_rec) != REC_MRR) {
00160         print_err("REC_MRR was not the last record in the stream!");
00161         goto next_file;
00162     }
00163 
00164     print_msg("... is valid");
00165 next_file:
00166     stdf_free_record(rec);
00167     stdf_close(f);
00168 }
00169     return EXIT_SUCCESS;
00170 }

Generated on Thu Jun 8 14:05:35 2006 for libstdf by  doxygen 1.4.6