Date:2013-01-15 21:05:33 (11 years 2 months ago)
Author:Werner Almesberger
Commit:69aba6ae19f0560cd5ebaba7e76c6e40ee215ee7
Message:ubb-patgen/ubb-patgen.c: accept file (- for standard input) as pattern source

Files: ubb-patgen/ubb-patgen.c (5 diffs)

Change Details

ubb-patgen/ubb-patgen.c
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <unistd.h>
17#include <ctype.h>
1718#include <string.h>
1819#include <math.h>
1920#include <time.h>
...... 
194195}
195196
196197
198static const char *load_pattern(const char *s)
199{
200    static char buf[20000]; /* more than enough :) */
201    FILE *file;
202    char *p = buf;
203    int comment = 0;
204    int c;
205
206    if (!strcmp(s, "-")) {
207        file = stdin;
208    } else {
209        file = fopen(s, "r");
210        if (!file)
211            return s;
212    }
213    while ((c = fgetc(file)) != EOF) {
214        if (comment) {
215            comment = c != '\n';
216            continue;
217        }
218        if (c == '#') {
219            comment = 1;
220            continue;
221        }
222        if (isspace(c))
223            continue;
224        if (buf+sizeof(buf)-1 == p) {
225            fprintf(stderr, "%s: file is too big\n", s);
226            exit(1);
227        }
228        *p++ = c;
229    }
230    if (file != stdin)
231        fclose(file);
232    *p = 0;
233    return buf;
234}
235
236
197237/* ----- DMA control ------------------------------------------------------- */
198238
199239
...... 
449489"usage: %s\n"
450490" %s [-q] -f freq_hz\n"
451491" %s [-q] [-f freq_hz] -c [active_s]\n"
452" %s [-q] [-f freq_hz] [-C] pattern\n\n"
492" %s [-q] [-f freq_hz] [-C] file|pattern\n\n"
453493" -c output bus clock on CLK without sending a pattern\n"
454494" -C temporarily output bus clock on CLK (for debugging)\n"
455495" -f freq_hz set bus clock to the specified frequency (default: 1 MHz)\n"
...... 
457497" differences.\n\n"
458498" active_s keep running that many seconds after setting the clock\n"
459499" (default: exit immediately but leave the clock on)\n"
500" file file containing the pattern\n"
460501" pattern send the specified pattern on DAT0 through DAT3\n\n"
461502"Frequency: the frequency in Hz, optionally followed by \"M\" or \"k\",\n"
462503" optionally followed by \"Hz\", optionally followed by \"+\" or \"-\".\n"
...... 
538579        usage(*argv);
539580    }
540581
582    if (pattern)
583        pattern = load_pattern(pattern);
584
541585    ubb_open(UBB_ALL);
542586
543587    PDFUNS = UBB_CMD;

Archive Download the corresponding diff file

Branches:
master



interactive