home *** CD-ROM | disk | FTP | other *** search
- /* scon_in() -- read in a string constant using input.
- * Format of an scon is either a quoted string, or a sequence
- * of characters ended with a seperator (' ', '\t' or '\n' or ',').
- *
- * In either mode, you can get funny characters into the string by
- * "quoting" them with a '\'.
- *
- * scon_in() uses myalloc() to create space to store the string in.
- */
- char *scon_in()
- {
- register char c,*s;
- static char text [80];
-
- s = &text[0];
-
- /* beginning state, skip seperators until something interesting comes along */
-
- l1: c=input();
- if(c == '"') goto l2;
- else if(c=='\n' || c=='\0') {
- rdlin(bsin);
- goto l1;
- }
- else if(c==' ' || c=='\t' || c==',') goto l1;
- else goto l3;
-
- /* have skipped unwanted material, seen a '"', read in a quoted string */
-
- l2: c=input();
- if(c == '\n') {
- fprintf(stderr,"scon_in: unterminated string\n");
- exit(1);
- }
- else if(c == '\\') { *s++ = bslash(bsin); goto l2; }
- else if(c == '"')
- if((c=input()) == '"') {
- *s++ = '"';
- goto l2;
- }
- else goto done;
- else { *s++ = c; goto l2; }
-
- /* skipped unwanted, seen something interesting, not '"', gather until sep */
-
- l3: *s++ = c;
- c=input();
- if(c == '\\') { c = bslash(bsin); goto l3; }
- else if(c==' ' || c=='\t' || c==',' || c=='\n') goto done;
- else goto l3;
-
- /* final state (if machine finished ok.) */
-
- done: unput(c);
- *s++ = '\0';
- s=myalloc(strlen(text)+1);
- strcpy(s,text);
- return(s);
- }
-