Esempio n. 1
0
/*
 * handleHeader - scan through and process header information
 */
static void handleHeader( int *start, SAREA *line )
{
    int         cur;

    cur = 0;
    if( strnicmp( helpInBuf, ":h", 2 ) == 0 ) {
        for( ;; ) {
            if( !mygetline() )
                break;
            if( strnicmp( helpInBuf, ":t", 2 ) == 0 )
                break;
            if( strnicmp( helpInBuf, ":eh", 3 ) == 0 )
                break;
            processLine( helpInBuf, helpOutBuf, cur, false );
            putline( helpOutBuf, cur );
            cur ++;
        }
        line->row = cur;
        uivfill( &helpScreen, *line, AT( ATTR_NORMAL ), UiGChar[UI_SBOX_HORIZ_LINE] );
        cur++;
        topPos = HelpTell( helpFileHdl );
        if( strnicmp( helpInBuf, ":eh", 3 ) == 0 ) {
            mygetline();
        }
    }
    *start = cur;
}
int main() {
    int len;

    printf("Input s1:");
    len=mygetline(s1);
    printf("Input s2:");
    len=mygetline(s2);

    squeeze(s1,s2);

    printf("result:%s\n",s1);
    return 0;
}
Esempio n. 3
0
/*
 * handleFooter - scan through and process footer information
 */
static void handleFooter( int *startline, SAREA *use, SAREA *line )
{
    int         start;

    start = *startline;
    if( strnicmp( helpInBuf, ":t", 2 ) == 0 ) {
        ++start;        /* leave room for line */
        for( ;; ) {
            if( !mygetline() )
                break;
            if( strnicmp( helpInBuf, ":et", 3 ) == 0 )
                break;
            processLine( helpInBuf, helpOutBuf, start, false );
            putline( helpOutBuf, start );
            ++start;
        }
        vscroll_fields( &helpTab, *use, start - use->row - use->height );
        vvscroll( &helpScreen, *use, start - use->row - use->height );
        use->height -= start - use->row;
        line->row = use->row + use->height;
        uivfill( &helpScreen, *line, AT( ATTR_NORMAL ), UiGChar[UI_SBOX_HORIZ_LINE] );
        topPos = HelpTell( helpFileHdl );
    }
    *startline = start;
}
Esempio n. 4
0
/*
 * Function: GetValue
 * Usage: Nkmax = (int)GetValue("datafile","Nkmax");
 * --------------------------------------------
 * Returns the value of the specified variable defined in datafile.
 *
 */
double GetValue(char *filename, char *str, int *status)
{
  int ispace;
  char c, istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  FILE *ifile = MyFOpen(filename,"r","GetValue");
  *status = 0;

  while(1) {
    mygetline(ifile,istr,"");
    if(strlen(istr)==0)
      break;
    getchunk(istr,ostr);
    if(!strcmp(ostr,str)) {
      for(ispace=strlen(ostr);ispace<strlen(istr);ispace++) 
	if(!isspace(istr[ispace]))
	  break;
      if(ispace==strlen(istr)-1)
	*status=0;
      else
	*status=1;
      getchunk(&(istr[ispace]),ostr);
      break;
    }
  }
  fclose(ifile);
  
  if(*status) 
    return strtod(ostr,(char **)NULL);
  else
    return 0;
}
Esempio n. 5
0
/* Reads strings from the file into the liked list */
void loadList( CDLL *list, char *infileName)
{
	char *line;
	char ** tokens;
	int tokenCnt=0;
	char * delim = ",";

	FILE* infile = fopen(infileName, "r");
	if(!infile) fatal("Can't open input file");

	while( mygetline( &line, infile ) )
	{
		STUDENT *s = malloc(sizeof(STUDENT));
		if (!s) fatal("malloc( sizeof(STUDENT))  failed in loadList");

		tokens = split( line, &tokenCnt, delim );
		s->andrewID = tokens[0];
		s->name = tokens[1];
		s->yrOfGrad = atoi(tokens[2]);
		s->gpa = atof(tokens[3]);
		s->major = tokens[4];

		insertAtTail( list,  s );

		free(line);
		free(tokens[2]);      /* year */
		free(tokens[3]);      /* major */
		free(tokens);
	}
	fclose(infile);
}
Esempio n. 6
0
/*
 * Function: GetString
 * Usage: GetString(string,"file.dat","ufile",&status);
 * ----------------------------------------------------
 * Obtains the string associated with the key "ufile" from the
 * file "file.dat".
 *
 */
void GetString(char *string, char *filename, char *str, int *status)
{
  int ispace;
  char c, istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  FILE *ifile = fopen(filename,"r");
  *status = 0;

  while(1) {
    mygetline(ifile,istr,"");
    if(strlen(istr)==0)
      break;
    getchunk(istr,ostr);
    if(!strcmp(ostr,str)) {
      for(ispace=strlen(ostr);ispace<strlen(istr);ispace++) 
	if(!isspace(istr[ispace]))
	  break;
      if(ispace==strlen(istr)-1)
	*status=0;
      else
	*status=1;
      getchunk(&(istr[ispace]),string);
      break;
    }
  }
  fclose(ifile);
}
Esempio n. 7
0
/* print the longest input line */
main()
{
	int len; /* current line length */
	int c;
	int max; /* maximum length seen so far */
	char line[MAXLINE]; /* current input line */
	char longest[MAXLINE]; /* longest line saved here */

	max = 0;
	while ((len = mygetline(line, MAXLINE)) > 0) {
		if (len > max) {
			max = len;
			copy(longest, line);
		}
		if (len == MAXLINE - 1)
			if (longest[MAXLINE - 2] != '\n') {
				while ((c = getchar()) != EOF && c != '\n')
					++max;
				if (c == '\n')
					++max;
			}
	}

	if (max > 0) /* there was a line */ {
		printf("Longest line: %d chars\n", max);
		printf("%s\n", longest);
		if (max > MAXLINE)
			printf("(truncated)\n");
	}
	else
		printf("Empty input!\n");
	return 0;
}
Esempio n. 8
0
int main( int argc, char *argv[] )
{
  // ALWAYS check arg before using argv

  if (argc < 2 )
  {
	  fprintf( stderr, "usage: ./%s <input filename>\n", argv[0] );
	  exit( EXIT_FAILURE );
  }

  FILE * infile = fopen( argv[1], "rt" );
  if (!infile)
  {
	  fprintf( stderr, "Cant open %s for read.\n", argv[1] );
	  exit( EXIT_FAILURE );
  }

  char *buffer=NULL; // no buffer (char array) has been allocated yet. Mygetline will allocate space to this ptr
  int lineNum=0;

  // Mygetline will only return a non null pointer if it read something into the buffer for you to print.
  // Otherwise it will return with a NULL in buffer to indicate there is no line to print.

  while ( mygetline( &buffer, infile ) ) //  while mygetline()   equvalent to    while mygetline != NULL
  {
	  printf("%2d: %s", ++lineNum, buffer );
	  free ( buffer ); // Since mygetline malloc'd a string, so you must free it before reusing that buffer
  }

  fclose( infile );

  return (EXIT_SUCCESS );
}
int main(int argc, char *argv[])
{
    int i;
    int linecount = 0;
    int max_linecount;
    char line[MAXLINE];

    if (argc > 1)
        max_linecount = abs(atoi(argv[1]));
    else
        max_linecount = 10;

    char *lines[max_linecount];

    while (mygetline(line, MAXLINE) > 0) {
        if (linecount < max_linecount) {
            *(lines+linecount) = (char *) malloc(sizeof line);
            strcpy(*(lines+(linecount++)), line);
        } else {
            for (i = 0; i < max_linecount-1; i++)
                strcpy(*(lines+i), *(lines+(i+1)));
            strcpy(*(lines+i), line);
        }
    }
    for (i = 0; i < max_linecount; i++)
        printf("%s", *(lines+i));
    for (i = 0; i < max_linecount; i++)
        free(*(lines+i));

    return 0;
}
Esempio n. 10
0
/*
 * Function: getelement()
 * Usage: n=getelement(ifile);
 * ---------------------------
 * Returns the first numbers in the line up until the first space.
 */
double getelement(FILE *ifile)
{
  char istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  int i=0;
  mygetline(ifile,istr,"");
  getchunk(istr,ostr);
  return strtod(ostr,(char **)NULL);
}
int main(){
  int len;
  while((len=mygetline())>0){
    detab();
    printf("%s",notab);
  }
  return 0;
}
int main(){
  int len;
  while((len=mygetline())>0){
    fold();
    printf("%s",innew);
  }
  return 0;
}
Esempio n. 13
0
/*简单计算器程序*/
main(){
    double sum,atof(char []);
    char line[MAXLINE];

    sum = 0;
    while (mygetline(line, MAXLINE)>0)
        printf("\t%g\n",sum+=atof(line));
    return 0;
}
Esempio n. 14
0
/* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == */
int main(int argc, char *argv[])
{
	CDLL list;
	int i,direction, k;
	CDLL_NODE *currNode;

	if (argc < 4)
	{
		printf("You must supply 3 values on the cmd line after %s:\n", argv[0]);
		printf("1: name of an input file contaning n names/labels of the members of the circle\n");
		printf("2: an integer:  k < n  ,  indicating that after deleting the selected starting element, k members are skipped before another deletions until all the members are deleted\n");
		printf("3: a string \"CW\" or \"CCW\" for clockwise counter-clockwise. This is the direction\n");
		printf("   you will move as you advance around the ring deleting members\n");
		exit( EXIT_FAILURE );
	}

	k  = atoi(argv[2]); /* assume valid int < n */
	if (strcmp(argv[3],"CW")==0)
		direction = CLOCKWISE; /* follow the NEXT ptr */
	else
		direction = COUNTERCLOCKWISE; /* follow the PREV ptr */

	/* Initialize CDLL (set head ptr NULL and set the cmp function */
	initList(&list, compareString,printString,freeString);
	loadList(&list,argv[1]);
	printf("\nLIST: ");printList(list, CLOCKWISE, BRIEF ); /* we follow the NEXT ptr around the ring, not the PREV ptr */

	do /* prompt user for a member to start the counting with */
	{
		char *name;
		printf("\nchoose a name as the starting point in the circle: ");
		if (!mygetline( &name,stdin)) fatal("mygetline failed in main reading from stdin.");
		currNode = searchList( list, name); // if user enters non-existent name it will ret NULL
		free( name );
	} while (!currNode);

	while (list.head) /* while list has any members left */
	{
		printf("\nDELETING: "); printString( currNode->data, BRIEF); fflush(stdout);
		currNode = deleteNode( &list, currNode, direction );
		if (!currNode)
		{
			printf("  <-- was the last man standing!\n");
			break;
		}
		printf("\nLIST: "); fflush(stdout);
		printList(list, CLOCKWISE, BRIEF );
		printf("RESUMING AT: "); printString( currNode->data, BRIEF ); printf( " and skipping %d elements \n", k );
		for ( i=1 ; i<=k ; ++i )
			if (direction==CLOCKWISE)
				currNode = currNode->next;
			else
				currNode=currNode->prev;

	} /* END WHILE - END OF GAME */
    return EXIT_SUCCESS;
}
int main(){
  int len;

  while((len=mygetline())>0){
    recoms();
    printf("%s",nocom);
  }
  return 0;
}
Esempio n. 16
0
int main(void)
{
    char text[20] = "";
    fputs("prompt: ", stdout);
    fflush(stdout);
    char* line = mygetline(text, sizeof text);
    printf("text = \"%s\"\n", line );
    return 0;
}
Esempio n. 17
0
int getop(char s[])
{
        int i = 0, c;
        s[0] = '\0';

        if (getopbuflen == 0 || getopbufp == getopbuflen-2) {
                getopbufp = 0;
                /* Get a new line of input from the user. */
                getopbuflen = mygetline(getopbuf, BUFSIZE);
        }

        if (getopbuf[getopbufp] == '\n') {
                return '\n';
        }

        /* Jump over spaces at the begining of the string. */
        while (isspace(c = getopbuf[getopbufp++]));
        s[i++] = c;

        if (isalpha(c) && c >= 'A' && c <= 'Z') {
                /* Collect the variable. */
                for (i = 1; getopbuf[getopbufp] != ' '
                     && getopbuf[getopbufp] != '\n';
                     s[i++] = getopbuf[getopbufp++]);
                s[i] = '\0';
                if (i > 1) { /* A properly formed variable definition. */
                        return VARIABLE;
                } else {
                        return c;
                }
        } else if (!isdigit(c) && c != '.' && c != '-') {
                return c; /* Not a number. */
        }

        if (c == '-') {
                if ((c = getopbuf[++getopbufp]) == ' ') {
                        /* If the next char is space, then c is a operator. */
                        return c;
                } else if (isdigit(c)) {
                        s[++i] = c;
                }

        }

        if (isdigit(c)) { /* Collect integer part. */
                for ( ; isdigit(c = getopbuf[getopbufp]); i++, getopbufp++) {
                        s[i] = c;
                }
        }

        if (c == '.') {   /* Collect fraction part. */
                while (isdigit(s[i++] = c = getopbuf[getopbufp++]));
        }

        s[i] = '\0';
        return NUMBER;
}
Esempio n. 18
0
Gains_t* get_gold(const char* fname, Date_t* adate)
{
 Gains_t *this;
 FILE *iFile;

 char  /*                  char                        */
      line[1024]
    , msgbuf[1024]
   ;

 double  /*                double                      */
        gain1
      , gain2
      , gain3
      , gain4
      , gain5
      , gain7
      , ysl
   ;

 int   /*                  int                        */
      dsl
    , doy
    , year
   ;

 this = (Gains_t*)malloc(sizeof(Gains_t));
 iFile= fopen(fname,"r");
 if ( !iFile ) 
   { 
   sprintf(msgbuf,"unable to open file %s",fname); 
   ERROR(msgbuf, "get_gold");
   }

  skipline(iFile,2);
  this->valid_flag= false;

  while ( mygetline(line,1024,iFile)>=0 )
   {
   sscanf(line,"%d %d %d %lg %lg %lg %lg %lg %lg %lg",
          &year,&doy,&dsl,&ysl,&gain1,&gain2,&gain3,&gain4,&gain5,&gain7);

    if ( year == adate->year && doy == adate->doy )
      {
      this->gains[0]= (float)gain1;
      this->gains[1]= (float)gain2;
      this->gains[2]= (float)gain3;
      this->gains[3]= (float)gain4;
      this->gains[4]= (float)gain5;
      this->gains[6]= (float)gain7;
      this->valid_flag= true; 
      break;
      }
   }
 return this;
}
Esempio n. 19
0
/* Reads strings from the file into the liked list */
void loadList( CDLL *list, char *infileName)
{
	FILE* infile = fopen(infileName, "r");
	if(!infile) fatal("Can't open input file");

	char *name;
	while( mygetline( &name, infile ) )
		insertAtTail( list, name );
	fclose(infile);
}
Esempio n. 20
0
main()
{
  int len;                       /* current line length */
  char line[MAXLINE+1];          /* current input line plus '\0' */
  
  while ((len = mygetline(line, MAXLINE)) != EOF)
    if (len > 80)
      printf("%s\n", line);
  return 0;
}
Esempio n. 21
0
int main(void)
{
	char readln[MAXLINE];
	
	while (mygetline(readln, MAXLINE) > 0) {
		reverse(readln);
		fprintf(stdout, "%s\n", readln);
	}
	return 0;
}
Esempio n. 22
0
File: 4-2.c Progetto: naiyt/kandr
int main() {
    char num[MAXLENGTH];
    double answer;

    while(mygetline(num, MAXLENGTH) > 0) {
        answer = atof(num);
        printf("%f\n", answer);
    } 

    return 0;
}
Esempio n. 23
0
int main(int argc, char *argv[])
{
    int len;
    char line[MAXLINE];
    while ((len = mygetline(line, MAXLINE)) > 0)
    {
        trim(line);
        printf("%s\n", line);
    }
    return 0;
}
Esempio n. 24
0
main()
{
   int len = 0;
   char line[MAXLINE];

   while ((len = mygetline(line, MAXLINE)) > 1) {
      reverse(line, len);
      printf("%s\n", line);
   }
   
}
Esempio n. 25
0
main()
{
   char buffer[MAXLINE];
   int len = 0;
   int i;
   
   while((len = mygetline(buffer, MAXLINE)) > 1) {
      printf("%s\n", buffer);
   }
   
}
Esempio n. 26
0
main()
{
   int len = 0;
   int newlen = 0;
   char line[MAXLINE];
   
   while((len = mygetline(line, MAXLINE)) > 1 ) {
      newlen = chomp(line, len);
      printf("Len: %d-%d, \n -%s-\n", len, newlen, line);
   }
}
Esempio n. 27
0
main()
{  
   int len;
   len = 0;
   char line[MAXLINE];  // array to hold input line
   
   while ((len = mygetline(line, MAXLINE)) > 1) {
      if (len >= 80)
         printf("=>%d: %s\n", len, line);
   }
}
Esempio n. 28
0
main()
{
	char line[MAXLINE];
	while(mygetline(line, MAXLINE))
	{
		printf("%s", line);
	}

	printf("end!!!");

	return 0;
}
/* print the longest input line and its length */
main() {
  int len;      /* current line length */
  char line[MAXLINE];    /* current input line */

  while ((len = mygetline(line, MAXLINE)) > 0) {
	if (len > MAXLINE) {
	  printf("%s\n", line);	  
	}
  }

  return 0;
}
Esempio n. 30
0
/* perform import command */
static int procimport(const char *upath, uint64_t lim){
  TCULOG *ulog = tculognew();
  if(!tculogopen(ulog, upath, lim)){
    printerr("tculogopen");
    return 1;
  }
  bool err = false;
  char *line;
  while(!err && (line = mygetline(stdin)) != NULL){
    uint64_t ts = ttstrtots(line);
    char *pv = strchr(line, '\t');
    if(!pv || ts < 1){
      tcfree(line);
      continue;
    }
    pv++;
    uint32_t sid = tcatoi(pv);
    char *mp = strchr(pv, ':');
    pv = strchr(pv, '\t');
    if(!pv){
      tcfree(line);
      continue;
    }
    pv++;
    uint32_t mid = 0;
    if(mp && mp < pv) mid = tcatoi(mp + 1);
    pv = strchr(pv, '\t');
    if(!pv){
      tcfree(line);
      continue;
    }
    pv++;
    int osiz;
    unsigned char *obj = (unsigned char *)tchexdecode(pv, &osiz);
    if(!obj || osiz < 3 || *obj != TTMAGICNUM){
      tcfree(obj);
      tcfree(line);
      continue;
    }
    if(!tculogwrite(ulog, ts, sid, mid, obj, osiz)){
      printerr("tculogwrite");
      err = true;
    }
    tcfree(obj);
    tcfree(line);
  }
  if(!tculogclose(ulog)){
    printerr("tculogclose");
    err = true;
  }
  tculogdel(ulog);
  return err ? 1 : 0;
}