home *** CD-ROM | disk | FTP | other *** search
- /* ->/ C.File
- Extensions to c library, to stamp and read stamp time off files
-
- M.D. James Aug 1989
-
- */
- #include "h.h"
- #include "os.h"
-
- #define d1970hi 0x33l
- #define d1970lo 0x6e996a00l
-
- #define BigOver100 42949673
-
-
- #define READ_CATINFO 5
- #define STAMP_FILE 9
-
- #define MAX_PARTS 10 /* things in a pathname separated with dots */
- #define MAX_WORDS 50 /* words on a command line */
-
- #define SUFFIXES "choapy" /* .o,.c,.h,.a,.p,.y files will be swapped */
-
- static char spac[]= " ";
- static char sep[] = "."; /* the string to separate tokens */
- static struct error *err;
-
- /* converts from file names in unix style */
- /* $.fish.file.c -> $.fish.c.file */
- /* but leaves */
- /* arm.c.leg -> arm.c.leg */
-
- void RISCfromUnix(char *str)
- {
- char * words[MAX_PARTS]; /* keep all of the tokens */
- char name[LZ];
- char * where,*token;
- int word,c ;
-
- word = 0;
-
-
- strcpy(name,str);
-
-
-
- /* locate all the words */
-
- for (where=name;((token = strtok(where,sep)) != NULL ) && (word < MAX_PARTS);where=NULL)
- {
- words[word]= (char *) malloc(strlen(token)+1);
- if (words[word] == NULL)
- report_error("Malloc Failed in RiscFromUnix");
- strcpy(words[word++],token);
- }
- word--;
-
- /* now reassemble into RISC type filename */
- strcpy(str,"");
-
- /* single char suffixes */
-
- if ((strlen(words[word])==1)&& (word>0)&&
- (strpbrk(words[word],SUFFIXES)!=NULL))
- {
- /* Take the root, and copy it out */
- for (c=0;c<=(word-2);c++)
- if (*words[c]!='\0')
- {
- strcat(str,words[c]);
- strcat(str,"."); /* will be more , so can leave dots */
- };
- /* now copy the last two words over if they are there */
- if (*words[word]!='\0')
- {
- strcat(str,words[word]);
- strcat(str,".");
- };
- if (*words[word-1]!='\0')
- strcat(str,words[word-1]);
- }
- else /* copy it over unchanged */
- for (c=0;c<=word;c++)
- if (*words[c]!='\0')
- {
- strcat(str,words[c]);
- if (c!=(word))
- strcat(str,"."); /* will be more , so can leave dots */
- } ;
-
- for (c=0;c<=word;free(words[c++]));
- }
-
-
- /* used as every file line is written to !make */
-
- void convertLine(char * line)
- {
- char str[LZ];
- char * where,*token;
- char *words[MAX_WORDS]; /* pointers to all of the words */
- int i,wordcnt;
-
-
-
-
- if (strlen(line) >= LZ)
- report_error("String too long in ConvertLine");
-
- /* move to temp workspace */
- strcpy(str,line);
-
- where = str;
- /* get rid of the tab characters to avoid messing up RISCfromUnix */
- while(*where!=0)
- {
- if (*where=='\t')
- *where=' ';
- where++;
- }
-
-
- /* locate all the words in name, and try to do the filename swap on them */
- /* strtok is non- reentrant */
- wordcnt = 0;
-
- for (where=str;((token=strtok(where,spac))!=NULL)&&(wordcnt < MAX_WORDS);where=NULL)
- {
- words[wordcnt]= (char *) malloc(strlen(token)+1);
- if (words[wordcnt] == NULL)
- report_error("Malloc Failed in ConvertLine");
- strcpy(words[wordcnt++],token);
- }
-
- /* rebuild the line */
- strcpy(line,"");
- for (i=0;i<wordcnt;i++)
- {
- RISCfromUnix(words[i]);
- strcat(line,words[i]);
- strcat(line," ");
- free(words[i]); /* let it go */
- };
-
-
-
- }
-
- /* when was it ? who am i ? what is it ? */
- unsigned
- int getstamp(char *name, int * stat)
- {
- /* calls the osfile */
- unsigned long int lo,hi,time_thing;
- char local_name[LZ];
- os_filestr fcb[1];
-
- /* add in the file path to the name */
- sprintf(local_name,"%s.%s",filepath,name);
-
- RISCfromUnix(local_name);
-
- fcb -> name = local_name;
-
- fcb -> action = READ_CATINFO;
-
- err = (struct error *) os_file(fcb);
-
- *stat = (fcb -> action); /* file ? directory ? nothing ? */
-
-
- /* this needs Unixing */
- /* 22089880000 centiseconds between 1900 and 1970 */
- /* knock off the difference */
- /* date in form - dd dddddddd */
- /* divide 40 bit number by 100 */
-
-
- hi = ((unsigned int) (fcb->loadaddr)&0xff)-d1970hi;
- lo = (unsigned int) (fcb->execaddr) -d1970lo;
- /* no borrow on overflow - unsigned*/
- /* integer wraps round */
- if (fcb->start >0) /* zero length is equal to old file */
- time_thing = (hi*BigOver100+lo/100);
- else
- time_thing = 0;
-
- return (time_thing);
- }
-
- void stamp( char * name)
- {
-
- char local_name[80];
- os_filestr fcb[1];
-
- /* add in the file path to the name */
- sprintf(local_name,"%s.%s",filepath,name);
-
- RISCfromUnix(local_name);
-
- fcb -> name = local_name;
-
- fcb -> action = STAMP_FILE;
-
- err =(struct error *) os_file(fcb);
-
- }
-
-
-
-