home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / k / make / !make_c_File < prev    next >
Encoding:
Text File  |  1994-10-12  |  4.5 KB  |  212 lines

  1. /* ->/ C.File
  2. Extensions to c library, to stamp and read stamp time off files 
  3.  
  4. M.D. James Aug 1989
  5.  
  6. */
  7. #include "h.h"
  8. #include "os.h"
  9.  
  10. #define d1970hi   0x33l
  11. #define d1970lo   0x6e996a00l
  12.  
  13. #define BigOver100 42949673
  14.  
  15.  
  16. #define READ_CATINFO 5
  17. #define STAMP_FILE   9
  18.  
  19. #define MAX_PARTS 10  /* things in a pathname separated with dots */
  20. #define MAX_WORDS 50  /* words on a command line */
  21.  
  22. #define SUFFIXES "choapy"   /* .o,.c,.h,.a,.p,.y files will be swapped */
  23.  
  24. static char  spac[]= " ";
  25. static char  sep[] = ".";       /* the string to separate tokens */
  26. static struct error *err;
  27.  
  28. /* converts from file names in unix style */
  29. /* $.fish.file.c -> $.fish.c.file    */
  30. /* but leaves */
  31. /* arm.c.leg     -> arm.c.leg */
  32.  
  33. void RISCfromUnix(char *str)
  34.   {
  35.   char * words[MAX_PARTS]; /* keep all of the tokens */
  36.   char name[LZ];
  37.   char * where,*token;
  38.   int word,c ;
  39.  
  40.   word = 0;
  41.  
  42.  
  43.   strcpy(name,str);
  44.   
  45.  
  46.  
  47.   /* locate all the words */
  48.  
  49.   for (where=name;((token = strtok(where,sep)) != NULL ) && (word < MAX_PARTS);where=NULL)
  50.     {
  51.     words[word]= (char *) malloc(strlen(token)+1);
  52.     if (words[word] == NULL) 
  53.       report_error("Malloc Failed in RiscFromUnix");   
  54.     strcpy(words[word++],token);
  55.     }
  56.   word--; 
  57.  
  58.  /* now reassemble into RISC type filename  */
  59.  strcpy(str,"");
  60.  
  61.    /* single char suffixes */
  62.  
  63.  if ((strlen(words[word])==1)&& (word>0)&&
  64.    (strpbrk(words[word],SUFFIXES)!=NULL)) 
  65.     {
  66.     /* Take the root, and copy it out */ 
  67.     for (c=0;c<=(word-2);c++)
  68.       if (*words[c]!='\0')
  69.         {
  70.         strcat(str,words[c]);
  71.         strcat(str,"."); /* will be more , so can leave dots */
  72.         };
  73.     /* now copy the last two words over if they are there */
  74.       if (*words[word]!='\0')
  75.         {
  76.         strcat(str,words[word]);
  77.         strcat(str,".");
  78.         };
  79.       if (*words[word-1]!='\0')
  80.         strcat(str,words[word-1]);
  81.     }
  82.   else /* copy it over unchanged */
  83.     for (c=0;c<=word;c++)
  84.       if (*words[c]!='\0')
  85.         {
  86.         strcat(str,words[c]);
  87.         if (c!=(word))
  88.           strcat(str,"."); /* will be more , so can leave dots */
  89.         } ;
  90.  
  91.     for (c=0;c<=word;free(words[c++]));
  92.   }
  93.  
  94.  
  95. /* used as every file line is written to !make */
  96.  
  97. void convertLine(char * line)
  98.   {
  99.   char str[LZ];
  100.   char * where,*token;
  101.   char *words[MAX_WORDS]; /* pointers to all of the words */
  102.   int i,wordcnt;
  103.  
  104.  
  105.  
  106.  
  107.   if (strlen(line) >= LZ)
  108.     report_error("String too long in ConvertLine");
  109.  
  110.   /* move to temp workspace */
  111.   strcpy(str,line);
  112.  
  113.   where = str;
  114.   /* get rid of the tab characters to avoid messing up RISCfromUnix */
  115.   while(*where!=0)
  116.     {
  117.     if (*where=='\t')
  118.       *where=' ';
  119.     where++;
  120.     }
  121.  
  122.  
  123.   /* locate all the words in name, and try to do the filename swap on them */
  124.   /* strtok is non- reentrant */
  125.   wordcnt = 0;
  126.  
  127.   for (where=str;((token=strtok(where,spac))!=NULL)&&(wordcnt < MAX_WORDS);where=NULL)
  128.     {
  129.     words[wordcnt]= (char *) malloc(strlen(token)+1);
  130.     if (words[wordcnt] == NULL) 
  131.       report_error("Malloc Failed in ConvertLine");   
  132.     strcpy(words[wordcnt++],token);
  133.     }
  134.  
  135.   /* rebuild the line */
  136.   strcpy(line,"");
  137.   for (i=0;i<wordcnt;i++) 
  138.     {
  139.     RISCfromUnix(words[i]);
  140.     strcat(line,words[i]);
  141.     strcat(line," ");
  142.     free(words[i]); /* let it go */
  143.     };               
  144.  
  145.  
  146.  
  147.   }
  148.  
  149. /* when was it ? who am i ? what is it ? */
  150. unsigned
  151. int getstamp(char *name, int * stat)
  152.   {
  153.   /* calls the osfile */
  154.   unsigned long int lo,hi,time_thing;
  155.   char local_name[LZ];
  156.   os_filestr fcb[1];
  157.  
  158.   /* add in the file path to the name */                 
  159.   sprintf(local_name,"%s.%s",filepath,name);
  160.  
  161.   RISCfromUnix(local_name);
  162.  
  163.   fcb -> name = local_name;
  164.  
  165.   fcb -> action = READ_CATINFO;
  166.  
  167.   err = (struct error *) os_file(fcb);
  168.  
  169.   *stat = (fcb -> action);   /* file ? directory ? nothing ? */
  170.  
  171.  
  172.   /* this needs Unixing */
  173.   /* 22089880000 centiseconds between 1900 and 1970 */
  174.   /* knock off the difference */
  175.   /* date in form - dd dddddddd */
  176.   /* divide 40 bit number by 100 */
  177.  
  178.  
  179.   hi  = ((unsigned int) (fcb->loadaddr)&0xff)-d1970hi; 
  180.   lo  =  (unsigned int) (fcb->execaddr)      -d1970lo;
  181.  /* no borrow on overflow - unsigned*/
  182.                 /* integer wraps round */
  183.   if (fcb->start >0)  /* zero length is equal to old file */
  184.     time_thing =  (hi*BigOver100+lo/100);
  185.   else 
  186.     time_thing = 0;
  187.  
  188.   return (time_thing);
  189.   }
  190.  
  191. void stamp( char * name)
  192.   {
  193.  
  194.   char local_name[80];
  195.   os_filestr fcb[1];
  196.  
  197.   /* add in the file path to the name */                 
  198.   sprintf(local_name,"%s.%s",filepath,name);
  199.  
  200.   RISCfromUnix(local_name);
  201.  
  202.   fcb -> name = local_name;
  203.  
  204.   fcb -> action = STAMP_FILE;
  205.  
  206.   err =(struct error *) os_file(fcb);
  207.  
  208.   }
  209.  
  210.  
  211.  
  212.