void getmp3taginfo(void) { long pos; int size; mp3_gottag = 0; size = sizeof(mp3_tag); pos = mp3_stream_size - size; if (pos < 0) return; if (lseek(mp3_fd, pos, SEEK_SET) < 0) return; if (read(mp3_fd, &mp3_tag, size) != size) return; if (strncmp(&mp3_tag.tag[0], "TAG", 3) != 0) return; /* Return file pointer to start of file */ lseek(mp3_fd, 0, SEEK_SET); /* Construct fill NULL terminated strings */ mkstring(&mp3_title[0], &mp3_tag.title[0], sizeof(mp3_tag.title)); mkstring(&mp3_artist[0], &mp3_tag.artist[0], sizeof(mp3_tag.artist)); mkstring(&mp3_album[0], &mp3_tag.album[0], sizeof(mp3_tag.album)); mkstring(&mp3_year[0], &mp3_tag.year[0], sizeof(mp3_tag.year)); mkstring(&mp3_comments[0], &mp3_tag.comments[0], sizeof(mp3_tag.comments)); mp3_genre = (mp3_tag.genre >= genre_count) ? "Unknown" : genre_table[mp3_tag.genre]; mp3_gottag = 1; }
int main(int argc, char *argv[]) { struct mkstring_options opts; memset(&opts, 0, sizeof(struct mkstring_options)); if (parse_cmdline(argc, argv, &opts)) { usage(argv[0]); return 1; } return mkstring(&opts); }
void reconnect() { int port = 0; mkstring(addr); if(*serveraddress) copystring(addr, serveraddress); if(serverconport) port = serverconport; disconnect(1); if(*addr) { if(port) connectserv(addr, port); else connectserv(addr); } else connectserv(); }
/* ========================================================================= */ void *make_data_type(unsigned long sioffset, char *mount_point) { switch(sioffset) { case PI_MNTNAME: return((void *)mkstring(mount_point)); break; /* its all */ case PI_TOTALSZ: case PI_FREESIZ: case PI_NRFREEB: return(malloc(sizeof(uint64_t))); break; /* about */ case PI_PCTFREE: case PI_PCTUSED: return(malloc(sizeof(int16_t))); break; /* the compiler */ } return(NULL); }
/* ========================================================================= */ struct file_stat *new_file_stat(char *filename) { struct file_stat *fs; assert ( filename != NULL ); if ( NULL == (fs = (struct file_stat *)malloc(sizeof(struct file_stat))) ) { /* Error messages *can* be printed at this point */ fprintf(stderr, "ERROR: Unable to allocate memory in the file.stat provider.\n"); return(NULL); } if ( NULL == (fs->name = mkstring(filename)) ) { fprintf(stderr, "ERROR: Unable to allocate memory in the file.stat provider.\n"); return(NULL); } if ( NULL == (fs->prevs = (struct stat *)malloc(sizeof(struct stat))) ) { fprintf(stderr, "ERROR: Unable to allocate memory in the file.stat provider.\n"); return(NULL); } if ( NULL == (fs->thiss = (struct stat *)malloc(sizeof(struct stat))) ) { fprintf(stderr, "ERROR: Unable to allocate memory in the file.stat provider.\n"); return(NULL); } if ( NULL == (fs->datas = (struct stat *)malloc(sizeof(struct stat))) ) { fprintf(stderr, "ERROR: Unable to allocate memory in the file.stat provider.\n"); return(NULL); } return(fs); }
int loaddefs(int fromfile, char *fname, int mode) { nialptr ts; int repeatloop, keepreading, nolines, inremark, linecnt; FILE *f1 = NULL; /* initialized to avoid complaint */ int errorsfound; if (fromfile) { f1 = openfile(fname, 'r', 't'); if (f1 == OPENFAILED) return (false); pushsysfile(f1); } /* a loaddefs always affects the global environment. We reset current_env to relect this. The code to restore the environment is below. This must be saved on the stack, otherwise it can get thrown away since it may only be owned by a transient definition value. The following example failed before I protected this on the stack: retry is { host 'vi bug.ndf'; loaddefs"bug l } where this definition was in the file bug.ndf. */ apush(current_env); current_env = Null; ts = topstack; /* to monitor stack growth on each action */ errorsfound = 0; /* reset parse error counter */ repeatloop = true; linecnt = 0; /* loop to pick up groups of lines */ while (repeatloop) { /* continue as long as their are line groups */ /* test on each circuit if an interrupt signal has been posted */ #ifdef USER_BREAK_FLAG if (fromfile) checksignal(NC_CS_NORMAL); #endif inremark = false; nolines = 0; keepreading = true; /* loop to pick up lines until a whitespace line occurs */ while (keepreading) { if (fromfile) { /* reading a line from the file */ readfileline(f1, (mode ? 2 : 0)); /* mode==2 only in a loaddefs */ /* readfileline places result on the stack */ if (top == Eoffault) { apop(); /* to remove the end of file marker */ repeatloop = false; break; /* to end read loop */ } } else { /* select a line from array defsndf loadded from defstbl.h */ char *line; line = defsndf[linecnt++]; if (linecnt == NOLINES) { repeatloop = false; keepreading = false; /* to end read loop */ } mkstring(line); /* convert the line to a Nial string and push it */ } if (nolines == 0) { /* check first line of group for a remark */ char firstchar; int i = 0; /* loop to skip blanks */ while (i < tally(top) && fetch_char(top, i) <= BLANK) i++; /* note whether first char is "#" */ firstchar = fetch_char(top, i); if (tally(top)) inremark = firstchar == HASHSYMBOL; else inremark = false; } /* if the line is all while space then we are at the end of a group */ if (top == Null || allwhitespace(pfirstchar(top))) { keepreading = false; freeup(apop()); /* to get rid of the empty line */ } else /* count the line on the stack */ nolines++; } /* we have a group of lines to process */ if (nolines > 0) { mklist(nolines); /* create a list of lines and link them*/ ilink(); if (inremark) { freeup(apop()); /* remarks are ignored */ } else { /* carry out the actions of the main loop */ iscan(); parse(true); /* check whether parse produced an error */ if (kind(top) == faulttype) { if (top != Nullexpr) { errorsfound++; if (mode == 0) { /* show error message */ apush(top); ipicture(); show(apop()); } } } /* evaluate the parse tree, if it is a fault, it is the value returned */ ieval(); #ifdef DEBUG memchk(); #endif if (mode) { /* show the result */ if (top != Nullexpr) { ipicture(); show(apop()); } else apop(); /* the Nullexpr */ } else freeup(apop()); /* free because it might not be Nullexpr */ } if (mode) { /* now display empty line */ writechars(STDOUT, "", (nialint) 0, true); if (keeplog && f1 == STDIN) writelog("", 0, true); } } /* check that the stack hasn't grown */ if (ts != topstack) { while (ts != topstack) freeup(apop()); exit_cover(NC_STACK_GROWN_I); } } /* done reading groups of lines */ if (fromfile) { closefile(f1); popsysfile(); } /* restore the current_env */ current_env = apop(); if (errorsfound > 0) nprintf(OF_NORMAL_LOG, "errors found: %d\n", errorsfound); return (true); }
void itimestamp(void) { get_tstamp(gcharbuf); mkstring(gcharbuf); }
int main() { var i = 1; autostr s = mkstring("hello world %d", i); puts(s); autostr t = "don't free this"; }
/* ========================================================================= */ struct options *ReadOptions(int argc, char *argv[]) { struct options *o; int index; int c; if ( NULL == (o = (struct options *)malloc(sizeof(struct options)))) { fprintf(stderr, "ERROR: Unable to allocate memory. Exiting.\n"); return(NULL); } set_opt_defaults(o); while ( -1 != ( c = getopt(argc, argv, ":+ab:d:ho:s" ) ) ) { switch(c) { case '+': o->bDebug = 1; break; case 'a': o->bAbout = 1; break; case 'h': o->bHelp = 1; break; case 'd': if ((( optarg[0] == 'r' ) || ( optarg[0] == 'R' )) && (optarg[1] == 0)) o->direct = DIRECT_READ; if ((( optarg[0] == 'w' ) || ( optarg[0] == 'W' )) && (optarg[1] == 0)) o->direct = DIRECT_WRITE; if ((( optarg[0] == 'r' ) || ( optarg[0] == 'R' )) && (( optarg[1] == 'w' ) || ( optarg[1] == 'W' )) && (optarg[2] == 0)) o->direct = DIRECT_ALL; if ( DIRECT_NONE == o->direct ) { fprintf(stderr, "ERROR: Failed to parse -d option \"%s\".\n", optarg); o->bError = 1; } break; case 'o': o->buf_rsize = atoi(optarg); break; case 'b': o->buf_bsize = atol(optarg); break; case 's': o->bStats = 1; break; case ':': /* User forgot required argument */ o->bError = 1; fprintf(stderr, "ERROR: Missing argument to the \"-%c\" option.\n", optopt); break; case '?': /* User entered some unknown/unsupported argument */ o->bError = 1; if (isprint (optopt)) fprintf(stderr, "ERROR: Unknown option \"-%c\".\n", optopt); else fprintf(stderr, "ERROR: Unknown option character `\\x%x'.\n", optopt); break; default: /* Really an unreachable place */ o->bError = 1; return(o); } } /* Read the non-flag options (If there are any... ) */ index = optind; while ( index < argc ) { if ( NULL == o->source ) { if ( NULL == (o->source = mkstring(argv[index])) ) { fprintf(stderr, "ERROR: Failed to create source filename string.\n"); return(NULL); } } else { if ( NULL == o->dest ) { if ( NULL == (o->dest = mkstring(argv[index])) ) { fprintf(stderr, "ERROR: Failed to create destination filename string.\n"); return(NULL); } } else { fprintf(stderr, "ERROR: Additional argument not understood.\n"); return(NULL); } } index++; } /* Start validating user input */ if ( o->bError ) { /* Error has already been printed */ return(NULL); } if (( o->bAbout ) || ( o->bHelp )) { if (( o->source ) || ( o->dest )) { fprintf(stderr, "NOTE: The -a and -h options are not compatible with other options.\n"); return(NULL); } /* No additional processing required if any of these are set */ return(o); } else { if (( NULL == o->source ) || ( NULL == o->dest )) { fprintf(stderr, "NOTE: Source and destination paths must be specified.\n"); return(NULL); } } return(o); }