Example #1
0
int goal_run(char *goal)
{ 
   struct target *aim = ((goal == NULL) ? target_list.head : target_lookup(goal));
   if(aim == NULL) return 1;
   struct name *prereq = aim->prereqs;

   char in[MAXLINE];
   int rline = 0;
   bool update = true;
   while (prereq != NULL) {
      if (target_lookup(prereq->name) != NULL)
         goal_run(prereq->name);
      else
         update = update && check_age(aim, prereq);
      if (prereq->next == NULL)
         break;
      prereq = prereq->next;
   }
   if (update) {
      FILE *fp = fopen(target_list.name, "r");
      if (fp == NULL)
         return 1;
      for (int i = 0; i < aim->line_num; i++) {
         fgets(in, MAXLINE, fp);
      }
      do {
         fgets(in, MAXLINE, fp);
         printf("Recipe line %d>> %s", rline++, in);
      } while (in[0] == '\t');
   }
   return 0;
}
Example #2
0
int init_target(void) 
{
	struct target_info * target;

	target = target_lookup(getenv("TARGET"));

	if (target == NULL) {
		target = target_first();
		trace("WARNING: invalid target.");
		tracef("Fallback to default: %s.", target->name);
	};

	trace("* target select...");

	/* TODO: ice driver selection */
	if (target_ice_configure(stdout, target, 1) < 0) {
		tracef("ERROR: target_ice_configure()!");
		return -1;
	}

	tracef("* target: %s [%s-%s-%s %s-%s-%s]", target->name, 
		   target->arch->name, target->arch->model, target->arch->vendor,
		   target->arch->cpu->family, target->arch->cpu->model, 
		   target->arch->cpu->vendor);

	if (target_config(stdout) < 0) {
		tracef("ERROR: target_config()!");
		return -1;
	}

	return 0;
}
Example #3
0
File: pr8.4.c Project: jbl5088/psu
//------------------------------------------------------------------------------
void pr8_work(char *goal) {
   if (goal == NULL) return;

   printf("goal: %s\n", goal);
   struct target *myTarget = target_lookup(tg_list, goal);
   if(myTarget != NULL) {
   	return;
   }
   // if goal is a known target,
   //   iterate through goal's list of sources,
   //     call pr8_work() on each source
    
   //   iterate through goal's list of sources,
   //     compare times of goal and its sources
  
   //   if necessary, iterate through goal's list of recipes,
   //     print the recipe

   // ... more later

   return;
}
Example #4
0
File: pr8.4.c Project: jbl5088/psu
static void read_lines(char *filename, FILE *fp)
{
   verify(filename != NULL, "null arg filename");
   verify(filename[0] != '\0', "empty arg filename");
   verify(fp != NULL, "null arg fp");

   fprintf(stderr, "%s: read_lines(%s)\n", prog, filename); 

   char original[MAXLINE+2];	// from fgets()
   char expanded[MAXLINE+2];	// after macro expansion
   char buffer[MAXLINE+2];	   // working copy, safe to modify

   char whsp[] = " \t\n\v\f\r";			// whitespace characters
   int line_number = 0;
   int recipe_line_number = 0;

   while (fgets(original, MAXLINE, fp) != NULL) {
       // it is possible that the input line was too long, so terminate the string cleanly
       original[MAXLINE] = '\n';
       original[MAXLINE+1] = '\0';

       line_number++;
     //printf("%s: %s: line %d: %s", prog, filename, line_number, original);

       // assume original[] is constructed properly
       // assume expanded[] is large enough
       macro_expand(original, expanded);
       printf("%s: %s: line %d: %s", prog, filename, line_number, expanded);

       strcpy(buffer, expanded);			// copy, safe to modify

       char *buf = buffer;

       while (*buf == ' ') buf++;			// skip past leading spaces (not tabs!)

       char *p_hash = strchr(buf, '#');		// a comment starts with #
    
       if (p_hash != NULL) {
           *p_hash = '\0'; 
       }			// remove the comment

       int n = 0;					// remove trailing whitespace
       while (buf[n] != '\0'){
           int n1 = strspn(&buf[n], whsp);		// buf[n .. n+n1-1] is whitespace
           int n2 = strcspn(&buf[n + n1], whsp);	// buf[n+n1 .. n+n1+n2-1] is not
           if (n2 == 0) {
                buf[n] = '\0'; break; }	// remove trailing whitespace
           n += n1 + n2;
      }

		if (buf[0] == '\0')	{			// nothing left?
		    continue; 
		}

		char *p_colon = strchr(buf, ':');		// : indicates a target-prerequisite line
		char *p_equal = strchr(buf, '=');		// = indicates a macro definition
		 
// ---------------------------Recipes---------------------------------------------------------
	       	
       if (buffer[0] == '\t') {
		     recipe_line_number++;
		     //printf("  >>> recipe line %d\n", recipe_line_number);
		    
           // the target that is before the recipe
           struct target *myTarget = tg_list.head;
           
           if ( myTarget != NULL) { 	 
               myTarget->rp_list.head = NULL;
               myTarget->rp_list.tail = NULL;
               
               // (save this for a later project)
		         char *recipe = Malloc(128*sizeof(char *));
		         int i = 1;
		         
		         for(; buffer[i] != '\0'; i++) {
		             recipe[i-1] = buffer[i];
		         }
		         recipe[i] = '\0';
		         list_recipes_append(&(myTarget->rp_list), recipe);
           }    
           
		}
		   
// --------------------------------Targets--------------------------------------------------------
		
		else if (p_colon != NULL) {
		    recipe_line_number = 0;
		   // printf("  >>> target-prerequisite\n");
	
		    // (save this for a later project)
		    char *target = Malloc(128 * sizeof(char *));
		    int i = 0;
		    //printf("%s\n",buffer);
	
		    // store target to the list
		    while(buffer[i] != ':' && buffer[i] != ' ') {
		        target[i] = buffer[i];
		        i++;
		    } 
			   
		    target[i] = '\0';
		    list_targets_append(&tg_list, target);

		    struct target *myTarget = target_lookup(tg_list, target);
		    		    
	// --------------------------------Sources------------------------------------------------------				
		    //struct list_sources sc_list = *(myTarget->sc_list);
		    
		    myTarget->sc_list.head = NULL;
          myTarget->sc_list.tail = NULL; 
		    		    
		    // store source to the list
		    // skip all the spaces and ':', and go to the first source
		    while(buffer[i] == ' ' || buffer[i] == ':' ) {
		        i++;
		    }	
			 
		    // store sources to the list
		    while(buffer[i] != '\0') {                 // not terminate until the end of line
			     if( isalpha(buffer[i]) ) {
		            char* source = Malloc(128*sizeof(char));
		            assert(source != NULL);
		            int j=0;
		     
		            while( isalpha(buffer[i]) ) {
		                source[j] = buffer[i];
		               // printf("source: %s\n", source);
		                j++;
		                i++;
		            }
		            list_sources_append(&(myTarget->sc_list), source);
			     }
		        else {	// skip one whitespace 
		            i++;
		        }
		    }
		}    
		   
	// --------------------------------Macros-----------------------------------------------------
		else if (p_equal != NULL){
		   // printf("  >>> macro definition\n");
	
		    // name = body
		    // *p_equal is '='
		    char *name_start = buf;
	
		    while (*name_start == ' ' || *name_start == '\t')	// skip past spaces and tabs
		    { name_start++; }
		    
		    char *name_end = p_equal-1;
	
		    while (*name_end == ' ' || *name_end == '\t') 
		    { name_end--; }
	
		    name_end++;
		    *name_end = '\0';
		    char *body_start = p_equal+1;
	
		    while (*body_start == ' ' || *body_start == '\t')
		     { body_start++; }
		     
		    char *body_end = body_start;
	
		    while (*body_end != '\0')	// end of string
		     { body_end++; }
	
		    while (*body_end == ' ' || *body_end == '\t')
		     { body_end--; }
			 body_end++;
			 *body_end = '\0';
			 macro_list_print();
		    macro_set(name_start, body_start);
			 macro_list_print();
		}
		else if (strncmp("include", buf, 7) == 0) {
		   // printf("  >>> include\n");
		    char *name_start = buf + 7;				// skip past "include"
		    while (*name_start == ' ' || *name_start == '\t') {	// skip past spaces and tabs
		        name_start++; 
		    }
	
		    if (*name_start == '\0') {
			 // following GNU Make, this is not an error
			   //  fprintf(stderr, "%s: %s: line %d: include but no filename\n", prog, filename, line_number);
			     continue;
		    }
		    else if (*name_start == '\'' || *name_start == '"'){		// quoted filename
		        // find matching quote, remove it
			     char *q = name_start + 1;				        // skip past ' or "
			     while (*q != *name_start && *q != '\0') { 
		            q++;	// find end of string or line
		        }
			     if (*q == '\0') {
		            fprintf(stderr, "%s: %s: line %d: file name error: >>>%s<<<\n", 
		                  prog, filename, line_number, name_start);
		            continue;
		        }
		        name_start++;	// skip past opening quote
		        *q = '\0';		// remove closing quote
		    }
		    
		    read_file(name_start, 0);
		}
		else {
		    printf("  >>> something else\n");
		    fprintf(stderr, "%s: %s: line %d: not recognized: %s", prog, filename, line_number, original);
		}
   }

   if (ferror(fp)) {	// error when reading the file
       fprintf(stderr, "%s: %s: read error: %s\n", prog, filename, strerror(errno)); 
   }

   return;
}
Example #5
0
void mcopy(int argc, char **argv, int mtype)
{
	Arg_t arg;
	int c, ret, fastquit;
	int todir;
	

	/* get command line options */

	init_clash_handling(& arg.ch);

	/* get command line options */
	todir = 0;
	arg.recursive = 0;
#ifdef OS_Minix
	arg.preserveTime = 1;	/* Copy file time as DOS does. */
#else
	arg.preserveTime = 0;
#endif
	arg.preserveAttributes = 0;
	arg.nowarn = 0;
	arg.textmode = 0;
	arg.verbose = 0;
	arg.type = mtype;
	fastquit = 0;
	while ((c = getopt(argc, argv, "abB/sptnmvQD:o")) != EOF) {
		switch (c) {
			case 's':
			case '/':
				arg.recursive = 1;
				break;
			case 'p':
				arg.preserveAttributes = 1;
				break;
			case 'a':
			case 't':
				arg.textmode = 1;
				break;
			case 'n':
				arg.nowarn = 1;
				break;
			case 'm':
				arg.preserveTime = 1;
				break;
			case 'v':
				arg.verbose = 1;
				break;
			case 'Q':
				fastquit = 1;
				break;
			case 'B':
			case 'b':
				batchmode = 1;
				break;
			case 'o':
				handle_clash_options(&arg.ch, c);
				break;
			case 'D':
				if(handle_clash_options(&arg.ch, *optarg))
					usage();
				break;
			case '?':
				usage();
			default:
				break;
		}
	}

	if (argc - optind < 1)
		usage();

	init_mp(&arg.mp);
	arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN | NO_DOTS;
	arg.mp.fast_quit = fastquit;
	arg.mp.arg = (void *) &arg;
	arg.mp.openflags = O_RDONLY;

	/* last parameter is "-", use mtype mode */
	if(!mtype && !strcmp(argv[argc-1], "-")) {
		arg.type = mtype = 1;
		argc--;
	}

	if(mtype){
		/* Mtype = copying to stdout */
		arg.mp.targetName = strdup("-");
		arg.mp.unixTarget = strdup("");
		arg.mp.callback = dos_to_unix;
		arg.mp.dirCallback = unix_copydir;
		arg.mp.unixcallback = unix_to_unix;		
	} else {
		char *target;
		if (argc - optind == 1) {
			/* copying to the current directory */
			target = ".";
		} else {
			/* target is the last item mentioned */
			argc--;
			target = argv[argc];
		}

		ret = target_lookup(&arg.mp, target);
		if(!arg.mp.targetDir && !arg.mp.unixTarget) {
			fprintf(stderr,"Bad target %s\n", target);
			exit(1);
		}

		/* callback functions */
		if(arg.mp.unixTarget) {
			arg.mp.callback = dos_to_unix;
			arg.mp.dirCallback = directory_dos_to_unix;
			arg.mp.unixcallback = unix_to_unix;
		} else {
			arg.mp.dirCallback = dos_copydir;
			arg.mp.callback = dos_to_dos;
			arg.mp.unixcallback = unix_to_dos;
		}
	}

	exit(main_loop(&arg.mp, argv + optind, argc - optind));
}
Example #6
0
int cmd_target(FILE *f, int argc, char ** argv)
{
	struct target_info * target = NULL;
	int force = 0;
	int probe = 0;
	int scan = 0;
	int config = 0;
	value_t val;
	int ret;
	int i;
	int n;

	argc--;
	argv++;

	if (argc == 0) {
		target = target_select_tool(f);
		config = 1;
	} else {
		if ((target = target_lookup(*argv)) != NULL) {
			DCC_LOG(LOG_TRACE, "target_lookup() success.");
			argc--;
			argv++;
		} else {
			if ((n = eval_uint32(&val, argc, argv)) >= 0) {
				argc -= n;
				argv += n;
				n = val.uint32;

				DCC_LOG(LOG_TRACE, "searching the target list...");

				target = target_first();
				for (i = 0; (i < n) && (target != NULL); i++)
					target = target_next(target);
			}
		} 

		while (argc) {
			if ((strcmp(*argv, "force") == 0) || 
				(strcmp(*argv, "f") == 0)) {
				force = 1;
			} else if ((strcmp(*argv, "probe") == 0) 
					|| (strcmp(*argv, "p") == 0)) {
					probe = 1;
			} else if ((strcmp(*argv, "scan") == 0) 
					   || (strcmp(*argv, "s") == 0)) {
				scan = 1;
			} else if ((strcmp(*argv, "config") == 0) 
					   || (strcmp(*argv, "c") == 0)) {
				config = 1;
			} else {
				fprintf(f, "Invalid argument: %s...\n", *argv);
				fprintf(f, "usage: target <NAME|ID> "
						"<force|probe|scan|config>\n");
				return -1;
			}
			argc--;
			argv++;
		}
	}

	/* FIXME */
	(void)scan;

	if (target != NULL) {
		fprintf(f, " - Target: '%s'\n", target->name);

		if ((ret = target_ice_configure(f, target, force)) < 0) {
			fprintf(f, " # ICE configuration ERROR!\n");
			fprintf(f, "ERROR: target_ice_configure()!\n");
			return ret;
		}
	}

	if (probe) {
		if ((ret = target_probe(f)) < 0) {
			fprintf(f, " # probe ERROR!\n");
			return ret;
		} 
		if(ret == 0) {
			fprintf(f, " - probe Fail!\n");
		} else {
			fprintf(f, " - probe Ok.\n");
		}
	} 

	if (config) {
		if ((ret = target_config(f)) < 0) {
			fprintf(f, " # Target configuration ERROR!\n");
			return ret;
		} 
	}

	return 0;
}