home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 502b.lha / cc / src / op.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  1.2 KB  |  61 lines

  1. /*
  2.  * file operands
  3.  * March 1989, Miles Bader (orig from cc.c by fred fish)
  4.  */
  5.  
  6. #include "common.h"
  7. #include "op.h"
  8.  
  9. /*
  10.  *    Split an operand name into rootname, basename, and suffix
  11.  *    components.  The rootname is the full name, minus any suffix,
  12.  *    but including any prefix.  The basename is the rootname minus
  13.  *    any prefix.  The suffix is anything after the last '.' character.
  14.  *    Only the suffix is allowed to be the null string.
  15.  */
  16. struct op *op_Create(filename)
  17. char *filename;
  18. {
  19.     char *split;
  20.     extern char *strrchr();
  21.     struct op *op=NEW(struct op);
  22.  
  23.     DBUG_ENTER("op_Create");
  24.  
  25.     DBUG_3("ops", "create op '%s'",filename);
  26.  
  27.     if(op==NULL)
  28.     fatal("couldn't allocate an op");
  29.  
  30.     op->rootname=filename;
  31.  
  32.     split=strrchr(filename,'/');
  33.     if(split==NULL)
  34.     split=strrchr(filename,':');
  35.  
  36.     if(split==NULL)
  37.     op->basename=filename;
  38.     else
  39.     op->basename=++split;
  40.  
  41.     split=strrchr(filename,'.');
  42.     if(split==NULL)
  43.     op->suffix="";
  44.     else{
  45.     *split++='\0';
  46.     op->suffix=split;
  47.     }
  48.  
  49.     DBUG_3("ops","rootname '%s'",op->rootname);
  50.     DBUG_3("ops","basename '%s'",op->basename);
  51.     DBUG_3("ops","suffix '%s'",op->suffix);
  52.  
  53.     DBUG_RETURN(struct op *,op);
  54. }
  55.  
  56. void op_Free(op)
  57. struct op *op;
  58. {
  59.     FREE(op);
  60. }
  61.