static int process_Renviron(const char *filename) { FILE *fp; char *s, *p, sm[BUF_SIZE], *lhs, *rhs, msg[MSG_SIZE+50]; int errs = 0; if (!filename || !(fp = R_fopen(filename, "r"))) return 0; snprintf(msg, MSG_SIZE+50, "\n File %s contains invalid line(s)", filename); while(fgets(sm, BUF_SIZE, fp)) { sm[BUF_SIZE-1] = '\0'; s = rmspace(sm); if(strlen(s) == 0 || s[0] == '#') continue; if(!(p = Rf_strchr(s, '='))) { errs++; if(strlen(msg) < MSG_SIZE) { strcat(msg, "\n "); strcat(msg, s); } continue; } *p = '\0'; lhs = rmspace(s); rhs = findterm(rmspace(p+1)); /* set lhs = rhs */ if(strlen(lhs) && strlen(rhs)) Putenv(lhs, rhs); } fclose(fp); if (errs) { strcat(msg, "\n They were ignored\n"); R_ShowMessage(msg); } return 1; }
SFUndoes* SFUndoFromString( char* str ) { enum sfundotype t = sfut_fontinfo; char* staticmsg = "fixme"; char* sfdfrag = str; if( !strncmp( str, "BeginFontLevelUndo", strlen("BeginFontLevelUndo"))) { char* p; if( (p = findterm( &str, "FontLevelUndoType:" )) ) t = atoi(p); if( (p = findterm( &str, "FontLevelUndoMessage:" )) ) staticmsg = p; } SFUndoes* ret = SFUndoCreateSFD( t, staticmsg, sfdfrag ); return ret; }
plain_termlist getterms(void) { /* Declarations */ unsigned char counter,minterm_size; plain_termlist minterms; char *buffer; char temp; plain_term *current_node; /* initialize the list of minterms for future use */ initialize(minterms); /* irint instractions to the user */ printf("Give the minterms, one in each line.\n"); printf("They must all have the same number of variables.\n"); printf("Anything apart from \"0\"s and \"1\"s in a line will signal the end of input.\n"); /* Note: minterms are kept in memory as strings. */ /* Allocate an initial buffer to hold the first minterm. */ /* The size is the number of bits used to represent a */ /* memory address and thus more than enough to hold a */ /* minterm of the fuction with the largest number of */ /* variables this machine can process to simplify */ if(!(buffer = malloc(8*sizeof(buffer)))) { /* if there is not enough memory, terminate. */ fprintf(stderr,"Not enough memory. Terminating...\n"); system("PAUSE"); exit(1); } /* read the first minterm and save it's size in memory */ /* the next minterms should be of that size */ counter = 0; while ((temp = getchar()) == '1' || temp == '0') *(buffer + counter++) = temp; *(buffer + counter) = '\0'; minterm_size = counter; /* if the first character is null the user didn't give any minterms. Possibly the zero funcion. */ if (temp == '\n') { /* create the first node and but the given minterm in it. */ /* then free the buffer. the new buffer will be smaller */ addtostart(malloc(minterm_size),minterms,plain_term); strcpy(content(first(minterms)),buffer); free(buffer); /* put "current_node" at the start of the list */ current_node = first(minterms); for(;;) { /* allocate memory for another minterm */ if (!(buffer = malloc(minterm_size))) { /* if there is not enough memory, terminate. */ fprintf(stderr,"Not enough memory. Terminating...\n"); system("PAUSE"); exit(1); } /* read another minterm */ counter = 0; while ((temp = getchar()) == '1' || temp == '0') *(buffer + counter++) = temp; *(buffer + counter) = '\0'; /* check for end of input */ /* newline means another term is to be read */ if (temp == '\n') { /* Note: the findterm is declared to take a termlist as it's */ /* input, but because both structs have the same first two */ /* members it should work fine with a plain_termlist too. */ if (findterm(buffer,(termlist)minterms)) { /* a minterm is given twice, notify he user */ printf("The last minterm was ignored as it has already been given.\n"); } else { /* add the term to the list */ add(buffer,current_node,plain_term); /* move "current_node" to the newly created node, */ /* so that the next node will be inserted after it */ current_node = next(current_node); } } else { /* the input has ended, so the last buffer wasn't used and it can be freed */ free(buffer); break; } } } else free(buffer); return minterms; }