Home | History | Annotate | Download | only in alsactl
      1 extern int debugflag;
      2 extern int force_restore;
      3 extern int ignore_nocards;
      4 extern char *command;
      5 extern char *statefile;
      6 
      7 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
      8 #define info(...) do {\
      9 	fprintf(stdout, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     10 	fprintf(stdout, __VA_ARGS__); \
     11 	putc('\n', stdout); \
     12 } while (0)
     13 #else
     14 #define info(args...) do {\
     15 	fprintf(stdout, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     16 	fprintf(stdout, ##args); \
     17 	putc('\n', stdout); \
     18 } while (0)
     19 #endif
     20 
     21 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
     22 #define error(...) do {\
     23 	fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     24 	fprintf(stderr, __VA_ARGS__); \
     25 	putc('\n', stderr); \
     26 } while (0)
     27 #else
     28 #define error(args...) do {\
     29 	fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     30 	fprintf(stderr, ##args); \
     31 	putc('\n', stderr); \
     32 } while (0)
     33 #endif
     34 
     35 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
     36 #define cerror(cond, ...) do {\
     37 	if (cond) { \
     38 		fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     39 		fprintf(stderr, __VA_ARGS__); \
     40 		putc('\n', stderr); \
     41 	} \
     42 } while (0)
     43 #else
     44 #define cerror(cond, args...) do {\
     45 	if (cond) { \
     46 		fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     47 		fprintf(stderr, ##args); \
     48 		putc('\n', stderr); \
     49 	} \
     50 } while (0)
     51 #endif
     52 
     53 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
     54 #define dbg(...) do {\
     55 	if (!debugflag) break; \
     56 	fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     57 	fprintf(stderr, __VA_ARGS__); \
     58 	putc('\n', stderr); \
     59 } while (0)
     60 #else
     61 #define dbg(args...) do {\
     62 	if (!debugflag) break; \
     63 	fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \
     64 	fprintf(stderr, ##args); \
     65 	putc('\n', stderr); \
     66 } while (0)
     67 #endif
     68 
     69 int init(const char *file, const char *cardname);
     70 int save_state(const char *file, const char *cardname);
     71 int load_state(const char *file, const char *initfile, const char *cardname,
     72 	       int do_init);
     73 int power(const char *argv[], int argc);
     74 int generate_names(const char *cfgfile);
     75 
     76 /* utils */
     77 
     78 int file_map(const char *filename, char **buf, size_t *bufsize);
     79 void file_unmap(void *buf, size_t bufsize);
     80 size_t line_width(const char *buf, size_t bufsize, size_t pos);
     81 void initfailed(int cardnumber, const char *reason);
     82 
     83 static inline int hextodigit(int c)
     84 {
     85         if (c >= '0' && c <= '9')
     86                 c -= '0';
     87         else if (c >= 'a' && c <= 'f')
     88                 c = c - 'a' + 10;
     89         else if (c >= 'A' && c <= 'F')
     90                 c = c - 'A' + 10;
     91         else
     92                 return -1;
     93         return c;
     94 }
     95